// JavaScript Document for products show
//评论分页，firefox不分；2011-8-10，不区分浏览器
function ProReviews_Pagination(txtDivID,thisURL,thisURLpara,thisIsBegin){
	PaginationAjax(txtDivID,thisURL,thisURLpara,thisIsBegin)
}

//V2011-10-03:History sold, Digg, Product Review，同时输出
function ProAttendantNum(ProID) {
	var xmlHttp = CreateHTTPObject();
	if (!xmlHttp)
	{
		return; //无法创建 xmlHttp 对象
	}
	
	var url = "/ajax/pro_attendant_num.asp?ProID=" + escape(ProID) + "&rnd=" + Math.random();
//	xmlHttp.open("GET", url, true);
	xmlHttp.open("GET", url, false);
//	xmlHttp.onreadystatechange = function(){HandleRequest(xmlHttp, txtDivID)};
	xmlHttp.send(null);
	var str_return = xmlHttp.responseText;
	str_return = str_return.Trim();
	s_oValue=str_return.split("|");
		if (s_oValue[0]!="") { InnerHTML("num_pro_sold_"+ProID,s_oValue[0]); }
		InnerHTML("num_pro_sold_"+ProID,s_oValue[0]);
		InnerHTML("num_pro_digg_"+ProID,s_oValue[1]);
		InnerHTML("num_pro_review_"+ProID,s_oValue[2]);
}

//V2011-10-03: 提交Digg，需同步处理；同时输出Digg数量和提示
function ProDiggIt(rProID) {
	var xmlHttp = CreateHTTPObject();
	if (!xmlHttp)
	{
		return; //无法创建 xmlHttp 对象
	}
	
	var url = "/ajax/pro_digg_it.asp?ProID=" + rProID + "&rnd=" + Math.random()
//	xmlHttp.open("GET", url, true);
	xmlHttp.open("GET", url, false);
//	xmlHttp.onreadystatechange = function(){HandleRequest(xmlHttp, rShowDivID)};
	xmlHttp.send(null);
	var str_return = xmlHttp.responseText;
	str_return = str_return.Trim();
	s_oValue=str_return.split("|");
	switch(s_oValue[0]) {
		case "er02001" : InnerHTML("sv_pro_digg_"+rProID,"Product is null"); break;
		case "er00002" : InnerHTML("sv_pro_digg_"+rProID,"Your IP is error."); break;
		case "er02501" : InnerHTML("sv_pro_digg_"+rProID,"Please digg it once in 24 hours."); break;
		case "er02502" :
			InnerHTML("sv_pro_digg_"+rProID,"Thank you.");
			InnerHTML("num_pro_digg_"+rProID,s_oValue[1]);
			break;
//		default :
	}
}



//技术支持
function ProTechService(ProSerID,txtDivID){
	var xmlHttp = CreateHTTPObject();
	if (!xmlHttp)
	{
		return; //无法创建 xmlHttp 对象
	}
	
	var url = "/ajax/pro_service.asp?id=" + escape(ProSerID);
//	xmlHttp.open("GET", url, false);
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function(){HandleRequest(xmlHttp, txtDivID)};
	xmlHttp.send(null);
}

function ProViewsNum(ProID,txtDivID) {
	var xmlHttp = CreateHTTPObject();
	if (!xmlHttp)
	{
		return; //无法创建 xmlHttp 对象
	}
	
	var url = "/ajax/pro_rev_num.asp?ProID=" + escape(ProID);
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function(){HandleRequest(xmlHttp, txtDivID)};
	xmlHttp.send(null);
}


//出售数量、推荐次数(Digg)
function ProSoldDiggNum(rProID,rShowDivID,rShowType) {
	var xmlHttp = CreateHTTPObject();
	if (!xmlHttp)
	{
		return; //无法创建 xmlHttp 对象
	}
	
	var url = "/ajax/pro_sold_num.asp?ProID=" + escape(rProID) + "&ShowType=" + escape(rShowType) + "&rnd=" + Math.random();
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function(){HandleRequest(xmlHttp, rShowDivID)};
	xmlHttp.send(null);
}





//订单
function IsOrderNeedSize(isNeedSize,id_e_in)
{
	var oSize=document.getElementById(id_e_in);
	if (isNeedSize=="Y")
	{
		if ((oSize.value=="")||(oSize==null))
		{
			document.getElementById("alert_o_need_"+id_e_in).innerHTML = "Please select Size/Spec.";
			document.getElementById("id_pro_b_item_"+id_e_in).className="pro_b_item_e";
			return false;
		}
		else
		{
			document.getElementById("alert_o_need_"+id_e_in).innerHTML = "";
			document.getElementById("id_pro_b_item_"+id_e_in).className="pro_b_item";
		}
	}
}

function IsOrderNeedColor(isNeedColor,id_e_in)
{
	var oColor=document.getElementById(id_e_in);
	if (isNeedColor=="Y")
	{
		if ((oColor.value=="")||(oColor==null))
		{
			document.getElementById("alert_o_need_"+id_e_in).innerHTML = "Please select Color/Style.";
			document.getElementById("id_pro_b_item_"+id_e_in).className="pro_b_item_e";
			return false;
		}
		else
		{
			document.getElementById("alert_o_need_"+id_e_in).innerHTML = "";
			document.getElementById("id_pro_b_item_"+id_e_in).className="pro_b_item";
		}
	}
}

function IsOrderNeedQty(isNeedQty,id_e_in)
{
	var oQty=document.getElementById(id_e_in);
	if (isNeedQty=="Y")
	{
		if ((oQty.value=="")||(oQty==null)||(oQty.value=="0"))
		{
			document.getElementById("alert_o_need_"+id_e_in).innerHTML = "Please input Quantity.";
			document.getElementById("id_pro_b_item_"+id_e_in).className="pro_b_item_e";
			return false;
		}
		else
		{
			document.getElementById("alert_o_need_"+id_e_in).innerHTML = "";
			document.getElementById("id_pro_b_item_"+id_e_in).className="pro_b_item";
		}
	}
}



//update 2012-1-7 改为专用函数检查加入购物车商品的各项数据
function ShoppingCartAdd(ProID,AddMethod,isNeedSize,id_e_in_size,isNeedColor,id_e_in_color,isNeedQty,id_e_in_qty){
	
	if(!ChkCartInput(isNeedSize,id_e_in_size,isNeedColor,id_e_in_color,isNeedQty,id_e_in_qty))
	{return false;}

	document.formOrderAdd.ProID.value=ProID;
	document.formOrderAdd.AddMethod.value=AddMethod;
	document.formOrderAdd.Action.value="Add";
	if (AddMethod=="Single"){
		document.formOrderAdd.submit();
	}
	else if (AddMethod=="BuyItNow"){
		document.formOrderAdd.action="/app/order_express.asp";
		document.formOrderAdd.submit();
	}
	//window.location.href="/app/order.asp?ProID="+ProID+strOrderExpand+"&Action=Add"
}


function AddToFavorites(ProID,txtDivID)
{
	var xmlHttp = CreateHTTPObject();
	if (!xmlHttp)
	{
		return; //无法创建 xmlHttp 对象
	}
	
	var url = "/ajax/add_to_favorites.asp?psid=" + escape(ProID);
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function(){HandleRequest(xmlHttp, txtDivID)};
	xmlHttp.send(null);
	
//	MyFavoritesRefresh("num_MyFavorites");
}


function MyFavoritesRefresh(txtDivID)
{
	var xmlHttp = CreateHTTPObject();
	if (!xmlHttp)
	{
		return; //无法创建 xmlHttp 对象
	}
	
	var url = "/ajax/refresh_favorites.asp";
//	xmlHttp.open("GET", url, false);
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function(){HandleRequest(xmlHttp, txtDivID)};
	xmlHttp.send(null);
}

function MyFavoritesDelete(rProID){
if(confirm("Are your sure delete this product from Your Favorites?")){
	document.formMyFavoritesDelete.ProID.value=rProID;
	document.formMyFavoritesDelete.submit();
	}
}



//计算单款产品金额小计(价格x数量): 单币种；2010-11-25废止
function ProSignleSubTotal(thisInputID,thisInputValueOri,ProPrice,thisSpanID,CurrencySymbol)
{
	var thisInputValue;
	var thisSubTotalValue;
	var txt_thisSpan="";
	thisInputValue=thisInputID.value;
	if ((ProPrice!="")&&(ProPrice!=null)&&(ProPrice!=0))
	{
		var ProPrice=ProPrice.replace(",","");
		thisSubTotalValue=GetDecimal2Num(thisInputValue*ProPrice,2);
		txt_thisSpan = CurrencySymbol + thisSubTotalValue;
		document.getElementById(thisSpanID).innerHTML = txt_thisSpan;
	}
	else if (thisInputValue==thisInputValueOri)
	{
		document.getElementById(thisSpanID).innerHTML = txt_thisSpan;
	}
}



//递增|递减数量
function updateQuantity(TxtID, act, num)
{
	var oID = document.getElementById(TxtID);
	if (oID==null) { return; }
	if(act=="plus"){
		oID.value =Number(oID.value) + num;
		if(Number(oID.value)>100000) { oID.value=100000;}
	}
	else if(act=="minus")
	{
		oID.value -= num;
		if(Number(oID.value)<1) { oID.value=1;}
	}
}


//执行Add Cart
function AddToCartSubmit(addCartPopID, txtDivID,ProID,isNeedSize,id_e_in_size,isNeedColor,id_e_in_color,isNeedQty,id_e_in_qty)
{	
	if(ChkCartInput(isNeedSize,id_e_in_size,isNeedColor,id_e_in_color,isNeedQty,id_e_in_qty)==true)
	{
		var oSize = document.getElementById(id_e_in_size);
		var oColor = document.getElementById(id_e_in_color);
		var oQty = document.getElementById(id_e_in_qty);
		var sizeVal, colorVal, qtyVal;
		
		if(oSize!=null){ sizeVal = oSize.value;}
		if(oColor!=null){ colorVal = oColor.value;}
		if(oQty!=null){ qtyVal = oQty.value;	}
		
		HideOrVisible(addCartPopID, true);	//显示 Add Cart Pop内容
		
		AddToCartAjax(txtDivID, ProID, sizeVal, colorVal, qtyVal);
	}		
}


//产品Ajax添加到购物车,因js处理中文等特殊字符Cookies产生乱码，避免直接获取非数字的Cookie值
function AddToCartAjax(txtDivID, ProID, oSizeVal, oColorVal, oQtyVal)
{
	var xmlHttp = CreateHTTPObject();
	if (!xmlHttp){return;}	

	var url = "/ajax/pro_add_cart.asp?act=getDetails&ProID="+escape(ProID)+"&oSize="+escape(oSizeVal)+"&oColor="+escape(oColorVal)+"&oQty="+escape(oQtyVal);
	
	//document.location.href=url; return;	
	
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function(){
		HandleRequest(xmlHttp, txtDivID);
		if(xmlHttp.status == 200)
		{
			updateMyCart("str_num_mycart");
		}
	};
	xmlHttp.send(null);
}


//更新My Cart数据，根据提交的参数返回不同内容， 待改...
function updateMyCart(txtDivID){
	var xmlHttp = CreateHTTPObject();	
	if (!xmlHttp){return;}	
	var url = "/ajax/pro_add_cart.asp?act=getMyCart";
	
	//document.location.href=url; return;
	
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = function(){HandleRequest(xmlHttp, txtDivID)};
	xmlHttp.send(null);
}


//根据系统设置添加到购物车的数据
function ChkCartInput(isNeedSize,id_e_in_size,isNeedColor,id_e_in_color,isNeedQty,id_e_in_qty){
	if (isNeedSize=="Y"){
		var oSize=document.getElementById(id_e_in_size);
		if (IsOrderNeedSize(isNeedSize,id_e_in_size)==false){
			alert("Please select Size/Spec.");
			return false;
		}

		if ((oSize!="")&&(oSize!=null)){
			document.formOrderAdd.oSize.value=oSize.value;
		}
	}

	if (isNeedColor=="Y"){
		var oColor=document.getElementById(id_e_in_color);
		if (IsOrderNeedColor(isNeedColor,id_e_in_color)==false){
			alert("Please select Color/Style.");
			return false;
		}

		if ((oColor!="")&&(oColor!=null)){
			document.formOrderAdd.oColor.value=oColor.value;
		}
	}
	

	if (isNeedQty=="Y"){
		var oQty=document.getElementById(id_e_in_qty);
		if (IsOrderNeedQty(isNeedQty,id_e_in_qty)==false){
			alert("Please input Quantity.");
			return false;
		}
		if ((oQty!="")&&(oQty!=null)){
			document.formOrderAdd.oQty.value=oQty.value;
		}		
	}
	
	return true;
}


//结算订单：不要直接转向order_method.asp，先执行Action="Submit"，将计算相关的运费等
//需要选择收货国家名称，以计算运费
function CheckOutFromPop()
{
	//document.location.href="/app/order.asp?Action=Submit";
	document.location.href="/app/order.asp";
}





