//dynsur banners
function banner(tipo, idiSesion, idiIni, idiFin, difi, div) {
	$.get('banner.php', { tipo: tipo, idiSesion: idiLang, idiIni: idiIni, idiFin: idiFin, difi: difi, random: Math.random() }, function(data) {
		$('#' + div).html(data);
	});
}


//  define pantalla 
function defineWH() {
   
    ventaW = (navigator.appName != "Microsoft Internet Explorer" )? window.innerWidth : document.body.offsetWidth-20
    ventaH = (navigator.appName != "Microsoft Internet Explorer")? window.innerHeight : document.body.offsetHeight-4
}

function reposiciona() {
	if (((navigator.appName == "Netscape")&& (ventaW!=window.innerWidth || ventaH!=window.innerHeight)) || (navigator.appName == "Microsoft Internet Explorer")){
		history.go(0)
	}

}


//gestion de menu superior
function ensenya(x) 
{
    y= document.getElementById("submenu"+x)
	y.style.visibility="visible"
}
function apaga(x) 
{
    y= document.getElementById("submenu"+x)
	y.style.visibility="hidden"
}

//escribe HTML en body
function escribeHTML(mensaje){
text = mensaIdi[mensaje][idiLang]
document.write(text)
}


function continuar(donde, tipo)
{
 if ( validarSolici(tipo))    
	{
	//definemotivo();
	//document.formulario.submit()
	//hardcoded tipo web = 1
	parameAbre = "idiIni=" + ini+ "&idiFin=" +fin + "&difi=" + difi + "&idiSesion=" + idiSesi + "&tipo=" +1 +"&colec=" + colec
    
	//alert(parameAbre)
	openWin(parameAbre, donde)
	}	
}

function continuarExtraParams(donde, tipo, params)
{
 if ( validarSolici(tipo))    
	{
	//definemotivo();
	//document.formulario.submit()
	//hardcoded tipo web = 1
	parameAbre = "idiIni=" + ini+ "&idiFin=" +fin + "&difi=" + difi + "&idiSesion=" + idiSesi + "&tipo=" +1 +"&colec=" + colec + params
    
	//alert(parameAbre)
	openWin(parameAbre, donde)
	}	
}

usuario=""
clave=""
function validarWekaner() 
{
	//txt = txt + " ini" + ini + " fin" + fin + " dif" + difi
	usuario = document.formulario.usuario.value;
	clave = document.formulario.clave.value;

	valor = 0
	if (!usuario || !clave){
	    valor = 1
		return false;
	}
	else{
		return true;
	}
}

function validarSolici(tipo) 
   {
 //Comprobaci�n valores de solicitud de partida
    ini = document.formulario.idiIni.value 
	fin = document.formulario.idiFin.value 
    difi = document.formulario.difi.value 
	idiSesi = document.formulario.idiSesion.value 
	colec =  document.formulario.colec.value 
	
    valor = 0;
	txt = mensaV[0][idiSesi]
	
	if(tipo=='usuario'){
		if(validarWekaner()){
		//ok
		}else{
		   txt = txt + mensaV[6][idiSesi]
	       valor = 1
		}
	}
	
	if (!ini){
		txt = txt + mensaV[1][idiSesi]
		valor = 1
	}
	if (!fin){
		txt = txt + mensaV[2][idiSesi]
		valor = 1
	}
	if (!difi){
		txt = txt + mensaV[3][idiSesi]
		valor = 1
	}
	if (ini == fin){
		txt = txt + mensaV[4][idiSesi]
		valor = 1
	}
	if (valor == 0){
		return true;}
	else{
		txt = txt + mensaV[5][idiSesi]
		alert(txt)
 		return false;
    }   


}

function validarSoliciFB(tipo) 
   {
 //Comprobaci�n valores de solicitud de partida
    ini = document.formulario.idiIni.value 
	fin = document.formulario.idiFin.value 
    difi = document.formulario.difi.value 
	idiSesi = document.formulario.idiSesion.value 
	colec =  document.formulario.colec.value 
	
    valor = 0;
	txt = mensaV[0][idiSesi]
	
	/*if(tipo=='usuario'){
		if(validarWekaner()){
		//ok
		}else{
		   txt = txt + mensaV[6][idiSesi]
	       valor = 1
		}
	}*/
	
	if (!ini){
		txt = txt + mensaV[1][idiSesi]
		valor = 1
	}
	if (!fin){
		txt = txt + mensaV[2][idiSesi]
		valor = 1
	}
	if (!difi){
		txt = txt + mensaV[3][idiSesi]
		valor = 1
	}
	if (ini == fin){
		txt = txt + mensaV[4][idiSesi]
		valor = 1
	}
	if (valor == 0){
		return true;}
	else{
		txt = txt + mensaV[5][idiSesi]
		alert(txt)
 		return false;
    }   


}
//colectivos

function seleccion(selector)
{
 // valor seleccionado
  x =selector.selectedIndex
  //alert(x)
  y = selector[x].text
  //valor
  selID = selector[x].value
  //campo oculto relacionado
  campoNombre= selector.name + "ID"
  //campo = document.getElementById(campoNombre)
  eval("campo=document.formulario." + campoNombre)
	//actualiza campo y muestra  
  pintaCole(y,selID,campo)
  
  selector.selectedIndex = 0
  //alert(campo.value)

}



function seleccAvis(selector)
{

text = mensaIdi[51][idiLang]
text = text + " " + mensajeNuevPart //mensa[3][idiLang] //FlipeAlert
text = text + " " + mensaIdi[52][idiLang]
alert(text)

}




function pintaCole(y,selID,campo)
{
  check = document.getElementById("resultSel").innerHTML
  checkID = campo.value 

  res = check.indexOf(y)
  if (res < 0){
  	check = check + " " + y
	//guarda valor en campo
	res2 = checkID.indexOf(selID)
    if (res2 < 0){
	 campo.value = campo.value + selID + ","
	}
  }
  else{
     check = check.replace(y, "")
	 cambia = selID + ","
	 campo.value = checkID.replace(cambia, "")
  }
  document.getElementById("resultSel").innerHTML = check
}

 function handleFrame(esta, destino)
 {
	chkFrame = iframedesc.document.body.innerHTML
	if (chkFrame.length > 1) {
		x = iframedesc.document.getElementById("unoIF").innerHTML
		y = iframedesc.document.getElementById("dosIF").innerHTML
		capDiv = eval("document.getElementById('" + destino +"')")
		capDiv.innerHTML = x + " "  + y
	}
 }


function handleSelec(esta, destino)
 {
	chkFrame = iframedesc.document.body.innerHTML
	if (chkFrame.length > 1) {
		x = iframedesc.document.getElementById("unoIF").innerHTML
		y = iframedesc.document.getElementById("dosIF").innerHTML
	}else{
		y= "ENLACE"
	}
     
	if(y =="ENLACE"){
		z= document.getElementById("ocultaEnla")
		z.style.visibility="visible"
		z= document.getElementById("ocultaDes")
		z.style.visibility="hidden"

	}else{

		z= document.getElementById("ocultaEnla")
		z.style.visibility="hidden"

		//alert(iframedesc.document.getElementById("unoIF").innerHTML)

		// pinta opciones
		trencaOp = x.split("|")
		for (i=1;i<(trencaOp.length);i++){
			valorOpt = trencaOp[i].split(",")
			var opti=document.createElement('option');
			opti.text=valorOpt[1]
			opti.value=valorOpt[0]
			//alert(opti.text + " " + opti.value)
			var selex=document.getElementById("colec");
			
			try
			  {
			  selex.add(opti,null); // standards compliant
			  }
			catch(ex)
			  {
			  selex.add(opti); // IE only
			  }	
		
		}
		zz= document.getElementById("ocultaDes")
		zz.style.visibility="visible"
		var x=document.getElementById("colec")
	    //alert("El VERDADERO desplegable contiene como <option> 1 " + x.options[1].text)

	}
 }





// selector de colectivos din�mico

function escuchaDivFram(proviene, coleID)
{
// obtenemos campos  de la Iframe
 	x = iframedesc.document.getElementById("IFcampo1").value
	y = iframedesc.document.getElementById("IFcampo2").value
	//y = "<b>" + y + "</b>"
	campo=document.formulario.colectivoID
	//actualiza campo y muestra
	pintaCole(y,x,campo)
	
//alert(x+" " +y)

}
 function cargaFrame(origen, numero)
 {
 //alert(numero)
 //'chKUsu.asp', 3
    if (numero == 3) {
	// chkUsuario
		x = eval("document.getElementById('usuario').value")
		x = limpiaMe(x)
	}
	else{
	// Colectivos
		x = eval("document.getElementById('claveChk" + numero + "').value")
		x = limpiaMe(x)
	}
	if(x){
	    x = encodeURI(x)
		origen = origen + "?clave=" + x
		document.getElementById("iframedesc").src = origen
		//alert(origen);
    }
 }
 
 function limpiaMe(x){
	 
  //x = x.replace(/nnnn/gi, "")
  var banned =new Array("script","select","insert","update","delete","drop","declare","exec","varchar","xp_", "�","=","'", "\"");
  for (i=0;i<banned.length;i++){
	  x = x.replace(banned[i], "")
  }
  return x 
 }


function openWin(parameAbre, donde)
{
//despues de carga definimos pantalla
//defineWH()
//WINDOW
//posicion inicial derecha ajustada al ancho pantalla
//posiVX = ((ventaW/2) - 400)
//alturaV = ventaH + 25
//eval("myWindow=window.open('wekanun.asp?"+parameAbre +"','"+donde+"','left="+posiVX +",top=0,resizable=no,width=800,height=" + alturaV + ",menubar=no,scrollbars=no,toolbar=no')");
//myWindow.focus();
//if (myWindow.opener == null) myWindow.opener = self;
navegame = "wekanun.asp?" + parameAbre 
///location.href=
if(parent){
        if(donde == '_self') {
                parent.self.location.href = navegame
        } else {
                parent.top.location.href = navegame
        }
}else{
        if(donde == '_self') {
                window.self.location.href = navegame
        } else {
                window.top.location.href = navegame
        }
}
//window.top.location = navegame

}

function openDemo(parameAbre, donde)
{
//despues de carga definimos pantalla
defineWH()
//posicion inicial derecha ajustada al ancho pantalla
posiVX = ((ventaW/2) - 300)
//alturaV = ventaH + 25
alturaV = 373

x = Math.round((Math.random() * 5000))
eval("myWindow=window.open('../jugar_on_line/wekapro.asp?"+parameAbre +"&idPropu=" + x + "&demoWeb=1" + "','"+donde+"','left="+posiVX +",top=170,resizable=no,width=600,height=" + alturaV + ",menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,status=no,titlebar=no')");
myWindow.focus();
if (myWindow.opener == null) myWindow.opener = self;

}

//parametros

function paramPag() 
{
    var paraURL = document.location.search.indexOf('?');
    var parametros = new Array();
    if (paraURL != -1) 
    {
        var parejas = document.location.search.substring(paraURL +1, document.location.search.length).split('&');
        for (var i=0; i<parejas.length; i++)
        {
            nombre = parejas[i].split('=');
            parametros[i] = new Array(2)
            parametros[i][0] = nombre[0]
            parametros[i][1] = nombre[1]

            //parametros[nombre[0]] = nombre[1];
            ///////parametros[i] = nombre[1];

        }
    }else{
 		parametros[0] = new Array(2)
            parametros[0][0] = ""
            parametros[0][1] = ""
    }
    return parametros;
}

// gestion banners ARSYS
//obsoleto
bannRef = "<a href='http://cgi.versiondigital.com/Banner/BannerClick.asp?lugar="
bannTarg ="target='_top'>"
bannImg = " src='http://cgi.versiondigital.com/Banner/ServeBanner.asp?lugar="
bannImgBorder = "border='0'>"
//obsoleto


function pintaBanner(lugar, wid, hei, idio){
/*<a href="http://cgi.versiondigital.com/Banner/BannerClick.asp?lugar=wek1p" target="_top">
	<img width="185" height="95" src="http://cgi.versiondigital.com/Banner/ServeBanner.asp?lugar=wek1p" border="0">
</a>*/

// futuros n tipos para n idiomas
//tempo = "wek" + idio +  lugar
tempo = "wek1" + lugar
lugar = tempo

// arsys
//obsoleto ARSYS
	tempRef = bannRef + lugar + "'" + " " + bannTarg								
	mides = "<img width='"+wid+"' height='"+hei+"'"								
	tempImg = mides + bannImg + lugar + "' " + bannImgBorder
//obsoleto

tempRef = "<a target='_top' href='http://"
tempImg = "<img width='"+wid+"' height='"+hei+"' border='0' src='http://"
// alternador
var d=new Date();
tempSec = d.getSeconds();

switch (lugar)
{
	case "wek1a":
		tempRef = tempRef + "www.wekanun.com'>"
		tempImg = tempImg + "www.wekanun.com/img/banner/patroAny.jpg'>"
	  break;
	case "wek1d":
	     if (tempSec > 29){
			tempRef = tempRef + "www.dnoche.net'>"
			tempImg = tempImg + "www.wekanun.com/img/banner/dnoched.jpg'>"
		}else{
			tempRef = tempRef + "www.marysplace.es'>"
			tempImg = tempImg + "www.wekanun.com/img/banner/merysplad.jpg'>"		
		}
	  break;
	case "wek1l":
		if (tempSec > 45){
			tempRef = tempRef + "www.marysplace.es'>"
			tempImg = tempImg + "www.wekanun.com/img/banner/meryspla.jpg'>"
		}else{
		   	if (tempSec > 30){
				tempRef = tempRef + "ru.iguana.ws'>"
				tempImg = tempImg + "www.wekanun.com/img/banner/iguana.gif'>"
			}else{
			      if (tempSec > 15){
				     tempRef = tempRef + "www.intercoined.org'>"
					 tempImg = tempImg + "www.wekanun.com/img/banner/co185Por.gif'>"

				  }else{
					 tempRef = tempRef + "www.coined.de'>"
					 tempImg = tempImg + "www.wekanun.com/img/banner/co185ger.gif'>"
				  }
			}		
		}

	  break;
	case "wek1m":
		if (tempSec > 45){
		   tempRef = tempRef + "www.intercoined.org'>"
		   tempImg = tempImg + "www.wekanun.com/img/banner/co185Ing.gif'>"
		}else{
		   	if (tempSec > 30){
					 tempRef = tempRef + "www.coined.de'>"
					 tempImg = tempImg + "www.wekanun.com/img/banner/co185ger.gif'>"
			}else{
			      if (tempSec > 15){
					tempRef = tempRef + "ru.iguana.ws'>"
					tempImg = tempImg + "www.wekanun.com/img/banner/iguana.gif'>"		

				  }else{
					tempRef = tempRef + "www.eurhabitat.com'>"
					tempImg = tempImg + "www.wekanun.com/img/banner/eurhabi.jpg'>"
				  }
			}		
		}
	  break;
	case "wek1p":
		tempRef = tempRef + "www.wekanun.com'>"
		tempImg = tempImg + "www.wekanun.com/img/banner/patroPro.jpg'>"
	  break;
	case "wek1r":
		if (tempSec > 45){
			tempRef = tempRef + "www.dnoche.net'>"
			tempImg = tempImg + "www.wekanun.com/img/banner/dnocher.jpg'>"
		}else{
		   	if (tempSec > 30){
				     //tempRef = tempRef + "www.intercoined.org'>"
					 //tempImg = tempImg + "www.wekanun.com/img/banner/co200Ing.gif'>"
					tempRef = tempRef + "www.eurhabitat.com'>"
					tempImg = tempImg + "www.wekanun.com/img/banner/eurhabi.jpg'>"

			}else{
			      if (tempSec > 15){
				  	tempRef = tempRef + "www.eurhabitat.com'>"
					tempImg = tempImg + "www.wekanun.com/img/banner/eurhabi.jpg'>"

				  }else{
				     tempRef = tempRef + "www.dnoche.net'>"
					 tempImg = tempImg + "www.wekanun.com/img/banner/dnocher.jpg'>"
					 //tempRef = tempRef + "www.coined.de'>"
					 //tempImg = tempImg + "www.wekanun.com/img/banner/co200ger.gif'>"
				  }
			}		
		}
      break;
	default:
	  //document.write("I'm looking forward to this weekend!");
}


document.write(tempRef)
document.write(tempImg)
document.write("</a>")
}

// POP UP

function popUpi()
{
	popup = document.getElementById("popupDiv")
	//a saco. No da su width or height
	altoPop=400
	anchoPop = 600
	destiPopY = 55
	popup.style.top = altoPop*-1
	medioVenta = (ventaW-anchoPop)/2
	popup.style.left = medioVenta

    timero=setTimeout("desliza("+destiPopY + ",1)",50);
		//alert(popup + " " + destiPopY)
	popup.style.visibility="visible"
}
function desliza(destino, x)
{
	popup = document.getElementById("popupDiv")
      if (x == 1){
	  		checkXY = parseInt(popup.style.top)
		
			  if (checkXY > destino){
				popup.style.top = destino
				clearTimeout(timero)
				destino = altoPop*-1
				timero=setTimeout("desliza("+destino + ",2)",7000);
			  }else{
				 popup.style.top = checkXY + 50
				 timero=setTimeout("desliza("+destino + ",1)",50);
			  }
		
		
	  }else{
	   		  checkXY = parseInt(popup.style.top)
			  if (checkXY < destino){
				popup.style.top = destino
				clearTimeout(timero)
			  }else{
			     if (destiPopY == checkXY)
				 {
				  popup.style.top = checkXY +15
				 }else{
				 	popup.style.top = checkXY - 50
				 }
				 timero=setTimeout("desliza("+destino + ",2)",50);
			  }

	  }	

}
function closePop()
{
    clearTimeout(timero)
	popup = document.getElementById("popupDiv")
	popup.style.visibility="hidden"

}







// COOKIES sin usar
function escribeCookie(tipo){
	if (tipo == "formulario"){
		ini = document.formulario.idiIni.value 
		fin = document.formulario.idiFin.value 
		difi = document.formulario.difi.value 
		idiSesi = document.formulario.idiSesion.value 
		var usuario = document.formulario.usuario.value;
		var clave = document.formulario.clave.value;
	}

        if (ini==null || ini == "" || ini=="undefined"){
		// por defecto spanischi
            ini = 1;
        }
        setCookie("IdiomaInicial", ini, expires, "/");
		
		if (fin==null || fin == "" || fin=="undefined"){
		// por defecto spanischi
            fin = 2;
        }
        setCookie("IdiomaFinal", fin, expires, "/");

		if (difi==null || difi == "" || difi=="undefined"){
		// por defecto spanischi
            difi = 1;
        }
        setCookie("Dificultad", difi, expires, "/");
		
		if (idiSesi==null || idiSesi == "" || idiSesi=="undefined"){
		// por defecto spanischi
            idiSesi = 2;
        }
        setCookie("IdiomaSesion", idiSesi, expires, "/");

		if (usuario==null || usuario == "" || usuario=="undefined"){
		// por defecto invitado
            usuario = "invitado";
        }
        setCookie("Wekaner", usuario, expires, "/");
		
		if (clave==null || clave == "" || clave=="undefined"){
		// por defecto invitado
            clave = "invitado";
        }
        setCookie("Clave", clave, expires, "/");


}

var today = new Date()

var expires = new Date();
 
// fix the bug in Navigator 2.0, Macintosh
 
fixDate(expires);
expires.setTime(expires.getTime() + 365 * 24 * 60 * 60 * 1000);

function setCookie(name, value, expires, path, domain, secure) {
 
 var curCookie = name + "=" + escape(value) +
 ((expires) ? "; expires=" + expires.toGMTString() : "") +
 ((path) ? "; path=" + path : "") +
 ((domain) ? "; domain=" + domain : "") +
 ((secure) ? "; secure" : "");
 document.cookie = curCookie;
}

function getCookie(name) {
 var dc = document.cookie;
 var prefix = name + "=";
 var begin = dc.indexOf("; " + prefix);
 if (begin == -1) {
 begin = dc.indexOf(prefix);
 if (begin != 0) return null;
 } else
 begin += 2;
 var end = document.cookie.indexOf(";", begin);
 if (end == -1)
 end = dc.length;
 return unescape(dc.substring(begin + prefix.length, end));
}

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 fixDate(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}

