function Set_Cookie( name, value, expires, path, domain, secure )
               {
                  // set time, it's in milliseconds
                  var today = new Date();
                  today.setTime( today.getTime() );

                  /*
                     if the expires variable is set, make the correct
                     expires time, the current script below will set
                     it for x number of days, to make it for hours,
                     delete * 24, for minutes, delete * 60 * 24
                  */
                  if ( expires )
                  {
                     expires = expires * 1000 * 60 * 60;
                  }
                  var expires_date = new Date( today.getTime() + (expires) );

                  document.cookie = name + '=' +escape( value ) +
                  ( ( expires ) ? ';expires=' + expires_date.toGMTString() : '' ) +
                  ( ( path ) ? ';path=' + path : '' ) +
                  ( ( domain ) ? ';domain=' + domain : '' ) +
                  ( ( secure ) ? ';secure' : '' );
               }

 function Get_Cookie(name) {
   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
}

/* escapeOverlay's construction is a bit hard to grasp. It is needed to be able to
stop the event listener. See the prototype API docs for more information:
http://www.prototypejs.org/api/event
*/
var escapeOverlay = {
	fx: function(e)
	{
		// To make script compatable with both MSIE and Firefox
		var kC  = (window.event) ? event.keyCode : e.keyCode;
		var Esc = (window.event) ? 27 : e.DOM_VK_ESCAPE;

		// If keypressed is escape and the new entry field is empty
		if(kC==Esc && ($F('newvalue') == '' || $F('newvalue') == null) )
			closeDialogue();
		else if(kC==Esc && window.confirm('Are you sure you wish to close the dialogue box?') )
			closeDialogue();
	}
}

// Save in cache (to be able to stopObserving() it), see Prototype API docs for more info:
// http://www.prototypejs.org/api/event
escapeOverlay.bfx = escapeOverlay.fx.bindAsEventListener(escapeOverlay);

// loadPopup shows the overlay and dialogue box
function loadPopup1()
{
 if(Get_Cookie('xl2vote1') == 'doneVoteX'){

 }else{
    	// Show the overlay (disables rest of page)
	showOverlay();

	//scroll to top
	scroll(0,0)

	//hide flash stuff
	//$('flashBannerHolder').hide();

	//set body overflow style
	document.body.style.overflow="hidden";

	// Show dialogue and focus on newvalue
	$('dialogue1').show();
	$('newvalue').focus();
  }
  
  function Delete_Cookie(name,path,domain) {
   if (Get_Cookie(name)) document.cookie = name + "=" +
      ( (path) ? ";path=" + path : "") +
      ( (domain) ? ";domain=" + domain : "") +
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
}


}

function loadPopup2()
{
    	// Show the overlay (disables rest of page)
	showOverlay();

	//scroll to top
	scroll(0,0)

	//hide flash stuff
	$('flashBannerHolder').hide();

	//set body overflow style
	document.body.style.overflow="hidden";

	// Show dialogue and focus on newvalue
	$('dialogue2').show();
	$('newvalue').focus();
}

// Shows the overlay and starts the ESCAPE event listener
function showOverlay()
{
	$('overlay').show();

	Event.observe(document, 'keypress', escapeOverlay.bfx );
}

// Hides the overlay and stops the ESCAPE event listener
function hideOverlay()
{
	$('overlay').hide();

	Event.stopObserving(document, 'keypress', escapeOverlay.bfx );
}

// Closes the dialogue box, resets it and hides the overlay
function closeDialogue1()
{
	Set_Cookie( 'xl2vote1', 'doneVoteX', 1, '/', '', '' );

	hideOverlay();

	//show flash stuff again
	//$('flashBannerHolder').show();

	//set body overflow style
	document.body.style.overflow="visible";

	// Hide dialogue
	$('dialogue1').hide();
	$('dialogue2').hide();

	// Clear dialogue
	$('newvalue').value = '';


}

function closeDialogue2()
{
	Set_Cookie( 'xl2vote2', 'doneVoteX', 1, '/', '', '' );

	hideOverlay();

	//show flash stuff again
	$('flashBannerHolder').show();

	//set body overflow style
	document.body.style.overflow="visible";

	// Hide dialogue
	$('dialogue1').hide();
	$('dialogue2').hide();

	// Clear dialogue
	$('newvalue').value = '';


}

/* Event handler for onKeyPress for the newvalue field. Enables the use of the ENTER (RETURN)
key when adding a new entry in the dialogue box */
function enterKey(event, field)
{
	// If the event key pressed was a return (code 13)
	if (event.which == 13 || event.keyCode == 13)
		addEntry(field.value);
}

// count is used to number the entries LI IDs
var count = 1;

// Adds an entry
function addEntry(message)
{
	// Close the dialogue
	closeDialogue();

	// If the value entered for the new entry is not empty
	if (message != '' && message != null)
	{
		// Build a new LI, set its value and id and add it
		newLI= Builder.node('li', {id: count});
		newLI.innerHTML = message;
		count++;

		// Append the new LI to the entries UL
		$('entries').appendChild(newLI);
	}
}


