function setcoks(data){
	data=data.split("|");
	if(data[0]=="OK"){
		$("logn").style.display="none";	
		$("loged").style.display="";
		$("showname").innerHTML=data[1];
	}else{
		alert("Sorry!Login Error!");
	}
}
function checkssion(data){
	data=data.split("|");
	if(data[0]=="OK"){
		$('logn').style.display="none";	
		$('loged').style.display="";	
		$("showname").innerHTML=data[1];
	}else{
		$('logn').style.display="";	
		$('loged').style.display="none";	
	}
}
function login(){
	var str="smail="+$('smail').value;
	str+="&pass="+$('pass').value;
	Ajax("/login.php",true,10,"POST",function(){setcoks(arguments[0])},str);
}
isMail=function(mstr){
	var str=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	return str.test(mstr);
}
isNum=function(mstr){
	var str=/^[\d]+\.?\d*$/;
	return str.test(mstr);
}
function showReg(){
	var ms=[];
	ms.push('<table width="503" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"  class="mtb">');
	ms.push('<tr>');
	ms.push('<td height="20" colspan="2" bgcolor="#EAEAEA">');
	ms.push('<div style="float:left;font-size:12px;font-weight:bold;">Registration</div>');
	ms.push('<div style="float:right;cursor:pointer;" onClick="$(\'popwindow\').style.display=\'none\';$(\'poswindow\').style.display=\'none\';">【Close】</div></td>');
	ms.push('</tr><tr>');
	ms.push('<td width="115" height="20" align="right">Name:</td>');
	ms.push('<td width="388" height="20"><input name="usname" type="text" id="usname" style="width:200px;" /></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" align="right">E_Mail:</td>');
	ms.push('<td height="20"><input name="email" type="text" id="email" style="width:200px;" /></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" align="right">Password:</td>');
	ms.push('<td height="20"><input name="pass" type="password" id="pass" style="width:200px;" /></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" align="right">Verify Password:</td>');
	ms.push('<td height="20"><input name="pass1" type="password" id="pass1" style="width:200px;" /></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" align="right">Tel:</td>');
	ms.push('<td height="20"><input name="tel" type="text" id="tel" style="width:200px;" /></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" align="right">Fax:</td>');
	ms.push('<td height="20"><input name="fax" type="text" id="fax" style="width:200px;" /></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" align="right">Address:</td>');
	ms.push('<td height="20"><input name="adds" type="text" id="adds" style="width:400px;" /></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" colspan="2" align="center"><input type="button" value="GO" onClick="reg();" /><input type="reset" value="Clear" /></td>');
	ms.push('</tr></table>');
  	$("smemo").innerHTML=ms.join("");
	$('popwindow').style.width=window.document.body.offsetWidth;
	$('popwindow').style.height=window.document.body.offsetHeight;
	$('popwindow').style.display='';
	$('poswindow').style.display='';
}
function postCart(){
	window.location.href="#";
	var ms=[];
	ms.push('<table width="503" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"  class="mtb"><tr>');
	ms.push('<td height="20" colspan="2" bgcolor="#EAEAEA">');
	ms.push('<div style="float:left;font-size:12px;font-weight:bold;">Inquire now</div>');
	ms.push('<div style="float:right;cursor:pointer;" onClick="$(\'popwindow\').style.display=\'none\';$(\'poswindow\').style.display=\'none\';">【Close】</div>');
	ms.push('</td></tr><tr>');
	ms.push('<td width="115" height="20" align="right">Name:</td>');
	ms.push('<td width="388" height="20"><input name="usname" type="text" id="usname" style="width:200px;" /></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" align="right">E_Mail:</td>');
	ms.push('<td height="20"><input name="email" type="text" id="email" style="width:200px;" /></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" align="right">Tel:</td>');
	ms.push('<td height="20"><input name="tel" type="text" id="tel" style="width:200px;" /></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" align="right">Fax:</td>');
	ms.push('<td height="20"><input name="fax" type="text" id="fax" style="width:200px;" /></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" align="right" valign="top">Message:</td>');
	ms.push('<td height="20"><textarea name="msg" rows="5" id="msg" style="width:300px;"></textarea></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" colspan="2">Products List:</td>');
	ms.push('</tr><tr>');
	ms.push('<td height="25" colspan="2">');
			ms.push("<div style='border-bottom:1px #E1E1E1;font-size:12px;width:100%' id='pids"+i+"'>");
				ms.push("<div style='float:left;width:60px;height:20px;line-height:20px;text-align:center;'>");
				ms.push("Picture");
				ms.push("</div>");
				ms.push("<div style='float:left;width:120px;height:20px;line-height:20px;overflow:hidden;text-align:center;'>");
				ms.push("Name");
				ms.push("</div>");
				//ms.push("<div style='float:left;width:60px;height:20px;line-height:20px;text-align:center;'>");
                //ms.push("No.");
				//ms.push("</div>");
				ms.push("<div style='float:left;width:60px;height:20px;line-height:20px;overflow:hidden;text-align:center;'>");
				ms.push("Operate");
				ms.push("</div>");
			ms.push("</div>");
	ms.push('</td>');
	ms.push('</tr><tr>');
	ms.push('<td height="25" colspan="2" id="product_list">');
	var s=HL.Cookie.Get("products");
	var str=[];
	var tmp="";
	if(s!=""){
		s=s.split("|||");
		for(var i=0;i<s.length;i++){
			tmp=s[i];
			tmp=tmp.split("||");
			ms.push("<div style='border-bottom:1px #E1E1E1;font-size:12px;width:100%' id='pids"+i+"'>");
				ms.push("<div style='float:left;width:60px;height:20px;line-height:20px;text-align:center;'>");
				ms.push("<img src='"+tmp[0]+"' width='20' height='20'>");
                ms.push("<input type=\"hidden\" name=\"p_img_"+i+"\" id=\"p_img_"+i+"\" value=\""+tmp[0]+"\">");
				ms.push("</div>");
				ms.push("<div style='float:left;width:120px;height:20px;line-height:20px;overflow:hidden;text-align:center;'>");
				ms.push(tmp[1]);
				ms.push("<input type=\"hidden\" name=\"p_id_"+i+"\" id=\"p_id_"+i+"\" value=\""+tmp[1]+"\">");
				ms.push("</div>");
				//ms.push("<div style='float:left;width:60px;height:20px;line-height:20px;text-align:center;'>");
                //ms.push("<input style='width:40px;height:20px;line-height:20px;' size=\"6\" maxlength=\"8\" type=\"text\" name=\"p_no_"+i+"\" id=\"p_no_"+i+"\" value=\"1\">");
				//ms.push("</div>");
				ms.push("<div style='float:left;width:60px;height:20px;line-height:20px;cursor:pointer;text-align:center;' onClick=\"delCart(\'"+tmp[1]+"\');$(\'pids"+i+"\').innerHTML='';\">");
				ms.push("【DEL】");
				ms.push("</div>");
			ms.push("</div>");
		}
	}
	ms.push('<input type=\"hidden\" name=\"pvaule\" id=\"pvaule\" value=\"'+s.length+'\"></td>');
	ms.push('</tr><tr>');
	ms.push('<td height="20" colspan="2" align="center"><input type="button" value="GO" onClick="sPost();" /><input type="reset" value="Clear" /></td>');
	ms.push('</tr></table>');
    $("smemo").innerHTML=ms.join("");
	$('popwindow').style.width=window.document.body.offsetWidth;
	$('popwindow').style.height=window.document.body.offsetHeight;
	$('popwindow').style.display='';
	$('poswindow').style.display='';
}
function sPost(){
	if($('usname').value==""){
		alert("Name Error!");
		$('usname').focus();
		return false;
	}
	if($('email').value==""||!isMail($('email').value)){
		alert("E_Mail Error!");
		$('email').focus();
		return false;
	}
	var str="uname="+$('usname').value;
	str+="&email="+$('email').value;
	str+="&tel="+$('tel').value;
	str+="&fax="+$('fax').value;
	str+="&msg="+$('msg').value;
	var img=[];
	var nid=[];
	var nno=[];
	var p=parseInt($("pvaule").value);
	for(var i=0;i<p;i++){
		//if(!isNum($('p_no_'+i).value)){
		//	alert('No. Error!');
		//	return false;
		//}
		img.push($('p_img_'+i).value);
		//nno.push($('p_no_'+i).value);
		nid.push($('p_id_'+i).value);
	}
	if(nid.join("")==""){
		alert("Please Choose Product!");
		return false;
	}
	str+="&p_img="+img.join("|");
	str+="&p_id="+nid.join("|");
	//str+="&p_num="+nno.join("|");
	img=null;
	nid=null;
	nno=null;
	var ms=[];
	ms.push('<table width="503" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"  class="mtb"><tr>');
	ms.push('<td height="100" colspan="2" align="center">請等待,系統正在處理你的詢價!</td>');
	ms.push('</tr></table>');
	$("smemo").innerHTML=ms.join("");
	Ajax("/spost.php",true,10,"POST",function(){postCancel(arguments[0])},str);
}
function postCancel(test){
	HL.Cookie.Del("products","/");
	alert(test);
	$('popwindow').style.display='none';
	$('poswindow').style.display='none';
	$("pro_list").innerHTML="";
	$("autopro_list").style.display="none";
}
function reg(){
	if($('email').value==""||!isMail($('email').value)){
		alert("E_Mail Error!");
		$('email').focus();
		return false;
	}
	if($('pass').value==""||$('pass1').value==""||$('pass').value!=$('pass1').value){
		alert("Password Error!");
		$('pass').focus();
		return false;
	}
	var str="usname="+$('usname').value;
	str+="&email="+$('email').value;
	str+="&pass="+$('pass').value;
	str+="&tel="+$('tel').value;
	str+="&fax="+$('fax').value;
	str+="&adds="+$('adds').value;
	Ajax("/reg.php",true,10,"POST",function(){regs(arguments[0])},str);
}
function regs(data){
	data=data.split("|");
	if(data[0]=="OK"){
		$('popwindow').style.display='none';
		$('poswindow').style.display='none';
		$('usname').value="";
		$('email').value="";
		$('pass').value="";
		$('tel').value="";
		$('fax').value="";
		$('adds').value="";
		alert("OK!");
	}else{
		alert("Sorry!Email Error!");
	}
}
function delCart(str){
	var s=HL.Cookie.Get("products");//GetCookie("products");
	var tmp=[];
	var m;
	if(s!=""){
		s=s.split("|||");
		for(var i=0;i<s.length;i++){
			m=s[i];
			if(m.indexOf(str)<=0)tmp.push(s[i]);
		}
	}
	if(tmp.length>0)HL.Cookie.Set("products",tmp.join("|||"),1440,"/");//SetCookie("products",tmp.join("|||"),24);
	else HL.Cookie.Del("products","/");
	get_Pro_List();
}
function get_Pro_List(){
	var s=HL.Cookie.Get("products");
	var str=[];
	var tmp="";
	if(s!=""){
		s=s.split("|||");
		str.push("<div style='clear:both;border:1px #E1E1E1 solid;font-size:12px;width:180px;height:20px;'>"+s.length+"Items In your Cart</div>");
		for(var i=0;i<s.length;i++){
			tmp=s[i];
			tmp=tmp.split("||");
			str.push("<div style='clear:both; width:180px; height:23px; border:1px #E1E1E1 solid; border-top:0px; font-size:12px;'>");
				str.push("<div style='float:left;width:30px;height:20px;line-height:20px;'>");
				str.push("<img src='"+tmp[0]+"' width='20' height='20'>");
				str.push("</div>");
				str.push("<div style='float:left;width:100px;height:20px;line-height:20px;overflow:hidden;'>");
				str.push(tmp[1]);
				str.push("</div>");
				str.push("<div style='float:left;width:50px;height:20px;line-height:20px;cursor:pointer;' onClick=\"delCart('"+tmp[1]+"');\">");
				str.push("【DEL】");
				str.push("</div>");
			str.push("</div>");
		}
		$("pro_list").innerHTML=str.join("");
		$("autopro_list").style.display="";
	}else{
		$("pro_list").innerHTML="";
		$("autopro_list").style.display="none";
	}
}