function pulsar(e,obj) {
tecla=(document.all) ? e.keyCode : e.which;
if(tecla==13) obj.onclick();
}

function abrirVentana(URL) {
	catWindow = window.open(URL,'catWin', 'width=690, height=400, toolbar=yes, location=yes, scrollbars=yes, resizable=yes');
}

function NuevoAjax(){
	var xmlhttp=false;
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		}catch(E){
			xmlhttp = false;
		}
	}
	if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function carga_contenido( destino , pagina ){
//alert(pagina);
var contenido;
var ajax;
contenido = document.getElementById(destino);
	ajax = NuevoAjax();
	ajax.open("GET", pagina, true);
	ajax.onreadystatechange=function(){
		if(ajax.readyState==1){
			//preloader.innerHTML = "Cargando...";
			//preloader.style.background = "url('loading.gif') no-repeat";
			contenido.innerHTML = "Cargando...";
		}else if(ajax.readyState==4){
			if(ajax.status==200){
				contenido.innerHTML = ajax.responseText;
				//preloader.innerHTML = "Cargado.";
				//preloader.style.background = "url('loaded.gif') no-repeat";
			}else if(ajax.status==404){
				//preloader.innerHTML = "La p&aacute;gina no existe";
				contenido.innerHTML = "La p&aacute;gina " + pagina + " no existe";
			}else{
				contenido.innerHTML  = "Error:" + ajax.status;
			}
		}
	}
	ajax.send(null);
}

function revisar_datos(){
	nombre = document.forms['bridge'].elements['nombre'];
	calle = document.forms['bridge'].elements['calle'];
	colonia = document.forms['bridge'].elements['colonia'];
	cp = document.forms['bridge'].elements['cp'];
	
	//nombre = document.getElementById('nombre');
	//calle = document.getElementById('calle');
	//colonia = document.getElementById('colonia');
	//cp = document.getElementById('cp');
	
	msg = "";
	if (nombre.value.length < 4){
		document.getElementById('bad_nombre').innerHTML = "<font color=red><b>*</b></font>";
		msg = msg + " Falta el nombre.";
	} else {
		document.getElementById('bad_nombre').innerHTML = "";
	}
	if (calle.value.length < 4){
		document.getElementById('bad_calle').innerHTML = "<font color=red><b>*</b></font>";
		msg = msg + " Falta la calle.";
	} else {
		document.getElementById('bad_calle').innerHTML = "";
	}
	if (colonia.value.length < 4){
		document.getElementById('bad_colonia').innerHTML = "<font color=red><b>*</b></font>";
		msg = msg + " Falta la colonia.";
	} else {
		document.getElementById('bad_colonia').innerHTML = "";
	}
	if (cp.value.length < 5){
		document.getElementById('bad_cp').innerHTML = "<font color=red><b>*</b></font>";
		msg = msg + " Falta el CP.";
	} else {
		document.getElementById('bad_cp').innerHTML = "";
	}

	if (nombre.value.length > 3 &&
		calle.value.length > 3 &&
		colonia.value.length > 3 &&
		cp.value.length > 4
		&& cp.value != "00000" && nombre.value !="" 
		&& calle.value!= "" && colonia.value != ""){
			document.getElementById('mensaje').innerHTML = "Los datos est\u00e1n completos";			
			document.getElementById('submit1').disabled = false;
			resultado = true;
	} else {
		msgA = "<font color=red><b>" ;
		msgA = msgA + "Los datos marcados con asterisco son obligatorios, favor de intentar nuevamente<br/>" ;
		msgA = msgA + "Falta alguno de los datos indispensables y esta marcado con (*)<br/>" ;
		msgA = msgA + "(" + msg + ")";
		msgA = msgA + "</b></font>" ;		
		document.getElementById('mensaje').innerHTML = msgA;	
		document.getElementById('submit1').disabled = true;		
		resultado=false;
	}
	return(resultado);
}

function passw_comer(forma){
	//verificar_password_comercial(trim(forma.usuario.value),trim(forma.password.value),forma);
	if (forma.usuario.value.length > 0) {	
		if (forma.password.value.length > 0) {
			es_valido_usuario_comercial(trim(forma.usuario.value),trim(forma.password.value),forma);
			forma.intentos_comercial.value = parseInt(forma.intentos_comercial.value) + 1;
			if (forma.intentos_comercial.value == "15"){
				alert("El usuario y password son incorrectos, favor de verificar la informacion proporcionada.");
				document.getElementById('submit1').disabled = true;
				document.getElementById('mensaje_password').innerHTML = "El usuario y password son incorrectos, favor de verificar la informacion proporcionada.";	
				history.go(0);
			}
		} else {
			document.getElementById('mensaje_password').innerHTML = "";
		}
	} else {
		document.getElementById('mensaje_password').innerHTML = "El usuario es un campo indispensable, favor de verificar la informacion proporcionada..";		
	}
}

function es_valido_usuario_comercial(usuario,password,forma){
	var resultado = "false";
	var	ajax = NuevoAjax();
	//ajax.open("POST","http://10.1.65.30/fut/utilerias/utl_validar_comercial.php",true);
	ajax.open("POST","http://10.1.65.9/fut/utilerias/utl_validar_comercial.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			resultado = ajax.responseText ;				
			if(resultado=="true") {
				document.getElementById('submit1').disabled = false;
				document.getElementById('mensaje_password').innerHTML = "Contrase&ntilde;a correcta";					
			} else {
				document.getElementById('submit1').disabled = true;	
				document.getElementById('mensaje_password').innerHTML = "<font color=red><b>Contrase&ntilde;a incorrecta</b></font>";				
			}
			
		}
	}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");	
	ajax.send("user="+usuario+"&passw="+password);
}