var contaCurso=0;
var listaCursos = new Array();
var AlojaStart = 0;
var AlojaEnd = 0;
var AlojaStartFormato = "";
var AlojaEndFormato = "";
var FinalPrice=0;
var AlojaPrice=0;

function arreglaAloja(a)
{
	document.getElementById('bloqueaccom').style.display='none';
	toreturn=false;

//	alert(escid);

if (a!="no")
	{
		FinalPrice=TotalPrice+AlojaPrice;
		document.getElementById('preciototal').innerHTML=FinalPrice;
		toreturn=true;
		document.getElementById('bloqueaccom').style.display='';
		document.getElementById('price_aloja').value=AlojaPrice;
		if (AlojaPrice>0)
			document.getElementById('show_price_aloja').innerHTML=AlojaPrice;
		else
			document.getElementById('show_price_aloja').innerHTML='';
	
	}
	else
	{
		FinalPrice=TotalPrice;
		document.getElementById('preciototal').innerHTML=FinalPrice;
		document.getElementById('price_aloja').value=AlojaPrice=0;
		document.getElementById('show_price_aloja').innerHTML='Not needed';
	}	
	return toreturn;
}


function pick()
{
	FinalPrice=TotalPrice+AlojaPrice;
	document.getElementById('preciototal').innerHTML=FinalPrice;
}




function DelyAddCourse()
{
	
	// Delete de courses
	listaCursos=Array();
	elDiv=document.getElementById('selectedcourses');
	elDiv.innerHTML='';

	// Add active course

	idCurso = document.getElementById('curso')[document.getElementById('curso').selectedIndex].value;
	nombreCurso = document.getElementById('curso')[document.getElementById('curso').selectedIndex].innerHTML;
	fechaCurso = document.getElementById('auto_datestart')[document.getElementById('auto_datestart').selectedIndex].innerHTML;
	valuefechaCurso = document.getElementById('auto_datestart')[document.getElementById('auto_datestart').selectedIndex].value;
	duraCurso = document.getElementById('duracion')[document.getElementById('duracion').selectedIndex].innerHTML;
	valueduraCurso = document.getElementById('duracion')[document.getElementById('duracion').selectedIndex].value;
	precio=parseInt(document.getElementById('precioreal').value);
	datestart=document.getElementById('datestart').value
	dateend=document.getElementById('dateend').value
	escid=document.getElementById('escid').value

	TotalPrice=precio;

	di=document.createElement("div");

	inp=document.createElement("input");
	inp.setAttribute("name","curso[]");
	inp.setAttribute("type","hidden");
	inp.setAttribute("value",idCurso);
	di.appendChild(inp);
	inp=document.createElement("input");
	inp.setAttribute("name","nombreCurso[]");
	inp.setAttribute("type","hidden");
	inp.setAttribute("value",nombreCurso);
	di.appendChild(inp);
	inp=document.createElement("input");
	inp.setAttribute("name","precio[]");
	inp.setAttribute("type","hidden");
	inp.setAttribute("value",precio);
	di.appendChild(inp);
	inp=document.createElement("input");
	inp.setAttribute("name","datestart[]");
	inp.setAttribute("datestart","1");
	inp.setAttribute("type","hidden");
	inp.setAttribute("value",datestart);
	di.appendChild(inp);
	inp=document.createElement("input");
	inp.setAttribute("name","dateend[]");
	inp.setAttribute("dateend","1");
	inp.setAttribute("type","hidden");
	inp.setAttribute("value",dateend);
	di.appendChild(inp);
	inp=document.createElement("input");
	inp.setAttribute("name","duracion[]");
	inp.setAttribute("type","hidden");
	inp.setAttribute("value",valueduraCurso);
	di.appendChild(inp);
	inp=document.createElement("input");
	inp.setAttribute("name","duracionTXT[]");
	inp.setAttribute("type","hidden");
	inp.setAttribute("value",duraCurso);
	di.appendChild(inp);
	elDiv.appendChild(di);
	
	sacaStartEnd(); //Calcula la fecha de entrada y salida para el alojamiento.
	checkAloja(document.getElementById('accommodation').options[document.getElementById('accommodation').selectedIndex].value);


}

var TotalPrice=0;
var escid;
var cursocerrado;
function autodatestart()
{
	
if (document.getElementById('auto_datestart').options.length > 0) 
{  } 
else {return;}
document.getElementById('datestart').value=document.getElementById('auto_datestart')[document.getElementById('auto_datestart').selectedIndex].innerHTML; 
end=document.getElementById('auto_datestart')[document.getElementById('auto_datestart').selectedIndex].value;
if (end!='no'){
 document.getElementById('dateend').value=end; 
 document.getElementById('duradiv').style.display='none';
 document.getElementById('duradiv2').style.display='none';
 cursocerrado=1;
}else{
document.getElementById('duradiv').style.display='block';
document.getElementById('duradiv2').style.display='block';
cursocerrado=0;
}

}			

function actualizaAjax(desde,hasta){xloadXMLDoc(desde,hasta);}

var sem;
var dias;
function calculaWeeks()
{

	if (cursocerrado==1)
	{
		dias = days_between(document.getElementById('datestart').value,document.getElementById('dateend').value);
		

	}
	else
	{
		cantidad=MM_findObj('cantidad').value;
		cantidad_extra=MM_findObj('cantidad_extra').value;
		numero=MM_findObj('numero').value;
		numero_extra=MM_findObj('numero_extra').value;
			cantidad=parseInt(cantidad);
			numero= parseInt(numero);	
			cantidad_extra= parseInt(cantidad_extra);
			numero_extra= parseInt(numero_extra);

		if (isNaN(cantidad) && isNaN(cantidad_extra))
		{
			dias=0;
		}
		else if (isNaN(cantidad))
		{
			dias=0;
		}
		else if (isNaN(cantidad_extra))
		{
			dias=cantidad*numero;
		}
		else
		{
			dias=(cantidad*numero)+(cantidad_extra*numero_extra);
		}
		mirafecha();
	}
		sem = Math.round(dias/7);
		if ((dias%7) > 0) sem++;
		document.getElementById('nrosemanas').value=sem;
		document.getElementById('dias').value=dias;
}


function sacaStartEnd()
{
	AlojaStart=0;
	AlojaEnd=0;
		elDiv=document.getElementById('selectedcourses');
		fechas=elDiv.getElementsByTagName('input');
		if (fechas.length > 0)
		{
		for (x=0;x<fechas.length;x++)
		{
			if (fechas[x].getAttribute('datestart')=="1")
			{
			start = fechas[x].value.split(' - ');
			fecha1 = start[0].split('/');
			
			if (fecha1[0].substr(0,1)=="0" || fecha1[0].substr(0,1)==0) { fecha1[0]=fecha1[0].substr(1); }
			if (fecha1[1].substr(0,1)=="0" || fecha1[1].substr(0,1)==0) { fecha1[1]=fecha1[1].substr(1); }
			
			date1 = new Date(fecha1[2],parseInt(fecha1[1])-1,fecha1[0]) ;
			date1.setDate(date1.getDate() - 1);
				if (AlojaStart > date1.getTime() || AlojaStart==0)
				{
				AlojaStart=date1.getTime();
				dia=date1.getDate();
				mes=(date1.getMonth()+1);
				dia=dia+'';
				if (dia.length=="1") dia="0"+dia;
				mes=mes+'';
				if (mes.length=="1") mes="0"+mes;
				AlojaStartFormato=dia+'/'+mes+'/'+date1.getFullYear();
				}
			}
			
			if (fechas[x].getAttribute('dateend')=="1")
			{
			fecha2 = fechas[x].value.split('/');

			if (fecha2[0].substr(0,1)=="0") fecha2[0]=fecha2[0].substr(1);
			if (fecha2[1].substr(0,1)=="0") fecha2[1]=fecha2[1].substr(1);

			date2 = new Date(fecha2[2],parseInt(fecha2[1])-1,fecha2[0]) ;
			
			// Extract weekend
			diasem=date2.getDay();
			switch(diasem)
			{
			case 0: // domingo
				date2.setDate(date2.getDate() - 2 );
			break;
			case 1:
				date2.setDate(date2.getDate() - 3 );
			break;
			case 6:
				date2.setDate(date2.getDate() - 1 );
			break;
			}
			
			date2.setDate(date2.getDate() + 1);
				
				if (AlojaEnd < date2.getTime() || AlojaEnd==0)
				{
				AlojaEnd=date2.getTime();
				dia=date2.getDate();
				mes=(date2.getMonth()+1);
				dia=dia+'';
				if (dia.length=="1") dia="0"+dia;
				mes=mes+'';
				if (mes.length=="1") mes="0"+mes;
				AlojaEndFormato=dia+'/'+mes+'/'+date2.getFullYear();
				}
			}
		}
		}
}


function days_between(date1, date2) {
    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24
    fecha1 = date1.split('/');
    fecha2 = date2.split('/');
date1 = new Date(fecha1[2],fecha1[1],fecha1[0]) ;
date2 = new Date(fecha2[2],fecha2[1],fecha2[0]) ;

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)
    
    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY)
}

function mirafecha()
{
caja=document.getElementById('datestart').value;
   if (caja)
   {  
      borrar = caja;
      if ((caja.substr(2,1) == "/") && (caja.substr(5,1) == "/"))
      {      
         for (i=0; i<10; i++)
	     {	
            if (((caja.substr(i,1)<"0") || (caja.substr(i,1)>"9")) && (i != 2) && (i != 5))
			{
               borrar = '';
               break;  
			}  
         }
	     if (borrar)
	     { 
	      a = caja.substr(6,4);
		    m = caja.substr(3,2);
		    d = caja.substr(0,2);
		    if((a < 1900) || (a > 2050) || (m < 1) || (m > 12) || (d < 1) || (d > 31))
		       borrar = '';
		    else
		    {
		     if((a%4 != 0) && (m == 2) && (d > 28))	   
		          borrar = ''; // Año no viciesto y es febrero y el dia es mayor a 28
			   else	
			   {
		          if ((((m == 4) || (m == 6) || (m == 9) || (m==11)) && (d>30)) || ((m==2) && (d>29)))
			         borrar = '';	      				  	 
			   }  // else
		    } // fin else
       } // if (error)
      } // if ((caja.substr(2,1) == "/") && (caja.substr(5,1) == "/"))			    			
	  else
	     borrar = '';

	  if (borrar == '')
	     {
	     }
	     else
	     {
		     if (cursocerrado==1)
		     {
		     
		     }
		     else
		     {
			     
			     s=document.getElementById('datestart').value;
			     s_tmp=s.split("/");
			     
			     ini=new Date(
			     parseInt(s_tmp[2]),
			     parseInt((s_tmp[1].substr(0,1)=="0"?s_tmp[1].substr(1,1):s_tmp[1].substr(0,2)))-1,
			     parseInt((s_tmp[0].substr(0,1)=="0"?s_tmp[0].substr(1,1):s_tmp[0].substr(0,2)))
			     );
			     diacomienzo=ini.getDay();
						diames=ini.getDate();
			     ini.setDate(ini.getDate()+dias);

			     if (ini.getDay()==diacomienzo) ini.setDate(ini.getDate()-1);
			     if (ini.getDay()==1){
			     	ini.setDate(ini.getDate()-3);
			     }
			     else if (ini.getDay()==0)
			     {
			     	ini.setDate(ini.getDate()-2);
			     }
					 else if (ini.getDay()==6)
					 {
					 	ini.setDate(ini.getDate()-1);
					 }
			
			     mes = new String (ini.getMonth()+1);
			     dia = new String (ini.getDate());
			     cero=otrocero='';
			     if (mes.length == 1) cero='0';
			     if (dia.length == 1) otrocero='0';
			     fin = otrocero+dia+'/'+cero+mes+'/'+ini.getFullYear();
			     document.getElementById('dateend').value=fin;
		     }
	     }
   } // if (caja)   
}
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;
}
var preciobase;

function pReqChange() {
    if (req.readyState == 4) {
        if (req.status == 200) {
			if (req.responseText.indexOf('invalid') == -1) {
				var xmld = req.responseXML;
				var xmld2= xmld.getElementsByTagName('opciones');

if (campo=='auto_datestart')
{
	document.getElementById('escid').value=parseInt(xmld2[0].getAttribute("escid"));
}
//alert(campo + );
if (campo=='duracion')
{
	document.getElementById('moneda').value=xmld2[0].getAttribute("moneda");
document.getElementById('monedaA').innerHTML=xmld2[0].getAttribute("moneda");
document.getElementById('monedaB').innerHTML=xmld2[0].getAttribute("moneda");
}


if (campo=='precio')
{
	
	document.getElementById('cantidad').value=parseInt(xmld2[0].getAttribute("cantidad"));
	document.getElementById('cantidad_extra').value=parseInt(xmld2[0].getAttribute("cantidad_extra"));
	
	document.getElementById('numero').value=xmld2[0].getAttribute("numero");
	document.getElementById('numero_extra').value=xmld2[0].getAttribute("numero_extra");

//	con_aloja=xmld2[0].getAttribute("con_aloja");
//	fuerzaAloja(con_aloja); // Curso < 4 semanas aloja obligado
		


autodatestart();

	document.getElementById('duracionextra_txt').innerHTML=xmld2[0].getAttribute("duracion_hand_txt");

	preciobase= xmld2[0].childNodes[0].getAttribute("idval");
	preciobase=parseInt(preciobase);
	if (preciobase>0)
	{
	document.getElementById('precioreal').value=preciobase;
	document.getElementById('precioreal_txt').innerHTML='';
	}
	else
	{
		document.getElementById('precioreal_txt').innerHTML='<br />Missing data or <br />Registration needed for quotation';
		document.getElementById('precioreal').value=0;
		document.getElementById(clave+"_img").src = document.getElementById("spacer_img").src; 
		return;
	}
	

	precioextra=parseInt(xmld2[0].getAttribute("precioextra"));
	if (precioextra > 0)
	{
	 document.getElementById('precioreal').value=preciobase+precioextra;
	}

calculaWeeks();

pick();
}

if (campo=='pricealoja')
{

	
	//AlojaPrice
	preciobase_aloja= xmld2[0].childNodes[0].getAttribute("idval");
	preciobase_aloja=parseInt(preciobase_aloja);
	
	if (preciobase_aloja>0)
	{
		AlojaPrice=preciobase_aloja;
	document.getElementById('price_aloja').value=preciobase_aloja;
	document.getElementById('show_price_aloja').innerHTML=preciobase_aloja;
	document.getElementById('monedaC').innerHTML=xmld2[0].getAttribute("moneda");


	}
	else 
	{
		AlojaPrice=0;
		document.getElementById('price_aloja').value="0";
		document.getElementById('show_price_aloja').innerHTML='Registration needed for quotation<br />';
		document.getElementById('monedaC').innerHTML='';
	}
	

pick();
}

				if(campo!='precio' && campo!='pricealoja' && campo!='none')
				{
				var cim = MM_findObj(campo);
				var prm =  MM_findObj(clave);
				var v1,v2=0;var i = 0;
				var j = cim.options.length;
				for (i=0;i<j;i++){cim.options[cim.options.length -1]= null;}
				for (j=0;j<xmld2[0].childNodes.length;j++) 
				  {
				  v1 = Base64.decode(xmld2[0].childNodes[j].firstChild.nodeValue);
				   v2 = xmld2[0].childNodes[j].getAttribute("idval");
				   cim.options[j] = new Option(v1,v2);
				   }
				   		   	cim.disabled=false;
		   	}
		   	
		   	 
	 			document.getElementById(clave+"_img").src = document.getElementById("spacer_img").src; 
				if (campo=='precio') DelyAddCourse();
				else if (siguiente!='none'){xloadXMLDoc(campo,siguiente);}
					
				if (campo=='accommodation') checkAloja(document.getElementById('accommodation').options[document.getElementById('accommodation').selectedIndex].value);
				
		  } else {
            alert("There was a problem retrieving the XML data:" + req.statusText);
        } 
     }
 	}
}

var req;
var siguiente,url,clave,campo,valueClave=null;

function xloadXMLDoc(arg1,arg2) {
	clave=arg1;
	campo=arg2;
	//alert(clave);
	if (clave!='precio' && clave!='precioaloja') valueClave = '&valor='+escape(MM_findObj(clave).value);
	switch(campo)
	{
/*	case 'ciudad':
		siguiente='escuela';
		valueClave = '&valor[]='+escape(MM_findObj(clave).value);
	break;
	case 'escuela':
		siguiente='curso';
		valueClave = '&valor[]='+escape(MM_findObj('pais').value)+'&valor[]='+escape(MM_findObj('ciudad').value);
	break;
	case 'curso':
		siguiente='auto_datestart';
		valueClave = '&valor[]='+escape(MM_findObj('pais').value)+'&valor[]='+escape(MM_findObj('ciudad').value)+'&valor[]='+escape(MM_findObj('escuela').value);
	break;*/
	case 'auto_datestart':
		siguiente='duracion';
		valueClave = '&valor='+escape(MM_findObj('curso').value);
	break;
	case 'duracion':
		siguiente='precio';
		valueClave = '&valor[]='+escape(MM_findObj('curso').value)+'&valor[]='+escape(document.getElementById('auto_datestart')[document.getElementById('auto_datestart').selectedIndex].innerHTML);
	break;
	case 'precio':
	if (AlojaStart>0 && AlojaEnd>0 && document.getElementById('accommodation').options[document.getElementById('accommodation').selectedIndex].value!='no')
	{
		siguiente='accommodation';
	}
	else
	{
		siguiente='none';
	}
	break;
	case 'accommodation':
	if (document.getElementById('accommodation').options[document.getElementById('accommodation').selectedIndex].value=='no')
		siguiente='none';
	else
		siguiente='tipoaloja';

	break;
	case 'tipoaloja':
	if (document.getElementById('accommodation').options[document.getElementById('accommodation').selectedIndex].value=='no')
		siguiente='none';
	else
	{
			siguiente='tipohabita';
			// para accommodation
	}
			valueClave = '&valor[]='+escape(MM_findObj(clave).value)+'&valor[]='+escape(MM_findObj('curso').value); 
	break;
	case 'tipohabita':
	muestraMensajeAloja(document.getElementById('tipoaloja').options[document.getElementById('tipoaloja').selectedIndex].value);
	
	if (document.getElementById('accommodation').options[document.getElementById('accommodation').selectedIndex].value=='no')
		siguiente='none';
	else
	{
		siguiente='tipopension';
	}
		valueClave = '&valor[]='+escape(MM_findObj(clave).value)+'&valor[]='+escape(MM_findObj('curso').value);
	break;
	case 'tipopension':
	if (document.getElementById('accommodation').options[document.getElementById('accommodation').selectedIndex].value=='no')
		siguiente='none';
	else
		siguiente='pricealoja';

		valueClave = '&valor[]='+escape(MM_findObj(clave).value)+'&valor[]='+escape(MM_findObj('tipoaloja').value)+'&valor[]='+escape(MM_findObj('curso').value);
	break;
	case 'pricealoja':
	if (document.getElementById('accommodation').options[document.getElementById('accommodation').selectedIndex].value=='no')
	return;
	
			valueClave = '&valor[]='+escape(MM_findObj(clave).value)+'&valor[]='+escape(MM_findObj('tipohabita').value)+'&valor[]='+escape(MM_findObj('tipoaloja').value)+'&valor[]='+escape(MM_findObj('accommodation').value)+'&valor[]='+escape(AlojaStartFormato)+'&valor[]='+escape(AlojaEndFormato)+'&valor[]='+escape(MM_findObj('curso').value);
	//
	//
		siguiente='none';
	break;	
	default:
		siguiente='none';
	}

	aleatorio=Math.round(Math.random()*1000);
	url = "/getValue_v2.php?rnd="+aleatorio+"&type=" + escape(clave)+valueClave;

	if (campo!='none' && campo!='precio' && campo!='pricealoja'  && campo!='tipopension')
	{
	 MM_findObj(campo).disabled=true;
	 }
	MM_findObj(clave + '_img').src = MM_findObj('cargando_img').src;
	
    if (window.XMLHttpRequest) {//XMLHttpRequest
        req = new XMLHttpRequest();
        req.onreadystatechange = pReqChange;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {//IE/Windows
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = pReqChange;
            req.open("GET", url, true);
            req.send();
        	}
		}
}


function muestraMensajeAloja(valor)
{
	switch(valor)
	{
		case "4":
//			mensa="Price includes: rent for the whole stay (but not utilities if you  stay 4 weeks or more)";
			mensa="Price includes: rent for the whole stay but not utilities";
		break;
		case "2":
			mensa="Price includes: Our fee + 100eur that we will pay to the owners to book your room and they should deduct later in the first month's rent.";
		break;

		case "no":
		default:
			mensa="";
		break;
		
	}
	document.getElementById('mensaje_pricealoja').innerHTML='<br />'+mensa;
}
/*
function fuerzaAloja(fuerza) // Curso < 4 semanas aloja obligado
{
	acco=document.getElementById('Accommodation');
	//document.getElementById('Accommodation')[document.getElementById('Accommodation').selectedIndex].value
	if (fuerza=='1')
	{
		// disable select
		// select accommodation
    acco.options[0].selected = true;
    acco.disabled='disabled';
	}
	else
	{
    acco.disabled='';
	}
	
}
*/

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function checkAloja(a)
{
if (arreglaAloja(a))
{
	if (a!="no" && AlojaStartFormato!='' && AlojaEndFormato!='')
	{
		document.getElementById('bloqaloja').style.display='';
		actualizaAjax('accommodation','tipoaloja');
		document.getElementById('fechas_aloja').innerHTML='From '+AlojaStartFormato+' to '+AlojaEndFormato+'';
		document.getElementById('aloja_end').value=AlojaEndFormato;
		document.getElementById('aloja_start').value=AlojaStartFormato;
	}
	else
	{
		document.getElementById('bloqaloja').style.display='none';	
		//		actualizaAjax('none','none');
	
		FinalPrice=TotalPrice;
		document.getElementById('preciototal').innerHTML=FinalPrice;
		document.getElementById('price_aloja').value=AlojaPrice=0;
		document.getElementById('show_price_aloja').innerHTML='';

	}
}
	
}

