
function TestCookies(sWeb, sCiudad, sIdioma){
    var cookieEnabled=(navigator.cookieEnabled)? true : false

    //if not IE4+ nor NS6+
    if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
        document.cookie="testcookie"
        cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
    }
    if (!cookieEnabled){
        alert("cookies not enabled");
        Recarga("EnableCookies.php");
    }
    iRet=SetupCookies(sWeb, sCiudad, sIdioma);
    return(iRet);
}

function TestCookies2(sCiudad, sIdioma){
    EscribeCookie("test", ".");
    if(!LeeCookie("test")){
        window.location="EnableCookies.php";
    }
    SetupCookies(sCiudad, sIdioma);
}


function alertSize() {
  var frameWidth = 0, frameHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    frameWidth = window.innerWidth;
    frameHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    frameWidth = document.documentElement.clientWidth;
    frameHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    frameWidth = document.body.clientWidth;
    frameHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + frameWidth );
  window.alert( 'Height = ' + frameHeight );
}

/**************************************************************************
 Mira si están escritas las cookies necesarias, y si no, las escribe.
 Retorna el numero de cookies que ha escrito.
**************************************************************************/
function SetupCookies(sWeb, sCiudad, sIdioma){
var iRet=0;
var frameWidth=0;
var frameHeight=0;

    var frameWidth,frameHeight;
    if (self.innerHeight){ // all except Explorer
    	frameWidth = self.innerWidth;
    	frameHeight = self.innerHeight;
    }else if (document.documentElement && document.documentElement.clientHeight){
    	// Explorer 6 Strict Mode
    	frameWidth = document.documentElement.clientWidth;
    	frameHeight = document.documentElement.clientHeight;
    }else if (document.body){ // other Explorers
    	frameWidth = document.body.clientWidth;
    	frameHeight = document.body.clientHeight;
    }

    
    if(!LeeCookie("AnchoVentana")){
        EscribeCookie("AnchoVentana", frameWidth);
        iRet++;
    }
    if(!LeeCookie("AltoVentana")){
        EscribeCookie("AltoVentana", frameHeight);
        iRet++;
    }
    if(!LeeCookie("AnchoPantalla")){
        EscribeCookie("AnchoPantalla", screen.availWidth);
        iRet++;
    }
    if(!LeeCookie("AltoPantalla")){
        EscribeCookie("AltoPantalla", screen.availHeight);
        iRet++;
    }
    if(!LeeCookie("Idioma")){
        EscribeCookie("Idioma", sIdioma);
        iRet++;
    }
    if(!LeeCookie("Web")){
        EscribeCookie("Web", sWeb);
        iRet++
    }
    if(!LeeCookie("Ciudad")){
        EscribeCookie("Ciudad", sCiudad);
        iRet++
    }
    if(!LeeCookie("Navegador")){
        EscribeCookie("Navegador", oBrowser.nav);
        iRet++
    }

    return(iRet);
}


function EscribeCookie(sVariable, sValor, iDias){
 var Expira;
 var sContenido="";
     if(iDias){
         var hoy = new Date();
         hoy.setTime( hoy.getTime() );
         var Fecha=new Date( hoy.getTime() + (iDias*24*60*60*1000) )
         Expira = "expires="+Fecha.toGMTString();
     }else
         Expira="";
     
     sContenido = sVariable +"="+ sValor;
     sContenido = sContenido +  ";" + Expira + ";";
     document.cookie=sContenido;
}

function LeeCookie(sVariable){
	var nameEQ = sVariable + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ')
		    c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
		    return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function BorraCookie(sVariable){
    EscribeCookie(sVariable, "asd", -1);
}
