// Author - Sunila Levi - Juan Carlos Vergara (February 17, 2009)

function checkSatisfactionForm()
{
   var why = "";
   why += checkStr("Name", document.forms["satisfactionfrm"].givenname);
   why += checkStr("Company Name", document.forms["satisfactionfrm"].company);
   why += checkEmail("Email Address", document.forms["satisfactionfrm"].email);
   why += checkRating("The ease of accessing EPSIIA Support?", document.forms["satisfactionfrm"].access);
   why += checkRating("The courtesy of the Technical Support Rep. who handled your call?", document.forms["satisfactionfrm"].courtesy);
   why += checkRating("The level of knowledge demonstrated by the Technical Support Rep. who handled your call?", document.forms["satisfactionfrm"].knowledge);
   why += checkRating("The Technical Support Rep's performance in keeping you informed of the status of your issue or ticket?", document.forms["satisfactionfrm"].speed);
   why += checkRating("Our performance in resolving general, non-critical support problems or issues?", document.forms["satisfactionfrm"].performance);
   why += checkRating("Our performance in resolving critical, production-impacting issues?", document.forms["satisfactionfrm"].escalate);
   why += checkRating("The frequency of our Account Manager's contact with you regarding new products or services?", document.forms["satisfactionfrm"].frequency);
   why += checkRating("The quality of our service compared to other vendors?", document.forms["satisfactionfrm"].quality);
   why += checkRating("Would you be a reference for EPSIIA?", document.forms["satisfactionfrm"].reference);
   
  if (why != "") {
      alert(why);
      return false;
   }

   return true;
}

function checkProductInfoForm()
{
   var why = "";
   why += checkStr("Name", document.forms["productinfofrm"].givenname);
   why += checkStr("Company Name", document.forms["productinfofrm"].company);
   why += checkStr("Industry", document.forms["productinfofrm"].industry);
   why += checkStr("Job Title", document.forms["productinfofrm"].jobtitle);
   why += checkEmail("Email Address", document.forms["productinfofrm"].email);
   why += checkSpecialInfo(document.forms["productinfofrm"].info);
   setBoxes(document.forms["productinfofrm"].infoval, document.forms["productinfofrm"].info);
   setBoxes(document.forms["productinfofrm"].productsval, document.forms["productinfofrm"].products);
   //setInfoOther(document.forms["productinfofrm"].infoval, document.forms["productinfofrm"].info_other);
  // alert(document.forms["productinfofrm"].infoval.value);
   
  if (why != "") {
      alert(why);
      return false;
   }

   return true;
}

function checkFeatureCustomerForm()
{
   var why = "";
   why += checkStr("Name", document.forms["featurecustomerfrm"].givenname);
   why += checkEmail("Email Address", document.forms["featurecustomerfrm"].email);
   why += checkStr("Product", document.forms["featurecustomerfrm"].product);
   why += checkStr("Feature Summary", document.forms["featurecustomerfrm"].feature);
   why += checkStr("Feature Details", document.forms["featurecustomerfrm"].details1);
   why += checkStr("Why is this feature important?", document.forms["featurecustomerfrm"].details2);
   why += checkStr("What is the root problem that you are trying to solve?", document.forms["featurecustomerfrm"].details3);
   why += checkStr("What are you (or users) currently doing to address this root problem?", document.forms["featurecustomerfrm"].details4);
   
  if (why != "") {
      alert(why);
      return false;
   }

   return true;
}

function checkFeatureForm()
{
   var why = "";
   why += checkStr("Name", document.forms["featurefrm"].givenname);
   why += checkEmail("Email Address", document.forms["featurefrm"].email);
   why += checkStr("Product", document.forms["featurefrm"].product);
   why += checkStr("Feature Summary", document.forms["featurefrm"].feature);
   why += checkStr("Feature Details", document.forms["featurefrm"].details1);
   why += checkStr("Why is this feature important?", document.forms["featurefrm"].details2);
   
  if (why != "") {
      alert(why);
      return false;
   }

   return true;
}

function checkProductBoxes(strng1, chkObject, chkObject2)
{
 var obj2val = null;
 for (var i=0; i<chkObject2.length; i++)
    {
      if (chkObject2[i].checked)
      {      
        obj2val = chkObject2[i].value;       
      }
  }
 
  var value = null;
 if(obj2val != "Request Epsiia Newsletter"){
 for (var i=0; i<chkObject.length; i++)
  {
    if (chkObject[i].checked)
    {      
      value="";
      break;
    }
  }
  
  if(value ==null)
  value = "Please select "+strng1+"\n";
  }
  else
  value="";
  
  return value;
}

function checkStr(strng1, tObject)
{
//alert(strng2);
   var error = "";
   var strng2 = tObject.value;
   if (strng2 == "") {
   error = "Please enter valid "+strng1+"\n";
   }
   return error;
}

function checkNum(strng1, tObject)
{
var error = "";
var strng = tObject.value;
var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
if(strng == ""){
   error = "Please enter valid "+strng1+"\n";
}
else {
if (isNaN(parseInt(stripped))) {
   error = "The phone number contains illegal characters.";
   }
}//else ends
return error;
}

function checkEmail(strng1, eObject)
{
  var error = ""; 
  var strng2 = eObject.value;
  if(strng2 == "")
    error = "Please enter valid "+strng1+"\n";
  else if(strng2.indexOf('@') == -1 || strng2.indexOf('.') == -1)
     {
     error = "Email Address is incorrect\n";
     eObject.value = "";
     eObject.focus();     
     }

   return error;
}

function getRadioValue(radioObject)
{
  var value = null
  for (var i=0; i<radioObject.length; i++)
  {
    if (radioObject[i].checked)
    {
      value = radioObject[i].value
      break
    }
  }
  return value
}

function checkRating(strng1, rObject)
{
  var error = ""; 
  var strng2 =  getRadioValue(rObject);
  if(strng2 == null)
    error = "Please select "+strng1+"\n";
  
   return error;
}

function checkBoxes(strng1, chkObject)
{
  var value = null;
  for (var i=0; i<chkObject.length; i++)
  {
    if (chkObject[i].checked)
    {      
      value="";
      break;
    }
  }
  
  if(value ==null)
  value = "Please select "+strng1+"\n";
  
  return value;
}


function checkGPD(var1, strng1, chkObject, emailObj, strng2)
{
  var value = "";
  
    if (chkObject[var1].checked)
    {
      if(emailObj.value == "")
      value = strng2+" is required for "+strng1+"\n";
    }
 
  
  return value;
}

function checkSpecialInfo(chkObject)
{
  var value = "";
  
    if (chkObject[1].checked)
    {
      if(document.forms["productinfofrm"].givenname.value == "" || document.forms["productinfofrm"].street.value == "" || document.forms["productinfofrm"].city.value == "" || document.forms["productinfofrm"].state.value == "" || document.forms["productinfofrm"].zip.value == "")
      value = "Name & Address is required for Sample eArchive CD Information\n";
    }
 
  
  return value;
}

function setBoxes(sObject, chkObject)
{
  var cvalue = "";
  for (var i=0; i<chkObject.length; i++)
  {
    if (chkObject[i].checked)
    { 
    if(cvalue != "")
      cvalue=cvalue+","+chkObject[i].value;
    else
     cvalue=chkObject[i].value;
    }
  }
   sObject.value = cvalue;
}

function setInfoOther(sObject, tObject)
{
if(tObject.value != "")
sObject.value = sObject.value+",Other - "+tObject.value;
}

