// JavaScript Document

var myBilling = [];
var billAddress = 1;//address is index 1 in the myBilling array
var billName = 2;//Name is index 2 in the myBilling array
var billCity = 3;//City is index 3 in the myBilling array
var billState = 4;//State is index 4 in the myBilling array
var billZip = 5;//Zip is index 5 in the myBilling array
var billCountry = 6;//Country is index 6 in the myBilling array


function Dwaines_imgSwap(imgSrc,idToSwitch)
{
	if(!document.getElementById || idToSwitch == null )return;
	
	myImg = document.getElementById(idToSwitch);
	myImg.src = imgSrc;
	
}

function goToAddPage(itemNum)
{
	window.location = "AddToCart.php?item="+itemNum;
}

function addItem(itemNum)
{
	//document.frm_cart.item_number.value = itemNum;
	//document.frm_cart.command.value = "ADD";
	//document.frm_cart.submit();
	//document.getElementById("txtHeading").text = itemNum;
		//Get a pointer to the game board.
	var chkOutWin = document.getElementById("frm_checkout");
	//chkOutWin = document.getElementById("checkout").style;
	chkOutWin.style.visibility = "visible";

	nWidth = 760;
	nHeight = 600;

	if (!chkOutWin) return;
	
		var nWizzy = 0;
		var nHizzy = 150;

	//Move the picture of the game board.
	chkOutWin.style.left = ((nWidth - nWizzy) / 1.9) + "px";
	chkOutWin.style.top = ((nHeight - nHizzy) / 2.5) + "px";
}

function ValidateEmail(theForm)
{
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	if (((theForm.Email.value.search(exclude) != -1)||(theForm.Email.value.search(check)) == -1)||(theForm.Email.value.search(checkend) == -1))
		{alert("Please enter a valid Email Address."); theForm.Email.focus(); return (false); }
	return (true); 
} 

function checkBill() 
{
	
	
	fm = document.getElementById("frm_cc");
	
	//alert(fm.BillState.SelectedIndex);
	
	if(fm.BillingIsShipping.checked == true)
	{
		if(billingIsEmpty() == true)
		{
			fm.BillName.value = fm.ShipName.value;
			fm.BillAddress.value = fm.ShipAddress.value;
			fm.BillCity.value = fm.ShipCity.value;
			fm.BillState.selectedIndex = fm.ShipState.selectedIndex;
			fm.BillZip.value = fm.ShipZip.value;
			fm.BillCountry.value = fm.ShipCountry.value ;    
		}
		else
		{
			myBilling[billAddress] = fm.BillAddress.value;
			myBilling[billName] = fm.BillName.value;
			myBilling[billCity] = fm.BillCity.value;
			myBilling[billState] = fm.BillState.selectedIndex;
			myBilling[billZip] = fm.BillZip.value;
			myBilling[billCountry] = fm.BillCountry.value;
			
			fm.BillName.value = fm.ShipName.value;
			fm.BillAddress.value = fm.ShipAddress.value;
			fm.BillCity.value = fm.ShipCity.value;
			fm.BillState.selectedIndex = fm.ShipState.selectedIndex;
			fm.BillZip.value = fm.ShipZip.value;
			fm.BillCountry.value = fm.ShipCountry.value ;    
		}
	}
	else
	{
			fm.BillAddress.value = myBilling[billAddress] ;
			fm.BillName.value = myBilling[billName];
			fm.BillCity.value = myBilling[billCity];
			fm.BillState.selectedIndex = myBilling[billState];
			fm.BillZip.value = myBilling[billZip];
			fm.BillCountry.value = myBilling[billCountry];
	}
    		
}		

function billingIsEmpty()
{
		//if these values don't equal nothing then the user has entered data
		//who cares what the data is ;)~
		if(fm.BillName.value !== "")return false;
    	if(fm.BillAddress.value !== "")return false;
    	if(fm.BillCity.value !== "")return false;
    	if(fm.BillState.SelectedIndex !== 0)return false;
    	if(fm.BillZip.value !== "")return false;
    	if(fm.BillCountry.value !== "")return false;    
		//if you're still here then return yes the billing info is blank 
		return true;
}
function openSecurityWindow(url) 
{
    window.open(url,"",'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=340');
}

function checkAdd(frm)
{
	if(frm.opt_XS.checked == false && frm.opt_S.checked == false && frm.opt_M.checked == false && frm.opt_L.checked == false && frm.opt_XL.checked == false && frm.opt_XXL.checked == false && frm.opt_XXXL.checked == false)
	{
		alert("Sorry you must choose a size to add this item to your cart.");
		frm.opt_S.focus();
		return false;
	}
}
