// JavaScript Document

function loadimg(id)
{	
	var img = document.getElementById(id);
	img.src = 'imgcode.php?seed='+Math.random();
}

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 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 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 set_small_cat(theid)
{
		//alert(theid);
		var dom = document.getElementById("select2");
		var xmlHttp = new Ajax();
		var url = "/small_cat.php";
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send("id="+theid);
		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 set_city(proid)
{
		//alert(proid);
		var dom = document.getElementById("city_select");
		var xmlHttp = new Ajax();
		var url = "set_city.php";
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send("proid="+proid);
		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_username()
{
	var dom = document.getElementById("span1");
	if(form1.username.value.length<4){
		dom.innerHTML="<img src=/images/bad.gif align=absmiddle>至少4个字符！";
		return false;
	}
	
		var xmlHttp = new Ajax();
		username = document.form1.username.value;
		var url = "check_username.php"; 
		
		
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send("username="+username);
   	 	
   	 	//xmlHttp.send(null);
		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)
				{
					if(xmlHttp.responseText==0){dom.className='myred';dom.innerHTML="<img src=/images/bad.gif align=absmiddle>用户名已经被占用";}
					if(xmlHttp.responseText==1){dom.className='mygreen';dom.innerHTML="<img src=/images/good.gif align=absmiddle>该用户名可用！";}
				}
			}
			
		}		
}

function check_email()
{
	var dom = document.getElementById("span2");
	var re = /(\S)+[@]{1}(\S)+[.]{1}(\w)+/;
	if(form1.email.value.length<6){
		dom.innerHTML="<img src=/images/bad.gif align=absmiddle>至少6个字符！";
		return false;
	}
	else if(!re.test(document.form1.email.value))
	{
		dom.innerHTML="<img src=/images/bad.gif align=absmiddle>电子邮件格式错误！";
		return false;
	}
	
		var xmlHttp = new Ajax();
		email = document.form1.email.value;
		var url = "check_email.php"; 
		
		
		xmlHttp.open("POST",url,true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
   	 	xmlHttp.send("email="+email);
   	 	
   	 	//xmlHttp.send(null);
		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)
				{
					if(xmlHttp.responseText==0){dom.className='myred';dom.innerHTML="<img src=/images/bad.gif align=absmiddle>邮件地址已经被占用";}
					if(xmlHttp.responseText==1){dom.className='mygreen';dom.innerHTML="<img src=/images/good.gif align=absmiddle>该邮件地址可用！";}
				}
			}
			
		}		
}

function p100()
{
	if(form1.p1.value.length>5){
		document.getElementById("span3").className='mygreen';
		document.getElementById("span3").innerHTML="<img src=/images/good.gif align=absmiddle>密码正确";		
	}else{
		document.getElementById("span3").className='myred';
		document.getElementById("span3").innerHTML="<img src=/images/bad.gif align=absmiddle>至少6个字符";
	}	
}

function p200()
{
	
	if(form1.p2.value==form1.p1.value){
		document.getElementById("span4").className='mygreen';
		document.getElementById("span4").innerHTML="<img src=/images/good.gif align=absmiddle>确认密码正确";
	}else{
		document.getElementById("span4").className='myred';
		document.getElementById("span4").innerHTML="<img src=/images/bad.gif align=absmiddle>确认密码不匹配";
	}
}
