function xperto_msgBox(var_msg){alert('[' + XPERTO_APP_TITLE + '] - ' + var_msg);}
function xperto_confirm_msgBox(var_msg){return confirm('[' + XPERTO_APP_TITLE + '] - ' + var_msg);}
function xperto_valid_form(var_lang){
	if(document.getElementById('contacto_email').value!="" && document.getElementById('contacto_nombre').value!="" &&  document.getElementById('contacto_compania').value!="" && document.getElementById('contacto_direcccion').value!="" && document.getElementById('contacto_ciudad').value!="" && document.getElementById('contacto_pais').value!="")
		 return true;
	else{
		if(document.getElementById(var_lang).value=="esp")
			alert("COMPLETE EL FORMULARIO (*)");
		else 
			if(document.getElementById(var_lang).value=="eng")
			alert("COMPLETE THE FORM (*)");

		return false;
	}

}

// FUNCION PARA CREAR OBJETO AJAX
	function x_crear_ajax(){
		//MICROSOFT
		var xmlHttp=false;
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlHttp = false;
			}
		}
		//MOZILLA
		if (!xmlHttp && typeof XMLHttpRequest!='undefined') {
			xmlHttp = new XMLHttpRequest();
		}
		return xmlHttp;
	}

// Funcion para ejecutar varias funciones con window.onload
// es decir cuando se carga la página.
// de esta forma nos evitamos en poner varios <body onLoad="....">
// ejemplo: 
// window.onload = x_windowOnLoad(window.onload, mi_funcion1());
// window.onload = x_windowOnLoad(window.onload, mi_funcion2());
// ...

function x_windowOnLoad(funcion1, funcion2) {
	return function() {
		if (funcion1)
			funcion1();
		if (funcion2)
			funcion2();
	}
}


var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|co|uk|es)$/;

function x_validar_dominio(FormField,NoWWW,CheckTLD) {
	// NoWWW y CheckTLD son opcionales, ambos aceptan los valores true, false, y null.
	// NoWWW se utiliza para verificar que un nombre de dominio no comience con 'www.', ejem. para WHOIS.
	DomainName=FormField.value.toLowerCase();
	if (CheckTLD==null) {CheckTLD=true}
	var specialChars="/\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var atom=validChars + '+';
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=DomainName.split(".");
	var len=domArr.length;
	if (len==1) {alert(FormField.title + " inválido"); FormField.focus(); return false}
	for (i=0;i<len;i++) {if (domArr[i].search(atomPat)==-1) {alert(FormField.title + " inválido"); FormField.focus(); return false}}
	if ((CheckTLD) && (domArr[domArr.length-1].length!=2) && (domArr[domArr.length-1].search(knownDomsPat)==-1)) {alert(FormField.title + " debe terminar en dominio bien conocido o país de dos letras."); FormField.focus(); return false}
	if ((NoWWW) && (DomainName.substring(0,4).toLowerCase()=="www.")) {alert(FormField.title + " inválido: comienza con www."); FormField.focus(); return false}
	return true;
	}

function x_validar_email (FormField,CheckTLD) {
	// CheckTLD es opcional, acepta los valores true, false, y null.
	emailStr = FormField.value.toLowerCase()
	if (CheckTLD==null) {CheckTLD=true}
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {alert(FormField.title + " parece ser incorrecta (Compruebe arroba (@) y puntos (.))"); FormField.focus(); FormField.focus(); return false}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {if (user.charCodeAt(i)>127) {alert(FormField.title + ": nombre de usuario contiene caracteres inválidos"); return false}}
	for (i=0; i<domain.length; i++) {if (domain.charCodeAt(i)>127) {alert(FormField.title + ": nombre de dominio contiene caracteres inválidos"); FormField.focus(); return false}}
	if (user.match(userPat)==null) {alert(FormField.title + ": nombre de usuario no es válido."); FormField.focus(); return false}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {for (var i=1;i<=4;i++) {if (IPArray[i]>255) {alert(FormField.title + ": dirección IP no es válida"); FormField.focus(); return false}}; return true}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {if (domArr[i].search(atomPat)==-1) {alert(FormField.title + ": nombre de dominio no es válido."); FormField.focus(); return false}}
	if ((CheckTLD) && (domArr[domArr.length-1].length!=2) && (domArr[domArr.length-1].search(knownDomsPat)==-1)) {alert(FormField.title + ": debe terminar en dominio bien conocido o país de dos letras."); FormField.focus(); return false}
	if (len<2) {alert(FormField.title + ": le falta un nombre de anfitrión"); FormField.focus(); return false}
	return true;
	}

function x_redondear(numero, decimales){
	valor=NumberToFixed(numero,decimales);
	return valor;
}

function NumberToFixed(n,x) {
      var temp=n;
      temp=Math.round(temp*Math.pow(10,x))/Math.pow(10,x);
      return temp;
}

function x_formatearNumero2Decimales(numero) { 
	var val = parseFloat(numero); 
	if (isNaN(val)) { return "0.00"; } 
	if (val <= 0) { return "0.00"; } 
	val += ""; 
	// Next two lines remove anything beyond 2 decimal places 
	if (val.indexOf('.') == -1) { return val+".00"; } 
	else { val = val.substring(0,val.indexOf('.')+3); } 
	val = (val == Math.floor(val)) ? val + '.00' : ((val*10 == Math.floor(val*10)) ? val + '0' : val); 
	return val; 
} 
