var selectedGals=new Array();

function addOrDelGal(id, name) {
	//first try to del
	wuzFound=false;
	for (var i=0; i<selectedGals.length; i++) {
		if (selectedGals[i]) {
			if (selectedGals[i][0]==id) {
				delete selectedGals[i];
				wuzFound=true;
			}
		}
	}
	
	//then if not found - add
	if (!wuzFound) {
		selectedGals.push(new Array(id,name));
	}
	
	printSelectedGals();
	
}


function printSelectedGals() {
	
	//сначала  удалим прежнее
	var deletePoint = document.getElementById('selectedGalsDiv');
    for (i=0; i<=deletePoint.childNodes.length;i++) {
	   	if (deletePoint.hasChildNodes())
			deletePoint.removeChild(deletePoint.lastChild);
    }
	
    var newUl	= document.createElement("ul");
    
	for (var i=0; i<selectedGals.length; i++) {
		if (selectedGals[i]) {
			
			var newLi = document.createElement("li");
			var newText = document.createTextNode(selectedGals[i][1]);
			
			newLi.appendChild(newText);
			
			//newImg = document.createElement("img");
			//newImg.src="/skins/3dmsk/i/del_sm.gif";
			//newLi.appendChild(newImg);
			
			newUl.appendChild(newLi);
		}
	}
	
	var node = document.getElementById("selectedGalsDiv");
	node.appendChild(newUl);
}




var cookieName = "picook";

function setCookie(Cookie, value, expiredays)
  {
          var ExpireDate = new Date ();
          ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
          document.cookie = Cookie + "=" + escape(value) +
          ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
  }

  function getCookie(Cookie)
  {
          if (document.cookie.length > 0)
          {
                  begin = document.cookie.indexOf(Cookie+"=");
                  if (begin != -1)
                  {
                          begin += Cookie.length+1;
                          end = document.cookie.indexOf(";", begin);
                          if (end == -1) end = document.cookie.length;
                          return unescape(document.cookie.substring(begin, end));
                  }
          }
          return null;
  }

  function CatLoadMenu()
  {
          cookieMenu = getCookie(cookieName);
          
       // alert ("Loading:" +cookieMenu);
         // alert(divNames.length);
          
          var idArray=cookieMenu.split("|");
       
          if(cookieMenu != null)
          {
                  for(i = 1; i < idArray.length-1; i++)
                  {
                  	if (idArray[i]) {
                  		trees[0].toggle(idArray[i]);	
                  	}
                  }
          }
  }

  function CatSaveMenu()
  {
  
  	//alert("onbeforeunload happend");
  	
          var cookiestring = '|';
		
          
          for(i = 0; i < divNames.length; i++)
          {
          	if (divNames[i]) {
 				  var block = document.getElementById("i_div0_"+divNames[i]);
                  
                  if(block.style.display == 'block')
                  {
                          cookiestring += divNames[i] + '|';
                  }	          		
          		
          	}
                 
          }
		
          //alert ("Saveed: " +cookiestring);
          setCookie(cookieName,cookiestring,1);
  }


function findObj(n, d) { 
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function switchClass(id,action,nClass) {
	if (action=='over') {
		id.className=nClass;

	}
	else if (action=='out') {
		id.className=nClass;	
	}
}
