// always-include-ie.js  Copyright 1998-2004 PaperThin, Inc. All rights reserved.

bName = navigator.appName;
bVer = parseInt(navigator.appVersion);

var bCanRollover=0
if (bName == "Netscape")
{
	if(bVer >= 3)
		bCanRollover=1;
}
else if (bName == "Microsoft Internet Explorer")
{
	if(bVer >= 4)
		bCanRollover=1;
}

function ImageSet(imgID,newTarget)
{
	if (bCanRollover)
		document[imgID].src=newTarget;
}
function clearStatus()
{
	window.status = "";
}
function setStatbar(statbar)
{
	var strStatbar=unescape(statbar);
	window.status=strStatbar;
}
function onLoadComplete()
{
	if( menus_included == 1 )
		document.onmouseover = document_mouseover;	// defined in menu_ie.js
}
function HandleLink(parentID,link,displaylink) 
{
	// links are in one of the following formats:
	// 		cpe_60_0,CP___PAGEID=100
	// 		CPNEWWIN:WindowName^params@CP___
	// 			CPNEWWIN:child^top=110:left=130:ww=140:hh=150:tb=1:loc=1:dir=0:stat=1:mb=1:sb=1:rs=1@CP___PAGEID=3811,Adv-Search-2.cfm,1
	// displaylink is the server relative URL or fully qualified URL
	if( jsPageAuthorMode == 0 )
	{
		windowname = "";
		windowparams = "";

		// "CPNEWWIN:" & NewWindowName & "^" & params & "@" & linkStruct.LinkURL; 
		pos = link.indexOf("CPNEWWIN:");
		if (pos != -1)
		{
			pos1 = link.indexOf ("^");
			windowname = link.substring (pos+9, pos1);
			pos2 = link.indexOf ("@");
			windowparams = link.substring (pos1 + 1, pos2);
			link = link.substring (pos2 + 1, link.length);
		}
		
		if( displaylink && displaylink != "" )
		{		
			if (windowname == "")
				window.location = displaylink;
			else
			{
				windowparams = FormatWindowParams(windowparams);
				window.open (displaylink, windowname, windowparams);
			}
		}
		else
		{
			targetLink = link;

			if (link.indexOf ("CP___") != -1)
			{

				httpPos = -1;
				commaPos = link.indexOf(",");
				if (commaPos != -1)
				{
					targetUrl = link.substr(commaPos + 1);
					if (targetUrl.indexOf("://") != -1 || targetUrl.indexOf("/") == 0)
					{
							httpPos = commaPos + 1;
					}		
				}

		
				if (httpPos != -1)
					targetLink = link.substr(httpPos);
				else
					targetLink = jsDlgLoader + "?url=/commonspot/utilities/handle-link.cfm&thelink=" + link;
				
				if (windowname == "")
					window.location = targetLink;
				else
				{
					windowparams = FormatWindowParams(windowparams);
					window.open (targetLink, windowname, windowparams);
				}
			}
			else
			{
				if (windowname == "")
					window.location = link;
				else
				{
					windowparams = FormatWindowParams(windowparams);
					window.open (link, windowname, windowparams);
				}
			}
		}
	}
	else if( jsSessionPreviewON == 1 )
	{
		previewLink(link);
	}
	else
	{
		if( document.all[parentID] )
			document.all[parentID].click();
	}
}
function doWindowOpen(href,name,params)
{
	window.open (href, name, params);
}

// 	CPNEWWIN:child^top=110:left=130:ww=140:hh=150:tb=1:loc=1:dir=0:stat=1:mb=1:sb=1:rs=1@CP___PAGEID=3811,Adv-Search-2.cfm,1
function FormatWindowParams(windowparams)
{
	if( windowparams.indexOf(":loc=") != -1 || windowparams.indexOf(":ww=") != -1 || windowparams.indexOf(":hh=") != -1 || 
	    windowparams.indexOf(":left=") != -1 || windowparams.indexOf(":top=") != -1 )
	{
		windowparams = substringReplace(windowparams,':left=',',left=');
		windowparams = substringReplace(windowparams,'left=','left=');
		windowparams = substringReplace(windowparams,':ww=',',width=');
		windowparams = substringReplace(windowparams,'ww=','width=');		
		windowparams = substringReplace(windowparams,':hh=',',height=');
		windowparams = substringReplace(windowparams,'hh=','height=');
		windowparams = substringReplace(windowparams,':loc=',',location=');
		windowparams = substringReplace(windowparams,'loc=','location=');
		windowparams = substringReplace(windowparams,':dir=',',directories=');
		windowparams = substringReplace(windowparams,'dir=','directories=');
		windowparams = substringReplace(windowparams,':tb=',',toolbar=');
		windowparams = substringReplace(windowparams,'tb=','toolbar=');
		windowparams = substringReplace(windowparams,':stat=',',status=');
		windowparams = substringReplace(windowparams,':mb=',',menubar=');
		windowparams = substringReplace(windowparams,':sb=',',scrollbars=');
		windowparams = substringReplace(windowparams,':rs=',',resizable=');
	}
	return windowparams;
}
function substringReplace(source,pattern,replacement)
{
	var pos = 0;
	var target="";
	while ((pos = source.indexOf(pattern)) != (-1))
	{
		target = target + source.substring(0,pos) + replacement;
		source = source.substring(pos+pattern.length);
		pos = source.indexOf(pattern);
	}
	return (target + source);
}
// handle scheduled element links
function show_sched_element(eid)
{
	evalCol = String(self.element_collection);
	dispFlag = false;
	ua = navigator.userAgent.toLowerCase();
	if (bName == "Netscape" || ua.indexOf('aol') >= 0)
	{
		// cloned from always-include-ns.js
		str = self.location.search;
		
		arrCtrls = new Array;
		for (i=0;i < self.element_collection.length;i++){
			sitem = self.element_collection[i];
			if (sitem.id == eid)
				arrCtrls[arrCtrls.length] = sitem.ctrl + "-" + eid;
		}

		dispFlag = arrCtrls.length != 0;
		// Look for the existing forceElement array		
		if (str != ""){
			qArray = str.split("&");
			forceElement = new Array();
			forceElementIndex = -1;
			for(i=0; i < qArray.length; i++)
			{
				el = qArray[i];
				qel = el.split('=');
				if  (qel.length == 1)
					qel[1] = '';
				if  (qel[0] == 'forceElement' || qel[0] == '?forceElement'){
					forceElement = qel[1].split(",");					
					forceElementIndex = i;
					break;
				}
			}	
			
			if (0 == forceElement.length)
				newLocation = str + "&forceElement=" + arrCtrls.join(",");
			else{	// There is a forceElement
				arrCtrlsCnt = arrCtrls.length;
				for (i=0;i < forceElement.length;i++){				// Loop over the existing elements
					iel = forceElement[i].split("-");
					for (j=0;j < arrCtrlsCnt;j++){
						jel = arrCtrls[j].split("-");
						if (jel[0] == iel[0])									// Is it the same control
							break;
					}
					if (j == arrCtrls.length)								// We reached the end  and did not find the control
						arrCtrls[arrCtrls.length] = forceElement[i];
				}
				qel = qArray[forceElementIndex].split("=");
				qArray[forceElementIndex] = qel[0] + "=" + arrCtrls.join(",");
				newLocation = qArray.join("&");
			}
		}
		else
			newLocation = "?forceElement=" + arrCtrls.join(",");
			
		self.location.search = newLocation;

		if  (!dispFlag)
			alert("You do not have access to the requested element.");
	
	}
	else
	{
		if ( evalCol != 'undefined' )
		{		
			for(i=0;i<self.element_collection.length;i++)
			{
				sitem = self.element_collection[i];
				sp = 'sched_elements_' + sitem.ctrl + '_' + sitem.id;
				obj = document.all.item(sp);
				if ( sitem.id == eid && obj != null)
				{
					dispFlag = true;
					if ( obj.length >= 0 )
					{
						for(z=0;z<obj.length;z++)
						{
							obj(z).style.display = 'block';
						}
					}
					else 
						document.all(sp).style.display = 'block';
					
					for (j=0;j < self.element_collection.length;j++){
						if (sitem.ctrl == self.element_collection[j].ctrl && i != j){
							sp = 'sched_elements_' + self.element_collection[j].ctrl + '_' + self.element_collection[j].id;
							obj = document.all.item(sp);

							if ( obj != null )
							{
								if ( obj.length >= 0 )
								{	
									for(z=0;z<obj.length;z++)
									{
										obj(z).style.display = 'none';
									}
								}
								else
									document.all(sp).style.display = 'none';
							}
						}
					}
				}
			}
		}

		if ( !dispFlag )
			alert("You do not have access to the requested element.")
	}
}


