// JavaScript Document

function goToUrl(selObj, goToLocation) 
	{
    eval("document.location.href = '" + goToLocation + selObj.options[selObj.selectedIndex].value + "'");
	}

function HideElement(Element_ID)
	{
	var objElement 				= document.getElementById(Element_ID);
	objElement.style.display 	= 'none';
	}

function DisplayElement(Element_ID)
	{
	var objElement 				= document.getElementById(Element_ID);

	if (objElement.tagName == 'TABLE' && navigator.appName != 'Microsoft Internet Explorer') 
		{
		objElement.style.display = 'table';
		}
	else
		{
		objElement.style.display = 'block';
		}
	}	

function ToggleElement(Element_ID,Field_ID,Field_Value) 
	{
	var objElement = document.getElementById(Element_ID);
	
	if (objElement.style.display != 'none') 
		{
		objElement.style.display = 'none';
		}
	else if (objElement.tagName == 'TABLE' && navigator.appName != 'Microsoft Internet Explorer') 
		{
		objElement.style.display = 'table';
		}
	else
		{
		objElement.style.display = 'block';
		}
	
	if (Field_ID && Field_Value)
		{
		TransferElementValue(Field_ID,Field_Value);
		}
	}

function ToggleImage(Element_ID) 
	{
	var theImg 		= document.getElementById(Element_ID);
	var Image		= theImg.src;
	var StrStart	= Image.indexOf('mp_minus_s.gif'); 

	if (StrStart > '0') 
		{
		theImg.src = '/img/cms/mp_plus_s.gif'
		}
	else
		{
		theImg.src = '/img/cms/mp_minus_s.gif'
		}
	}

function ToggleParentToChild(Element_ID_Self, Element_ID,ElementType,Attribute,Value)
	{
	var objElementSelf	= document.getElementById(Element_ID_Self);
	var objElement 		= document.getElementById(Element_ID);
	var Checked			= false;
	
	if (!ElementType) 	var ElementType = 'input';
	if (!Attribute)		var Attribute 	= 'type';
	if (!Value)			var Value 		= 'checkbox';

	if (objElementSelf.checked == true)
		{
		Checked = true;
		}
	else
		{
		Checked = false;
		}

	objElementSelf.checked = Checked;

	var Fields = objElement.getElementsByTagName(ElementType);
	
	for (i=0; i < Fields.length; i++)
		{
		var AttributeTMP = Fields[i].getAttribute(Attribute);
		
		if (AttributeTMP == Value && Value == 'checkbox')
			{
			Fields[i].checked = Checked;
			}
		}
	}
	
function TransferElementValue(Field_ID,Field_Value)
	{
	var objField 	= document.getElementById(Field_ID);
	var objValue 	= document.getElementById(Field_Value);
	
  	if (document.selection && document.selection.createRange)  // Internet Explorer
  		{
    	sel = document.selection.createRange();

		objValue.value = sel.text;
		}
  	else if (objField != "undefined")  // Firefox & safari, etc...
 		{
		var textLength 	= parseInt(objField.textLength);
		var selStart 	= objField.selectionStart;
		var selEnd 		= objField.selectionEnd;

		if (selStart != selEnd)
			{
			objValue.value = objField.value.substring(selStart,selEnd);
			}
		}
	}

function ValueArray_Remove(Value,ArrayList)
	{
	// REMOVING A VALUE FROM AN ARRAY IS KINDA TRICKY (DAMN YOU JAVASCRIPT! IMPROVE ALREADY!)
	// Removing a value means the keys of the array may no longer match up with the length of an array.
	// Using splice to remove the value doesn't solve this. 
	// Hence why I'm creating a new array altogether.
	
	var Array_TMP = new Array();
	
	for(dt=0; dt < ArrayList.length;dt++) 
		{
		if (Value != ArrayList[dt])
			{
			Array_TMP.push(ArrayList[dt]);
			}
		}

	return Array_TMP;
	}

function AssignValue(Element_ID,Value)
	{
	var objElement 				= document.getElementById(Element_ID);
	objElement.value 			= Value;	
	}
	
function AssignOnClick(Element_ID,Action)
	{
	var objElement 				= document.getElementById(Element_ID);
	objElement.onclick 			= Action;	
	}
	
function OpenLightBox(ImageName,Path,Title,Description)
	{
	var objBody 					= document.getElementsByTagName("body").item(0);
	var objLightBox 				= document.createElement("div");

	objLightBox.setAttribute('id','LightBox');
	objLightBox.onclick 			= function () {CloseLightBox(); return false;}
	objLightBox.style.display 		= 'block';
	objLightBox.style.position 		= 'absolute';
	objLightBox.style.border 		= 'none';
	objLightBox.style.top 			= '0%';
	objLightBox.style.left 			= '0%';
	objLightBox.style.margin 		= '0px';
	objLightBox.style.padding		= '30px';
	objLightBox.style.zIndex 		= '90';
 	objLightBox.style.textAlign		= 'center';
	objLightBox.style.width 		= document.body.clientWidth + 'px';
 	objLightBox.style.background	= '#575757';
	objBody.insertBefore(objLightBox, objBody.firstChild);
	
	if (Title)
		{
		var TitleText				= document.createTextNode(Title);	
		var objTitle 				= document.createElement("div");
		objTitle.setAttribute('id','LightBoxTitle');
		objTitle.style.width 		= '100%';
		objTitle.style.height 		= '20px';
		objTitle.style.fontSize 	= '12pt';
		objTitle.style.color 		= '#D1C0AA';
		
		objTitle.appendChild(TitleText);
		alert(TitleText);
		objLightBox.insertBefore(objTitle,objLightBox.firstChild);
		}

	var WidthTMP					= document.body.clientWidth - 60;
	var HeightTMP					= document.body.clientHeight - 60;
	var objImage 					= document.createElement("img");
	objImage.setAttribute('id','Image');
	objImage.setAttribute('src',Path + '/' + ImageName);
	objImage.style.position 		= 'relative';
	
	var Y = objImage.height;
	var X = objImage.width;
	
	//alert ('Image Object ' + objImage.height + ' / ' + objImage.width + "\n");

	/*
	if (objImage.height > HeightTMP)
		{
		var Percentage 		= HeightTMP / objImage.height;
		
		objImage.height 	= HeightTMP;
		objImage.width		= Math.floor(objImage.width * Percentage);
		objImage.style.top 	= '30px'
		objImage.style.left	= ((document.body.clientWidth - objImage.width) / 2) + 'px';
		}
	else if (objImage.width > WidthTMP)
		{
		var Percentage 		= WidthTMP  / objImage.width;
		
		objImage.width 		= WidthTMP;
		objImage.height		= Math.floor(objImage.Height * Percentage);
		objImage.style.top 	= ((document.body.clientHeight - objImage.height) / 2) + 'px';
		objImage.style.left	= '30px'
		}
	else
		{
		objImage.style.top 	= ((document.body.clientHeight - objImage.height) / 2) + 'px';
		objImage.style.left	= ((document.body.clientWidth - objImage.width) / 2) + 'px';
		}
	*/
	//alert ('Image Object ' + objImage.height + ' / ' + objImage.width + "\n");
	//alert ('Position ' + objImage.style.top + ' / ' + objImage.style.left + "\n");
	
	objLightBox.insertBefore(objImage,objLightBox.lastChild);
	}

function CloseLightBox()
	{
	var objLightBox 	= document.getElementById('LightBox');
	var objImage 		= document.getElementById('Image');
	
	objLightBox.style.display 		= 'none';
	objImage.style.display 			= 'none';
	}

