var gsListaFavoritos = ',';
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 validarEmail(valor) {
  var regexp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
  return regexp.test(valor);
}

function validarEntero(valor) {
  valor = parseInt(valor);
  return !isNaN(valor);
}

function validarUrl(valor) {
  var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
  return regexp.test(valor);
}

function validarDate(Cadena) {
   var Fecha= new String(Cadena)
   var RealFecha= new Date()  
   var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))
   var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))
   var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))

   if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){
      return false
   }
   if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){
      return false
   }
   if (isNaN(Dia) || parseInt(Dia)<1 || parseInt(Dia)>31){
      return false
   }
   if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
      if (Mes==2 && Dia > 28 || Dia>30) {
         return false
      }
   }
  
   return true   
}

function validarCIF(elCIF) {
  var temp = elCIF.toUpperCase();
  if (!/^[A-Za-z0-9]{9}$/.test(temp)) {
     return false
  }
  if (!/^[ABCDEFGHKLMNPQS]/.test(temp)) {
	return false
  }
  return true
}

function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function verFlashInactivo(psFlash,piAncho,piAlto) {
  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='"+ piAncho +"' height='" + piAlto + "'" + ">";
  vRet += "<param name='movie' value='" + psFlash + "'>";
  vRet += "<param name='quality' value='high'>";
  vRet += "<param name='menu' value='false'>";
  vRet += "<embed wmode='transparent' src='" + psFlash + "' width='" + piAncho + "' height='" + piAlto + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' menu='false'></embed></object" + ">";
  return vRet;
}

function verFlash(psFlash,piAncho,piAlto) {
	/*
  document.write("<object classid='clsid 27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+ piAncho +"' height='" + piAlto + "' align='middle'>\r\n");
  document.write("<param name='allowScriptAccess' value='sameDomain' />\r\n");
  document.write("<param name='allowFullScreen' value='false' />\r\n");
  document.write("<param name='movie' value='" + psFlash + "' />\r\n");
  document.write("<param name='quality' value='high' />\r\n");
  document.write("<param name='scale' value='exactfit' />\r\n");
	document.write("<param name='bgcolor' value='#ffffff' />\r\n");
	document.write("<embed src='" + psFlash + "' width='" + piAncho + "' height='" + piAlto + "' quality='high' scale='exactfit' bgcolor='#ffffff' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />\r\n");
	document.write("</object>\r\n");
	*/

  document.write("<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='"+ piAncho +"' height='" + piAlto + "'>");
  document.write("<param name='allowScriptAccess' value='sameDomain' />");
  document.write("<param name='allowFullScreen' value='false' />");
  document.write("<param name='movie' value='" + psFlash + "'>");
  document.write("<param name='quality' value='high'>");
  document.write("<param name='menu' value='false'>");
  document.write("<embed wmode='transparent' src='" + psFlash + "' width='" + piAncho + "' height='" + piAlto + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' menu='false'></embed></object>");
  
  
}

function verFlashBG(psFlash,piAncho,piAlto,psColor) {
  document.write("<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='"+ piAncho +"' height='" + piAlto + "'>");
  document.write("<param name='movie' value='" + psFlash + "'>");
  document.write("<param name='quality' value='high'>");
  document.write("<param name='menu' value='false'>");
  document.write("<param name='bgcolor' value='" + psColor + "' />");
  document.write("<embed wmode='transparent' src='" + psFlash + "' bgcolor='" + psColor + "' width='" + piAncho + "' height='" + piAlto + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' menu='false'></embed></object>");
}

function verApplet1RT(cnt, img) {
  vRet = "<applet code='pmvr.class' codebase='http://www.campingsonline.com/applets/' align='baseline' width='355' height='280'>"
  vRet += "<param name='center' value='" + cnt + "'>"
  vRet += "<param name='image' value='http://www.campingsonline.com/_camping/camping_images/" + img + "'>"
  vRet += "<param name='auto' value='1'>"
  vRet += "<param name='view' value='360'></applet>";
  return vRet;
}

function verApplet2RT(hFov, sYaw, urrl) {
  vRet = "<applet code='uPixScreen.class' codebase='http://www.campingsonline.com/applets/' archive='uPixScreen.jar' align='baseline' width='355' height='280'>"
  vRet += "<param name='licenseFile' value='_psk2.asf'>"
  vRet += "<param name='autoPan' value='yes'>"
  vRet += "<param name='autoPanDelay' value='0'>"
  vRet += "<param name='autoPanSpeed' value='20'>"
  vRet += "<param name='horFov' value='" + hFov + "'>"
  vRet += "<param name='hq' value='1'>"
  vRet += "<param name='maxFps' value='45'>"
  vRet += "<param name='partialStitch' value='no'>"
  vRet += "<param name='startFov' value='100.0'>"
  vRet += "<param name='startPitch' value='0.0'>"
  vRet += "<param name='startYaw' value='" + sYaw + "'>"
  vRet += "<param name='url' value='http://www.campingsonline.com/_camping/camping_images/" + urrl + "'>"
  vRet += "<param name='viewtype' value='1'>"
  vRet += "<param name='customizationFile' value='../applets/Col.cfg'></applet>";
  return vRet;
}

function verApplet3RT(tPos, aPan, aPanS, Wl) {
  sFoto = "<applet code='PixScreen.class' codebase='http://www.campingsonline.com/applets/upixVV' archive='PixScreen.jar' width=400 height=300>"
  sFoto += "<PARAM NAME=licenseFile VALUE='_psk2.asf'>"
  sFoto += "<PARAM NAME=customizationFile VALUE='Col.cfg'>"
  sFoto += "<PARAM NAME=titlePos VALUE='" + tPos + "'>"
  sFoto += "<PARAM NAME=autoPan VALUE='" + aPan + "'>"
  sFoto += "<PARAM NAME=autoPanSpeed VALUE='" + aPanS + "'>"
  sFoto += "<PARAM NAME=world VALUE=" + Wl + ">"
  sFoto += "</applet>"
  return sFoto;
}

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 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();
	}
}

function fvClickFavoritos(piTipo, piId) {
	var num;
	num = piTipo + ':' + piId;
	if (gsListaFavoritos.indexOf(',' + num + ',') < 0) { //No existe... lo aņado...
		gsListaFavoritos = gsListaFavoritos + num + ',';
	} else { //Existe y lo quito...
		gsListaFavoritos = gsListaFavoritos.replace(num + ',', "");
		if (gsListaFavoritos.lastIndexOf(',') != gsListaFavoritos.length -1) {
			gsListaFavoritos = gsListaFavoritos + ',';
		}
	}
	Set_Cookie("favoritos", gsListaFavoritos, 365, '/');
}

function fvMarcarFavoritos() {
	var buscaid = '';
	cook = Get_Cookie("favoritos");
	if (cook) gsListaFavoritos = cook;
	coma = gsListaFavoritos.split(",");
	for (x in coma) {
		if (coma[x]) {
			punto = coma[x].split(":");
			switch (punto[0]) {
				case '1': buscaid = "oferta_" + punto[1]; break;
				case '2': buscaid = "camping_" + punto[1];	break;
			}
			var obj = document.getElementById(buscaid);
			if (obj) obj.checked = true;
		}
	}
}

function fvChangeCheck(poObj, piTipo, piId) {
	fvClickFavoritos(piTipo,piId);
	switch (piTipo) {
		case 1: buscaid = "oferta_" + piId;  break;
		case 2: buscaid = "camping_" + piId; break;
	}
	var obj = document.getElementById(buscaid);
	if (obj) {
		obj.checked = !obj.checked;
	}
}

function fvGoFavoritos(poA) {
	cook = Get_Cookie("favoritos");
	if (cook) gsListaFavoritos = cook;
	poA.href = "favoritos.asp?rqsFav=" + gsListaFavoritos;
}

function fvPopUp(pagina, ancho, alto) {
	var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, width=" + ancho + ", height=" + alto + ", top=85, left=140";
	window.open(pagina,"",opciones);
}

function verApplet1RT2(psPath, cnt, img) {
  vRet = "<applet code='pmvr.class' codebase='include/applet/' align='baseline' width='355' height='280'>"
  vRet += "<param name='center' value='" + cnt + "'>"
  vRet += "<param name='image' value='" + psPath + img + "'>"
  vRet += "<param name='auto' value='1'>"
  vRet += "<param name='view' value='360'></applet>";
  return vRet;
}

function verApplet2RT2(psPath, hFov, sYaw, urrl) {
  vRet = "<applet code='uPixScreen.class' codebase='include/applet/' archive='uPixScreen.jar' align='baseline' width='355' height='280'>"
  vRet += "<param name='licenseFile' value='_psk2.asf'>"
  vRet += "<param name='autoPan' value='yes'>"
  vRet += "<param name='autoPanDelay' value='0'>"
  vRet += "<param name='autoPanSpeed' value='20'>"
  vRet += "<param name='horFov' value='" + hFov + "'>"
  vRet += "<param name='hq' value='1'>"
  vRet += "<param name='maxFps' value='45'>"
  vRet += "<param name='partialStitch' value='no'>"
  vRet += "<param name='startFov' value='100.0'>"
  vRet += "<param name='startPitch' value='0.0'>"
  vRet += "<param name='startYaw' value='" + sYaw + "'>"
  vRet += "<param name='url' value='" + psPath + urrl + "'>"
  vRet += "<param name='viewtype' value='1'>"
  vRet += "<param name='customizationFile' value='include/applet/Col.cfg'></applet>";
  return vRet;
}

function verApplet3RT2(psPath, tPos, aPan, aPanS, Wl) {
  sFoto = "<applet code='PixScreen.class' codebase='include/applet/upixVV' archive='PixScreen.jar' width=400 height=300>"
  sFoto += "<PARAM NAME=licenseFile VALUE='_psk2.asf'>"
  sFoto += "<PARAM NAME=customizationFile VALUE='Col.cfg'>"
  sFoto += "<PARAM NAME=titlePos VALUE='" + tPos + "'>"
  sFoto += "<PARAM NAME=autoPan VALUE='" + aPan + "'>"
  sFoto += "<PARAM NAME=autoPanSpeed VALUE='" + aPanS + "'>"
  sFoto += "<PARAM NAME=world VALUE=" + Wl + ">"
  sFoto += "</applet>"
  return sFoto;
}

