//#########################################################################################################
//    # File Name: registration.js
//    # File Version: v 1.0
//    # Created By: Amit Sankhala
//    # Created On: 09 December 2008
//    # Last Modified By:
//    # Last modified On:
//#########################################################################################################

//==================================================================================================== 
//  Function Name : registrationStep1 
//	# Created By: Amit Sankhala
//	# Created On: 08 December 2008
//	Last Modified By:
//	Last modified On:
//  Purpose : validated affiliate program step1.
//---------------------------------------------------------------------------------------------------- 
function registrationStep1()
{
	//alert(frm);
	frm = document.forms[0];

	with(frm)
	{			
		if(!IsEmpty(txtEmail,"Please Enter Email Address"))
		{
			return false;
		}
		if(!IsEmail(txtEmail,'Please Enter Valid Email Address'))
		{
			return false;
		}
		for(i=0;i<rdnAffiliate.length;i++)
		{
			if(rdnAffiliate[i].checked)
			{
				rdnSelected = i+1;
				break;
			}
		}
		if(rdnSelected == '2')
		{
			action = 'registration_school.php';	
		}
		else
		{
			action = 'registration_standard.php';
		}
		
		submit();
	}
}
//==================================================================================================== 
//  Function Name : validate_registerS2 
//	# Created By: Amit Sankhala
//	# Created On: 08 December 2008
//	Last Modified By:
//	Last modified On:
//  Purpose : validated standard/contributor affiliate program registration step2.
//---------------------------------------------------------------------------------------------------- 
function validate_registerS2(frm)
{
	with(frm)
	{
		if(!IsEmpty(txtFirstName,"Please Enter First Name"))
		{
			return false;
		}
		if(!IsEmpty(txtLastName,"Please Enter Last Name"))
		{
			return false;
		}		
		if(!IsEmpty(txtEmail,"Please Enter Email Address"))
		{
			return false;
		}
		if(!IsEmail(txtEmail,"Please Enter Valid Email Address"))
		{
			return false;
		}
        
        //check whether email already exists or not.
        var url = 'ajax/emailExists.php?email='+txtEmail.value;
new Ajax.Request(url, {
  method: 'get',
  asynchronous: false,
  onSuccess: function(transport) {
  bEmailExists = transport.responseText;
  if(bEmailExists == 1)
  {             
     alert("Email Address Already Exists. Please Use Different Email Address");                
  }
  }
});
    if(bEmailExists == 1)
     {
        return false;
     }
        		
		if(!IsEmpty(txtCPhone,"Please Enter Contact Phone"))
		{
			return false;
		}
		regex = /^[0-9]{3}-[0-9]{3}-[0-9]{4}/;
		if(!regex.test(txtCPhone.value)) 
		{ 
			alert("Phone Number Should Be in ###-###-#### Format"); 
			txtCPhone.focus(); 
			return false; 
		}
		if(!IsEmpty(txtBName,"Please Enter Business Name"))
		{
			return false;
		}
		if(!IsEmpty(txtBAddress,"Please Enter Business Address"))
		{
			return false;
		}
		if(!IsEmpty(txtCity,"Please Enter City Of Business"))
		{
			return false;
		}
		if(!IsEmpty(cmbUSStates,"Please Select State Of Business"))
		{
			return false;
		}
		if(!IsEmpty(txtZip,"Please Enter Zip Of Business"))
		{
			return false;
		}
		if(!IsZip(txtZip, "ZipCode Should Be of 5 or 9 Numeric Digits"))
        {
            return false;
        }
		if(!IsEmpty(txtGenBIndustry,"Please Enter General Business Industry"))
		{
			return false;
		}
        if(!IsEmpty(txtTaxID,"Please Enter Tax ID"))
        {
            return false;
        }
        
        /*for(i=0;i<rdnAffiliateType.length;i++)
        {
            if(rdnAffiliateType[i].checked && rdnAffiliateType[i].value == 'contributor')
            {   
                bContributor = true;                
                break;
            }
        }*/
        bContributor = false;
        if(Trim(txtContributorCode.value) != '')
        {
            bContributor = true;
        }
        if(bContributor == true)
        {
		    if(!IsEmpty(txtContributorCode,"Please Enter Contributor's Code"))
		    {
			    return false;
		    }
            //check whether contributor is active contributor in CPU..
        var url = 'ajax/checkContributorExists.php?code='+txtContributorCode.value;
        new Ajax.Request(url, {
          method: 'get',
          asynchronous: false,
          onSuccess: function(transport) {
          bContributorExists = transport.responseText;
          if(Trim(bContributorExists) == '' || Trim(bContributorExists) == 1)
          {             
             alert("Contributor Code Does Not Exists in CPU. "+ "\n"+" Please Check Your My Account->Contributor Widget on CPU For Your Contributor Code.");                
          }
          }
        });	
        if(bContributorExists == 1)
        {
            return false;
        }
        }
		if(!IsEmpty(txtPassword,"Please Enter Password"))
		{
			return false;
		}
		if(!IsEmpty(txtCPassword,"Please Enter Confirm Password"))
		{
			return false;
		}
		if(!fnCompare(txtPassword,txtCPassword,"Password Confirmation Failed"))
		{
			return false;
		}
		if(!document.getElementById("chkPrivacy").checked)
		{
			alert("Plasee Accept Privacy Policy");
			return false;
		}
        
		action = 'process/registrationController.php?hdnAction=standard';
		submit();
	}
}
//==================================================================================================== 
//  Function Name : validate_registerSChool2 
//	# Created By: Amit Sankhala
//	# Created On: 08 December 2008
//	Last Modified By:
//	Last modified On:
//  Purpose : validated Schools for education relief affiliate program registration step2.
//---------------------------------------------------------------------------------------------------- 
function validate_registerSChool2(frm)
{
	with(frm)
	{
		if(!IsEmpty(txtHSchoolName,"Please Enter High School Name"))
		{
			return false;
		}
		if(!IsEmpty(txtSAddress,"Please Enter School Address"))
		{
			return false;
		}
		if(!IsEmpty(txtCity,"Please Enter City Of School"))
		{
			return false;
		}
		if(!IsEmpty(txtState,"Please Enter State Of School"))
		{
			return false;
		}
		if(!IsEmpty(txtZip,"Please Enter Zip Of School"))
		{
			return false;
		}
		
		if(!IsEmpty(txtEmail,"Please Enter Email Address"))
		{
			return false;
		}
		if(!IsEmail(txtEmail,"Please Enter Valid Email Address"))
		{
			return false;
		}
		if(!IsEmpty(txtFirstName,"Please Enter First Name"))
		{
			return false;
		}
		if(!IsEmpty(txtLastName,"Please Enter Last Name"))
		{
			return false;
		}
		if(!IsEmpty(txtPosHeld,"Please Enter Position Held in School"))
		{
			return false;
		}
		if(!IsEmpty(txtSNumber,"Please Enter School Number"))
		{
			return false;
		}
		if(!IsEmpty(txtPhone,"Please Enter Phone Number"))
		{
			return false;
		}
		regex = /^[0-9]{3}-[0-9]{3}-[0-9]{4}/;
		if(!regex.test(txtPhone.value)) 
		{ 
			alert("Phone Number Should Be in ###-###-#### Format"); 
			txtPhone.focus(); 
			return false; 
		}
			
		if(!IsEmpty(txtPassword,"Please Enter Password"))
		{
			return false;
		}
		if(!IsEmpty(txtCPassword,"Please Enter Confirm Password"))
		{
			return false;
		}
		if(!fnCompare(txtPassword,txtCPassword,"Password Confirmation Failed"))
		{
			return false;
		}
		if(!document.getElementById("chkPrivacy").checked)
		{
			alert("Plasee Accept Privacy Policy");
			return false;
		}
		action = 'thankyou.php';
		submit();
	}
}

//==================================================================================================== 
//  Function Name : fnEmailExists 
//    # Created By: Amit Sankhala
//    # Created On: 08 December 2008
//    Last Modified By:
//    Last modified On:
//  Purpose : check whether email already exists in the database or not.
//---------------------------------------------------------------------------------------------------- 
function fnEmailExists(strEmail)
{
      var url = 'ajax/emailExists.php?email='+strEmail;
new Ajax.Request(url, {
  method: 'get',
  onSuccess: function(transport) {
    return transport.responseText;    
  }
});
}
//==================================================================================================== 
//  Function Name : viewPrivacyPolicy 
//    # Created By: Amit Sankhala
//    # Created On: 06 January 2009
//    Last Modified By:
//    Last modified On:
//  Purpose : View Privacy Policy in the popup window.
//---------------------------------------------------------------------------------------------------- 
function viewPrivacyPolicy()
{
    window.open("viewPolicy.php","_blank","height=400, width=400, scrollbars=1, scrollbars=1, left=20px, top=50px, resizable = 1");
}