javaBrs = /\n/gi;
function getPageSize(){var xScroll,yScroll;if(window.innerHeight && window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight > document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;};var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth=self.innerWidth;};windowHeight=self.innerHeight;}else if(document.documentElement && document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;};if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;};if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;};arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize;};
function getPageScroll(){var xScroll,yScroll;if (self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset;}else if(document.documentElement && document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft;}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft;};arrayPageScroll=new Array(xScroll,yScroll);return arrayPageScroll;};
function findPosX(obj){var curleft=0;if(obj.offsetParent){while(1){curleft+=obj.offsetLeft;if(!obj.offsetParent){break;};obj=obj.offsetParent;};}else if(obj.x){curleft+=obj.x;};return curleft;};
function findPosY(obj){var curtop = 0;if(obj.offsetParent){while(1){curtop+=obj.offsetTop;if(!obj.offsetParent){break;};obj=obj.offsetParent;};}else if(obj.y){curtop += obj.y;};return curtop;};
function isValidMail(email){var pattern=new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);return pattern.test(email);};
function jsleft(str,n){if(n<=0){return "";}else if(n>String(str).length){return str;}else{return String(str).substring(0,n);};};
function jsright(str,n){if(n<=0){return "";}else if(n>String(str).length){return str;}else{var iLen=String(str).length;return String(str).substring(iLen,iLen-n);};};
function ocultaespera(){if(document.getElementById("wml")){document.getElementById("wml").style.display="block";};if(document.getElementById("mensajeespera")){document.getElementById("mensajeespera").style.display = "none";};};
function muestraespera(){if(document.getElementById("wml")){document.getElementById("wml").style.display="none";};if(document.getElementById("mensajeespera")){document.getElementById("mensajeespera").style.display = "block";};};	
function trimString(str){str = this != window? this : str;return str.replace(/\s+/g,'');};
String.prototype.trim = trimString;
function guardarCambios(obj,objForm){
	objValue = obj.value; objTitle=obj.title;
	var bots = document.getElementsByName(obj.name);
	for(var i=0;i<bots.length;i++){bots[i].value="espere...";bots[i].disabled=true;bots[i].title="Por favor espere un momento mientras se procesa su solicitud...";}
	objForm.submit();
};	
/* Select calendar */
function showDate(controlName,retValue,iniYear,lastYear,className){if(className==null){className="";};if(controlName==null){return;};if(retValue==null){retValue="";};var cDay=getFecha(retValue,"day");var cMonth=getFecha(retValue,"month");var cYear=getFecha(retValue,"year");var dNow=new Date();if((iniYear==null)&&(lastYear==null)){iniYear=dNow.getFullYear();lastYear=iniYear-100;}else if(iniYear==null){iniYear=lastYear-100;}else if(lastYear==null){lastYear=iniYear-100;};var html = "<input type=\"hidden\" id=\""+controlName+"\" name=\""+controlName+"\" value=\""+retValue+"\">";html+="<table border=0 cellpadding=0 cellspacing=0 style=\"border-collapse:collapse;\">";html+="<tr><td>"+showDay(controlName,cDay,null,className)+"</td>";html+="<td>"+showMonth(controlName,cMonth,className)+"</td>";html+="<td>"+showYear(controlName,cYear,iniYear,lastYear,className)+"</td></tr></table>";document.write(html);html=null;};
function showDay(controlName,retValue,maxDays,className){if(className==null){className="";};if(className!=""){className=" class=\""+className+"\" ";};if (maxDays==null){maxDays=32;};var html="<select "+className+" name=\""+controlName+"_day\" id=\""+controlName+"_day\" size=1 onChange=\"controldateUpdate('"+controlName+"');\">";html+="<option value=\"\">--</option>";for (var i=1;i<maxDays;i++){html+="<option ";if(retValue==completa(i,"0",2,"L")){html+="selected ";};html+="value=\""+completa(i,"0",2,"L")+"\">"+completa(i,"0",2,"L")+"</option>";};html+="</selected>";if (!document.getElementById(controlName+"_day_div")){html="<div id=\""+controlName+"_day_div\">"+html+"</div>";return html;};document.getElementById(controlName+"_day_div").innerHTML=html;html=null;};
function showMonth(controlName,retValue,className){var meses=new Array(["01","Enero","31"],["02","Febrero","28"],["03","Marzo","31"],["04","Abril","30"],["05","Mayo","31"],["06","Junio","30"],["07","Julio","31"],["08","Agosto","31"],["09","Septiembre","30"],["10","Octubre","31"],["11","Noviembre","30"],["12","Diciembre","31"]);if(className==null){className="";};if(className!=""){className=" class=\""+className+"\" ";};var html="<select "+className+" name=\""+controlName+"_month\" id=\""+controlName+"_month\" size=1 onchange=\"controldateUpdate('"+controlName+"');updateDays('"+controlName+"',this);\">";html+="<option value=\"\">--</option>";for(var i=0;i<meses.length;i++){html+="<option ";if(retValue==meses[i][0]){html+="selected ";};html+="value=\""+meses[i][0]+"\">"+meses[i][1]+"</option>";};html+="</selected>";if(!document.getElementById(controlName+"_month_div")){html="<div id=\""+controlName+"_month_div\">"+html+"</div>";return html;};document.getElementById(controlName+"_month_div").innerHTML=html;html=null;};
function updateDays(controlName,obj){var meses=new Array(["01","Enero","31"],["02","Febrero","28"],["03","Marzo","31"],["04","Abril","30"],["05","Mayo","31"],["06","Junio","30"],["07","Julio","31"],["08","Agosto","31"],["09","Septiembre","30"],["10","Octubre","31"],["11","Noviembre","30"],["12","Diciembre","31"]);if(obj!=null){var thisClassName=$(obj).attr("class");}else{var thisClassName="";};if(!document.getElementById(controlName+"_day_div")){return;};if(!document.getElementById(controlName+"_month")){return;};if(!document.getElementById(controlName+"_year")){return;};var bisiesto=esBisiesto(document.getElementById(controlName+"_year").value);var cMonth=document.getElementById(controlName+"_month").value;if(cMonth==""){showMonth(controlName,document.getElementById(controlName+"_day").value,thisClassName);return;};var maxDays=31;for(var i=0;i<meses.length;i++){if(cMonth==meses[i][0]){maxDays=parseInt(meses[i][2]);break;};};if((bisiesto==true)&&(cMonth=="02")){maxDays=29;};maxDays+=1;showDay(controlName,document.getElementById(controlName+"_day").value,maxDays,thisClassName);return;};
function showYear(controlName,retValue,iniYear,lastYear,className){if(className==null){className="";};if(className!=""){className=" class=\""+className+"\" ";};var html="<select "+className+"name=\""+controlName+"_year\" id=\""+controlName+"_year\" size=1 onchange=\"controldateUpdate('"+controlName+"');updateDays('"+controlName+"',this);\">";html+="<option value=\"\">--</option>";for(var i=lastYear;i>iniYear;i--){html+="<option ";if(retValue==i.toString()){html+="selected ";};html+="value=\""+i+"\">"+i.toString()+"</option>";};html+="</selected>";if (!document.getElementById(controlName+"_year_div")){html="<div id=\""+controlName+"_year_div\">"+html+"</div>";return html;};document.getElementById(controlName+"_year_div").innerHTML=html;html=null;};
function esBisiesto(aYear){if (aYear==""){return false;};if(aYear%400==0){return true;};if(aYear%100==0){return false;};if(aYear%4==0){return true;};return false;};	
function completa(dato,character,len,side){if(dato==null){dato="";};if(character==null){character="0";};if(len==null){len=2;};if(side==null){side="L"}else{side=side.toUpperCase();};if(dato.length < len){for(var i=0;i<(len+1);i++){if(dato.length>=len){return dato;};if(side=="L"){dato=character+dato;}else{dato=dato+character;};};};return dato;};
function getFecha(sFecha,sPart){if(sPart==null){return "";}else{sPart=sPart.toLowerCase();};if(sFecha==null){return "";};if(sFecha.length!=10){return "";};var sRet="";if(sPart=="day"){sRet=sFecha.substring(8);if(isNaN(sRet)){return "";}else{return sRet;}};if(sPart=="year"){sRet=sFecha.substring(0,4);if(isNaN(sRet)){return "";}else{return sRet;}};if(sPart=="month"){sRet=sFecha.substring(5,7);if(isNaN(sRet)){return "";}else{return sRet;}};return "";};	
function controldateUpdate(controlName){if(!document.getElementById(controlName)){return;};var cDay="00";var cMonth="00";var cYear="0000";if(document.getElementById(controlName+"_day")){cDay=completa(document.getElementById(controlName+"_day").value,"0",2,"L");};if(document.getElementById(controlName+"_month")){cMonth=completa(document.getElementById(controlName+"_month").value,"0",2,"L");};if(document.getElementById(controlName+"_year")){cYear=completa(document.getElementById(controlName+"_year").value,"0",4,"L");};document.getElementById(controlName).value = cYear+"-"+cMonth+"-"+cDay;return;};
function gotoPag(dest){document.location.href=dest;};
function showLink(linkTxt,linkTitle,linkDest){if(linkDest==null){linkDest="";};if(linkTitle==null){linkTitle=linkTxt;};var html = "<div ";if(linkDest!=""){html+="onclick=\"gotoPag('"+linkDest+"');\" title=\""+linkTitle+"\" class=\"cuentaTitle\">";}else{html+="class=\"cuentaTitle\">";};html+=linkTxt+"</div>";document.write(html);};
function logOut(){var confirma = window.confirm("¿Esta seguro que desea cerrar su sesión?");if (!confirma){return;};gotoPag("/logout.jsp");};
function doLoginHome(objForm){
	$("#loginHome .formError").each(function(){this.innerHTML="";$(this).css("display","none");});
	if(document.getElementById("loginButton")){var logB=document.getElementById("loginButton");}else{var logB=objForm.loginButton;};
	var objTitle=logB.title;objValue=logB.value;logB.disabled=true;
	logB.title="Por favor espere un momento...";logB.value="Espere";$("#loginLoader").css("display","inline");
	var stageEr=false;var usu_dato1=objForm.usu_dato1.value;var usu_dato2=objForm.usu_dato2.value;var dest="/micuenta.jsp";var captcha=objForm.captcha.value;
	if(!isValidMail(usu_dato1)){$("#men_usu_dato1").html("Por favor ingrese su dirección de email.").css("display","block");stageEr=true;};
	if(usu_dato2.trim()==""){$("#men_usu_dato2").html("Por favor ingrese la clave de acceso.").css("display","block");stageEr=true;};
	if(captcha.trim().length!=5){$("#men_captcha").html("El código ingresado está errado.").css("display","block");stageEr=true;};
	if(stageEr){logB.value=objValue;logB.title=objTitle;logB.disabled=false;$("#loginLoader").css("display","none");return false;};
	var data = "pag=retorno_login&captcha="+escape(captcha)+"&dest="+escape(dest)+"&usu_dato1="+escape(usu_dato1)+"&usu_dato2="+escape(usu_dato2)+"&id=20";
	$("#loginHome .formError").each(function(){this.innerHTML="";$(this).css("display","none");});
	$.post("/ajax/ajax_login.jsp",data,function(data){
		if(jsleft(data,4)=="ERR:"){
			$("#ajaxResult").html(data.replace(/ERR:/,""));
			$("#loginHome .formError").each(function(){
				var mensaje=$("#ajaxResult ."+this.id).html();
				if((mensaje!="")&&(mensaje!=null)){this.innerHTML=mensaje;$(this).css("display","block");};
			});logB.value=objValue;logB.title=objTitle;logB.disabled=false;$("#loginLoader").css("display","none");
			var d = new Date();
			var newcaptcha = $(".mb2").attr("src")+"ref="+d;
			$(".mb2").attr("src",newcaptcha);
				
		}else if(jsleft(data,3)=="OK:"){
			var usuNombres = data.replace(/OK:/,"");
			$("#login_div").remove();
			document.location.href = dest;
		}else{
			logB.value=objValue;logB.title=objTitle;logB.disabled=false;$("#loginLoader").css("display","none");	
		};	
	},"html");
	return false;
};
