function trim(str) {
  
  return str.replace(/^\s+|\s+$/g, '');
}

//OK
//valida direccion de email   "nombre_usuario@server.dominio" (dominio .XXX or xxx.xx)
function validateEmail(vfld){
	      
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(vfld)) {
	  return true;
	  }else{return false};
}

//valida nombre de usuario
function validateName(param)
{
  var fullName= trim(param);
  
  
 if ( /^[a-z\d_]+$/.test(fullName) ){
   return true;
 }else{ return false; }
}


//busca si hay letras o num en un texto
//espacios en blanco
function validateText(param)
{
   if ( /^[\w\s]+$/.test(param)){
     return true;
   } else {return false;}; 
}


//valida fecha "dd/mm/yyyy"  o "mm/dd/yyyy"
//validates date in this format ""dd/mm/yyyy" or "mm/dd/yyyy"
function validateDate(param)
{
  
  if (/^\d{1,2}\/\d{1,2}\/\d{2,4}$/.test(param)){
	
	return true;
}else{
	return false;}
}

//valida hora "hh:mm"
//validates time "hh:mm"
function validateTime(param)
{
 if (/^(0[1-9]|1\d|2[0-3]):([0-5]\d)$/.test(param)){
	return true;
}else{
	return false;}
}    	
//OK
//valida num telefono
//formatos validos xxx-xxx-xxxx xxx-xxxxxxx xxxxxxxxxx 
function validateTelnr(param)
{
     if (/^[0-9]{3}-?[0-9]{3}-?[0-9]{4}$/.test(param)){
      return true;
  }else{ return false; }
}

function checkPresent(str){
	if(trim(str) != ''){
		return true;
	}
	return false;
}


function checkLength(mystr, minlenght){
	var str = trim(mystr.value);

	if(str.length >= minlenght){
		return true;
	}
	return false;
}


function openPopup(image_name, image_width, image_height){
	var top = (screen.height - image_height) /2;
	var left = (screen.width - image_width) /2;
	window.open("inc/image_popup.php?file_name="+image_name,"picture","resizable=no, width="+image_width+", 	height="+image_height+", top="+top +", left="+left);
}

function showDialog(name)
{
	var dlgCommon = dojo.widget.byId(name);
	dlgCommon.show();
	hideFlashDivs();
	return true;
}

function hideDialog(name)
{
	showFlashDivs();
	var dlgCommon = dojo.widget.byId(name);
	dlgCommon.hide();
	return true;
}

function hideFlashDivs()
{
	var logo = dojo.byId('logo');
	var news = dojo.byId('news');
	var anim = dojo.byId('anim');
	if (logo != null) logo.style.display="none";
	if (news != null) news.style.display="none";
	if (anim != null) anim.style.display="none";
}

function showFlashDivs()
{
	var logo = dojo.byId('logo');
	var news = dojo.byId('news');
	var anim = dojo.byId('anim');
	if (logo != null) logo.style.display="block";
	if (news != null) news.style.display="block";
	if (anim != null) anim.style.display="block";
}

function show_div(id)
{
	if(document.getElementById(id)){
		document.getElementById(id).style.display ="block";
	}
}

function hide_div(id)
{
	if(document.getElementById(id)){
		document.getElementById(id).style.display ="none";
	}
}

//-------------------------------------------------------------------------------
// Check Browser
function loadBrowserCSS(id, path){

	var theUA = navigator.userAgent.toLowerCase();
	isExplorer = (theUA.indexOf('msie')!=-1);
	var posInicio = theUA.lastIndexOf('msie')+4;
	theversion = parseFloat(theUA.substring(posInicio, posInicio+4));
	
	if (isExplorer){
		//var link ='<link href="' + path + "styles_ie" + theversion + '.css" rel="stylesheet" type="text/css" id="IE_style" />';
		//document.write(path + "styles_ie" + theversion + '.css');
		/*
		if(document.getElementById(id)){
			document.write('Load Style');
			document.getElementById(id).href = path + "styles_ie"+theversion+".css";
		}
		*/
		
		var link = document.createElement('link');  
		link.href = path + "styles_ie" + theversion + '.css';  
		link.rel = 'stylesheet';  
		link.type = 'text/css';
		document.getElementsByTagName('head')[0].appendChild(link);

		//document.write(link);
		//alert(document.getElementById(id).href+"::");
	}
}

function showDialog(name)
{
	var dlgCommon = dojo.widget.byId(name);
	if(dlgCommon != null) dlgCommon.show();
	hideFlashDivs();
	return true;
}

function hideDialog(name)
{
	showFlashDivs();
	var dlgCommon = dojo.widget.byId(name);
	if(dlgCommon != null) dlgCommon.hide();
	return true;
}


