// JavaScript Document
var CLANG;
var locPath;
//
// INSERTA ANIMACIÓN INTRO
function writeActiveX(flash,w,h){
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+w+'" height="'+h+'" id="loader" align="middle">'+
'<param name="allowScriptAccess" value="sameDomain" />'+
'<param name="movie" value="'+flash+'" />'+
'<param name=scale value=noscale />'+
'<param name="quality" value="high" />'+
'<param name="bgcolor" value="#000000" />'+
'<embed src="'+flash+'" quality="high" bgcolor="#000000" scale="noscale" width="'+w+'" height="'+h+'" name="loader" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
'</object>');
}
// INSERTA EL MENU FLASH
function writeMenu(flash,w,h,lang,cSectionId){
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+w+'" height="'+h+'" id="loader" align="middle">'+
'<param name="allowScriptAccess" value="sameDomain" />'+
'<param name="movie" value="'+flash+'?lang='+lang+'&cSectionId='+cSectionId+'" />'+
'<param name=scale value=noscale />'+
'<param name="quality" value="high" />'+
'<param name="wmode" value="transparent" />'+
'<embed src="'+flash+'?lang='+lang+'&cSectionId='+cSectionId+'" quality="high" wmode="transparent" scale="noscale" width="'+w+'" height="'+h+'" name="loader" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
'</object>');
}
// INSERTA LA GALERIA FLASH
function writeGallery(flash,w,h){
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="'+w+'" height="'+h+'" id="loader" align="middle">'+
'<param name="allowScriptAccess" value="sameDomain" />'+
'<param name="movie" value="'+flash+'" />'+
'<param name=scale value=noscale />'+
'<param name="quality" value="high" />'+
'<param name="wmode" value="transparent" />'+
'<embed src="'+flash+'" quality="high" wmode="transparent" scale="noscale" width="'+w+'" height="'+h+'" name="loader" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
'</object>');
}
// PONE EMAILS
function ponMail(n,d){
document.write("<a href='mailto:"+n+"@"+d+"'>"+n+"@"+d+"</a>");
}
// VARIABLES DE ENTORNO
function initEnvironment(){
locPath = document.location.href.split("?lang=")[0];
var locLang = document.location.href.split("?lang=")[1];
CLANG = (locLang == undefined)?window.location.replace(locPath+"?lang=ES"):locLang;
//alert(CLANG);
}
// GESTIONA LOS GETURL DENTRO DEL SITE
function loadUrl(url,language){
if(language != undefined && language != null && language != ""){
	window.location.assign(url+"?lang="+language);
	}else{
	window.location.assign(url+"?lang="+CLANG);
	}
}

initEnvironment();

//***********************************************

// SOCKET CON AJAX

var xmlobject;
var cSection;

function loadXML(currentSection){
var ajax = new Ajax.Request('data'+CLANG+'.xml?rnd='+Math.random() ,{ parameters:CLANG ,method: 'get', onComplete: checkDOM	});
cSection = currentSection;
}

function checkDOM(resp){
	// ALMACENAMOS RESP EN UNA VAR
	var xmlstring = resp.responseText;	
	var xmlobject = resp.responseXML;
	//alert(xmlstring);
	procesaRespuesta(xmlobject);	
}
function procesaRespuesta(xmlobject){
// get the XML root item
/*alert(xmlobject);
alert(xmlobject.getElementsByTagName('sections')[0]);
alert(xmlobject.getElementsByTagName('sections')[0].getElementsByTagName("section")[0].getElementsByTagName("mainText")[0].firstChild.nodeValue);*/
var root = xmlobject.getElementsByTagName("sections")[0];
var section = root.getElementsByTagName("section");
var footerT = root.getElementsByTagName("pie")[0].getElementsByTagName("mainText")[0].firstChild.nodeValue;
var footerTPhone = root.getElementsByTagName("pie")[0].getElementsByTagName("firstSmallText")[0].firstChild.nodeValue;
var mainT = "";
var firstT = "";
var secondT = "";
//alert(section.length);
for(i=0;i<section.length;i++){
//alert(section[i].getAttribute("id"));
if(section[i].getAttribute("id") == cSection){
	mainT = (section[i].getElementsByTagName("mainText")[0].firstChild.nodeValue == null)?"":section[i].getElementsByTagName("mainText")[0].firstChild.nodeValue;
	firstT = section[i].getElementsByTagName("firstSmallText")[0].firstChild.nodeValue;
	secondT = section[i].getElementsByTagName("secondSmallText")[0].firstChild.nodeValue;
	if(cSection == 'reservas'){
		formArray = section[i].getElementsByTagName("formFields")[0].firstChild.nodeValue.split("||");
		//alert(formArray.length);
			$('fNom').innerHTML = formArray[0];
			$('fMail').innerHTML = formArray[1];
			$('fTel').innerHTML = formArray[2];
			$('fPer').innerHTML = formArray[3];
			$('fCom').innerHTML = formArray[4];
			$('fDate').innerHTML = formArray[5];
			document.reserva.send.value = formArray[6];
			/*$('fError').innerHTML = formArray[7];
			$('fOk').innerHTML = formArray[8];*/			
		}
	}
}
//
$('MainText').innerHTML = (mainT == undefined || mainT == "")?"":mainT;
$('firstSmallText').innerHTML = (firstT == undefined || firstT == "")?"":firstT;
$('secondSmallText').innerHTML = (secondT == undefined || secondT == "")?"":secondT;
$('footer').innerHTML = (footerT == undefined || footerT == "")?"":footerT;
$('footerPhone').innerHTML = (footerTPhone == undefined || footerTPhone == "")?"":footerTPhone;
//
}

// GESTIONS FORMULARIO DE ENVIO

var submits=0;
function submitView(form){
	if (submits == 0) {		
		submits++;
		 form.action = "sendmail.php";
		form.submit();
 	} else {
  		window.setTimeout("submits=0",2000);
 	}
	return false;
}

//

function languageChooser(lang){
//	document.write("<p><a href='"+locPath+"?lang=CA'>catal&agrave;</a> | <a href='"+locPath+"?lang=ES'>espa&ntilde;ol</a> | <a href='"+locPath+"?lang=EN'>english</a></p><br />");
	document.write("<p><a href='"+locPath+"?lang=ES'>espa&ntilde;ol</a> | <a href='"+locPath+"?lang=EN'>english</a></p><br />");
	}