/*
* Joe Faron, Inc. 2007
*/

var error;

function checkSubmit(type){

  firstErrorDiv="";
  error = 0;

  if(type == "stock"){
    checkFieldOr('tickers','price');
    checkField('shares');
    checkField('comission');
    checkFieldOr('growth', 'newPrice');
  }
   if(checkIfErrors() == false){
     return false;
   }else{
     return true;
   }
}

function checkField(fieldName){
  v = document.getElementById(fieldName).value;
  if (v.length==0){
      new Effect.Highlight(fieldName, {duration:2.5, startcolor:'#FFCCCC'});
      setdiv((fieldName+'Label'), "invalidLabel");
      error++;
  }else{
      setdiv((fieldName+'Label'), "");
      setdiv(fieldName, "validLabel");
  }
}

function checkFieldOr(fieldNameOne, fieldNameTwo){
  vOne = document.getElementById(fieldNameOne).value;
  vTwo = document.getElementById(fieldNameTwo).value;
  if (vOne.length==0 && vTwo.length==0){
      new Effect.Highlight(fieldNameOne, {duration:2.5, startcolor:'#FFCCCC'});
      new Effect.Highlight(fieldNameTwo, {duration:2.5, startcolor:'#FFCCCC'});
      setdiv((fieldNameOne+'Label'), "invalidLabel");
      setdiv((fieldNameTwo+'Label'), "invalidLabel");
      error++;
  }else{
      setdiv((fieldNameOne+'Label'), "");
      setdiv(fieldNameOne, "validLabel");
      setdiv((fieldNameTwo+'Label'), "");
      setdiv(fieldNameTwo, "validLabel");
  }
}


function checkIfErrors() {
  if(error > 0){
    showdiv("correctErrors");
    return false;
  }else{
    hidediv("correctErrors");
    return true;
  }
}