/* utils */
	/* --- can't work because of another javascript ---
	function addOnloadEvent(fct){
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = fct;
		}
		else {
			window.onload = function() {
				oldonload();
				fct();
			}
		}
	}
	*/
	
	function $(val){
		return document.getElementById(val);
	}
	function $t(elemType,o){
		if(!o)o=document;
		return o.getElementsByTagName(elemType);
	}
	function $c(elemType,cssClass,o){
		if(!o)o=document;
		var listLcl = o.getElementsByTagName(elemType);
		var list2return = new Array();
		for(var i=0;i<listLcl.length;i++){
			if(listLcl[i].className.indexOf(cssClass+" ")>-1 || listLcl[i].className.indexOf(" "+cssClass)>-1 || listLcl[i].className == cssClass)
				list2return.push(listLcl[i]);
		}
		return list2return;
	}
/* utils */

var EMAkgiValid = new Object();
EMAkgiValid.newsletters = function(o){
	$t("div",o.parentNode.parentNode)[1].style.display=o.checked?"block":"none";
}

EMAkgiValid.checkMailEnterKey = function(event,o){
	if(event.keyCode==13){
		EMAkgiValid.checkMail(o);
	}
}

EMAkgiValid.validMail = function(str){
	var isValid = true;
	/*
	isValid = isValid && (str.indexOf("@") > 0);
	isValid = isValid && (str.indexOf(".") > str.indexOf("@") + 1);
	isValid = isValid && (str.indexOf(".") > str.length-7 && str.indexOf(".") < str.length-2);*/
	var re = /(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/;
	return str.match(re);
	return isValid;
}

EMAkgiValid.checkMail = function(o){
	for(var oLcl = o;oLcl;oLcl=oLcl.parentNode){
		if(oLcl.tagName=="FORM"){
			if(!EMAkgiValid.validMail(o.value)) oLcl.onsubmit=function(){alert("Sorry but your e-mail seems to be incorrect");return false;}
			else oLcl.onsubmit=null;
			break;
		}
	}
}

EMAkgiValid.createValid = function(formLcl){
	
	$('error-pannel').style.display = 'none';
	$('error-pass-match').style.display = 'none';
	$('pass_error').style.display = 'none';
	$('login_error').style.display = 'none';
	$('email_valid_error').style.display = 'none';
	$('phone_length_error').style.display = 'none';
	
	if($("password").value=='' && $("r_password").value=='' && $("login").value=='' && $("email").value=='' && $("phone").value=='') {
		$('error-pannel').style.display = 'block';
		$('error-empty').style.display = 'block';
		return false;
	}
	
	if($("password").value!=$("r_password").value){
		//alert("password and confirmation don't match");
		$('error-pannel').style.display = 'block';
		$('error-pass-match').style.display = 'block';
		return false;
	}
	if($("password").value=="" || $("password").value.length<5 || $("password").value.length>32){
		//alert("please fill your password (min 5 char. max 32 char.) ");
		$('pass_error').style.display = 'inline';
		return false;
	}
	if($("login").value=="" || $("login").value.length<3 || $("login").value.length>25){
		//alert("please fill your login (min 3 char. max 25 char.)");
		$('login_error').style.display = 'inline';
		return false;
	}
	if(!EMAkgiValid.validMail($("email").value)){
		//alert("your e-mail seems to be incorrect");
		$('email_valid_error').style.display = 'inline';
		return false;
	}
	if($("phone").value.length>15){
		//alert("please fill your phone number");
		$('phone_length_error').style.display = 'inline';
		return false;
	}
	/*if($("select").selectedIndex==0){
		alert("please choose your country");
		return false;
	}
	*/
	formLcl.submit();
}

EMAkgiValid.validLogin = function(formLcl){
	if($("login").value=="" && $("password").value=="" ){
		//alert("All the fields are required");
		$('invalid-inputs').style.display = 'none';
		$('fields_required').style.display = 'block';
		return false;
	}
	if($("password").value=="" || $("password").value.length<5 || $("password").value.length>32){
		//alert("please fill your password");
		$('fields_required').style.display = 'none';
		$('invalid-inputs').style.display = 'block';
		return false;
	}
	if($("login").value=="" || $("login").value.length<3 || $("login").value.length>25){
		//alert("please fill your login");
		$('fields_required').style.display = 'none';
		$('invalid-inputs').style.display = 'block';
		return false;
	}
	formLcl.submit();
}

EMAkgiValid.isNumber = function(val){
	if(val=="")return false;
	if(val.indexOf(",")>-1 && val.indexOf(".")>-1)return false;
	if(val.indexOf(".")!=val.lastIndexOf("."))return false;
	if(val.indexOf(",")!=val.lastIndexOf(","))return false;
	var re=new RegExp(/[0-9,\.]/);
	for(var i=0;i<val.length;i++){
		if(!val.charAt(i).match(re)){return false;}
	}
	return true;
}

EMAkgiValid.step2Valid = function(formLcl){
	if(!EMAkgiValid.isNumber($('bel20').value)){
		//alert('You must enter a numeric value into the Bel 20 field');
		$('fields-required').style.display = 'block';
		return false;
	}
	if(!EMAkgiValid.isNumber($('dowjones').value)){
		//alert('You must enter a numeric value into the Dow Jones field');
		$('fields-required').style.display = 'block';
		return false;
	}
	if(!EMAkgiValid.isNumber($('eurodollar').value)){
		//alert('You must enter a numeric value into the EUR/USD Rate field');
		$('fields-required').style.display = 'block';
		return false;
	}
	formLcl.submit();
}