// 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 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.formu["domain"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campodominio').style.color = '#000000';
	}
	
	if (titular.length == 0)
	{
		document.getElementById('campotitular').style.color = '#FF0000';
		document.formu["titular"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotitular').style.color = '#000000';
	}
	
	if (contacto.length == 0)
	{
		document.getElementById('campocontacto').style.color = '#FF0000';
		document.formu["contacto"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campocontacto').style.color = '#000000';
	}
	
	if (cif.length == 0)
	{
		document.getElementById('campocif').style.color = '#FF0000';
		document.formu["cif"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campocif').style.color = '#000000';
	}
	
	if (email.length == 0 || !validacorreo(email))
	{
		document.getElementById('campoemail').style.color = '#FF0000';
		document.formu["email"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campoemail').style.color = '#000000';
	}
		
	if (provincia == 1)
	{
		document.getElementById('campoprovincia').style.color = '#FF0000';
		document.formu["provincia"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campoprovincia').style.color = '#000000';
	}
	
	if (cp.length == 0)
	{
		document.getElementById('campocp').style.color = '#FF0000';
		document.formu["cp"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campocp').style.color = '#000000';
	}
	
	if (tfno.length == 0)
	{
		document.getElementById('campotfno').style.color = '#FF0000';
		document.formu["tfno"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotfno').style.color = '#000000';
	}
	
	if (cont==0)
		document.formu.submit();
	else
		return false;
}

function validarformu2(formu)
{
	cont = 0;
	var plan = document.formu["planb"].value;
		
	//--- SI NO SE HA SELECCIONADO UN PLAN --
	if (plan == "seleccione")
	{
		document.getElementById('campoplan').style.color = '#FF0000';
		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 ("nada" == "nada")
		{
			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-alojamiento3TJ.php";
				else
					document.formu.action = "registro-dominios3TJ.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 ("nada" == "nada")
		{
			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.formu["titulartj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotitulartj').style.color = '#000000';
	} 
					 
	if (numerotj.length == 0 || numerotj.length < 16)
	{
		document.getElementById('camponumerotj').style.color = '#FF0000';
		document.formu["numerotj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('camponumerotj').style.color = '#000000';
	}
	
	if (isNaN(cvtj) || cvtj.length == 0 || cvtj.length <3)
	{
		document.getElementById('campocvtj').style.color = '#FF0000';
		document.formu["cvtj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campocvtj').style.color = '#000000';
	}
	
	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.formu["domain"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campodomain').style.color = '#000000';
	} 
	
	if (email.length == 0 || !validacorreo(email))
	{
		document.getElementById('campoemail').style.color = '#FF0000';
		document.formu["email"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campoemail').style.color = '#000000';
	}
	
	if (titulartj.length == 0)
	{
		document.getElementById('campotitulartj').style.color = '#FF0000';
		document.formu["titulartj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotitulartj').style.color = '#000000';
	} 
					 
	if (numerotj.length == 0 || numerotj.length < 16)
	{
		document.getElementById('camponumerotj').style.color = '#FF0000';
		document.formu["numerotj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('camponumerotj').style.color = '#000000';
	}
	
	if (isNaN(cvtj) || cvtj.length == 0 || cvtj.length <3)
	{
		document.getElementById('campocvtj').style.color = '#FF0000';
		document.formu["cvtj"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campocvtj').style.color = '#000000';
	}
	
	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.formu["domain"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campodomain').style.color = '#000000';
	} 
	
	if (titular.length == 0)
	{
		document.getElementById('campotitular').style.color = '#FF0000';
		document.formu["titular"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotitular').style.color = '#000000';
	} 
					 
	if (email.length == 0 || !validacorreo(email))
	{
		document.getElementById('campoemail').style.color = '#FF0000';
		document.formu["email"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campoemail').style.color = '#000000';
	}
	
	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.formu["domain"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campodominio').style.color = '#000000';
	}
	
	if (titular.length == 0)
	{
		document.getElementById('campotitular').style.color = '#FF0000';
		document.formu["titular"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotitular').style.color = '#000000';
	}
	
	if (email.length == 0 || !validacorreo(email))
	{
		document.getElementById('campoemail').style.color = '#FF0000';
		document.formu["email"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campoemail').style.color = '#000000';
	}
		
	if (tfno.length == 0)
	{
		document.getElementById('campotfno').style.color = '#FF0000';
		document.formu["tfno"].focus();
		cont=1;
	}
	else
	{
		document.getElementById('campotfno').style.color = '#000000';
	}
	
	if (cont==0)
	{
		document.formu["subject"].value = "Traslado: " + document.formu["domain"].value + " .:: registro-dominios.info ::.";
		document.formu.submit();
	}
	else
		return false;
}

