////////////////////////////////////////////////////////////////////////////////
// BEGIN
//

	function showCanvas()
	{
		// Window Size
		windowSize();
		
		var w = document.body.scrollWidth;
		var h = document.body.scrollHeight;
		
		if( myHeight > h )
			h = myHeight;
			
		if( myWidth > w )
			w = myWidth;
		
		// Create Canvas
		var canvas = document.createElement( "div" );
			canvas.id = "canvas";
			canvas.innerHTML = "&nbsp;";
			canvas.className = "canvas";
			canvas.style.width = w + "px";
			canvas.style.height = h + "px";
			canvas.style.visibility = "visible";
			document.body.appendChild( canvas );
	}
	
	function removeCanvas()
	{
		var canvasJS = document.getElementById( "canvas" );
			document.body.removeChild( canvasJS );
	}
	
	function showNewsletter()
	{
		// Canvas
		showCanvas();
		
		var w = document.body.scrollWidth;
		var h = document.body.scrollHeight;
		
		if( myHeight > h )
			h = myHeight;
			
		if( myWidth > w )
			w = myWidth;
		
		var newsletter = document.createElement( "div" );
			newsletter.id = "newsletter";
			newsletter.className = "newsletter";
			newsletter.style.top = ((h-320) / 2) + "px";
			newsletter.style.left = ((w-515) / 2) + "px";
			newsletter.innerHTML = "<iframe name=\"_newletter_\" src=\"newsletter.php\" frameborder=\"0\" style=\"height: 100%; width: 100%;\"></iframe>";
			document.body.appendChild( newsletter );
	}
	
	function removeNewsletter()
	{
		var newsletterJS = document.getElementById( "newsletter" );
			document.body.removeChild( newsletterJS );
			
		removeCanvas();
	}
	
	function showImage( path, imageID )
	{
		// Canvas
		showCanvas();
		
		var w = document.body.scrollWidth;
		var h = document.body.scrollHeight;
		
		if( myHeight > h )
			h = myHeight;
			
		if( myWidth > w )
			w = myWidth;
		
		// Create Image Container
		var myImageContainerJS = document.createElement( "div" );
			myImageContainerJS.id = "myImageContainer";
			myImageContainerJS.className = "posABS";
			myImageContainerJS.style.visibility = "hidden";
		
		var today=new Date()
		var time=today.getSeconds()
		var myImageJS = document.createElement( "img" );
			myImageJS.id = "myImage";
			myImageJS.className = "myBorder myGalleryImage";
			myImageJS.src = path+"?"+time.valueOf();;
			
			myImageJS.onload = function()
			{
				var myImageContainerJS = document.getElementById( "myImageContainer" );
				
				var objW = this.width;
				var objH = this.height;
				myImageContainerJS.style.top = (((h-objH) - 50) / 2) + "px";
				myImageContainerJS.style.left = ((w-objW) / 2) + "px";
				myImageContainerJS.style.width = (objW+2) + "px";
				myImageContainerJS.style.height = (objH+2) + "px";
				//myImageContainerJS.appendChild( this );	
				myImageContainerJS.style.visibility = "visible";
			}
		
		var myImageTextJS = document.createElement( "div" );
			myImageTextJS.id = "myImageText";
			myImageTextJS.style.height = "50px";
			myImageTextJS.style.overflow = "auto";
			myImageTextJS.style.backgroundColor = "#000000";
			myImageTextJS.style.padding = "5px";
			myImageTextJS.style.color = "#FFFFFF";
		
		var myImageTitleJS = document.createElement( "div" );
			myImageTitleJS.innerHTML = document.getElementById( "myTitle_" + imageID ).value;
			
		var myImageDescJS = document.createElement( "div" );
			myImageDescJS.innerHTML = document.getElementById( "myDesc_" + imageID ).value;
			myImageDescJS.style.textAlign = "left";
			
		var myClose = document.createElement( "div" );
			myClose.innerHTML = "X";
			myClose.className = "myClose";
			myClose.style.color = "#FFFFFF";
			myClose.style.backgroundColor = "#000000";
			myClose.onclick = function () { removeImage(); }
			
		
		
		document.body.appendChild( myImageContainerJS );
		myImageContainerJS.appendChild( myClose );
		myImageContainerJS.appendChild( myImageJS );
		myImageContainerJS.appendChild( myImageTextJS );
		myImageTextJS.appendChild( myImageTitleJS );
		myImageTextJS.appendChild( myImageDescJS );
	}
	
	function removeImage()
	{
		var myImageJS = document.getElementById( "myImageContainer" );
			document.body.removeChild( myImageJS );
			
		removeCanvas();
	}

	var myWidth = 0, myHeight = 0;
	function windowSize()
	{
		if( typeof( window.innerWidth ) == 'number' )
		{
			//Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		}
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
		{
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		}
		else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
		{
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
	}
//
// END
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// MENU.JS 
// Author:		Brenden Tarasoff
// Created:		28.10.2005
// Description:	This file will handle all the menu and menu related functions
//				within the Content Management System (CMS). 
////////////////////////////////////////////////////////////////////////////////
	
////////////////////////////////////////////////////////////////////////////////
// BEGIN
//

	function loadedDates()
	{
		var obj = document.getElementById( "dates" );
		var curdates = false;
		
		if( obj!=null && obj.options!=null)
		{
			// Determine if this option already exists
			curdates = new Array();
			for( i = 0; i < obj.options.length; i++ )
			{
				curdates[i] = obj.options[i].value;
			}
		}
		return curdates;
	}
	
	function dumpDate(target, date_show, date_value)
	{
		var obj = document.getElementById( "dates" );
		var index;
		var addOption = true;
		
		if( obj!=null && obj.options!=null )
		{
			// Determine if this option already exists
			for( i = 0; i < obj.options.length; i++ )
			{
				if( obj.options[i].value == date_value ) { addOption = false; index = i; }
			}
			
			if( addOption ) { obj.options[obj.options.length] = new Option(date_show, date_value, false, false); }
			else
			{
				obj.options[index] = null;
			}
			
			// Sort the respective date array
			sortSelect( obj );
			selectAllOptions( obj );
		}
		
		//document.getElementById(target).value = date_value;
		//document.getElementById(target + "_disp").value = date_show;
		//hideCal(target);
	}
	
	function hasOptions( obj )
	{
		if( obj != null && obj.options!=null ) { return true; }
		return false;
	}
	
	function selectAllOptions(obj){if(!hasOptions(obj)){return;}for(var i=0;i<obj.options.length;i++){obj.options[i].selected = true;}}
	function selectUnselectMatchingOptions(obj,regex,which,only){if(window.RegExp){if(which == "select"){var selected1=true;var selected2=false;}else if(which == "unselect"){var selected1=false;var selected2=true;}else{return;}var re = new RegExp(regex);if(!hasOptions(obj)){return;}for(var i=0;i<obj.options.length;i++){if(re.test(obj.options[i].text)){obj.options[i].selected = selected1;}else{if(only == true){obj.options[i].selected = selected2;}}}}}
	function selectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"select",false);}
	function selectOnlyMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"select",true);}
	function unSelectMatchingOptions(obj,regex){selectUnselectMatchingOptions(obj,regex,"unselect",false);}
	function sortSelect(obj){var o = new Array();if(!hasOptions(obj)){return;}for(var i=0;i<obj.options.length;i++){o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;}if(o.length==0){return;}o = o.sort(
	function(a,b){if((a.text+"") <(b.text+"")){return -1;}if((a.text+"") >(b.text+"")){return 1;}return 0;});for(var i=0;i<o.length;i++){obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);}}
	function removeSelectedOptions(from){if(!hasOptions(from)){return;}if(from.type=="select-one"){from.options[from.selectedIndex] = null;}else{for(var i=(from.options.length-1);i>=0;i--){var o=from.options[i];if(o.selected){from.options[i] = null;}}}from.selectedIndex = -1;}

//
// END
////////////////////////////////////////////////////////////////////////////////
