var createxmlhttp=function(){
	try {return new ActiveXObject("Msxml5.XMLHTTP");}catch(e){}
	try {return new ActiveXObject("Msxml4.XMLHTTP");}catch(e){}
	try {return new ActiveXObject("Msxml3.XMLHTTP");}catch(e){}
	try {return new ActiveXObject("Msxml2.XMLHTTP");}catch(e){}
	try {return new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}
	try {return new XMLHttpRequest();}catch(e){}
	return null;
}


function getcp_en(cpid,cplb){
	if(cpid==""){
		document.getElementById("cplist").innerHTML="The wrong parameters";
		return;
	};
	document.getElementById("cplb").innerHTML=cplb;
	var xmlhttpobj = new createxmlhttp();
	if(xmlhttpobj){
		xmlhttpobj.open('get',"getcp_en.asp?cpid="+cpid+"&number="+Math.random(),true);
		xmlhttpobj.send(null);
		xmlhttpobj.onreadystatechange=function(){
			if(xmlhttpobj.readystate==4){
				if(xmlhttpobj.status==200){
					var html = xmlhttpobj.responseText;
					document.getElementById("cplist").innerHTML=html;
				}else{
					document.getElementById("cplist").innerHTML="Sorry, you request the page in question......";
				}
			}else{
				document.getElementById("cplist").innerHTML="Loading,please Waiting...";
			}
		}	
	}
}


function getdzsw_en(dzsw){
	if(dzsw==""){
		document.getElementById("cplist").innerHTML="The wrong parameters";
		return;
	};
	var xmlhttpobj = new createxmlhttp();
	if(xmlhttpobj){
		xmlhttpobj.open('get',"getdzsw_en.asp?word="+dzsw+"&number="+Math.random(),true);
		xmlhttpobj.send(null);
		xmlhttpobj.onreadystatechange=function(){
			if(xmlhttpobj.readystate==4){
				if(xmlhttpobj.status==200){
					var html = xmlhttpobj.responseText;
					document.getElementById("cplist").innerHTML=html;
				}else{
					document.getElementById("cplist").innerHTML="Sorry, you request the page in question...";
				}
			}else{
				document.getElementById("cplist").innerHTML="Loading,please Waiting...";
			}
		}	
	}
}

function Trim(){
	return this.replace(/\s+$|^\s+/g,"");
}
String.prototype.Trim=Trim;	

function getObject(elementId) { 	
	if (document.getElementById) { 
		return document.getElementById(elementId); 
	} else if (document.all) { 
		return document.all[elementId]; 
	} else if (document.layers) { 
		return document.layers[elementId]; 
	} 
}

function getObjValue(elementId){	
	if(getObject(elementId).value!=undefined)
		return getObject(elementId).value.Trim();
	else
		return "";
}




function sendSubmit() {	
	var xmlhttpobj = new createxmlhttp();
	if(xmlhttpobj&&checkForm()){
		getObject("submit").value="Sending...";
		getObject("submit").disabled=true;
		
		xmlhttpobj.open("POST", "books/AddBook.asp", true);
		xmlhttpobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		var aIdArray=new Array("flag="+Math.random());
		var aUserArr=["aname","company","country","add","website","email","tel","fax","productsclass","productname","remarks"];
		var argLen=aUserArr.length;
		for(i=0;i<argLen;i++){
			aIdArray[i+1]="&"+aUserArr[i]+"="+escape(getObjValue(aUserArr[i]));
		}
		var data =aIdArray.join('');
		xmlhttpobj.onreadystatechange=function(){
			if(xmlhttpobj.readyState==4){
				if(xmlhttpobj.status==200){
					if(xmlhttpobj.responseText==1){
						alert("Message success!");	
					}else{
						alert("* You will take the items, then submit the completed!");
					}

					getObject("submit").value="Send It";	
					getObject("submit").disabled=false;

					clearForm();				
				
				}else{
					alert("Network transmission error! Please try again!");	
				}
			}	
		}
    		xmlhttpobj.send(data);
  	}
}

function checkForm(){	
	if((getObjValue("aname")=="")||(getObjValue("company")=="")||(getObjValue("tel")=="")||(getObjValue("email")=="")){
		alert("* Not is Empty！");
		return false;
	}
	if(getObjValue("aname").length>20){
		alert("Name is Long!");
		return false;
	}

	if(getObjValue("email")!="" && !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(getObjValue("email"))){
		alert("E-mail Error！");
		return false;
	}
	return true;
}

function clearForm(){	
	getObject("aname").value="";
	getObject("company").value="";
	getObject("email").value="";
	getObject("add").value="";
	getObject("website").value="";
	getObject("tel").value="";
	getObject("fax").value="";
	getObject("productsclass").value="";
	getObject("productname").value="";
	getObject("remarks").value="";
	getObject("country").value="";
}
