﻿function getXMLHttpRequest(){  
	var xmlHttp;
	var xmlHttpRequest = null; 
	if (window.ActiveXObject){
	  var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
	  var xmlHttp = new XMLHttpRequest();
	}
	return xmlHttp;
}

//-------会员注册--------
function RegUserName(url){
	xmlHttp=getXMLHttpRequest();
	xmlHttp.open("get", url, false);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-Length",length);
	xmlHttp.send();
	RegMessage.innerHTML=(xmlHttp.ResponseText);
}

//-------加入收藏--------
function AddFavorite(url){
	var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async="false";
	xmlDoc.load(url);
	root = xmlDoc.documentElement;
	alert(xmlDoc.getElementsByTagName("items")[0].childNodes[0].xml);
}

//-------购物车操作--------
function UserInquiryBasket(url,ShowMessage){
	xmlHttp=getXMLHttpRequest();
	xmlHttp.open("get", url, false);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-Length",length);
	xmlHttp.send(null);
	if (ShowMessage!=false){
		var LoginMessage=(xmlHttp.ResponseText);
		if (LoginMessage=="请先登陆！"){
			window.location='/User/Login.asp?RequestUrl='+document.location.href;
		}else{
			alert(xmlHttp.ResponseText);
		}
	}
}

//-------送货地址--------
function SendGoodsAddress(url,Id){
	if (Id != "") {
	  	var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.load(url+"?Sign=FillForm&Id="+Id);
		root = xmlDoc.documentElement;
		document.DataForm.Consignee.value=(xmlDoc.getElementsByTagName("Consignee")[0].childNodes[0].xml);
		document.DataForm.Address.value=(xmlDoc.getElementsByTagName("Address")[0].childNodes[0].xml);
		document.DataForm.PostalCode.value=(xmlDoc.getElementsByTagName("PostalCode")[0].childNodes[0].xml);
		document.DataForm.Tel.value=(xmlDoc.getElementsByTagName("Tel")[0].childNodes[0].xml);
		document.DataForm.MTel.value=(xmlDoc.getElementsByTagName("MTel")[0].childNodes[0].xml);
		document.DataForm.EMail.value=(xmlDoc.getElementsByTagName("EMail")[0].childNodes[0].xml);
		document.DataForm.Explain.value=(xmlDoc.getElementsByTagName("Explain")[0].childNodes[0].xml);
		if (xmlDoc.getElementsByTagName("Sex")[0].childNodes[0].xml=="1"){
				document.DataForm.Sex[0].checked=true;
			}else{
				document.DataForm.Sex[1].checked=true;
			}
	}
}


//-------显示产品详细--------
function ProductDetailsData(DivId,url){
	LoadingData(DivId);
	DetailsButton.className='ProDInfoButton';
	SpecBriefButton.className='ProDInfoButton';
	OtherButton.className='ProDInfoButton';
	ProductComment.className='ProDInfoButton';
	ProductBrand.className='ProDInfoButton';
	//HistoryOrdersList.className='ProDInfoButton';
	
	ProductDetailsHttp=getXMLHttpRequest();
	ProductDetailsHttp.open("get", url, true);
	ProductDetailsHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ProductDetailsHttp.setRequestHeader("Content-Length",length);
	ProductDetailsHttp.onreadystatechange = ProductDetailsDataReadyStateChange;
	ProductDetailsHttp.send();
}
function ProductDetailsDataReadyStateChange(){
	if (ProductDetailsHttp.readyState == 4){
		if (ProductDetailsHttp.status == 200){
			ProductDetailsInfoData.innerHTML=(ProductDetailsHttp.ResponseText);
  		}
  	}
}
//-------显示载入过程--------
function LoadingData(DivId){
	$(DivId).innerHTML="<p align=center><br><img border='0' src='../images/DotIco/loadingSmall.gif'>数据加载中....</p>"
}


//-------显示商品评论[由Ajax分页调用]--------
function ProductCommentData(DivId,url){
	LoadingData(DivId);
		
	ProductCommentHttp=getXMLHttpRequest();
	ProductCommentHttp.open("get", url, true);
	ProductCommentHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ProductCommentHttp.setRequestHeader("Content-Length",length);
	ProductCommentHttp.onreadystatechange = ProductCommentDataReadyStateChange;
	ProductCommentHttp.send();
}
function ProductCommentDataReadyStateChange(){
	if (ProductCommentHttp.readyState == 4){
		if (ProductCommentHttp.status == 200){
			ShowProductComment.innerHTML=(ProductCommentHttp.ResponseText);
  		}
  	}
}

//-------书写商品评论--------
function ProductCommentSaveData(DivId,url,ShowCommentUrl){

	ProductCommentSaveHttp=getXMLHttpRequest();
	
	ProductCommentSaveHttp.open("POST", url, true);
	ProductCommentSaveHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ProductCommentSaveHttp.setRequestHeader("Content-Length",length);
	ProductCommentSaveHttp.onreadystatechange = ProductCommentSaveDataReadyStateChange;
	ProductCommentSaveHttp.send();
	
	ProductDetailsData(DivId,ShowCommentUrl);    //重载评论列表
}
function ProductCommentSaveDataReadyStateChange(){
	if (ProductCommentSaveHttp.readyState == 4){
		if (ProductCommentSaveHttp.status == 200){
			alert(ProductCommentSaveHttp.ResponseText);
			CommentDetails.value='';
  		}
  	}
}

//-------载入会员登陆-------
function LoginDivData(DivId,url){
	LoadingData(DivId);
	LoginDivDataHttp=getXMLHttpRequest();
	LoginDivDataHttp.open("get", url, true);
	LoginDivDataHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	LoginDivDataHttp.setRequestHeader("Content-Length",length);
	LoginDivDataHttp.onreadystatechange = function(){LoginDivDataReadyStateChange(DivId)};
	LoginDivDataHttp.send();
}
function LoginDivDataReadyStateChange(DivId){
	if (LoginDivDataHttp.readyState == 4){
		if (LoginDivDataHttp.status == 200){
			$(DivId).innerHTML=(LoginDivDataHttp.ResponseText);		
  		}
  	}
}

//-------公用载入DIV数据-------
function LoadDivData(DivId,url){
	LoadingData(DivId);
	LoadDivDataHttp=getXMLHttpRequest();
	LoadDivDataHttp.open("get", url, true);
	LoadDivDataHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	LoadDivDataHttp.setRequestHeader("Content-Length",length);
	LoadDivDataHttp.onreadystatechange = function(){LoadDivDataReadyStateChange(DivId)};
	LoadDivDataHttp.send(null);
}
function LoadDivDataReadyStateChange(DivId){
	if (LoadDivDataHttp.readyState == 4){
		if (LoadDivDataHttp.status == 200){
			$(DivId).innerHTML=(LoadDivDataHttp.responseText);		
  		}
  	}
}