	/* class roll over */
	function roll_over(obj,state,clas){
		obj.className = clas;
	}
	
	/* remove trailing and leading blanks from a string */
	function trim(s) {
		while (s.substring(0,1) == ' ') {
			s = s.substring(1,s.length);
		}
		while (s.substring(s.length-1,s.length) == ' ') {
			s = s.substring(0,s.length-1);
		}
		return s;
	}
	
	/* check if object is an array */
	function isArray(obj){
		return(typeof(obj.length)=="undefined")?false:true;
	}

	/* basic form validation */
	function checkForm(poForm){
		for(i=0; i<poForm.elements.length; i++){
			if(poForm.elements[i].lang == "true"){
				//alert(poForm.elements[i].type); 
				switch (poForm.elements[i].type) {
					case "text":
					case "password":
					case "textarea":
					case "file":
						if(trim(poForm.elements[i].title)!=""){
							if(trim(poForm.elements[i].value) == ""){
								alert(poForm.elements[i].title);
								poForm.elements[i].value = "";
								poForm.elements[i].focus();
								return false;
							}
						}
						//custom validations
						if(poForm.elements[i].alt!=null){
							if(trim(poForm.elements[i].alt)!=''){
								//check email address
								if((trim(poForm.elements[i].value) != "")&&(poForm.elements[i].alt=="email")){
									if(!emailCheck(poForm.elements[i].value)){
										alert("Escriba una direccion de e-mail válida");
										poForm.elements[i].focus();
										return false;
									}
								}
								//check numeric values
								if((trim(poForm.elements[i].value) != "")&&(poForm.elements[i].alt=="numeric")){
									if(!checknumber(poForm.elements[i].value)){
										alert("El campo debe ser tipo numérico");
										poForm.elements[i].focus();
										return false;
									}
								}
								//check valid files
								if((trim(poForm.elements[i].value) != "")&&(poForm.elements[i].alt=="file")){
									var tmp_file_obj = poForm.elements[i];
									var tmp_file_name = trim(poForm.elements[i].value);
									var tmp_file_types = trim(poForm.elements[i].accept);
									if(!checkfilename(tmp_file_name)){
										alert("El nombre del archivo no puede contener caracteres especiales como letras acentuadas o espacios");
										tmp_file_obj.focus();
										return false;
									}
									if(!checkfiletype(tmp_file_name,tmp_file_types)){
										alert("Archivo inválido, verifique el tipo de archivo.");
										tmp_file_obj.focus();
										return false;
									}
								}
							}
						}
						break;
					case "radio":
						elradio = eval("poForm."+poForm.elements[i].name);
						checado = false;
						if(isArray(elradio)){
							for(j=0; j<elradio.length; j++){
								if(elradio[j].checked)
									checado = true;
							}
						} else{
							if(elradio.checked)
								checado = true;
						}
						if(!checado){
							if(isArray(elradio)){
								alert(elradio[0].title);
								elradio[0].focus();
							} else{
								alert(elradio.title);
								elradio.focus();
							}
							return false;
						}
						break;
					case "select-one":
						if(poForm.elements[i].selectedIndex < 1){
							alert(poForm.elements[i].title);
							poForm.elements[i].focus();
							return false;
						}
						break;
					case "select-multiple":
						if(poForm.elements[i].selectedIndex < 1){
							alert(poForm.elements[i].title);
							poForm.elements[i].focus();
							return false;
						}
						break;
				}
			}
		}
		return true;
	}
	
	/* validates an email address */
	function emailCheck(emailStr) {
		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) {
			return false
		}
		var user=matchArray[1]
		var domain=matchArray[2]
		if (user.match(userPat)==null) {
		    return false
		}
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					return false
				}
			}
			return true
		}
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			return false
		}
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
			return false
		}
		if (len<2) {
			alert(errStr)
			return false
		}
		return true;
	}
	
	/* open window */
	function openWin(Addr, Name, Options){
		var tmp = window.open(Addr, Name, Options);
	}
	
	/* validates a number */	
	function checknumber(poField){
		var x=poField;
		var anum=/(^\d+$)|(^\d+\.\d+$)/;
		if (anum.test(x))
			testresult=true;
		else{
			testresult=false;
		}
		return (testresult);
	}
	
	/* check if filename contains special chars */
	function checkfilename(fileName) {
		var donde = fileName.lastIndexOf('\\');
		var ArregloChars = new Array('á','é','í','ó','ú',' ','ñ','Á','É','Í','Ó','Ú','Ñ','/','*','?');
		for(i=0;i<16;i++) {
			if(fileName.indexOf(ArregloChars[i], donde) >= 0) {
				return false;
			}
		}
		return true;
	}
	
	/* check if file is of specified type */
	function checkfiletype(filePath, fileTypes) {
		var fileName = new Array();
		fileName = filePath.split('.');
		var fileExt = fileName[fileName.length-1];
		fileExt = fileExt.toLowerCase()
		var aFileTypes = fileTypes.split(',');
		var counter=0;
		var found=0;
		while (counter < aFileTypes.length) {
			if(fileExt==aFileTypes[counter]) {
				found=1;
				break;
			}
		  counter+=1;
		}
		if(!found) {
			return false;
		}
		return true;
	}
	
	/* show and hide a block */
	function displayBlock(elemID) {
		var DataID = elemID;
		if (DataID.style.display=="block") {
			DataID.style.display="none";
		} else {
			DataID.style.display="block";
		}
	}
	
	function showBlock(elemID) {
		var DataID = elemID;
		DataID.style.display="block";
	}
	
	function hideBlock(elemID) {
		var DataID = elemID;
		DataID.style.display="none";
	}
	
	/* promts user logout */												
	function doLogout(pURL){
		if (window.confirm('¿Está seguro que desea terminar la sesión?'))
			window.location.href=pURL;
		else
			return;
	}
	
	/* confirm deletion */
	function cfm_delete(modName,itemID,itemName){
		if (window.confirm('¿Está seguro que desea eliminar '+itemName+'?'))
			self.location.href='index.asp?action='+modName+'.delete&'+itemID;
	}

	/* confirm status update */
	function cfm_status(modName,itemID,itemName,itemActive){
		if (itemActive){
			if (window.confirm('¿Está seguro que desea desactivar '+itemName+'?'))
				self.location.href='index.asp?action='+modName+'.status&active=0&'+itemID;
		} else {
			if (window.confirm('¿Está seguro que desea activar '+itemName+'?'))
				self.location.href='index.asp?action='+modName+'.status&active=1&'+itemID;
		}
	}
	
	/* sort window */
	function cfm_sort(modName,parentID){
		wnd = window.open('index.asp?action='+modName+'.sortform&id_parent='+parentID,'sort','width=550,height=300,resizable=no,scrollbars=yes,menubar=no');
	}
	
	/* history window */
	function cfm_history(modName,modID,itemID){
		wnd = window.open('index.asp?action='+modName+'.history&id_module='+modID+'&id_item='+itemID,'history','width=550,height=300,resizable=no,scrollbars=yes,menubar=no');
	}
	
	/* sessions window for admins */
	function cfm_sessions_adm(adminID){
		wnd = window.open('index.asp?action=admins.sessions&id_admin='+adminID,'sessions','width=650,height=300,resizable=no,scrollbars=yes,menubar=no');
	}
	
	/* sessions window for users */
	function cfm_sessions_usr(userID){
		wnd = window.open('index.asp?action=users.sessions&id_user='+userID,'sessions','width=650,height=300,resizable=no,scrollbars=yes,menubar=no');
	}
	
	/* view comment window */
	function cfm_view(modName,modID,itemID){
		wnd = window.open('index.asp?action='+modName+'.view&'+modID,'view','width=550,height=300,resizable=no,scrollbars=yes,menubar=no');
	}
	
	/* change class for slideshow */
	function classover(classname){
		if(document.getElementById(classname).className!='img_on')
			document.getElementById(classname).className='img_over';
	}
	function classout(classname){
		if(document.getElementById(classname).className!='img_on')
			document.getElementById(classname).className='img_off';
	}
	function classrestore(classname){
		document.getElementById(classname).className='img_off';
	}
	function classon(classname){
		document.getElementById(classname).className='img_on';
	}
	
	
	/* draw clock (loading...) */
function dc(fl)
{
  var x,y;
  if (self.innerHeight)
  {// all except Explorer
    x = self.innerWidth;
    y = self.innerHeight;
  }
  else 
  if (document.documentElement && document.documentElement.clientHeight)
  {// Explorer 6 Strict Mode
   x = document.documentElement.clientWidth;
   y = document.documentElement.clientHeight;
  }
  else
  if (document.body)
  {// other Explorers
   x = document.body.clientWidth;
   y = document.body.clientHeight;
  }

  var el=document.getElementById('desktop');
	if(null!=el)
	{
		el.style.visibility = (fl==1)?'visible':'hidden';
		el.style.display = (fl==1)?'block':'none';
		el.style.width = x + "px";
		el.style.height = y + "px";
		el.style.zIndex = 1;
	}

	var el=document.getElementById('loader');
	if(null!=el)
	{
		var top = (y/2) - 50;
		var left = (x/2) - 200;
		if( left<=0 ) left = 10;

		el.style.visibility = (fl==1)?'visible':'hidden';
		el.style.display = (fl==1)?'block':'none';
		el.style.left = left + "px"
		el.style.top = top + "px";
		el.style.zIndex = 2;
	}
}

	/* left menu effect */
	function left_menu(stt,elem){
		if(stt)
			document.getElementById(elem).style.visibility="visible"
		else
			document.getElementById(elem).style.visibility="hidden"
	}
	
	/* history window */
	function win_directory(loURL){
		wnd = window.open(loURL,'directory','width=500,height=500,resizable=no,scrollbars=yes,menubar=no');
	}