
function getElement(name) {
	if (document.all) {
		return document.all(name);
	}
	return document.getElementById(name);
}

var check_error='check_error';
var check_success='check_success';

var ratingMsgs = new Array(6);
var ratingMsgColors = new Array(6);
var barColors = new Array(6);

ratingMsgs[0] = "太短";
ratingMsgs[1] = "弱";
ratingMsgs[2] = "一般";
ratingMsgs[3] = "很好";
ratingMsgs[4] = "极佳";
ratingMsgs[5] = ""; // 未评级

ratingMsgColors[0] = "#676767";
ratingMsgColors[1] = "#aa0033";
ratingMsgColors[2] = "#f5ac00";
ratingMsgColors[3] = "#6699cc";
ratingMsgColors[4] = "#008000";
ratingMsgColors[5] = "#676767";

barColors[0] = "#dddddd";
barColors[1] = "#aa0033";
barColors[2] = "#ffcc33";
barColors[3] = "#6699cc";
barColors[4] = "#008000";
barColors[5] = "#676767";

var tipsmsg=new Array();

tipsmsg[0]="用户名由2-10个字符组成。";
tipsmsg[1]="请正确输入用户名。";
tipsmsg[2]=""; // 正在检测你输入的帐户是否可用。
tipsmsg[3]="用户名已经有人注册了。";
tipsmsg[4]="恭喜！你的用户名符合要求，并可以使用。";
tipsmsg[25]="用户名不符合要求，请输入2-10个字符。";

tipsmsg[10]="不少于6个字符，且区分大小写。";
tipsmsg[11]="请输入6-16个字符的密码。";
tipsmsg[12]="密码设置正确。";
tipsmsg[28]="禁止使用纯数字密码。";

tipsmsg[13]="请再输入一遍你上面填写的密码。";
tipsmsg[14]="密码两次校验不吻合,请检查后重新输入。";
tipsmsg[15]="必须先正确填写密码。"
tipsmsg[16]="密码符合要求。";

tipsmsg[20]="请输入E-mail地址。";
tipsmsg[21]="正在检测你的E-mail地址是否可用。";
tipsmsg[22]="此邮箱已经有人用过了。";
tipsmsg[23]="E-mail地址格式有错误，请重新填写。";
tipsmsg[24]="E-mail地址填写正确。";

tipsmsg[30]="校验失败。";

var userNameRE = new RegExp("^[\u0391-\uFFE5a-zA-Z0-9_]*$");
var passwordRE = new RegExp("^[0-9]+$");
var emailRE = new RegExp("^[\\w-_\\.]+@([a-z|0-9|-]+\\.)+[a-z]{2,5}$");

var userNameHoldValue = Array('', 0, 'tips-default');
var emailHoldValue = Array('', 20, 'tips-default');

function changeTips(eleId, msgId, styles) {
	obj = $(eleId + '_tips');
	obj.innerHTML = tipsmsg[msgId];
	obj.className = styles;
}

function checkUserName(checkObj) {
	var checkValue = checkObj.value.strip();
	if(userNameHoldValue[0] != checkValue) {
		if(checkValue.length < 2 || checkValue.length > 10) {
			changeTips('userNameId', 25, check_error);
			userNameHoldValue = Array(checkValue, 25, check_error);
		} else if(!(userNameRE.test(checkValue))) {
			changeTips('userNameId', 1, check_error);
			userNameHoldValue = Array(checkValue, 1, check_error);
		} else {
			changeTips('userNameId', 2, 'tips-loading');
			userNameHoldValue = Array(checkValue, 2, 'tips-loading');
			remoteCheck('1', checkValue);
		}
	} else {
		if(checkValue == "") {
			changeTips('userNameId', 1, check_error);
			userNameHoldValue = Array(checkValue, 1, check_error);
		} else {
			changeTips('userNameId', userNameHoldValue[1], userNameHoldValue[2]);
		}
	}
}

function checkPassword(checkObj) {
	if(checkObj.value.length < 6 || checkObj.value.length > 16) {
		changeTips('passwordId', 11, check_error);
	} else {
		changeTips('passwordId', 16, check_success);
	}
	remoteCheck('3',checkObj.value);
}

function checkRePassword(checkObj) {
	if(checkObj.value.length < 6 || checkObj.value.length > 16) {
		changeTips('verifyPasswordId', 11, check_error);
	} else if(checkObj.value != $('passwordId').value) {
		changeTips('verifyPasswordId', 14, check_error);
	} else {
		changeTips('verifyPasswordId', 16, check_success);
	}
}

function checkEmail(checkObj) {
	if(emailHoldValue[0] != checkObj.value) {
		if(!emailRE.test(checkObj.value)) {
			changeTips('emailId', 23, check_error);
			emailHoldValue = Array(checkObj.value, 23, check_error);
		} else {
			changeTips('emailId', 21, 'tips-loading');
			emailHoldValue = Array(checkObj.value, 21, 'tips-loading');
			remoteCheck('2',checkObj.value);
		}
	} else {
		if(checkObj.value == "") {
			changeTips('emailId', 20, check_error);
		} else {
			changeTips('emailId', emailHoldValue[1], emailHoldValue[2]);
		}
	}
}

function remoteCheck(checkType, checkValue) {
	var checkUrl = '/dhtml/registerValidate.html';
	var params = 'checkType=' + checkType;
	var processResult = null;
	switch(checkType) {
	case '1' :
		params += '&userName=' + checkValue;
		processResult = processCheckUserNameResult;
		break;
	case '2' :
		params += '&email=' + checkValue;
		processResult = processCheckEmailResult;
		break;
	case '3' :
		params += '&password=' + checkValue;
		processResult = processCheckPasswordResult;
		break;
	}
	new Ajax.Request(checkUrl, {
		method: 'post', postBody: '' , parameters: params
			, onSuccess: processResult
	});
}

function processCheckUserNameResult(transport, json) {
	var jsonObj = transport.responseText.evalJSON();
	var checkResult = jsonObj.resultCode;

	if(checkResult != '') {
		if(checkResult == '4') {
			changeTips('userNameId', 4, check_success);
			userNameHoldValue = Array(userNameHoldValue[0], 4, check_success);
	 	}
		if(checkResult == '3') {
			changeTips('userNameId', 3, check_error);
			userNameHoldValue = Array(userNameHoldValue[0], 3, check_error);
		}
		if(checkResult == '30') {
			changeTips('userNameId', 30, check_error);
			userNameHoldValue = Array(userNameHoldValue[0], 30, check_error);
		}
	}
}

function processCheckEmailResult(transport, json) {
	var jsonObj = transport.responseText.evalJSON();
	var checkResult = jsonObj.resultCode;
	if(checkResult != '') {
		if(checkResult == '24') {
	 		changeTips('emailId', 24, check_success);
	 		emailHoldValue = Array(emailHoldValue[0], 24, check_success);
	 	}
		if(checkResult == '22') {
			changeTips('emailId', 22, check_error);
			emailHoldValue = Array(emailHoldValue[0], 22, check_error);
		}
		if(checkResult == '30') {
			changeTips('emailId', 30, check_error);
			emailHoldValue = Array(emailHoldValue[0], 30, check_error);
		 }
	}
}

function processCheckPasswordResult(transport, json) {
	var jsonObj = transport.responseText.evalJSON();
	var checkResult = jsonObj.resultCode;

	var posbar = getElement("posBar");
	var negbar = getElement("negBar");
	var passwdRating = getElement("passwdRating");
	var barLength = getElement("passwdBar").width;

	var passwordId = document.getElementById("passwordId");
	if(passwordId.value != "") {
		rating = parseInt(checkResult);
		DrawBar(rating);
	}
}

function DrawBar(rating) {
	var posbar = getElement('posBar');
	var negbar = getElement('negBar');
	var passwdRating = getElement('passwdRating');
	var barLength = getElement('passwdBar').width;

	if (rating >= 0 && rating <= 4) {//We successfully got a rating
		posbar.style.width = barLength / 4 * rating + "px";
		negbar.style.width = barLength / 4 * (4 - rating) + "px";
	} else {
		posbar.style.width = "0px";
		negbar.style.width = barLength + "px";
		rating = 5; // Not rated Rating
	}
	posbar.style.background = barColors[rating];
	passwdRating.innerHTML = "<font color='" + ratingMsgColors[rating] + "'>" + ratingMsgs[rating] + "</font>";
}

function ResetPasswordBar() {
	var posbar = getElement('posBar');
	var negbar = getElement('negBar');
	var passwdRating = getElement('passwdRating');
	var barLength = getElement('passwdBar').width;

	posbar.style.width = "0px";
	negbar.style.width = barLength + "px";
	passwdRating.innerHTML = "";
}
function sendPassword(){
			var  userName = document.registerFormId.userName.value;
			if(userName==""){
				alert("请输入用户名!");
				return 0;
			}
			var str1="/des/user/sendPassword.do?userName="+userName;
			window.location.href(str1);
		}
function fucCheckTEL(TEL)     
{     
var i,j,strTemp;     
strTemp="0123456789,";     
for (i=0;i<TEL.length;i++)     
{     
j=strTemp.indexOf(TEL.charAt(i));     
if (j==-1)     
{     
//说明有字符不合法     
return 0;     
}     
}     
//说明合法     
return 1;     
}    

 function checkForm2() {
	var userNameId = document.getElementById("xingming");
	var zhengjian = document.getElementById("zhengjian");
	var danwei = document.getElementById("danwei");
	var dianhua = document.getElementById("dianhua");
	var dizhi = document.getElementById("dizhi");
	var youbian = document.getElementById("youbian");
	var emailId = document.getElementById("youxiang");
	var chuanzhen = document.getElementById("chuanzhen");
	var shouji = document.getElementById("shouji");
	if(userNameId.value == "") {
		alert("姓名不能为空!");
		userNameId.focus() ;
		return false;
	}
	
	if(zhengjian.value == "") {
		alert("证件不能为空!");
		zhengjian.focus() ;
		return false;
	}
	if(danwei.value == "") {
		alert("单位不能为空!");
		danwei.focus() ;
		return false;
	}
	if(dianhua.value == "") {
		alert("固定电话不能为空!");
		dianhua.focus() ;
		return false;
	}
	if(dizhi.value == "") {
		alert("地址不能为空!");
		dizhi.focus() ;
		return false;
	}
	if(youbian.value == "") {
		alert("邮编不能为空!");
		youbian.focus() ;
		return false;
	}
	if(emailId.value == "") {
		alert("E-mail地址不能为空!");
		emailId.focus() ;
		return false;
	} else if(!emailRE.test(emailId.value)) {
		alert("E-mail地址格式有错误!");
		emailId.focus() ;
		return false;
	}
	if(chuanzhen.value == "") {
		alert("传真不能为空!");
		chuanzhen.focus() ;
		return false;
	}
	if(shouji.value == "") {
		alert("手机不能为空!");
		shouji.focus() ;
		return false;
	}
	if(fucCheckTEL(shouji.value)==0) {
		alert("手机只能输入数字!");
		shouji.focus() ;
		return false;
	}
	var submitId = document.getElementById("submitId");
	submitId.disabled = true;
 }

 function checkDoc(){
			var item = $('input[@name=shContents][@checked]').val();
		
			if(item==0){
			$("#shDesName1").attr("readonly", "true").css("background", "#BBB8B8" );
			$("#shDesPieces1").attr("readonly", "true").css("background", "#BBB8B8" );
			$("#shDesPrice1").attr("readonly", "true").css("background", "#BBB8B8" );
			$("#shDesTotal1").attr("readonly", "true").css("background", "#BBB8B8" );
			
			$("#shDesName2").attr("readonly", "true").css("background", "#BBB8B8"  );
			$("#shDesPieces2").attr("readonly", "true").css("background", "#BBB8B8"  );
			$("#shDesPrice2").attr("readonly", "true").css("background", "#BBB8B8"  );
			$("#shDesTotal2").attr("readonly", "true").css("background", "#BBB8B8"  );
			
			$("#shDesName3").attr("readonly", "true").css("background", "#BBB8B8"  );
			$("#shDesPieces3").attr("readonly", "true").css("background", "#BBB8B8"  );
			$("#shDesPrice3").attr("readonly", "true").css("background", "#BBB8B8"  );
			$("#shDesTotal3").attr("readonly", "true").css("background", "#BBB8B8"  );
		}else{
			$("#shDesName1").removeAttr("readonly").removeAttr("style");
			$("#shDesPieces1").removeAttr("readonly").removeAttr("style");
			$("#shDesPrice1").removeAttr("readonly").removeAttr("style");
			$("#shDesTotal1").removeAttr("readonly").removeAttr("style");
			
			$("#shDesName2").removeAttr("readonly").removeAttr("style");
			$("#shDesPieces2").removeAttr("readonly").removeAttr("style");
			$("#shDesPrice2").removeAttr("readonly").removeAttr("style");
			$("#shDesTotal2").removeAttr("readonly").removeAttr("style");
			
			$("#shDesName3").removeAttr("readonly").removeAttr("style");
			$("#shDesPieces3").removeAttr("readonly").removeAttr("style");
			$("#shDesPrice3").removeAttr("readonly").removeAttr("style");
			$("#shDesTotal3").removeAttr("readonly").removeAttr("style");
		}
		}
 function checkForm(type) {
	//var SAccount = document.getElementById("SAccount");

	var SAccount =$("#SAccount").val(); 

	var SCompany =$("#SCompany").val(); //document.getElementById("SCompany");
	var SAddress =$("#SAddress").val();// document.getElementById("SAddress");
	var SCity = $("#SCity").val();//document.getElementById("SCity");
	var SPost = $("#SPost").val();//document.getElementById("SPost");
	var SCountry = $("#SCountry").val();//document.getElementById("SCountry");
	var SAttn = $("#SAttn").val();//document.getElementById("SAttn");
	var SMobile = $("#SMobile").val();//document.getElementById("SMobile");
	var STel = $("#STel").val();//document.getElementById("STel");
	
	var CAccount = $("#CAccount").val();//document.getElementById("CAccount");
	var CCompany = $("#CCompany").val();//document.getElementById("CCompany");
	var CAddress = $("#CAddress").val();//document.getElementById("CAddress");
	var CCity = $("#CCity").val();//document.getElementById("CCity");
	var CPost = $("#CPost").val();//document.getElementById("CPost");
	var CCountry = $("#CCountry").val();//document.getElementById("CCountry");
	var CAttn = $("#CAttn").val();//document.getElementById("CAttn");
	var CMobile = $("#CMobile").val();//document.getElementById("CMobile");
	var CTel = $("#CTel").val();//document.getElementById("CTel");
	
	var shContents=$('input[@name=shContents][@checked]').val();

	var shDesName1 = $("#shDesName1").val();//document.getElementById("shDesName1");
	var shDesPieces1 = $("#shDesPieces1").val();//document.getElementById("shDesPieces1");
	var shDesPrice1 = $("#shDesPrice1").val();//document.getElementById("shDesPrice1");
	var shDesTotal1 = $("#shDesTotal1").val();//document.getElementById("shDesTotal1");
	var shNo = $("#shNo").val();//document.getElementById("shNo");
	var shWeight = $("#shWeight").val();//document.getElementById("shWeight");
	var shTotal = $("#shTotal").val();//document.getElementById("shTotal");
	var shPayment=$('input[@name=shPayment][@checked]').val();
	var rerult = true;




	//document.getElementById("show_type").value=type;


	if(SAccount == ""||SAccount==null) {
		$("#_SAccount").css("color", "#f00");
		rerult = false;
	}else{
		$("#_SAccount").removeAttr("style");
	}
	if(SCompany == ""||SCompany==null) {
		$("#_SCompany").css("color", "#f00");
		rerult = false;
	}else{
		$("#_SCompany").removeAttr("style");
	}
	if(SAddress == ""||SAddress==null) {
		$("#_SAddress").css("color", "#f00");
		rerult = false;
	}else{
		$("#_SAddress").removeAttr("style");
	}
	if(SCity == ""||SCity==null) {
		
			$("#_SCity").css("color", "#f00");
		rerult = false;
	}else{
		$("#_SCity").removeAttr("style");
	}
	if(SPost == ""||SPost==null) {
	
			$("#_SPost").css("color", "#f00");
	
		rerult = false;
	}else{
		$("#_SPost").removeAttr("style");
	}
	if(SCountry == ""||SCountry==null) {
	
			$("#_SCountry").css("color", "#f00");
	
		rerult = false;
	}else{
		$("#_SCountry").removeAttr("style");
	}
	if(SAttn == ""||SAttn==null) {
		
		$("#_SAttn").css("color", "#f00");
	
		rerult = false;
	}else{
		$("#_SAttn").removeAttr("style");
	}
	if(SMobile == ""||SMobile==null) {
		
		$("#_SMobile").css("color", "#f00");
	
		rerult = false;
	}else{
		$("#_SMobile").removeAttr("style");
	}
	if(STel == ""||STel==null) {
	
			$("#_STel").css("color", "#f00");
		rerult = false;
	}else{
		$("#_STel").removeAttr("style");
	}
	if(CCompany == ""||CCompany==null) {
		
			$("#_CCompany").css("color", "#f00");

		rerult = false;
	}else{
		$("#_CCompany").removeAttr("style");
	}
	if(CAddress == ""||CAddress==null) {
	
			$("#_CAddress").css("color", "#f00");
	
		rerult = false;
	}else{
		$("#_CAddress").removeAttr("style");
	}
	if(CCity == ""||CCity==null) {
		
			$("#_CCity").css("color", "#f00");
	
		rerult = false;
	}else{
		$("#_CCity").removeAttr("style");
	}
	if(CPost == ""||CPost==null) {
		
			$("#_CPost").css("color", "#f00"); 
	
		rerult = false;
	}else{
		$("#_CPost").removeAttr("style");
	}
	if(CCountry == ""||CCountry==null) {
		
			$("#_CCountry").css("color", "#f00");
	
		rerult = false;
	}else{
		$("#_CCountry").removeAttr("style");
	}
	if(CAttn == ""||CAttn==null) {
		
			$("#_CAttn").css("color", "#f00");
	
		rerult = false;
	}else{
		$("#_CAttn").removeAttr("style");
	}
	if(CMobile == ""||CMobile==null) {
		
			$("#_CMobile").css("color", "#f00");
	
		rerult = false;
	}else{
		$("#_CMobile").removeAttr("style");
	}
	if(CTel == ""||CTel==null) {
		
			$("#_CTel").css("color", "#f00");

		rerult = false;
	}else{
		$("#_CTel").removeAttr("style");
	}
	if(shContents == ""||shContents==null) {
	
			$("#_shContents").css("color", "#f00");

		rerult = false;
	}else{
		$("#_shContents").removeAttr("style");
	}
	if(shContents==1){
		if(shDesName1 == ""||shDesName1==null) {
			
				$("#_shDesName1").css("color", "#f00");
		
			rerult = false;
		}else{
		$("#_shDesName1").removeAttr("style");
		}
		if(shDesPieces1 == ""||shDesPieces1==null) {
		
				$("#_shDesPieces1").css("color", "#f00");
	
			rerult = false;
		}else{
		$("#_shDesPieces1").removeAttr("style");
		}
		if(shDesPrice1 == ""||shDesPrice1==null) {
			
				$("#_shDesPrice1").css("color", "#f00");
	
			rerult = false;
		}else{
		$("#_shDesPrice1").removeAttr("style");
		}
	
		if(shDesTotal1 == ""||shDesTotal1==null) {
		
				$("#_shDesTotal1").css("color", "#f00");
	
			rerult = false;
		}else{
		$("#_shDesTotal1").removeAttr("style");
		}
	}else{
		$("#_shDesName1").removeAttr("style");
		$("#_shDesPieces1").removeAttr("style");
		$("#_shDesPrice1").removeAttr("style");
		$("#_shDesTotal1").removeAttr("style");
	}
	if(shNo == ""||shNo==null) {
	
			$("#_shNo").css("color", "#f00");

		rerult = false;
	}else{
		$("#_shNo").removeAttr("style");
	}
	if(shWeight == ""||shWeight==null) {
	
		//document.getElementById("_shWeight").style.color = "#f00"; 
	$("#_shWeight").css("color", "#f00");
		rerult = false;
	}else{
		$("#_shWeight").removeAttr("style");
	}
	if(shTotal == ""||shTotal==null) {
	
		//document.getElementById("_shTotal").style.color = "#f00"; 
		$("#_shTotal").css("color", "#f00");
		rerult = false;
	}else{
		$("#_shTotal").removeAttr("style");
	}
	if(shPayment == ""||shPayment==null) {
	
		//document.getElementById("_shTotal").style.color = "#f00"; 
		$("#_shPayment").css("color", "#f00");
		rerult = false;
	}else{
		$("#_shPayment").removeAttr("style");
	}

	 $("#show_type").attr("value",type);
	 var _type= $("#show_type").val();
	
	if(rerult == false){
  
      var newElement="<div class=\"STYLE5\">There are one or more required fields that need to be filled in correctly.  <strong>They are now marked in red.<\/strong><\/div>"; 

     //document.getElementById('notice1')
     $("#notice1").innerHTML=newElement; 
 		//document.getElementById('notice1').style.color = "#f00";
 		$("#notice1").css("color", "#f00");
 		var newElement2="<div class=\"STYLE5\">请完成以下红色标出的 (*)必填项 部分.<\/div>"; 

       $("#notice2").innerHTML=newElement; 
 		
 		$("#notice2").css("color", "#f00");
 		alert("There are one or more required fields that need to be filled in correctly.数据填写不完整!");
 		return false;
	}
 	if (window.confirm("您确定要提交订单吗？are you sure to submit the order?") == false)
        return false;
   
   	document.billform.submit();
  	return(true); 
 }
