//// funciones de reposicionamiento de la capa
//var Doc = new Document();
var imgDetail = null;
function getRealLeft(objeto)
{	if ((NS4) || (NS6)) { xPos = objeto.x; } else { xPos = objeto.offsetLeft; tempEl = objeto.offsetParent; while (tempEl != null) { xPos += tempEl.offsetLeft; tempEl = tempEl.offsetParent; }}
	return xPos;
}
function getRealTop(objeto)
{	if ((NS4) || (NS6)) { yPos = objeto.y; } else { yPos = objeto.offsetTop; tempEl = objeto.offsetParent; while (tempEl != null) { yPos += tempEl.offsetTop; tempEl = tempEl.offsetParent; }}
	return yPos;
}
function openWin(URL,target,ancho,alto,left,top,scroll)
{	var wWidth = "width="+ ancho;
	var hHeight = ",height="+ alto;
	var lLeft = ",left="+ left;
	var tTop = ",top="+ top;
	var parameters = wWidth + hHeight + lLeft + tTop;
	if (scroll) { parameters += ",scrollbars=yes"; }	
	var newWindow = window.open (URL,target,parameters);
	newWindow.focus();
}
//// funcion reposicionamiento de tablas MODO EDICION
var swEdita = 0;
function modoEditar()
{	var cEdita = "lEdita";
	if (swEdita)
	{	var lEdita = "lEdita";
		var posImagen = document.images["edita"];
		var MiX=getRealLeft(posImagen);
		var MiY=getRealTop(posImagen);
		Doc.all.item(lEdita).moveTo(MiX,MiY);
		//// alert(Doc.all.item(lEdita).style.left);
	}
}

/////////// Funciones detectar el raton
var languageNavShow = 0;
var controlJsOnload = 0;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = posicRatonXY;
document.onkeypress = keyhandler;
	
var posicX = 0;
var posicY = 0;
var salgoX = 0;
var salgoY = 0;
	
var inicioY=60;
var RatonYStart;
var RatonYFinish;
var hLayer = 0;

function keyhandler(e)
{	if(IE)	{	Key = event.keyCode }
	else if (NS6)
	{	Key = e.which; }
	if (Key == 13) { return false;}
}
	
function posicRatonXY(e)
{	if(IE)
	{	posicX = event.clientX;
		posicY = event.clientY;
	}
	else if(NS6)
		{	posicX = e.pageX;
			posicY = e.pageY;
		}
	if(languageNavShow==1)
	{	RatonYStart = MiYH - 66;
		if (IE)	{ hLayer = document.all.item('lBanderas').clientHeight; }		///Explorer+
		else { hLayer = document.getElementById('lBanderas').offsetHeight; }	///Netscape 6+
		RatonYFinish = RatonYStart + 14 + hLayer;
		if( (posicX<513) || (posicX>611)){salgoX = 1;}
		if( (posicY<RatonYStart)  || (posicY>RatonYFinish)){salgoY = 1;}
		
		if((salgoX==1)||(salgoY==1))
		{	document.getElementById("lBanderas").style.visibility="hidden";
			languageNavShow=0;
			posicX = 0; posicY = 0;
			salgoX = 0; salgoY = 0;
		}
	}
	return true;					
}

// Esta función se utiliza para cambiar solamente de idioma y que se quede en el mismo posting
function languageNav(ps_Lang){
	var s_current_URL=window.location.href;
	var regExp=/language=[a-z]*/i;
	
	s_current_URL=s_current_URL.toLowerCase();
	
	if ((s_current_URL.match("/french/")!= null))
	{

	    s_current_URL=s_current_URL.replace(/french/,"english");	    
	    s_current_URL=s_current_URL.replace(/regfr/,"regeng");

        	      	    
	
	}
	else if ((s_current_URL.match("/english/") != null))
	{ 
	    s_current_URL=s_current_URL.replace(/english/,"french");
	    s_current_URL=s_current_URL.replace(/regeng/,"regfr");	    
	  
	}

 
	//si contiene el parámetro de lenguage lo cambia
	if(s_current_URL.match(regExp))
	{
		window.location.href = s_current_URL.replace(regExp,"language="+ps_Lang.toLowerCase())
	}
	else
	{
	    //si no lo añade dependiendo de si hay o no otros parámetros
		window.location.href = s_current_URL+((s_current_URL.indexOf("?")>0)?"&":"?")+"language="+ps_Lang.toLowerCase();
	}
}

//// Reposicionamiento de las capas del iconos e idiomas
var posHeader=null;
var MiXH; var MiYH;
function inicio()
{	//// Reposiciona la capa de los idiomas
	var lCapa="lBanderas";
	posHeader = document.images["header"];//aqui se buscaria el nombre del KeyPath, imagen cabecera
	if (posHeader!=null)
	{	MiXH=getRealLeft(posHeader);
		MiYH=getRealTop(posHeader);
		Doc.all.item(lCapa).style.left = MiXH + 365;
		Doc.all.item(lCapa).style.top = MiYH - 52;
	}
	imgDetail = document.getElementById("imgPhoto");


	if (imgDetail != null)
	{	imgDetail.style.pixelWidth = preload.width; }
	controlJsOnload = 1;
}

var WinX = 0; 
var WinY = 0;
function WinReposition(url)
{	WinX = ( (screen.width/2) - 235);
	WinY = ( (screen.height/2) - 227);
	openWin(url,'PNieve',471,455,WinX,WinY,1);
}

//Funciones referentes a VERSION IMPRIMIBLE
var txtPlace = null;	var tablePlace = "tablePlace";
var txtName = null;		var tableName = "tableName";
var txtHTML = null;		var tableHTML = "tableHTML";
var txtSRHeader = null;	var tableSRHeader = "tableSRHeader";
var tableResult = "resultPrint"; var EditionPlaceHoldersCell = "EditionPlaceHoldersCell";
function printPage()
{	var URL = "/MPTurSpainWeb/Pages/print.html";
	if (document.getElementById(tableSRHeader) != null)
	{	txtSRHeader = document.getElementById(tableSRHeader).innerHTML; }
	if (document.getElementById(tablePlace) != null)
	{	txtPlace = document.getElementById(tablePlace).innerHTML; }
	if (document.getElementById(tableName) != null)
	{	txtName = document.getElementById(tableName).innerHTML; }
	if (document.getElementById(tableResult) != null)
	{	txtHTML = document.getElementById(tableResult).innerHTML; }
	else
	{	
		if (document.getElementById(tableHTML) != null)
		{
			txtHTML = document.getElementById(tableHTML).innerHTML;		
		}
		else
		{
			// Si no existe nada con id = tableHTML es que la página tiene EditionPlaceHorldersCell en su lugar
			txtHTML = document.getElementById(EditionPlaceHoldersCell).innerHTML;
		}
	 }
	openWin(URL,"_blank",600,500,0,0,1);
}

function sendMail(culture)
{	
	var URL = document.location.href;
	openWin('/MPTurSpainWeb/Templates/envio email/Send.aspx?urlpage='+ escape(URL)+'&culture=' +culture,'_blank',315,320,100,200,0);
	
	



}


////funciones buscador Simple
function textSearch(oetChannel)
{	
	var URL = oetChannel + "/Buscador Avanzado/Home.aspx?freeText=";
	var txtSearch = document.getElementById("vBuscar").value;
	if ((txtSearch != AdvSrh) && (txtSearch !=""))
	{
			txtSearch = encodeURIComponentNew(txtSearch);
			URL+=txtSearch;
			document.location.href=URL;	
	}
}

// Utf8 encode

function utf8(wide) {
	var c, s;
	var enc = "";
	var i = 0;
	while(i<wide.length) {
	c= wide.charCodeAt(i++);
	// handle UTF-16 surrogates
	if (c>=0xDC00 && c<0xE000) continue;
	if (c>=0xD800 && c<0xDC00) {
		if (i>=wide.length) continue;
		s= wide.charCodeAt(i++);
		if (s<0xDC00 || c>=0xDE00) continue;
		c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
	}
	// output value
	if (c<0x80) enc += String.fromCharCode(c);
	else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
	else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
	else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
	}
	return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
	return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
	var s = utf8(s);
	var c;
	var enc = "";
	for (var i= 0; i<s.length; i++) {
	if (okURIchars.indexOf(s.charAt(i))==-1)
		enc += "%"+toHex(s.charCodeAt(i));
	else
		enc += s.charAt(i);
	}
	return enc;
}


// fin de utf8 encode

function RObj(ea){var LS="";var QS=new Object();var un="undefined";var f="function";var n="number";var r="string";var e1="ERROR:Index out of range in\r\nRequest.QueryString";var e2="ERROR:Wrong number of arguments or invalid property assignment\r\nRequest.QueryString";var e3="ERROR:Object doesn't support this property or method\r\nRequest.QueryString.Key";function Err(arg){if(ea)alert("Request Object:\r\n"+arg)};function URID(t){var d="";if(t){for(var i=0;i<t.length;++i){var c=t.charAt(i);d+=(c=="+"?" ":c);};};return unescape(d);};function OL(o){var l=0;for(var i in o){if(typeof(o[i])!=f) l++;};return l;};function AK(key){var auk=true;for(var u in QS){if(typeof(QS[u])!=f&&u.toString().toLowerCase()==key.toLowerCase()){auk=false;return u;}};if(auk){QS[key]=new Object();QS[key].toString=function(){return TS(QS[key])};QS[key].Count=function(){return OL(QS[key])};QS[key].Count.toString=function(){return OL(QS[key]).toString()};QS[key].Item=function(e){if(typeof(e)==un) return QS[key];else {if(typeof(e)==n){var a=QS[key][Math.ceil(e)];if(typeof(a)==un) Err(e1+"(\""+key+"\").Item("+e+")");return a;}else Err("ERROR:Expecting numeric input in\r\nRequest.QueryString(\""+key+"\").Item(\""+e+"\")");}};QS[key].Item.toString=function(e){if(typeof(e)==un) return QS[key].toString();else {var a=QS[key][e];if(typeof(a)==un) Err(e1+"(\""+key+"\").Item("+e+")");return a.toString();};};QS[key].Key=function(e){var t=typeof(e);if(t==r){var a=QS[key][e];return(typeof(a)!=un&&a&&a.toString()?e:"");}else Err(e3+"("+(e?e:"")+")");};QS[key].Key.toString=function(){return un};};return key};function AVTK(key,val){if(key!=""){var key=AK(key);var l=OL(QS[key]);QS[key][l+1]=val;}};function TS(o){var s="";for(var i in o){var ty=typeof(o[i]);if(ty=="object") s+=TS(o[i]);else if(ty!=f) s+=o[i]+", ";};var l=s.length;if(l>1)return(s.substring(0,l-2));return(s==""?un:s);};function KM(k,o){var k=k.toLowerCase();for(var u in o){if(typeof(o[u])!=f&&u.toString().toLowerCase()==k) return u;};}if(window.location&&window.location.search){LS=window.location.search;var l=LS.length;if(l>0){LS=LS.substring(1,l);var preAmpAt=0;var ampAt=-1;var eqAt=-1;var k=0;var skip=false;for(var i=0;i<l;++i){var c=LS.charAt(i);if(LS.charAt(preAmpAt)=="="||(preAmpAt==0&&i==0&&c=="=")) skip=true;if(c=="="&&eqAt==-1&&!skip) eqAt=i;if(c=="&"&&ampAt==-1){if(eqAt!=-1) ampAt=i;if(skip) preAmpAt=i+1;skip=false;};if(ampAt>eqAt){AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,ampAt)));preAmpAt=ampAt+1;eqAt=ampAt=-1;++k;};};if(LS.charAt(preAmpAt)!="="&&(preAmpAt!=0||i!=0||c!="=")){if(preAmpAt!=l){if(eqAt!=-1) AVTK(URID(LS.substring(preAmpAt,eqAt)),URID(LS.substring(eqAt+1,l)));else if(preAmpAt!=l-1) AVTK(URID(LS.substring(preAmpAt,l)),"");};if(l==1) AVTK(LS.substring(0,1),"");};};};var TC=OL(QS);if(!TC) TC=0;QS.toString=function(){return LS.toString()};QS.Count=function(){return(TC?TC:0)};QS.Count.toString=function(){return(TC?TC.toString():"0")};QS.Item=function(e){if(typeof(e)==un) return LS;else {if(typeof(e)==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof(QS[i])!=f&&++c==e) return QS[i];};Err(e1+"().Item("+e+")");}else return QS[KM(e,QS)];};return un;};QS.Item.toString=function(){return LS.toString()};QS.Key=function(e){var t=typeof(e);if(t==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof(QS[i])!=f&&++c==e) return i;}}else if(t==r){var e=KM(e,QS);var a=QS[e];return(typeof(a)!=un&&a&&a.toString()?e:"");}else Err(e2+"().Key("+(e?e:"")+")");Err(e1+"().Item("+e+")");};QS.Key.toString=function(){Err(e2+"().Key");};this.QueryString=function(k){if(typeof(k)==un) return QS;else {var k=KM(k,QS);if(typeof(QS[k])==un){t=new Object();t.Count=function(){return 0};t.Count.toString=function(){return "0"};t.toString=function(){return un};t.Item=function(e){return un};t.Item.toString=function(){return un};t.Key=function(e){Err(e3+"("+(e?e:"")+")");};t.Key.toString=function(){return un};return t;}if(typeof(k)==n) return QS.Item(k);else return QS[k];}};this.QueryString.toString=function(){return LS.toString();};this.QueryString.Count=function(){return(TC?TC:0)};this.QueryString.Count.toString=function(){return(TC?TC.toString():"0")};this.QueryString.Item=function(e){if(typeof(e)==un) return LS.toString();else {if(typeof(e)==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof(QS[i])!=f&&++c==e) return QS[i];};Err(e1+".Item("+e+")");}else return QS[KM(e,QS)];}if(typeof(e)==(n)) Err(e1+".Item("+e+")");return un;};this.QueryString.Item.toString=function(){return LS.toString()};this.QueryString.Key=function(e){var t=typeof(e);if(t==n){var e=Math.ceil(e);var c=0;for(var i in QS){if(typeof(QS[i])=="object"&&(++c==e)){return i;}}}else if(t==r){var e=KM(e,QS);var a=QS[e];return(typeof(a)!=un&&a&&a.toString()?e:"");}else Err(e2+".Key("+(e?e:"")+")");Err(e1+".Item("+e+")");};this.QueryString.Key.toString=function(){Err(e2+".Key");};};var Request=new RObj(false);



function ValidateTextSearchHome(search,oetChannel)
{
	document.getElementById("vBuscar").value=search;
	ValidateTextSearch(message,oetChannel);
}

////funcion que valida que al menos introduzca 3 caracteres.
function ValidateTextSearch(message,oetChannel)
{	
	//var URL = "/TourSpain/Buscador Avanzado/Home.aspx?freeText=";
	if (!oetChannel) oetChannel="/TourSpain";
	if(Request.QueryString("language")=="undefined")
	var URL = oetChannel + "/Buscador Avanzado/Home.aspx?language=es&freeText=";
else
	var URL = oetChannel + "/Buscador Avanzado/Home.aspx?language=" + Request.QueryString("language") + "&freeText=";

	var txtSearch = document.getElementById("vBuscar").value;
		
	var cad = "";
	
	if (txtSearch != AdvSrh)
	{	cad = Trim(txtSearch);
		if(cad.length<3)
		{
			alert(message);
		}	
		else
		{	
	
			var valor = cad.match(/(\w)/);
			
			if(valor!=null)
			{
					cad = encodeURIComponentNew(cad);
					URL+=cad;
					document.location.href=URL;
			}
			else
			{
					alert(message);		
			}
		}
		
	}	
}
///Funciones para eliminar los blancos del principio y el final de una cadena.
///************************
function LTrim(text)
{	// Devuelve una cadena sin los espacios del principio
	var i=0;
	var j=0;
// Busca el primer caracter de un espacio
	for(i=0; i<=text.length-1; i++)
		if(text.substring(i,i+1) != ' ')
		{	j=i;
			break;
		}
	return text.substring(j, text.length);
}
function RTrim(text)
{	// Quita los espacios en blanco del final de la cadena
	var j=0;
	
	// Busca el ultimo caracter <> de un espacio
	for(var i=text.length-1; i>-1; i--)
		if(text.substring(i,i+1) != ' ')
		{	j=i;
			break;
		}
	return text.substring(0, j+1);
}
function Trim(text){
	// Quita los espacios del principio y del final
	return LTrim(RTrim(text));
}

/// Funciones para Site Wise
var gImages=new Array;
var gIndex=0;
var DCS=new Object();
var WT=new Object();
var DCSext=new Object();

var gDomain="statse.webtrendslive.com";
var gDcsId="dcs22mcxspifwz7nqn24qpmsj_8k4n";

if (gDcsId==""){
	var gTagPath=gDomain;
}
else{
	var gTagPath=gDomain+"/"+gDcsId;
}

function dcsVar(){
	var dCurrent=new Date();
	WT.tz=dCurrent.getTimezoneOffset()/60*-1;
	WT.bh=dCurrent.getHours();
	WT.ul=navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
	if (typeof(screen)=="object"){
		WT.cd=screen.colorDepth;
		WT.sr=screen.width+"x"+screen.height;
	}
	if (typeof(navigator.javaEnabled())=="boolean"){
		WT.jo=navigator.javaEnabled()?"Yes":"No";
	}
	WT.ti=document.title;
	WT.js="Yes";
	if (typeof(gVersion)!="undefined"){
		WT.jv=gVersion;
	}
	WT.sp="";
	DCS.dcsuri=window.location.pathname;
	DCS.dcsqry=window.location.search;
	if ((window.document.referrer!="")&&(window.document.referrer!="-")){
		if (!(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)<4)){
			DCS.dcsref=window.document.referrer;
		}
	}
	DCS.dcssip=window.location.hostname;
	DCS.dcsdat=dCurrent.getTime();
}

function A(N,V){
	return "&"+N+"="+escape(V);
}

function dcsCreateImage(dcsSrc){
	if (document.images){
		gImages[gIndex]=new Image;
		gImages[gIndex].src=dcsSrc;
		gIndex++;
	}
	else{
		document.write('<IMG BORDER="0" NAME="DCSIMG" WIDTH="1" HEIGHT="1" SRC="'+dcsSrc+'">');
	}
}

function dcsMeta(){
	var myDocumentElements;
	if (document.all){
		myDocumentElements=document.all.tags("meta");
	}
	else if (document.documentElement){
		myDocumentElements=document.getElementsByTagName("meta");
	}
	if (typeof(myDocumentElements)!="undefined"){
		for (var i=1;i<=myDocumentElements.length;i++){
			myMeta=myDocumentElements.item(i-1);
			if (myMeta.name){
				if (myMeta.name.indexOf('WT.')==0){
					WT[myMeta.name.substring(3)]=myMeta.content;
				}
				else if (myMeta.name.indexOf('DCSext.')==0){
					DCSext[myMeta.name.substring(7)]=myMeta.content;
				}
				else if (myMeta.name.indexOf('DCS.')==0){
					DCS[myMeta.name.substring(4)]=myMeta.content;
				}
			}
		}
	}
}

function dcsTag(TagImage){
	var P="http"+(window.location.protocol.indexOf('https:')==0?'s':'')+"://"+TagImage+"/dcs.gif?";
	for (N in DCS){
		if (DCS[N]) {
			P+=A(N,DCS[N]);
		}
	}
	for (N in WT){
		if (WT[N]) {
			P+=A("WT."+N,WT[N]);
		}
	}
	for (N in DCSext){
		if (DCSext[N]) {
			P+=A(N,DCSext[N]);
		}
	}
	if (P.length>2048&&navigator.userAgent.indexOf('MSIE')>=0){
		P=P.substring(0,2040)+"&WT.tu=1";
	}
	dcsCreateImage(P);
}

dcsVar();
dcsMeta();
dcsTag(gTagPath);

// funciones para Nielsen // Netratings : Netratings SiteCensus V5.1
var _rsCI="es-segitur";
var _rsCG="0";
var _rsDT=0;
var _rsDU=0; 
var _rsDO=0; 
var _rsX6=0;  
var _rsSI=escape(window.location);
var _rsLP=location.protocol.indexOf('https')>-1?'https:':'http:';
var _rsRP=escape(document.referrer);
var _rsND=_rsLP+'//secure-uk.imrworldwide.com/';

if (document.images){
	var gImages=new Array;
	gImages[gIndex]=new Image;
	gImages[gIndex].src=_rsND+'cgi-bin/m?ci='+_rsCI+'&cg='+_rsCG+'&si='+_rsSI+'&rp='+_rsRP;
	gIndex++;
}
else{
	document.write('<IMG BORDER="0" NAME="DCSIMG" WIDTH="1" HEIGHT="1" SRC="'+_rsND+'cgi-bin/m?ci='+_rsCI+'&cg='+_rsCG+'&si='+_rsSI+'&rp='+_rsRP+'">');
}
//fin funciones Nielsen

//funciones MultiPortales
function mp_change_culture(current_culture,cookie_name){
	var expire_date = new Date();
 	//expire_date.setTime(expire_date.getTime()+5000*60*60*24*1000);
	window.document.cookie=cookie_name+"="+current_culture + ";path=/"; //expires="+ expire_date.toGMTString();	
	languageNav(current_culture.substr(0,2))
}