	var regExForName = /^[a-zA-Z- ]{1,20}$/;
// 	var regExForEmail = /^[0-9a-zA-Z_\.]+\@[0-9a-zA-Z_\.]+\.[0-9a-zA-Z_\.]{2,4}$/;
 	var regExForEmail = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,4})$/;
 	var regExForPassword = /^[0-9a-zA-Z]{6,12}$/;
 	var regExForSkype = /^[a-zA-Z]{1}[0-9a-zA-Z-_]{5,31}$/;
 	var regExForCity = /^[a-zA-Z\s-]{1,30}$/;
 	var regExForAddress = /^[a-zA-Z\d\s-\/\.]{1,255}$/;
 	var regExForTitle = /^[a-zA-Z\d\s-\/\.]{1,32}$/;
 	var regExForCompany = /^[a-zA-Z\d\s-\/\.]{1,64}$/;
 	var regExForZip = /^[0-9a-zA-Z\s]{4,8}$/;
 	var regExForDevice = /^[0-9a-zA-Z\s]{1,30}$/;
 	var regExForPhone = /^[0-9\-+ ]{6,20}$/;
 	var issetTimer = 0;
 	var isStateRemoved = false;
 	var stateNode = "";
 	var noError = true;
 	var current_object_id = "form";
//	var ignoreArray = new Array;
 	
	var rejectImage = '/images/default/gui/rejected.png';
	var activeImage = '/images/default/gui/active.png';
	var nullImage = '/images/default/gui/spacer.gif';
//	regExForName.test($("username").value)

	email_regx = '[0-9a-zA-Z_]+\@[0-9a-zA-Z_\.]+\.[0-9a-zA-Z_\.]{2,4}';
	phone_regex = '[0-9\- ]{6,20}';
	cc_regex = '[0-9]{16}';
	cvv_regex = '[0-9]{3}';
	zip_regex = '[0-9a-zA-Z ]{4,8}';
	
	function handleErr(msg,url,l)
	{
//		Handle the error here
//		alert("hghjhg");
		noError = false;
		return false;
	}
	
	function setErrMessage_OLD( mess ) {
		if( issetTimer == 1) { clearTimeout(timer); }
		$( "form_err" ).innerHTML = mess;
		timer = setTimeout( '$("form_err").innerHTML = "&nbsp;"; issetTimer=0;', '4000' );
		issetTimer = 1;
	}

	function setErrMessage( mess ) {
		if( issetTimer == 1) { eval(timer_actions); clearTimeout(timer); }
		error_td_id = current_object_id + "_error";
		error_tr_id = current_object_id + "_error_tr";
		$( error_td_id ).innerHTML = mess;
		if( navigator.appName == 'Netscape' ){ var display_val = "table-row"; } else { var display_val = "inline"; }
//		$( error_tr_id ).style.display = "table-row";
//		$( error_tr_id ).style.display = "inline";
		$( error_tr_id ).style.display = display_val;
		timer_actions = '$(error_td_id).innerHTML = "&nbsp;"; $( error_tr_id ).style.display = "none"; issetTimer=0;';
		timer = setTimeout( timer_actions, '4000' );
		issetTimer = 1;
	}

	function setTrue( toId ) {
		$( toId ).innerHTML = '';
	}
	
	function md5_passw_submit( ) {
		$("md5_passw").value = md5( $("password").value );
		$("password").value = '';
		$("password0").value = '';
	}
	
	function createDefaultInterface( ) {
		createCheckFormArray( );
		if( $("country").value != 840 ) { switchState( 0 ); }
//		$("country").value = 0;
		$("form_switch").value = "enter";
	}
		
	function switchState_OLD( activeCountry ) {
		if( activeCountry == "840" && isStateRemoved ) {
//			alert( "hjhjjhj" )
			$( "x_tbody" ).insertBefore( stateNode, $( "city_tr" ) );
			isStateRemoved = false;
		} else if( activeCountry != "840" && !isStateRemoved ) {
			stateNode = $( "state_tr" ).parentNode.removeChild(  $( "state_tr" ) );
			isStateRemoved = true;
		}
	}
	
	function switchState( activeCountry ) {
		if( navigator.appName == 'Netscape' ){ var display_val = "table-row"; } else { var display_val = "inline"; }
		if( activeCountry == "840" && isStateRemoved ) {
//			alert( "hjhjjhj" )
//			$( "x_tbody" ).insertBefore( stateNode, $( "city_tr" ) );
			$( "state_tr" ).style.display = display_val;
			isStateRemoved = false;
		} else if( activeCountry != "840" && !isStateRemoved ) {
//			stateNode = $( "state_tr" ).parentNode.removeChild(  $( "state_tr" ) );
			$( "state_tr" ).style.display = "none";
			isStateRemoved = true;
		}
	}
	
	function regExTester( obj, regEx, errMess, returnImgId ) {
		if( obj.value == '' ) { $( returnImgId ).src = nullImage; return true; }
		answer = regEx.test( obj.value );
		setAnswerImg( answer, errMess, returnImgId );
	}

	function regExTest( obj, regEx ) {
		if( obj.value == '' ) {  return 2; }
		return regEx.test(obj.value)? 1:0;
	}

	function setAnswerImg( answer, errMess, returnImgId ) {
		current_object_id = returnImgId.replace(/_img/, "");
//		alert(current_object_id);
		if( !answer ) {
			$(returnImgId).src = rejectImage;
			setErrMessage( errMess );
		} else {
			$(returnImgId).src = activeImage;
		}
	}
		
	function createCheckFormArray( ) {
		checkFormArr = new Array( );

		var i = 0;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('email');
		checkFormArr[i]["reg_ex"] = regExForEmail;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'Please enter valid email address';
		checkFormArr[i]["err_msg2"] = 'The email address field is a mandatory';
		checkFormArr[i]["img_id"] = 'email_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('email0');
		checkFormArr[i]["reg_ex"] = '';
		checkFormArr[i]["answer"] = '$("email0").value == $("email").value';
		checkFormArr[i]["err_msg"] = 'The email address you re-typed is different from the original one. Please re-type your email address';
		checkFormArr[i]["err_msg2"] = 'You must re-type your email address on the relevant field';
		checkFormArr[i]["img_id"] = 'email0_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('password');
		checkFormArr[i]["reg_ex"] = regExForPassword;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'Your password must contain from 6 to 12 alphabetic characters or numbers';
		checkFormArr[i]["err_msg2"] = 'The password field is a mandatory';
		checkFormArr[i]["img_id"] = 'password_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('password0');
		checkFormArr[i]["reg_ex"] = '';
		checkFormArr[i]["answer"] = '$("password0").value == $("password").value';
		checkFormArr[i]["err_msg"] = 'The password you re-typed is not matching the original one. Please re-type your password';
		checkFormArr[i]["err_msg2"] = 'You must re-type your password. It is a mandatory field';
		checkFormArr[i]["img_id"] = 'password0_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('f_name');
		checkFormArr[i]["reg_ex"] = regExForName;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'The first name field can contain only alphabetic characters and spaces';
		checkFormArr[i]["err_msg2"] = 'First name is a mandatory field, please type your first name';
		checkFormArr[i]["img_id"] = 'f_name_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('l_name');
		checkFormArr[i]["reg_ex"] = regExForName;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'The last name field can contain only alphabetic characters and spaces';
		checkFormArr[i]["err_msg2"] = ' The last name field is a mandatory';
		checkFormArr[i]["img_id"] = 'l_name_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('title');
		checkFormArr[i]["reg_ex"] = regExForTitle;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'Title field contains disabled characters';
		checkFormArr[i]["err_msg2"] = '';
		checkFormArr[i]["img_id"] = 'title_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('mob_number');
		checkFormArr[i]["reg_ex"] = regExForPhone;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'Please enter a valid phone number';
		checkFormArr[i]["err_msg2"] = 'The phone number field is mandatory';
		checkFormArr[i]["img_id"] = 'mob_number_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('cell_phone');
		checkFormArr[i]["reg_ex"] = regExForPhone;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'Please enter a valid cell phone number';
		checkFormArr[i]["err_msg2"] = 'The cell phone number field is mandatory';
		checkFormArr[i]["img_id"] = 'cell_phone_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('msn');
		checkFormArr[i]["reg_ex"] = regExForEmail;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'Please enter a valid MSN messenger login name';
		checkFormArr[i]["err_msg2"] = '';
		checkFormArr[i]["img_id"] = 'msn_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('skype');
		checkFormArr[i]["reg_ex"] = regExForSkype;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'Please enter valid Skype name';
		checkFormArr[i]["err_msg2"] = '';
		checkFormArr[i]["img_id"] = 'skype_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('company');
		checkFormArr[i]["reg_ex"] = regExForCompany;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'The company field contain disabled characters';
		checkFormArr[i]["err_msg2"] = 'The company name is a mandatory';
		checkFormArr[i]["img_id"] = 'company_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('country');
		checkFormArr[i]["reg_ex"] = "";
		checkFormArr[i]["answer"] = '$("country").value != 0';
		checkFormArr[i]["err_msg"] = 'Please choose country';
		checkFormArr[i]["err_msg2"] = 'The country field is mandatory';
		checkFormArr[i]["img_id"] = 'country_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('state');
		checkFormArr[i]["reg_ex"] = "";
		checkFormArr[i]["answer"] = '($("state").value != 0 && $("country").value == 840)';
		checkFormArr[i]["err_msg"] = 'Please choose a state';
		checkFormArr[i]["err_msg2"] = 'The state field is mandatory';
		checkFormArr[i]["img_id"] = 'state_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('city');
		checkFormArr[i]["reg_ex"] = regExForCity;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'The city field can contain only alphabetic characters and spaces';
		checkFormArr[i]["err_msg2"] = 'The city field is mandatory';
		checkFormArr[i]["img_id"] = 'city_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('address');
		checkFormArr[i]["reg_ex"] = regExForAddress;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'The address field can contain only spaces slashes, minuses and alphabetic characters';
		checkFormArr[i]["err_msg2"] = 'The address is mandatory ';
		checkFormArr[i]["img_id"] = 'address_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('zip');
		checkFormArr[i]["reg_ex"] = regExForZip;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'The zip code you have typed is invalid';
		checkFormArr[i]["err_msg2"] = 'The zip code field is mandatory';
		checkFormArr[i]["img_id"] = 'zip_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('phone');
		checkFormArr[i]["reg_ex"] = regExForPhone;
		checkFormArr[i]["answer"] = '';
		checkFormArr[i]["err_msg"] = 'Please enter a valid organization phone number';
		checkFormArr[i]["err_msg2"] = '';
		checkFormArr[i]["img_id"] = 'phone_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('agree_affilation');
		checkFormArr[i]["reg_ex"] = '';
		checkFormArr[i]["answer"] = '$("agree_affilation").checked';
		checkFormArr[i]["err_msg"] = 'To continue you must agree to the Affilation agreement, accept the Real Dice Privacy and policy and you must agree to the Real Dice EULA';
		checkFormArr[i]["err_msg2"] = '';
		checkFormArr[i]["img_id"] = 'agree_affilation_img';

		i++;
		checkFormArr[i] = new Array( );
		checkFormArr[i]["obj"] = $('agree_18');
		checkFormArr[i]["reg_ex"] = '';
		checkFormArr[i]["answer"] = '$("agree_18").checked';
		checkFormArr[i]["err_msg"] = 'To register you must be at least 18 years old';
		checkFormArr[i]["err_msg2"] = '';
		checkFormArr[i]["img_id"] = 'agree_18_img';
	}
	
	function checkEditForm( ) {
//		ignoreArray[0] = true;
//		ignoreArray[1] = true;
//		ignoreArray[2] = true;
//		ignoreArray[3] = true;
//		return checkFormCicle ( false );
		return checkFormCicle ( true );
	}
	
	function checkForm( ) {
		return checkFormCicle( false );
	}
	
	function checkFormCicle( ignore ) {
		xLength = checkFormArr.length;
		for( i = 0; i < xLength; i++ ) {
//			if( ignore && ignoreArray[i] != undefined ) { alert( i ); continue; }
			if( $(checkFormArr[i]["img_id"] ) == undefined || ( $(checkFormArr[i]["img_id"] ) == "state_img" && isStateRemoved ) ) { continue; }
			if( checkFormArr[i]["img_id"] == "state_img" && isStateRemoved ) { continue; }
//			if( $(checkFormArr[i]["img_id"] ) == undefined ) { continue; }

			current_object_id = checkFormArr[i]["img_id"].replace(/_img/, "");
			error_td_id = current_object_id + "_error";
			error_tr_id = current_object_id + "_error_tr";

			if( checkFormArr[i]["obj"].value == '' ) {
				xAnswer = 2;
			} else if( checkFormArr[i]["reg_ex"] != '' ) { 
				xAnswer = regExTest( checkFormArr[i]["obj"], checkFormArr[i]["reg_ex"] );
			} else {
				xAnswer = eval( checkFormArr[i]["answer"] );
			}

			if( xAnswer == 0 ) { 
				$(checkFormArr[i]["img_id"]).src = rejectImage;
				setErrMessage( checkFormArr[i]["err_msg"] );
				checkFormArr[i]["obj"].focus();
				return false;
			} else if( xAnswer == 2 && checkFormArr[i]["err_msg2"] != '' ) {
				$(checkFormArr[i]["img_id"]).src = rejectImage;
				setErrMessage( checkFormArr[i]["err_msg2"] );
				checkFormArr[i]["obj"].focus( );
				return false;
			} else if ( xAnswer == 1 ) {
				$(checkFormArr[i]["img_id"]).src = activeImage;
			}
		}
		if( !ignore ) { md5_passw_submit( ); }
		return true;
	}