//	Mapa - Situacion -
// ............................................................

var imgact = 0;
var side_bar_html = "";
var gmarkers = [];
var i = 0;
var map;

function load_mapa() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
        map.setCenter(new GLatLng(MapLat, MapLon), MapZoom);
		}
	  setMapMode('hyb');
      carga_inicial();
	}

function setMapMode(mode) {
	   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) {
        GEvent.trigger(gmarkers[i], "click");
}

function createMarker(point, nombre) { 
      var marker = new GMarker(point, "FirstMarker"); 
          GEvent.addListener(marker, 'click', function() { 
          marker.openInfoWindowHtml(nombre); 
       }); 
      return marker; 
   }
   
function createMarker2(point,name,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the side_bar
        gmarkers[i] = marker;
        // add a line to the side_bar html
        side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>';
        i++;
        return marker;
}


function openInfoWindowHtml(nom) {
   alert(nom);	
}

	
function carga_inicial(){
		var p = new GLatLng(38.91388500805814, 1.2257105112075806);
		var n = "IBIZAHOUSERENTING";
   	    marker = createMarker2(p,n,'<table cellspading="0" cellspacing="0" width="110"><tbody><tr><td><img src="../img/site/vvibiza/logo.gif"></td></tr><tr><td valign="top" align="left" style="padding-left: 5px;"><div style="width:75px" alt="Ibizahouserenting" class="text"><strong>Ibizahouserenting.com</strong></div></td></tr></tbody></table>'); 
    	map.addOverlay(marker);
		
}

//	Mapa - Situacion -
// ............................................................


var image_names = new Array();

function preload(){
    var images = new Array();
    var i;
	for (i = 0; i < image_names.length; i++) {
	   images[i] = new Image();
	   images[i].src = image_names[i];	
	}
}
	
function Addpreload(nomimg){
	image_names[image_names.length] = nomimg;
    }

function sendform(name) {
   f = document.getElementById(name);
   f.submit();
}

function mostrar(div) {
   var d = document.getElementById(div);
   d.style['display'] = 'block';
}

function ocultar(div) {
   var d = document.getElementById(div);
   d.style['display'] = 'none';
}

function prueba(){
	document.write("Hola que tal");
	//alert("hola");
	//document.getElementById("Hora_recogida").focus();	
}

function get_select_value(sel) {
   var d = document.getElementById(sel);
   return d.options[d.selectedIndex].value;
}

function hide_div(id) {
   var d = document.getElementById(id);
   d.style.display = 'none';
}

function show_div(id) {
   var d = document.getElementById(id);
   d.style.display = 'block';
}

function hide_td(id) {
   var d = document.getElementById(id);
   d.style.display = 'none';
}

function show_td(id) {
   var d = document.getElementById(id);
   //d.style.display = 'table-cell';
   //d.style.display = 'inline-block';
   d.style.display = 'block';
}

/*function show_td(id) {
	alert('Entro en show_td_div '+id);	
   var d = document.getElementById(id);
	alert('Entro en show_td_div 2 '+id);   
   d.style.display = 'inline';
	alert('Entro en show_td_div 3 '+id);      
}*/

function get_value(table) {
   var d = document.getElementById(sel);
   return d.options[d.selectedIndex].value;
}

/* ---------------------------------------------------------------------------------------------------------*/
function ld_mod(name, fid) {
   location = name + ".php" + ((typeof(fid) != "undefined") ? ("?fid=" + fid) : '');
}

function popup(name) {
   newwin =  window.open('popup.php?mod=' + name,'easyibiza','height=600,width=500,scrollbars=yes');
   newwin.focus();
}

var img = new Array();
var imgnom = new Array();
var nimgs = 0;
var pg = 0;

function show_img(div, num) {
   var dv = document.getElementById(div);
   
   dv.src = img[num].src;
}

function show_pg(n) {
   var pag;
   // ocultar actual
   pag = document.getElementById('page' + pg);    pag.style['display']    = 'none';
   pag = document.getElementById('t_pager' + pg); pag.style['color']      = '#656261';
                                                  pag.style['fontSize']   = '10px';
   pag = document.getElementById('b_pager' + pg); pag.style['color']      = '#656261';
                                                  pag.style['fontSize']   = '10px';
   // mostrar nuevo
   pg = n;
   pag = document.getElementById('page' + pg);    pag.style['display']    = 'block';
   pag = document.getElementById('t_pager' + pg); pag.style['color']      = '#900';
                                                  pag.style['fontSize']   = '11px';
   pag = document.getElementById('b_pager' + pg); pag.style['color']      = '#900';
                                                  pag.style['fontSize']   = '11px';
}

function show_div(nom, n, tot) {
   for (i = 0; i < tot; i++) {
	  dv = document.getElementById(nom+i)
	  dv.style['display'] = (i == n) ? 'block' : 'none';
   }
}

function swap_div(name) {
	  dv = document.getElementById(name)
	  if (divstat[name] == 'none') {
	     dv.style['display'] = 'block';
		 divstat[name]       = 'block';
	  } else {
	     dv.style['display'] = 'none';
		 divstat[name]       = 'none';
	  }
}

// ------------------------[  e-mail check
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;
}

// ------------------------[  Form validation
							
function set_field_ok(nom) {
   var d = document.getElementById('form_' + nom);
   
   d.style.background = 'none';
   d.style.padding = '0px';
   d.style.margin = '0px';
}
							
function set_field_err(nom) {
   var d = document.getElementById('form_' + 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
   }
}

// ------------------------[  Credit card check
function cc_check(cc) { return (cc.lenght == 16) ? true : false; }

// ------------------------[   Date functions

function get_date(d, m, y) {
   var dd = document.getElementById(d).selectedIndex
   var dm = document.getElementById(m).selectedIndex
   var dy = document.getElementById(y).selectedIndex

   var hoy = new Date();
   var tm = new Date();
   tm.setYear(1900 + hoy.getYear() + dy)
   tm.setMonth(dm)
   tm.setDate(dd + 1)

   return tm   
}

function set_date(d, m, y, dia) {
   var dd = document.getElementById(d)
   var dm = document.getElementById(m)
   var dy = document.getElementById(y)
   
   var hoy = new Date();
   var year = dia.getYear() - hoy.getYear();
   if (year >= 1900) year -= 1900;

   dd.selectedIndex = dia.getDate() - 1
   dm.selectedIndex = dia.getMonth()
   dy.selectedIndex = year
}

function update_date(id, im, iy, od, om, oy, days) {
   var d = get_date(id, im, iy)
   
   d.setTime(d.getTime() + (days * 86400000))
   set_date(od, om, oy, d)
}

function checkDate(d) {
   if (!d) d = 1
   update_date('in_d', 'in_m', 'in_y', 'out_d', 'out_m', 'out_y', d)
}