﻿var chosen_var=0;
var exit_was=0;
var was_click = 0;

//-------------------универсальный прием куков----------------------
		
function getCookie(Name) {
   var search = Name + "=";
   if (document.cookie.length > 0) { // если есть какие-либо куки
      offset = document.cookie.indexOf(search);
      if (offset != -1) { // если кука существует 
         offset += search.length;
         // установить индекс начала значения
         end = document.cookie.indexOf(";", offset);
         // установить индекс конца значения куки
         if (end == -1)
            end = document.cookie.length;
         return unescape(document.cookie.substring(offset, end));
      } 
   }
}

//-------------------универсальная задача куков--------------------
function setCookie(name, value, expire) {
   document.cookie = name + "=" + escape(value)
   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
}



function over()
	{
		document.getElementById("personalization").style.display="block"; 
		was_click=1;
		//потому что когда указатель на квадратиках то получается, что не на блоке, а на квадратиках и блок отключается, значит когда на квадратиках надо блок снова включить.
		
		current_bg=document.getElementById("body").style.backgroundImage;
		current_bg_color=document.getElementById("body").style.backgroundColor;
		
		if(this.id=="green1"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/green1.gif")';
			document.getElementById("body").style.backgroundColor="#d4e7e4";
		}
		if(this.id=="green2"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/green2.gif")';
			document.getElementById("body").style.backgroundColor="#ecf2d7";
		}
		if(this.id=="red"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/red.gif")';
			document.getElementById("body").style.backgroundColor="#f5e8dc";
		}
		if(this.id=="grey"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/grey.gif")';
			document.getElementById("body").style.backgroundColor="#e2e2e2";
		}
		if(this.id=="yellow"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/yellow.gif")';
			document.getElementById("body").style.backgroundColor="#ffedc7";
		}
	}	

function out(){
		if(chosen_var != 1)
		{
			document.getElementById("body").style.backgroundImage=current_bg;
			document.getElementById("body").style.backgroundColor=current_bg_color;
		}
		if (was_click == 0)
			{
			document.getElementById('personalization').style.display='block';
			}
		else
		{
			was_click= 0;
		}
	}
	
function chosen(){
		document.getElementById("personalization").style.display="none";
		
		chosen_var=1;
		
		if(this.id=="green1"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/green1.gif")';
			document.getElementById("body").style.backgroundColor="#d4e7e4";
			setCookie("bg_color", "color=green1");
		}
		if(this.id=="green2"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/green2.gif")';
			document.getElementById("body").style.backgroundColor="#ecf2d7";
			setCookie("bg_color", "color=green2");
		}
		if(this.id=="red"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/red.gif")';
			document.getElementById("body").style.backgroundColor="#f5e8dc";
			setCookie("bg_color", "color=red");
		}
		if(this.id=="grey"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/grey.gif")';
			document.getElementById("body").style.backgroundColor="#e2e2e2";
			setCookie("bg_color", "color=grey");
		}
		if(this.id=="yellow"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/yellow.gif")';
			document.getElementById("body").style.backgroundColor="#ffedc7";
			setCookie("bg_color", "color=yellow");
		}
	}
	

function cookie_chek(){
		var bg_color_cookie = getCookie("bg_color");
		
		if (bg_color_cookie=="color=green1"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/green1.gif")';
			document.getElementById("body").style.backgroundColor="#d4e7e4";
			setCookie("bg_color", "color=green1");
		}
		if (bg_color_cookie=="color=green2"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/green2.gif")';
			document.getElementById("body").style.backgroundColor="#ecf2d7";
			setCookie("bg_color", "color=green2");
		}
		if (bg_color_cookie=="color=red"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/red.gif")';
			document.getElementById("body").style.backgroundColor="#f5e8dc";
			setCookie("bg_color", "color=red");
		}
		if (bg_color_cookie=="color=grey"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/grey.gif")';
			document.getElementById("body").style.backgroundColor="#e2e2e2";
			document.cookie = "color=grey";
			setCookie("bg_color", "color=grey");
		}
		if (bg_color_cookie=="color=yellow"){
			document.getElementById("body").style.backgroundImage='url("/img/default/base/yellow.gif")';
			document.getElementById("body").style.backgroundColor="#ffedc7";
			setCookie("bg_color", "color=yellow");
		}
	}

var event_tag = "-";

function see_tag(a){
	a = a || window.event;
	var a = a.target || a.srcElement;
	
	event_tag = a;
	return false;
}

function personalization_off(){
		if ((event_tag.tagName == "Ul") || (event_tag.tagName == "LI"))
		{
			a = "-";
		}
		else
		{
			this.style.display='none';
			exit_was=1;
		}
	}
	
//Лого овер	
function personalization_on()
	{
		if (exit_was == 0)
			document.getElementById('personalization').style.display='block';
		else
			exit_was=0;
	}
	
//выход не на логотип	
function exit_on_header(b)
{
	exit_was=0;
	
	b = b || window.event;
	/*
	b = b.target || b.srcElement;
	*/
	
	
	if ((/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) || (/MSIE (7).+Win/.test(navigator.userAgent)) || (/MSIE (8).+Win/.test(navigator.userAgent)))
	{
		if (b.srcElement.id == "header")
		document.getElementById('personalization').style.display='none';
	}
	else if (b.target.id == "header")
		document.getElementById('personalization').style.display='none';
}




