////////////////////////////////////////////////////////////////////////////////
///// ar_Store version 0.1
///// Programmed by: Amit Roy
///// reisswolf@gmail.com
///// Special note: 
////////////////////////////////////////////////////////////////////////////////





function SignUp_ShowWebSiteURLRow () {

	var Element ;

	///// Show the label.
	Element = GetRefToElement ("WebSiteLabel");
	Element.visibility = 'show';
	Element.style.visibility = 'visible';

	///// Show the input field.
	Element = GetRefToElement ("WebSiteFormElement");
	Element.visibility = 'show';
	Element.style.visibility = 'visible';

} ///// End SignUp_ShowWebSiteURLRow ()





function SignUp_HideWebSiteURLRow () {

	var Element;

	///// Show the label.
	Element = GetRefToElement ("WebSiteLabel");
	Element.visibility = 'hide';
	Element.style.visibility = 'hidden';

	///// Show the input field.
	Element = GetRefToElement ("WebSiteFormElement");
	Element.visibility = 'hide';
	Element.style.visibility = 'hidden';

} ///// End SignUp_HideWebSiteFormElement ()





function SignUp_DisplayCountry () {

	var StateIndex = document.SignUpForm.StateProvince.selectedIndex;

	if (StateIndex >= 2 && StateIndex <= 51) {
		document.SignUpForm.Country.selectedIndex = 1;
	} ///// End if ()
	else if (StateIndex >= 55 && StateIndex <= 67) {
		document.SignUpForm.Country.selectedIndex = 2;
	} ///// End else if ()

} ///// End SignUp_DisplayCountry ()





function SignUp_ValidateSignUpForm (Form) {

	var Element = "";
	var ElemVal = "";
	var RegExp_1 = "";
	var RegExp_2 = "";

	///// Validate the first name.
	ElemVal = Form.FirstName.value;
	if (ElemVal == "") {
		alert ("Invalid first name");
		return false;
	} ///// End if ()

	///// Validate the last name.
	ElemVal = Form.LastName.value;
	if (ElemVal == "") {
		alert ("Invalid last name");
		return false;
	} ///// End if ()

	///// Validate the e-mail address.
	RegExp_1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	RegExp_2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 
	ElemVal = Form.EMailAddress.value;
	if ( RegExp_1.test (ElemVal) || !RegExp_2.test (ElemVal) ) {
		alert ("Invalid e-mail address");
		return false;
	} ///// End if ()

	///// Validate the second instance of the e-mail address.
	var ReTypedEMailAddress = Form.ReTypeEMailAddress.value;
	if (ReTypedEMailAddress != ElemVal) {
		alert ("Mismatch between the two e-mail addresses provided");
		return false;
	} ///// End if ()

	///// Validate the website URL.
	/*if (Form.WebSiteYesNo[0].checked) {
		ElemVal = Form.WebSiteURL.value;
		if (ElemVal == "http://" || ElemVal.length < 12) {
			alert ("Invalid website URL; please use the format:  http://www.mysite.com");
			return false;
		} ///// End if ()
	} ///// End if ()*/
	
	//var urlregex = new RegExp("^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)");
	if (Form.WebSiteYesNo[0].checked) {
			ElemVal = Form.WebSiteURL.value;
			var urlRegxp = /(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)/;
			if (urlRegxp.test(ElemVal) != true)
			{
				alert("URL appears to be incorrect!! Please use format:  www.abc.com");
				Form.WebSiteURL.focus();
				return false;
			}
	}



	///// Validate address line 1.
	ElemVal = Form.AddressLine_1.value;
	if (ElemVal == "") {
		alert ("Invalid address line 1");
		return false;
	} ///// End if ()

	///// Validate the city.
	ElemVal = Form.City.value;
	if (ElemVal == "") {
		alert ("Invalid city");
		return false;
	} ///// End if ()

	///// Validate the state and country.
	var StateIndex = Form.StateProvince.selectedIndex;
	var CountryIndex = Form.Country.selectedIndex;
	if (
		((StateIndex < 2 || StateIndex > 51) && CountryIndex == 1) ||
		((StateIndex < 55) && CountryIndex == 2)
	) {
		alert ("Invalid combination of state and country");
		return false;
	} ///// End if ()

	///// Validate the postal code..
	
	ElemVal = Form.PostCode.value;
	
	
	if (CountryIndex == 1) 
	{
		if (!/\d\d\d\d\d/.test (ElemVal) || ElemVal.length > 5) 
		{
			
			alert ("Invalid postal code for the selected country");
			return false;
		} ///// End if ()
	} ///// End if ()
	
	else if (CountryIndex == 2 ) 
	{
		strlen = ElemVal.length; 
		if (strlen != 6 ) 
		{
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			return false;
		}
		ElemVal=ElemVal.toUpperCase();        
		// in case of lowercase characters
		// Check for legal characters in string - note index starts at zero
		if ('ABCEHJKLMNPRSTVXY'.indexOf(ElemVal.charAt(0)) < 0) 
		{
			
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			return false;
		}
		if ('0123456789'.indexOf(ElemVal.charAt(1)) < 0) 
		{
			
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			return false;
		}
		if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(ElemVal.charAt(2)) < 0) 
		{
			
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			return false;
		}
		if ('0123456789'.indexOf(ElemVal.charAt(3)) < 0) 
		{
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			return false;
		}
		if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(ElemVal.charAt(4)) < 0) 
		{
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			return false;
		}
		if ('0123456789'.indexOf(ElemVal.charAt(5)) < 0) 
		{
			
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			return false;
		}
	}
	
	///// Validate the telephone number.
	//RegExp_1 = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;
	RegExp_1 = /^\d{3}\-?\d{3}\-?\d{4}$/;
	ElemVal = Form.Telephone.value;
	if (!RegExp_1.test (ElemVal)) {
		alert ("Invalid telephone number.  Valid format: 123-555-0123");
		Form.Telephone.focus();
		return false;
	} ///// End if ()

	///// Validate the password.
	ElemVal = Form.Password.value;
	if (ElemVal.length < 6) {
		alert ("Please choose a password that is at least six characters long.");
		return false;
	} ///// End if ()

	///// Validate the second instance of the password.
	var ReTypedPassword = Form.ReTypePassword.value;
	if (ReTypedPassword != ElemVal) {
		alert ("Mismatch between the two passwords provided");
		return false;
	} ///// End if ()

	return true;

} ///// End SignUp_ValidateSignUpForm ()

function Forgot_Password (Form)
{
	if(Form.EMailAddress.value == ""  )
	{
		alert("Please Enter Valid Email ID");
		return false;
	}
	
	/*else if(Form.EMailAddress.value != Form.EMail.value )
	{
		alert("INVALID EMAIL ID");
		return false;
	}
	else if(Form.EMailAddress.value == Form.EMail.value )
	{
		return true;
	}*/	
}


function FieldsValidate(Form)
{
	/*if(Form.fax.value == "")
	{
		alert("NULL VALUE! Enter Fax No.");
		Form.fax.focus();
		return false;
	}*/	
	//return true;
	
	
	var Element = "";
	var ElemVal = "";
	var RegExp_1 = "";
	var RegExp_2 = "";

	///// Validate the e-mail address.
	RegExp_1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	RegExp_2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 
	
	ElemVal = Form.email.value;
	if ( RegExp_1.test (ElemVal) || !RegExp_2.test (ElemVal) ) {
		alert ("Invalid e-mail address");
		Form.email.focus();
		return false;
	} ///// End if ()

	///// Validate address line 1.
	ElemVal = Form.address_line_1.value;
	if (ElemVal == "") {
		alert ("Invalid address line 1");
		Form.address_line_1.focus();
		return false;
	} ///// End if ()

	///// Validate the city.
	ElemVal = Form.city.value;
	if (ElemVal == "") {
		alert ("Invalid city");
		Form.city.focus();
		return false;
	} ///// End if ()

	///// Validate the state and country.
	/*var StateIndex = Form.state.selectedIndex;
	var CountryIndex = Form.country.selectedIndex;
	if (
		((StateIndex < 2 || StateIndex > 51) && CountryIndex == 1) ||
		((StateIndex < 55) && CountryIndex == 2)) {
		alert ("Invalid combination of state and country");
		Form.state.focus();
		return false;
	} ///// End if ()

	///// Validate the postal code..
	ElemVal = Form.post_code.value;	
	if (CountryIndex == 1) 
	{
		if (!/\d\d\d\d\d/.test (ElemVal) || ElemVal.length > 5) 
		{
			alert ("Invalid postal code for the selected country");
			Form.post_code.focus();
			return false;
		} ///// End if ()
	} ///// End if ()
	
	else if (CountryIndex == 2 ) 
	{
		strlen = ElemVal.length; 
		if (strlen != 6 ) 
		{
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			Form.post_code.focus();
			return false;
		}
		ElemVal=ElemVal.toUpperCase();        
		// in case of lowercase characters
		// Check for legal characters in string - note index starts at zero
		
		if ('ABCEHJKLMNPRSTVXY'.indexOf(ElemVal.charAt(0)) < 0) 
		{
			
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			Form.post_code.focus();
			return false;
		}
		if ('0123456789'.indexOf(ElemVal.charAt(1)) < 0) 
		{
			
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			Form.post_code.focus();
			return false;
		}
		if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(ElemVal.charAt(2)) < 0) 
		{
			
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			Form.post_code.focus();
			return false;
		}
		if ('0123456789'.indexOf(ElemVal.charAt(3)) < 0) 
		{
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			Form.post_code.focus();
			return false;
		}
		if ('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(ElemVal.charAt(4)) < 0) 
		{
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			Form.post_code.focus();
			return false;
		}
		if ('0123456789'.indexOf(ElemVal.charAt(5)) < 0) 
		{
			
			alert ("Invalid postal code for the selected country Valid format: L4B1B4");
			Form.post_code.focus();
			return false;
		}
	}*/
	
	///// Validate the telephone number.
	///// Validate the telephone number.
	//RegExp_1 = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;
	RegExp_1 = /^\d{3}\-?\d{3}\-?\d{4}$/;
	ElemVal = Form.telephone.value;
	if (!RegExp_1.test (ElemVal)) {
		alert ("Invalid telephone number! Valid format: 123-555-1234");
		Form.telephone.focus();
		return false;
	} ///// End if ()

}




