

//
//  Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
//
//  Written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>
//  The following functions are released to the public domain.
//

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function fsDivWrite(text,id){
	if (document.getElementById){
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all){
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers){
		x = document.layers[id];
		text2 = '<P CLASS="testclass">' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}

var gdExpdate = new Date ();
FixCookieDate (gdExpdate); // Correct for Mac date bug - call only once for given Date object!
gdExpdate.setTime (gdExpdate.getTime() + (500 * 24 * 60 * 60 * 1000)); // 24 hrs from now 

function fdivMochilaVaciar(){
	DeleteCookie ("COLURLs");
	DeleteCookie ("COLURLTITULOSs");
	fdivTopURLs("divTopURLs", 1);
}

function fhtmlMochilaURLs(){

	var lsHistURLs="", lsHistTitulos="", lshtmHist="";

	lshtmHist+="<img HSPACE=10 ALIGN=left VALIGN=middle src='http://www.campingsonline.com/_include/i/icoMochila.gif' /><B>Mochila de favoritos</B>. Si quieres puedes guardar las búsquedas más interesantes para acceder directamente la próxima vez que nos visites.<BR>Para ello pulsar [<B>agregar</B>] la dirección que te interese (la opción de registrar cookies de tu navegador tiene que estar activada).<BR>";
        try {
		lsHistURLs=(GetCookie("COLURLs")==null)?"":GetCookie("COLURLs");
		lsHistTitulos=(GetCookie("COLURLTITULOSs")==null)?"":GetCookie("COLURLTITULOSs");
		if (lsHistURLs.length>0){
			var lasHistURLs=lsHistURLs.split("!!!");
			var lasHistTitulos=lsHistTitulos.split("!!!");
			lshtmHist+="<ul>"
			for (var i=0; i<lasHistURLs.length; i++){
				if (lasHistURLs[i].length>0){
					lshtmHist+="<li>";
					lshtmHist+="<A HREF='javascript:fdivMochilaURLsQuitar(\"" + lasHistURLs[i] + "\",\"" + lasHistTitulos[i] + "\")'>[Quitar]</A>&nbsp;&nbsp;"
					lshtmHist+="<A HREF='" + lasHistURLs[i] + "'>" + lasHistTitulos[i] + "</a>";
					lshtmHist+="</li>";
				}
			}
			lshtmHist+="</ul>";
			lshtmHist+="Other options [<A HREF='javascript:fdivMochilaVaciar()'>Vaciar mi mochila de favoritos</A>]&nbsp;|&nbsp;[<A HREF='javascript:fdivTopURLs(\"divTopURLs\",0)'>Hide the list</A>]";
			return(lshtmHist);
		} else return(lshtmHist+"<BR>Favorite addresses were not found in your backpack.</A>");
        } catch (e) {
       		return(lshtmHist+"Favorite addresses were not found in your backpack.</A>");
	}
	return("");
}

function fdivMochilaURLsQuitar(psURL, psTitulo){

	var lsHistURLs="", lsHistTitulos="";

       try {
		lsHistURLs=(GetCookie("COLURLs")==null)?"":GetCookie("COLURLs");
		lsHistTitulos=(GetCookie("COLURLTITULOSs")==null)?"":GetCookie("COLURLTITULOSs");

//alert("psURL:"+psURL+"\n\nlsHistURLs:"+lsHistURLs);
//		var lreMatch=new RegExp(/!!!\psURL/g);
		lsHistURLs=lsHistURLs.replace(psURL,"");

//		lreMatch=new RegExp("/"+psTitulo+"/g");
		lsHistTitulos=lsHistTitulos.replace(psTitulo,"");

		SetCookie ("COLURLs", lsHistURLs, gdExpdate, "/");
		SetCookie ("COLURLTITULOSs", lsHistTitulos, gdExpdate, "/");
		fdivTopURLs("divTopURLs", 1);

	} catch (e) {
       		alert("error" + e);
	}
}

function fdivMochilaURLsAdd(psURL, psTitulo){

	var lsHistURLs="", lsHistTitulos="";

       try {
		lsHistURLs=(GetCookie("COLURLs")==null)?"":GetCookie("COLURLs");
		lsHistTitulos=(GetCookie("COLURLTITULOSs")==null)?"":GetCookie("COLURLTITULOSs");
		lsHistURLs+="!!!"+psURL;
		lsHistTitulos+="!!!"+psTitulo;
		SetCookie ("COLURLs", lsHistURLs, gdExpdate, "/");
		SetCookie ("COLURLTITULOSs", lsHistTitulos, gdExpdate, "/");
		fdivTopURLs("divTopURLs", 1);
	} catch (e) {
       		alert("error" + e);
	}

}

function fdivTopURLs(psDiv, piEstado){

	var lbMostrar=false;
	if (gshtmlTopURLs.length>0)
		lbMostrar=true;
	else
		lbMostrar=(GetCookie("COLURLs")==null)?false:true;
	
	if (lbMostrar){

		var lsHtmlDiv="";
		var lsHtmlCab="";
		var lsHtmlPie="";

		lsHtmlCab="<table width='100%'  border='0' cellpadding='0' cellspacing='0' background='_include/i/gr/GR_ReqGenFondo.gif' bgcolor='F1F1F1'>";
		lsHtmlCab+="<tr>";
			lsHtmlCab+="<td width='1%' align='left' valign='top'><img src='http://www.campingsonline.com/_include/i/gr/GR_ReqGenEsqSupIzq.gif' width='10' height='5' /></td>";
			lsHtmlCab+="<td width='95%' align='left' valign='top'><img src='http://www.campingsonline.com/_include/i/gr/GR_ReqGenFondo.gif' width='5' height='5' /></td>";
			lsHtmlCab+="<td HEIGHT=35 width='3%' ROWSPAN=3 align='right' valign='top'><img src='http://www.campingsonline.com/_include/i/t.gif' BORDER=0 HEIGHT=3 WIDTH=20 /><br /><A HREF='javascript:fdivTopURLs(\""+psDiv+"\",1)'><img BORDER=0 src='http://www.campingsonline.com/_include/i/icoUltimasbusquedas.gif' /></A></td>";
			lsHtmlCab+="<td width='1%' align='right' valign='top'><img src='http://www.campingsonline.com/_include/i/gr/GR_ReqGenEsqSupDer.gif' width='10' height='5' /></td>";
		lsHtmlCab+="</tr>";
		lsHtmlCab+="<tr>";
			lsHtmlCab+="<td width='1%' height='5' align='left' valign='top' nowrap='nowrap'><img src='http://www.campingsonline.com/_include/i/gr/GR_ReqGenFondo.gif' width='5' height='5' /></td>";
			lsHtmlCab+="<td width='95%' height='5' align='left' valign='middle' nowrap='nowrap' class='BS_Titulo'>";
	
			lsHtmlPie+="</td>";
			lsHtmlPie+="<td width='1%' height='5' align='right' valign='top' nowrap='nowrap'><img src='http://www.campingsonline.com/_include/i/gr/GR_ReqGenFondo.gif' width='5' height='20' /></td>";
		lsHtmlPie+="</tr>";
		lsHtmlPie+="<tr>";
			lsHtmlPie+="<td width='1%' align='left' valign='top'><img src='http://www.campingsonline.com/_include/i/gr/GR_ReqGenEsqInfIzq.gif' width='10' height='5' /></td>";
			lsHtmlPie+="<td width='95%' align='left' valign='top'><img src='http://www.campingsonline.com/_include/i/gr/GR_ReqGenFondo.gif' width='5' height='5' /></td>";
			lsHtmlPie+="<td width='1%' align='right' valign='top'><img src='http://www.campingsonline.com/_include/i/gr/GR_ReqGenEsqInfDer.gif' width='10' height='5' /></td>";
		lsHtmlPie+="</tr>";
		lsHtmlPie+="</table><BR>";
	
		switch (piEstado){
			case 0:
				lsHtmlDiv=lsHtmlCab + "<A HREF='javascript:fdivTopURLs(\""+psDiv+"\",1)'>Please click here to see your latest searching</A>." + lsHtmlPie;
				break;
			case 1:
				lsHtmlDiv=lsHtmlCab + "<img HSPACE=10 ALIGN=left VALIGN=middle src='http://www.campingsonline.com/_include/i/icoBrujula.gif' /><BR />Your latest searching are the following. <A HREF='javascript:fdivTopURLs(\""+psDiv+"\",0)'>Click here to hide the list</A>.<BR>";
				lsHtmlDiv+=gshtmlTopURLs + fhtmlMochilaURLs() + lsHtmlPie;
				break;
			case -1:
				lsHtmlDiv=""
				break;
		}
		fsDivWrite(lsHtmlDiv,psDiv)

	}

}


function verVideoSize(psVideo, piw, pih) {
  vRet = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='"+ piw +"' height='"+ pih +"'>\r\n";
  vRet += "<param name='movie' value='http://www.campingsonline.com/_include/flash/mediaplayer.swf'\r\n>";
  vRet += "<param name='quality' value='high'>\r\n";
  vRet += "<param name='menu' value='false'>\r\n";
  vRet += "<param name='bgcolor' value='#FFFFFF' />\r\n";
  vRet += "<param name='allowfullscreen' value='true' />\r\n";
  vRet += "<param name='allowscriptaccess' value='always' />\r\n";
  vRet += "<param name='flashvars' value='file=" + psVideo + "&amp;autostart=true&amp;width=" + piw + "&amp;height=" + pih + "' />\r\n";
  vRet += "<embed src='http://www.campingsonline.com/_include/flash/mediaplayer.swf' width='" + piw + "' height='" + pih + "' allowscriptaccess='always' allowfullscreen='true' flashvars='file=" + psVideo + "&amp;autostart=true&amp;width=" + piw + "&amp;height=" + pih + "' />\r\n";
  vRet += "</object>\r\n";
  return vRet;
}

var giMousex = 0;
var giMousey = 0;

function Browser() {
  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();


function fvMostrarCapa(id, pbMostrar) {
	if (document.getElementById)
	{
		x = document.getElementById(id);
		if (!pbMostrar) x.style.visibility = "hidden";
		else x.style.visibility = "visible";
	}
	else if (document.all){
		x = document.all[id];
		if (!pbMostrar) x.style.visibility = "hide";
		else x.style.visibility = "visible";
	}
	else if (document.layers){
		x = document.layers[id];
		if (!pbMostrar) x.style.visibility = "hidden";
		else x.style.visibility = "show";
	}
}

//Para la capa emergente...
function fvEventoMouse() {
  	if (browser.isNS) {
	    document.addEventListener("mousemove", mouseMove,   true);
		event.preventDefault();
	}
	if (browser.isIE) {
		document.attachEvent("onmousemove", mouseMove);
	}
}

//Para la capa emergente...
function mouseMove(event) {
  	if (browser.isNS) {
		giMousex = event.clientX + window.scrollX;
		giMousey = event.clientY + window.scrollY;
		event.preventDefault();
	}
	if (browser.isIE) {
		giMousex = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
		giMousey = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
	}
}

function fvPosicionaCapa(id) {
	document.getElementById(id).style.left = giMousex + "px";
	document.getElementById(id).style.top = giMousey + "px";
}

function fvPosicionaCapaVideo(id) {
	document.getElementById(id).style.left = "130px";
	document.getElementById(id).style.top = (giMousey-200) + "px";
}

function fvPonEnCapa(id, text) {
	if (document.getElementById)
	{
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		text2 = '<P CLASS="testclass">' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}
