/* 	======================================================
*	Author		: Cornelius Dito 
*	Web Design 	: Wulan	
*	Project		: Lambada Website
*	Powered by	: Dewata Production Indonesia
*	=====================================================*/
function validateReg(){ 
	
	var theForm = document.forms["registration"];
	var class_pty = document.forms["registration"].class_pty;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var passwordRE = /^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$/;
	var userRE0 = new RegExp("http://");
	var errMsg = "";
	var setfocus = "";
	var filterzip=/^\d{5}$|^\d{5}-\d{4}$/;
	/*var class_pty='';
		//alert('test2');
		for (var i=0; i < document.registration.class_pty.length; i++){
			if (document.registration.class_pty[i].checked){
					class_pty=document.registration.class_pty[i].value;
			}
		}	
	*/	
 	if (!theForm.check_term.checked){
		errMsg = "You have not agree with our term of order!";
		setfocus = "['check_term']";
	}
 	
	if (theForm.jewelry.value == ""){
		errMsg = "Warning!\nWhat kind of jewelry items are you looking for ?";
		setfocus = "['jewelry']";
	}
	
	if (theForm.companyfield.value == ""){
		errMsg = "Warning!\nWhat is your company business field ?";
		setfocus = "['companyfield']";
	}
	
	/*if(class_pty==''){
		errMsg("Warning!\nPlease select classification!",'');	
	}*/
	if (!class_pty[0].checked && !class_pty[1].checked && !class_pty[2].checked && !class_pty[3].checked && !class_pty[4].checked){
		errMsg = "Warning!\nPlease select your business classification!";
		setfocus = "['check_term']";
	}
	
	if (theForm.txt_ship_country.value == ""){
		errMsg = "Warning!\nEnter your Shipment country !";
		setfocus = "['txt_ship_country']";
	}
	
	if (theForm.txt_ship_zip.value == ""){
		errMsg = "Warning!\nPlease enter your Shipping Zip/Postal Code !";
		setfocus = "['txt_ship_zip']";
	}
	
	if(!filterzip.test(theForm.txt_ship_zip.value)){
		errMsg="Warning!\nPlease enter your Zip/Postal Code correctly.";
		setfocus="['txt_ship_zip']";
	}
	var bzip=theForm.txt_ship_zip.value;
	if(bzip.substr(0,1)=="0"){
		errMsg="Warning!\nPlease enter your Zip/Postal Code correctly.";
		setfocus="['txt_ship_zip']";
	}
	
	if (theForm.txt_ship_city.value == ""){
		errMsg = "Warning!\nPlease enter your shipment City !";
		setfocus = "['txt_ship_city']";
	}
	
	if (theForm.txt_ship_address1.value == ""){
		errMsg = "Warning!\nPlease enter your shipment address !";
		setfocus = "['txt_ship_address1']";
	}
	
	if (theForm.txt_bill_country.value == ""){
		errMsg = "Warning!\nEnter your Billing Country !";
		setfocus = "['txt_bill_country']";
	}
	
	if (theForm.txt_bill_zip.value == ""){
		errMsg = "Warning!\nPlease enter your Billing Zip/Postal Code !";
		setfocus = "['txt_bill_zip']";
	}
	
	if(!filterzip.test(theForm.txt_bill_zip.value)){
		errMsg="Warning!\nPlease enter your Zip/Postal Code correctly.";
		setfocus="['txt_bill_zip']";
	}
	var bzip=theForm.txt_bill_zip.value;
	if(bzip.substr(0,1)=="0"){
		errMsg="Warning!\nPlease enter your Zip/Postal Code correctly.";
		setfocus="['txt_bill_zip']";
	}
	
	if (theForm.txt_bill_city.value == ""){
		errMsg = "Warning!\nPlease enter your Billing City !";
		setfocus = "['txt_bill_city']";
	}
	
	if (theForm.txt_bill_address1.value == ""){
		errMsg = "Warning!\nPlease enter your Billing Address !";
		setfocus = "['txt_bill_address1']";
	}

	if (theForm.txt_position.value == "" && theForm.txt_position2.value == "" && theForm.txt_position3.value == "" && theForm.txt_position4.value == "" && theForm.txt_position5.value == ""){
		errMsg = "Warning!\nPlease enter Your position in the company !";
		setfocus = "['c_owner']";
	}	
	//alert ('tes');
	/*if (theForm.txt_phone_mobile.value == ""){
		errMsg = "Warning!\nPlease enter Your mobile phone number !";
		setfocus = "['txt_phone_mobile']";
	}*/	
	
	if (theForm.txt_phone.value == ""){
		errMsg = "Warning!\nPlease enter Your phone number !";
		setfocus = "['txt_phone']";
	}	
	
	if (theForm.txt_company.value == ""){
		errMsg = "Warning!\nPlease enter Your company name !";
		setfocus = "['txt_company']";
	}

	/*if (!passwordRE.test(theForm.txt_password_r.value)){
		errMsg = "Warning!\nYour password not secure, Please change your password!";
		setfocus = "['txt_password_r']";
	}
	
	if (!passwordRE.test(theForm.txt_password.value)){
		errMsg = "Warning!\nYour password not secure, Please change your password!";
		setfocus = "['txt_password']";
	}*/

	if (theForm.txt_password.value != theForm.txt_password_r.value){
		errMsg = "Warning!\nPlease Retype your 2nd password correctly !";
		setfocus = "['txt_email_r']";
	}
	
	if (theForm.txt_password_r.value == ""){
		errMsg = "Warning!\nPlease Enter your 2nd password!";
		setfocus = "['txt_password_r']";
	}
	
	if (theForm.txt_password.value == ""){
		errMsg = "Warning!\nPlease Enter your password!";
		setfocus = "['txt_password']";
	}
	
	if (theForm.txt_email.value != theForm.txt_email_r.value){
		errMsg = "Warning!\nPlease Retype your 2nd Email correctly !";
		setfocus = "['txt_email_r']";
	}
	
	if (!emailRE.test(theForm.txt_email_r.value)){
		errMsg = "Warning!\nPlease check your 2nd Mail !";
		setfocus = "['txt_email_r']";
	}
	
	if (!emailRE.test(theForm.txt_email.value)){
		errMsg = "Warning!\nPlease check your Mail !";
		setfocus = "['txt_email']";
	}
	
	if (theForm.txt_email_r.value == ""){
		errMsg = "Warning!\nPlease enter your 2nd mail!";
		setfocus = "['txt_email_r']";
	}
	
	if (theForm.txt_email.value == ""){
		errMsg = "Warning!\nPlease enter your mail First !";
		setfocus = "['txt_email']";
	}


	if (theForm.txt_last.value == ""){
		errMsg = "Warning!\nPlease enter Your last name !";
		setfocus = "['txt_last']";
	}

	if (theForm.txt_first.value == ""){
		errMsg = "Warning!\nPlease enter Your first name!";
		setfocus = "['txt_first']";
	}

	if (theForm.txt_gender.value == ""){
		errMsg = "Please select your gender!";
		setfocus = "['male']";
	}
	
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}

	
	else theForm.submit();
}


function validateLogin(){ 
	var theForm = document.forms["login"];
	var userRE0 = new RegExp("http://");
	var errMsg = "";
	var setfocus = "";
		
	if (theForm.password.value == ""){
		errMsg = "Warning!\nPlease Enter your Password First !";
		setfocus = "['password']";
	}
	if (theForm.username.value == ""){
		errMsg = "Warning!\nPlease Enter your Account First !";
		setfocus = "['username']";
	}


	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}

	
	else theForm.submit();
}

function isNumeric1(msg){
	var theForm = document.forms["registration"];
	var numericExpression = /^[0-9]+$/;
	if (theForm.txt_phone.value != ""){
		if(theForm.txt_phone.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.txt_phone.value = "";
			theForm.txt_phone.focus();
			return false;
		}
	}
	
	if (theForm.txt_country_code.value != ""){
		if(theForm.txt_country_code.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.txt_country_code.value = "";
			theForm.txt_country_code.focus();
			return false;
		}
	}
	
	if (theForm.txt_area_code.value != ""){
		if(theForm.txt_area_code.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.txt_area_code.value = "";
			theForm.txt_area_code.focus();
			return false;
		}
	}
	
}

function isNumeric2(msg){
	var theForm = document.forms["registration"];
	var numericExpression = /^[0-9]+$/;
	if (theForm.txt_phone_fax.value != ""){
		if(theForm.txt_phone_fax.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.txt_phone_fax.value = "";
			theForm.txt_phone_fax.focus();
			return false;
		}
	}
	
	if (theForm.txt_country_fax.value != ""){
		if(theForm.txt_country_fax.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.txt_country_fax.value = "";
			theForm.txt_country_fax.focus();
			return false;
		}
	}
	
	if (theForm.txt_area_fax.value != ""){
		if(theForm.txt_area_fax.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.txt_area_fax.value = "";
			theForm.txt_area_fax.focus();
			return false;
		}
	}
	
}

function isNumeric3(msg){
	var theForm = document.forms["registration"];
	var numericExpression = /^[0-9]+$/;
	if (theForm.txt_phone_mobile.value != ""){
		if(theForm.txt_phone_mobile.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.txt_phone_mobile.value = "";
			theForm.txt_phone_mobile.focus();
			return false;
		}
	}
	
	if (theForm.txt_country_mobile.value != ""){
		if(theForm.txt_country_mobile.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.txt_country_mobile.value = "";
			theForm.txt_country_mobile.focus();
			return false;
		}
	}
	
	if (theForm.txt_area_mobile.value != ""){
		if(theForm.txt_area_mobile.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.txt_area_mobile.value = "";
			theForm.txt_area_mobile.focus();
			return false;
		}
	}
	
}

function passwordChanged1() {
var strength = document.getElementById('strength1');
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
var pwd = document.getElementById("txt_password");
if (pwd.value.length==0) {
strength.innerHTML = '';
} else if (false == enoughRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:red"><strong>&nbsp;Too Short!</strong></span>';
} else if (strongRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:green"><strong>&nbsp;Strong!</strong></span>';
} else if (mediumRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:purple"><strong>&nbsp;Medium!</strong></span>';
} else {
strength.innerHTML = '<span style="color:red"><strong>&nbsp;Weak!</strong></span>';
}
}

function passwordChanged2() {
var strength = document.getElementById('strength2');
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
var pwd = document.getElementById("txt_password_r");
if (pwd.value.length==0) {
strength.innerHTML = '';
} else if (false == enoughRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:red"><strong>&nbsp;Too Short!</strong></span>';
} else if (strongRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:green"><strong>&nbsp;Strong!</strong></span>';
} else if (mediumRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:purple"><strong>&nbsp;Medium!</strong></span>';
} else {
strength.innerHTML = '<span style="color:red"><strong>&nbsp;Weak!</strong></span>';
}
}


function verifynotify1(field1, field2, result_id, match_html, nomatch_html) {
 this.field1 = field1;
 this.field2 = field2;
 this.result_id = result_id;
 this.match_html = match_html;
 this.nomatch_html = nomatch_html;

 this.check = function() {
   if (!this.result_id) { return false; }
   if (!document.getElementById){ return false; }
   r = document.getElementById(this.result_id);
   if (!r){ return false; }

   if (this.field1.value != "" && this.field1.value == this.field2.value) {
     r.innerHTML = this.match_html;
   } else {
     r.innerHTML = this.nomatch_html;
   }
 }
}


function verifynotify2(field1, field2, result_id, match_html, nomatch_html) {
 this.field1 = field1;
 this.field2 = field2;
 this.result_id = result_id;
 this.match_html = match_html;
 this.nomatch_html = nomatch_html;

 this.check = function() {
   if (!this.result_id) { return false; }
   if (!document.getElementById){ return false; }
   r = document.getElementById(this.result_id);
   if (!r){ return false; }

   if (this.field1.value != "" && this.field1.value == this.field2.value) {
     r.innerHTML = this.match_html;
   } else {
     r.innerHTML = this.nomatch_html;
   }
 }
}


