// JavaScript Document

//****************************************************************************************************	PARÁMETROS
//****************************************************************************************************
var IDDLE;
var LASTCHECK;
var TIMEOUT = 300; // en segundos

function update_timeout() {
   var tm = new Date();	
   IDDLE = tm.getTime();
   LASTCHECK = IDDLE;
}
function check_timeout() {
   var tm = new Date;
   var now = tm.getTime();
   if ((now - LASTCHECK) > 2000) update_timeout();
   LASTCHECK = now;
   if ((now - IDDLE) > (TIMEOUT * 1000)) document.location="/";
   setTimeout("check_timeout()", 1000);   
}

//****************************************************************************************************	
//****************************************************************************************************
var side_bar_html = "";
var gmarkers = [];
var i = 0;
var chtml;
var map;

function load_map() {
  if (document.getElementById('map')) {
	if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.setCenter(new GLatLng(38.98129653184322, 1.4117431640625), 11);
		
		var latlng = new GLatLng(38.991738,1.544663);
        map.addOverlay(new GMarker(latlng));
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);

	  }
      update_timeout();
   }
}	
function setMapMode(mode) {
   update_timeout();
   switch(mode) {
	  case 'map': map.setMapType(G_NORMAL_MAP); break;
	  case 'sat': map.setMapType(G_SATELLITE_TYPE); break;
	  case 'hyb': map.setMapType(G_HYBRID_TYPE); break;
   }
}
function myclick(i) {
   update_timeout();
   GEvent.trigger(gmarkers[i], "click");
}
//****************************************************************************************************	
//****************************************************************************************************

//****************************************************************************************************
//****************************************************************************************************
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_preloadimg() { //v3.0
  var d=document; if(d.img){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadimg.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 popup(name) {
   newwin =  window.open(name+'.php','CasaLuis','height=600,width=500,scrollbars=yes');
   newwin.focus();
}
//****************************************************************************************************
//****************************************************************************************************
function go_to(url){
	window.location = url;
}
//****************************************************************************************************
//****************************************************************************************************
function newsletter(notext,badformat){
   f = document.getElementById('frm_news');
   m = document.getElementById('news_mail');
   if (f.value == '') {
      alert(notext);
	} else {
      mail = check_email(m.value);
	  if(mail){
		  f.submit();
	  }else{
		  alert(badformat);
	  }
	}
}
//****************************************************************************************************
//****************************************************************************************************
							
function set_field_ok(nom) {
   var d = document.getElementById(nom);
   
   d.style.background = 'none';
   d.style.padding = '0px';
   d.style.margin = '0px';
}
							
function set_field_err(nom) {
   var d = document.getElementById(nom);
   
   d.style.backgroundColor = '#FFCCCC';
   //d.style.padding = '5px';
   //d.style.margin = '0px 10px 0px 0px';
}
							
function check_input(nom) {
   f = document.getElementById(nom)
   d = document.getElementById('form_' + nom)
   if (f.value == '') {
      set_field_err(nom)
	  return false
   } else {
      set_field_ok(nom)
	  return true
   }
}

function check_select(nom) {
   f = document.getElementById(nom)
   d = document.getElementById('form_' + nom)
   if (f.selectedIndex == 0) {
      set_field_err(nom)
	  return false
   } else {
      set_field_ok(nom)
	  return true
   }
}

function check_radio(nom) {
   f = document.getElementById(nom)
   
   return f.checked
}

function check_chbox(nom) {
   f = document.getElementById(nom)
   d = document.getElementById('form_' + nom)
   if (!f.checked) {
      set_field_err(nom)
	  return false
   } else {
      set_field_ok(nom)
	  return true
   }
}
//****************************************************************************************************
//****************************************************************************************************
function check_email (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  // --- Email address seems incorrect (check @ and .'s)
   }

   var user = matchArray[1]
   var domain = matchArray[2]
   if (user.match(userPat) == null) {
      return false   // ---  The username doesn't seem to be valid.
   }

   var IPArray = domain.match(ipDomainPat)
   if (IPArray != null) {
      for (var i=1; i <= 4; i++) {
	     if (IPArray[i] > 255) {
	        return false  // --- Destination IP address is invalid!
	     }
     }
     return true
   }

   var domainArray = domain.match(domainPat)
   if (domainArray == null) {
	  return false  // --- The domain name doesn't seem to be valid.
   }

   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 > 5) {
      return false  // --- The address must end in a three-letter domain, or two letter country.
   }

   if (len < 2) {
      return false  // --- This address is missing a hostname!
   }

   return true;
}
//****************************************************************************************************
//****************************************************************************************************
