// JavaScript Document
var nav4 = window.Event ? true : false;

//---- Comprobar si se han rellenado los campos obligatorios -----
function trim(cadena)
{
	cadena = cadena.replace(/^\s+/,'').replace(/\s+$/,'');
	return(cadena);
}

//---- Solo se permiten números ------
function solonum(evt)
{	
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
	var key = nav4 ? evt.which : evt.keyCode;	
	return (key <= 13 || (key >= 48 && key <= 57));
}

function validacorreo(email){
    regx = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
    return regx.test(email);
}

function validarformu(formu)
{
	var cont = 0;
	var domain = document.formu["domain"].value;
	var titular = document.formu["titular"].value;
	var contacto = document.formu["contacto"].value;
	var cif = document.formu["cif"].value;
	var email = document.formu["email"].value;
	var pais = document.formu["pais"].value;
	var provincia = document.formu["provincia"].value;
	var cp = document.formu["cp"].value;
	var tfno = document.formu["tfno"].value;
	
	domain = trim(domain);
	titular = trim(titular);
	contacto = trim(contacto);
	cif = trim(cif);	
	email = trim(email);
	cp = trim(cp);
	tfno = trim(tfno);
	
	if (domain.length == 0)
	{
		document.getElementById('campodominio').style.color = '#FF0000';
		document.getElementById('dominio2').innerHTML = "Debe introducir un nombre de dominio v&aacute;lido!!";
		document.getElementById('dominio1').style.display = '';
		document.formu["domain"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campodominio').style.color = '#000000';
		document.getElementById('dominio1').style.display = 'none';
	}
	
	if (titular.length == 0)
	{
		document.getElementById('campotitular').style.color = '#FF0000';
		document.getElementById('titular2').innerHTML = "Debe introducir un nombre de titular v&aacute;lido!!";
		document.getElementById('titular1').style.display = '';
		document.formu["titular"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotitular').style.color = '#000000';
		document.getElementById('titular1').style.display = 'none';
	}
	
	if (contacto.length == 0)
	{
		document.getElementById('campocontacto').style.color = '#FF0000';
		document.getElementById('contacto2').innerHTML = "Debe introducir un nombre de contacto v&aacute;lido!!";
		document.getElementById('contacto1').style.display = '';
		document.formu["contacto"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campocontacto').style.color = '#000000';
		document.getElementById('contacto1').style.display = 'none';
	}
	
	if (cif.length == 0)
	{
		document.getElementById('campocif').style.color = '#FF0000';
		document.getElementById('cif2').innerHTML = "Debe introducir el NIF/CIF del titular!!";
		document.getElementById('cif1').style.display = '';
		document.formu["cif"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campocif').style.color = '#000000';
		document.getElementById('cif1').style.display = 'none';
	}
	
	if (email.length == 0 || !validacorreo(email))
	{
		document.getElementById('campoemail').style.color = '#FF0000';
		document.getElementById('email2').innerHTML = "Debe introducir un E-Mail v&aacute;lido!!";
		document.getElementById('email1').style.display = '';
		document.formu["email"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campoemail').style.color = '#000000';
		document.getElementById('email1').style.display = 'none';
	}
		
	if ((pais == 0 || pais == 21) && provincia == 1)
	{
		document.getElementById('campoprovincia').style.color = '#FF0000';
		document.getElementById('provincia2').innerHTML = "Debe indicar su Provincia!!";
		document.getElementById('provincia1').style.display = '';
		document.formu["provincia"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campoprovincia').style.color = '#000000';
		document.getElementById('provincia1').style.display = 'none';
	}
	
	if (cp.length == 0)
	{
		document.getElementById('campocp').style.color = '#FF0000';
		document.getElementById('cp2').innerHTML = "Debe introducir un c&oacute;digo postal v&aacute;lido!!";
		document.getElementById('cp1').style.display = '';
		document.formu["cp"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campocp').style.color = '#000000';
		document.getElementById('cp1').style.display = 'none';
	}
	
	if (tfno.length == 0)
	{
		document.getElementById('campotfno').style.color = '#FF0000';
		document.getElementById('tfno2').innerHTML = "Debe introducir un n&uacute;mero de tel&eacute;fono v&aacute;lido!!";
		document.getElementById('tfno1').style.display = '';
		document.formu["tfno"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotfno').style.color = '#000000';
		document.getElementById('tfno1').style.display = 'none';
	}
	
	if (cont==0)
		document.formu.submit();
	else
		return false;
}

function validarformu2(formu)
{
	cont = 0;
	var pais = document.formu["pais"].value;
	var plan = document.formu["planb"].value;
		
	//--- SI NO SE HA SELECCIONADO UN PLAN --
	if (plan == "seleccione")
	{
		document.getElementById('campoplan').style.color = '#FF0000';
		document.getElementById('plan2').innerHTML = "Por favor, seleccione un Plan para poder continuar!!";
		document.getElementById('plan1').style.display = '';
		document.formu["planb"].focus();
		return false;
	}
	else
	{
		//-- tomo el valor del contrato seleccionado --
		if (document.formu.contrato2[0].checked)
			document.formu.contrato.value = document.formu.contrato2[0].value;
		else
			document.formu.contrato.value = document.formu.contrato2[1].value;
		
		//-- tomando el valor del plan elegido --
		if (pais == 0 || pais == 21)
		{
			if (document.formu.pago2[0].checked)
			{
				document.formu.pago.value = document.formu.pago2[0].value;
				
				if (document.formu.operacion.value == "alojamiento")
					document.formu.action = "contratar-alojamiento4.php";
				else
					document.formu.action = "registro-dominios4.php";
			}
			else if (document.formu.pago2[1].checked)
			{
				document.formu.pago.value = document.formu.pago2[1].value;
				
				if (document.formu.operacion.value == "alojamiento")
					document.formu.action = "contratar-alojamiento4.php";
				else
					document.formu.action = "registro-dominios4.php";
			}
			else
			{
				document.formu.pago.value = document.formu.pago2[2].value;
				
				if (document.formu.operacion.value == "alojamiento")
					document.formu.action = "contratar-alojamiento3DB.php";
				else
					document.formu.action = "registro-dominios3DB.php";
			}
		}
		
		document.formu.plan.value = document.formu.planb.value;
		document.formu.planb.selectedIndex = 0; 
		document.formu.contrato2[0].disabled = true;
		document.formu.contrato2[1].checked = true;
		
		if (pais==0 || pais==21)
		{
			document.formu.pago2[0].disabled = true;
			document.formu.pago2[1].disabled = true;
			document.formu.pago2[2].disabled = true;
			document.formu.pago2[0].checked = true;
		}
		
		
		document.formu.submit();
	}	
}

function validarformutj(formu)
{
	var cont = 0;
	var titulartj = document.formu["titulartj"].value;
	var numerotj = document.formu["numerotj"].value;
	var cvtj = document.formu["cvtj"].value;
		
	titulartj = trim(titulartj);
	numerotj = trim(numerotj);
	cvtj = trim(cvtj);	
	
	if (titulartj.length == 0)
	{
		document.getElementById('campotitulartj').style.color = '#FF0000';
		document.getElementById('titulartj2').innerHTML = "Debe introducir un nombre de titular v&aacute;lido!!";
		document.getElementById('titulartj1').style.display = '';
		document.formu["titulartj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotitulartj').style.color = '#000000';
		document.getElementById('titulartj1').style.display = 'none';
	} 
					 
	if (numerotj.length == 0 || numerotj.length < 16)
	{
		document.getElementById('camponumerotj').style.color = '#FF0000';
		document.getElementById('numerotj2').innerHTML = "Debe introducir un n&uacute;mero de tarjeta v&aacute;lido!!";
		document.getElementById('numerotj1').style.display = '';
		document.formu["numerotj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('camponumerotj').style.color = '#000000';
		document.getElementById('numerotj1').style.display = 'none';
	}
	
	if (isNaN(cvtj) || cvtj.length == 0 || cvtj.length <3)
	{
		document.getElementById('campocvtj').style.color = '#FF0000';
		document.getElementById('cvtj2').innerHTML = "Debe introducir un c&oacute;digo de validaci&oacute;n v&aacute;lido!!";
		document.getElementById('cvtj1').style.display = '';
		document.formu["cvtj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campocvtj').style.color = '#000000';
		document.getElementById('cvtj1').style.display = 'none';
	}
	
	if (cont==0)
		document.formu.submit();
	else
		return false;
}

function validarformutj2(formu)
{
	var cont = 0;
	var domain = document.formu["domain"].value;
	var email = document.formu["email"].value;
	var titulartj = document.formu["titulartj"].value;
	var numerotj = document.formu["numerotj"].value;
	var cvtj = document.formu["cvtj"].value;
		
	domain = trim(domain);
	email = trim(email);
	titulartj = trim(titulartj);
	numerotj = trim(numerotj);
	cvtj = trim(cvtj);	
	
	if (domain.length == 0)
	{
		document.getElementById('campodomain').style.color = '#FF0000';
		document.getElementById('domain2').innerHTML = "Debe introducir un nombre de dominio v&aacute;lido!!";
		document.getElementById('domain1').style.display = '';
		document.formu["domain"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campodomain').style.color = '#000000';
		document.getElementById('domain1').style.display = 'none';
	} 
	
	if (email.length == 0 || !validacorreo(email))
	{
		document.getElementById('campoemail').style.color = '#FF0000';
		document.getElementById('email2').innerHTML = "Debe introducir un E-Mail v&aacute;lido!!";
		document.getElementById('email1').style.display = '';
		document.formu["email"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campoemail').style.color = '#000000';
		document.getElementById('email1').style.display = 'none';
	}
	
	if (titulartj.length == 0)
	{
		document.getElementById('campotitulartj').style.color = '#FF0000';
		document.getElementById('titulartj2').innerHTML = "Debe introducir un nombre de titular v&aacute;lido!!";
		document.getElementById('titulartj1').style.display = '';
		document.formu["titulartj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotitulartj').style.color = '#000000';
		document.getElementById('titulartj1').style.display = 'none';
	} 
					 
	if (numerotj.length == 0 || numerotj.length < 16)
	{
		document.getElementById('camponumerotj').style.color = '#FF0000';
		document.getElementById('numerotj2').innerHTML = "Debe introducir un n&uacute;mero de tarjeta v&aacute;lido!!";
		document.getElementById('numerotj1').style.display = '';
		document.formu["numerotj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('camponumerotj').style.color = '#000000';
		document.getElementById('numerotj1').style.display = 'none';
	}
	
	if (isNaN(cvtj) || cvtj.length == 0 || cvtj.length <3)
	{
		document.getElementById('campocvtj').style.color = '#FF0000';
		document.getElementById('cvtj2').innerHTML = "Debe introducir un c&oacute;digo de validaci&oacute;n v&aacute;lido!!";
		document.getElementById('cvtj1').style.display = '';
		document.formu["cvtj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campocvtj').style.color = '#000000';
		document.getElementById('cvtj1').style.display = 'none';
	}
	
	if (cont==0)
		document.formu.submit();
	else
		return false;
}

function validarformtransf(formu)
{
	var cont = 0;
	var domain = document.formu["domain"].value;
	var titular = document.formu["titular"].value;
	var email = document.formu["email"].value;
			
	domain = trim(domain);
	titular = trim(titular);
	email = trim(email);
	
	if (domain.length == 0)
	{
		document.getElementById('campodomain').style.color = '#FF0000';
		document.getElementById('domain2').innerHTML = "Debe introducir un nombre de dominio v&aacute;lido!!";
		document.getElementById('domain1').style.display = '';
		document.formu["domain"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campodomain').style.color = '#000000';
		document.getElementById('domain1').style.display = 'none';
	} 
	
	if (titular.length == 0)
	{
		document.getElementById('campotitular').style.color = '#FF0000';
		document.getElementById('titular2').innerHTML = "Debe introducir un nombre de titular v&aacute;lido!!";
		document.getElementById('titular1').style.display = '';
		document.formu["titular"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotitular').style.color = '#000000';
		document.getElementById('titular1').style.display = 'none';
	} 
					 
	if (email.length == 0 || !validacorreo(email))
	{
		document.getElementById('campoemail').style.color = '#FF0000';
		document.getElementById('email2').innerHTML = "Debe introducir un E-Mail v&aacute;lido!!";
		document.getElementById('email1').style.display = '';
		document.formu["email"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campoemail').style.color = '#000000';
		document.getElementById('email1').style.display = 'none';
	}
	
	if (cont==0)
		document.formu.submit();
	else
		return false;
}

function validarformutraslado(formu)
{
	var cont = 0;
	var domain = document.formu["domain"].value;
	var titular = document.formu["titular"].value;
	var email = document.formu["email"].value;
	var tfno = document.formu["tfno"].value;
	
	domain = trim(domain);
	titular = trim(titular);
	email = trim(email);
	tfno = trim(tfno);
	
	if (domain.length == 0)
	{
		document.getElementById('campodominio').style.color = '#FF0000';
		document.getElementById('dominio2').innerHTML = "Debe introducir un nombre de dominio v&aacute;lido!!";
		document.getElementById('dominio1').style.display = '';
		document.formu["domain"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campodominio').style.color = '#000000';
		document.getElementById('dominio1').style.display = 'none';
	}
	
	if (titular.length == 0)
	{
		document.getElementById('campotitular').style.color = '#FF0000';
		document.getElementById('titular2').innerHTML = "Debe introducir un nombre de titular v&aacute;lido!!";
		document.getElementById('titular1').style.display = '';
		document.formu["titular"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotitular').style.color = '#000000';
		document.getElementById('titular1').style.display = 'none';
	}
	
	if (email.length == 0 || !validacorreo(email))
	{
		document.getElementById('campoemail').style.color = '#FF0000';
		document.getElementById('email2').innerHTML = "Debe introducir un E-Mail v&aacute;lido!!";
		document.getElementById('email1').style.display = '';
		document.formu["email"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campoemail').style.color = '#000000';
		document.getElementById('email1').style.display = 'none';
	}
		
	if (tfno.length == 0)
	{
		document.getElementById('campotfno').style.color = '#FF0000';
		document.getElementById('tfno2').innerHTML = "Debe introducir un n&uacute;mero de tel&eacute;fono v&aacute;lido!!";
		document.getElementById('tfno1').style.display = '';
		document.formu["tfno"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotfno').style.color = '#000000';
		document.getElementById('tfno1').style.display = 'none';
	}
	
	if (cont==0)
	{
		document.formu["subject"].value = "Traslado: " + document.formu["domain"].value + " .:: registro-dominios.info ::.";
		document.formu.submit();
	}
	else
		return false;
}

/*function validarformualoj(formu)
{
	var cont = 0;
	var dominio = document.formu["domain"].value;
			
	dominio = trim(dominio);
		
	if (dominio.length == 0)
	{
			document.getElementById('campodominio').style.color = '#FF0000';
			document.getElementById('dominio2').innerHTML = "Debe introducir un nombre de dominio v&aacute;lido!!";
			document.getElementById('dominio1').style.display = '';
			document.formu["domain"].focus();
			cont=1;
	}
	else
	{
		document.getElementById('campodominio').style.color = '#000000';
		document.getElementById('dominio1').style.display = 'none';
	}
	
	if (cont==0)
	{
		if (document.formu.operacion[0].checked)
			document.formu.action = "../buscador/mwhois.php";
		else
			document.formu.action = "contrataralojamiento2.php";
		document.formu.submit();
	}
	else 		
		return false;
			

}*/


/*function validarformucuenta(formu)
{
	var cont = 0;
	var titularcuenta = document.formu["titularcuenta"].value;
	var entidad = document.formu["entidad"].value;
	var sucursal = document.formu["sucursal"].value;
	var dc = document.formu["dc"].value;
	var cuenta = document.formu["cuenta"].value;
		
	titularcuenta = trim(titularcuenta);
	entidad = trim(entidad);
	sucursal = trim(sucursal);
	dc = trim(dc);
	cuenta = trim(cuenta);
	
	if (titularcuenta.length == 0)
	{
		document.getElementById('campotitularcuenta').style.color = '#FF0000';
		document.getElementById('titularcuenta2').innerHTML = "Debe introducir un nombre de titular v&aacute;lido!!";
		document.getElementById('titularcuenta1').style.display = '';
		document.formu["titularcuenta"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotitularcuenta').style.color = '#000000';
		document.getElementById('titularcuenta1').style.display = 'none';
	}
	
	if (isNaN(entidad) || entidad.length == 0 || entidad.length <4)
	{
		document.getElementById('campoentidad').style.color = '#FF0000';
		document.formu["entidad"].focus();
		cont=2;
	}
	else
	{
		document.getElementById('campoentidad').style.color = '#000000';
	}
	
	if (isNaN(sucursal) || sucursal.length == 0 || sucursal.length <4)
	{
		document.getElementById('camposucursal').style.color = '#FF0000';
		document.formu["sucursal"].focus();
		cont=2;
	}
	else
	{
		document.getElementById('camposucursal').style.color = '#000000';
	}
	
	if (isNaN(dc) || dc.length == 0 || dc.length < 2)
	{
		document.getElementById('campodc').style.color = '#FF0000';
		document.formu["dc"].focus();
		cont=2;
	}
	else
	{
		document.getElementById('campodc').style.color = '#000000';
	}
	
	if (isNaN(cuenta) || cuenta.length == 0 || cuenta.length < 10)
	{
		document.getElementById('campocuenta').style.color = '#FF0000';
		document.formu["cuenta"].focus();
		cont=2;
	}
	else
	{
		document.getElementById('campocuenta').style.color = '#000000';
	}
	
	if (cont == 2)
	{
		document.getElementById('datos2').innerHTML = "Por favor, revise su n&uacute;mero de cuante bancaria!!";
		document.getElementById('datos').style.display = '';	
	}
	else
	{
		document.getElementById('datos').style.display = 'none';
	}
	
	if (cont==0)
		document.formu.submit();
	else 		
		return false;
}
*/

