function initMenu() {
	var opc = document.getElementById('opc'+thisPage.getId());
	var opcParent = null;
	if (opc==null) {
		opc = document.getElementById('subopc'+thisPage.getId());
		if (opc!=null) {
			opc.className = 'active';
			opc = opc.previousSibling;
			if (opc!=null) {
				while((opc!=null) && (opc.tagName=='DD' || opc.tagName==null)){
					opc = opc.previousSibling;
				}
			}
			if (opc.tagName=='DT') {
				opc.className = 'sublevel-active';
				opc = opc.nextSibling;
				if (opc!=null) {
					while((opc!=null) && (opc.tagName=='DD' || opc.tagName==null)){
						if (opc.className!='active')opc.className = '';
						opc = opc.nextSibling;
					}
				}
			}
		} else if (arrayPages.length>2) {
			opc = document.getElementById('subopc'+arrayPages[2]);
			if (opc!=null) {
				opc.className = 'active';
				opc = opc.previousSibling;
				if (opc!=null) {
					while((opc!=null) && (opc.tagName=='DD' || opc.tagName==null)){
						opc = opc.previousSibling;
					}
				}
				if (opc.tagName=='DT') {
					opc.className = 'sublevel-active';
					opc = opc.nextSibling;
					if (opc!=null) {
						while((opc!=null) && (opc.tagName=='DD' || opc.tagName==null)){
							if (opc.className!='active')opc.className = '';
							opc = opc.nextSibling;
						}
					}
				}
			}
		}
	} else if (opc!=null) {
		if (opc.className!='sublevel') {
			opc.className = 'active';
		} else {
			opc.className = 'sublevel-active-select';
		}

		opc = opc.nextSibling;
		if (opc!=null) {
			while((opc!=null) && (opc.tagName=='DD' || opc.tagName==null)){
				if (opc.className!='active')opc.className = '';
				opc = opc.nextSibling;
			}
		}
	}
}

function toggleMenuLevel(elemId) {
	var opc = document.getElementById(elemId);
	if(opc!=null) {
		if(opc.className.indexOf("sublevel")==-1) return;
		switch(opc.className) {
			case "sublevel":
				opc.className = "sublevel-active";
				opc = opc.nextSibling;
				if (opc!=null) {
					while((opc!=null) && (opc.tagName=='DD' || opc.tagName==null)){
						if(opc.nodeType==1 && opc.nodeName.toUpperCase()=="DD") {
							if (opc.getAttribute("id")=='subopc'+thisPage.getId())
								opc.className = 'active';
							else
								opc.className = '';
						}			
						opc = opc.nextSibling;
					}
				}		
				break;
			case "sublevel-active":
				opc.className = "sublevel";
				opc = opc.nextSibling;
				if (opc!=null) {
					while((opc!=null) && (opc.tagName=='DD' || opc.tagName==null)){
						if(opc.nodeType==1 && opc.nodeName.toUpperCase()=="DD") 
							opc.className = 'none';
						opc = opc.nextSibling;
					}
				}		
				break;
			case "sublevel-active-select":
				opc.className = "sublevel-select";
				opc = opc.nextSibling;
				if (opc!=null) {
					while((opc!=null) && (opc.tagName=='DD' || opc.tagName==null)){
						if(opc.nodeType==1 && opc.nodeName.toUpperCase()=="DD") 
							opc.className = 'none';
						opc = opc.nextSibling;
					}
				}		
				break;
			case "sublevel-select":
				opc.className = "sublevel-active-select";
				opc = opc.nextSibling;
				if (opc!=null) {
					while((opc!=null) && (opc.tagName=='DD' || opc.tagName==null)) {
						if(opc.nodeType==1 && opc.nodeName.toUpperCase()=="DD") {
							if (opc.getAttribute("id")=='subopc'+thisPage.getId())
								opc.className = 'active';
							else
								opc.className = '';	
						}		
						opc = opc.nextSibling;
					}
				}		
				break;			 
		}
	}
}

function initLanguageChange() {
	var selector = document.getElementById('lenguaje');
	if (selector!=null) {
		selector.onchange = function() {
			document.location.href = selector.value;
			}
	}
}

function initFontSize() {
	var minus = document.getElementById('fileLinkA4');
	var plus = document.getElementById('fileLinkA5');
	if (minus!=null) {
		minus.onclick = function() { thisPage.changeStyles(0); }
		minus.onkeypress = function() { thisPage.changeStyles(0); }
	}
	if (plus!=null) {
		plus.onclick = function() { thisPage.changeStyles(1); }
		plus.onkeypress = function() { thisPage.changeStyles(1); }
	}
}

function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function setTxtSearch(id,text,num) {
	if (id!=null && id!="" && text!=null && text!="") {
		if (id =="PWD" || id=="PWD_CHPWD" || id=="NEWPWD_CHPWD" || id=="REPPWD_CHPWD") {
			var relId = "";
			switch(id) {
				case "PWD":
					relId = "PWD2";
					break;
				case "PWD_CHPWD":
					relId = "PWD2_CHPWD";
					break;
				case "NEWPWD_CHPWD":
					relId = "NEWPWD2_CHPWD";
					break;	
				case "REPPWD_CHPWD":
					relId = "REPPWD2_CHPWD";
					break;
			}
			if (trimAll(document.getElementById(id).value) == "") {
				document.getElementById(id).value = "";
				document.getElementById(id).className = "invisible";
				document.getElementById(relId).className = "visible";
			}
			if (trimAll(document.getElementById(relId).value) == "") {
				document.getElementById(relId).value = text;
			}
		} else {
			if (trimAll(document.getElementById(id).value) == "") {
				document.getElementById(id).value = text;
			}
		}
	}
}

function setTxtSearchBlanco(id,text,num) {
	if (id!=null && id!='' && text!=null && text!='') {
		if (trimAll(document.getElementById(id).value) == text) {
			document.getElementById(id).value = "";
			if (num!=null && num==1) {
				document.getElementById(id).className = "invisible";
				var relId = "";
				switch(id) {
					case "PWD":
					case "PWD2":
						relId = "PWD";
						break;
					case "PWD_CHPWD":
					case "PWD2_CHPWD":
						relId = "PWD_CHPWD";
						break;
					case "NEWPWD_CHPWD":
					case "NEWPWD2_CHPWD":
						relId = "NEWPWD_CHPWD";
						break;	
					case "REPPWD_CHPWD":
					case "REPPWD2_CHPWD":
						relId = "REPPWD_CHPWD";
						break;
					default:
						relId = "PWD";
						break;
				}
				document.getElementById(relId).className = "visible";
				document.getElementById(relId).focus();
			}
		}
	}
}

function showLogin() {
	var loginform = document.getElementById('loginform');
	if (loginform != null) {
		if (loginform.className == 'invisible') {
			loginform.className = 'visible';
		} else {
			loginform.className = 'invisible';    
		}
	}
	if(document.getElementById("checkuserinfo")!=null)
		document.getElementById("checkuserinfo").className = "invisible";
}

function showChangePwd() {
	var loginform = document.getElementById('changepwd');
	if (loginform != null) {
		if (loginform.className == 'invisible') 
			loginform.className = 'visible';
		else 
			loginform.className = 'invisible';    
	}
	if(document.getElementById("checkuserinfo")!=null)
		document.getElementById("checkuserinfo").className = "invisible";
}

function checkUserLogged() {
	params = "step=0";
	var m_jsp = "";
	var arrInp = Form.getInputs("login"+thisPage.getId(),"hidden","logjsp"+thisPage.getId());
	
	var ajax_login = function(xmlrequest) {
		var json = eval("("+xmlrequest.responseText+")");
		if(json.logged) {
			if($("username"+thisPage.getId())!=null)
				$("username"+thisPage.getId()).innerHTML = json.usrName;
			if($("changepwd")!=null) 
				$("changepwd").className = "invisible";	
			if($("loginform")!=null) 
				$("loginform").className = "invisible";
			if($("checkuserinfo")!=null)
				$("checkuserinfo").className = "invisible";
			if($("logininfo")!=null) 
				$("logininfo").className = "visible";
			if($("loginlink"+thisPage.getId())!=null) 
				Element.hide($("loginlink"+thisPage.getId()));
		} else {
			if($("checkuserinfo")!=null)
				$("checkuserinfo").className = "invisible";
		}
	}
	
	if(arrInp!=null && arrInp.length>0) { 
		m_jsp = arrInp[0].value;
		
		var ajax = new Ajax.Request(
              		m_jsp,                  // URL
              		{                       // options
                  		asynchronous:   true,
                  		method:         "post",
                  		parameters:     params,
                  		onComplete:     ajax_login
               		});
        }       		
}

function closeUserSession(redirect) {
	params = "step=1";
	var m_jsp = "";
	var arrInp = Form.getInputs("login"+thisPage.getId(),"hidden","logjsp"+thisPage.getId());
	
	var ajax_login = function(xmlrequest) {
		var json = eval("("+xmlrequest.responseText+")");
		if(!json.logged) {
			if($("username"+thisPage.getId())!=null)
				$("username"+thisPage.getId()).innerHTML = "";
			if($("changepwd")!=null) 
				$("changepwd").className = "invisible";	
			if($("loginform")!=null) 
				$("loginform").className = "invisible";
			if($("checkuserinfo")!=null)
				$("checkuserinfo").className = "invisible";	
			if($("logininfo")!=null) 
				$("logininfo").className = "invisible";
			if($("loginlink"+thisPage.getId())!=null) 
				Element.show($("loginlink"+thisPage.getId()));
			if(redirect!=null && redirect!="")
				document.location.href = redirect;
		} else {
			if($("checkuserinfo")!=null)
				$("checkuserinfo").className = "invisible";
		}
	}
	
	if(arrInp!=null && arrInp.length>0) { 
		m_jsp = arrInp[0].value;		
		
		var ajax = new Ajax.Request(
              		m_jsp,                  // URL
              		{                       // options
                  		asynchronous:   true,
                  		method:         "post",
                  		parameters:     params,
                  		onComplete:     ajax_login
               		});
        }       		
} 
 

