/*
#################################################################################################### 
# File Name: prescreener.js
# File Version: v 1.0
# Created By: Priji Rajendran
# Created On: 26 Feb 2008
# Last Modified By:
# Last modified On:
# This file handles the prescreener functions
#====================================================================================================\


#====================================================================================================
#  Function Name    :    showHideData()
#  Created By: Priji Rajendran
#  Created On: 7 Feb 2008
#  Last Modified By: 
#  Last modified On: 
#  Purpose : Shows and hides the zip,ethnicity and houisehold income field based on coiuntry and language
#  Parameters: optCountryId : country id
#----------------------------------------------------------------------------------------------------
*/

function showHideData(optCountryId)
{	
    var languageid=getCookie('LangID');
	var browser=navigator.appName;

	if(parseInt(optCountryId)==(document.getElementById('hdUnitedStatesCountryId').value) && languageid==(document.getElementById('hdEnglishLanguageId').value))
	 {
	   document.getElementById('zip_table').style.display="block";
	   document.getElementById('ethinicity_table').style.display="block";
	   document.getElementById('zip_table').style.visibility="visible";
	   document.getElementById('ethinicity_table').style.visibility="visible";
	   
	   if (browser=="Netscape")
	   {
		 document.getElementById('txtZipPostal').focus();
	   }	  
	 }
	 else if(parseInt(optCountryId)==(document.getElementById('hdCanadaCountryId').value) && languageid==(document.getElementById('hdEnglishLanguageId').value))
	 {
	   document.getElementById('zip_table').style.display="block";
	   document.getElementById('ethinicity_table').style.display="none";
	   document.getElementById('zip_table').style.visibility="visible";
	   document.getElementById('ethinicity_table').style.visibility="hidden";
	  
	   document.getElementById('optAnnualHouseholdIncomeId').selectedIndex=0;
	   document.getElementById('optEthnicityId').selectedIndex=0;
	   
	   if (browser=="Netscape")
	   {
		 document.getElementById('txtZipPostal').focus();
	   }  
	 }														  
	 else
	 {	 
	  document.getElementById('zip_table').style.display="none";
	  document.getElementById('ethinicity_table').style.display="none";
	  document.getElementById('zip_table').style.visibility="hidden";
	  document.getElementById('ethinicity_table').style.visibility="hidden";
	  
	  document.getElementById('txtZipPostal').value="";
	  document.getElementById('optAnnualHouseholdIncomeId').selectedIndex=0;
	  document.getElementById('optEthnicityId').selectedIndex=0;			  
	 }
	 
}
/*
#====================================================================================================
#  Function Name    :    getCookie()
#  Created By: Priji Rajendran
#  Created On: 7 Feb 2008
#  Last Modified By: 
#  Last modified On: 
#  Purpose :Returns a cookie value for a given cookie 
#  Parameters: c_name: cookie name
#----------------------------------------------------------------------------------------------------
*/
function getCookie(c_name)
{
 if (document.cookie.length>0)
 {
   c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
     c_start=c_start + c_name.length+1; 
     c_end=document.cookie.indexOf(";",c_start);
     if (c_end==-1) c_end=document.cookie.length;
     return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
  return "";
}
//====================================================================================================
//    Function Name    :    validatePin()
//    Created By: Priji Rajendran
//    Created On: 31 Jan 2008
//    Last Modified By:
//    Last modified On:
//  Purpose : Validates  5 digit pin code for United States
// parameters: element
//----------------------------------------------------------------------------------------------------

function validatePin()
{
    var countryvalue;
    var pin,k;
    countryvalue=document.forms[0].elements['optCountryId'].value;
    if(parseInt(countryvalue)==(document.getElementById('hdUnitedStatesCountryId').value))
	{
    
      pin=document.getElementById('txtZip').value;
      k=pin.match(/^\d\d\d\d\d$/);
       if(k!=undefined)
	   {
		    
       }
       else
	   {
       alert("Please enter 5 digit Zip code.");
       document.getElementById('txtZip').focus();
       return false
       
       }
      
    }
    return true;   
}
/*
#====================================================================================================
#  Function Name    :    checkPrescreener()
#  Created By: Priji Rajendran
#  Created On: 7 Feb 2008
#  Last Modified By: 
#  Last modified On: 
#  Purpose : Validate the prescreener form
#  Parameters: frm: form object
#----------------------------------------------------------------------------------------------------
*/
function checkPrescreener(frm)
{ 

  var languageid=getCookie('LangID');
    with(frm)
    {       
		
		if(optCountryId.value=="")
		{
			 alert('Please select country.');
			 optCountryId.focus();
			 return false;
		}	
			
		if(txtZipPostal.value=="")
		{
			if(optCountryId.value==(hdUnitedStatesCountryId.value) && languageid==(hdEnglishLanguageId.value))
			{
			  alert('Please enter valid zip code.');
		      txtZipPostal.focus();
			  return false;		
      		}	
			else if(optCountryId.value==(hdCanadaCountryId.value) && languageid==(hdEnglishLanguageId.value))
			{
				alert('Please enter valid zip code.');		
				txtZipPostal.focus();
				return false;
			}
		}
		
		if(optCountryId.value==(hdUnitedStatesCountryId.value) && languageid==(hdEnglishLanguageId.value))
		{
			 if(txtZipPostal.value!="")
			 {
			    if(txtZipPostal.value.length !=5)
			    {
				    alert('Please enter valid zip code.');
					txtZipPostal.focus();
					return false;
			    }
			   
				 for(i=0;i<txtZipPostal.value.length;i++)
				{
				   // Check that current character is number.
				  var c = txtZipPostal.value.charAt(i);
			 
				   if ((c < "0") || (c > "9"))
				  {
				   alert("Please enter valid zip code.");
				   txtZipPostal.focus();
				   return false;
				  }	
			
				}	
			   			   
			 }
			
		}//by ram
		else if(optCountryId.value==(hdCanadaCountryId.value) && languageid==(hdEnglishLanguageId.value))
		{
			if(txtZipPostal.value!="")
			 {			    
			   
			    if(!isProperCanadaZip(txtZipPostal.value))
				{
					alert('Please enter valid zip code.');
					txtZipPostal.focus();
					return false;
				}
				 
			   			   
			 }
		}//end by ram
		
		if(!IsEmpty(txtAge,'Please enter your age.'))
		{
		  txtAge.focus();
          return false;
        }
    if(!Isnumber(txtAge,'Please enter a valid age.'))
	{
      return false;
    }
    if(txtAge.value<13)
	{
        alert("Enter age between 13 and 100");
        txtAge.focus();
        return false;
    }
    if(txtAge.value>100)
	{
        alert("Enter age between 13 and 100");
        txtAge.focus();
        return false;
    }
		
	  var gender_radio_choice = false;
		for (counter = 0; counter < rdGender.length; counter++)
         {
           if (rdGender[counter].checked)
              gender_radio_choice = true; 
          }
		if(gender_radio_choice==false)
		{
			alert("Please select your gender.")
			return false;
		}
		if(optCountryId.value==(hdUnitedStatesCountryId.value) && languageid==(hdEnglishLanguageId.value))
		{
			if(optEthnicityId.value=="")
			{
				 alert('Please select your ethinicity.');
				 optEthnicityId.focus();
				 return false;
			}
		}
		
		if(optCountryId.value==(hdUnitedStatesCountryId.value) && languageid==(hdEnglishLanguageId.value))
		{
			if(optAnnualHouseholdIncomeId.value=="")
			{
				 alert('Please select your household income.');
				 optEthnicityId.focus();
				 return false;
			}
		}		
    	
	action = "prescreener_handler.php";	
	fnDisableButtonOnSubmit(frm); //disable button on submit
  }        
}
/*
#====================================================================================================
#  Function Name    :    setVisibility()
#  Created By: Priji Rajendran
#  Created On: 7 Feb 2008
#  Last Modified By: 
#  Last modified On: 
#  Purpose : Show or hides the element specified by id
#  Parameters: id= field id, visiblility =display/none
#----------------------------------------------------------------------------------------------------
*/

function setVisibility(id, visibility) 
{
      var x;
      x=document.getElementById(id);
      document.getElementById(id).style.display = visibility;
      try
	  {
       x.style.top = window.event.y + 10;
       x.style.left = window.event.x ;
      }
      catch(e)
	  {
    
      }
}
/*
#====================================================================================================
#  Function Name    :    restoreDayMonthYear()
#  Created By: Priji Rajendran
#  Created On: 7 Feb 2008
#  Last Modified By: 
#  Last modified On: 
#  Purpose : Restores the value of day month year if a country is US or Non Us
#           i.e sets the filed on appropriate value change
#  Parameters: countryType= US/NONUS
#----------------------------------------------------------------------------------------------------
*/
function restoreDayMonthYear(countryType)
{
	  
	  with(document.frmPrescreener)
	  {
		  if(countryType=="US")
		  {
			 optMonthIdnonus.value=optMonthId.value;
			 optDayIdnonus.value=optDayId.value;
			 optYearIdnonus.value=optYearId.value;			 
		  }
		  else
		  {
			 optMonthId.value=optMonthIdnonus.value;
			 optDayId.value=optDayIdnonus.value;
			 optYearId.value=optYearIdnonus.value;
		  }
	  }
}
/*
#====================================================================================================
#  Function Name    :    Click_Language()
#  Created By: Priji Rajendran
#  Created On: 7 Feb 2008
#  Last Modified By: 
#  Last modified On: 
#  Purpose : Submits the prescreener form on click of the language
#  Parameters:strLanguage=Language
#----------------------------------------------------------------------------------------------------
*/
function Click_Language(strLanguage)
{
      document.frmPrescreener.hdLanguageName.value = strLanguage;
      document.frmPrescreener.action ="";
	  fnDisableButtonOnSubmit(document.frmPrescreener); //disable button on submit	  
      document.frmPrescreener.submit();
}
/*
#====================================================================================================
#  Function Name    :    validate_email()
#  Created By: Priji Rajendran
#  Created On: 05 May 2008
#  Last Modified By: 
#  Last modified On: 
#  Purpose : Validates the email field;
#  Parameters:strLanguage=Language
#----------------------------------------------------------------------------------------------------
*/
function validate_email()
{
   var frm=document.frmEmailGet;
   with(frm)
   {
      if(!IsEmail(txtEmail,"Please enter valid email."))
          return false;
	  
	  fnDisableButtonOnSubmit(frm); //disable button on submit	  
    }
 }