

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 ajfindPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function ajxEmailFriend(dvName, e, target) {  
	if (document.getElementById('dvLogGiftList'))
	{
		document.getElementById('dvLogGiftList').style.display = 'none';
	}
	document.getElementById('dvEmailFriend').style.display = 'none';
	
	document.getElementById(dvName).style.display = 'block';
	document.getElementById("EmailResponse").style.display = 'none';
	document.getElementById("EmailForm").style.display = 'block';
	var coords = ajfindPos(document.getElementById(target));
	document.getElementById(dvName).style.left = coords[0] - 260 + 'px';
	document.getElementById(dvName).style.top = coords[1] + 'px';
}

function ajxFrmEmailFriend(f)
{

	var formValid = true;
	if (chkElement("txtFriendEmail", "lblFriendEmail") == false)
	{
		formValid = false;
	}


	if (chkElement("txtYourEmail", "lblYourEmail") == false)
	{
		formValid = false;
	}

	
	
	if (formValid == false)
	{
		document.getElementById("required").style.color	= "red";
		document.getElementById("required").innerHTML = "Please enter required field"
	} else
	{
		if (!isEmail(alltrim(document.getElementById("txtFriendEmail").value)))
		{
			document.getElementById("required").style.color	= "red";
			document.getElementById("required").innerHTML = "Your email is invalid."
			setFieldRed("txtFriendEmail", "lblFriendEmail")
			formValid = false;
		}
		
		if (!isEmail(alltrim(document.getElementById("txtYourEmail").value)))
		{
			document.getElementById("required").style.color	= "red";
			document.getElementById("required").innerHTML = "Your email is invalid."
			setFieldRed("txtYourEmail", "lblYourEmail")
			formValid = false;
		}
	}

	
	if (formValid == false) { return formValid; }
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return false;
	} 
	
	var sku = alltrim(document.getElementById("txtSku").value)
	var fname = alltrim(document.getElementById("txtFriendName").value)
	var femail = alltrim(document.getElementById("txtFriendEmail").value)
	var yname = alltrim(document.getElementById("txtYourName").value)
	var yemail = alltrim(document.getElementById("txtYourEmail").value)
	var msg = alltrim(document.getElementById("txtMessage").value)
	

	var url = "/ajaxed/product-emailfriend.asp?prc=emailfriend&sku="+sku+"&fname="+fname+"&femail="+femail+"&yname="+yname+"&yemail="+yemail+"&msg="+msg+"&sid="+Math.random()

	//window.location.href = url
	//xmlHttp.onreadystatechange=stateChanged;

	xmlHttp.onreadystatechange=stateEmailFriend;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	return false;
}

function stateEmailFriend() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("EmailResponse").style.display = 'block';
		document.getElementById("EmailForm").style.display = 'none';
	}
}


function ajxUpdateShipMethod(iShpCode, iRecID)
{
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return false;
	} 

	var url = "/ajaxed/checkout-shippingupdate.asp?prc=updShip&recid=" + iRecID + "&shpmethod=" + iShpCode +"&sid="+Math.random()

	//xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.onreadystatechange=stateUpdateShipMethod;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	return false;
}

function stateUpdateShipMethod() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		// done
	}
}

