// JavaScript Document

//clear application form
function clear_form1(){
	for (i=document.form.titlcust.length-1; i > -1; i--) {
		if (document.form.titlcust[i].checked) {
			document.form.titlcust[i].checked = false;
		}
	}
	document.form.otticust.value = "";
	document.form.frstcust.value = "";
	document.form.middcust.value = "";
	document.form.lastcust.value = "";
	document.form.add1cust.value = "";
	document.form.add2cust.value = "";
	document.form.citycust.value = "";
	document.form.sttecust.value = "";
	document.form.zippcust.value = "";
	
	for (i=document.form.doorcust.length-1; i > -1; i--) {
		if (document.form.doorcust[i].checked) {
			document.form.doorcust[i].checked = false;
		}
	}
	document.form.tel1cust.value = "";
	document.form.tel2cust.value = "";
	document.form.tel3cust.value = "";
	document.form.mailcust.value = "";
	document.form.reaccust.value = "";
	for (i=document.form.listcust.length-1; i > -1; i--) {
		if (document.form.listcust[i].checked) {
			document.form.listcust[i].checked = false;
		}
	}
	document.form.bdmocust.value = "";
	document.form.bddycust.value = "";
	document.form.favocust.value = "";
	document.form.speccust.value = "";
	document.form.dislcust.value = "";
	
	return false;
}

//check application form signup.asp
function check_form1(){
	
	if(document.form.mailcust.value == ""){
		alert("Please enter your valid Email Address.");
		document.form.mailcust.focus();
		return false;
	}
	//email validation
	var theEmail = document.form.mailcust.value;
	var atLoc = theEmail.indexOf("@", 1);
	var dotLoc = theEmail.indexOf(".", atLoc+2);
	var len = theEmail.length;
	if(atLoc > 0 && dotLoc > 0 && len > dotLoc+2){
		//return true;
	}else{
		alert("The format of your email entered is not correct.");
		document.form.mailcust.focus();
		return false;
	}
	
	if(document.form.passcust.value != "" && document.form.cpsscust.value != ""){
		if(document.form.passcust.value == document.form.cpsscust.value){
			if(document.form.passcust.value.length < 6){
				alert("Your password has to be at least 6 characters in length.");
				document.form.passcust.value = "";
				document.form.cpsscust.value = "";
				document.form.passcust.focus();
				return false;
			}else{
				if(alphanumeric(document.form.passcust.value)== false){
					alert("Your password contains character other than alphanumeric.");
					document.form.passcust.value = "";
					document.form.cpsscust.value = "";
					document.form.passcust.focus();
					return false;
				}
			}
		}else{
			alert("Passwords you entered do not match. Please enter again.");
			document.form.passcust.value = "";
			document.form.cpsscust.value = "";
			document.form.passcust.focus();
			return false;
		}
	}else{
		alert("Please enter both a login password and confirmation password.");
		document.form.passcust.focus();
		return false;
	}
	
	//myOption = -1;
	//for (i=document.form.titlcust.length-1; i > -1; i--) {
		//if (!document.form.titlcust[i].checked) {
			//myOption = i;
			//if(document.form.otticust.value == ""){
				//alert("Please enter your title if it does not apply to either one.");
				//document.form.otticust.focus();
				//return false;
			//}
		//}		
	//}	
	//if (myOption == -1) {
		////alert("Please select your title.");		
		//return false;
	//}	
	
	
	if(document.form.frstcust.value == ""){
		alert("Please enter your first name.");
		document.form.frstcust.focus();
		return false;
	}
	if(document.form.lastcust.value == ""){
		alert("Please enter your last name.");
		document.form.lastcust.focus();
		return false;
	}
	if(document.form.add1cust.value == ""){
		alert("Please enter the address.");
		document.form.add1cust.focus();
		return false;
	}
	if(document.form.citycust.value == ""){
		alert("Please enter City.");
		document.form.citycust.focus();
		return false;
	}
	if(document.form.tel1cust.value == "" && document.form.tel2cust.value == "" && document.form.tel3cust.value == ""){
		alert("Please enter at lease one telephone number.");
		document.form.tel1cust.focus();
		return false;
	}else{
		if(document.form.tel1cust.value !="") {
			if(CheckPhoneNumber(document.form.tel1cust.value) == 0){
				alert("You have entered invalid character.");
				document.form.tel1cust.focus();
				return false;
			}
		}
	}
}

//select other when text box is focused
function select_ot(){
	document.form.titlcust[4].checked = true;
}

//shipping.asp
//calculate delivery fee automatically
function change_shipinfo1(){
	location.href = 'http://www.terrymayny.com/shipping.asp';
}
function change_shipinfo2(){
	location.href = 'http://www.terrymayny.com/shipping.asp?delv=1';
}

//club_2.asp login checking
function signin_form(){
	if(document.loginform.lgidcust.value == ""){
		alert("Please enter your login ID, which is normally your email address.");
		document.loginform.lgidcust.focus();
		return false;
	}
	if(document.loginform.passcust.value == ""){
		alert("Please enter your password.");
		document.loginform.passcust.focus();
		return false;
	}
}

//alpha numeric checking
function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

//phone number checking
function CheckPhoneNumber(TheNumber) {
	var valid = 1
	var GoodChars = "0123456789()-+ "
	var i = 0
	
	for (i =0; i <= TheNumber.length -1; i++) {
		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
// Note: Remove the comments from the following line to see this
// for loop in action.
// alert(TheNumber.charAt(i) + " is no good.")
			valid = 0
		} // End if statement
	} // End for loop
	return valid
}

//order.asp page, checking the inventory after selecting the date
function verify_inve(){
	d = document.form2.shipdate.value;
	
	location.href = 'http://www.terrymayny.com/order.asp?d='+d;
}
