function gid(element){
	return document.getElementById(element);
}


function Ajax(){
	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 cargar_muni(prov){
	ajax=Ajax();
	ajax.open("GET", "cont_muni.php?prov="+prov,true);
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange=function(){	
		if (ajax.readyState==1){
			gid('etiqueta_carga_muni').style.display='inline';
		}
		if (ajax.readyState==4){
			gid('etiqueta_carga_muni').style.display='none';
			gid('cont_muni').innerHTML=""+ ajax.responseText + "";
			ajax2=Ajax();
    	ajax2.open("GET", "cont_cp.php?muni=",true);
    	
    	ajax2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	ajax2.onreadystatechange=function(){	
    		if (ajax2.readyState==1){
				gid('etiqueta_carga_cp').style.display='inline';
			}
			if (ajax2.readyState==4){
				gid('etiqueta_carga_cp').style.display='none';
    			gid('cont_cp').innerHTML=""+ ajax2.responseText + "";
    		}
    	}	
    	ajax2.setRequestHeader("Content-Type","text/xml;charset=iso-8859-1");
    	ajax2.send('D');
		}
	}	
	ajax.setRequestHeader("Content-Type","text/xml;charset=iso-8859-1");
	ajax.send('D');
}

function cargar_cp(muni){
	ajax=Ajax();
	ajax.open("GET", "cont_cp.php?muni="+muni,true);
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange=function(){	
		if (ajax.readyState==1){
			gid('etiqueta_carga_cp').style.display='inline';
		}
		if (ajax.readyState==4){
			gid('etiqueta_carga_cp').style.display='none';
			gid('cont_cp').innerHTML=""+ ajax.responseText + "";
		}
	}	
	ajax.setRequestHeader("Content-Type","text/xml;charset=iso-8859-1");
	ajax.send('D');
}

function cargar_muni2(prov){
	ajax=Ajax();
	ajax.open("GET", "cont_muni2.php?prov="+prov,true);
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange=function(){	
		if (ajax.readyState==1){
			gid('etiqueta_carga').style.display='inline';
		}
		if (ajax.readyState==4){
			gid('etiqueta_carga').style.display='none';
			gid('cont_muni').innerHTML=""+ ajax.responseText + "";
			document.form_pedido.municipio_envio.style.background = "#ffffff";
		  document.form_pedido.municipio_envio.style.color = "#1c1c1c";
			ajax2=Ajax();
    	ajax2.open("GET", "cont_cp2.php?muni=",true);
    	
    	ajax2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	ajax2.onreadystatechange=function(){	
    		if (ajax2.readyState==1){
				gid('etiqueta_carga').style.display='inline';
			}
			if (ajax2.readyState==4){
				gid('etiqueta_carga').style.display='none';
    			gid('cont_cp').innerHTML=""+ ajax2.responseText + "";
    			document.form_pedido.cp_envio.style.background = "#ffffff";
		      document.form_pedido.cp_envio.style.color = "#1c1c1c";
    		}
    	}	
    	ajax2.setRequestHeader("Content-Type","text/xml;charset=iso-8859-1");
    	ajax2.send('D');
		}
	}	
	ajax.setRequestHeader("Content-Type","text/xml;charset=iso-8859-1");
	ajax.send('D');
}

function cargar_cp2(muni){
	ajax=Ajax();
	ajax.open("GET", "cont_cp2.php?muni="+muni,true);
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange=function(){	
		if (ajax.readyState==1){
			gid('etiqueta_carga').style.display='inline';
		}
		if (ajax.readyState==4){
			gid('etiqueta_carga').style.display='none';
			gid('cont_cp').innerHTML=""+ ajax.responseText + "";
			document.form_pedido.cp_envio.style.background = "#ffffff";
		  document.form_pedido.cp_envio.style.color = "#1c1c1c";
		}
	}	
	ajax.setRequestHeader("Content-Type","text/xml;charset=iso-8859-1");
	ajax.send('D');
}

function guardar_pedido(){
	ajax=Ajax();
	ajax.open("GET", "guardar_pedido.php",true);
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange=function(){	
		if (ajax.readyState==4){
			document.form_pedido.submit();
		}
	}	
	ajax.setRequestHeader("Content-Type","text/xml;charset=iso-8859-1");
	ajax.send('D');
}

function validar_login3(login) {
	ajax=Ajax();
	ajax.open("GET", "validar_login.php?login="+login,true);
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange=function(){	
		if (ajax.readyState==1){
			//gid('etiqueta_carga_cp').style.display='inline';
		}
		if (ajax.readyState==4){
			if(ajax.responseText!="") {
				gid('log_msg').style.display='inline';
				gid('log_msg').innerHTML=""+ ajax.responseText + "";
			} else {
				gid('log_msg').style.display='none';
			}
		}
	}	
	ajax.setRequestHeader("Content-Type","text/xml;charset=iso-8859-1");
	ajax.send('D');
}
