// JavaScript Document
	
	function escribir(text,donde){
		var caz;
		caz = document.getElementById(donde);
		caz.innerHTML = text;
		}
	
	function showme(quien,que){
		target = document.getElementById(quien);
		if(que==1) { si = "";}
		else si = "none";
		target.style.display = si;
		}
		
	function numeros(valor){
		var numerics =  /^[0-9]+$/;
		if(valor.value.match(numerics) && valor.value.length > 0) {
			return true;
			}
		else {alert("El campo acepta sólo  números");
		
		valor.value = "";
		valor.target[fields].style.background = '#CCCCCC';
				target[fields].style.color      = '#000';
		target = getElementById("agregarus");
		target.precio.focus();
		}
		
	}
	function fecha_valuer(form,valor){
		var validador = new Array();
		target = document.all(form);
		validador = target[valor].value.split("-");
		alert("fecha no valida");
		d = validador[0].length;
		m = validador[1].length;
		a = validador[2].length;
		
		
	}

function validarform(form,campo,valor,quevalido,noacepto){
	// ------------[CATALOGO DECLAVES PARA VALIDAR]-----------
	//   1: validar si es vacio o no
	//   2: validar que sea solo numeros
	//	 3: validar que sea solo letras
	//   4: validar que ..
	// BEGIN
	target = document.all(form);
	//document.getElementById(lugar);
	var mesagge;
	switch(quevalido){
		case 1:
		mesagge = "";
		campos = new Array();
		campos = campo.split(",");
		
		for(i=0;i<campos.length;i++){
			fields = campos[i];
			if(target[fields].value.length<=0) {
				mesagge += "para generar una búsqueda es necesario el campo "+fields+"\n";
				target[fields].style.background = 'red';
				target[fields].style.color = '#FFFFFF';
				if(fields=="gira"){
					document.getElementById("contenedor_giros").style.background = 'red';
					document.getElementById("contenedor_giros").style.color = '#FFFFFF';
				}
			}
			else{
				//target[fields].style.background = '#666';
				//target[fields].style.color      = '#FFF';
				//document.getElementById("contenedor_giros").style.background = '#fff';
				//	document.getElementById("contenedor_giros").style.color = '#000';
				
				}
		}
		
		//mesagge = mail("email");
		
		
		if (mesagge.length > 2)  
				alert("Los campos marcados en rojo son necesarios");
		else {
			  	target.submit();
		}
		break;
		
	case 2:
		sectorus = document.form1.sectorus.value;
		estado   =  document.form1.estado.value;
		ciudad 	 = document.form1.ciudad.value;
		nempresa = document.form1.nempresa.value;
		if (sectorus.length > 0 || estado!=0 || ciudad !=0 || nempresa) document.form1.submit();
		else alert("Debe seleccionar por lo menos una opción para obtener un resultado de búsqueda avanzada");
	break;
		}
		
}

function checar(form,campos){
		target = document.getElementById(form);
		for(a=0;a<target[campos].length;a++){
			target[campos][a].click();
			}
	}
	function cambiotexto(stat){
		if(stat==false) tet = "Seleccionar";
		else 			tet = "Quitar";
		escribir(tet,"que");
		}

		function mail(form,campo,valor){
			partes = new Array();
			dominio = new Array();
			partes = valor.split("@");
			dominio = valor.split(".");
			if(partes.length > 1) {
				if (dominio.length > 1) {
					mesagge = null;
					}
				else 	{
					mesagge = "asdasd";
					alert("Ingrese un nombre de dominio valido");
					//document.agregarus.email.focus();
					document.getElementById(campo).focus();
					document.getElementById(campo).value="";
				}
				
			}
			else{
				mesagge = "asdasd";
				alert("Ingrese un mail valido porfavor");
				document.getElementById(campo).focus();
					document.getElementById(campo).value="";
			}
			return mesagge;
			}
			
			
			
			function fecha_valida(valor){
				var formato_fecha = /^([012][1-9]|3[01])(-|-)(0[1-9]|1[012])\2(\d{4})$/;
				if(valor.value.match(formato_fecha) && valor.value.length > 0) {
			return true;
			}
		else {alert("La fecha no es valida");
		
		valor.value = "";
		valor.style.background = 'red';
		valor.style.color      = '#fff';
		} 
				}
    function estados(url,lugar) {

      http_request = false;
	  //document.form1.timer.value=0;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // Ver nota sobre esta linea al final
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
				
                    http_request = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Falla :( No es posible crear una instancia XMLHTTP');
			
            return false;
        }
        http_request.onreadystatechange = function(){
			
			
			  if (http_request.readyState == 4) {
            if (http_request.status == 200) {
			   escribirme(lugar,http_request.responseText);
            }
			else {
                alert('Hubo problemas con la petición.');
            }
        }
		
		else{
			escribirme(lugar,"<img src='loading.gif' width='20'>");
			}
			};
        http_request.open('POST', url, true);
        http_request.send(null);

    }

	function escribirme(lugar,valor){
		target = document.getElementById(lugar);
			   target.innerHTML = valor; 
			   //http_request.responseText;
		}
    /*function alertContents() {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
			   escribirme("giros",http_request.responseText);
			   var veredicto = http_request.responseText;
            }
			else {
                alert('Hubo problemas con la petición.');
            }
        }
    }*/

function open_eyes(whos,lim){
		var s = lim;
		if (document.getElementById("contador").value < s){
			document.getElementById("contador").value ++;
			setTimeout("open_eyes('"+whos+"',"+lim+")",5);
			w = 10 * document.getElementById("contador").value;
			h = w/2 ;
			document.getElementById(whos).style.width  = ""+w+"px";
			document.getElementById(whos).style.height = ""+h+"px";
			} 
	}

function close_eyes(whos){
		if (document.getElementById("contador").value > 0){
			document.getElementById("contador").value --;
			setTimeout("close_eyes('"+whos+"')",1);
			w = 10 * document.getElementById("contador").value;
			h = w/2 ;
			document.getElementById(whos).style.width = ""+w+"px";
			document.getElementById(whos).style.height = ""+h+"px";
			} 
	}
function showme(tar,que){
	target = document.getElementById(tar);
	switch(que){
		case 1: 
		target.style.display="";
		break;
		case 0: 
		target.style.display="none";
		break;
		}
	}
