    var xmlHttp;
	var disp = false;
	
	function noenter() {
	  return !(window.event && window.event.keyCode == 13); 
	}
	
	function showPagos01(theId) {
		document.getElementById(theId).style.display = "block";
	}
    
    function createXMLHttpRequest() {
        try {
		req = new XMLHttpRequest();
	} catch(err1) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (err2) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (err3) {
				req = false;
			}
		}
	}
	return req;
    }
	
	function getDisponibilidad(showin, tamanio) { //Disponibilidad
        url = "disponibilidadBanner.php?" + 
				"showin=" + showin + 
				"&tamanio=" + tamanio + 
				"&pais=" + document.getElementById("paisfp").value + 
				"&provincia=" + document.getElementById("provinciafp").value + 
				"&localidad=" + document.getElementById("localidadfp").value + 
				"&categoria=" + document.getElementById("categoriafp").value + 
				"&subcategoria=" + document.getElementById("subcategoriafp").value;
        
        xmlHttp = createXMLHttpRequest();
        xmlHttp.onreadystatechange = handleDisponibilidad;
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
    }
	
	function handleDisponibilidad() {
        if(xmlHttp.readyState == 4) {
            if(xmlHttp.status == 200) {
			    updateDisponibilidad();
            }
            else {
                alert("Error al cargar los datos.");
            }
        }
    }
	
	function updateDisponibilidad() {
		var response = xmlHttp.responseXML.documentElement;
		if(response.getElementsByTagName('disponible')[0].firstChild.data == "N")
		{
			document.getElementById("txtDisponible").innerHTML = "No se encuentra espacio disponible para publicar su Banner";
			disp = false;
		}
		else
		{
			document.getElementById("txtDisponible").innerHTML = "Espacio disponible.";
			disp = true;
		}
    }
	
    function getSubCategorias() { //1
	idData = document.getElementById("categoria").value;
        url = "ajax/cb_subCategoria.php?id=" + idData;
	removeOptionLast(document.getElementById("subcategoria"));
        
        xmlHttp = createXMLHttpRequest();
        xmlHttp.onreadystatechange = handleCategoriaChange;
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
    }
    
    function getProvincias() { //2
        idData = document.getElementById("pais").value;
        url = "ajax/cb_provincia.php?id=" + idData;
	removeOptionLast(document.getElementById("provincia"));
	removeOptionLast(document.getElementById("localidad"));
        
        xmlHttp = createXMLHttpRequest();
        xmlHttp.onreadystatechange = handlePaisChange;
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
    }

    function getLocalidades() { //3
	idData = document.getElementById("provincia").value;
        url = "ajax/cb_localidad.php?id=" + idData;
        
        xmlHttp = createXMLHttpRequest();
        xmlHttp.onreadystatechange = handleLocalidadChange;
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
    }

    function getLocalidadesFP() { //3
	idData = document.getElementById("provinciafp").value;
        url = "ajax/cb_localidad.php?id=" + idData;
        
        xmlHttp = createXMLHttpRequest();
        xmlHttp.onreadystatechange = handleLocalidadChangeFP;
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
    }
	
	function submitform2()
    {
		if( document.getElementById('categoria').value == 6 || (document.getElementById('keyWords').value != "" && document.getElementById('categoria').value == -1 && document.getElementById('pais').value == -1) || (document.getElementById('keyWords').value != "" && document.getElementById('pais').value != -1) )
		{
			alert("Es posible que encuentre material Sólo para Adultos")
		}
		//alert("Seleccione un al menos una categoria o un pais en donde desea realizar la búsqueda");
    }

    function submitform()
    {
		if(document.getElementById('categoria').value > -1 || document.getElementById('pais').value > -1) {
			if( document.getElementById('categoria').value == 6 || (document.getElementById('keyWords').value != "" && document.getElementById('categoria').value == -1 && document.getElementById('pais').value == -1) || (document.getElementById('keyWords').value != "" && document.getElementById('pais').value != -1 && document.getElementById('categoria').value == -1) )
			{
				alert("Es posible que encuentre material Sólo para Adultos")
			}
			if(document.formbus.keyWords.value == ""){
				window.location = "searchcr.php?subcategoria=0&ipaid=0&ifree=0&type=3&current=1&cat=" + document.getElementById("categoria").value + "&sub=" + document.getElementById("subcategoria").value + "&pai=" + document.getElementById("pais").value + "&pro=" + document.getElementById("provincia").value + "&loc=" + document.getElementById("localidad").value + "&rinicio=1";
			}else{
				document.formbus.submit();
			}
		}else {
			alert("Seleccione al menos una categoría o un país en donde desea realizar la búsqueda");
			return false;
		}
		return true;
    }

    function CreateBookmarkLink() { 
	url = "Webpage URL";  
	if (window.sidebar) {	
		window.sidebar.addPanel(document.title, location.href,"");	
	} else if( window.external ) { 
		window.external.AddFavorite( location.href, document.title); 
	} else if(window.opera && window.print) { 
		return true; 
	} 
    }

    function getDataforList(type) {
	xmlHttp = createXMLHttpRequest();
	switch(type)
	{
		case 1: 
			idData = document.getElementById("categoria").value;
			url = "ajax/cb_subCategoria.php?id=" + idData;
			removeOptionLast(document.getElementById("subcategoria"));
			xmlHttp.onreadystatechange = handleCategoriaChange;
			break;
		case 2:
			idData = document.getElementById("pais").value;
			url = "ajax/cb_provincia.php?id=" + idData;
			removeOptionLast(document.getElementById("provincia"));
			removeOptionLast(document.getElementById("localidad"));
			xmlHttp.onreadystatechange = handlePaisChange;
			break;
		case 3:
			idData = document.getElementById("provincia").value;
        		url = "ajax/cb_localidad.php?id=" + idData;
			xmlHttp.onreadystatechange = handleLocalidadChange;
			break;
		case 4: 
			idData = document.getElementById("categoriafp").value;
			url = "ajax/cb_subCategoria.php?id=" + idData;
			removeOptionLast(document.getElementById("subcategoriafp"));
			xmlHttp.onreadystatechange = handleCategoriaChangeFP;
			break;
		case 5:
			idData = document.getElementById("paisfp").value;
			url = "ajax/cb_provincia.php?id=" + idData;
			removeOptionLast(document.getElementById("provinciafp"));
			removeOptionLast(document.getElementById("localidadfp"));
			xmlHttp.onreadystatechange = handlePaisChangeFP;
			break;
		case 6:
			idData = document.getElementById("provinciafp").value;
			url = "ajax/cb_provincia.php?id=" + idData;
			xmlHttp.onreadystatechange = handleLocalidadChangeFP;
			break;
	}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
    }
	
	function handleStatusChange() {
        if(xmlHttp.readyState == 4) {
            if(xmlHttp.status == 200) {
		    updateStatus();
            }
            else {
                alert("Error al cargar los datos.");
            }
        }
    }

    function handleCategoriaChangeFP() {
        if(xmlHttp.readyState == 4) {
            if(xmlHttp.status == 200) {
		    updateCategoria("subcategoriafp");
            }
            else {
                alert("Error al cargar los datos.");
            }
        }
    }

    function handleCategoriaChange() {
        if(xmlHttp.readyState == 4) {
            if(xmlHttp.status == 200) {
		    updateCategoria("subcategoria");
            }
            else {
                alert("Error al cargar los datos.");
            }
        }
    }

    function handlePaisChangeFP() {
        if(xmlHttp.readyState == 4) {
            if(xmlHttp.status == 200) {
		    updateProvincia("provinciafp",false);
            }
            else {
                alert("Error al cargar los datos.");
            }
        }
    }
    
    function handlePaisChange() {
        if(xmlHttp.readyState == 4) {
            if(xmlHttp.status == 200) {
		    updateProvincia("provincia",true);
            }
            else {
                alert("Error al cargar los datos.");
            }
        }
    }

    function handleLocalidadChangeFP() {
	if(xmlHttp.readyState == 4) {
            if(xmlHttp.status == 200) {
		    updateLocalidad("localidadfp");
            }
            else {
                alert("Error al cargar los datos.");
            }
        }
    }

    function handleLocalidadChange() {
	if(xmlHttp.readyState == 4) {
            if(xmlHttp.status == 200) {
		    updateLocalidad("localidad");
            }
            else {
                alert("Error al cargar los datos.");
            }
        }
    }

    function updateCategoria(elementName) {
	var localidadXML = xmlHttp.responseXML.getElementsByTagName("subcategoria");
	var cb_localidad = document.getElementById(elementName);

	for (var i = 0; i < localidadXML.length; i++) {
		var iLocalidad = localidadXML[i].getElementsByTagName("sub_id");
		var nLocalidad = nLocalidad = localidadXML[i].getElementsByTagName("sub_nombre");
		cb_localidad.options[cb_localidad.options.length] = new Option(nLocalidad[0].firstChild.nodeValue, iLocalidad[0].firstChild.nodeValue,false,false);
	}
    }
	
	var intentos = 1;
	
	function updateStatus() {
		var xmlDoc = xmlHttp.responseXML;
		var respuesta1 = xmlDoc.getElementsByTagName("number")[0].childNodes[0].nodeValue;
		var respuesta2 = xmlDoc.getElementsByTagName("url")[0].childNodes[0].nodeValue;
		var respuesta3 = xmlDoc.getElementsByTagName("tiempo")[0].childNodes[0].nodeValue;
		//var iLocalidad = localidadXML[0].getElementsByTagName("number");
		
		//alert("Number" + respuesta1);
		//alert("URL" + respuesta2);
		//alert("Tiempo" + respuesta3);
		if(respuesta1 == "OK"){
			document.compra001.submit();
		}
		document.getElementById("estado").innerHTML = "Intento: " + intentos + "<br/>Status: " + respuesta1 + "<br/>URL: " + respuesta2 + "<br/>Tiempo: " + respuesta3;
		intentos++;
    }

    function updateLocalidad(elementName) {
	var localidadXML = xmlHttp.responseXML.getElementsByTagName("localidad");
	var cb_localidad = document.getElementById(elementName);
	removeOptionLast(cb_localidad);

	for (var i = 0; i < localidadXML.length; i++) {
		var iLocalidad = localidadXML[i].getElementsByTagName("id");
		var nLocalidad = nLocalidad = localidadXML[i].getElementsByTagName("municipio");
		cb_localidad.options[cb_localidad.options.length] = new Option(nLocalidad[0].firstChild.nodeValue, iLocalidad[0].firstChild.nodeValue,false,false);
	}
    }

    function updateProvincia(elementName, type) {
	var provinciaXML = xmlHttp.responseXML.getElementsByTagName("provincia");
	var cb_provincia = document.getElementById(elementName);

	for (var i = 0; i < provinciaXML.length; i++) {
		var iProvincia = provinciaXML[i].getElementsByTagName("id");
		var nProvincia = nProvincia = provinciaXML[i].getElementsByTagName("nombre");
		if(nProvincia.length == 0)
			nProvincia = provinciaXML[i].getElementsByTagName("opcion");
		else
			if (type)
				cb_provincia.onchange = function(){getLocalidades()};
			else
				cb_provincia.onchange = function(){getLocalidadesFP()};
		cb_provincia.options[cb_provincia.options.length] = new Option(nProvincia[0].firstChild.nodeValue, iProvincia[0].firstChild.nodeValue,false,false);
	}
    }

    function removeOptionLast(elSel) {
	while (elSel.length > 1) {
		elSel.remove(elSel.length - 1);
	}
    }

var checkobj
function agreesubmit(el){
	checkobj=el
	if (document.all||document.getElementById){
		for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
		var tempobj=checkobj.form.elements[i]
		if(tempobj.type.toLowerCase()=="submit")
			tempobj.disabled=!checkobj.checked
		}
	}
}

function defaultagree(el){
	if (!document.all&&!document.getElementById){
		if (window.checkobj&&checkobj.checked)
		return true
		else{
			alert("Lea las clausulas legales")
			return false
		}
	}
}

function validaLists(){
	if(document.getElementById("categoriafp").value < 1){
		alert("Dato obligatorio: Debe seleccionar una CATEGORIA");
		document.getElementById("categoriafp").focus();
		return false;
	}

	if(document.getElementById("subcategoriafp").value < 1){
		alert("Dato obligatorio: Debe seleccionar una SUBCATEGORIA");
		document.getElementById("subcategoriafp").focus();
		return false;
	}

	if(document.getElementById("paisfp").value < 1){
		alert("Dato obligatorio: Debe seleccionar un PAIS");
		document.getElementById("paisfp").focus();
		return false;
	}

	if(document.getElementById("paisfp").value == 70 && document.getElementById("provinciafp").value < 1){
		alert("Dato obligatorio: Debe seleccionar una PROVINCIA");
		document.getElementById("provinciafp").focus();
		return false;
	}

	if(document.getElementById("paisfp").value == 70 && document.getElementById("localidadfp").value < 1){
		alert("Dato obligatorio: Debe seleccionar una LOCALIDAD");
		document.getElementById("localidadfp").focus();
		return false;
	}
	return true;
}

function check_form(f) {
		if(!check_entero2(f.edad))
		{
			f.edad.value = 0;
		}
		if(f.nombre.value == 0){
		alert("Dato obligatorio: NOMBRE. Solo admite letras y espacios");
		f.nombre.focus();
		f.edad.value = 0;
		return false;
		}
		if(f.apellidos.value == 0){
		alert("Dato obligatorio: Apellido. Solo admite letras y espacios");
		f.apellidos.focus();
		f.edad.value = 0;
		return false;
		}
		if(!validaLists()){
			f.edad.value = 0;
		return false;
		}
		if(f.email.value.indexOf('@',0)==-1 || f.email.value.indexOf(';',0)!=-1
		
			|| f.email.value.indexOf(' ',0)!=-1 || f.email.value.indexOf('/',0)!=-1
		
			|| f.email.value.indexOf(';',0)!=-1 || f.email.value.indexOf('<',0)!=-1
		
			|| f.email.value.indexOf('>',0)!=-1 || f.email.value.indexOf('*',0)!=-1
		
			|| f.email.value.indexOf('|',0)!=-1 || f.email.value.indexOf('`',0)!=-1
		
			|| f.email.value.indexOf('&',0)!=-1 || f.email.value.indexOf('$',0)!=-1
		
			|| f.email.value.indexOf('!',0)!=-1 || f.email.value.indexOf('"',0)!=-1
		
			|| f.email.value.indexOf(':',0)!=-1) {
		
				alert("Dato obligatorio: email. El email tiene que tener un formato correcto");
				f.email.focus();
				f.edad.value = 0;
				return (false);
		  }
		if(f.telefono1.value == 0){
		alert("Dato obligatorio: telefono");
		f.edad.value = 0;
		f.telefono1.focus();
		return false;
		}
		if(f.provincia.value == 0){
		alert("Dato obligatorio: Provincia");
		f.provincia.focus();
		f.edad.value = 0;
		return false;
		} 
return (true); 
}


var numeros="0123456789";
var letras="abcdefghyjklmnñopqrstuvwxyz";
var letras_mayusculas="ABCDEFGHYJKLMNÑOPQRSTUVWXYZ";

function tiene_numeros(texto){
   for(i=0; i<texto.length; i++){
      if (numeros.indexOf(texto.charAt(i),0)!=-1){
         return 1;
      }
   }
   return 0;
} 

function tiene_letras(texto){
   texto = texto.toLowerCase();
   for(i=0; i<texto.length; i++){
      if (letras.indexOf(texto.charAt(i),0)!=-1){
         return 1;
      }
   }
   return 0;
} 

function tiene_minusculas(texto){
   for(i=0; i<texto.length; i++){
      if (letras.indexOf(texto.charAt(i),0)!=-1){
         return 1;
      }
   }
   return 0;
} 

function tiene_mayusculas(texto){
   for(i=0; i<texto.length; i++){
      if (letras_mayusculas.indexOf(texto.charAt(i),0)!=-1){
         return 1;
      }
   }
   return 0;
} 

function seguridad_clave(clave){
	var seguridad = 0;
	if (clave.length!=0){
		if (tiene_numeros(clave) && tiene_letras(clave)){
			seguridad += 30;
		}
		if (tiene_minusculas(clave) && tiene_mayusculas(clave)){
			seguridad += 30;
		}
		if (clave.length >= 4 && clave.length <= 5){
			seguridad += 10;
		}else{
			if (clave.length >= 6 && clave.length <= 8){
				seguridad += 30;
			}else{
				if (clave.length > 8){
					seguridad += 40;
				}
			}
		}
	}
	return seguridad				
}	

function muestra_seguridad_clave(clave,formulario){
	seguridad=seguridad_clave(clave);
	formulario.seguridad.value=seguridad + "%";
}

function check_name(f) {
		if( f.value.search('^[a-z A-Z áéíóúÁÉÍÓÚÑñ]+$') == -1 ) {
		alert("Dato obligatorio: Solo admite letras y espacios");
		f.value = '';
		return false;
		}
}
function check_correo(f) {
	if( f.value.toLowerCase().search('(^[a-z][a-z0-9\-_.]+[@][a-z0-9\-_.]+[.][a-z]+$)') == -1 ) {
	alert("Dato obligatorio: Formato de correo electronico incorrecto");
	f.value = '';
	return false;
	}
}

function check_entero2(f) {
	if( f.value.search('[^0-9]') != -1 || f.value == "" ) {
	f.value = '';
	return false;
	}
}

function check_entero(f) {
	if( f.value.search('[^0-9]') != -1 || f.value == "" ) {
	alert("Dato obligatorio: Solo admite numeros");
	f.value = '';
	return false;
	}
}

function calcular_beneficio(f) {
	f.total.value = (f.uni.value * (f.subtotal.value * (f.margen.value / 100)));
	f.uniC.value = (f.uni.value);
	f.totalC.value = (f.uni.value * (f.subtotalC.value * (f.margenC.value / 100)));
	var total = document.TOTAL.totalV.value / 1;
	var subtotal = f.total.value / 1;
	var tot = total + subtotal;
	var totalC = document.TOTAL.totalC.value / 1;
	var subtotalC = f.totalC.value / 1;
	var totC = totalC + subtotalC;
	document.TOTAL.totalV.value = eval("tot");
	document.TOTAL.totalC.value = eval("totC");
	return false;
}

function calcular_beneficio2(f) {
	f.total.value = (f.uni.value * (f.subtotal.value * (f.margen.value / 100)));
	f.uniC.value = (f.uni.value);
	f.totalC.value = (f.uni.value * (f.subtotalC.value * (f.margenC.value / 100)));
	var total = document.TOTAL.totalV.value / 1;
	var subtotal = f.total.value / 1;
	var tot = total + subtotal;
	var totalC = document.TOTAL.totalC.value / 1;
	var subtotalC = f.totalC.value / 1;
	var totC = totalC + subtotalC;
	document.TOTAL.totalV.value = eval("tot");
	document.TOTAL.totalC.value = eval("totC");
	return false;
}

