/*
================================================================================================================
Archivo: js.Esav.jdmrs001_a.js
Creado por: ----
Fecha de creacin: --/--/---- (MM/DD/YYYY)
nombre anterior: jdmrs001_a.js


Modificado: C. Tapia Mori
Fecha de modificacin: 03 Oct 2008

Copy Right JDM Centro de Informatica (c) 2008
================================================================================================================
*/
//--Variables Globales
var dath;
var resh;
var datw;
var resw;
var objchk;
var formatDate = 'dd/mm/yyyy';

window.status = '';

function numero(k){return (k>47&&k<58);}

function getVal(dato){
	if (dato){
		if (dato.ID){
			return document.getElementById(dato.ID).value;
		}
	}
}

function validar_Fecha(mes,dia,anno) {
	z_mes = document.getElementById(mes).value;
	z_dia = document.getElementById(dia).value;
	if (z_mes != ""){
		if (z_mes.length == 1){
			z_mes = '0'+z_mes;
		}
	}
	if (z_dia != ""){
		if (z_dia.length == 1){
			z_dia = '0'+z_dia;
			document.getElementById(dia).value=z_dia;
		}
	}		
	z_anno = document.getElementById(anno).value;
	var obj = z_mes + '/' + z_dia + '/' + z_anno
	if (z_mes != "" && z_dia != "" && z_anno != "") {
		
		//var s_Expresion = /^((0[13578]|10|12)([/])(0[1-9]|[12][0-9]|3[01])([/])(\d{4}))|((0[469]|11)([/])([0][1-9]|[12][0-9]|30)([/])(\d{4}))|((02)([/])((0[1-9]|1[0-9]|2[0-9])([/])(\d{4})))$/;
		var s_Expresion = /^((0[13578]|10|12)([/])(0[1-9]|[12][0-9]|3[01])([/])(\d{4}))|((0[469]|11)([/])([0][1-9]|[12][0-9]|30)([/])(\d{4}))|((02)([/])((0[1-9]|1[0-9]|2[0-8])([/])(\d{4})))|((02)([/])(29)([/])([02468][048]00))|((02)([/])(29)([/])([13579][26]00))|((02)([/])(29)([/])([0-9][0-9][0][48]))|((02)([/])(29)([/])([0-9][0-9][2468][048]))|((02)([/])(29)([/])([0-9][0-9][13579][26]))$/;
		if (!obj.match(s_Expresion)) {
			alert("Ingrese una fecha valida (MM/dd/yyyy).");//alert('Invalid Date... Please verify');//
			document.getElementById(dia).value = "";
			document.getElementById(mes).focus();
			return;
		}
	}
}

function Validafecha(e,dia,mes,ano,obj){
	try{
	dias = getVal({'ID':dia});
	mes  = getVal({'ID':mes});
	ano  = getVal({'ID':ano});
	
	fecha=mes+"/"+dias+"/"+ano

	if (dias==""){}
	else{
		var hoy = new Date();
		hoy = new Date(hoy.getMonth()+1+"/"+hoy.getDate()+"/"+hoy.getFullYear());
		fecing = new Date(ano, mes-1, dias)
		if(hoy>fecing){
			obj.value = "";
			obj.focus();
			return;
		}
		else{
			if(!e) e = window.event;
			var key = !document.all ? e.which : e.keyCode;
			if (key==13 || key==0){
				if (EfficaxMSI_ValidarFechaValida(fecha)==0){
							alert("Ingrese una fecha valida.");//alert('Invalid Date... Please verify');
							document.getElementById(dia).value="";
							document.getElementById(dia).focus();
							return(false);
				}
			}
		}
	}
	}catch(e){alert(e.message)}
}

function buscaruta(num){
	w = 480;
	h = 282;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition  = (screen.height) ? (screen.height-h)/2 : 0;	
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',status=yes,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes'
	obj_tipo=document.getElementById(tipo);
	if(obj_tipo[0].checked=="true") tipo="OW";
	else tipo="RT";
	ruta=document.getElementById("rd0074a"+num).value
	if(tipo=="MC" && num>0){
		if(document.getElementById("rd0074a"+(num-1)).value=="" || document.getElementById("rh0074a"+(num-1)).value==""){
//			alert("Ingrese la Ruta Anterior")
		}
		else{
			url="jdmrs004.asp?num="+num+"&tipo="+tipo+"&ruta="+ruta
			window.open(url,"rutas",settings); 
		}
	}
	else{
		url="jdmrs004.asp?num="+num+"&tipo="+tipo
		window.open(url,"rutas",settings); 
	}
} 


function visualizar(obj){
	objchk = obj.value;
	if(obj.value=="OW")
		document.getElementById('fila_return').style.visibility = "hidden";
	else 
		document.getElementById('fila_return').style.visibility = "visible";
}

function dupli(num){
	nume	 = eval(num);
	obj_tipo = document.getElementById('tipo');
	if(obj_tipo[0].checked=="true") tipo="OW";
	else tipo="RT";	
	if(tipo=="RT"){
		document.getElementById("rd0074a"+(nume+1)).value=document.getElementById("rh0074a"+num).value
		document.getElementById("rh0074a"+(nume+1)).value=document.getElementById("rd0074a"+num).value
	}
	if(tipo=="MC" && num<3){
		document.getElementById("rd0074a"+(nume+1)).value=document.getElementById("rh0074a"+num).value
	}
}

function  habcombo(){
	if (document.mante.desesp.value=='') document.mante.pordes.disabled=true;
	else document.mante.pordes.disabled=false;
}

function calen(caja){
	settings ='height=193,width=208,top=120,left=320,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=no'
	rd0074a=document.getElementById("rd0074a"+caja).value
	rh0074a=document.getElementById("rh0074a"+caja).value
	if(caja=='0'){
		mes=document.mante.mes.value
		ano=document.mante.ano.value 
	}
	else{
		mes=document.getElementById("mes"+caja).value
		ano=document.getElementById("ano"+caja).value
	}
	url="jdmrs017.asp?mes="+mes+"&ano="+ano+"&rd0074a="+rd0074a+"&rh0074a="+rh0074a+"&caja="+caja
	if(rd0074a!='' && rh0074a!='') window.open(url,"rutas",settings);
	else alert('You must complete From and To fields')
}
// Por DRQ
//COMBOS DE LAS RUTAS
//	obj_top = obj_input.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
//	obj_top = obj_input.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
//	obj_top = obj_input.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
//	obj_top = obj_input.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop;
//variable capa ruta donde se guarda nombre de objeto para despues llamar y cerrar su DIV
var caparuta="";
var flagdiv="";

function show_div(obj_input,sw_on,sw_y){
	obj_top = obj_input.offsetParent.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop+obj_input.offsetParent.offsetParent.offsetParent.offsetParent.offsetTop+obj_input.offsetParent.offsetParent.offsetParent.offsetTop+obj_input.offsetParent.offsetParent.offsetTop+obj_input.offsetParent.offsetTop+obj_input.offsetTop+obj_input.offsetHeight+1;
	if(sw_y=="d") obj_left = obj_input.offsetLeft+1;
	else obj_left = obj_input.offsetLeft+25;
	obj = eval("document.getElementById('"+obj_input.name.substr(0,7)+"_div')");
	if(obj.style.display=="none" && sw_on==1){
		obj.style.display = "inline";
		caparuta = obj_input.name;
	}
	else{
		obj.style.display = "none";
		caparuta = "";
	}
	obj.style.top = obj_top;
	obj.style.left = obj_left;

	// Para esconder los combos de numero de personas
	caja_adulto = document.getElementById('nadult');
	caja_nino = document.getElementById('nchild');
	caja_infante = document.getElementById('ninfant');
	if(objchk=="RT" && (obj_input.name=="rd0074a0" || obj_input.name=="rh0074a0")){
		if(obj.style.display=="none"){
			caja_adulto.style.visibility="visible";
			caja_nino.style.visibility="visible";
			caja_infante.style.visibility="visible";
		}	
	}
	else{
		if(obj.style.display=="inline"){
			caja_adulto.style.visibility="hidden";
			caja_nino.style.visibility="hidden";
			caja_infante.style.visibility="hidden";
		}
		else{
			caja_adulto.style.visibility="visible";
			caja_nino.style.visibility="visible";
			caja_infante.style.visibility="visible";
		}
	}
}

function cierra_div(input,y){
	if(input.name!=caparuta && caparuta!=""){
		caja = document.getElementById(caparuta);
		if(caja){show_div(caja,0);}
	}
	show_div(input,1,y);
}

function envia_codigo(objfila){
//	valor = objfila.innerText;
//	arreglo = valor.split(" - ");
	objcaja = document.getElementById(caparuta);
	if(cancela_timer()){
//		objcaja.value = arreglo[0];
		objcaja.value = objfila.valor;		
		regresa_foco();
		show_div(objcaja,1);
	}
}

function regresa_foco(){
	flagdiv = "SS";
	if(caparuta!=""){
		caja = document.getElementById(caparuta);
		caja.focus();
	}
	cancela_timer();
}

function cancela_timer(){
	clearTimeout(counter);
	countDownTime=countDownInterval+1;
	return true
}

function cierra(nomcaja){
	objcaja = eval("document.getElementById('"+nomcaja.substr(0,7)+"_div')");
	if(caparuta!="" && caparuta==nomcaja && objcaja.style.display=="inline"){
		caja = document.getElementById(caparuta);
		if(caja){show_div(caja,0);}
	}
}

var conteoInterval=7;
var conteoTime=conteoInterval+1;
var contador=0;
var idioma="ES";
function conteo(){
	conteoTime--;
	if (conteoTime<=0){
		conteoTime=conteoInterval;
		clearTimeout(contador);
		conteoTime=conteoInterval+1;
		chg_aviso(idioma);
//		top.window.status = 0;
		return;
	}
//	top.window.status = conteoTime;
	contador=setTimeout("conteo()", 1000);
}

var countDownInterval=1;
var countDownTime=countDownInterval+1;
var counter=0;
function countDown(nomtext){
	countDownTime--;
	if (countDownTime <=0){
		countDownTime=countDownInterval;
//		top.window.status = 0;
		clearTimeout(counter);
		countDownTime=countDownInterval+1;
		cierra(nomtext);
		return;
	}
//	top.window.status = countDownTime;
	counter=setTimeout("countDown('"+nomtext+"')", 1000);
}
function startit(objtext){
	countDown(objtext.name);
}
//FIN COMBO DE LAS RUTAS
function chg_aviso(lang){
	obj_visa = document.getElementById('txt_visa');
	obj_mast = document.getElementById('txt_mast');
	obj_veri = document.getElementById('txt_veri');
	if(lang=="ES"){
		obj_visa.innerHTML = "Esta tienda est&aacute; autorizada  para realizar las siguientes transacciones electr&oacute;nicas :"
		//obj_mast.innerHTML = "Autorizado para<br> ventas con Mastercard"
		obj_veri.innerHTML = "Su información esta protegida pues este sitio cuenta con un Certificado SSL de VeriSign"
		idioma = "EN";
	}
	else{
		obj_visa.innerHTML = "Authorized to process electronic transactions with :"
		//obj_visa.innerHTML = "Authorized by Visa to process<br>Verified by Visa transactions"
		//obj_mast.innerHTML = "Authorized to process<br>Mastercard transactions"
		obj_veri.innerHTML = "This Web site can secure your private information using a VeriSign SSL Certificate"
		idioma = "ES";
	}
	conteo();
}
// Fin Por DRQ
