function checkaddy(logform) {
   if (logform.ship_fname.value == "") {alert("Please enter a first name under Shipping Information."); logform.ship_fname.focus();return false;}
   else if (logform.ship_lname.value =="") {alert("Please enter a last name under Shipping Information. "); logform.ship_lname.focus();return false;}
   else if (logform.ship_street_one.value =="") {alert("Please enter a shipping address."); logform.ship_street_one.focus(); return false;}
   else if (logform.ship_postal_code.value =="") {alert("Please enter a zip code under Shipping Information."); logform.ship_postal_code.focus(); return false;}
   else if (logform.ship_city.value =="") {alert("Please enter a city under Shipping Information. "); logform.ship_city.focus(); return false;}
   else if (logform.ship_state.value=="") {alert("Please enter a state under Shipping Information. "); logform.ship_state.focus(); return false;}
   else if (logform.ship_phone.value=="") {alert("Please enter a phone number under Shipping Information. "); logform.ship_phone.focus();return false;}
   else if (logform.bill_fname.value=="") {alert("Please enter a first name under Billing Information. "); logform.bill_fname.focus(); return false;}
   else if (logform.bill_lname.value=="") {alert("Please enter a last name under Billing Information. "); logform.bill_lname.focus(); return false;}
   else if (logform.bill_street_one.value=="") {alert("Please enter an address under Billing Information. "); logform.bill_street_one.focus(); return false;}
   else if (logform.bill_postal_code.value=="") {alert("Please enter a zip code under Billing Information. "); logform.bill_postal_code.focus(); return false;}
   else if (logform.bill_city.value=="") {alert("Please enter a city under Billing Information. "); logform.bill_city.focus(); return false;}
   else if (logform.bill_state.value=="") {alert("Please enter a state under Billing Information. "); logform.bill_state.focus(); return false;}
   else if (logform.bill_phone.value=="") {alert("Please enter a phone number under Billing Information."); logform.bill_phone.focus(); return false;}
   else if (logform.email_one.value != logform.email_two.value){alert("The email addresses you entered do not match, please verify your email."); logform.email_one.focus(); return false;}
   else{ return true;}
}

function validforcart(prodform) {
    if (prodform.add_quantity.value=="0"){alert("Please enter a valid quantity.");prodform.add_quantity.focus();return false;}
    else if (prodform.color.value =="0") {alert("Please select a color."); prodform.color.focus();return false;}
    else if (prodform.pole.value=="0"){alert("Please select a connection type."); prodform.pole.focus();return false;}
    else{ return true;}
}

function checknewsignup(fm) {
	fm.email_new.value=fm.email_new.value.toLowerCase();
	var emailcheck = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
	if(fm.password_new.value != fm.password_verify.value){alert("The password and verified password do not match. Please re-enter your desired password.");fm.password_new.focus();return false;}
	else if(fm.password_new.value==""){alert("Please enter a password."); fm.password_new.focus();return false;}
	else if(fm.postal_code.value==""){alert("Please enter your zip code."); fm.postal_code.focus(); return false;}	
	else if(fm.birth_year.value==""){alert("Please select a birth year before continuing."); fm.birth_year.focus();return false;}
	else if((fm.gender[0].checked == false) && (fm.gender[1].checked == false)){
			alert("Please select a gender."); return false;
		}
	else if(fm.registration_id.value==""){alert("Please enter a registration id."); fm.registration_id.focus(); return false;}
	else if(fm.radio_serial_new.value==""){alert("Please enter your Livio Radio's serial number."); fm.radio_serial_new.focus(); return false;}
	else if(fm.isread.value==false){alert("You need to accept the terms and conditions before continuing."); fm.isread.focus();return false;}
	else if(fm.fname_new.value==""){alert("Please enter your first name."); fm.fname_new.focus(); return false;}
	else if(fm.lname_new.value==""){alert("Please enter your last name."); fm.lname_new.focus(); return false;}
	else if(fm.purchase_date.value==""){alert("Please enter a purchase date."); fm.purchase_date.focus(); return false;}
	else if(fm.email_new.value.search(emailcheck) == -1){alert("The email address you entered is not valid. Please enter another email."); fm.email_new.focus();return false;}
	else{return true;}
}


function checkexistsignup(fm){
	if(fm.email_exist.value==""){alert("Please enter your email address."); fm.email_exist.focus(); return false;}
	else if(fm.password_exist.value==""){alert("Please enter your password."); fm.password_exist.focus(); return false;}
	else if(fm.registration_id_exist.value==""){alert("Please enter your registration ID."); fm.registration_id_exist.focus();return false;}
	else if(fm.fname_exist.value==""){alert("Please enter your first name."); fm.fname_exist.focus();return false;}
	else if(fm.lname_exist.value==""){alert("Please enter your last name."); fm.lname_exist.focus();return false;}
	else if(fm.purchase_date_exist.value==""){alert("Please enter a purchase date."); fm.purchase_date_exist.focus(); return false;}
	else if(fm.radio_serial_exist.value==""){alert("Please enter your radio's serial number."); fm.radio_serial_exist.focus();return false;}
	else{return true;}
}

function copyaddy(){
 if(document.formaddress.copybox.checked) {
   document.formaddress.ship_fname.value = document.formaddress.bill_fname.value;
   document.formaddress.ship_lname.value = document.formaddress.bill_lname.value;
   document.formaddress.ship_company.value = document.formaddress.bill_company.value;
   document.formaddress.ship_street_one.value = document.formaddress.bill_street_one.value;
   document.formaddress.ship_street_two.value = document.formaddress.bill_street_two.value;
   document.formaddress.ship_postal_code.value = document.formaddress.bill_postal_code.value;
   document.formaddress.ship_city.value = document.formaddress.bill_city.value;
   document.formaddress.ship_state.value = document.formaddress.bill_state.value;
   document.formaddress.ship_phone.value = document.formaddress.bill_phone.value;
}}

function applycoupon(coupon){
        var ajaxRequest;  // The variable that makes Ajax possible!
        try{
                ajaxRequest = new XMLHttpRequest();
        } catch (e){
                try{
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try{
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                                alert("Your browser broke!");
                                return false;
                        }
                }
        }
        ajaxRequest.onreadystatechange = function(){
                if(ajaxRequest.readyState == 4){
                        var ajaxDisplay = document.getElementById('fillincost');
                        ajaxDisplay.innerHTML = ajaxRequest.responseText;
                }
        }
   var queryString = "?couponcode=" + coupon;
   ajaxRequest.open("GET", "applycoupon.php" + queryString, true);
   ajaxRequest.send(null);
}


function checkPicture(color,product){
        var ajaxRequest;  // The variable that makes Ajax possible!
        try{
                ajaxRequest = new XMLHttpRequest();
        } catch (e){
                try{
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try{
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                                alert("Your browser broke!");
                                return false;
                        }
                }
        }
        ajaxRequest.onreadystatechange = function(){
                if(ajaxRequest.readyState == 4){
                        var ajaxDisplay = document.getElementById('theproductimage');
                        ajaxDisplay.innerHTML = ajaxRequest.responseText;
                }
        }
   var queryString = "?color=" + color + "&productid=" + product;
   ajaxRequest.open("GET", "changeimage.php" + queryString, true);
   ajaxRequest.send(null);
}

function newPicture(productid,imageline){
        var ajaxRequest;  // The variable that makes Ajax possible!
        try{
                ajaxRequest = new XMLHttpRequest();
        } catch (e){
                try{
                        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        try{
                                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                                alert("Your browser broke!");
                                return false;
                        }
                }
        }
        ajaxRequest.onreadystatechange = function(){
                if(ajaxRequest.readyState == 4){
                        var ajaxDisplay = document.getElementById('theproductimage');
                        ajaxDisplay.innerHTML = ajaxRequest.responseText;
                }
        }
   var queryString = "?productid=" + productid + "&imageline=" + imageline;
   ajaxRequest.open("GET", "newimage.php" + queryString, true);
   ajaxRequest.send(null);
}


function grab_states(statecode,spanid){
	var stateList;
	var stateShip;

	try{
		stateList = new XMLHttpRequest();
	} catch (e){
		try{
			stateList = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e){
			try{
				stateList = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				alert("Your browser broke!");
				return false;
			}}}
	stateList.onreadystatechange = function(){
		if(stateList.readyState ==4){
			var stateDisplay = document.getElementById('fill_states');
			stateDisplay.innerHTML = stateList.responseText;
			try{stateShip = new XMLHttpRequest();}
			catch (e){try{stateShip= new ActiveXObject("Msxml2.XMLHTTP");}
			catch (e){try{stateShip= new ActiveXObject("Microsoft.XMLHTTP");}
			catch (e){alert("Your browser broke!");
				return false;
			}}}
			stateShip.onreadystatechange = function(){
				if(stateShip.readyState ==4){
					var stateDispTwo = document.getElementById('ship_states');
					stateDispTwo.innerHTML = stateShip.responseText;
				}}

			var twoString = "?statecode=" + statecode + "&spanid=ship_states";
			stateShip.open("GET","module_state.php" + twoString, true);
			stateShip.send(null);
			}}
	var queryString = "?statecode=" + statecode + "&spanid=fill_states";
	stateList.open("GET","module_state.php" + queryString,true);
	stateList.send(null);
}		
