var giftHttp= GetXmlHttpObject();

function giftShopCheck(maxId){

	if(document.getElementById("giftShopForm").conditionCheck.checked == false){
		document.getElementById("conditionMsg").innerHTML="You must read and agree to the terms and condition. Please try again."
		return;
	}

	var orderString="";

	for(var i=1;i<=maxId;i++){
		if(document.getElementById("orderNum"+i)!=null){
			if(document.getElementById("orderNum"+i).value >0)
				orderString+=i+"b"+document.getElementById("orderNum"+i).value+"_";
		}
	}

	if(orderString == ""){
		document.getElementById("conditionMsg").innerHTML="You haven't selected any item."
		return;
	}
		
	var uEmail;

	/*if(!debug){
		uEmail = getCookie("userEmail")
		
		if(uEmail == null){
			document.getElementById("conditionMsg").innerHTML="Please login to enter this section."
			return;
		}
	}else{*/
	/*	if(!memberLogin){
			document.getElementById("conditionMsg").innerHTML="Please login to enter this section."
			return;
		}else{
			uEmail = '&forumMode=1';
		}*/
	//}

	http = GetXmlHttpObject();

	if (!http)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 

	window.scrollTo(0,0);

	document.getElementById("conditionMsg").innerHTML="";
	//var params = 'rand='+getCurrMsec()+'&order='+orderString+'&uEmail='+uEmail;
	var params = 'rand='+getCurrMsec()+'&order='+orderString;
	if(screen.width >= 1024)
		params = params + "&screen=1024";
	
	var url="giftShop_order.php?"+params;
	//alert(url)
	http.onreadystatechange=handleOrderGift;
	http.open("GET",url,true);
	http.send(null);

}

function handleOrderGift() 
{ 
	if (http.readyState==4 || http.readyState=="complete")
	{ 
		var res_array = http.responseText.split("#@@#");
		
		if(res_array[0]== "1"){
			document.getElementById("giftContent").innerHTML=res_array[1]; 
		}else if(res_array[0]== "0"){
			document.getElementById("giftContent").innerHTML=res_array[1]; 
		}else{
			document.getElementById("giftContent").innerHTML=http.responseText; 
		}
	} 
} 

function giftShopConfirm(orderId,email){
	
	window.scrollTo(0,0);
	var url="giftShop_mailInfo.php?oid="+orderId+"&email="+email;

	giftHttp.onreadystatechange=handleGiftShopConfirm
	giftHttp.open("GET",url,true);
	giftHttp.send(null);

}

function handleGiftShopConfirm() {
	if (giftHttp.readyState==4 || giftHttp.readyState=="complete")
	{ 
			//if(debug){
				var arr = giftHttp.responseText.split("|");
				document.getElementById("giftContent").innerHTML=arr[0]; 
				if(arr[1]!= null){
					setCCPoint(arr[1]);
				}
			/*}else{
				document.getElementById("giftContent").innerHTML=giftHttp.responseText; 
			}*/
			giftHttp = null;
	} 
}

function giftShopUserInfo(orderId){
	
	giftHttp= GetXmlHttpObject();

	var cNo = document.getElementById("contactNo").value; 
	var mAdd =document.getElementById("mailingAddress").value;

	// check email
	if (cNo==""){
		document.getElementById("giftShopMsg").innerHTML="Please enter your contact number!";
		return;
	}
	
	if (mAdd==""){
		document.getElementById("giftShopMsg").innerHTML="Please enter your mailing address!";
		return;
	}

	var url="giftShop_done.php?oid="+orderId;
	url+="&contact="+cNo;
	url+="&mail="+mAdd;
	//if(debug)
	//url+="&forumMode=1";

	giftHttp.onreadystatechange=handleGiftShopConfirm;
	giftHttp.open("GET",url,true)
	giftHttp.send(null)

}

