function validar_formulario(type)
{
	switch(type)
	{
		case "access_read":
			var MATRICULA=document.getElementById("MATRICULA").value; 
			if(!MATRICULA) { alert("Escribe o ingresa tu matrícula!"); document.getElementById('MATRICULA').focus(); return false; }
			document.getElementById("validar").value='Verificando...'; document.getElementById("validar").disabled=true; 
			hideddrivetip(); load_options('access_read');
			return false;
		break;
	}
}

function load_options(tipo)
{
	var archivo_ajax="TE_ajax_generico.php?tipo="+tipo;
	switch (tipo)
	{
		case "access_read": var valor=document.getElementById("MATRICULA").value; var punto=document.getElementById("punto").value; break;
	}
	if(valor) 
	{
		var ajax=funcionnuevoAjax();
		ajax.open("POST", archivo_ajax, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		switch (tipo)
		{
			case "access_read": ajax.send("MATRICULA="+valor+"&punto="+punto); break;
		}
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1)
			{
				switch (tipo)
				{
					case "access_read": document.getElementById("validar").value='Verificando...'; document.getElementById("validar").disabled=true; break; 
				}
			}
			if (ajax.readyState==4)
			{
				//alert(ajax.responseText);
				if(!ajax.responseText) { }
				else 
				{
					switch (tipo)
					{
						case "access_read":
							var respuesta=new Array(2); respuesta=ajax.responseText.split("*&*"); 
							document.getElementById("ROW_DETAILS").innerHTML=respuesta[1]; 
							document.getElementById("validar").value='Validar'; document.getElementById("validar").disabled=false;
							if((respuesta[2]) && (respuesta[2]=="error")) { document.all.sound.src = "../sounds/error.wav"; }
							document.getElementById("MATRICULA").value=''; document.getElementById("MATRICULA").focus();
						break;
					}
				}
			}
		}
	}
}

function valida_tipo_de_reporte(tipo, forma)
{
	if(!forma) { var forma = "reportes"; }
	if(tipo==1) { document.getElementById(forma).target="_self"; 	document.getElementById("mode").value="normal"; }
	if(tipo==2) { document.getElementById(forma).target="_blank"; 	document.getElementById("mode").value="toprint"; }
	if(tipo==3) { document.getElementById(forma).target="_blank"; 	document.getElementById("mode").value="toExcel"; }
	document.getElementById(forma).submit();
}

function carga_datos(tipo)
{
	var archivo_ajax="../config/ajax/ajax_generico.php?tipo="+tipo;
	switch (tipo)
	{
		case "ESTADOS" 	: var valor=document.getElementById("PAIS_ID").value; 					break;
		case "CIUDADES"	: var valor=document.getElementById("ESTADO_ID").value; 				break;
		case "SUBZONAS_EMBARQUES": var valor=document.getElementById("ZONA_EMBARQUE_ID").value; break;
		case "SUBZONAS": var valor=document.getElementById("ZONA_ID").value; 					break;
		case "CANCELA_CHEQUERA" : if (!confirm('Realmente desea cancelar esta chequera??? ')) { return false; } var valor=document.getElementById("CHEQUERA_ID").value; break;
		case "clientes_d_remisionesXfacturar" : var valor=document.getElementById("CLAVE_ID").value; break;
		case "clientes_d_remisionesXfacturarXnombre": var valor=document.getElementById("DESCRIPCION_CLIENTE").value; if (valor.length<=3) { return false; } break;
		case "CATEGORIAS" 	: var valor=document.getElementById("CLASE_ID").value; 				break;
		case "SUBCATEGORIAS": var valor=document.getElementById("CATEGORIA_ID").value; 			break;
		case "ZONAS_ALMACEN": var valor=document.getElementById("ALMACEN_ID").value; 			break;
		case "UBICACIONES"	: var valor=document.getElementById("ZONA_ALM_ID").value; 			break;
		case "options_search":var valor=document.getElementById("categorie").value; 			break;
		case "socio_estado" : var valor=document.getElementById("pais").value; 					break;
	}
	if ((valor=="") || (valor==" ")) { }
	else
	{
		var ajax=funcionnuevoAjax();
		ajax.open("POST", archivo_ajax, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		switch (tipo)
		{
			case "ESTADOS" 	: ajax.send("PAIS_ID="+valor);						break;
			case "CIUDADES" : ajax.send("ESTADO_ID="+valor);					break;
			case "SUBZONAS_EMBARQUES" : ajax.send("ZONA_EMBARQUE_ID="+valor); 	break;
			case "SUBZONAS" : ajax.send("ZONA_ID="+valor); 						break;
			case "CANCELA_CHEQUERA" : ajax.send("CHEQUERA_ID="+valor);			break;
			case "clientes_d_remisionesXfacturar" : ajax.send("CLAVE_ID="+valor);break;
			case "clientes_d_remisionesXfacturarXnombre" : ajax.send("RAZON_SOCIAL="+valor); break;
			case "CATEGORIAS" 	: ajax.send("CLASE_ID="+valor);					break;
			case "SUBCATEGORIAS" 	: ajax.send("CATEGORIA_ID="+valor);			break;
			case "ZONAS_ALMACEN" 	: ajax.send("ALMACEN_ID="+valor);			break;
			case "UBICACIONES" 		: ajax.send("ZONA_ALM_ID="+valor);			break;
			case "options_search" 	: ajax.send("categorie="+valor); 			break;
			case "socio_estado" 	: ajax.send("pais="+valor);		 			break;
		}
		ajax.onreadystatechange=function()
		{
			if (ajax.readyState==1)
			{
				switch (tipo)
				{
					case "ESTADOS" :
						document.getElementById("FILA_ESTADO").innerHTML="<img src='../images/cargando.gif' border='0' width='160'>";
						document.getElementById("FILA_CIUDAD").innerHTML="<img src='../images/cargando.gif' border='0' width='160'>";
					break;
					case "CIUDADES" :
							document.getElementById("FILA_CIUDAD").innerHTML="<img src='../images/cargando.gif' border='0'>";
					break;
					case "SUBZONAS_EMBARQUES" :
							document.getElementById("FILA_SUBZONA_EMBARQUE").innerHTML="<img src='../images/cargando.gif' border='0'>";
					break;
					case "SUBZONAS" :
							document.getElementById("FILA_SUBZONA").innerHTML="<img src='../images/cargando.gif' border='0'>";
					break;
					case "SUBZONAS" :
							document.getElementById("FILA_ESTATUS").innerHTML="<img src='../images/cargando.gif' border='0'>";
					break;
					case "CATEGORIAS" :
						document.getElementById("FILA_CATEGORIA").innerHTML="<img src='../images/cargando.gif' border='0' width='135'>";
						document.getElementById("FILA_SUBCATEGORIA").innerHTML="<img src='../images/cargando.gif' border='0' width='87'>";
					break;
					case "SUBCATEGORIAS" :
							document.getElementById("FILA_SUBCATEGORIA").innerHTML="<img src='../images/cargando.gif' border='0' width='87'>";
					break;
					case "ZONAS_ALMACEN" :
						document.getElementById("FILA_ZONA_ALM").innerHTML="<img src='../images/cargando.gif' border='0' width='183'>";
						document.getElementById("FILA_UBICACION").innerHTML="<img src='../images/cargando.gif' border='0' width='183'>";
					break;
					case "UBICACIONES" :
							document.getElementById("FILA_UBICACION").innerHTML="<img src='../images/cargando.gif' border='0' width='183'>";
					break;
					case "options_search" 	: document.getElementById("FILA_INPUT_MARCA").innerHTML="Loading..."; break;
					case "socio_estado" 	: document.getElementById("FILA_INPUT_MODELO").innerHTML="Loading..."; break;
				}
			}
			if (ajax.readyState==4)
			{
				//alert(ajax.responseText);
				if(!ajax.responseText) { }
				else 
				{
					switch (tipo)
					{
						case "ESTADOS":	var respuesta=new Array(2); respuesta=ajax.responseText.split("*&*"); document.getElementById("FILA_ESTADO").innerHTML=respuesta[1]; document.getElementById("FILA_CIUDAD").innerHTML=respuesta[2]; break; 
						case "CIUDADES": document.getElementById("FILA_CIUDAD").innerHTML=ajax.responseText; break;
						case "SUBZONAS_EMBARQUES": document.getElementById("FILA_SUBZONA_EMBARQUE").innerHTML=ajax.responseText; break;
						case "SUBZONAS": document.getElementById("FILA_SUBZONA").innerHTML=ajax.responseText; break;
						case "CANCELA_CHEQUERA": document.getElementById("FILA_ESTATUS").innerHTML=ajax.responseText; break;
						case "clientes_d_remisionesXfacturar": 
								var respuesta=new Array(2);
								respuesta=ajax.responseText.split("*&*");
								switch(respuesta[1])
								{
									case "vacio":
										alert('El cliente no existe o no tiene remisiones sin facturar...'); 
										document.getElementById("CLAVE_ID").value=""; 
										document.getElementById("CLIENTE_ID").value=""; 
										document.getElementById("DESCRIPCION_CLIENTE").value=""; 
									break;
									default: 
										document.getElementById("CLAVE_ID").value=respuesta[1];
										document.getElementById("CLIENTE_ID").value=respuesta[2];
										document.getElementById("DESCRIPCION_CLIENTE").value=respuesta[3];
										document.getElementById("FILA_SELECCIONA_REMISION").innerHTML=respuesta[4];
									break;									
								}
						break;
						case "clientes_d_remisionesXfacturarXnombre": 
								var respuesta=new Array(2);
								respuesta=ajax.responseText.split("*&*");
								switch(respuesta[1])
								{
									case "vacio":
										alert('El cliente no existe o no tiene remisiones sin facturar...'); 
										document.getElementById("CLAVE_ID").value=""; 
										document.getElementById("CLIENTE_ID").value=""; 
										document.getElementById("DESCRIPCION_CLIENTE").value=""; 
									break;
									default: 
										document.getElementById("CLAVE_ID").value=respuesta[1];
										document.getElementById("CLIENTE_ID").value=respuesta[2];
										document.getElementById("DESCRIPCION_CLIENTE").value=respuesta[3];
										document.getElementById("FILA_SELECCIONA_REMISION").innerHTML=respuesta[4];
									break;									
								}
						break;
						case "CATEGORIAS":	var respuesta=new Array(2); respuesta=ajax.responseText.split("*&*"); document.getElementById("FILA_CATEGORIA").innerHTML=respuesta[1]; document.getElementById("FILA_SUBCATEGORIA").innerHTML=respuesta[2]; break; 
						case "SUBCATEGORIAS": document.getElementById("FILA_SUBCATEGORIA").innerHTML=ajax.responseText; break;
						case "ZONAS_ALMACEN":	var respuesta=new Array(2); respuesta=ajax.responseText.split("*&*"); document.getElementById("FILA_ZONA_ALM").innerHTML=respuesta[1]; document.getElementById("FILA_UBICACION").innerHTML=respuesta[2]; break; 
						case "UBICACIONES": document.getElementById("FILA_UBICACION").innerHTML=ajax.responseText; break;
						case "options_search": 
								var respuesta=new Array(2);
								respuesta=ajax.responseText.split("*&*");
								switch(respuesta[1])
								{
									case "1":
										document.getElementById("FILA_TXT_MARCA").innerHTML=respuesta[2]; 
										document.getElementById("FILA_INPUT_MARCA").innerHTML=respuesta[3]; 
										document.getElementById("FILA_TXT_MODELO").innerHTML=respuesta[4]; 
										document.getElementById("FILA_INPUT_MODELO").innerHTML=respuesta[5]; 
									break;
									default: 
										document.getElementById("FILA_TXT_MARCA").innerHTML=respuesta[2]; 
										document.getElementById("FILA_INPUT_MARCA").innerHTML=respuesta[3]; 
										document.getElementById("FILA_TXT_MODELO").innerHTML=respuesta[4]; 
										document.getElementById("FILA_INPUT_MODELO").innerHTML=respuesta[5]; 
									break;									
								}
						break;
						case "socio_estado":
							var respuesta=new Array(2);
								respuesta=ajax.responseText.split("*&*");
								switch(respuesta[1])
								{
									default: 
										document.getElementById("FILA_TXT_MARCA").innerHTML=respuesta[1]; 
										document.getElementById("FILA_INPUT_MARCA").innerHTML=respuesta[2]; 
									break;									
								}
						break;

					}
				}
			}
		}
	}
}

function detalles(id,type) { if(type==1) { var select="7"; } if(type==2) { var select="6"; }  if(type==3) { var select="8"; } var pagina="?select="+select+"&id="+id; document.location = pagina; }

function valida_campos(type)
{
	switch(type)
	{
		case "contacto":
			var NOMBRE		=document.getElementById("NOMBRE").value;
			var EMPRESA		=document.getElementById("EMPRESA").value;
			var DOMICILIO	=document.getElementById("DOMICILIO").value;
			var CIUDAD		=document.getElementById("CIUDAD").value;
			var TELEFONO	=document.getElementById("TELEFONO").value;
			var EMAIL		=document.getElementById("EMAIL").value;
			var SITIO		=document.getElementById("SITIO").value;
			var MENSAJE		=document.getElementById("MENSAJE").value;
			if (!NOMBRE) 	{ alert("Nombre incorrecto!"); 							document.getElementById('NOMBRE').focus();		return false; }
			if (!EMPRESA) 	{ alert("Empresa incorrecta!"); 						document.getElementById('EMPRESA').focus();		return false; }
			if (!DOMICILIO)	{ alert("Domicilio incorrecto!");						document.getElementById('DOMICILIO').focus();	return false; }
			if (!CIUDAD)	{ alert("Ciudad incorrecta!");	 						document.getElementById('CIUDAD').focus();		return false; }
			if (!TELEFONO)	{ alert("Telefono incorrecto!"); 						document.getElementById('TELEFONO').focus();	return false; }
			if (!EMAIL) 	{ alert("Esciba una direccion de correo electronico!");	document.getElementById('EMAIL').focus();	 	return false; }
			else { if (validarEmail(EMAIL)==false) { alert("Direccion de correo electronico incorrecta!");	document.getElementById('EMAIL').focus(); return false; } }
			if (!SITIO)		{ alert("Pagina web incorrecta!"); 						document.getElementById('SITIO').focus();	return false; }
			if (!MENSAJE)	{ alert("Mensaje incorrecto!"); 						document.getElementById('MENSAJE').focus();	return false; }
		break;
		case "empresa_email": 
			var DE_EMAIL		=document.getElementById("DE_EMAIL").value;
			var DE_NOMBRE		=document.getElementById("DE_NOMBRE").value;
			var MENSAJE		=document.getElementById("MENSAJE").value;
	
//			if (MENSAJE.search("href")>=0) { alert("Mensaje incorrecto!"); 						document.getElementById('MENSAJE').focus();	return false; } 

			if (!DE_EMAIL) 	{ alert("Esciba una direccion de correo electronico!");	document.getElementById('DE_EMAIL').focus(); 	return false; }
			else { if (validarEmail(DE_EMAIL)==false) { alert("Direccion de correo electronico incorrecta!");	document.getElementById('DE_EMAIL').focus(); return false; } }
			if (!DE_NOMBRE) 	{ alert("Nombre incorrecto!"); 						document.getElementById('DE_NOMBRE').focus();		return false; }
			if (!MENSAJE)	{ alert("Mensaje incorrecto!"); 						document.getElementById('MENSAJE').focus();	return false; }
		break;
		case "empresa_recomienda":
			var DE_NOMBRE		=document.getElementById("DE_NOMBRE").value;
			var DE_EMAIL		=document.getElementById("DE_EMAIL").value;
			var RECEPTOR		=document.getElementById("RECEPTOR").value;
			if (!DE_NOMBRE) 	{ alert("Nombre incorrecto!"); 						document.getElementById('DE_NOMBRE').focus();		return false; }
			if (!DE_EMAIL) 		{ alert("Esciba una direccion de correo electronico!");	document.getElementById('DE_EMAIL').focus(); 	return false; }
			else { if (validarEmail(DE_EMAIL)==false) { alert("Direccion de correo electronico incorrecta!");	document.getElementById('DE_EMAIL').focus(); return false; } }
			if (!RECEPTOR) 		{ alert("Esciba una direccion de correo electronico!");	document.getElementById('RECEPTOR').focus(); 	return false; }
			else
			{
				var LISTA_DE_RECEPTORES=new Array(2);
				LISTA_DE_RECEPTORES=RECEPTOR.split(",");
				for ( i=0; i < LISTA_DE_RECEPTORES.length; i++ )
				{
				
					var DIRECCION = LISTA_DE_RECEPTORES[i].replace(" ","");
					if (validarEmail(DIRECCION)==false) { alert("Error en el CORREO DEL RECEPTOR! \nPara enviar a varias direcciones, separa con coma ( , ) los correos receptores."); document.getElementById('RECEPTOR').focus(); return false; }
				}
			}
		break;
		case "recuerda_pass":
			var EMAIL		=document.getElementById("EMAIL").value;
			if (!EMAIL) 		{ alert("Esciba una direccion de correo electronico!");	document.getElementById('EMAIL').focus(); 	return false; }
			else { if (validarEmail(EMAIL)==false) { alert("Direccion de correo electronico incorrecta!");	document.getElementById('EMAIL').focus(); return false; } }
		break;

	}
}

/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var offsetfromcursorX=10 //Customize x offset of tooltip
var offsetfromcursorY=5 //Customize y offset of tooltip
var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).
document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="../images/arrow2.gif">') //write out pointer image
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""
var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""
function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function ddrivetip(thetext, thewidth, thecolor){
	if (ns6||ie){
		if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
		if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
		tipobj.innerHTML=thetext
		enabletip=true
		return false
	}
}
function positiontip(e){
	if (enabletip){
		var nondefaultpos=false
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
		var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20
		var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
		var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY
		var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth){
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=curX-tipobj.offsetWidth+"px"
			nondefaultpos=true
		}
		else if (curX<leftedge)
			tipobj.style.left="5px"
		else{
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
			pointerobj.style.left=curX+offsetfromcursorX+"px"
		}
		//same concept with the vertical position
		if (bottomedge<tipobj.offsetHeight){
			tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
			nondefaultpos=true
		}
		else{
			tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
			pointerobj.style.top=curY+offsetfromcursorY+"px"
		}
		tipobj.style.visibility="visible"
		if (!nondefaultpos)
		pointerobj.style.visibility="visible"
		else
		pointerobj.style.visibility="hidden"
	}
}
function hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		tipobj.style.visibility="hidden"
		pointerobj.style.visibility="hidden"
		tipobj.style.left="-1000px"
		tipobj.style.backgroundColor=''
		tipobj.style.width=''
	}
}
document.onmousemove=positiontip
