
/* This java script file is used for the registration process validation for the merchant. */
/* Modified By : Gajanan Late on 7/9/2004  */
/* 1) Password allows special characters  and no. of minimum characters have changed to 6. */
/* 2) Modified by Gajanan Late on 30/8/2004 for displaying promoters details & stake validation. */
/* 3) Modified By Gajanan Late on 2/9/2004 for implementing QA Guide Lines for form elements .*/ 
/* Validate all the form elements of the registration form 
    Modified By : Gajanan Late on 11/30/2004  for validating payto and owners fields.
	
	Modified By: Nikhil Sonurlekar. 
	Description : As per referer, URL field is optional. (Concerning www.exportavenue.com)
						Change in all alert messages.
	Date : 21-03-2005

@ Modified:		By Noor Shaikh on June-20-2007
@ Description:	Updated functions chkSpecialCharCustom(), chkSpecialChar() and chkSpecialChar2() to validate hazardous characters.

@ Modified:		By Noor Shaikh on August-10-2007
@ Description:  Added condition to check confirmation code entered is empty or not and also validated for special characters.
*/
function validate() {
		document.getElementById("CAPTID").src ="/servlet/ccw.CaptchaServlet1";

}
function valid(referer)
 {
	var text
	var formElementName
	var element
	var textBlank
				
	for( i = 0; i < document.mer_reg.elements.length; i++) // walk through all the form elements.
	{
		element = document.mer_reg.elements[i];
		formElementName = element.name;
		// Started By Noor. Validate Confirmation Code is blank or not
		if(formElementName =='capt')
			{
				text = "Confirmation Code";
				if(!chkBlank(element,text)) 
					return false;
				if(!chkSpecialCharCustom(element,text,'~!@#$%^&*=()+[]{}/|;:,<>.?')) 
					return false;
			}
		// Ended By Noor.
		// these are the form fields (text boxes) to be validated
		if(formElementName == 'name' || formElementName=='middle_name' ||formElementName== 'state1' ||formElementName == 'last_name' || formElementName == 'pay_to' || formElementName == 'city' || formElementName == 'zip'  || formElementName == 'address' || formElementName == 'ISDCode' || formElementName == 'STDCode' || formElementName == 'phone' || formElementName == 'email' || formElementName == 'url' || formElementName == 'bankName' ||  formElementName == 'accNo' ||  formElementName == 'branch'  ||  formElementName == 'owner_name'  ||  formElementName == 'owner_age'  ||  formElementName == 'owner_sex'  ||  formElementName == 'owner_edu'  ||  formElementName == 'owner_add'  ||  formElementName == 'owner_fin_stack'  ||  formElementName == 'about_com'  ||  formElementName == 'about_ser'  ||  formElementName == 'logPartner_detail'  || formElementName == 'uname'  || formElementName == 'pword'  || formElementName == 'pword1' || formElementName == 'secretAnswer'  )
		{
			//alert("Name: "+ formElementName+" number: "+i);
					
			if(formElementName == 'name')
			{   
				text = "First Name ";
				textBlank="First Name is missing.\nPlease enter your First Name in Contact Details section.";
				if(!chkSpecialChar2(element,text)) return false;
				if(!checkNumber(element,text)) return false;
			}
		   if(formElementName =='middle_name')
			{  
				text="Middle Name";
				textBlank="Middle Name is missing.\nPlease enter your Middle Name in Contact Details section.";
				if(element.value!='') {
					if(!chkSpecialCharCustom(element,text,'`~!#$%^&()[]{}|;,+<>?')) return false;
					if(!chkSpecialChar2(element,text)) return false;
					if(!checkNumber(element,text)) return false;
				}
				
			}
			
			var dotcount=0;
			var charEle;
			if(formElementName == 'url')
			{
				//alert("nikhil");
				
				text = "Website URL ";
				textBlank="Website URL is missing.\nPlease enter Website URL in Contact Details section.";
				if(element.value!='')
				{
					if(!chkSpecialCharCustom(element,text,'`~!#$%^&()[]{}|;,+<>?')) return false;
					for(var x=0; x<element.value.length; x++)
					{
						charEle = element.value.substring(x, x+1)
						if(charEle == '.')
						{
							dotcount++;
						}
					}
					if (dotcount < 2)
					{
						alert('Website URL is incorrect.\nPlease enter correct Website URL in Contact Details section.');
						element.focus();
						element.select();
						return false;
					}
					naString=element.value.substring(0,1);
					if(naString==' ' || naString=='.')
					{
					  alert("Website URL is incorrect.\nPlease enter correct Website URL in Contact Details section.");
					 element.focus();
					 element.select();
					 return false;
					}
				}

		}

			
		
		if(formElementName == 'last_name' )
			{
				text = "Last Name ";
				textBlank="Last Name is missing.\nPlease enter your Last Name in Contact Details section.";
				if(!chkSpecialChar2(element,text)) return false;
				if(!checkNumber(element,text)) return false;
			}
			
			if(formElementName == 'pay_to')
			{
				text = "Pay To name ";
			    textBlank="Pay To name is missing.\nPlease enter your Pay To name in Contact Details section.";
				//if(!chkSpecialChar2(element,text)) return false;
                if(!chkSpecialCharCustom(element,text,'`~!@#$%^+{}[]/|;:,<>?') ) return false;
			}
			
			/*if(formElementName == 'country' )
			{
				text = "Country ";
				textBlank="You have not selected Country Name.\nPlease select Country Name from Contact Details section..";
			}*/
						
			if(formElementName == 'state1')
			{
				text = "State";
			    textBlank="You have not entered State.\nPlease enter Name of State in Contact Details section.";
				if(!chkSpecialCharCustom(element,text,';/%') ) return false;
				if(element.value =='')
				{
					text="State";
					if(!chkSpecialChar2(element,text)) return false;
					if(!checkNumber(element,text)) return false;
				}
			}

			
			/*if(formElementName == 'branchCountry' )
			{
				text = "Bank branch country ";
				textBlank="You have not selected country for bank branch.\nPlease select Country of your Bank Branch in Bank Details section.";
			}*/
			
			
			if(formElementName == 'city' )
			{
				textBlank="You have not entered City.\nPlease enter Name of the City in Contact Details section.";
				text = "City";
				if(!chkSpecialChar2(element,text)) return false;
				if(!checkNumber(element,text)) return false;
			}
			var naString;

			if(formElementName == 'zip' )
			{
				
				/*text = "Zip ";
				naString=element.value.substring(0,2);
				if((naString=='NA') && (element.value.length>2))
				{
				  alert("Enter only 'NA' if your city does not  have PIN/ZIP code");
				  element.focus();
				  return false;
				}

				if(!chkSpecialCharCustom(element,text,'`~!@#$%^&()+[]{}/|;:,<>.?')) return false;*/
				/*textBlank="You have not entered Zip/Pin. Please enter Zip/Pin code";
				text = "zip";
				if(!chkSpecialChar2(element,text)) return false;
				if(!checkNumber(element,text)) return false;*/
				text = "ZIP/PIN";
				naString=element.value.substring(0,2);
				if(element.value == '')
				{
				  alert("ZIP/PIN is missing.\nPlease enter ZIP/PIN in Contact Details section, If your city does not have ZIP/PIN, enter NA.");
				  element.focus();
				  return false;
				}
				if( (naString=='NA') && (element.value.length>2))
				{
					alert("ZIP/PIN is incorrect.\nIf your city does not have ZIP/PIN, enter 'NA' only.");
					element.focus();
					element.select();
					return false;
				}
				if(!chkSpecialCharCustom(element,text,'`~!@#$%^&()+[]{}/|;:,<>.?')) return false;
			}

			if(formElementName == 'address' )
			{
				text = "Mailing Address ";
				textBlank="Mailing Address is missing.\nPlease enter Mailing Address in Contact Details section.";
				if(!chkSpecialCharCustom(element,text,';%')) return false; // added by noor
			}
			if(formElementName == 'phone')
			{
				text = "Phone";
				textBlank="Phone Number is missing.\nPlease enter Phone Number in Contact Details section.";
				if(!chkSpecialCharCustom(element,text,';%/')) return false; // added by noor
			}
			if(formElementName == 'ISDCode')
			{
				text = "Country Code";
				textBlank="Country Code is missing.\nPlease enter Country Code in Contact Details section.";
				if(!chkSpecialCharCustom(element,text,';%/')) return false; // added by noor
			}
			if(formElementName == 'STDCode')
			{
				text = "Area Code"; 
				textBlank="Area Code is missing.\nPlease enter Area Code in Contact Details section. If your City does not have Area Code, Enter 0.";
				if(!chkSpecialCharCustom(element,text,';%/')) return false; // added by noor
			}
			
			if(formElementName == 'email')
			{
				
				text = "Email Address ";
				textBlank=" Email Address is missing.\n Please enter Email Address in Contact Details section.";
				if(element.value != "")
				{
					if(!chkEmail(element,text)) return false;
					if(!chkSpecialCharCustom(element,text,'`~!#$%^&()[]{}/|;:,+<>?'))return false;
						
						if(element.value.indexOf("_") == 0)
						{
							alert('Email address you have provided is not correct.\nPlease ensure that email address is in proper format like myname@myaddress.com.');
							element.focus();
							return false;
						}
				}
			
			}
		
			/*

			*/
		    if(formElementName == 'owner_name')
			{   
				text = "Promoter's Name ";
				textBlank="Promoter's Name is missing.\nPlease enter Promoters' Name in Owners/Promoters section.";
				if(!chkSpecialCharCustom(element,text,'`~!@#$%^&+-{}[]()/|;:,<>?') ) return false;
				if(!checkNumber(element,text)) return false;
			} 

			if(formElementName == 'owner_age')
			{
				
				text = "Promoter's Age ";
				textBlank="Promoter's Age is missing.\nPlease enter Promoters' Age in Owners/Promoters section.";
				if(!chkSpecialChar(element,text)) return false;
				
				if(element.value==0 || element.value=='')
				{
					alert("Promoter's Age is missing.\nPlease enter Promoter's Age in Owners/Promoters section.");
					element.focus();
					return false;
				 }
				 if(isNaN(element.value))
				{
					alert("Promoter's Age is incorrect.\nPlease enter numeric value for Promoter's Age in Owners/Promoters section.");
					element.focus();
					return false;
				 }
			}
		
			if(formElementName == 'owner_add' )
			{
				textBlank="Promoter's Address is missing.\nPlease enter Promoter's Address in Owners/Promoters section.";
				text = "Promoters Address ";

				if(!chkSpecialCharCustom(element,text,";%#&")) return false; // added by noor
				//if(!chkSpecialChar(element,text)) return false;
			}

			if(formElementName == 'owner_edu')
			{
				text = "Promoters' Educational Qualification ";
				textBlank="Promoter's Educational Qualification is missing.\nPlease enter Promoter's Educational Qualification in Owners/Promoters section.";
				if(!chkSpecialCharCustom(element,text,"#&;%/")) return false; // added by noor
				//if(!chkSpecialChar(element,text)) return false;
			} 
			
			//=========Added by Noor===========================//

			if(formElementName == 'vc_detail')
			{
				text = " Angel / VC funding details ";
				if(!chkSpecialCharCustom(element,text,";%")) 
					return false; 
			} 

			//========Ended by Noor=============================//
			
			if(formElementName == 'owner_fin_stack')
			{
				if(element.value==''){
				text = "Promoters' Financial Stake ";
				textBlank="Promoter's Financial Stake is missing.\nPlease enter Promoter's Financial Stake in Owners/Promoters section.";
				//if(!chkSpecialChar(element,text)) return false;
				}
			}   
			
	
			
	
			if(formElementName == 'pword') 
			{
				text = "Password ";
				textBlank="Password is missing.\nPlease enter password in Login Details section.";
			//	if(!chkSpecialChar(element,text)) return false;
				if(element.value != '' && element.value.length < 6) 
				{
					//alert("Password cannot be less than 6 characters");
				    alert('Password can not be less than 6 characters.\nPlease ensure that length of password is minimum 6 characters.');
					element.focus();
					return false;
				}

				if(element.value ==document.mer_reg.uname.value ||  element.value==document.mer_reg.last_name.value)
				{
					alert("Password is incorrect.\nPlease ensure that Password is not same as User Name or Last Name.");
					element.focus();
					return false;
				}

			}

			if(formElementName == 'uname') 
			{
				text = "User Name ";
				textBlank="User Name is missing.\nPlease enter User Name in Login Details section.";
				if(!chkSpecialCharCustom(element,text,"`~!@#$%^&()+-[]{}/|;:,<>.?'\"")) return false;
				if(element.value != '' && element.value.length < 6)
				{
					//alert("User name cannot be less than 6 characters");
					alert('User name can not be less than 6 characters. Please try again!');
					element.focus();
					return false;
				}
			}

			if(formElementName == 'bankName' )	
			{
				text = "Bank Name ";
				textBlank="Bank Name is missing.\nPlease enter Bank Name in Bank Details section.";
				if(!chkSpecialCharCustom(element,text,';%/')) return false; // added by noor
			}
				
			if(formElementName == 'accNo')
			{	
				textBlank="Account Number is missing.\nPlease enter Account Number in Bank Details section.";
				text = "Account Number "; 
				if(!chkSpecialCharCustom(element,text,';%/')) return false; // added by noor
			}

			if(formElementName == 'branch' ) 
			{
				text = "Branch Name ";
				textBlank="Branch Name is missing.\nPlease enter Branch Name in Bank Details section.";
				if(!chkSpecialCharCustom(element,text,';%/')) return false; // added by noor
			}

			if(formElementName == 'bankzip' ) 
			{
				text = "Bank Zip";
				//textBlank="Branch Name is missing.\nPlease enter Branch Name in Bank Details section.";
				if(!chkSpecialCharCustom(element,text,';%/')) return false; // added by noor
			} 

			if(formElementName == 'about_com'  )
			{
				text = "Company / Site description ";
				textBlank="Company / Site description is missing.\nPlease enter Company / Site description in Brief Description section.";
				if(!chkSpecialCharCustom(element,text,';%')) return false; // added by noor
			}
			if(formElementName == 'about_ser') 
			{
				text = "Product / Services description ";
				textBlank="Product / Services description is missing.\nPlease enter Product / Services description in Brief Description section.";
				if(!chkSpecialCharCustom(element,text,';%')) return false; // added by noor
			}
			if(formElementName=='minTransAmount')
			{
				textBlank="Please enter minimum transaction amount";
			}	
			if(formElementName=='AvgTransAmount')
			{
				textBlank="Please enter average transaction amount";
			}	
			if(formElementName=='noOfTransPerMonth')
			{
				textBlank="Please enter total no of transactions per month";
			}	
			if(formElementName == 'secretAnswer') 
			{
				text = "Secret Answer"; 
				textBlank="Secret Answer is missing.\nPlease enter Secret Answer in Login Details section.";
				if(!chkSpecialCharCustom(element,text,';%/')) return false; // added by noor
				if(element.value==document.mer_reg.pword.value)
				{
					alert("Secret Answer is incorrect.\nPlease ensure that it is not same as Password.");
					element.focus();
					return false;
				}
			}
			if(formElementName == 'logPartner_detail' ) 
			{
				text = "Logistics Partner details ";
				textBlank="Logistics Partner details are missing.\nPlease enter Logistics Partner details in Brief Description section.";
				if(!chkSpecialCharCustom(element,text,';%')) return false; // added by noor
			}
				
			if(formElementName == 'uname'  ) 
			{
				//text = "Login Name "; 
				textBlank="User Name is missing.\nPlease enter User Name in Login Details section.";
			}
				
			if(formElementName == 'pword1' )
			{
				//text = "Confirm Password";
				textBlank="You have not re-entered the Password.\nPlease re-enter the Password in Login Details Section.";
			}
			if(formElementName == 'pword1' )	
			{
				if(element.value !="")
				{
					if(element.value != document.mer_reg.elements[i-1].value)
					{
						alert("Password does not match.\nPlease re-enter the password in Login Details Section.");
						element.focus();
						element.select();
						return false;
					}
				}
			}

			// If referer is exportavenue then make url as optional. 
			if(referer=='yes') {
				//alert("referer");
				if(formElementName !='middle_name' && formElementName != 'state1' && formElementName !='url')
				{   
					//alert("referer in ");
					if(!chkBlankCustom(element,textBlank)) return false;
				}
			}
			else if(referer!='yes')
			{
				//alert("no referer ppppp");
				if(formElementName !='middle_name' && formElementName != 'state1')
				{   
					if(!chkBlankCustom(element,textBlank)) return false;
				}
			   
			}
		
		}

			
		// Validation for the select form elements.
		if(formElementName == 'sel_status' || formElementName == 'acct_type' || formElementName == 'accType' || formElementName == 'mode' || formElementName == 'owner_sex' || formElementName == 'secretQuestion' || formElementName == 'country' || formElementName == 'branchCountry' )
		{
			if(formElementName == 'sel_status') text = "You have not selected Business Filling Status.\nPlease select Business Filling status from Contact Details section.";
			if(formElementName == 'acct_type') text = "You have not selected Account Type.\nPlease select Account Type from Bank Details section."; 
			if(formElementName == 'accType') text = "You have not selected Account Type.\nPlease select Account Type from Bank Details section."; 
			if(formElementName == 'mode') text = "You have not selected Mode of Operation.\nPlease select Mode of Operation from Bank Details section."; 
			if(formElementName == 'owner_sex') text = "You have not selected Promoters' gender.\nPlease select Promoters' gender from Owners/Promoters section.";
			if(formElementName == 'secretQuestion') text = "You have not selected Secret Question.\nPlease select the Secret Question from Login Details section."; 
			if(formElementName == 'country' ) text="You have not selected Country.\nPlease select Country from Contact Details section.";
			if(formElementName == 'branchCountry' ) text="You have not selected Country for Bank Branch.\nPlease select Country of your Bank Branch in Bank Details section.";
			
			if(element[element.selectedIndex].value == "sel")
			{
				alert(text);
				element.focus();
				return false;
			}
			if(element[element.selectedIndex].value == "")
			{
				alert(text);
				element.focus();
				return false;
			}
		}

		// special validation for toll number
		if (formElementName == 'TollPhone')
		{
			text = 'Toll Free / Residence No';
			if(!chkSpecialCharCustom(element,text,'`~!@#$%^&+[]{}/|;:,<>.?')) return false;
		} 


		// validation for numeric text fields
		if(formElementName == 'ISDCode' || formElementName == 'STDCode' || formElementName == 'phone'  || formElementName == 'MobilePhone' || formElementName == 'fax_no' || formElementName == 'owner_fin_stack' || formElementName == 'owner_age' || formElementName == 'countryCode' || formElementName == 'ISDCodeFax' || formElementName == 'STDCodeFax')
		{
			if(element.value != '')
			{
				var alertText;
				if(formElementName == 'ISDCode')
				{
					alertText = 'Country Code';
					if(!chkSpecialCharCustom(element,text,'`~!@#$%^&()-[]{}/|;:,<>.?'))return false;
					if(!checkforNumber(element,alertText)) return false;

					
				}

				if(formElementName == 'STDCode')
				{
					alertText = 'Area Code';
					if(!chkSpecialCharCustom(element,text,'`~!@#$%^&+-[]{}/|;:,<>.?')) return false;
					if(!checkforNumber(element,alertText)) return false;
				}

				if(formElementName == 'phone')
				{
					alertText = 'Phone Number';
					if(!chkSpecialCharCustom(element,alertText,'`~!@#$%^&()+[]{}/|;:,<>.?')) return false;
					if(!checkforNumber(element,alertText)) return false;

				}
				
				if(formElementName == 'MobilePhone')
				{
					 alertText = 'Mobile Phone Number';
					 if(document.mer_reg.countryCode.value != "")
					 {
						if(!chkSpecialCharCustom(document.mer_reg.countryCode,'Country Code','`~!@#$%^&()[]{}/|;:,<>.?')) return false;
						if(!checkforNumber(document.mer_reg.countryCode,'Country Code')) return false;

					 }
					else
					{	
						alert("Country Code for Mobile Number is missing.\nPlease Enter Country for Mobile Number in Contact Details section.");
						document.mer_reg.countryCode.focus();
						return false;
					}
					
					if(element.value !='')
					{
					 
					 if(!chkSpecialChar(element,alertText)) return false;
					 if(!checkforNumber(element,alertText)) return false; 
                    
					}
					else
					{
						alert('Mobile Number is missing.\nEnter valid Mobile Number in Contact Details section.');
						element.focus();
						return false;
					}
					alertText = 'Mobile Phone Number';

				}
				
				if(formElementName == 'ISDCodeFax')
				{
				    alertText = 'Country code of Fax Number';
					if(!chkSpecialCharCustom(element,text,'`~!@#$%^&()-[]{}/|;:,<>.?'))return false;
					if(!checkforNumber(element,alertText)) return false;
					 if(document.mer_reg.STDCodeFax.value=='')
					{
						alert("Area Code for Fax Number is missing.\nPlease enter Area Code for fax Number in Contact Details section.");
						document.mer_reg.STDCodeFax.focus();
						return false;
					}
					else if(document.mer_reg.fax_no.value == '')
					{
						alert("Fax Number is missing.\nPlease enter complete Fax Number in Contact Details section.");
						document.mer_reg.fax_no.focus();
						return false;
					}
					
					
				}

				if(formElementName == 'STDCodeFax')
				{
					alertText = 'Area code of Fax Number';
					if(!chkSpecialCharCustom(element,text,'`~!@#$%^&+-[]{}/|;:,<>.?')) return false;
					if(!checkforNumber(element,alertText)) return false;

					if(document.mer_reg.ISDCodeFax.value == '')
					{
						alert("Country Code for fax number is missing.\n Please enter Country Code for fax Number in Contact Details section.");
						document.mer_reg.ISDCodeFax.focus();
						return false;
					}
					else if(document.mer_reg.fax_no.value=='')
					{
						alert("Fax number is missing.\nPlease enter complete Fax number in Contact Details section.");
						document.mer_reg.fax_no.focus();
						return false;
					}
					
				}

				if(formElementName == 'fax_no')
				{
					alertText = 'Fax Number';
					
					if(!chkSpecialCharCustom(element,alertText,'`~!@#$%^&()+[]{}/|;:,<>.?')) return false;
					if(!checkforNumber(element,alertText)) return false;

					if(document.mer_reg.ISDCodeFax.value == '')
					{
						alert("Country Code for Fax Number is missing.\nPlease enter Country Code for Fax Number in Contact Details section");
						document.mer_reg.ISDCodeFax.focus();
						return false;
					}
					else if(document.mer_reg.STDCodeFax.value=='')
					{
						alert("Area Code for Fax Number is missing.\nPlease enter Area Code for Fax Number in Contact Details section");
						document.mer_reg.STDCodeFax.focus();
						return false;
					}
					
				}
				
				
				if(formElementName == 'owner_fin_stack')
				{
					var totalStake;
					var childStakeVal;
					var exponent;
					var  dotIndex;

					childStakeVal = document.mer_reg.totalStake.value;
					var newParentStake=element.value;
				

					if (childStakeVal != '')
					{
						childStakeVal = parseFloat(document.mer_reg.totalStake.value);
					}
					else
					{
						childStakeVal =  0;
					}
                  
				   
					if(isNaN(newParentStake))
						{  
							alert('Financial stake value is incorrect.\nPlease enter a valid numeric value for financial stake.');
							element.focus();
            				return false;
            			}
				
				   for(var s=0; s<newParentStake.length;s++)
						{
							 exponent=newParentStake.charAt(s);
							
							if(exponent=='e' || exponent=='E')
							{
								alert('You have entered Exponent value.\nPlease enter a numeric value for financial stake.');
								element.focus();
								return false;
								
							}
						} 
				    dotIndex=newParentStake.indexOf(".");
					if(dotIndex !=-1)
					{
						var newString=newParentStake.substring(dotIndex+1,newParentStake.length);
						
						if(newString.length>2)
						{
							alert('Financial Stake is incorrect.\nPlease enter two decimal places for Financial Stake.');
							element.focus();
							return false;
						}
					}  
					totalStake = parseFloat(element.value) + childStakeVal;
					if(totalStake > 100)
					{
						alert("Total Financial Stake cannot be greater than 100 %");
						element.focus();
						return false;
					}
					alertText = 'Financial Stake';
				}
				
			   if(formElementName == 'owner_age')
				{
					alertText = 'Owner/Promoters\' age';
				}
				if(formElementName == 'countryCode')
				{
					if(document.mer_reg.MobilePhone.value == "")
					{
						alert("Mobile Number is missing.\nPlease enter a valid Mobile Number in Contact Details section.");
						document.mer_reg.MobilePhone.focus();
						return false;
					}
					alertText = 'Country Code';
				}

			 }
		}


   //added  for validation of Business Clauses ...........   on 9/14/2004
	if(formElementName=='ck1')
	{
		if(element.checked==false)
		{
			alert( "You have not confirmed your acceptance of CCAvenue's Terms of Service and Operating Rules and Regulations.\nYou must review and agree to CCAvenue's Terms of Service and Operating Rules and Regulations to proceed with your registration.");
			element.focus();
			return false;
		}
	}

	if(formElementName=='ck2')
	{
		if(element.checked==false)
		{
			alert( "You have not confirmed that the merchandise/services offered by you conform to CCAvenue's list of non-acceptable Products. \nTo be able to proceed with your registration, your products and/or services must conform to CCAvenue's list of non-acceptable Products.");
			element.focus();
			return false;
		}
	}

  if(formElementName=='ck3')
	{
		if(element.checked==false)
		{	
			alert("You have not agreed to maintain a minimum balance of"+" "+ document.mer_reg.mbal.value+" "+"in your CCAvenue account nor have you agreed to the CCAvenue Rolling Reserve of"+" "+document.mer_reg.rres.value+"% to be retained from the weekly payout for a period of 180 days.\nYou must agree to the maintenance of the minimum balance and the Rolling Reserve to proceed with your registration.");
			element.focus();
			return false;
		}
	}



	} //Loop ends here.
	// special validation for the state
	//alert(document.mer_reg.state[document.mer_reg.state.selectedIndex].value);
	
	if(document.mer_reg.state.length == 1)
	{  
		if(document.mer_reg.state1.value == '')
		{     
			alert("Name of the State is missing.\nPlease Enter valid State Name in Contact Details section.");
	 		document.mer_reg.state1.focus();
			return false;
		}
	}
	else 
	if(document.mer_reg.state.options.length > 1)	
	{
		if((document.mer_reg.state.options.selectedIndex < 1) || (document.mer_reg.state[document.mer_reg.state.selectedIndex].value == ''))
		{
			alert("You have not selected the State name.\nPlease Select a State name from Contact Details section.");
			document.mer_reg.state.focus();
			return false;
		}
	}

    // validating url
	
		if(document.mer_reg.url.value != '')
		{
			var val = document.mer_reg.url.value;
			var urllen = val.length;			
			var dotcnt,spacecnt, i;
			cnt = spacecnt = 0;
			for(i=0; i < urllen; i++)
			{

				var ch = val.substring(i,i+1);
				if(ch == ' ' )
					spacecnt++;
				if(ch == '.' )
					cnt = cnt + 1;
			}
			if(cnt < 2 || spacecnt > 0)
			{
				alert("Website URL is incorrect.\nPlease enter correct URL in Contact Details section.");
				document.mer_reg.url.focus();
				return false;
			}
		}
			if(document.mer_reg.bankzip.value !='')
			{
				text = "BankZip";
				if(!chkSpecialCharCustom(document.mer_reg.bankzip,text,'`~!@#$%^&()+[]{}/|;:,<>.?')) return false;
			}
			if(document.mer_reg.middle_name.value !='')
			{
				text = "Middle Name";
				if(!chkSpecialCharCustom(document.mer_reg.middle_name,text,'`~!@#$%^&()+[]{}/|;:,<>.?')) return false;
			}
	
		// validation for total finantial stake.... shd be less than 100 %
		//what('/content/approvalprocess.htm','500');		
  	document.mer_reg.action="/servlet/ccw.ma.RegisterMerchant?referer="+referer+"";
}

function openWindow1() {
	sealWin=window.open("/content/whatnext.jsp","win1",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=450,height=540');
		self.name = "mainWin1"; 
}

/* Pops up promoter details form where the merchant can fill up promoters. */
function popPromoterForm(val,promoDetails,ownerName,ownerAge,ownerSex,ownerEdu,ownerAdd,referer)
{  
	
	var promDetails = promoDetails;
	var re = new RegExp ('#', 'gi') ;
	promDetails = promDetails.replace(re, '|') ;
	re = new RegExp ('&', 'gi') ;
	promDetails = promDetails.replace(re, '*') ;
	promoWin = window.open("/MA/reg/add_promoters.jsp?val="+val+"&promoDetails="+promDetails+"&ownerName="+ownerName+"&ownerAge="+ownerAge+"&ownerSex="+ownerSex+"&ownerEdu="+ownerEdu+"&ownerAdd="+ownerAdd+"&referer="+referer,"win1",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=550,height=460');
	
} 
          
/* pops up window with information about account type like economy or premium.*/
function what(url, ht)
{
	postwindow = window.open(url,"win1",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=450,height='+ht);
	self.name = "mainWin"; 
	window.status="done";
}


/**/
function changeOption(formElement)
	{
		//alert(formElement);
		var name = formElement.name;
		if(name=="payOption" || name=="bankName" || name=="branch" || name=="number" || name=="dd" || name=="mm" || name=="yy")
		{
				formElement.form.PaymentOption[0].checked=true;
		}
		
		if(name == "ChequeDeposit" || name == "ChequeNO" || name == "branchName" || name == "draweeBankName" || name == "draweeBranchName")
		{
				formElement.form.PaymentOption[1].checked=true;
				formElement.form.payOption[0].checked = false;
//				formElement.form.payOption[].checked = false;
		}

		if(name == "FundsTransfer" || name == "AccountNO" )
		{
				formElement.form.PaymentOption[2].checked=true;
				formElement.form.payOption[0].checked = false;
				formElement.form.payOption[1].checked = false;

		}
	}

	function validatePayForm()
	{
		
		if(document.payForm.PaymentOption[0].checked==true)
		{
			if(document.payForm.payOption[0].checked==false && document.payForm.payOption[1].checked==false)
			{
				alert("Payment Type is not selected.\nPlease select the Correct Payment Type(cheque / DD)");
				document.payForm.payOption[0].focus();
				return false;
			}
			if(document.payForm.bankName.value=="")
			{
				alert("Bank Name is missing.\nPlease enter the Bank Name.");
				document.payForm.bankName.focus();
				return false;
			}
			if(document.payForm.branch.value=="")
			{
				alert("Branch Name is missing.\nPlease enter the Branch Name.");
				document.payForm.branch.focus();
				return false;
			}
			if(document.payForm.number.value=="")
			{
				alert("Cheque Number is missing.\nPlease enter the Cheque Number");
				document.payForm.number.focus();
				return false;
			}
			if(document.payForm.dd.value=="0" || document.payForm.mm.value=="0" || document.payForm.yy.value =="-1")
			{
				
				alert("Date is incorrect.\nPlease enter proper Date");
				document.payForm.dd.focus();
				return false;
			}
		}
		if(document.payForm.PaymentOption[1].checked==true)
		{
			if(document.payForm.ChequeDeposit.value=="")
			{
				alert("CCAvenue Bank Option is not selected.\nPlease select CCAvenue Bank Option, where you intend to deposit the cheque.");
				document.payForm.ChequeDeposit.focus();
				return false;
			}
			if(document.payForm.branchName.value=="")
			{
				alert("Branch Name is not selected.\nPlease select Branch Name where you have deposited the cheque.");
				document.payForm.branchName.focus();
				return false;
			}
			if(document.payForm.ChequeNO.value=="")
			{
				alert("Cheque Number is missing.\nPlease enter cheque number.");
				document.payForm.ChequeNO.focus();
				return false;
			}
			if(document.payForm.draweeBankName.value=="")
			{
				alert("Bank Name is missing.\nPlease enter the bank name on which a cheque is drawn.");
				document.payForm.draweeBankName.focus();
				return false;
			}
			if(document.payForm.draweeBranchName.value=="")
			{
				alert("Bank Branch Name is missing.\nPlease enter the Bank Branch Name on which a cheque is drawn.");
				document.payForm.draweeBranchName.focus();
				return false;
			}
		}
		if(document.payForm.PaymentOption[2].checked==true)
		{
			if(document.payForm.FundsTransfer.value=="")
			{
				alert("CCAvenue Bank Account is not selected.\nPlease select the CCAvenue bank account where you intend to make funds transfer.");
				document.payForm.FundsTransfer.focus();
				return false;
			}
			if(document.payForm.AccountNO.value=="")
			{
				alert("Account Number1 is missing.\nPlease enter your account number1.");
				document.payForm.AccountNO.focus();
				return false;
			}
		}
		return true;
	}
             

function setPromoters(){
		

		var promoDetails = "";
		var status = "";
		var totalStake;
		var stackMainProm=0;
		var textPromo="";
		var txt="";
		totalStake = parseFloat(document.promoForm.parentVal.value);
		
		for(i=1; i < 6; i++){
			var ownerName = eval("document.promoForm.owner_name"+i);
			var ownerAge = eval("document.promoForm.owner_age"+i);
			var ownerSex = eval("document.promoForm.owner_sex"+i);
			var ownerEdu = eval("document.promoForm.owner_edu"+i);
			var ownerAdd = eval("document.promoForm.owner_add"+i);
			var ownerFinStack = eval("document.promoForm.owner_fin_stack"+i);
			var sexVal = ownerSex.options[ownerSex.options.selectedIndex].value;

			if(ownerFinStack.value != '')
			{
				totalStake = totalStake + parseFloat(ownerFinStack.value);
				stackMainProm=stackMainProm+parseFloat(ownerFinStack.value);
			}
			//added by Gajanan on 9/3/2004  
			
			if(ownerName.value != "")
			{ 
				 textPromo="Promoter's Name";
				if(!chkSpecialChar2(ownerName,textPromo)) return false; 
				if(!checkNumber(ownerName,textPromo)) return false;		
				 
				 if(ownerAge.value == "")
				 {
					 alert("Promoter's Age is missing.\nPlease enter Promoter's Age.");
					 ownerAge.focus();
					 return false;
				 }
				 
				 if(sexVal=="sel")
				 {
					 alert("You have not selected promoter's gender.\nPlease select promoter's gender.");
					 ownerSex.focus();
					 return false;
				 }
				 if(ownerEdu.value=="")
				 {
					 alert("Promoter's Educational Qualification is missing.\nPlease enter Promoter's Educational Qualification.");
					 ownerEdu.focus();
					 return false;
				 }
				 
				  if(ownerAdd.value=="")
				 {
					 alert("Promoter's Residential Address is missing.\nPlease enter Promoter's Residential Address.");
					 ownerAdd.focus();
					 return false;
				 } 
				 
				 if(ownerFinStack.value=="")
				 {
					 alert("Promoter's Financial Stake is missing.\nPlease enter Promoter's Financial Stake.");
					 ownerFinStack.focus();
					 return false;
				 } 
					
		    }

			if(ownerAge.value != "")
			{ 
				if(ownerName.value == "")
				 {
					 alert("Promoter's Name is missing.\nPlease enter Promoter's Name.");
					 ownerName.focus();
					 return false;
				 }
				 
				 if(sexVal=="sel")
				 {
					 alert("You have not selected Promoter's Gender.\nPlease select Promoter's Gender.");
					 ownerSex.focus();
					 return false;
				 }
				 if(ownerEdu.value=="")
				 {
					 alert("Promoter's Educational Qualification is missing.\nPlease enter Promoter's Educational Qualification.");
					 ownerEdu.focus();
					 return false;
				 }
				 
				  if(ownerAdd.value=="")
				 {
					 alert("Promoter's Residential Address is missing.\nPlease enter Promoter's Residential Address.");
					 ownerAdd.focus();
					 return false;
				 } 
				 
				 if(ownerFinStack.value=="")
				 {
					 alert("Promoter's Financial Stake is missing.\nPlease enter Promoter's Financial Stake.");
					 ownerFinStack.focus();
					 return false;
				 } 
					
		    }
			
				if(sexVal == "M" || sexVal =="F")
			    { 
				if(ownerName.value == "")
				 {
					 alert("Promoter's Name is missing.\nPlease enter Promoter's Name");
					 ownerName.focus();
					 return false;
				 }
				 
				 if(ownerAge.value =="")
				 {
					 alert("Promoter's Age is missing.\nPlease enter Promoter's Age.");
					 ownerAge.focus();
					 return false;
				 }
				 if(ownerEdu.value=="")
				 {
					 alert("Promoter's Educational Qualification is missing.\nPlease enter Promoter's Educational Qualification.");
					 ownerEdu.focus();
					 return false;
				 }
				 
				  if(ownerAdd.value=="")
				 {
					 alert("Promoter's Residential Address is missing.\nPlease enter Promoter's Residential Address.");
					 ownerAdd.focus();
					 return false;
				 } 
				 
				 if(ownerFinStack.value=="")
				 {
					 alert("Promoter's Financial Stake is missing.\nPlease enter Promoter's Financial Stake.");
					 ownerFinStack.focus();
					 return false;
				 } 
					
		    }	

			if(ownerEdu.value !="")
			{ 
				if(ownerName.value == "")
				 {
					 alert("Promoter's Name is missing.\nPlease enter Promoter's  Name.");
					 ownerName.focus();
					 return false;
				 }
				 
				 if(ownerAge.value =="")
				 {
					 alert("Promoter's Age is missing.\nPlease enter Promoter's Age.");
					 ownerAge.focus();
					 return false;
				 }
				if(sexVal.value =="sel")
				{
					 alert("Promoter's gender is not selected.\nPlease select Promoters gender.");
					 ownerAdd.focus();
					 return false;
				 } 
				 
				 if(ownerAdd.value=="")
				 {
					 alert("Promoter's Residential Address is missing.\nPlease enter Promoter's Residential Address.");
					 ownerAdd.focus();
					 return false;
				 }
		
				 if(ownerFinStack.value=="")
				 {
					 alert("Promoter's Financial Stake is missing.\nPlease enter Promoter's Financial Stake.");
					 ownerFinStack.focus();
					 return false;
				 } 
					
		    }	
				
			
			if(ownerFinStack.value !="")
			{ 
				if(ownerName.value == "")
				 {
					 alert("Promoter's Name is missing.\nPlease enter Promoter's Name.");
					 ownerName.focus();
					 return false;
				 }
				 
				 if(ownerAge.value =="")
				 {
					 alert("Promoter's Age is missing.\nPlease enter Promoter's Age.");
					 ownerAge.focus();
					 return false;
				 }
				if(sexVal.value =="sel")
				{
					alert("Promoter's Gender is not selected.\nPlease select Promoters Gender.");
					 ownerAdd.focus();
					 return false;
				 } 
				 
				 if(ownerEdu.value=="")
				 {
					 alert("Promoter's Educational Qualification is missing.\nPlease enter Promoter's Educational Qualification.");
					 ownerEdu.focus();
					 return false;
				 }
		
				 if(ownerFinStack.value=="")
				 {
					 alert("Promoter's Financial Stake is missing.\nPlease enter Promoter's Financial Stake.");
					 ownerFinStack.focus();
					 return false;
				 } 
					
		    }	

		    if(ownerAdd.value !="")
			{ 
				if(ownerName.value == "")
				 {
					 alert("Promoter's Name is missing.\nPlease enter Promoter's Name.");
					 ownerName.focus();
					 return false;
				 }
				 
				 if(ownerAge.value =="")
				 {
					 alert("Promoter's Age is missing.\nPlease enter Promoter's Age.");
					 ownerAge.focus();
					 return false;
				 }
				if(sexVal.value =="sel")
				{
					 alert("You have not selected Promoter's Gender.\nPlease select Promoters Gender.");
					 ownerAdd.focus();
					 return false;
				 } 
				 
				 if(ownerEdu.value=="")
				 {
					 alert("Promoter's Educational Qualification is missing.\nPlease enter Promoter's Educational Qualification.");
					 ownerEdu.focus();
					 return false;
				 }
		
				 if(ownerAdd.value=="")
				 {
					  alert("Promoter's Address is missing.\nPlease enter Promoter's Address.");
					 ownerAdd.focus();
					 return false;
				 } 
					
		      }	
				
				
			if(ownerAge.value !="")
			{
				if(ownerAge.value ==0)
				{
					alert('Age is incorrect.\nAge can not be Zero.');
					ownerAge.focus();
					return false;
				}
				if(ownerAge.value<0)
				{
					alert('Age is incorrect.\nAge can not be Negative.');
					ownerAge.focus();
					return false;
				}
			} 
           
		  
		   if(ownerName.value != "")
			{
			    var txt = "Owner's Name";
						
				if(ownerAge.value == "" || sexVal == "sel" || ownerEdu.value == "" || ownerAdd.value == "" || ownerFinStack.value == "")
				{
					alert("Incomplete data !!...\nPlease fill in all the data.");
					status = "";
					ownerName.focus();
					return false;
				}
				else
					status = "set";
			} 

			if(ownerAge.value != "")
			{
				var txt ="Owner's Age ";
				if(ownerName.value == "" || sexVal == "sel" || ownerEdu.value == "" || ownerAdd.value == "" || ownerFinStack.value == "")
				{
					alert("Incomplete data !!...\nPlease fill in all the data.");
					status = "";
					ownerAge.focus();
					return false;
				}
				
				else
					status = "set";
			}

			if(sexVal != "sel")
			{

				if(ownerName.value == "" || ownerAge.value == "" || ownerEdu.value == "" || ownerAdd.value == "" || ownerFinStack.value == "")
				{
					alert("Incomplete data !!...\nPlease fill in all the data.");
					status = "";
					ownerSex.focus();
					return false;
				}
				else
					status = "set";
			}
				if(ownerEdu.value != "")
			{
				var txt = "Owners' Educational Qualification ";
				if(!chkSpecialCharCustom(ownerEdu,txt,";%/")) return false; //added by noor
				if(ownerName.value == "" || ownerAge.value == "" || sexVal == "sel" || ownerAdd.value == "" || ownerFinStack.value == "")
				{
					alert("   Incomplete data !!...\nPlease fill in all the data.");
					status = "";
					ownerEdu.focus();
					return false;
				}
				else
					status = "set";
			}

			if(ownerAdd.value != "")
			{
				var txt = ownerAdd.value;
				if(!chkSpecialCharCustom(ownerAdd,txt,"#&;%")) return false;
				if(ownerName.value == "" || ownerAge.value == "" || sexVal == "sel" || ownerEdu.value == "" || ownerFinStack.value == "")
				{
					alert("Incomplete data !!...\nPlease fill in all the data.");
					status = "";
					ownerAdd.focus();
					return false;
				}
				else
					status = "set";
			}

			if(ownerFinStack.value != "")
			{
				var txt = "Owners' Financial Stack";
				if(ownerName.value == "" || ownerAge.value == "" || sexVal == "sel" || ownerEdu.value == "" || ownerAdd.value == "")
				{
					alert("Incomplete data !!...\nPlease fill in all the data.");
					status = "";
					ownerFinStack.focus();
					return false;
				}
				else
				{

					var pattern = "^[0-9]+$";	
					var regex = new RegExp(pattern)
					if (regex.test(ownerFinStack.value)) 
					{
						status = "set";
					}
					else{
						if(ownerFinStack.value.indexOf('.') < 0)
						{
							alert('Financial Stake is incorrect.\nPlease enter Numeric value for Finafsncial Stake.');
							ownerFinStack.focus();
							return false; 
						}
					}
				}
			} 

			if(status == "set")
			promoDetails += ownerName.value + "#" + ownerAge.value + "#" + sexVal + "#" + ownerEdu.value + "#" + ownerAdd.value + "#" + ownerFinStack.value + "&"

				status = "";
		}

		if(totalStake > 100)
		{
			
			alert("The Financial Stake is incorrect.\nPlease ensure that Financial Stake should not be more than 100%.");
			return false;
		}

		//promoDetails = promoDetails.substring(0,promoDetails.length-1);
		window.opener.document.mer_reg.promoDetails.value = promoDetails;
		window.opener.document.mer_reg.totalStake.value= stackMainProm;
		window.close();

}


function submit()
{
	if(document.setupfee.payment_type[0].checked==true)
	{ 
	 //https://www.ccavenue.com/mer_register/
	 document.setupfee.action="mer_select_payoption_wld.jsp";
	 document.setupfee.submit();
	}
	if(document.setupfee.payment_type[1].checked==true)
	{
	 //https://www.ccavenue.com/mer_register/
	 document.setupfee.action="mer_pay_success_wld.jsp";//only  when all payment options are uploaded
	// document.setupfee.action="mer_ccdetail_ccav.jsp";
	 document.setupfee.submit();
	}
}
function submitDMAForm(flag)
{
	var element
	var formElementName
	var text
	if(flag=='true')
	{
		document.dmaForm.action.value = 'submit';
		for( i = 0; i < document.dmaForm.elements.length; i++) // walk through all the form elements.
		{
			element = document.dmaForm.elements[i];
			formElementName = element.name;
			if(formElementName == 'dmaRefName')
			{
				text = "Referance Name ";
				if(!chkBlank(element,text)) return false;
				
			}
			if(formElementName == 'business')
			{
				text = 'Nature Of Business ';
				if(!chkBlank(element,text)) return false;
				if(!chkSpecialCharCustom(element,text,';%/')) return false; // added by noor
			}
			if(formElementName == 'trnVolume' || formElementName == 'dailyVolume' || formElementName == 'monthlyVolume' )
			{
				if(formElementName == 'trnVolume')
					text = 'Average Transaction Amount';
			
				if(formElementName == 'dailyVolume')
					text = 'Average daily Business Volume';
				
				if(formElementName == 'monthlyVolume')
					text = 'Average monthly Business Volume';

				if(!chkSpecialCharCustom(element,text,';%/')) return false; // added by noor
				if(!chkBlank(element,text)) return false;
				if(!chkNaN(element,text)) return false;
			}
			if(formElementName == 'remarks')
			{
				text = 'Remarks ';
				if(!chkSpecialCharCustom(element,text,';%/')) return false; // added by noor
			}
		}
	}
	else
	if(flag=='false')
		document.dmaForm.action.value = 'cancel';

		document.dmaForm.submit();
}


// Following two functions are added by Gajanan Late on 2/9/2004.
function  checkforNumber(element,text)
{ 
  
	var re = new RegExp ('-', 'gi') ;
	var CCNum=element.value;
	if(CCNum.indexOf("+") != -1)
	{
		CCNum=CCNum.substring(1,CCNum.length);
		
	}
	else if(CCNum.indexOf("(") != -1) 
	{
		if(CCNum.indexOf(")") !=-1)
		{   
			 
			CCNum=CCNum.substring(1,CCNum.length-1);
			
		}
		else 
		{
			alert(text+' is incorrect.\nPlease Enter valid'+' '+text+'.');
			element.focus();
			element.select();
			return false;
		}
	} 
	
	//check for hypens (-)
	else if (CCNum.indexOf("-") != -1)
	{  
        CCNum=CCNum.replace(re,'');
		CCNum=trim(CCNum);
	}
	for ( var i = 0; i <CCNum.length; ++i ) 
	{
		var c = CCNum.charAt(i);
		if( c < '0' || c > '9' ) 
		{
			alert(text+' is incorrect.\nPlease Enter numeric value for'+' '+text+'.');
			element.focus();
			element.select();
			return false;
		} 
	}
	return true; 

} 


function chkBlankCustom(formelement,text)
{
	if (formelement.value=='')
	{
		alert(text);
		formelement.focus();
		formelement.select();
		return false;
	}
	else
	{
		return true;
	}
}

//This function allows period(.) in  a field added by Gajanan  on 9/1/2004
function chkSpecialChar2(formelement,text)
{
	var msg='true';
	var a=formelement.value;
	var b=a.length;
	var cha='`~!@#$%^&()+-[]{}/|;:,<>?';
	var ch=cha.length;
	var i,j;

	for(i=0;i<ch;i++)
	{
		var ch1=cha.substring(i,i+1);
		for(j=0;j<b;j++)
		{
			var a1=a.substring(j,j+1);
			if(a1==ch1)
			{
				//msg='You have entered Special Characters like ' +cha+' '+'in'+' '+text+'.'+'\nPlease enter valid'+' '+text+'.';
				msg='Special Character "' +ch1+ '" is not allowed in '+text+'\nPlease enter correct '+text+'.'; //added by Noor.
				//msg=text+' is incorrect.'+'\nPlease enter valid'+' '+text+'.';
				alert(msg);
				formelement.focus();
				formelement.select();
				return false;
			}
		}
	}
	if (msg=='true')
	{
	return true;
	}
}//end of function.
