//Variables globales
	var GB_ROOT_DIR = "/source/jscript/greybox/";//ruta para el greybox
	var startDate=null;
	var endDate=null;
	var arrival=null;
	var departure=null;
	var callbacks = 0;
//end variables globales

//formulario	
		function ajax(div,url){//simplificando el ajaxload 
			//alert(url);
			$ajaxload(div,url, "<img src='/content/media/img/loading.gif'>", "appear", false);
		}

		function show(id){//muestra el elemento
			document.getElementById(id).style.display = 'block';
		}
		
		function hide(id){//oculta un elemento
			document.getElementById(id).style.display = 'none';
		}
		
		function cambiarIdioma(newLang,idioma)
			{
				if(newLang!=idioma)
				{
					//alert(newLang + " " + idioma);
					
					var query = window.location.search;//query string
					var url,direccion;//la url que devolvemos
					
					if (query!=""){//si tiene algo en la query
						dire = escape(window.location).split(escape(window.location.search));
						direccion=unescape(dire[0])+"";
					}
					else{
						direccion = window.location+"";
					}

					switch (newLang) 
						{
							case "eng":
								newLang="en";
							break
							case "s":
								newLang="sv";
							break
							case "po":
								newLang="pt";
							break
							case "d":
								newLang="de";
							break
							case "dk":
								newLang="da";
							break
						}
			
					if (direccion.indexOf(".")>10) {
						direccion='.'+direccion.slice(direccion.indexOf("http://")+7,direccion.length);	
					}
					else{
						direccion=direccion.slice(direccion.indexOf("."),direccion.length);	
					}
					
					var url="http://"+newLang+direccion+query;
					//alert(url);
					loading();
					window.location=url;
				}
			}
		
		function browserCheck(){//mira el tipo de navegador y devuelve el tipo
			if (document.getElementById){browser="FF"}
			if (document.all){
				
					version=0
					if (navigator.appVersion.indexOf("MSIE")!=-1){
						temp=navigator.appVersion.split("MSIE")
						version=parseFloat(temp[1])
					}
					//alert(version);
					if (version<=6) browser="IEOLD";
					else browser="IE";
				
				}
				
			if (document.layers){browser="OTHER"}
			
			//alert (browser);
			return browser;
		}
		
		function hideFormElements(){// hide all form elements
			var numForms=document.forms.length
			for (f=0; f<numForms; f++){
				var numElements=document.forms[f].elements.length
				for (e=0; e<numElements; e++){
					document.forms[f].elements[e].style.visibility="hidden";
				}
			}
			hide('order');
		}
		
		function showFormElements(){// hide all form elements
			var numForms=document.forms.length
			for (f=0; f<numForms; f++){
				var numElements=document.forms[f].elements.length
				for (e=0; e<numElements; e++){
					document.forms[f].elements[e].style.visibility="visible";
				}
			}
			show('order');
		}
				
		function isNumberKey(evt){
			var charCode = (evt.which) ? evt.which : event.keyCode;
				
			if((charCode==46||charCode==8||charCode==45||charCode==47) ||(charCode >= 48 && charCode <= 57) ){
				return true;
			}
			else {
				return false;
			}
		
		}
		  
		 function isAlphaKey(evt){
			 var charCode = (evt.which) ? evt.which : event.keyCode;
			 if ((charCode==8 || charCode==32) || ( (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) ) ) {
			 	return true;
			 }
			 else {
				 return false;
			 }
		  }
		 
		 function isEmail(valor) {
		  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
			return (true)
		  } else {
			return false;
		  }
		}

		function resetDates() {
			startDate = endDate = null;
		}

		function compareDatesOnly(date1, date2) {
			var year1 = date1.getYear();
			var year2 = date2.getYear();
			var month1 = date1.getMonth();
			var month2 = date2.getMonth();
			var day1 = date1.getDate();
			var day2 = date2.getDate();
			
			if (year1 > year2) {
				return -1;
			}
			if (year2 > year1) {
				return 1;
			}

			//years are equal
			if (month1 > month2) {
				return -1;
			}
			if (month2 > month1) {
				return 1;
			}

			//years and months are equal
			if (day1 > day2) {
				return -1;
			}
			if (day2 > day1) {
				return 1;
			}

			//days are equal
			return 0;
		}

		function filterDates1(arrival) {
			startDate = arrival.date;
			document.getElementById('departure').value=document.getElementById('arrival').value;//ponemos en el text el valor de la llegada
			if (endDate == null) { //solo si no se habia creado antes el objeto
				var departure = new Calendar.setup({
					inputField     :    "departure",
					button         :    "departure",  
					date           :     startDate,//empieza desde...
					electric       :     false,
					showsTime      :     false,        
					disableFunc    :    dateInRange2,
					onUpdate       :    filterDates2
				});
			}
		}

		function filterDates2(arrival) {
			endDate = arrival.date;
		}

		function dateInRange1(date) {

			if (endDate != null) {
				// Disable dates after end date
				var compareEnd = compareDatesOnly(date, endDate);
				if  (compareEnd < 0) {
					return (true);
				}
				// Hilight end date with "edges" style
				if  (compareEnd == 0) {
					{return "edges";}
				}
				// Hilight inner dates with "between" style
				if (startDate != null){
					var compareStart = compareDatesOnly(date, startDate);
					if  (compareStart < 0) {
						return "between";
					} 
				} 
			}
			//disable days prior to today
			var today = new Date();
			var compareToday = compareDatesOnly(date, today);
			if (compareToday > 0) {
				return(true);
			}
			//all other days are enabled
			return false;
			//alert(ret + " " + today + ":" + date + ":" + compareToday + ":" + days1 + ":" + days2);
			return(ret);
		}

		/* Can't choose days before the
		 * start date if it is choosen, hilights start and end dates with one style and dates between them with another*/

		function dateInRange2(date) {
			if (startDate != null) {
				// Disable dates before start date
				var compareDays = compareDatesOnly(startDate, date);
				if  (compareDays < 0) {
					return (true);
				}

				// Hilight end date with "edges" style
				if  (compareDays == 0) {
					{return "edges";}
				}

				// Hilight inner dates with "between" style
				if ((endDate != null) && (date > startDate) && (date < endDate)) {
					return "between";
				} 
			} 

			var now = new Date();
			if (compareDatesOnly(now, date) < 0) {
				return (true);
			}

			//all other days are enabled
			return false;
		}
		
		function popup (url, width, height) {
			//var day = new Date(); 
			var name = "popup"; //day.getTime();
		
		  var left = (screen.availWidth-10 - width) / 2;
		  var top = (screen.availHeight-20 - height) / 2;
		
		  features = "width="+width+",height="+height+",left="+left+",top="+top;
		  features += ",screenX="+left+",screenY="+top;
		  features += ",scrollbars=0,resizable=1,location=0";
		  features += ",menubar=0,toolbar=0,status=0";
		
		  return window.open(url, name, features);
		}
		
		function leftshift(op,n) {// VBScript is missing Left Shift, so this fixes that 
			return op << n;
		}
				
