var xmlHttp = false;

function createXMLHttp(){
	if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		try{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}
		}
	}
}

function sendRequestSAD(url,tag){
	createXMLHttp();
	xmlHttp.open("get",url,true);
	xmlHttp.onreadystatechange = function (){processresponseSAD(tag)};
	xmlHttp.send(null);
}

function processresponseSAD(tag){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			dynamicSADInfo(tag);
		}else{
//			alert("ajax error");
		}
	}
}

function dynamicSADInfo(tag){
	delSADList();
	var tableStr = document.getElementById("dynamicSAD");
	if (tableStr == null) return;
	var xmlSADList = xmlHttp.responseXML.getElementsByTagName("sadList");
	var current = null;
	var innerStr = "";
	innerStr += "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
	innerStr += "<tr><th width=\"140\" height=\"30\">商品名称</th>";
	innerStr += "<th width=\"60\">地区</th>";
	if(tag=='buy'){
		innerStr += "<th width=\"130\">意向价格(以下)</th>";
	}else{
		innerStr += "<th width=\"130\">意向价格(以上)</th>";
	}
	innerStr += "<th width=\"115\">预计交货日期</th>";
	innerStr += "<th>动作</th></tr>";
	
	
	for(var i=0; i<xmlSADList.length; i++){
		current = xmlSADList[i];
		var sadId = current.getElementsByTagName("sadId")[0].firstChild.nodeValue;
		var product = current.getElementsByTagName("product")[0].firstChild.nodeValue;
		var area = current.getElementsByTagName("area")[0].firstChild.nodeValue;
		var price = current.getElementsByTagName("price")[0].firstChild.nodeValue;
		var price = current.getElementsByTagName("price")[0].firstChild.nodeValue;
		var currcncy = current.getElementsByTagName("currcncy")[0].firstChild.nodeValue;
		var time = current.getElementsByTagName("time")[0].firstChild.nodeValue;
		
		innerStr += "<tr>";
		innerStr += "<td width=\"140\" height=\"30\">"+product+"</td>";
		innerStr += "<td width=\"60\">"+area+"</td>";
		innerStr += "<td width=\"130\">"+price+"("+currcncy+")</td>";
		innerStr += "<td width=\"115\">"+time+"</td>";
		innerStr += "<td><a href=\"./attendSAD.do?tag="+tag+"&infoSadId="+sadId+"&time="+time+"\">";
		innerStr += "<span class=\"Emphasis\">详情>></span></a></td></tr>";
		innerStr += "<tr><td height=\"1\" colspan=\"8\" background=\"images/tiao1.gif\"></td></tr>";
		
	}
	innerStr += "</table>";
	
	tableStr.innerHTML = innerStr;
}

function delSADList(){
	var del = document.getElementById("dynamicSAD");
	if (del != null) {
	while (del.hasChildNodes()) {
		del.removeChild(del.firstChild);
	}
	}
}

function onImgClickSAD(tag){
	sendRequestSAD('sadOfAjax?tag='+tag,tag);
}