var whitespace = " \t\n\r";
var defaultEmptyOK = false
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyzáéíóúñü"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÑ"

function validar() {
var envi = 1
form = document.formval
if (form.NOMBRE.value=='') {alert("Debe rellenar el campo NOMBRE");form.NOMBRE.focus();envi = 0;}
if (envi > 0) {if(form.TELEFONO.value=='') { alert("Debe rellenar el campo TELEFONO");form.TELEFONO.value='';form.TELEFONO.focus();envi = 0;}}
if (envi > 0) {if(isWhitespace(form.TELEFONO.value)) { alert("No deje espacios en el campo TELEFONO");form.TELEFONO.value='';form.TELEFONO.focus();envi = 0;}}
if (envi > 0) {if(!(esNumero(form.TELEFONO.value))) {alert("Ingrese sólo números para el campo TELEFONO");form.TELEFONO.value='';form.TELEFONO.focus();envi = 0;}}
if (envi > 0) {if(form.TELEFONO.value.length != 9) {alert("El campo teléfono debe contener 9 digitos");form.TELEFONO.value='';form.TELEFONO.focus();envi = 0;}}
if (envi == 0) {return false;} else {return true;}
}

// COMPROBAR SI ES UN CORREO ELECTRONICO

function isEmail (s)
{
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function isWhitespace (s)
{   var i;
	var compro = false
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        // si el caracter en que estoy no aparece en whitespace,
        // entonces retornar falso
        if (whitespace.indexOf(c) != -1) return true;
    }
    return false;
}

function isAlphanumeric (s)
{   var i;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!(isLetter(c) || isDigit(c) ) ) return false;
    }

    return true;
}

function esNumero (s)
{   var i;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!(isDigit(c))) return false;
    }

    return true;
}



function isLetter (c)
{
    return( ( uppercaseLetters.indexOf( c ) != -1 ) ||
            ( lowercaseLetters.indexOf( c ) != -1 ) )
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function selpobl(isla,muni) {
valor = 1
if (isla<1) {valor=0;alert("Antes debe seleccionar una Isla y un Municipio.")}
if (muni<1&&valor>0) {valor=0;alert("Seleccione un Municipio.")}

if (valor > 0) {
	pagina = "ci_pobl.asp?isla="+isla+"&muni="+muni
	window.open(pagina,"_blank",'toolbar=no,directories=no,scrollbars=yes,location=no,menubar=no,width=550, height=450, top=50,left=75,status=yes,');
}
}

function Cambiar(form) {
	cadena = form.file.value
	ancho = form.file.value.length	
	ext = cadena.substr(ancho-3,3).toLowerCase()
	if (ext!='jpg'&&ext!='gif'&&ext!='bmp'&&ext!='tif') {alert("Sólo se admiten imágenes en formato JPG,GIF,BMP o TIF,\nEl fichero seleccionado no será almacenado.");}
	else {MM_swapImage('logo','',cadena,1)}	
}

function calcula(form) {
	var precio = 0
	var precio2 = 0
	if (form.PACK[0].checked) {precio = 50}
	if (form.PACK[1].checked) {precio = 90}
	if (form.PACK[2].checked) {precio = 120}
	if (form.PACK[3].checked) {precio = 200}
	if (form.PACK[4].checked) {precio = 300}
	if (form.PACK[5].checked) {precio = 50}
	if (form.PACK[6].checked) {precio = 90}
	if (form.PACK[7].checked) {precio = 120}
	if (form.ICONOS.value > 0) {precio2 = parseInt(form.ICONOS.value)}
	form.TOTAL.value = precio + precio2 * 2
}

function validar2() {
var envi = 1
form = document.formval
if (form.NOMBRE.value=='') {alert("Debe rellenar el campo 'Nombre de Empresa'");form.NOMBRE.focus();envi = 0;}
if (envi > 0) {if (form.CONTACTO.value=='') {alert("Debe rellenar el campo 'Persona de contacto'");form.CONTACTO.focus();envi = 0;}}
if (envi > 0) {if(form.TELEFONO.value=='') { alert("Debe rellenar el campo TELEFONO");form.TELEFONO.value='';form.TELEFONO.focus();envi = 0;}}
if (envi > 0) {if(isWhitespace(form.TELEFONO.value)) { alert("No deje espacios en el campo TELEFONO");form.TELEFONO.value='';form.TELEFONO.focus();envi = 0;}}
if (envi > 0) {if(!(esNumero(form.TELEFONO.value))) {alert("Ingrese sólo números para el campo TELEFONO");form.TELEFONO.value='';form.TELEFONO.focus();envi = 0;}}
if (envi > 0) {if(form.TELEFONO.value.length != 9) {alert("El campo teléfono debe contener 9 digitos");form.TELEFONO.value='';form.TELEFONO.focus();envi = 0;}}
//if (envi > 0) {if (!isEmail(form.EMAIL.value)) {alert("El E-mail indicado no es correcto'");form.EMAIL.focus();envi = 0;}}
if (envi == 0) {return false;} else {return true;}
}

function ciayuda(num) {
	if (num == 1) {pagina = "ci_faq.asp"}
	if (num == 2) {pagina = "ci_precios.asp"}
	if (num == 3) {pagina = "ci_contrato.asp"}
	window.open(pagina,"_blank",'toolbar=no,directories=no,scrollbars=yes,location=no,menubar=no,width=655, height=450, top=50,left=170,status=yes,');
}

