//-------- puedes configurar estos parametros --------
var $ruta_del_css="legal.css";
var $frase ="<p id='titulo_splash'>Advertencia</p> <p id='texto_splash'>Debes ser mayor de edad para poder visitar esta pagina <br><br>¿Tienes mas de 18 años?</p>";

//--------- a partir de aqui no tocar------------------------------------------------
addCss($ruta_del_css);
function inicio(){
	$check=getCookie('splash_mayor_edad');
	if($check=='si_es_mayor') return;
	var $docBody = document.getElementsByTagName("body").item(0);
	var $fondo_splash = document.createElement("div");
	var $splash = document.createElement("div");
	var $boton_si = document.createElement("div");
	var $boton_no = document.createElement("div");
	$fondo_splash.id='fondo_splash';
	$splash.id='splash';
	$boton_si.id='boton_si';
	$boton_no.id='boton_no';	
	$splash.innerHTML= $frase;
	$boton_si.innerHTML="SI";
	$boton_no.innerHTML="NO";
	$splash.appendChild($boton_si);
	$splash.appendChild($boton_no);
	$docBody.appendChild($fondo_splash);
	$docBody.appendChild($splash);
	if(!NiftyCheck())
		return;
	RoundedTop("div#splash","#333","#A1B638");
	RoundedBottom("div#splash","#333","#FFFFFF");
	
	if(document.getElementById && !window.getComputedStyle){// DOM but not Mozilla
		document.getElementById("fondo_splash").style.position = "absolute";
		document.getElementById("splash").style.position = "absolute";
		window.onscroll = splash;
	}
	$boton_si.onclick= function(){
			$splash.style.display="none";
			$fondo_splash.style.display="none";
			setCookie('splash_mayor_edad','si_es_mayor');
	}
	$boton_no.onclick= function(){
			window.location = "http://www.google.es";
	}
}
function splash(){
	//alert("hola");
	var pos = (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;
	document.getElementById("fondo_splash").style.top = parseInt(pos + 0) + "px";
	//var pos = (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;
	document.getElementById("splash").style.top = parseInt(pos + 100) + "px";
}

//================ añade un poco de estilo al documento =========================
function addCss(url){
	var obj = document.createElement('link');
	obj.rel = 'stylesheet';
	obj.type = 'text/css';
	obj.media = 'screen,projection';
	obj.href = url;
	document.getElementsByTagName('head')[0].appendChild(obj);
}


//================ redondea las esquinas ========================================
function NiftyCheck(){
if(!document.getElementById || !document.createElement)
    return(false);
var b=navigator.userAgent.toLowerCase();
if(b.indexOf("msie 5")>0 && b.indexOf("opera")==-1)
    return(false);
return(true);
}

function Rounded(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
var l=v.length;
for(i=0;i<l;i++){
    AddTop(v[i],bk,color,size);
    AddBottom(v[i],bk,color,size);
    }
}

function RoundedTop(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddTop(v[i],bk,color,size);
}

function RoundedBottom(selector,bk,color,size){
var i;
var v=getElementsBySelector(selector);
for(i=0;i<v.length;i++)
    AddBottom(v[i],bk,color,size);
}

function AddTop(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rtop";
d.style.backgroundColor=bk;
for(i=1;i<=lim;i++){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.insertBefore(d,el.firstChild);
}

function AddBottom(el,bk,color,size){
var i;
var d=document.createElement("b");
var cn="r";
var lim=4;
if(size && size=="small"){ cn="rs"; lim=2}
d.className="rbottom";
d.style.backgroundColor=bk;
for(i=lim;i>0;i--){
    var x=document.createElement("b");
    x.className=cn + i;
    x.style.backgroundColor=color;
    d.appendChild(x);
    }
el.appendChild(d,el.firstChild);
}

function getElementsBySelector(selector){
var i;
var s=[];
var selid="";
var selclass="";
var tag=selector;
var objlist=[];
if(selector.indexOf(" ")>0){  //descendant selector like "tag#id tag"
    s=selector.split(" ");
    var fs=s[0].split("#");
    if(fs.length==1) return(objlist);
    return(document.getElementById(fs[1]).getElementsByTagName(s[1]));
    }
if(selector.indexOf("#")>0){ //id selector like "tag#id"
    s=selector.split("#");
    tag=s[0];
    selid=s[1];
    }
if(selid!=""){
    objlist.push(document.getElementById(selid));
    return(objlist);
    }
if(selector.indexOf(".")>0){  //class selector like "tag.class"
    s=selector.split(".");
    tag=s[0];
    selclass=s[1];
    }
var v=document.getElementsByTagName(tag);  // tag selector like "tag"
if(selclass=="")
    return(v);
for(i=0;i<v.length;i++){
    if(v[i].className==selclass){
        objlist.push(v[i]);
        }
    }
return(objlist);
}
//================= Cookies ====================
function setCookie(name, value)
         {
         //If name is the empty string, it places a ; at the beginning
         //of document.cookie, causing clearCookies() to malfunction.
         if(name != '')
            document.cookie = name + '=' + value;
         }

function getCookie(name)
         {
         //Without this, it will return the first value 
         //in document.cookie when name is the empty string.
         if(name == '')
            return('');
         
         name_index = document.cookie.indexOf(name + '=');
         
         if(name_index == -1)
            return('');
         
         cookie_value =  document.cookie.substr(name_index + name.length + 1, 
                                                document.cookie.length);
         
         //All cookie name-value pairs end with a semi-colon, except the last one.
         end_of_cookie = cookie_value.indexOf(';');
         if(end_of_cookie != -1)
            cookie_value = cookie_value.substr(0, end_of_cookie);

         //Restores all the blank spaces.
         space = cookie_value.indexOf('+');
         while(space != -1)
              { 
              cookie_value = cookie_value.substr(0, space) + ' ' + 
              cookie_value.substr(space + 1, cookie_value.length);
							 
              space = cookie_value.indexOf('+');
              }

         return(cookie_value);
         }