﻿//去除空格
String.prototype.trim = function() {	return this.replace(/^\s+|\s+$/g,"");}
String.prototype.ltrim = function() {	return this.replace(/^\s+/,"");}
String.prototype.rtrim = function() {	return this.replace(/\s+$/,"");}

function CharCheck(RegExpStr)
{
	var InputChar = String.fromCharCode(event.keyCode);
	if(RegExpStr.test(InputChar))
	{
		return true;
	}
	else
	{
		return false;
	}
}


function CheckEmail(email)
{
	var RegExpStr = /^([\w\_\-\.]{1,})(@)([\w\-\.]{1,})(\.)([a-zA-Z\.]{1,})$/;
	return RegExpStr.test(email);
}


function isIE(){ //ie? 
   if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1) 
    return true; 
   else 
    return false; 
} 

if(!isIE()){ //firefox innerText define
   HTMLElement.prototype.__defineGetter__("innerText", 
    function(){
     var anyString = "";
     var childS = this.childNodes;
     for(var i=0; i<childS.length; i++) {
      if(childS[i].nodeType==1)
       anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
      else if(childS[i].nodeType==3)
       anyString += childS[i].nodeValue;
     }
     return anyString;
    } 
   ); 
   HTMLElement.prototype.__defineSetter__("innerText", 
    function(sText){ 
     this.textContent=sText; 
    } 
   ); 
}

function checklogin(){
if(document.formlogin.Email.value==''){
alert('Please write down your E-mail.');
document.formlogin.Email.focus();
return false;
}

if(document.formlogin.Password.value==''){
alert('Please write down your password.');
document.formlogin.Password.focus();
return false;
}


return true;
}




//*注册*************************************************************************************

function checkreg(){


if(document.getElementById("Email").value.trim().length!=0)
  {
    if (!CheckEmail(document.getElementById("Email").value.trim()))
     {
	  document.getElementById("Email_Info").style.color='red';
      document.getElementById("Email_Info").innerText="* The Email address pattern is not correct!";
      document.getElementById("Email").focus();
      return false;
      }
	else
	 {
	  document.getElementById("Email_Info").style.color='';
      document.getElementById("Email_Info").innerText="*";
	 }  
	  
}
else
{
	document.getElementById("Email_Info").style.color='red';
	document.getElementById("Email_Info").innerText="* Email cannot be spatial!";
	document.getElementById("Email").focus();
	return false;
}
   
if(!checkuseremail(document.getElementById("Email").value))
{
   document.getElementById("Email_Info").style.color='red';
   document.getElementById("Email_Info").innerText="* This e-mail address has already been registered .";
   document.getElementById("Email").focus();
   return false;
}   

else
 {
  document.getElementById("Email_Info").style.color='';
  document.getElementById("Email_Info").innerText="*";
 }  

	if(document.formreg.Password.value.trim().length<6){
	document.formreg.Password.focus();
	document.getElementById("passwordmessage").style.color='#FF0000';
	document.formreg.vPassword.value='';
	document.getElementById("vPassword_Info").style.color='';
	document.getElementById("vPassword_Info").innerText="*";
	return false;
	}
	document.getElementById("passwordmessage").style.color='';
	
	
	if(document.formreg.Password.value!=document.formreg.vPassword.value){
	document.getElementById("vPassword_Info").style.color='red';
	document.getElementById("vPassword_Info").innerText="* Please write down the same password.";
	document.formreg.vPassword.focus();
	return false;
	}
	document.getElementById("vPassword_Info").innerText="";

//

if(document.formreg.FirstName.value.trim()==''){
document.getElementById("FirstName_Info").style.color='red';
document.getElementById("FirstName_Info").innerText="* Please write down your First Name.";
document.formreg.FirstName.focus();
return false;
}
document.getElementById("FirstName_Info").style.color='';
document.getElementById("FirstName_Info").innerText="*";

if(document.formreg.LastName.value.trim()==''){
document.getElementById("LastName_Info").style.color='red';
document.getElementById("LastName_Info").innerText="* Please write down your Last Name.";
document.formreg.LastName.focus();
return false;
}
document.getElementById("LastName_Info").style.color='';
document.getElementById("LastName_Info").innerText="*";



if(document.formreg.Address1.value==''){
document.getElementById("Address1_Info").style.color='red';
document.getElementById("Address1_Info").innerText="* Please write down your Shipping Address1.";
document.formreg.Address1.focus();
return false;
}
document.getElementById("Address1_Info").style.color='';
document.getElementById("Address1_Info").innerText="*";



return true;
}


function checkuseremail(obj)
{
function init()
{
if (window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
	
	try{
		var xml=init();
		xml.open("get","checkemail.php?email="+obj,false);
		xml.send("<a></a>");
		
		var strStatus=xml.responseText;
		if(strStatus=="1"){
			return false;
		}
	}catch(ex){
		alert(ex.message);
	}
	return true;
}



//*****************************************************************************************
//删除各种分类节点--------------------------------------------------------------
function CheckAll(form)
{
   for (var i=0;i<form.elements.length;i++)
   {
      var e = form.elements[i];
      e.checked = true;
   }
}

