
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
//http://www.somacon.com/p143.php

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

//////////////////////////////////////////////////////////////////////////////
//  checkCompletedForm
//////////////////////////////////////////////////////////////////////////////

//function checkCompletedForm(s,action){ // completed form
function checkCompletedForm(s){ // completed form
	if ('object' != typeof(s))
			return(false);
			
	if ("" == s.name.value) {
		if(confirm("Sorry!  We don't seem to have your name on file.  Click OK to edit your customer information.")){
			s.action = "your_info_edit.asp";
			s.submit();
			}
		return(false);
		}

	var temp_str = trim(s.name.value)

	if (temp_str.indexOf(" ") == -1) { //no space found, only 1 word
		if(confirm("Sorry!  We don't seem to have your first and last names on file.  Click OK to edit your customer information.")){
			s.action = "your_info_edit.asp";
			s.submit();
		}
	}	
		
	if ("" == s.addr1.value) {
		if(confirm("Sorry!  We don't seem to have your address on file. Click OK to edit your customer information.")){
			s.action = "your_info_edit.asp";
			s.submit();
			}
		return(false);
		}
	if ("" == s.city.value) {
		if(confirm("Sorry!  We don't seem to have your city on file. Click OK to edit your customer information.")){
			s.action = "your_info_edit.asp";
			s.submit();
			}
		return(false);
		}
	if ("" == s.state.value) {
		if(confirm("Sorry!  We don't seem to have your state on file. Click OK to edit your customer information.")){
			s.action = "your_info_edit.asp";
			s.submit();
			}
		return(false);
		}
	if ("" == s.zip.value) {
		if(confirm("Sorry!  We don't seem to have your zip on file. Click OK to edit your customer information.")){
			s.action = "your_info_edit.asp";
			s.submit();
			}
		return(false);
		}
	if ("" == s.phone.value) {
		if(confirm("Sorry!  We don't seem to have your phone number on file. Click OK to edit your customer information.")){
			s.action = "your_info_edit.asp";
			s.submit();
			}
		return(false);
		}
    if ("2" == s.addressType.value && s.CompanyName.value == "") {
		if(confirm("Sorry!  You have specified a commercial address, but no company name. Click OK to edit your customer information.")){
			s.action = "your_info_edit.asp";
			s.submit();
			}
		return(false);
		}	
	if ("" == s.gift_cert.value)
	{
	    var cnum =  trim(s.num_x.value);
	    
	    if ("" == cnum) {
		    if(confirm("Sorry!  We don't seem to have your credit card number on file. Click OK to edit your customer information.")){
			    s.action = "your_info_edit.asp";
			    s.submit();
			}
		    return(false);
		}
		
		if (!checkCardNumWithMod10(cnum)) {
		    if(confirm("Sorry!  Your credit card number is not valid. Click OK to edit your customer information.")){
			    s.action = "your_info_edit.asp";
			    s.submit();
			}
		    return(false);
		}
		
	    if ("" == s.CVN.value) {
		    if(confirm("Sorry!  We don't seem to have your credit card verification number on file. Click OK to edit your customer information.")){
			    s.action = "your_info_edit.asp";
			    s.submit();
			}
		    return(false);
		}
		
		var expArr = s.exp.value.split("/");
		
		if (!checkExpDate(expArr[0], expArr[1]))
		{
		    if(confirm("Sorry!  The expiration date of your card has expired. Click OK to edit your customer information.")){
			    s.action = "your_info_edit.asp";
			    s.submit();
			}
		    return(false);		
		}
		
	}
	
//	if ("" == action)
//	    action = "your_shipping_info.asp";	
//	//s.action = "your_shipping_info.asp";
//	s.action = action;
	s.submit();
}

//////////////////////////////////////////////////////////////////////////////
//  check_blank_form
//////////////////////////////////////////////////////////////////////////////
function check_blank_form(s){
	if ('object' != typeof(s))
		return(false);
		
	if ("" == s.email.value) {
		alert("Sorry! To track your order, you must enter your email address.");
		s.email.focus();
		return(false);
		}
		
	if ("" == s.password.value) {
		alert("Sorry! To track your order, you must enter a password.");
		s.password.focus();
		return(false);
		}
	if ("" == s.password2.value) {
		alert("Please confirm your password.");
		s.password2.focus();
		return(false);
		}
	if (s.password.value != s.password2.value) {
		alert("Sorry! Your passwords don't match!");
		s.password.value = "";
		s.password2.value = "";
		s.password.focus();
		return(false);
		}
	if ("" == s.name.value) {
		alert("Please enter your name.");
		s.name.focus();
		return(false);
		}

	var temp_str = trim(s.name.value);

	if (temp_str.indexOf(" ") == -1) { //no space found, only 1 word
		alert("Please enter your first and last names.");
		s.name.focus();
		return(false);
		}
	
    if ("2" == getCheckedValue(s.elements['addressType']) && s.CompanyName.value == "") {
		    alert("Sorry!  You have specified a commercial address, but no company name.\nPlease enter a Company Name so we can make sure your order is delivered promptly.");
            s.CompanyName.focus();
		    return(false);
		}
				
	if ("" == s.addr1.value) {
		alert("Please enter your address.");
		s.addr1.focus();
		return(false);
		}
	if ("" == s.city.value) {
		alert("Please enter your city.");
		s.city.focus();
		return(false);
		}
	if ("" == s.state.value) {
		alert("Please enter your state.");
		s.state.focus();
		return(false);
		}
	if ("" == s.zip.value) {
		alert("Please enter your postal code.");
		s.zip.focus();
		return(false);
		}
	if ("" == s.phone.value) {
		alert("Please enter your phone number.");
		s.phone.focus();
		return(false);
		}
		
	if ("" == s.gift_cert.value)
	{
	    var cnum =  trim(s.num_x.value);
	    
        if ("" == cnum) 
        {
	        alert("Please enter a credit card number.");
	        s.num_x.focus();
	        return(false);
	    }
	    
	    if (!checkCardNumWithMod10(cnum)) 
	    {
	        alert("Sorry - the card number you have entered is not valid.");
	        s.num_x.focus();
	        return(false);
	     }
	    var moSelect = document.getElementById('mo');
        var mo =   moSelect.options[moSelect.selectedIndex].value;
    
        var yrSelect = document.getElementById('yr');
        var yr =   yrSelect.options[yrSelect.selectedIndex].value;
    
	    if(! checkExpDate(mo, yr))
	    {
	        alert("The expiration date you have entered is not valid.");
	        return(false);
	    }
	    
	    s.CVN.value = trim(s.CVN.value);
	    
	    if ("" == s.CVN.value) 
        {
	        alert("Please enter your card's verification number.");
	        s.CVN.focus();
	        return(false);
	    }
	    
	    if (!isNumber(s.CVN.value)) 
        {
	        alert("Sorry - the card verification number is not valid.");
	        s.CVN.focus();
	        return(false);
	    }
	}
	s.submit();
}
//////////////////////////////////////////////////////////////////////////////
//  check_blank_form_2 - check everything but let the credit card info be removed
//////////////////////////////////////////////////////////////////////////////
function check_blank_form_2(s){
	if ('object' != typeof(s))
		return(false);
		
	if ("" == s.email.value) {
		alert("Sorry! To track your order, you must enter your email address.");
		s.email.focus();
		return(false);
		}
		
	if ("" == s.password.value) {
		alert("Sorry! To track your order, you must enter a password.");
		s.password.focus();
		return(false);
		}
	if ("" == s.password2.value) {
		alert("Please confirm your password.");
		s.password2.focus();
		return(false);
		}
	if (s.password.value != s.password2.value) {
		alert("Sorry! Your passwords don't match!");
		s.password.value = "";
		s.password2.value = "";
		s.password.focus();
		return(false);
		}
	if ("" == s.name.value) {
		alert("Please enter your name.");
		s.name.focus();
		return(false);
		}

	var temp_str = trim(s.name.value);

	if (temp_str.indexOf(" ") == -1) { //no space found, only 1 word
		alert("Please enter your first and last names.");
		s.name.focus();
		return(false);
		}
	
    if ("2" == getCheckedValue(s.elements['addressType']) && s.CompanyName.value == "") {
		    alert("Sorry!  You have specified a commercial address, but no company name.\nPlease enter a Company Name so we can make sure your order is delivered promptly.");
            s.CompanyName.focus();
		    return(false);
		}
				
	if ("" == s.addr1.value) {
		alert("Please enter your address.");
		s.addr1.focus();
		return(false);
		}
	if ("" == s.city.value) {
		alert("Please enter your city.");
		s.city.focus();
		return(false);
		}
	if ("" == s.state.value) {
		alert("Please enter your state.");
		s.state.focus();
		return(false);
		}
	if ("" == s.zip.value) {
		alert("Please enter your postal code.");
		s.zip.focus();
		return(false);
		}
	if ("" == s.phone.value) {
		alert("Please enter your phone number.");
		s.phone.focus();
		return(false);
		}
		

	s.submit();
}
/////*************************
//////////////////////////////////////////////////////////////////////////////
//  check_blank_form_shipping_address
//////////////////////////////////////////////////////////////////////////////
function check_blank_form_shipping_address(s){
	if ('object' != typeof(s))
		return(false);
		
	if ("" == s.name.value) {
		alert("Please enter the name.");
		s.name.focus();
		return(false);
		}

	var temp_str = trim(s.name.value);

	if (temp_str.indexOf(" ") == -1) { //no space found, only 1 word
		alert("Please enter the first and last names.");
		s.name.focus();
		return(false);
		}
	
    if ("2" == getCheckedValue(s.elements['addressType']) && s.CompanyName.value == "") {
		    alert("Sorry!  You have specified a commercial address, but no company name.\nPlease enter a Company Name so we can make sure your order is delivered promptly.");
            s.CompanyName.focus();
		    return(false);
		}
				
	if ("" == s.addr1.value) {
		alert("Please enter your address.");
		s.addr1.focus();
		return(false);
		}
	if ("" == s.city.value) {
		alert("Please enter your city.");
		s.city.focus();
		return(false);
		}
	if ("" == s.state.value) {
		alert("Please enter your state.");
		s.state.focus();
		return(false);
		}
	if ("" == s.zip.value) {
		alert("Please enter your postal code.");
		s.zip.focus();
		return(false);
		}

	s.submit();
}
