
// ----- START VALIDATION FOR MEMBERSHIP FORM 2 ------------ //
function check_signupForm2()
{
	// CHECK FOR USER-TYPE //
	/*
			if(document.form2.accountType.value=="0")
			{
				alert("Please select a Account-Type");
				document.form2.accountType.focus();
				return false;
			}
	*/
	
	var i;
	
	/*
	if(document.form2.accountType[0].checked==false && document.form2.accountType[1].checked==false && document.form2.accountType[2].checked==false)
	{
		alert("Please select a Account Type");
		return false;
	}
	*/
	
	if(document.form2.accountType.options[document.form2.accountType.selectedIndex].value==0)
	{
		alert("Please select a Account Type");
		document.form2.accountType.focus();
		return false;
	}
	
	
	// FIRST-NAME	
	if(document.form2.firstName.value=="")
	{
		alert("Please enter your First-Name");
		document.form2.firstName.focus();
		return false;
	}
	else
	{
		var fname=document.form2.firstName.value;
		if(fname.indexOf(" ")!=-1)
		{
			alert("Please do not enter any spaces for First-Name");
			document.form2.firstName.focus();
			document.form2.firstName.select();	
			return false;
		}
	}
		
	//LAST-NAME
	if(document.form2.lastName.value=="")
	{
		alert("Please enter your Last-Name");
		document.form2.lastName.focus();
		return false;
	}
	else
	{
		var lname=document.form2.lastName.value;
		if(lname.indexOf(" ")!=-1)
		{
			alert("Please do not enter any spaces for Last-Name");
			document.form2.lastName.focus();
			document.form2.lastName.select();
			return false;
		}
	}
	
	// EMAIL - ID VALIDATION
	if(document.form2.email.value=="")
	{
		alert("Please enter your Email-Id");
		document.form2.email.focus();
		return false;
	}
	else
	{
		var str=document.form2.email.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1)
		{
		   alert("Invalid E-mail ID");
		   document.form2.email.focus();
		   document.form2.email.select();
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("Invalid E-mail ID");
   		   document.form2.email.focus();
		   document.form2.email.select();
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    alert("Invalid E-mail ID");
		   	document.form2.email.focus();
		   	document.form2.email.select();	
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1)
		 {
		    alert("Invalid E-mail ID");
		   	document.form2.email.focus();
		   	document.form2.email.select();
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		 {
		    alert("Invalid E-mail ID");
		   	document.form2.email.focus();
		   	document.form2.email.select();
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1)
		 {
		    alert("Invalid E-mail ID");
			document.form2.email.focus();
			document.form2.email.select();
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1)
		 {
		    alert("Invalid E-mail ID");
			document.form2.email.focus();
		   	document.form2.email.select();
		    return false;
		 }
	}
	
	// Password //
	if(document.form2.password.value=="")
	{
		alert("Please enter the password");
		document.form2.password.focus();
		return false;
	}
	
	// VerifyPassword //
	if(document.form2.passwordVerify.value=="")
	{
		alert("Please Re-Enter the password");
		document.form2.passwordVerify.focus();
		return false;
	}
	
	// Check the Password //
	if(document.form2.password.value!="" && document.form2.passwordVerify.value!="")
	{
		var str1=document.form2.password.value;
		var str2=document.form2.passwordVerify.value;
		if(str1 != str2)
		{
			alert("Sorry ! The passwords do not make a match !");
			str1="";
			str2="";
			document.form2.password.value;
			return false;
		}
	}
	
	// Address Validation
	if(document.form2.address.value=="")
	{
		alert("Please enter your address");
		document.form2.address.focus();
		return false;
	}
	
	// City Validation
	if(document.form2.city.value=="")
	{
		alert("Please enter your city");
		document.form2.city.focus();
		return false;
	}
	
	// State Validation
	if(document.form2.state.value=="0")
	{
		alert("Please select your state");
		document.form2.state.focus();
		return false;
	}
	
	// ZipCode Validation
	if(document.form2.zipCode.value=="")
	{
		alert("Please select your zipCode");
		document.form2.zipCode.focus();
		return false;
	}
	
	// Country Validation
	if(document.form2.country.value=="0")
	{
		alert("Please select your country");
		document.form2.country.focus();
		return false;
	}
	
	// PHONE - NUMBER VALIDATION
	if(document.form2.phone.value!="")
	{
		var str_phone=document.form2.phone;
		
		// Declaring required variables
		var digits = "0123456789";
		
		// non-digit characters which are allowed in phone numbers
		var phoneNumberDelimiters = "()- ";
		
		// characters which are allowed in international phone numbers
		// (a leading + is OK)
		var validWorldPhoneChars = phoneNumberDelimiters + "+";
		
		// Minimum no of digits in an international phone no.
		var minDigitsInIPhoneNumber = 10;
		
		if(str_phone.value.indexOf(" ")!=-1)
		{
			alert("Please do not enter any spaces");
			document.form2.phone.focus();
			document.form2.phone.select();
			return false;
		}
		
		// ----------------------------------------------------------- //
		if (checkInternationalPhone(str_phone.value,validWorldPhoneChars)==false)
		{
			alert("Please Enter a Valid Phone Number");
			str_phone.focus();
			str_phone.select();
			return false;
		}
	}
	// ------------------------ // 
	document.form2.txtSubmit.value = "1";
}

// ---------------------------------- END OF FUNCTION FOR MEMBERSIGNUP FORM 2 ------------------------------------------------ //

// FUNCTION VALIDATES THE PHONE
function checkInternationalPhone(strPhone,validWorldPhoneChars)
{
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

// FUNCTION THAT STRIPS THE CHARACTERS
function stripCharsInBag(s, bag)
{
	var i;
	var returnString = "";
	// Search through string's characters one by one. If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++)
	{   
		// Check that current character isn't whitespace.
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

// FUNCTION TO CHECK THE INTEGER VALUE
function isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++)
   	{   
       	// Check that current character is number.
        var c = s.charAt(i);
   	    if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
}

// -------------- START OF FUNCTION FOR MEMBERSIGNUP FORM 3 ------------------------------------------ //
function check_signupForm3()
{
	// CHECK FOR CREDIT-CARD NAME
	if(document.form3.cardname.value=="")
	{
		alert("Please enter your Credit-Card Name");
		document.form3.cardname.focus();
		return false;
	}
	
	// CHECK CREDIT-CARD TYPE
	/*if(document.form2.creditCardType.value=="0")
	{
		alert("Please enter your Credit-Card Type");
		document.form2.creditCardType.focus();
		return false;
	}*/
	
	// CHECK FOR CREDIT-CARD NUMBER
	if(document.form3.creditCardNumber.value=="")
	{
		alert("Please enter your Credit-Card Number");
		document.form3.creditCardNumber.focus();
		return false;
	}
	
	// EXPIRY MONTH
	if(document.form3.creditCardExpirationMM.value=="0")
	{
		alert("Please select a Month");
		document.form3.creditCardExpirationMM.focus();
		return false;
	}
	
	// EXPIRY YEAR
	if(document.form3.creditCardExpirationYY.value=="0")
	{
		alert("Please select a Year");
		document.form3.creditCardExpirationYY.focus();
		return false;
	}
		
	// CHECK FOR CREDIT-CARD VERIFICATION NUMBER
	if(document.form3.cvsNumber.value=="")
	{
		alert("Please enter your Card Verification Number");
		document.form3.cvsNumber.focus();
		return false;
	}

	// ------------------------ // 
	document.form3.txtSubmit.value = "1";
	return true;
}

// ----------- END OF FUNCTION FOR MEMBERSHIP FORM 3----------------------------------------------- //

// -- CHECK SCRIPT FOR LOGIN -- //
function chklogin()
{
	if(document.frmlogin.txtemail.value=="")
	{
		alert("Please enter your email address");
		document.frmlogin.txtemail.focus();
		document.frmlogin.txtemail.select();
		return false;
	}
	else
	{
		var str=document.frmlogin.txtemail.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1)
		{
		   alert("Invalid E-mail ID");
		   document.frmlogin.txtemail.focus();
		   document.frmlogin.txtemail.select();
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
   		   document.frmlogin.txtemail.focus();
		   document.frmlogin.txtemail.select();
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		   	document.frmlogin.txtemail.focus();
		   	document.frmlogin.txtemail.select();	
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		   	document.frmlogin.txtemail.focus();
		   	document.frmlogin.txtemail.select();
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		   	document.frmlogin.txtemail.focus();
		   	document.frmlogin.txtemail.select();
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
			document.frmlogin.txtemail.focus();
			document.frmlogin.txtemail.select();
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
			document.frmlogin.txtemail.focus();
		   	document.frmlogin.txtemail.select();
		    return false;
		 }
	}
}

// ------------------------------------------------------ //
// MemberSignup1 - Page
function go2home()
{
	document.CFForm_1.action="home.cfm";
	document.CFForm_1.method="post";
	document.CFForm_1.submit();
	return true;
}
// ------------------------------------------------------ //

// ***********************************************************************************************//

//  --------- LOGIN - FORM ------------ //

function loginform()
{
	if(document.formlogin.txtemail.value=="")
	{
		alert("Please enter your email address");
		document.formlogin.txtemail.focus();
		document.formlogin.txtemail.select();
		return false;
	}
	else
	{
		var str=document.formlogin.txtemail.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1)
		{
		   alert("Invalid E-mail ID");
		   document.formlogin.txtemail.focus();
		   document.formlogin.txtemail.select();
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
   		   document.formlogin.txtemail.focus();
		   document.formlogin.txtemail.select();
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		   	document.formlogin.txtemail.focus();
		   	document.formlogin.txtemail.select();	
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		   	document.formlogin.txtemail.focus();
		   	document.formlogin.txtemail.select();
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		   	document.formlogin.txtemail.focus();
		   	document.formlogin.txtemail.select();
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
			document.formlogin.txtemail.focus();
			document.formlogin.txtemail.select();
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
			document.formlogin.txtemail.focus();
		   	document.formlogin.txtemail.select();
		    return false;
		 }
	}
	
	if(document.formlogin.txtpassword.value=="")
	{
		alert("Please enter your password");
		document.formlogin.txtpassword.focus();
		document.formlogin.txtpassword.select();
		return false;
	}
	
	document.formlogin.submit();		
}
// ----------------------------------------- //

function checkEnter(e)
{
	 //e is event object passed from function invocation
	var characterCode;
	if(e && e.which)
	{ 
		e = e
	characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}	
	if(characterCode == 13)
	{ 
		if(document.formlogin.txtpassword.value=="")
		{
			alert("Please enter your password");
			document.formlogin.txtpassword.focus();
			document.formlogin.txtpassword.select();
			return false;
		}
		else
		{
			document.forms[0].submit() //submit the form
			return false;
		}
	}
	else
	{
		return true;
	}
}

// ---- Validate Change-Password Form  ---- //
function checkpass()
{
	if(document.formpassword.txtoldpass.value=="")
	{
		alert("Please enter the old password");
		document.formpassword.txtoldpass.focus();
		return false;
	}
	if(document.formpassword.txtnewpass.value=="")
	{
		alert("Please enter the new password");
		document.formpassword.txtnewpass.focus();
		return false;
	}
	if(document.formpassword.txtconfirmpass.value=="")
	{
		alert("Please enter confirmation password");
		document.formpassword.txtconfirmpass.focus();
		return false;
	}
	// Check the Password //
	if(document.formpassword.txtnewpass.value!="" && document.formpassword.txtconfirmpass.value!="")
	{
		var str1=document.formpassword.txtnewpass.value;
		var str2=document.formpassword.txtconfirmpass.value;
		if(str1 != str2)
		{
			alert("Sorry ! The passwords do not make a match !");
			str1="";
			str2="";
			document.formpassword.txtnewpass.value;
			return false;
		}
	}	
}

// Function for Help Section  //
function checkqus()
{
	if(document.formMessages.txtquestion.value=="")
	{
		alert("Please enter the question");
		document.formMessages.txtquestion.focus();
		return false;
	}
}

// ----- function to edit registration form --------------- //
function editRegForm()
{
	var i;
	if(document.form2.accountType[0].checked==false && document.form2.accountType[1].checked==false && document.form2.accountType[2].checked==false)
	{
		alert("Please select a Account Type");
		return false;
	}	
	//FIRST-NAME	
	if(document.form2.firstName.value=="")
	{
		alert("Please enter your First-Name");
		document.form2.firstName.focus();
		return false;
	}
	else
	{
		var fname=document.form2.firstName.value;
		if(fname.indexOf(" ")!=-1)
		{
			alert("Please do not enter any spaces for First-Name");
			document.form2.firstName.focus();
			document.form2.firstName.select();	
			return false;
		}
	}
		
	//LAST-NAME
	if(document.form2.lastName.value=="")
	{
		alert("Please enter your Last-Name");
		document.form2.lastName.focus();
		return false;
	}
	else
	{
		var lname=document.form2.lastName.value;
		if(lname.indexOf(" ")!=-1)
		{
			alert("Please do not enter any spaces for Last-Name");
			document.form2.lastName.focus();
			document.form2.lastName.select();
			return false;
		}
	}
	//EMAIL - ID VALIDATION
	if(document.form2.email.value=="")
	{
		alert("Please enter your Email-Id");
		document.form2.email.focus();
		return false;
	}
	else
	{
		var str=document.form2.email.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1)
		{
		   alert("Invalid E-mail ID");
		   document.form2.email.focus();
		   document.form2.email.select();
		   return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   alert("Invalid E-mail ID");
   		   document.form2.email.focus();
		   document.form2.email.select();
		   return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    alert("Invalid E-mail ID");
		   	document.form2.email.focus();
		   	document.form2.email.select();	
		    return false;
		}
		if (str.indexOf(at,(lat+1))!=-1)
		{
		    alert("Invalid E-mail ID");
		   	document.form2.email.focus();
		   	document.form2.email.select();
		    return false;
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		{
		    alert("Invalid E-mail ID");
		   	document.form2.email.focus();
		   	document.form2.email.select();
		    return false;
		}
		if (str.indexOf(dot,(lat+2))==-1)
		{
		    alert("Invalid E-mail ID");
			document.form2.email.focus();
			document.form2.email.select();
		    return false;
		}
		if (str.indexOf(" ")!=-1)
		{
		    alert("Invalid E-mail ID");
			document.form2.email.focus();
		   	document.form2.email.select();
		    return false;
		}
	}
	// Address Validation
	if(document.form2.address.value=="")
	{
		alert("Please enter your address");
		document.form2.address.focus();
		return false;
	}
	// City Validation
	if(document.form2.city.value=="")
	{
		alert("Please enter your city");
		document.form2.city.focus();
		return false;
	}
	// State Validation
	if(document.form2.state.value=="0")
	{
		alert("Please select your state");
		document.form2.state.focus();
		return false;
	}
	// ZipCode Validation
	if(document.form2.zipCode.value=="")
	{
		alert("Please select your zipCode");
		document.form2.zipCode.focus();
		return false;
	}
	// Country Validation
	if(document.form2.country.value=="0")
	{
		alert("Please select your country");
		document.form2.country.focus();
		return false;
	}
	// PHONE - NUMBER VALIDATION
	if(document.form2.phone.value!="")
	{
		var str_phone;
		str_phone=document.form2.phone;
		
		// Declaring required variables
		var digits = "0123456789";
		
		// non-digit characters which are allowed in phone numbers
		var phoneNumberDelimiters = "()- ";
		
		// characters which are allowed in international phone numbers
		// (a leading + is OK)
		
		var validWorldPhoneChars = phoneNumberDelimiters + "+";
				
		// Minimum no of digits in an international phone no.
		var minDigitsInIPhoneNumber = 10;
		
		if(str_phone.value.indexOf(" ")!=-1)
		{
			alert("Please do not enter any spaces");
			document.form2.phone.focus();
			document.form2.phone.select();
			return false;
		}
		
		// ----------------------------------------------------------- //
		if (checkInternationalPhone(str_phone.value,validWorldPhoneChars)==false)
		{
			alert("Please Enter a Valid Phone Number");
			str_phone.focus();
			str_phone.select();
			return false;
		}
	}
}