document.write('<LINK REL="SHORTCUT ICON" HREF="/logo.ico">');

var deliveryType;

function setNav(the_loc)
{
	the_loc = the_loc.toString();
	the_page = the_loc.substring(the_loc.lastIndexOf("/")+1, the_loc.lastIndexOf("."));
	the_loc.indexOf(".php") == -1 ? the_page = "index" : ""
	the_page.indexOf("samples") >= 0 ? the_page = "samples" : ""
	the_tab = document.getElementById("tab_" + the_page);
	if (the_tab && the_page == "shop")
	{
		the_tab.className = "tab_shop_on";
	}
	else if (the_tab)
	{
		the_tab.className = "tab_on";
	}
}

function doHover(the_item)
{
	the_item.className == "tab_shop_off" ? the_item.className = "tab_shop_over" : ""
	the_item.className == "tab_off" ? the_item.className = "tab_over" : ""
}

function unHover(the_item)
{
	the_item.className == "tab_shop_over" ? the_item.className = "tab_shop_off" : ""
	the_item.className == "tab_over" ? the_item.className = "tab_off" : ""
}

function filterNum(str)
{
	re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\]|\'|\"|\[|\}|\{|\<|\>|\||\$/g;
	// remove special characters like "$" and "," etc...
	return str.replace(re, "");
}

function showDeliveryType(oValue)
{
	deliveryType = oValue;
	switch (oValue)
	{
		case "Email"		:	$("#gift-by-email").show();
								$("#gift-by-snailmail").hide();
								break;

		case "Snail mail"	:	$("#gift-by-email").hide();
								$("#gift-by-snailmail").show();
								break;

		default				:	$("#gift-by-email").hide();
								$("#gift-by-snailmail").hide();
								break;
	}
}

function viewConfirm(str)
{ 
	isError = new Array();
	var errorList = "";

	var packageSize = document.getElementById("packagesPackageSize").value;
	var speciesNumber = filterNum(document.getElementById("packageSpeciesNumber").value);
	var specialNeeds = filterNum(document.getElementById("packageSpecialNeeds").value);
	var personality = filterNum(document.getElementById("packagePersonality").value);
	var additionalInfo = filterNum(document.getElementById("packageAdditionalInfo").value);
	var customerName = document.getElementById("customerName").value;
	var customerEmail = document.getElementById("customerEmail").value;
	var customerState = document.getElementById("customerState").value;

	var donateCVPS = document.getElementById("donateCVPS").checked;
	var donateCVPSamount = document.getElementById("donateCVPSamount").value;

	var giftCertID = document.getElementById("giftCertID").value;

	var referrer = document.getElementById("referrer").value;

	packageSize == "" ? isError.push("You must specify a package size.") : ""
	customerName.length < 1 ? isError.push("You must enter your name.") : ""
	customerEmail.length < 1 ? isError.push("You must enter an email address.") : ""
	customerState == "" ? isError.push("You must select a state.") : ""
	donateCVPS == true && (donateCVPSamount <= 0 ||  donateCVPSamount.length < 1) ? isError.push("You checked the donation box, but did not enter an amount.") : ""
	isNaN(donateCVPSamount) == true ? isError.push("The donation must be dollar amounts only.") : ""
	donateCVPSamount.length > 0 && donateCVPS == false ? isError.push("You have not verified you wish to make the specified donation.") : ""
	
	if (isError.length > 0)
	{
		for(i=0;i<isError.length;i++)
		{
			errorList += isError[i] + "\n";
		}
		alert(errorList);
	}
	else
	{
		var xmlHttp;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		//Do reg exp to fix special characters...like # especially

		var url="ajax/view-confirm.php";
		url=url+"?packageSize="+packageSize;
		url=url+"&speciesNumber="+speciesNumber;
		url=url+"&specialNeeds="+specialNeeds;
		url=url+"&personality="+personality;
		url=url+"&additionalInfo="+additionalInfo;
		url=url+"&customerName="+customerName;
		url=url+"&customerEmail="+customerEmail;
		url=url+"&customerState="+customerState;
		url=url+"&donateCVPS="+donateCVPS;
		url=url+"&donateCVPSamount="+donateCVPSamount;
		url=url+"&giftCertID="+giftCertID;
		url=url+"&referrer="+referrer;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=function()
		{
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{
				document.getElementById("confirm-order-div").innerHTML = xmlHttp.responseText;
				theSelects = document.getElementById("create-order-div").getElementsByTagName("SELECT");
				for (i=0;i<theSelects.length; i++ )
				{
					theSelects[i].disabled = true;
				}
				theTextareas = document.getElementById("create-order-div").getElementsByTagName("TEXTAREA");
				for (i=0;i<theTextareas.length; i++ )
				{
					theTextareas[i].disabled = true;
				}
				theInputs = document.getElementById("create-order-div").getElementsByTagName("INPUT");
				for (i=0;i<theInputs.length; i++ )
				{
					theInputs[i].disabled = true;
				}
			} 
		};
		document.getElementById("confirm-order-div").style.display = "block";
		document.getElementById("confirm-order-div").innerHTML = "<center style='margin-top:10px'><img src='images/ajax-loader.gif' style='margin-right:5px;'/>Loading...</center>";
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function viewConfirmGift(str)
{
	isError = new Array();
	var errorList = "";

	var certDeliveryType = document.getElementById("certDeliveryType").value;
	//var certDeliveryTo = document.getElementById("certDeliveryTo").value;
	
	var recipientsName = document.getElementById("recipientsName").value;
	var recipientsEmail = document.getElementById("recipientsEmail").value;
	var recipientsStreet = document.getElementById("recipientsStreet").value;
	var recipientsCity = document.getElementById("recipientsCity").value;
	var recipientsState = document.getElementById("recipientsState").value;
	var recipientsZip = document.getElementById("recipientsZip").value;

	var sendersName = document.getElementById("sendersName").value;
	var sendersEmail = document.getElementById("sendersEmail").value;
	var giftPackageSize = document.getElementById("giftPackageSize").value;

	var giftNote = document.getElementById("giftNote").value;
	
	certDeliveryType == "" ? isError.push("You must select a delivery method.") : ""
	//certDeliveryTo == "" ? isError.push("You must select a certificate recipient.") : ""
	recipientsName.length < 1 ? isError.push("You must enter a recipient.") : ""
	if (deliveryType == "Email")
	{
		recipientsEmail.length < 1 ? isError.push("You must enter the recipient's email.") : ""
	}
	if (deliveryType == "Snail mail")
	{
		recipientsStreet.length < 1 ? isError.push("You must enter the recipient's street address.") : ""
		recipientsCity.length < 1 ? isError.push("You must enter the recipient's city.") : ""
		recipientsState == "" ? isError.push("You must select the recipient's state.") : ""
		recipientsZip.length < 1 ? isError.push("You must enter the recipient's zip code.") : ""
	}
	sendersName.length < 1 ? isError.push("You must enter your name.") : ""
	sendersEmail.length < 1 ? isError.push("You must enter your email address.") : ""
	giftPackageSize.length < 1 ? isError.push("You must enter a package size.") : ""
	
	if (isError.length > 0)
	{
		for(i=0;i<isError.length;i++)
		{
			errorList += isError[i] + "\n";
		}
		alert(errorList);
	}
	else
	{
		var xmlHttp;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request");
			return;
		}
		//Do reg exp to fix special characters...like # especially

		var url="ajax/view-confirm-gift.php";
		url=url+"?certDeliveryType="+certDeliveryType;
		//url=url+"&certDeliveryTo="+certDeliveryTo;
		
		url=url+"&recipientsName="+recipientsName;
		url=url+"&recipientsEmail="+recipientsEmail;
		url=url+"&recipientsStreet="+recipientsStreet;
		url=url+"&recipientsCity="+recipientsCity;
		url=url+"&recipientsState="+recipientsState;
		url=url+"&recipientsZip="+recipientsZip;
		
		url=url+"&sendersName="+sendersName;
		url=url+"&sendersEmail="+sendersEmail;
		url=url+"&giftPackageSize="+giftPackageSize;

		url=url+"&giftNote="+giftNote;
		
		url=url+"&sid="+Math.random();

		xmlHttp.onreadystatechange=function()
		{
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{
				document.getElementById("confirm-gift-div").innerHTML = xmlHttp.responseText;
				theSelects = document.getElementById("create-order-gift-div").getElementsByTagName("SELECT");
				for (i=0;i<theSelects.length; i++ )
				{
					theSelects[i].disabled = true;
				}
				theTextareas = document.getElementById("create-order-gift-div").getElementsByTagName("TEXTAREA");
				for (i=0;i<theTextareas.length; i++ )
				{
					theTextareas[i].disabled = true;
				}
				theInputs = document.getElementById("create-order-gift-div").getElementsByTagName("INPUT");
				for (i=0;i<theInputs.length; i++ )
				{
					theInputs[i].disabled = true;
				}
			} 
		};
		document.getElementById("confirm-gift-div").style.display = "block";
		document.getElementById("confirm-gift-div").innerHTML = "<center style='margin-top:10px'><img src='images/ajax-loader.gif' style='margin-right:5px;'/>Loading...</center>";
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function editOrder()
{
	document.getElementById("confirm-order-div").style.display = "none";
	theSelects = document.getElementById("create-order-div").getElementsByTagName("SELECT");
	for (i=0;i<theSelects.length; i++ )
	{
		theSelects[i].disabled = false;
	}
	theTextareas = document.getElementById("create-order-div").getElementsByTagName("TEXTAREA");
	for (i=0;i<theTextareas.length; i++ )
	{
		theTextareas[i].disabled = false;
	}
	theInputs = document.getElementById("create-order-div").getElementsByTagName("INPUT");
	for (i=0;i<theInputs.length; i++ )
	{
		theInputs[i].disabled = false;
	}
}

function editGift()
{
	document.getElementById("confirm-gift-div").style.display = "none";
	theSelects = document.getElementById("create-order-gift-cert").getElementsByTagName("SELECT");
	for (i=0;i<theSelects.length; i++ )
	{
		theSelects[i].disabled = false;
	}
	theTextareas = document.getElementById("create-order-gift-cert").getElementsByTagName("TEXTAREA");
	for (i=0;i<theTextareas.length; i++ )
	{
		theTextareas[i].disabled = false;
	}
	theInputs = document.getElementById("create-order-gift-cert").getElementsByTagName("INPUT");
	for (i=0;i<theInputs.length; i++ )
	{
		theInputs[i].disabled = false;
	}
}

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 showSamplePage(page)
{
	$(".samples_link").css("font-weight","normal");
	$(".samples_link").css("font-size","12px");
	$(".samples_link").css("color","");
	$(".samples_link_"+page).css("font-weight","bold");
	$(".samples_link_"+page).css("font-size","14px");
	$(".samples_link_"+page).css("color","black");
	$(".sample_page").hide();
	$("#sample_page_"+page).show();
	if (page==3)
	{
		$("#popcorn-pic").css("display", "block");
	}
	else
	{
		$("#popcorn-pic").css("display", "none");
	}
}