// FCT Cart Javascript 
var ship_firstname = "";
var ship_surname = "";
var ship_address1 = "";
var ship_address2 = "";
var ship_address3 = "";
var ship_city = "";
var ship_state = "";
var ship_zipcode = "";

function InitSaveVariables(form) 
{
	ship_firstname 	= $('ship_firstname').value;
	ship_surname 	= $('surname').value;	
	ship_address1 	= $('ship_address1').value;
	ship_address2 	= $('ship_address2').value;
	ship_address3 	= $('ship_address3').value;
	ship_city		= $('ship_city').value;
	ship_state 		= $('ship_state').value;
	ship_zipcode 	= $('ship_zipcode').value;
}

function ShipToBillPerson(form) 
{
	if (form.copy.checked) 
	{
		InitSaveVariables(form);
		$('ship_firstname').value 	= $('firstName').value;
		$('ship_surname').value 	= $('surname').value;
		$('ship_address1').value 	= $('address1').value;
		$('ship_address2').value 	= $('address2').value;
		$('ship_address3').value 	= $('address3').value;
		$('ship_city').value 		= $('city').value;
		//SELECT boxes are a little more complex
		var dropdownIndex 			= $('state').selectedIndex;
		var dropdownValue 			= $('state')[dropdownIndex].value;
		$('ship_state').value 		= dropdownValue;
		$('ship_zipcode').value 	= $('zipcode').value;
	}
	else 
	{
		$('ship_firstname').value 	= ship_firstname;
		$('ship_surname').value 	= ship_surname;	
		$('ship_address1').value 	= ship_address1;
		$('ship_address2').value	= ship_address2;
		$('ship_address3').value 	= ship_address3;
		$('ship_city').value 		= ship_city;
		$('ship_state').value 		= ship_state;
		$('ship_zipcode').value 	= ship_zipcode;
	}
}


var xmlHttp

function showShipDates(state, productId, productNum)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 alert ("Browser does not support HTTP Request")
	 return
	 }
	var url="getProductShipDates.php"
	url=url+"?state="+state+"&productId="+productId+"&productNum="+productNum
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
	 document.getElementById("delivery_date_list").innerHTML=xmlHttp.responseText 
	 } 
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	 {
	 // Firefox, Opera 8.0+, Safari
	 xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
	 //Internet Explorer
	 try
	  {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e)
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	 }
	return xmlHttp;
}

function validation(form){
	var allcookies = document.cookie;
	var pos = allcookies.indexOf("captcha=");
	
	if (pos != -1) {
		var start = pos + 8;
		var end = allcookies.indexOf(";", start);
		
		if (end == -1) end = allcookies.length;
		var value = allcookies.substring(start, end);
		value = unescape(value);
	}

	if (form.code.value.toLowerCase() != value.toLowerCase()) {
		alert('Incorrect security code entered');
		return false;
	}
	return true;
	
}
