// JavaScript Document
function Ajax()
{
    var xmlHttp=null;
    if(window.XMLHttpRequest)
     {//非IE内核浏览器
         xmlHttp=new XMLHttpRequest();
     }
    else if(window.ActiveXObject)
     {//IE内核浏览器
        try
         {//IE6.0
             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
         }
        catch(e1)
         {
            try
             {
                 xmlHttp=new ActiveXObject("MSXML2.XMLHTTP");
             }
            catch(e2)
             {
                try
                 {
                     xmlHttp=new ActiveXObject("MSXML3.XMLHTTP");
                 }
                catch(e3)
                 {
                     alert("创建Ajax失败："+e3)
                 }
             }
         }
     }
    else
     {//未知浏览器
         alert("未能识别的浏览器");
     }
    return xmlHttp;
}

function ajaxpage()
{
	var dom = document.getElementById('index_tech');
	var xmlHttp = new Ajax();
	var url = 'index_tech.php';
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xmlHttp.send();
	xmlHttp.onreadystatechange=	function(){
		if(xmlHttp.readyState==1){dom.innerText="正在连接服务器......";}
		else if(xmlHttp.readyState==2 || xmlHttp.readystate==3){dom.innerText="正在读取数据......";}
		else if(xmlHttp.readyState==4)
		{		
			if(xmlHttp.status==200)dom.innerHTML=xmlHttp.responseText;
		}
	}
}

function check_login()
{
		var dom1 = document.getElementById("login_div_1");
		var dom2 = document.getElementById("login_div_2");
		var xmlHttp = new Ajax();
		var url = "/loginstat.php"; 	
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send(null);
		xmlHttp.onreadystatechange=	function()
		{
    		if(xmlHttp.readyState==4)
			{
				if(xmlHttp.status==200)
				{
						if(xmlHttp.responseText=="1"){
							dom1.style.display='none';
							dom2.style.display='block';
						}else{
							dom2.style.display='none';
							dom1.style.display='block';							
						}
				}
			}	
		}
}

function check_coupon()
{
		var dom = document.getElementById("coupon_span");
		var code = document.getElementById("code_input").value;
		var xmlHttp = new Ajax();
		var url = "check_coupon.php"; 	
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send("id="+code);
		xmlHttp.onreadystatechange=	function()
		{
    		if(xmlHttp.readyState==4)
			{
				if(xmlHttp.status==200)
				{
						dom.innerHTML=xmlHttp.responseText;
				}
			}	
		}
}


function clear_cart()
{
		var dom = document.getElementById("txtbox");
		var xmlHttp = new Ajax();
		var url = "/addtocart.php?action=clear_cart"; 	
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send(null);
		xmlHttp.onreadystatechange=	function()
		{
    		if(xmlHttp.readyState==4)
			{
				if(xmlHttp.status==200)
				{
						dom.innerHTML=xmlHttp.responseText;
				}
			}	
		}
}

function check_repeat(theid){
	var xmlHttp = new Ajax();
	var url = "/check_repeat.php?action=check_repeat"; 	
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xmlHttp.send("id="+theid);
	xmlHttp.onreadystatechange=	function()
	{
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{
				if(xmlHttp.responseText=="1"){
					document.getElementById('cart_tr_'+theid).className='alert_tr';
				}
			}
		}	
	}
}


function addtocart(theid)
{
	var dom = document.getElementById("txtbox");
	var xmlHttp = new Ajax();
	var url = "/addtocart.php?action=add"; 	
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xmlHttp.send("id="+theid);
	xmlHttp.onreadystatechange=	function()
	{
		if(xmlHttp.readyState==4)
		{
			if(xmlHttp.status==200)
			{
				dom.innerHTML=xmlHttp.responseText;
			}
		}	
	}		
}



function addtocart2(theid)
{
		var dom = window.opener.document.getElementById("txtbox");
		var xmlHttp = new Ajax();
		var url = "/addtocart.php?action=add"; 	
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send("id="+theid);
		xmlHttp.onreadystatechange=	function()
		{
    		if(xmlHttp.readyState==4)
			{
				if(xmlHttp.status==200)
				{
						dom.innerHTML=xmlHttp.responseText;
				}
			}	
		}
}


function bookmark(theid)
{
		//var dom = document.getElementById("txtbox");
		var xmlHttp = new Ajax();
		var url = "/addtocart.php?action=bookmark"; 	
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send("id="+theid);
		xmlHttp.onreadystatechange=	function()
		{
    		if(xmlHttp.readyState==4)
			{
				if(xmlHttp.status==200)
				{
						//dom.innerHTML=xmlHttp.responseText;
						alert(xmlHttp.responseText);
				}
			}	
		}
}


function remove(theid)
{
		var dom = document.getElementById("txtbox");
		var xmlHttp = new Ajax();
		var url = "/addtocart.php?action=remove"; 	
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send("id="+theid);
		xmlHttp.onreadystatechange=	function()
		{

    		if(xmlHttp.readyState==4)
			{
				if(xmlHttp.status==200)
				{
						dom.innerHTML=xmlHttp.responseText;
				}
			}	
		}	
}

function q_update(theid,q)
{
		if(isNaN(q)){alert("请输入正整数!");return false}
		if(q<1){alert("请输入正整数!");return false}
		var dom = document.getElementById("txtbox");
		var xmlHttp = new Ajax();
		var url = "/addtocart.php?action=update"; 	
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send("id="+theid+"&q="+q);
		xmlHttp.onreadystatechange=	function()
		{
    		if(xmlHttp.readyState==4)
			{
				if(xmlHttp.status==200)
				{
						dom.innerHTML=xmlHttp.responseText;
				}
			}	
		}	
}

function order_deal(order_id)
{
		var xmlHttp = new Ajax();
		var url = "/add_to_order.php"; 	
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send("order_id="+order_id);		
}

function myhide(div_id)
{
	var dom = document.getElementById(div_id);
	dom.style.display='none';
}

function open_window(url){
	window.open(url,'new_window','width=560,height=620,left=0,top=0,toolbar=0,scrollbars=0');
}

function check_all(obj,cName)
{
    var checkboxs = document.getElementsByName(cName);
    for(var i=0;i<checkboxs.length;i++){checkboxs[i].checked = obj.checked;}
}
