/* ajax for product image */
// index ajax show product images

var webroot="http://www.gooptv.com"; // no '/' in the end


var xmlhttp;
// 创建xmlhttp对象函数
function createXMLHttpRequest(){
	// for IE
	if(window.ActiveXObject){
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest){
		xmlhttp=new XMLHttpRequest();
	}
}
// set cookie
function setCookie(sName,sValue,oExpires,sPath,sDomain,bSecure){
	var sCookie=sName+ "=" +encodeURIComponent(sValue);
	if(oExpires){
		sCookie+="; expires=" +oExpires.toGMTString();
	}
	if(sPath){
		sCookie+="; path=" +sPath;
	}
	if(sDomain){
		sCookie+="; domain=" +sDomain;
	}
	if(bSecure){
		sCookie+="; secure";
	}
	document.cookie=sCookie;
}

// delete cookie
function deleteCookie(sName,sPath,sDomain,bSecure){
	setCookie(sName,"",new Date(0),sPath,sDomain,bSecure);
}

function filter(obj){
	createXMLHttpRequest();
	var category=document.getElementById("category").value;
	var value=obj.options[obj.selectedIndex].value;
	if(value=="select"){
		return false;
	}
	var pageNo=document.getElementById("showpages").getElementsByTagName("span")[0].getAttribute("id");
	setCookie("filter",value);
	startRequest(category,value,pageNo);
}


function startRequest(category,value,pageNo){
	xmlhttp.open("GET",webroot+"/filter.php?category="+category+"&order="+value+"&PageNo="+pageNo,true);
	xmlhttp.setRequestHeader("If-Modified-Since","0");
	xmlhttp.send(null);
	xmlhttp.onreadystatechange=function(){
			if (xmlhttp.readyState==4){
				if (xmlhttp.status==200){
					var list=document.getElementById("list");
					list.innerHTML=xmlhttp.responseText;
				}
			}
	}
}