var popupWin_1 = new Array();
var popupWin_2 = new Array();


function winopen(url, w, h) 
{
  var left = (screen.width) ? (screen.width-w)/2 : 0;
  var top  = (screen.height) ? (screen.height-h)/2 : 0;

  window.open(url, "_blank", "width="+w+",height="+h+",left="+left+",top="+top+",resizable=yes,scrollbars=yes");
  
  return;
}

function winopen2(url,target, w, h) 
{
  var left = (screen.width) ? (screen.width-w)/2 : 0;
  var top  = (screen.height) ? (screen.height-h)/2 : 0;

 if(popupWin_2[target] != null)
	if(!popupWin_2[target].closed)
		popupWin_2[target].focus();
	else
		popupWin_2[target] = window.open(url, target, "width="+w+",height="+h+",left="+left+",top="+top+",resizable=yes,scrollbars=yes");
  else
	popupWin_2[target] = window.open(url, target, "width="+w+",height="+h+",left="+left+",top="+top+",resizable=yes,scrollbars=yes");
  
  return;
}


function winopencustom(url, target, p) 
{
  window.open(url, target, p);
  return;
}

function winopenprompt(url, w, h,resize,scrollbar) 
{
  var left = (screen.width) ? (screen.width-w)/2 : 0;
  var top  = (screen.height) ? (screen.height-h)/2 : 0;

  window.open(url, "_blank", "width="+w+",height="+h+",left="+left+",top="+top+",resizable="+resize+",scrollbars="+scrollbar);
  
  return;
}

function winopenprompt2(url,target, w, h,resize,scrollbar) 
{
  var left = (screen.width) ? (screen.width-w)/2 : 0;
  var top  = (screen.height) ? (screen.height-h)/2 : 0;

  if(popupWin_1[target] != null)
	if(!popupWin_1[target].closed)
		popupWin_1[target].focus();
	else
		popupWin_1[target] = window.open(url, target, "width="+w+",height="+h+",left="+left+",top="+top+",resizable="+resize+",scrollbars="+scrollbar);
  else
	popupWin_1[target] = window.open(url, target, "width="+w+",height="+h+",left="+left+",top="+top+",resizable="+resize+",scrollbars="+scrollbar);
  
  return;
}

function ToggleDisplayWks(button, item, cid)
{
  if (button.src.indexOf("dot.gif") == -1 ) {
    if ((item.style.display == "") || (item.style.display == "none")) {
      item.style.display = "block";
      button.src = "/images/wk_minus.gif";
	  writecookie('WkSpaceTree', cid, 0)
	} else {
      item.style.display = "none";
  	  button.src = "/images/wk_plus.gif";
	  writecookie('WkSpaceTree', cid, 1)
    }
  }
  return false;
}

function getcookie(cookiename) 
{   
  var search = cookiename + "="   
  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 writecookie(cookiename,item,newvalue) 
{   
	if((document.cookie.indexOf(cookiename + "=")) != -1)
	{
		var cookiearray = getcookie(cookiename).split("&")
		
		var cookiefound = false
		
		// loop through the array and checks or the identifier equals the item paramater
        // if yes replace the current value for the newvalue parameter 
		for (var i = 0; i < cookiearray.length; i++)
		{
			var string2check = cookiearray[i].split("=")
			if (string2check[0] == item)
				{
					string2check[0]
					cookiearray[i] = string2check[0] + "=" + newvalue
					cookiefound = true
				}
		}
		
		//Add new value to the array
		if (cookiefound == false)
			cookiearray[cookiearray.length] = item + "=" + newvalue
		
		//Build a new cookiestring
		var newcookie = ""
		
		for (var i = 0; i < cookiearray.length; i++)
			if (cookiearray[i] != "")
  			newcookie = newcookie +  cookiearray[i]	+ "&"		
	
    document.cookie = cookiename + "=" + newcookie;
	}
	else
  	document.cookie = cookiename + "=" + item + "=" + newvalue + "&";
}
