
var inputErrorClass ="notetrue";
var inputOkClass ="noteawoke";
var inputNormalClass ="note";
var infoboxWarningClass ="notetrue";
var infoboxErrorClass ="noteawoke";
var infoboxOkClass ="notetrue";
var infoboxHintClass ="note";
function formEle(required,datatype,parameter,infobox,errormsg,combine,status)
{
	this.r	= required;	
	this.d	= datatype;
	this.p	= parameter;
	this.i	= infobox;
	this.e	= errormsg;
	this.c = combine;
	this.s = status;
} 

var msgInfo= new Array();
msgInfo[0]= new Array('Select a username that is easy to remember.  It must be at least 4 characters long.  The first character must be a letter.  The other characters may consist of letters, numbers, and the underscore character.  The user name is not case-sensitive.', 'Username not filled in.', 'Must be at least 4 characters long.' ,'The first character must be a letter.','Valid characters are letters, numbers, and the underscore character.','This username is currently being used. Please select another username ');
var txtUsername = new formEle(true,"txtUsername",null,"txtUsername_info",msgInfo[0],"reg_username_info_check");

msgInfo[1]= new Array('This will be your prime email address.  You can use it instead of your user name to sign in.  IT CANNOT BE MODIFIED ONCE IT IS ACCEPTED.  This email address can only be used to create one LajoGroup account. ','Email not filled in.','You have not typed in a valid email address.','<span class=\"R\">This email address is currently being used. Please select another email address.<\/span>');
var txtEmail= new formEle(true,"txtEmail",null,"txtEmail_info",msgInfo[1],"reg_password_info_check");

msgInfo[2]= new Array('Re-type your email address to confirm that you have typed it correctly.  ','Re-type Email not filled in.' ,'You have not typed in a valid email address.' , 'This email address does not match the email address you typed in above.  Please try again.');
var txtReEmail	= new formEle(true,"txtReTypeEmail",null,"txtReEmail_info",msgInfo[2],"confirm_reg_password_info_check");

msgInfo[3]= new Array('Type in your password.  Your password is case-sensitive. The password must be at least six characters long.  If you forget it in the future, we can send a temporary password to your primary email address. This will allow you to sign in to modify your previous password.','Password not filled in.','<span class=\"R\">Password must have at least 6 code.<\/span>');
var txtPassword = new formEle(true,"txtPassword",null,"txtPassword_info",msgInfo[3],"DNS_info_check");

msgInfo[4]= new Array('Re-type your password to confirm that you have typed it correctly.','Re-type Pass not filled in.','The password does not match the password you typed in above.  Please try again.');
var txtRePassword= new formEle(true,"txtReTypePassword",null,"txtRePassword_info",msgInfo[4],"username2_info_check");

msgInfo[5]= new Array('','First Name not filled in.','First Name is a required field.');
var txtFirstname= new formEle(true,"txtFirstname",null,"txtFirstname_info",msgInfo[5],"reg_nickname_info_check");

msgInfo[6]= new Array('','Last Name not filled in.','Last Name is a required field.');
var txtLastname= new formEle(true,"txtLastname",null,"txtLastname_info",msgInfo[6],"reg_nickname_info_check");

msgInfo[7]= new Array('Type in the name of your business.  We will use this name to post your company on our site under “Find a Reseller” once you buy an XSKN product to resell. ','<span class=\"R\">Business name must input. <\/span>');
var txtBusinessName= new formEle(true,"txtBusinessName",null,"txtBusinessName_info",msgInfo[7],"reg_nickname_info_check");

msgInfo[8]= new Array('Type in your URL (the address of your web site), if you have one.  We will post this URL along with your business name on our site under “Find a Reseller”.','<span class=\"R\">URL must input.<\/span>');
var txtUrl= new formEle(true,"txtUrl",null,"txtUrl_info",msgInfo[8],"reg_nickname_info_check");

msgInfo[9]= new Array('','<span class=\"R\">Phone number must input.<\/span>');
var txtPhone= new formEle(true,"txtPhone",null,"txtPhone_info",msgInfo[9],"reg_nickname_info_check");

msgInfo[10]= new Array('','<span class=\"R\">Cell phone number must input.<\/span>');
var txtCellPhone = new formEle(true,"txtCellPhone",null,"txtCellPhone_info",msgInfo[10],"reg_nickname_info_check");

msgInfo[11]= new Array('','<span class=\"R\">City not filled in.<\/span>');
var txtCity= new formEle(true,"txtCity",null,"txtCity_info",msgInfo[11],"reg_nickname_info_check");

msgInfo[12]= new Array('Type in your Zip Code (may not be applicable in some countries, in which case it may be left blank).','<span class=\"R\">Zip Code not filled in.<\/span>','Please input correct Zip Code!');
var txtZipCode= new formEle(true,"txtZipCode",null,"txtZipCode_info",msgInfo[12],"reg_nickname_info_check");

msgInfo[13]= new Array('Type in the validation code that you see in the box below.','<span class=\"R\">Validation Code not filled in.<\/span>');
var txtValidationCode= new formEle(true,"txtValidationCode",null,"txtValidationCode_info",msgInfo[13],"reg_nickname_info_check");

msgInfo[14]= new Array('Select the country you are from.','You must select a Country.');
var ddlCountry= new formEle(true,"ddlCountry",null,"ddlCountry_info",msgInfo[14],"reg_nickname_info_check");

msgInfo[15]= new Array('Select your state, province, or region.','You must select a State/Province/Region.');
var ddlState= new formEle(true,"ddlState",null,"ddlState_info",msgInfo[15],"reg_nickname_info_check");

msgInfo[16]= new Array('To block email about promotions and discounts, please check <font color="#ff0000">do not send me email</font>.  You can change this setting later.','<span class=\"R\">sorry<\/span>');
var radiobtnSend = new formEle(true,"radiobtnSend",null,"radiobtnSend_info",msgInfo[16]);
var radiobtnNoSend = new formEle(true,"radiobtnNoSend",null,"radiobtnSend_info",msgInfo[16]);

msgInfo[17]= new Array('Type in your address. If you need more space use address below.','Address not filled in.','<span class=\"R\">Address must input.<\/span>');
var txtAddress1= new formEle(true,"txtAddress",null,"txtAddress1_info",msgInfo[17]);

msgInfo[18]= new Array('','');
var txtAddress2= new formEle(true,"txtAddress2",null,"txtAddress2_info",msgInfo[18]);

msgInfo[19]= new Array('Select Member Type','');
var rblMemberType_0 = new formEle(true,"rblSendemail_0",null,"rblMemberType_info",msgInfo[19]);
var rblMemberType_1 = new formEle(true,"rblSendemail_1",null,"rblMemberType_info",msgInfo[19]);
var rblMemberType_2 = new formEle(true,"rblSendemail_2",null,"rblMemberType_info",msgInfo[19]);
var rblMemberType_3 = new formEle(true,"rblSendemail_3",null,"rblMemberType_info",msgInfo[19]);
var rblMemberType_4 = new formEle(true,"rblSendemail_4",null,"rblMemberType_info",msgInfo[19]);

msgInfo[20]= new Array('Comment','<span class=\"R\">Comment not filled in.<\/span>');
var txtComment= new formEle(true,"txtComment",null,"txtComment_info",msgInfo[20]);



function initForm()
{
	var infobox;
	var x=document.getElementById("main1");
	if(!x) return;
	var y =x.getElementsByTagName("input");
	for(var i =0;i<y.length;i++)
	{
		if(y[i].type =="text" || y[i].type == "password" || y[i].type == "radio")
		{
			y[i].onfocus=getFocus; 
			y[i].onblur=lostFocus;
		}
	}
	
	var dropCountry = document.getElementById("ddlCountry");
	if(dropCountry != null)
	{
	dropCountry.onfocus = getFocus;
	dropCountry.onblur = lostFocus;
	}
	
	var dropState = document.getElementById("ddlState");
	if(dropState != null)
	{
	dropState.onfocus = getFocus;
	dropState.onblur = lostFocus;
	}
	
	var txtComment  = document.getElementById("txtComment");
	if(txtComment != null)
	{
	txtComment.onfocus = getFocus;
	txtComment.onblur = lostFocus;
	}
}

function getInfobox(obj) 
{
	if(obj.id)
	{
		if(eval(obj.id).i && document.getElementById(eval(obj.id).i)) return document.getElementById(eval(obj.id).i);
	}
	return;
}
function getInitStatus(obj)
{
	if(obj.id)
	{
	if(eval(obj.id).s || eval(obj.id).s==0 ) return eval(obj.id).s;
	}
	return;
}


function getErrorMsg(obj,errorCode) 
{
	if(obj.id)
	{
	if(eval(obj.id).e[errorCode]) return eval(obj.id).e[errorCode];
	}
	return;
}
function initStatus(obj,isinput)
{
	var infobox = getInfobox(obj); 
	var errorCode = getInitStatus(obj);
	if(infobox)
	{
		if(!errorCode || errorCode == 0)
		{ 
			infobox.className	= infoboxHintClass;
			infobox.innerHTML	= getErrorMsg(obj,0);
		}
		if(errorCode >0)
		{
			infobox.className	= infoboxErrorClass;
			infobox.innerHTML	= getErrorMsg(obj,errorCode);
		}
	}
}
function ValidateAll()
{
	var flag = true;
	var infobox;
	var x=document.getElementById("main1");
	if(!x) return;
	var y =x.getElementsByTagName("input");
	for(var i =0;i<y.length;i++)
	{
		if(y[i].type =="text" || y[i].type == "password" || y[i].type == "radio")
		{
			var flag1 = ValidateShow(y[i]);
			flag = flag && flag1;
		}
		
	}
	var flag1
	var dropCountry = document.getElementById("ddlCountry");
	if(dropCountry != null)
	{
	flag1 = ValidateShow(dropCountry);
	flag = flag && flag1
	}
	
	var dropState = document.getElementById("ddlState");
	if(dropState != null)
	{
	flag1 = ValidateShow(dropState);
	flag = flag && flag1;
	}
	
	var txtComment = document.getElementById("txtComment");
	if(txtComment != null)
	{
	flag1 = ValidateShow(txtComment);
	flag = flag && flag1;
	}
	
	return flag;
}
function ValidateShow(obj)
{
	var flag;
	var errorCode = validateValue(obj);
	if(errorCode == 0)
	{
		flag = true;
		if(obj.id)
		{
			if(eval(obj.id).i && document.getElementById(eval(obj.id).i))
			{
				document.getElementById(eval(obj.id).i).className = 'note';
				document.getElementById(eval(obj.id).i).innerHTML = '&nbsp;<img src=\"../images/right.gif\" width=\"19\" height=\"16\" align=\"absmiddle\">'
			}
		}
	}
	if(errorCode >= 1)
	{
		flag = false;
		if(obj.id)
		{
			if(eval(obj.id).i && document.getElementById(eval(obj.id).i))
			{
				document.getElementById(eval(obj.id).i).className = "noteawoke";
				document.getElementById(eval(obj.id).i).innerHTML = (eval(obj.id).e)[errorCode] + "";
			}
		}
	}
	return flag;
}

function isIE()
{
	if(document.all) return true;
	return false;
}
function showInfo(obj,errorCode,forcible)
{
	var t=obj.offsetTop; 
	var l=obj.offsetLeft;
	var e = obj;
	var infobox = getInfobox(obj);
	if(infobox)
	{
			
		if(errorCode == 0 )
		{
			var msg = getErrorMsg(obj,errorCode);
			if(msg)
			{
				infobox.style.position = "absolute";
				infobox.innerHTML	= msg;
				if(infobox.innerHTML != '&nbsp;')
				{
					infobox.className	= infoboxWarningClass;
				}
			}
			else
			{
				return ;
			}
		}
		if(errorCode >0)
		{	
			infobox.style.position = "";
			infobox.className	= infoboxErrorClass;
			infobox.innerHTML	= getErrorMsg(obj,errorCode);
		}
		if(errorCode <0)
		{
			infobox.style.position = "";
			infobox.innerHTML = "";
			infobox.className	= infoboxHintClass;
		}
	}
}

function getFocus(evnt)
{
	var obj;
	if (isIE()) 
	{
		obj = event.srcElement;
	}
	else
	{
		obj = evnt.target;
	}
	showInfo(obj,0);

}
function lostFocus(evnt)
{
	var obj;
	if (isIE()) 
	{
		obj = event.srcElement;
	}
	else
	{
		obj = evnt.target;
	}		
	showInfo(obj,-1);
	if(obj.value == '')
	{
		return ;
	}
	var errorCode = validateValue(obj);
	if(errorCode == 0)
	{
		if(obj.id)
		{
			if(eval(obj.id).i && document.getElementById(eval(obj.id).i))
			{
				document.getElementById(eval(obj.id).i).className = 'note';
				document.getElementById(eval(obj.id).i).innerHTML = '&nbsp;<img src=\"../images/right.gif\">'
			}
		}
	}
	if(errorCode >= 1)
	{
		if(obj.id)
		{
			if(eval(obj.id).i && document.getElementById(eval(obj.id).i))
			{
				document.getElementById(eval(obj.id).i).className = "noteawoke";
				document.getElementById(eval(obj.id).i).innerHTML = (eval(obj.id).e)[errorCode] ;
			}
		}
	}
}
function validateValue(obj)
{
var errorCode;
switch(getDatatype(obj))
{
	case "txtUsername":  if(obj.value.length == 0) return 1;
											    if(obj.value.length < 4) return 2;
											    var i = CheckUsername(obj.value);
											    if(i == "0")
												{ 
													if(CheckUsernameByAjax(obj.value) == "TRUE")
													{
														return 5 ;
													}
													else
													{
													   return 0 ;
													}
													}
												else 
												{
													if(i == "1") return 3;
													if(i == "2") return 4;
												}break;
	case "txtPassword": if(obj.value.length == 0) return 1;if(obj.value.length < 6 || obj.value.lenght >20) return 2; else return 0;break;
	case "txtReTypePassword":if(obj.value.length == 0) return 1;
												if(obj.value != document.getElementById("txtPassword").value) return 2; else return 0;
												break;
	case "txtEmail": if(obj.value.length == 0) return 1;
													if(CheckEmail(obj.value) == '0')
													{	
													  if(CheckEmailByAjax(obj.value) == "TRUE")
													  { return 3 ;}
													  else
													  { return 0 ;}}
													else
													{ 
														return 2 ;
													 }
													break;
	case "txtReTypeEmail": if(obj.value.length == 0) return 1;
													if(CheckEmail(obj.value) == '0')
													{
													if(obj.value != document.getElementById("txtEmail").value) return 3 ;else return 0 ;
													}
													else
													{
													   return 2;
													}break;
	case "txtFirstname": if(obj.value.length < 1 ) return 1 ;else return 0 ;break;
	case "txtLastname" : if(obj.value.length < 1 ) return 1 ;else return 0 ;break;
	case "txtCity" : if(obj.value.length < 1 ) return 1 ;else return 0 ;break;
	case "txtAddress1" : if(obj.value.length < 1 ) return 1 ;else return 0 ;break;
	case "ddlCountry" : if(obj.value == "0") return 1 ;else return 0 ;break;
	case "ddlState" :  if(document.getElementById("ddlCountry").value == "0") return 1;
													else
													{
													if(obj.options.length > 1)
													{
														if(obj.value == "0" || obj.value == "") 
														{return 1 ;}
														else {
														document.getElementById("ddlState").value = obj.value ;
														return 0 ;
														}
													}
													else
													{
													  if(obj.options.length == 1) return 0; else return 1;
													}}break;
	case "txtValidationCode" : if(obj.value.length < 1 ) return 1; else return 0; break;
	case "txtComment" : if(obj.value.length < 1 ) return 1 ;else return 0 ;break;
	default: return 0;break;
}
}
function getDatatype(obj)
{
	if(obj.id)
	{
		if(eval(obj.id).d) return eval(obj.id).d;
	}
	return false;
}


function CheckUsernameByAjax(key)
{
	var ajax = GetObjects();
	var url = "../Common/XmlHttpRequest.aspx?type=validateusername&checkvalue=" + key;
	
	ajax.open("POST", url, false);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    ajax.send("");
	
	var result = ajax.responseText;
	
    if(result!="")
    { 
		var allArray = result.split("|");
        return allArray[0]; 
    }
}
function CheckEmailByAjax(email)
{
	var ajax = GetObjects();
	var url = "../Common/XmlHttpRequest.aspx?type=validateEmail&checkvalue=" + email;
	
	ajax.open("POST", url, false);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    ajax.send(null);
	
	var result = ajax.responseText;
	
    if(result!="")
    { 
		var allArray = result.split("|");
        return allArray[0]; 
    }
}

function char_test(chr) 
//字符检测函数 
{ 
var i; 
var smallch="abcdefghijklmnopqrstuvwxyz"; 
var bigch="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
for(i=0;i<26;i++) 
  if(chr==smallch.charAt(i) || chr==bigch.charAt(i)) 
    return(1); 
return(0); 
} 

function spchar_test(chr) 
//数字和特殊字符检测函数 
{ 
var i; 
var spch="_-.0123456789"; 
for (i=0;i<13;i++) 
   if(chr==spch.charAt(i)) 
    return(1); 
return(0); 
}
function spchar_test1(chr) 
//数字和特殊字符检测函数 
{ 
var i; 
var spch="_-0123456789"; 
for (i=0;i<13;i++) 
   if(chr==spch.charAt(i)) 
    return(1); 
return(0); 
} 

function CheckUsername(str)
{
 var i,flag=0; 
 if(char_test(str.charAt(0)) == 0)
  return 1;
 for(i=0;i<str.length;i++) 
  if(char_test(str.charAt(i))==0 && spchar_test1(str.charAt(i))==0) 
	return 2;

  return 0;
}
function CheckEmail(str) 
{ 
var i,flag=0; 
var at_symbol=0; 
//“@”检测的位置 
var dot_symbol=0; 
//“.”检测的位置 
//if(char_test(str.charAt(0))==0 ) 
 // return (1); 
//首字符必须用字母 

for (i=1;i<str.length;i++) 
  if(str.charAt(i)=='@') 
    { 
    at_symbol=i; 
    break; 
    } 
//检测“@”的位置 

if(at_symbol==str.length-1 || at_symbol==0) 
  return(2); 
//没有邮件服务器域名 

//if(at_symbol<3) 
 // return(3); 
//帐号少于三个字符 

//if(at_symbol>19 ) 
 // return(4); 
//帐号多于十九个字符 

for(i=1;i<at_symbol;i++) 
  if(char_test(str.charAt(i))==0 && spchar_test(str.charAt(i))==0) 
    return (5); 
for(i=at_symbol+1;i<str.length;i++) 
  if(char_test(str.charAt(i))==0 && spchar_test(str.charAt(i))==0) 
    return (5); 
//不能用其它的特殊字符    
    
for(i=at_symbol+1;i<str.length;i++) 
  if(str.charAt(i)=='.') dot_symbol=i; 
for(i=at_symbol+1;i<str.length;i++)  
  if(dot_symbol==0 || dot_symbol==str.length-1 || dot_symbol == at_symbol+1) 
//简单的检测有没有“.”，以确定服务器名是否合法 
  return (6); 
   
return (0);  
//邮件名合法 
}
 function ChangeStateByAjax()
{
	var Country = document.getElementById("ddlCountry").value;
	var ajax = GetObjects();
	var url = "../Common/XmlHttpRequest.aspx?type=country&checkvalue=" + Country;
	
	ajax.open("Post", url, false);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    ajax.send(Country);
	
	var result = ajax.responseText;
	
	var objState = document.getElementById("ddlState");
	objState.length = 0; 
    objState.options.add(new Option("== Please select a state ==", "0")); 
    if(result != "")
    { 
        var allArray = result.split("|"); 
        var thisArray;
        for(var i = 0; i < allArray.length; i++) 
        {
			thisArray = allArray[i].split(",");                 
            objState.options.add(new Option(thisArray[0].toString(),thisArray[1].toString())); 
        }
    }
}

function SetStateValue()
{
	document.getElementById("hidState").value = document.getElementById("ddlState").value;
}

window.onload = function ()
{
	initForm();
}

