/* 	======================================================
*	Author		: Cornelius Dito 
*	Web Design 	: Wulan	
*	Project		: Lambada Website
*	Powered by	: Dewata Production Indonesia
*	=====================================================*/
function validateUpdate(){ 
	var theForm = document.forms["updates"];
	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}$/;

	if (theForm.scountry.value == ""){
		errMsg = "Attention\nSaisissez le pays SVP!";
		setfocus = "['scountry']";
	}
	
	if (theForm.szip.value == ""){
		errMsg = "Attention!\nSaisissez le code postal SVP!";
		setfocus = "['szip']";
	}
	if(!filterzip.test(theForm.szip.value)){
		errMsg="Attention!\nSVP saisissez votre code postal correctement!";
		setfocus="['szip']";
	}
	var szip=theForm.szip.value;
	if(szip.substr(0,1)=="0"){
		errMsg="Attention!\nSVP saisissez votre code postal correctement!";
		setfocus="['szip']";
	}
	
	if (theForm.scity.value == ""){
		errMsg = "Attention!\nSaisissez la ville SVP!";
		setfocus = "['scity']";
	}
	
	if (theForm.sadd1.value == ""){
		errMsg = "Attention!\nSaisissez votre adresse SVP!";
		setfocus = "['sadd1']";
	}


	if (theForm.bcountry.value == ""){
		errMsg = "Attention\nSaisissez le pays SVP!";
		setfocus = "['bcountry']";
	}
	
	if (theForm.bzip.value == ""){
		errMsg = "Attention!\nSaisissez le code postal SVP!";
		setfocus = "['bzip']";
	}

	if(!filterzip.test(theForm.bzip.value)){
		errMsg="Attention!\nSVP saisissez votre code postal correctement!";
		setfocus="['bzip']";
	}
	var bzip=theForm.bzip.value;
	if(bzip.substr(0,1)=="0"){
		errMsg="Attention!\nSVP saisissez votre code postal correctement!";
		setfocus="['bzip']";
	}
	
	if (theForm.bcity.value == ""){
		errMsg = "Attention!\nSaisissez la ville SVP!";
		setfocus = "['bcity']";
	}
	
	if (theForm.badd1.value == ""){
		errMsg = "Attention!\nSaisissez votre adresse SVP!";
		setfocus = "['badd1']";
	}
	
	if (theForm.m3.value == "" && theForm.p3.value == ""){
		errMsg = "Attention!\nMerci de saisir votre numéro de telephone ou de téléphone portable!";
		setfocus = "['m3']";
	}
	
	if (theForm.m2.value == "" && theForm.p2.value == ""){
		errMsg = "Attention!\nmerci de saisir votre numéro de telephone ou de téléphone portable!";
		setfocus = "['m2']";
	}
	
	if (theForm.m1.value == "" && theForm.p1.value == ""){
		errMsg = "Attention!\nmerci de saisir votre numéro de telephone ou de téléphone portable!";
		setfocus = "['m1']";
	}
	
	//if (theForm.number_tlp.value == ""){
	//	errMsg = "Attention!\nPlease enter your phone number !";
	//	setfocus = "['number_tlp']";
	//}
	
	//if (theForm.area_tlp.value == ""){
	//	errMsg = "Attention!\nPlease enter your phone code area in your country !";
	//	setfocus = "['area_tlp']";
	//}
	
	//if (theForm.country_tlp.value == ""){
	//	errMsg = "Attention!\nPlease enter your phone country area !";
	//	setfocus = "['country_tlp']";
	//}
	
	if (!emailRE.test(theForm.email.value)){
		errMsg = "Attention!\nSaisissez votre email correctement SVP!";
		setfocus = "['email']";
	}
	
	if (theForm.email.value == ""){
		errMsg = "Attention!\nSaisissez votre adresse email SVP!";
		setfocus = "['email']";
	}

	//if (theForm.company.value == ""){
	//	errMsg = "Attention!\nPlease enter your company name !";
	//	setfocus = "['company']";
	//}

	if (theForm.fname.value == ""){
		errMsg = "SVP saisissez votre nom!";
		setfocus = "['name']";
	}
	
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}

	else doUpdate();
	//else theForm.submit();
}


function validateLogin(){ 
	var theForm = document.forms["login"];
	var userRE0 = new RegExp("http://");
	var errMsg = "";
	var setfocus = "";
		
	if (theForm.password.value == ""){
		errMsg = "Attention!\nVeuillez saisir votre mot de passe!";
		setfocus = "['password']";
	}
	if (theForm.username.value == ""){
		errMsg = "Attention!\nSaisissez vos informations de compte!";
		setfocus = "['username']";
	}


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

	
	else theForm.submit();
}

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

function isNumeric2(msg){
	var theForm = document.forms["updates"];
	var numericExpression = /^[0-9]+$/;
	if (theForm.country_mobile.value != ""){
		if(theForm.country_mobile.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.country_mobile.value = "";
			theForm.country_mobile.focus();
			return false;
		}
	}
	
	if (theForm.area_mobile.value != ""){
		if(theForm.area_mobile.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.area_mobile.value = "";
			theForm.area_mobile.focus();
			return false;
		}
	}
	
	if (theForm.number_mobile.value != ""){
		if(theForm.number_mobile.value.match(numericExpression)){
			return true;
		}else{
			alert(msg);
			theForm.number_mobile.value = "";
			theForm.number_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;Trop Court!</strong></span>';
} else if (strongRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:green"><strong>&nbsp;Bon!</strong></span>';
} else if (mediumRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:purple"><strong>&nbsp;Moyen!</strong></span>';
} else {
strength.innerHTML = '<span style="color:red"><strong>&nbsp;Très Moyen!</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;Trop Court!</strong></span>';
} else if (strongRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:green"><strong>&nbsp;Bon!</strong></span>';
} else if (mediumRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:purple"><strong>&nbsp;Moyen!</strong></span>';
} else {
strength.innerHTML = '<span style="color:red"><strong>&nbsp;Très Moyen!</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;
   }
 }
}



