// JavaScript Document

	function MM_validateForm() { //v4.0
	  var i,p,q,nm,test,num,mini,maxi,errors='',args=MM_validateForm.arguments;
	  for (i=0; i<(args.length-2); i+=3) { 
		test=args[i+2]; 
		val=MM_findObj(args[i]);
		if (val) { 
			nm=args[i+1];
			if ((val=val.value)!="") {
				if (test.indexOf('isEmail')!=-1) { 
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) 
						errors+='- '+nm+' debe contener un e-mail.\n';
			} else if (test!='R') { 
				num = parseFloat(val);
				if (isNaN(val)) 
					errors+='- '+nm+' debe ser numérico.\n';
					if (test.indexOf('inRange') != -1) { 
						p=test.indexOf(':');
						mini=test.substring(8,p); 
						maxi=test.substring(p+1);
						if (num<mini || maxi<num) 
							errors+='- '+nm+' debe contener un número entre '+mini+' y '+maxi+'.\n';
					} 
				} 
			} else if (test.charAt(0) == 'R') 
				errors += '- '+nm+' es obligatorio.\n'; 
			}
		} 
		if(errors){
			alert('Han ocurrido los siguientes errores:\n'+errors);
		}else{
			setTimeout('document.getElementById(\'confirmationButton\').disabled=1;',500);
		}
		document.MM_returnValue = (errors == '');
	}
	
	function validateExsc() {
		var adlt=document.getElementById("Adults").value;
		var chld=document.getElementById("Children").value;
		document.ft_search.action="http://secure.spinofftravel.com/events/step2.php";
		document.ft_search.submit();
	}
	
	
	function bookEntrada(tCode,mCode,num) {
		var desde=document.getElementById("cfrm_date_"+num).value;
		var days=document.getElementById("days_"+num).value;		
		var y_in=desde.substring(0,4);
		var m_in=desde.substring(4,6);
		var d_in=desde.substring(6);
		var nm=(num.indexOf("_")==-1?'0':num.substring(num.indexOf("_")+1));
			
		document.forms["form1"].tCode.value=tCode;
		document.forms["form1"].mCode.value=mCode;
		document.forms["form1"].day.value=d_in;
		document.forms["form1"].month.value=m_in;
		document.forms["form1"].year.value=y_in;
		document.forms["form1"].days.value=days;
		document.forms["form1"].num.value=nm;
		document.forms["form1"].submit();

//		document.location.href="test.php?tCode="+tCode+"&mCode="+mCode+"&day="+d_in+"&month="+m_in+"&year="+y_in+"&days="+days+"&num="+nm;
	}
	
	
	function showDetails(a,b,c) {
		document.location.href="details.php?avToken="+a+"&tCode="+b+"&tName="+c;
	}
	
	function DoOnLoad(){
		window.focus();
		if(typeof(roomChanged)!="undefined")roomChanged(12)
	}
	function MM_openBrWindow(theURL,winName,features){
	  window.open(theURL,winName,features);
	  window.focus();
	}
	
	function showImage(theURL){
		var p_image=document.getElementById("PIMAGE");
		p_image.src=theURL;
	}
	
	
	function showChildren(value){
	
	switch(value) {
			case '1':
				document.getElementById("child01").style.display="block";
				document.getElementById("child02").style.display="none";
				document.getElementById("child03").style.display="none";
				document.getElementById("child04").style.display="none";
				document.getElementById("child05").style.display="none";
				break;
			case '2':
				document.getElementById("child01").style.display="block";
				document.getElementById("child02").style.display="block";
				document.getElementById("child03").style.display="none";
				document.getElementById("child04").style.display="none";
				document.getElementById("child05").style.display="none";
				break;
			case '3':
				document.getElementById("child01").style.display="block";
				document.getElementById("child02").style.display="block";
				document.getElementById("child03").style.display="block";
				document.getElementById("child04").style.display="none";
				document.getElementById("child05").style.display="none";
				break;
			case '4':
				document.getElementById("child01").style.display="block";
				document.getElementById("child02").style.display="block";
				document.getElementById("child03").style.display="block";
				document.getElementById("child04").style.display="block";
				document.getElementById("child05").style.display="none";
				break;
			case '5':
				document.getElementById("child01").style.display="block";
				document.getElementById("child02").style.display="block";
				document.getElementById("child03").style.display="block";
				document.getElementById("child04").style.display="block";
				document.getElementById("child05").style.display="block";
				break;
			default :
				document.getElementById("child01").style.display="none";
				document.getElementById("child02").style.display="none";
				document.getElementById("child03").style.display="none";
				document.getElementById("child04").style.display="none";
				document.getElementById("child05").style.display="none";
		}
	}
	
	function buttonStatus(status){
		var r=MM_findObj('confirmationButton')
		r.disabled=(status==false)
	}
	
	
	
	function changeDuration(valor,num) {
		var y_in=valor.substring(0,4);
		var m_in=valor.substring(4,6);
		var d_in=valor.substring(6);	
		var d_out=document.getElementById("day_out").value;
		var m_out=document.getElementById("month_out").value;
		var y_out=document.getElementById("year_out").value;
		var days_sel=document.getElementById("days_"+num);
	
		var date_in=new Date();
		date_in.setDate(d_in);
		date_in.setMonth(m_in);
		date_in.setFullYear(y_in);
		
		var date_out=new Date();
		date_out.setDate(d_out);
		date_out.setMonth(m_out);
		date_out.setFullYear(y_out);
		
		var one_day=1000*60*60*24;
		var dist=Math.ceil((date_out.getTime()-date_in.getTime())/(one_day));
		
		if(days_sel.options.length>1) {  // Si nomes hi ha un dia que ja no faci res més.
			days_sel.options.length = 0;
			var contador= 0;
			for (var i = 0; i <= dist; i++) {
				days_sel.options[contador] = new Option((i+1),(i+1));
				contador ++;
			}	
		}	
	}

	function changeDays(num,val) {
		var valor=document.getElementById("cfrm_date_"+num).value;
		var days_to=document.getElementById("cto_date_"+num).value;	
		var y_in=valor.substring(0,4);
		var m_in=valor.substring(4,6);
		var d_in=valor.substring(6);	
	
		var date_in=new Date();
		date_in.setFullYear(y_in);
		date_in.setMonth(m_in);
		date_in.setDate((d_in*1));
		
		var n_date=new Date(date_in.getTime() + (val*1)*24*60*60*1000);	
		
		days_to=n_date.getFullYear()+""+(n_date.getMonth()<9?"0"+n_date.getMonth():n_date.getMonth())+""+(n_date.getDate()<9?"0"+n_date.getDate():n_date.getDate());
	
	}

	function changeLanguage(lang) {
		document.getElementById("language").value=lang;
		document.forms["ft_search"].submit();
	}

	function clearOption() {
		selectObject = document.getElementById("destinationCode");

		for (var i=selectObject.options.length-1; i>=0; i--){
		  selectObject.options[i] = null;
		}
	    selectObject.options.selectedIndex = -1;
	}

	function addOption(optionText,optionValue) {
		selectObject = document.getElementById("destinationCode"); 
	    var optionObject = new Option(optionText,optionValue);
	    var optionRank = selectObject.options.length;
	    selectObject.options[optionRank]=optionObject;
	}

	function changeCountry () {
		xCountry = document.getElementById ("countryCode");
		document.getElementById("submiter").src="js-destinations.php?country="+xCountry[xCountry.selectedIndex].value+"&s="+Math.random(100000);		
	}
