
var rightCaret = String.fromCharCode (62);

function openWin( windowURL, windowName, windowFeatures )
{return window.open( windowURL, windowName, windowFeatures );}

function displayChildren(sMenu){
   var d = document.getElementById(sMenu);
   if (d.className == "clsHiddenMenu")
      d.className = "clsVisibleMenu";
   else
      d.className = "clsHiddenMenu";
}

function InsertTags (tagName) {
	if (tagName == "")
		return (false);	
	var selectionRange = getSelectionRange ();
	if (selectionRange != null) {
		var currentText = selectionRange.text;
		var preText = "<" + tagName + rightCaret;
		var postText = "</" + tagName + rightCaret;
		replaceText (selectionRange, preText, postText, currentText);
   }
}
function getSelectionRange () {
	var selectionRange = document.selection.createRange ();
	if (isEditable (selectionRange)) {
      var currentText = selectionRange.text;
		if (currentText != "")
			return (selectionRange);			
   }
   return (null);
}

function isEditable (selectionRange) {
   if (selectionRange.parentElement().tagName == "TEXTAREA")
      return (true);
   return (false);
}

function replaceText (selectionRange, preText, postText, currentText) {
	currentText=RTrim(currentText);
	selectionRange.text = preText + currentText + postText + " ";
	selectionRange.parentElement ().focus ();
}

function RTrim(str)
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
          i--;
      s = s.substring(0, i+1);
   }
   return s;
}

function LaunchImageManager(){
   window.showModalDialog("/admin/imageManager.asp", "select:no", "resizable:no; help:no; status:no; scroll:no; font-size:14px; dialogWidth:700px; dialogHeight:520px;");
}  
function LaunchResourceManager(){ 
   window.showModalDialog("/admin/resourceManager.asp", "select:no", "resizable:no; help:no; status:no; scroll:no; font-size:14px; dialogWidth:700px; dialogHeight:450px;");
}  
function pickImageFile(el){
   var sResult = window.showModalDialog("/admin/imageManager.asp", "value:" + el.value, "resizable:no; help:no; status:no; scroll:no; font-size:14px; dialogWidth:700px; dialogHeight:520px;");
   if (sResult != "cancel") el.value = sResult;
}   
function pickResourceFile(el, dir){
   var args = "value:" + el.value;
   if (dir)
      args += ";root:" + dir;
   var sResult = window.showModalDialog("/admin/resourceManager.asp", args, "resizable:no; help:no; status:no; scroll:no; font-size:14px; dialogWidth:700px; dialogHeight:520px;");
   if (sResult != "cancel") el.value = sResult;
}

function viewFile(el){
   if (el.value != "")
      window.open(el.value);
   else
      alert("Please select a file first.");
}
function clearSetting(el){
   el.value = "";
}		
function checkName(el)
{
	var allowKey = false;
	var keyCode = window.event.keyCode;
	switch (true)
	{
		case (el.value.length >= 50):
			allowKey = false;
			break;
		case (keyCode == 45):
		case ((keyCode >= 48) && (keyCode <= 57)): 
		case ((keyCode >= 65) && (keyCode <= 90)):
		case ((keyCode >= 97) && (keyCode <= 122)):
			allowKey = true;
			break;
		default:
			allowKey = false;
			break;
	}
	window.event.returnValue = allowKey;
}
function checkKey(){
   var e = window.event;
   if (e.keyCode == 13) 
      submitForm();
   e.cancelBubble = true;
}

function testLink(obj) {
	var testObj = document.getElementById(obj).value;
	if (testObj.indexOf("http://")>-1) { 
		
	}
	else { 
		testObj = "http://" + testObj
	}
	javascript:window.open(testObj);
}
/* Color Picker Functions */
var colorPickerTarget = null;
function setSelectedColor(color)
{
	if (!ValidateColor(color))
		return;
	var el = document.getElementById('selectedColor');
	if (el)
	{
		el.style.backgroundColor = color;
		el.innerText = color;
		switch (color.substr(3,1))
		{
			case 'F':
			case 'E':
			case 'D':
			case 'C':
			case 'B':
			case 'A':
			case '9':
				el.style.color = "#000000";
				break;
			case '8':
			case '7':
			case '6':
			case '5':
			case '4':
			case '3':
			case '2':
			case '1':
			case '0':
				el.style.color = "#ffffff";
				break;
		}
	}
}
function ValidateColor(sValue) 
{
	sValue = sValue.toUpperCase();
	
	if (sValue.length != 7)
		return false;
		
	if (sValue.substr(0,1) != '#')
		return false;
	
	for (var i=1; i<=6; i++)
	{	
		switch (sValue.substr(i, 1))
		{
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
			case 'A':
			case 'B':
			case 'C':
			case 'D':
			case 'E':
			case 'F':
				break;
			default:
				return false;
				break;
		}
	}
	return true;
}

function colorPanelOkButton_onclick()
{
	colorPickerTarget.innerText = document.getElementById('selectedColor').innerText;
	hideColorPicker();
}
function colorPanelCancelButton_onclick()
{
	hideColorPicker();
}
function hideColorPicker()
{
	var colorPicker = document.getElementById("colorPanel");
	colorPicker.style.left = -9999;
	colorPickerTarget = null;
}
function showColorPicker(el)
{
	if (el)
	{
		colorPickerTarget = el;
	
		var colorPicker = document.getElementById("colorPanel");
		if (colorPicker)
		{
			colorPicker.style.top = getTop(window.event.srcElement);
			colorPicker.style.left = getLeft(window.event.srcElement);
			
			setSelectedColor(colorPickerTarget.value);
			
			colorPicker.style.display = 'block';
		}
	}
}
function getTop(el)		
	{
		var topPos = el.offsetTop;
		el = el.parentElement.offsetParent
		while (el)
		{
			topPos = topPos + el.offsetTop;
			el = el.offsetParent;
		} 
		return topPos;
	}		
	function getLeft(el)
	{
		var leftPos = el.offsetLeft;
		el = el.parentElement.offsetParent
		while (el)
		{
			leftPos = leftPos + el.offsetLeft;
			el = el.offsetParent;
		} 
		return leftPos;		
	}

	
