function leerCookie(nombre) {
   a = document.cookie.substring(document.cookie.indexOf(nombre + '=') + nombre.length + 1,document.cookie.length);
   if(a.indexOf(';') != -1)a = a.substring(0,a.indexOf(';'))
   return a; 
}


function exiteCookie () {
	
	
	if ( getCookie("micoleccionBSK") == "vacio" ) { 
			return (false); 
	} else {
			
			return (true);
		
	}

}

function setCookie(cookieName,cookieValue,expires,path,domain,secure) {

	document.cookie=escape(cookieName)+'='+escape(cookieValue)+(expires?'; EXPIRES='+expires.toGMTString():'')+(path?'; PATH='+path:'')+(domain?'; DOMAIN='+domain:'')+(secure?'; SECURE':'');

}

function getCookie(cookieName) {
	
	var cookieValue="vacio";
	
	var posName=document.cookie.indexOf(escape(cookieName)+'=');
	
	if (posName!=-1) {
		
		var posValue=posName+(escape(cookieName)+'=').length;
		
		var endPos=document.cookie.indexOf(';',posValue);
		
		if (endPos!=-1) cookieValue=unescape(document.cookie.substring(posValue,endPos));
		
		else cookieValue=unescape(document.cookie.substring(posValue));
	}
	return cookieValue;
} 


function crearCookieSession () {
	var valor_actual = new String();
	var ahora=new Date();
	var manyana=new Date(ahora.getTime()+1000*60*60*24) 
	setCookie('micoleccionBSK','init;',manyana); 
}


function addToCollectionGallery() {

	if(!navigator.cookieEnabled) {
		
		alert ("Para crear tu colección debes tener activadas las cookies en tu navegador.");

	}else{
	
		//addingAviso();
		if (!exiteCookie()) { // si la cookie NO existe deberemos crearla con un ID determinado	
			
				crearCookieSession();
				contador = devuelveImagenActual();
				valor_actual = getCookie("micoleccionBSK");				
				valor_actual = valor_actual+"coleccion_bsk:"+array_imagenes[contador]+";";
				var ahora=new Date();
				var manyana=new Date(ahora.getTime()+1000*60*60*24) 
				setCookie('micoleccionBSK',valor_actual,manyana); 
				
		} else { // concatenamos el valor del item seleccionado 
		
				contador = devuelveImagenActual();
		
				if (!(isAlreadyAdded("coleccion_bsk:"+array_imagenes[contador]+";"))) {
		
				
				valor_actual = getCookie("micoleccionBSK");				
				valor_actual = valor_actual+"coleccion_bsk:"+array_imagenes[contador]+";";
				var ahora=new Date();
				var manyana=new Date(ahora.getTime()+1000*60*60*24) 
				setCookie('micoleccionBSK',valor_actual,manyana); 
				
				}else{
				
					addingAviso();
					
				}
			
		
		}
	}
}



function isAlreadyAdded(element) {
	

	var temp_cookie = new String(); 

	if (exiteCookie()) {


		temp_cookie = getCookie("micoleccionBSK");		
	
		if (temp_cookie == null) { crearCookieSession(); }
		
		posicion = temp_cookie.indexOf(element);
		
		if (posicion == -1) {
		
		//	alert("not added yet");
			return(false);
		
		}else{
			
		//	alert("already added!!");
			return (true);
			
		}
	}else{
		
		 return(false);
			
	}

	

	
}


function addToCollection(id,cruz,added) {

	if(!navigator.cookieEnabled) {
		
		alert ("Para crear tu colección debes tener activadas las cookies en tu navegador.");

	}else{
	
		//addingAviso();
		if (!exiteCookie()) { // si la cookie NO existe deberemos crearla con un ID determinado	
			
				crearCookieSession();
				valor_actual = getCookie("micoleccionBSK");	
				valor_actual = valor_actual+"coleccion_bsk:"+id+";";
				var ahora=new Date();
				var manyana=new Date(ahora.getTime()+1000*60*60*24) 
				setCookie('micoleccionBSK',valor_actual,manyana); 
				
		} else { // concatenamos el valor del item seleccionado 
		
			if (!(isAlreadyAdded("coleccion_bsk:"+id+";"))) {	
				
				
				valor_actual = getCookie("micoleccionBSK");	
				valor_actual = valor_actual+"coleccion_bsk:"+id+";";
				var ahora=new Date();
				var manyana=new Date(ahora.getTime()+1000*60*60*24) 
				setCookie('micoleccionBSK',valor_actual,manyana); 
				
			}
			
		
		}
		
		document.getElementById(cruz).src = "./images/seccion-coleccion/col_nav_already_added_icon.png";
		document.getElementById(added).src = "./images/seccion-coleccion/es_col_nav_btn0_already_added.gif";	
		
	}
}


function addToCollectionLookbook(id,cruz,added,div) {

	if(!navigator.cookieEnabled) {
		
		alert ("Para crear tu colección debes tener activadas las cookies en tu navegador.");

	}else{
	
		//addingAviso();
		if (!exiteCookie()) { // si la cookie NO existe deberemos crearla con un ID determinado	
			
				crearCookieSession();
				valor_actual = getCookie("micoleccionBSK");	
				valor_actual = valor_actual+"lookbook_bsk:"+id+";";
				var ahora=new Date();
				var manyana=new Date(ahora.getTime()+1000*60*60*24) 
				setCookie('micoleccionBSK',valor_actual,manyana); 
				
		} else { // concatenamos el valor del item seleccionado 
		
			if (!(isAlreadyAdded("coleccion_bsk:"+id+";"))) {	
				
				
				valor_actual = getCookie("micoleccionBSK");	
				valor_actual = valor_actual+"lookbook_bsk:"+id+";";
				//alert(valor_actual);
				var ahora=new Date();
				var manyana=new Date(ahora.getTime()+1000*60*60*24) 
				setCookie('micoleccionBSK',valor_actual,manyana); 
				
			}
			
		
		}
		
		document.getElementById(cruz).src = "./images/seccion-lookbook/col_nav_already_added_icon.png";
		document.getElementById(added).src = "./images/seccion-lookbook/es_col_nav_btn0_already_added.gif";	
		document.getElementById(div).style.left = "353px";
		document.getElementById(div).style.visibility = "visible";
	}
}



function marcaComoAdded(cruz,added) {

	document.getElementById(cruz).src = "./images/seccion_estilismo/col_nav_already_added_icon.png";
	document.getElementById(added).src = "./images/seccion_estilismo/es_col_nav_btn0_already_added.gif";	
	
}

function addToCollectionEstilismo(orden,id,cruz,added,div) {

	if(!navigator.cookieEnabled) {
		
		alert ("Para crear tu colección debes tener activadas las cookies en tu navegador.");

	}else{
	
	//addingAviso();
	if (!exiteCookie()) { // si la cookie NO existe deberemos crearla con un ID determinado	
			
				
				crearCookieSession();
				valor_actual = getCookie("micoleccionBSK");				
				valor_actual = valor_actual+"estilismo_bsk:"+orden+"_"+id+";";
				var ahora=new Date();
				var manyana=new Date(ahora.getTime()+1000*60*60*24) 
				setCookie('micoleccionBSK',valor_actual,manyana); 
				
		} else { // concatenamos el valor del item seleccionado 
		
				
			
				if (!(isAlreadyAdded("estilismo_bsk:"+orden+"_"+id))) {
			
					valor_actual = getCookie("micoleccionBSK");				
					valor_actual = valor_actual+"estilismo_bsk:"+orden+"_"+id+";";
					var ahora=new Date();
					var manyana=new Date(ahora.getTime()+1000*60*60*24) 
					setCookie('micoleccionBSK',valor_actual,manyana); 
	
				}
	
		}
		
		
	document.getElementById(cruz).src = "./images/seccion_estilismo/col_nav_already_added_icon.png";
	document.getElementById(added).src = "./images/seccion_estilismo/es_col_nav_btn0_already_added.gif";
	document.getElementById(div).style.left = parseInt(document.getElementById(div).style.left) + 13 + "px";
	
	
		
	}	
}