var YA = false;

function ValidarTelefono(numero) {
	if (ValidarFijo(numero)||ValidarMovil(numero)) {
		return true;
	} else {
		return false;
	}
}


function ValidarFijo(numero){
	var NUMEROS="1234567890";
	if (numero.length==9) {
		for (var i=0;i<numero.length;i++) {
			if (NUMEROS.indexOf(numero.charAt(i))<0) {
				return false;
			}
			if (((numero.charAt(0)!='9' && numero.charAt(0)!='8')||numero.charAt(1)==0)) {
				return false;
			}
		}
		return true;
	} else {
		return false;
	}
}


function ValidarMovil(numero){
	var NUMEROS="1234567890";
	if (numero.length==9) {
		for (var i=0;i<numero.length;i++) {
			if (NUMEROS.indexOf(numero.charAt(i))<0) {
				return false;
			}
			if (numero.charAt(0)!='6' && numero.charAt(0)!='7') {
				return false;
			}
		}
		return true;
	} else {
		return false;
	}
}

function pedirAyuda(op)
{
	f = document.getElementById('frmayu');
	f.ope.value = op;
	
	$.fn.colorbox({width:"550", height:"400", open:true, inline:true,href:"#s3", open:true, onComplete:function(){$('#cboxClose').hide();}});
}

function validaAyuda(f)
{
	if (f.nombre.value == "" )
	{
		alert ("El nombre es obligatorio.");
		f.nombre.focus();
		return false;
	}

	if (f.tel.value == "" )
	{
		alert ("Debe introducir el telefono de contacto.");
		f.tel.focus();
		return false;
	}

	if (!ValidarTelefono(f.tel.value))
	{
		alert ("El telefono de contacto es incorrecto.");
		f.tel.focus();
		return false;
	}

	if (! f.politica.checked)
	{
		alert ("Tienes que aceptar la politica de privacidad.");
		f.politica.focus();
		return false;
	}

	if ( YA == true )
	{
		alert("Un momento por favor, ya estamos procesando tu peticion.");
		return false;
	}
	YA = true;
	f.submit();
}

function loadCobertura(acc, teln)
{
	if (acc != 'cobertura' )
		return true;

	tel = teln;

	$.fn.colorbox({width:"550", height:"300", open:true, inline:true,href:"#s5", open:true, onComplete:function(){$('#cboxClose').hide();}});

	$.ajax({
		type: "POST",
		url: "/remoto/ajax/listado-ofertas.php",
//		'async': false,
		data: "accion=cobertura&tel=" + tel,
		success: function(msg)
		{
			pos = msg.indexOf('Cober = No se ha podido comprobar');
			if (pos != -1)
			{
				window.location.href='/nueva-linea';
				return true;
			}

		    $("#id_listing_details").html(msg);
			$.fn.colorbox.close();
			return true;
		}
	});
	return false;
}

