
function AbsUrl(sAbsUrl)
{
	if(sAbsUrl.length==0 || sAbsUrl.indexOf(":")>=0)
		return sAbsUrl;
		
	var sLocation = location.pathname.toLowerCase().split("\\").join("/");
	var iIndex    = -1;
		
	if(sAbsUrl.substr(0,1)!='/')
		iIndex = sLocation.lastIndexOf("/")+1;

	if(iIndex==-1)	iIndex = sLocation.indexOf("/pilot/");
	if(iIndex==-1)	iIndex = sLocation.indexOf("/toolkit_homepage/");
	if(iIndex==-1)	iIndex = sLocation.indexOf("/mod1/");
	if(iIndex==-1)	iIndex = sLocation.indexOf("/mod2/");
	if(iIndex==-1)	iIndex = sLocation.indexOf("/mod3/");
	if(iIndex==-1)	iIndex = sLocation.indexOf("/mod4/");
	if(iIndex==-1)	iIndex = sLocation.indexOf("/mod5/");
	if(iIndex==-1)	iIndex = sLocation.indexOf("/toolkit/");
	if(iIndex==-1)	iIndex = sLocation.indexOf("/default.aspx-pid=318.htm");

	var sRoot = location.pathname.substr(0, iIndex);

	return sRoot+sAbsUrl;
}

function GotoUrl(sUrl)
{
	window.location = AbsUrl(sUrl);
}

function Popup(url)
{
	var wnd = window.open(AbsUrl(url),"","toolbar=no,,width=650,height=550,directories=no,status=no,scrollbars=yes,resize=yes,menubar=no");
        
    if(wnd!=null)	wnd.focus();
    else			alert("Popup window cannot be opened.");
}

function PopupBig(url)
{
	var wnd = window.open(AbsUrl(url),"","toolbar=no,,width=800,height=600,directories=no,status=no,scrollbars=yes,resize=yes,menubar=no");
        
    if(wnd!=null)	wnd.focus();
    else			alert("Popup window cannot be opened.");
}

function _CO(OptionList) 
{
   for (x = OptionList.length; x >= 0; x--) 
   {
      OptionList[x] = null;
   }
}

function _RO(OptionList)
{
	_CO(OptionList);
	for(var i=0; i<8; ++i) _AO1(OptionList,"");
}

function _AO1(OptionList, OptionText) 
{
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionText);
}

function _AO2(OptionList, OptionText, OptionValue) 
{
   // Add option to the bottom of the list
   OptionList[OptionList.length] = new Option(OptionText, OptionValue);
}

// MENU FUNCTIONS

function _ML()
{
	document.writeln("<tr><td colspan=2><img src='/images/ms.gif' height=2 width=150></td></tr>")
}

function _MIO(sTitle, sUrl)
{
	_ML()
	document.writeln("<tr><td><img src='/Images/AB.gif'></td><td height=18 width=135><a href='"+sUrl+"' class=mlink>"+sTitle+"</a></td></tr>")
}

function _MIC(sTitle, sUrl)
{
	_ML()
	document.writeln("<tr><td><img src='/Images/AR.gif'></td><td height=18 width=135><a href='"+sUrl+"' class=mlink>"+sTitle+"</a></td></tr>")
}

function _MIS(sTitle, sUrl)
{
	document.writeln("<tr bgcolor=FAFCF8><td>&nbsp;</td><td height=18 width=135><a href='"+sUrl+"' class=mlink>"+sTitle+"</a></td></tr>")
}

function _MS(sTitle)
{
	_ML()
	document.writeln("<tr><td colspan=2 height=18 width=135><span class=mlinkb>&nbsp;&nbsp;"+sTitle+"</span></td></tr>")
}


function _DelWarning()
{
	event.returnValue=window.confirm('You are about to delete this item. Are you sure you wish to continue?');
	return event.returnValue;
}

function EditList_Init(sID)
{
	var oList  = document.forms[0].elements[sID+":CSelection"];
	var oValue = document.forms[0].elements[sID+":CValue"];
	
	var sValues = oValue.value.split(";");
	
	for(var i=0; i!=sValues.length; ++i)
	{
		var sValue = sValues[i].replace(/&s/g, ";").replace(/&a/g, "&");
	
		if(sValue!="")
			oList.options[oList.options.length] = new Option(sValue, sValue);
	}
}

function EditList_Add(sID)
{
	var oVoc   = document.forms[0].elements[sID+":CVocabulary"];
	var oText  = document.forms[0].elements[sID+":COther"];
	var oValue = document.forms[0].elements[sID+":CValue"];
	var oList  = document.forms[0].elements[sID+":CSelection"];
	
	var sNew = oText.value;
	
	if(sNew=="")
		sNew = oVoc.options[oVoc.selectedIndex].text;
	
	oList.options[oList.options.length] = new Option(sNew, sNew);

	oText.value = "";
	oVoc.value = "";
	
	EditList_Rebuild(sID);
}

function EditList_Rebuild(sID)
{
	var oValue = document.forms[0].elements[sID+":CValue"];
	var oList  = document.forms[0].elements[sID+":CSelection"];
	
	oValue.value = "";
	
	for(var i=0; i!=oList.options.length; ++i)
	{
		var sText  = oList.options[i].text;
		var sValue = sText.replace(/&/g, "&a").replace(/;/g, "&s");
		
		oValue.value += sValue + ";";
	}
}

function EditList_Del(sID)
{
	var oList  = document.forms[0].elements[sID+":CSelection"];
	
	if(oList.selectedIndex>=0)
		oList.options[oList.selectedIndex] = null;
	
	EditList_Rebuild(sID)
}

function OnPrintVersion(bShow)
{
	if(document.all)
	{
		if(document.all["CHeaderRow"])
		{
			document.all["CHeaderRow"  ].style.display = bShow ? "" : "none";
			document.all["CLeftHolder" ].style.display = bShow ? "" : "none";
			document.all["CRightHolder"].style.display = bShow ? "" : "none";
	//		document.all["CFooterMenu" ].style.display = bShow ? "" : "none";
			document.all["CHideMenu"   ].style.display = bShow ? "" : "none";
			document.all["CShowMenu"   ].style.display = bShow ? "none" : "";
		}
		else
		{
			document.all["tdLeft"   ].style.display = bShow ? "" : "none";
			document.all["CHideMenu"].style.display = bShow ? "" : "none";
			document.all["CShowMenu"].style.display = bShow ? "none" : "";
		}
	}
	else if (document.getElementById)
	{
		if(document.getElementById("CHeaderRow"))
		{
			document.getElementById("CHeaderRow"  ).style.display = bShow ? "" : "none";
			document.getElementById("CLeftHolder" ).style.display = bShow ? "" : "none";
			document.getElementById("CRightHolder").style.display = bShow ? "" : "none";
	//		document.getElementById("CFooterMenu" ).style.display = bShow ? "" : "none";
			document.getElementById("CHideMenu"   ).style.display = bShow ? "" : "none";
			document.getElementById("CShowMenu"   ).style.display = bShow ? "none" : "";
		}
		else
		{
			document.getElementById("tdLeft"   ).style.display = bShow ? "" : "none";
			document.getElementById("CHideMenu").style.display = bShow ? "" : "none";
			document.getElementById("CShowMenu").style.display = bShow ? "none" : "";
		}
	}
}

function mie(event)
{
	var elem = event.srcElement!=null ? event.srcElement : event.target;

	elem.obc = elem.style.backgroundColor;
	elem.style.backgroundColor = "#C5C5B1";
}

function mil(event)
{
	var elem = event.srcElement!=null ? event.srcElement : event.target;

	elem.style.backgroundColor = elem.obc;
}

function mic(event)
{
	var elem = event.srcElement!=null ? event.srcElement : event.target;
	
	var url = elem.url!=null ? elem.url : elem.getAttribute("url");
	
	GotoUrl(url);
}

//=================================

function cbd_confirm(i_sMsg)    { U_YesNo(i_sMsg); }

//---------------------------------------------------------------------
// U_YesNo: Prompt for user confirmation
//---------------------------------------------------------------------
function U_YesNo(i_sMsg) { 
	event.returnValue = confirm(i_sMsg); 
}

//== CMS FUNCTIONS ================

function CmsDragStart(args)
{
	event.dataTransfer.setData("text", args);
}

function CmsDragEnterOver()
{
	var data = event.dataTransfer.getData("text");
	
	if(data.match("^WebContent,[0-9]+,[0-9]+,[0-9]+$"))
	{
		event.srcElement.style.backgroundColor = "#ff8100";

		window.event.returnValue=false;
	}
}

function CmsDragLeave()
{
	event.srcElement.style.backgroundColor = "#E0E0E0";
}

function CmsDrop(clientID)
{
	event.srcElement.style.backgroundColor = "#E0E0E0";

	__doPostBack(clientID, event.dataTransfer.getData("text"));
}

function ShowDialog(url, width, height)
{	

	url = url + "&dt=" + new Date().valueOf();

	window.showModalDialog(url, '', 'dialogHeight: '+height+'px; dialogWidth: '+width+'px; edge: Raised; center: Yes; help: No; resizable: No; status: No;');
}
