var _LIT_CHECK_NAME = "Por favor, indica tu nombre en el campo <Nombre>";
var _LIT_CHECK_PHONE = "Por favor, indica un télefono válido en el campo <Teléfono>";
var _LIT_CHECK_EMAIL = "Por favor, indica un correo electrónico válido en el campo <E-mail>";
var _LIT_CHECK_QUESTION = "Por favor, indica el motivo de tu consulta en el campo <Consulta>";



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
function toggleLayer(whichLayer ,iState )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if (iState == 1){
	vis.display = 'block';
  } else {
	vis.display = 'none';
  }
}


function changeLink (whichLink, iState){
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLink );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLink];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLink];
  if (iState == 1){
 	elem.className = 'menu_selected';
  } else {
	if (whichLink == 'menuEstudioLink' || whichLink == 'menuProyectosLink'){
	 	elem.className = 'menu tipo1';
	} else {
	 	elem.className = 'menu tipo2';
	}
  }
}

function LTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {

      var j=0, i = s.length;

      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      s = s.substring(j, i);
   }
   return s;
}
function RTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {

      var i = s.length - 1;       // Get length of string

      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }

   return s;
}
function Trim(str)
{
   return RTrim(LTrim(str));
}
function isEmpty (str){
    return (Trim(str) == "");
}

function isLengthMoreThan(value,fieldLength){
	s = Trim(value);
	return(value.length >= fieldLength);
}

function isEmail(email){
    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    return (email.search(validRegExp) != -1);
}
function isPhone(phone)
{
	phone=Trim(phone);
	var patron = /(^([0-9\-\+\/\ ]){9,17})/
	return patron.test(phone);
}

function checkPhone (field, fieldDescription){
  if (!isPhone(field.value)) {
    alert(fieldDescription);
    field.focus();
    field.select();
	return false;
  }
  return true;
}

function checkEmail (field, fieldDescription){
  if (!isEmail(field.value)) {
    alert(fieldDescription);
    field.focus();
    field.select();
	return false;
  }
  return true;
}

function checkEmpty(field, fieldDescription){
    if (isEmpty(field.value)){
        alert(fieldDescription);
        field.focus();
        field.select();
        return true;
    }
	return false;
}

function checkContactData() {
	var txtNombre = MM_findObj("txtNombre");
	var txtTelefono = MM_findObj("txtTelefono");
	var txtMail = MM_findObj("txtMail");
	var txtConsulta = MM_findObj("txtConsulta");
	if (checkEmpty(txtNombre, _LIT_CHECK_NAME)) {
		return false;
	}
	if (!isEmpty(txtTelefono.value)) {
		if (!checkPhone(txtTelefono, _LIT_CHECK_PHONE)) {
			return false;
		}
	}
	if (checkEmpty(txtMail, _LIT_CHECK_EMAIL)) {
		return false;
	}
	if (!checkEmail(txtMail, _LIT_CHECK_EMAIL)) {
		return false;
	}
	if (checkEmpty(txtConsulta, _LIT_CHECK_QUESTION)) {
		return false;
	}
	return true;
}

function establecerTipoProyecto(){
	var formData = MM_findObj("formBuscador");
	formData.action = "establecerTipoProyecto.php";
	formData.submit();
}

function establecerSubtipoProyecto(){
	var formData = MM_findObj("formBuscador");
	formData.action = "establecerSubtipoProyecto.php";
	formData.submit();
}

function establecerTipoGestion(){
	var formData = MM_findObj("formBuscador");
	formData.action = "establecerTipoGestion.php";
	formData.submit();
}

function setOpacity(obj) {
	if(obj.xOpacity>.99) {
		obj.xOpacity = .99;
		return;
	}
	obj.style.opacity = obj.xOpacity;
	obj.style.MozOpacity = obj.xOpacity;
	obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
}

function imagenMouseOver(obj){
	obj.xOpacity = .90;
	setOpacity(obj);
}
function imagenMouseOut(obj){
	obj.xOpacity = .98;
	setOpacity(obj)
}


