function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function replaceSubstring(inputString, fromString, toString) {
	var temp = inputString;
	if (fromString == '') {
	return inputString;
	}
	if (toString.indexOf(fromString) == -1){
	while (temp.indexOf(fromString) != -1){
	 var toTheLeft = temp.substring(0, temp.indexOf(fromString));
	 var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
	 temp = toTheLeft + toString + toTheRight;
	}
	}
	else{
	var midStrings = new Array('~', '`', '_', '^', '#');
	var midStringLen = 1;
	var midString = '';
	while (midString == '') {
	 for (var i=0; i < midStrings.length; i++) {
	    var tempMidString = '';
	    for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
	    if (fromString.indexOf(tempMidString) == -1) {
	       midString = tempMidString;
	       i = midStrings.length + 1;
	    }
	 }
	}
	while (temp.indexOf(fromString) != -1) {
	 var toTheLeft = temp.substring(0, temp.indexOf(fromString));
	 var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
	 temp = toTheLeft + midString + toTheRight;
	}
	while (temp.indexOf(midString) != -1) {
	 var toTheLeft = temp.substring(0, temp.indexOf(midString));
	 var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
	 temp = toTheLeft + toString + toTheRight;
	}
	}
	return temp;
}

function vprint(idioma,plana,parametros) {
	window.open("/vprint.php?Idioma="+idioma+"&Plana="+plana+"&"+parametros, "","resizable=1,SCROLLBARS=YES,HEIGHT=600,WIDTH=818");
}

function imprimir(){
	window.print();
	window.close();
}

function paginadoListado(mipagina) {
	var ff=window.document.bava;
	ff.pagina.value=mipagina;
	ff.submit();
}

function RedimensionarMenu(){
	
	/*
	
	if(window.document.getElementById("menu")){
		
		var mi_menu = window.document.getElementById("menu");
		widthTotal = mi_menu.offsetWidth;
		
		var enlaces = mi_menu.getElementsByTagName("a");
		var total = enlaces.length;
		var widthMenu = 0;
		for(i=0; i<total; i++){
			widthMenu += enlaces[i].offsetWidth;
		}
		widthMenu += total - 1;
		
		if(widthTotal > widthMenu){
			var resto = widthTotal - widthMenu;
			var pRight = window.document.getElementById("sinmenu").offsetWidth;
			total = pRight + resto - (14 + 14);
			window.document.getElementById("sinmenu").style.width = total + "px";
		}
		
	}

	*/

	if(window.document.getElementById("menu")){

		var widthMenu = $("#menu").width();
		
		var enlaces = $("#menu a");
		var total = enlaces.length;
		var widthReal = 0;
		for(i=0; i<total; i++){
			widthReal += $(enlaces[i]).width() + 14 + 14 + 1;
		}
		widthReal++;
		
		if(navigator.userAgent.indexOf("Mac") != -1){ 
			widthReal++;
		} 		
		
		if(widthMenu > widthReal){
			var resto =  widthMenu - widthReal;
			var cambio = parseInt($("#menu #sinmenu").css("padding-right"));
			var total = cambio + resto;
			$("#menu #sinmenu").css("padding-right",total+"px");
		}
		
	}

			

}

function AjustaHome(){
	
	var altoIzq = document.getElementById("actualidad-izq").offsetHeight;
	var altoDer = document.getElementById("actualidad-der").offsetHeight;
	if(altoIzq > altoDer){
		document.getElementById("actualidad-der").style.height = altoIzq + "px";
	}
	else if(altoDer > altoIzq){
		document.getElementById("actualidad-izq").style.height = altoDer + "px";
	}

}

function getRadio(ctrl){
	for(i=0;i<ctrl.length;i++)
		if(ctrl[i].checked) return ctrl[i].value;
}

function elimina_acentos(cadena){
	tofind = "ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ,;.:-_´¨+*`[]'¡?¿ºª!·$%&/()=?¿|@#~’";
	replac = "AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn                                   ";
	return(strtr(cadena,tofind,replac));
}

function Arregla_Rewrite(texto) {
	texto = elimina_acentos(texto);
	texto = str_replace('"',"",texto);
	texto = str_replace("  "," ",texto);
	texto = str_replace("  "," ",texto);
	texto = str_replace("  "," ",texto);
	texto = str_replace("  "," ",texto);
	texto = str_replace(" ","-",texto);
	return texto;
}

function vaciar(dato){
	dato.value = "";
}

function comprobarEmail(valor) {
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\D{2,4})+$/.test(valor)){
		return false;
	} else {
		return true;
	}
}

function validarNIF(nif) {
	nif = replaceSubstring(nif,' ','');
	nif = replaceSubstring(nif,'-','');
	nif = replaceSubstring(nif,'.','');
	if(nif.length!=9){
		return false;
	}
	else{
		if(!(CalculaNif(nif) || CalculaCif(nif) || CalculaNie(nif))) {
			return false;
		}
		else {
			return true;
		}
	}
}

function CalculaNie(nif){
	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';
	var letraNie = nif.substring(0,1);
	var dni = nif.substring(1,8);
	var letraNif = nif.substring(8,9);
	var letraAux;
	var letraInicio='X';
	var numero = dni%23;
	letraAux = letras.substring(numero,numero+1);
	if ((letraAux == letraNif.toUpperCase()) && (letraInicio==letraNie.toUpperCase())){
		return true;
	}
	else{
		return false;
	}
}

function CalculaNif(nif){
	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';
	var dni    = nif.substring(0,8);
	var letraNif = nif.substring(8,9);
	var letraAux;
	var numero = dni%23;
	letraAux = letras.substring(numero,numero+1);
	if(letraAux == letraNif.toUpperCase()){
		return true;
	}
	else{
		return false;
	}
}

function CalculaCif(elCIF){
	var resul = false;
	var temp = elCIF.toUpperCase();
	if (!/^[A-Za-z0-9]{9}$/.test(temp)) {
		resul = false;
	}
	else {
		if (!/^[ABCDEFGHKLMNPQS]/.test(temp)) {
			resul = false;
		}
		else {
			resul = ValidaCIF(temp);
		}
	}
	return resul;
}

function ValidaCIF(elCIF){
	var resul = false;
	var v1 = new Array(0,2,4,6,8,1,3,5,7,9);
	var letrascif = 'ABCDEFGHIJ';
	var temp = 0;
	var temp1;
	for(i=2;i<=6;i+=2){
		temp = temp + v1[parseInt(elCIF.substr(i-1,1))];
		temp = temp + parseInt(elCIF.substr(i,1));
	}
	temp = temp + v1[parseInt(elCIF.substr(7,1))];
	temp = (10 - ( temp % 10));
	if( temp == 10 ) {
		if ((elCIF.substring(8,9)=='J') || (elCIF.substring(8,9)=='0')) {
			resul = true;
		}
		else {
			resul = false;
		}
	}
	else {
		if ((elCIF.substring(8,9)==temp) || (elCIF.substring(8,9)==letrascif.substring(temp-1,temp))) {
			resul = true;
		}
		else {
			resul = false;
		}
	}
	return resul;
}

function validarBusqueda(){

	ff = window.document.f_busqueda;
	if(ff.busqueda.value.length < 3){
		alert("Introduzca como mínimo un criterio de búsqueda (3 caractéres).");
	}
	else{
		ff.submit();
	}
	
}

function validarBuscarDominios(){

	ff = window.document.f_dominios;
	if(ff.sld.value.length < 3){
		alert("Introduzca como mínimo un nombre de dominio (3 caractéres).");
	}
	else{
		ff.submit();
	}

}

function activarBuscarDominios(){
	window.document.f_dominios.enviar.click();
}

function borrarContacto(){
	ff = window.document.f_contactar;
	ff.Nombre.value = "";
	ff.Apellidos.value = "";
	ff.Empresa.value = "";
	ff.Telefono.value = "";
	ff.Email.value = "";
	ff.Comentarios.value = "";
	ff.Captcha.value = "";
}

function activarValidarContacto(){
	window.document.f_contactar.enviar.click();
}

function validarContacto(){

	ff = window.document.f_contactar;
	fallo = "";
	if(ff.Nombre.value.length < 3){ fallo += "· Nombre (mínimo 3 caractéres).\n"; }
	if(ff.Apellidos.value.length < 3){ fallo += "· Apellidos (mínimo 3 caractéres).\n"; }
	if(ff.Telefono.value.length < 9){ fallo += "· Teléfono de contacto (mínimo 9 caractéres).\n"; }
	if(ff.Email.value.length < 3){ fallo += "· Email (mínimo 3 caractéres).\n"; }else if(!comprobarEmail(ff.Email.value)){ fallo += "· Email incorrecto.\n"; }
	if(ff.Presupuesto.value == ""){ fallo += "· Solicitar.\n"; }
	if(ff.Comentarios.value == ""){ fallo += "· Comentarios.\n"; }
	if(ff.Captcha.value == ""){ fallo += "· Texto de la imagen.\n"; }
	if(!ff.Politica.checked){ fallo += "· Debes aceptar nuestra política de privacidad y protección de datos.\n"; }
	if(fallo != ""){
		alert("Se ha producido un error en la inserción de los datos del formulario.\nPor favor revise atentamente el/los siguiente/s campo/s:\n\n" + fallo);
	}
	else{
		ff.submit();
	}
	
}

function borrarEnviar(){
	ff = window.document.f_enviar;
	ff.nombre_de.value = "";
	ff.email_de.value = "";
	ff.nombre_para.value = "";
	ff.email_para.value = "";
	ff.Captcha.value = "";
}

function activarValidarEnviar(){
	window.document.f_enviar.enviar.click();
}

function validarEnviar(){

	ff = window.document.f_enviar;
	fallo = "";
	if(ff.nombre_de.value.length < 3){ fallo += "· Nombre del remitente (mínimo 3 caractéres).\n"; }
	if(ff.email_de.value.length < 3){ fallo += "· Email del remitente (mínimo 3 caractéres).\n"; }else if(!comprobarEmail(ff.email_de.value)){ fallo += "· Email del remitente incorrecto.\n"; }
	if(ff.nombre_para.value.length < 3){ fallo += "· Nombre de tu amigo (mínimo 3 caractéres).\n"; }
	if(ff.email_para.value.length < 3){ fallo += "· Email de tu amigo (mínimo 3 caractéres).\n"; }else if(!comprobarEmail(ff.email_para.value)){ fallo += "· Email de tu amigo incorrecto.\n"; }
	if(ff.Captcha.value == ""){ fallo += "· Texto de la imagen.\n"; }
	if(fallo != ""){
		alert("Se ha producido un error en la inserción de los datos del formulario.\nPor favor revise atentamente el/los siguiente/s campo/s:\n\n" + fallo);
	}
	else{
		ff.submit();
	}
	
}

function regenera_texto_outlook_1() {
	ff = window.document.ffcorreo;
	var mi_email = ff.mi_email.value;
	if((mi_email == "") || !comprobarEmail(mi_email)){
		alert("Introduzca un email válido.");
	} else {
		var valores = mi_email.split("@");
		document.getElementById("outlook_2_1").innerHTML = '<span class="txt">'+mi_email+'</span>';
		document.getElementById("outlook_3_1").innerHTML = '<span class="txt">mail.'+valores[1]+'</span>';
		document.getElementById("outlook_3_2").innerHTML = '<span class="txt">mail.'+valores[1]+'</span>';
		document.getElementById("outlook_4_1").innerHTML = '<span class="txt">'+mi_email+'</span>';
		document.getElementById("outlook_5_1").innerHTML = '<span class="txtblanco">mail.'+valores[1]+'</span>';
		document.getElementById("outlook_6_1").innerHTML = '<span class="txt">mail.'+valores[1]+'</span>';
		document.getElementById("outlook_6_2").innerHTML = '<span class="txt">mail.'+valores[1]+'</span>';
		document.getElementById("outlook_6_3").innerHTML = '<span class="txt">'+mi_email+'</span>';
		document.getElementById("outlook_6_5").innerHTML = '<span class="txtblanco">mail.'+valores[1]+'</span>';
		document.getElementById("outlook_7_1").innerHTML = '<span class="txtblanco">mail.'+valores[1]+'</span>';
		document.getElementById("outlook_8_1").innerHTML = '<span class="txtblanco">mail.'+valores[1]+'</span>';
		document.getElementById("faq-oculta").style.display = "block";
	}
}

function regenera_texto_outlook_2() {
	ff = window.document.ffcorreo;
	var mi_email = ff.mi_email.value;
	if((mi_email == "") || !comprobarEmail(mi_email)){
		alert("Introduzca un email válido.");
	} else {
		var valores = mi_email.split("@");
		document.getElementById("outlook2000_1_1").innerHTML = '<span class="txt">'+mi_email+' en Dommia</span>';
		document.getElementById("outlook2000_1_4").innerHTML = '<span class="txt">'+mi_email+'</span>';
		document.getElementById("outlook2000_2_1").innerHTML = '<span class="txt">mail.'+valores[1]+'</span>';
		document.getElementById("outlook2000_2_2").innerHTML = '<span class="txt">mail.'+valores[1]+'</span>';
		document.getElementById("outlook2000_2_3").innerHTML = '<span class="txt">'+mi_email+'</span>';
		document.getElementById("faq-oculta").style.display = "block";
	}
}

function regenera_texto_outlook_3() {
	ff = window.document.ffcorreo;
	var mi_email = ff.mi_email.value;
	if((mi_email == "") || !comprobarEmail(mi_email)){
		alert("Introduzca un email válido.");
	} else {
		var valores = mi_email.split("@");
		document.getElementById("outlook2003_1_2").innerHTML = '<span class="txt">'+mi_email+'</span>';
		document.getElementById("outlook2003_1_3").innerHTML = '<span class="txt">'+valores[0]+'</span>';
		document.getElementById("outlook2003_1_5").innerHTML = '<span class="txt">mail.'+valores[1]+'</span>';
		document.getElementById("outlook2003_1_6").innerHTML = '<span class="txt">mail.'+valores[1]+'</span>';
		document.getElementById("outlook2003_2_1").innerHTML = '<span class="txt">'+mi_email+' en Dommia</span>';
		document.getElementById("outlook2003_3_2").innerHTML = '<span class="txt">'+mi_email+'</span>';
		document.getElementById("outlook2003_3_3").innerHTML = '<span class="txt">'+valores[0]+'</span>';
		document.getElementById("outlook2003_3_5").innerHTML = '<span class="txt">mail.'+valores[1]+'</span>';
		document.getElementById("outlook2003_3_6").innerHTML = '<span class="txt">mail.'+valores[1]+'</span>';
		document.getElementById("faq-oculta").style.display = "block";
	}
}

function MasInfo(id){
	if($(".ico-mas-" + id).attr("src") == "/media/image/web/mas.gif"){
		$(".ico-mas-" + id).attr("src","/media/image/web/menos.gif");
	} else {
		$(".ico-mas-" + id).attr("src","/media/image/web/mas.gif");
	}
	$(".hosting-" + id).fadeToggle("slow");
}
