var servletName = "dcms"
var myURL = window.location.href
var channel = decodeChannel()

function switchToIFrameR(elementID, docID, server, dbPath, width, height) {
	var divElement = document.getElementById(elementID)
//	alert("dbPath="+dbPath)
	divElement.innerHTML="<iFrame width=" + width + " height=" + height + " src=\"" + dbPath+"/0/"+
	docID + "?EditDocument\" frameborder=\"0\"></iFrame>"
}
function isValidRSSURL(rssURL) {
	if (rssURL.indexOf("servlet/dcms") > -1 || 
		rssURL.indexOf("&docID=") > -1 || 
		rssURL.indexOf("https:") > -1)  {
		alert("This URL is not a valid RSS feed. The URL must not include 'https', 'servlet/dcms', or &docID'.")
		return false
	} else {
		return true
	}
}

function getAgentAdvancedSearchLink() {
	window.location.href= getAgentAdvancedSearchURL()
}

// the following two functions were taken from IBM's common.js
// This method is used when we need to have a handle on closing child windows on logout. It
// takes in the same parameters as window.open. We need to use this for opening all popup windows
// that need window management
function doAddWindow(url, wTitle) {
	if (wTitle== null) {
		addWindow(url,"stdPopup")		
	} else {
		addWindow(url, wTitle)
	}
}

// this function copied from Murali.. for use in the Agent Desktop banner area
function popUpWindowFromBanner(theWindowLink,theWindowTitle,theWindowParams) {
	popUpDefaultParams = 'width=640,height=480,directories=0,location=0,menubar=1,toolbar=1,titlebar=1,statusbar=1,resizable=1,scrollbars=1,alwaysRaised=1,status=1';
	thePopUpParams = popUpDefaultParams;
	if (theWindowParams == null || theWindowsParams == 'undefined' || theWindowParams.length < 1)
	{
		thePopUpParams = popUpDefaultParams; 
	} else {
		thePopUpParams = theWindowParams;
	}
	addWindow(theWindowLink, theWindowTitle, thePopUpParams);
}
//
function addWindow(url, title, windowParams) {
        var aWindow = null;
        var invalids = "!@#$%^&*()-~,'<.>/?;:\|";         
 
        for(i=0; i < title.length; i++) {
                var tempVal = title.charAt(i);                 
 
                for(k=0; k < invalids.length; k++) {
                        var tempInvalidVal = invalids.charAt(k);                         
                        if(tempVal == tempInvalidVal || tempVal == " ") {                                 
 
 
                                title = title.replace(title.charAt(i),"_");                        
                        }                         
                }                         
        } 
 

        if(windowParams == null) {
 //       alert("in addWindow 3")
                aWindow = window.open(url, title,'width=640,height=480,directories=no,location=yes,menubar=yes,toolbar=yes,titlebar=yes,resizable=yes,scrollbars=yes,alwaysRaised=yes,status=yes');
                aWindow.focus();
                openedWinsTitle[openedWinsTitle.length] = title; 
                openedWins[openedWins.length] = aWindow; 
        }
        else {
        
                aWindow = window.open(url, title, windowParams);
                aWindow.focus();
                openedWinsTitle[openedWinsTitle.length] = title;                 
                openedWins[openedWins.length] = aWindow;                                 
        }    
        // different from EUD version
        persistWindows()
        return aWindow     
} 
 
// Called on the body onUnload tag in order to keep track of the windows opened with addWindow
// dy 20070130 This is invoked always from addWindow. The onUnLoad event is not predictable enough.
function persistWindows() {
//alert("start persistWindows")
        if (openedWinsTitle.length > 0) {                     
                    // get existing cookie value 
                    var cookieGoodies = getCookie(cookieName);     
                    // create additional cookie values 
                    var moreCookieText = ''; 
                    if (openedWinsTitle) { 
                        for(i=0; i<openedWinsTitle.length; i++){ 
                                var winName = openedWinsTitle[i]; 
                                var winHnd = openedWins[i]; 
                                if (winHnd && winHnd.open && !winHnd.closed) {         
                                        moreCookieText += openedWinsTitle[i] + delimiter; 
                                    } 
                        } 
                    } 
                    // create the new cookie 
                createCookie(cookieName, cookieGoodies + moreCookieText); 
        } 
//alert("end persistWindows")        
} 

function launchEmail(emailURL) {
//launchApplication(emailURL)
	addWindow(emailURL, "FFICMsgCtr","width=640,height=480,directories=no,menubar=yes,titlebar=yes,resizable=yes,scrollbars=yes,alwaysRaised=yes,status=yes, left=40, top=50")
}

function swapImage(object,imgURL) {
	object.src=junctionName() + imgURL
}
/*
function getWebsealJunction() {
	if (location.href.indexOf("https://lb04") > -1) {
		return "/eudhp";
	} 
	
	if (location.href.indexOf("desktopdev") > -1) {
		return "/eudhpdev";
	}
	
	if (location.href.indexOf("desktoptest") > -1) {
		return "/eudhptest";
	}
	if (location.href.indexOf("desktopuat") > -1) {
		return "/eudhpuat";
	}
	if (location.href.indexOf("desktopcert") > -1) {
		return "/eudhpcert";
	}
	if (location.href.indexOf("https://desktop.")  > -1){
		return "/eudhpprod";
	}
	if (location.href.indexOf("https://agentdesktop.") > -1) {
		return "/eudhpprod";
	}
}
*/
function useAddWindow(url, title, params) {
	addWindow(url, title, params);
}
function openDCMSHelp() {
	addWindow(junctionName() + '/dcms/desktophelp.nsf/vwHelpByKey/DCMSDesktop?openDocument','DCMSDesktopHelp');
}
// two functions needed to show/hide the Desktop Directory Popup
function hoverDirectory() {
	showDesktopDirectory()
}
function hideDesktopDirectory() {
	desktopDirectoryDiv = document.getElementById("desktopDirectory")
	desktopDirectoryDiv.style.visibility="hidden"
	docListSelectionPulldown = document.getElementById("docListSelectionSpan")
	if (docListSelectionPulldown) {
		docListSelectionPulldown.style.visibility="visible"
	}
//add other lines if needed
}

function showDesktopDirectory() {
	desktopDirectoryDiv = document.getElementById("desktopDirectory")
	desktopDirectoryDiv.style.visibility="visible"
	docListSelectionPulldown = document.getElementById("docListSelectionSpan")
	if (docListSelectionPulldown) {
		docListSelectionPulldown.style.visibility="hidden"
	}
}

function getCategoryLink(link) {
	var cTemp = ""
	var cLoc = myURL.indexOf("category=")
	var cTempStart = ""
	var cStartLoc = myURL.indexOf("&startIndex=")
//	alert(cStartLoc)
	if (cStartLoc > -1) {
		cTempStart = myURL.substring(cStartLoc + 12)
//		alert(cTempStart)
		cStartLoc = cTempStart.indexOf("&")
		if (cStartLoc > -1) {
			cTempStart = cTempStart.substring(0, cStartLoc)
//			alert(cTempStart)
		}
	}
	if (cLoc>-1) {
		cTemp = myURL.substring(cLoc+9)
		cLoc = cTemp.indexOf("&")
		if ( cLoc > -1) {
			cTemp = cTemp.substring(0,cLoc)
		}
	}
	if (cTemp=="") {
		cTemp="All Documents"
	}
	
	cTemp = replaceSubstring(cTemp,"%20"," ")
	var newLink = link + "&startIndex=" + cTempStart + "&category=" + cTemp + '">' + "Return to " + replaceSubstring(cTemp,"%26","&") + '</a>'
	return newLink
}

function toggleSummaries() {
	var summariesState = WM_readCookie("DCMSSummaries")
	if (!summariesState) {
		summariesState="on"
	}
//	alert(summariesState)
	var summaries = document.getElementsByTagName("div")
	var j=0
	for (i = 0; i < summaries.length; i++){
		if (summaries[i].className == "documentListItemSummary") {
			if (summariesState=="on") {
				summaries[i].style.display="none"
				WM_setCookie("DCMSSummaries","off")
//				document.getElementById("showSummaries").style.visibility="visible"
//				document.getElementById("hideSummaries").style.visibility="hidden"
			}
			else {
				summaries[i].style.display="block"
				WM_setCookie("DCMSSummaries","on")
//				document.getElementById("hideSummaries").style.visibility="visible"
//				document.getElementById("showSummaries").style.visibility="hidden"
			}
		}
	}
}
function getSelectedItem(listItem) {
	return listItem.options[listItem.selectedIndex].text
}
function changeCategory(listitem) {
	var newCat = getSelectedItem(listitem)
	newCat = replaceSubstring(newCat, "&", "%26")
	var catPos = myURL.indexOf("&category=");
	var startPos = myURL.indexOf("&startIndex=");
	if (startPos == -1) {
		if (catPos == -1) {
			newURL=myURL+"&category=" + newCat
		} else {
			newURL = myURL.substring(0, catPos) + "&category=" + newCat
		}
	} else {
		newURL = myURL.substring(0, startPos) + "&category=" + newCat
	}
	location.href = newURL
}

function junctionName() {
	var junctionCookie = WM_readCookie("IV_JCT")
	if (junctionCookie) {
		return junctionCookie 
	} else {
		return ""
	}
}

function leftNavLink(newURL) {

	if (myURL.indexOf("https://desktop") > -1) {
		window.location = wpsRootURLDomino("desktop") + newURL;
	} else {
		if (myURL.indexOf("https://agentdesktop") > -1) {
			window.location = wpsRootURLDomino("agentdesktop") + newURL;
		} else {
			window.location = newURL
		}
	}
}
function getAgentLogoHTML(top, height, width, image, desktopLinkNeeded) {
	if (desktopLinkNeeded) {
		if (hasAgentDesktopCookie()) {
		} else {
			top = top - 14
		}
	}
	return	"\n<img border=\"0\" height=\"79\" width=\"1\" src=\"/icons/ecblank.gif\"/>" +
		"<div id=\"logoDiv\" " +
		"style=\"position:absolute; top:" + top + "px; left:6px;z-index:100\" height=\"" + height +
		"\" width=\"" + width + "\" visibility=\"visible\">" +
		"<a href=\"javascript:goToRootURL()\"><img height=\"" + height + "\" width=\"" + width + "\" src=\"/cms/images/" + image + "\" border=\"0\">" +
		"</a></div>";

	}
/*
function moveLogo() {
	if (hasAgentDesktopCookie()) {
	}
	else {
		var topChar = document.getElementById("logoDiv").style.top
		var topNum = 0
		topNum = parseInt(topChar.substr(0,topChar.length-2)) - 20
  		var topMoved = topNum + "px"
		document.getElementById("logoDiv").style.top=topMoved
	}
}
*/
function getEnvironment() {
	domain = myURL.substring(0, myURL.indexOf(".")+1);
	if (domain.indexOf("dev.") > -1 ) {
		return "dev";
	} else if (domain.indexOf("test.") > -1 ) {
		return "test";
	} else if (domain.indexOf("uat.") > -1 ) {
		return "uat";
	} else if (domain.indexOf("cert.") > -1 ) {
		return "cert";
	} else {
		return "";  // prod
	}	
}

function wpsRootURL(desktop, virtualPortal) {
	env = getEnvironment();
	var junction = "wps" + env  
	if (env=="" || env=="uat" || env== "cert") {  //i.e. production, uat and cert
		junction = "jctwps"
	} else {
		if (env=="test" && desktop == "desktop") {  
			junction = "eudtest"
		}
	}
	return "https://" + desktop + env + ".firemansfund.com/" + junction + 
		"/wps/myportal/" + virtualPortal
}
function wpsRootURLDomino(desktop) {
	env = getEnvironment();
	var junctionSuffix = env
	if (env=="") {
		junctionSuffix = "prod"
	}
	return "https://" + desktop + env + ".firemansfund.com/eudhp" + junctionSuffix
}


function websealRootURL(){
	if (channel == "agent411" || channel == "agentdesktop" || 
		channel == "agentdesktophelp") {
//		alert(wpsRootURLDomino("agentdesktop"))
		return wpsRootURLDomino("agentdesktop")
	}
	else {
		return ""  //wpsRootURLDomino("desktop")
	}
	/*
	if ( myURL.indexOf("https://lb04.firemansfund.com") > -1)        {
		return "https://lb04.firemansfund.com/eudhp";
	}  else {
		if ( myURL.indexOf("localhost") > -1)	{ 
			return "https://lb04.firemansfund.com/eudhp";
		}  else {
			if (myURL.indexOf("https://desktoptest.firemansfund.com") > -1) { //TEST
				return "https://desktoptest.firemansfund.com/eudhptest";
			}  else {
				if (myURL.indexOf("https://desktopcert.firemansfund.com") > -1) { //CERT
					return "https://desktopcert.firemansfund.com/eudhpcert";
				} else {
					if (myURL.indexOf("https://desktopuat.firemansfund.com") > -1) { 

//UAT
						return "https://desktopuat.firemansfund.com/eudhpuat";
					} else {
						if (myURL.indexOf("https://desktop.firemansfund.com") > -1) { 

//UAT
							return "https://desktop.firemansfund.com/eudhpprod";
						} else {
							return ""; // just a server relative link
						}
					}
				}
			}
		}	
	}
	*/
}

function getAgentChangePWURL() {
	var env=getEnvironment()
	var wpsURL = ""
	if (env=="dev") {
		wpsURL = "https://lb04.firemansfund.com/wasdev05s/RM/userInfoSetPassword.do"
	} else if (env=="test") {
		wpsURL = "https://lb03.firemansfund.com/wastest05s/RM/userInfoSetPassword.do"
	} else if (env == "uat") {
		wpsURL = "https://lbuat.firemansfund.com/jct05s/RM/userInfoSetPassword.do"
	} else if (env == "cert") {
		wpsURL = "https://lb02.firemansfund.com/jct05s/RM/userInfoSetPassword.do"
	} else {
		wpsURL = "https://lb01.firemansfund.com/jct05s/RM/userInfoSetPassword.do"
	}

	return  wpsURL	
}

function getAgentSiteMapURL() {
	var env=getEnvironment()
	var wpsURL = ""
	if (env=="dev") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLN4038vMGSUGYnvqRGGIeGGLOSEK-Hvm5qfpB-t76AfoFuaGhEeWOigDWtX-q/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82XzVfMk5M"
	} else if (env=="test") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLt4w3dnQGSUGYjvqRGGKWGGLOHgghX4_83FT9IH1v_QD9gtzQ0IhyR0UA7k717w!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82XzlfM0FE"
	} else if (env == "uat") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4w3MXYBSUGYjvqRGGKWGGJGHkjqfD3yc1P1g_S99QP0C3JDQyPKHRUB_xdrcA!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0FfNDNE"
	} else if (env == "cert") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4k3CbAASUGYZvqRGGKmaGKO8UaB_ggxX4_83FT9IH1v_QD9gtzQ0IhyR0UAzm-h4Q!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0RfNFA5"
//		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4w3CTAHSUGYZvqRGGKmaGL-8YauIQixIH1vfV-P_NxU_QD9gtzQ0IhyR0UAAVhx9A!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0FfNFA5"
//		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd443CbAASUGYZvqRGGKmmGJmLggxX4_83FT9IH1v_QD9gtzQ0IhyR0UAWwNa3w!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0NfNFA5"
	} else {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4k3DbMESUGYFvqRGGLmaGKO8YZGLggxX4_83FT9IH1v_QD9gtzQ0IhyR0UASvxWiw!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0RfNVZC"
//orig	wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4o3DbMESUGYFvqRGGLmmGLO_ggxX4_83FT9IH1v_QD9gtzQ0IhyR0UA2wkU1g!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0JfNVZC"
	}

	return  wpsURL	
}
function getAgentNewsURL() {
	var env=getEnvironment()
	var wpsURL = ""
	if (env=="dev") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLN4038vMCSUGYnvqRGGIeGGLOSEK-Hvm5qfpB-t76AfoFuaGhEeWOigD7z0xF/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82XzVfMk5L"
	} else if (env=="test") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLt4w3dnQCSUGYjvqRGGKWGGLOHgghX4_83FT9IH1v_QD9gtzQ0IhyR0UAwzTGAA!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82XzlfM0FD"
	} else if (env == "uat") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4w3MXYCSUGYjvqRGGKWGGJGHkjqfD3yc1P1g_S99QP0C3JDQyPKHRUBZluAqg!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0FfNDND"
	} else if (env == "cert") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4k3CTAHSUGYZvqRGGKmaGKO8UaB_gixIH1vfV-P_NxU_QD9gtzQ0IhyR0UAhTNa4A!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0RfNFA4"
//		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4w3CTAHSZnFOwOZZvqREAaSmCmmmJkLmpgjTK8jqpgpmph_vKFrCELM1yM_N1U_SN9bP0C_IDcUBCLKHR0VATd2Jis!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0FfNFA4" 
//		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd443CTAHSUGYZvqRGGKmmGJmLggxX4_83FT9IH1v_QD9gtzQ0IhyR0UARLkwMQ!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0NfNFA4"
	} else {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4k3DbMESUGYFvqRGGLmaGKO8YZGLgixIH1vfV-P_NxU_QD9gtzQ0IhyR0UAHhrHZA!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0RfNVZB"
//orig	wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4o3DbMESUGYFvqRGGLmmGLO_ggxX4_83FT9IH1v_QD9gtzQ0IhyR0UA2wkU1g!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0JfNVZB"
	}
	//wpsRootURL("agentdesktop", "agent")
//	alert(wpsURL)
	return  wpsURL	
}
function getAgentMyDesktopURL() {
	var env=getEnvironment()
	var wpsURL = ""
	if (env=="dev") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLN4038vMCSUGYnvqRGGIeGGLOSEJB-t76vh75uan6AfoFuaGhEeWOigCvKd2q/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82XzVfMk5K"
	} else if (env=="test") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLt4w3dnQCSUGYjvqRGGKWGGLOHgihIH1vfV-P_NxU_QD9gtzQ0IhyR0UAl9JX7w!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82XzlfM0FC"	
	} else if (env == "uat") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4w3MXYCSUGYjvqRGGKWGGJGHkjqgvS99X098nNT9QP0C3JDQyPKHRUBMr0RRQ!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0FfNDNC"
	} else if (env == "cert") {
		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vMAfIjzeNd4s0tjPTDchMrMnMzq1JT9CP0o8yAoiYBjiANEKaZfiSGmCmamGO8UaA_QszXIz83VT9I31s_AGQkzKLwotS8lNQi_YJci8rMTF1Hi3JHRQDM_xC0/delta/base64xml/L3dJdyEvd0ZNQUlzQUsvNElVRS82X0RfNFA3"
//		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4w3CbAASZnFOwOZZvqREIY5QswUU8zMBU3MEaYXyTxHmF4kMf94Q9cQhJivR35uqn6Qvrd-gH5BbigIRJQ7OioCABXmpBE!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0FfNFA3"
//		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd443CTAHSUGYZvqRGGKmmGJmLgixIH1vfV-P_NxU_QD9gtzQ0IhyR0UAEF-h3g!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0NfNFA3"
	} else {
	 	    wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4k3DXMESUGYFvqRGGLmaGKO8YZGLggxX4_83FT9IH1v_QD9gtzQ0IhyR0UAtjXHlQ!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0RfNVY5"
//orig		wpsURL = "/wps/myportal/agent/kcxml/04_Sj9SPykssy0xPLMnMz0vM0Y_QjzKLd4o3DbMESUGYFvqRGGLmmGLO_gixIH1vfV-P_NxU_QD9gtzQ0IhyR0UAj--FOQ!!/delta/base64xml/L3dJdyEvd0ZNQUFzQUMvNElVRS82X0JfNVY5"
	}
	//wpsRootURL("agentdesktop", "agent")
//	alert(wpsURL)
	return  wpsURL	
}
function eudChangePassword() {
	popUpWindowFromBanner(getAgentChangePWURL(), "ChangePassword")
}

function directToAgentDesktop(pageName){
	if (!pageName) {
		location.href = getAgentMyDesktopURL() //wpsRootURL("agentdesktop", "agent")   // the default
	} else 	if (pageName=="News") {
		location.href = getAgentNewsURL()
	} else if (pageName=="SiteMap") {
		location.href = getAgentSiteMapURL()
	} else if (pageName == "MyDesktop") {
		location.href = getAgentMyDesktopURL()
	} else if (pageName == "ChangePW") {
		location.href = getAgentChangePWURL()
	} else if (pageName == "AdvancedSearch") {
		location.href = getAgentAdvancedSearchURL()
	} else {
		location.href = wpsRootURL("agentdesktop", "agent")
	}
	
//	location.href = wpsRootURL("desktop",pageName)
//	location.href = wpsRootURL("agentdesktop", "agent")
}
function directToEmpDesktop(pageName){
	if (!pageName) {
		location.href ="/servlet/dcms?c=empfrontpage"   //pageName = "employee"    // the default
	} else {
		location.href = wpsRootURL("desktop",pageName)
	}	
}
function directToDirectory(){
	location.href = wpsRootURL("desktop","PortalDirectory") 
}

// dy changes for Agent Desktop
function getAgentDesktopLink() {

	if (hasAgentDesktopCookie()) {
		return "<div style=\"color:black;background=#cccccc;width:778;\"; height=\"0\">"+
"<table bgcolor=\"#cccccc\" width=\"778\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">"+
"<tr>"+
"<td align=\"right\" height=\"0\" valign=\"top\" class=\"hp-popup-eud\">" +
"<a href=\"javascript:directToAgentDesktop()\">" +
"<font class=\"hp-popup-eud\">Agent Desktop</font></a>&nbsp;</td>"+
"</tr>" +
"</table></div>"

	}
	return ""
}
function hasAgentDesktopCookie() {
	var desktopCookie = WM_readCookie("EnterpriseDesktop")
	if (desktopCookie) {
		return (desktopCookie == "Agent") 
	}
	return false;
}

// dy changes

function passwordIsValid(password) {
	if (password.length < 5) {
		return false
	}
	var hasNum   = false
	var hasUpper = false
	var hasLower = false
	var compare = ""
	
	for (i=0; i < password.length;i++) {
		compare=password.charAt(i)
		compareL = compare.toLowerCase()
		if (compare >= "0" && compare <= "9") {
			hasNum = true
		}
		else {
			if (compareL >="a" && compareL <= "z") {
				if (compare == compare.toUpperCase()) {
					hasUpper=true
				}
				else {
					hasLower = true
				}
			}
			else {
				return false
			}
		}
	}
	if (hasNum && hasLower && hasUpper) {
		return true
	}
	return false
}

function displayDCMSHelp(helpKey) {
	if (myURL.indexOf("http://desktopcontent.")>-1 ||
		myURL.indexOf("https://desktop.")>-1 ) {
		displayPopUp('http://www.firemansfund.com/dcms/dcmshelp.nsf/vwHelpByKey/' + 
		helpKey + '?opendocument',525, 400,'DCMSHelp')
	} else {
		displayPopUp('/dcms/dcmshelp.nsf/vwHelpByKey/' + 
			helpKey + '?opendocument',525, 400,'DCMSHelp')
	}
}
/* 20081121 These next two functions changed to fix the https for dev/test/uat
since these servers do not have https */
function HttpsIsNeeded() {
	if ((myURL.indexOf("//fficdev.") > -1) || 
		(myURL.indexOf("//ffictest.") > -1) || 
		(myURL.indexOf("//fficuat.") > -1) ||
		(myURL.indexOf("//ifgdev.") > -1) ||
		(myURL.indexOf("//ifgtest.") > -1) ||
		(myURL.indexOf("//ifguat.") > -1) ) {
		return false
	} else {
		return true
	}	
}

function editComponent(documentID, dbPath) { 
	var newURL = dbPath.toLowerCase()
	if (HttpsIsNeeded()) {
		newURL=replaceSubstring(newURL,"http:","https:")
	} else {
		// skip it
	}
	if (newURL.indexOf("agentdev.") > -1 ||
		newURL.indexOf("agenttest.") > -1 ||
		newURL.indexOf("agentuat.") > -1 ||
		newURL.indexOf("agentcert.") > -1 ||
		newURL.indexOf("agent.") > -1 ) {
		newURL = junctionName() + dbPath.substr(dbPath.indexOf(".com")+4)
	}
	dbPath = newURL
	winTitle = "DCMSEditor" //+ winIndex
	abURL = dbPath + '/0/' + documentID + '?editDocument'; 
	wwidth=750
	wheight=500
	opts = 'width=' + wwidth + ',height=' + wheight + ',resizable=yes, scrollbars=yes' 
	launchDCMSEditor(abURL)
}

function deleteComponent(compdocumentID, channel) {
	if (confirm("Do you want to permanently delete this component?")) {
	var x = "/servlet/dcms?c=" + channel + "&docID=" + compdocumentID + "&cmd=changeStatus&status=6&Eff="
	window.document.location.href = x
	}
}
function addComponent() {
//	winIndex += 1
//	winTitle = "DCMSEditor" //ComponentEditor" + winIndex
//	var f = window.document.forms[0]
//	var y = f.ComponentTypeTX.selectedIndex
//	var x = f.ComponentTypeTX.options[y].value
	abURL = websealRootURL() + dbPath + "/"+x + "?Openform&P=" + documentID
//	wwidth=650
//	wheight=800
//	opts = 'width=' + wwidth + ',height=' + wheight + ',resizable=yes, scrollbars=yes' 
//	popupWinArray[winIndex]=window.open( abURL,winTitle, opts)
//	popupWinArray[winIndex].focus()
//	dy PCMR4
	launchDCMSEditor(abURL)
//	launchApplication(abURL,"DCMSEditor")
}
function launchDCMSEditor(abURL) {
	wwidth=750
	wheight=550
	opts = 'width=' + wwidth + ',height=' + wheight + ',resizable=yes, scrollbars=yes,toolbar' 
//	DCMSEditorWindow = window.open( abURL,"DCMSEditor", opts)
	DCMSEditorWindow = addWindow( abURL,"DCMSEditor", opts)
	DCMSEditorWindow.focus()
//	dy PCMR4
//	launchApplication(abURL,"DCMSEditor")
}
function editPage(docID, serverName, dbPath) {
	setVisibilityIE("hide","ActionBox")
//	goToDomino(websealRootURL() + dbPath + "/vwAllDocs/"+docID+"?editdocument")
//alert("editPage")
	launchDCMSEditor(websealRootURL() + dbPath + "/vwAllDocs/"+docID+"?editdocument")
}
function displayEUDPopup(url, title, opts) {
	addWindow(url, title, opts)
}

function displayPopUp(abURL, width, height, windowName) {
	opts = 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes'; 
	wTitle = ((windowName) ? windowName : "windowTitle");
	//var newWindow = window.open( abURL, wTitle, opts);
	var newWindow = addWindow( abURL, wTitle, opts);
	newWindow.focus();
}

function goTop() {
	scrollTo('top');
}
function scrollTo(id){
	loc = window.location.href;
	index = loc.indexOf('#')
	if(index > -1){loc = loc.substring(0,index);} 
	window.location.href = loc + "#" + id;
}
function loginDirect(serverName, dbPath) {
	var url = window.document.location.href
	window.document.location.href = "http://" + serverName + dbPath + "/pgRedirect?openpage&login&URL=" + 

url
}

function goTo(url) {
	url = replaceSubstring(url, "intra02", "portal02")
	if (url.substr(0,4)=="app:") {
		url = url.substr(4)
		if (url.substr(0,2)=="..") {
			url = dbPath + url.substr(2)
		}
		launchApplication(url)
	}
	else {
		if (url.substr(0,2)=="..") {
			if (nsfLoc > document.location.href.length - 7) { // it's the home page
				window.location.href = dbPath + url.substr(2)
			}
			else {
				window.location.href=url
			}
		}
		else { 
			window.location.href=url
		} 
	}
}

function publishLater(channel) {
	var x = new Date()
	if (document.layers) {
		var formattedNow = x.getMonth()+1+"/"+x.getDate()+"/"+(x.getYear()+1900 ) + " 11:00 PM"
	}
	else {
		var formattedNow = x.getMonth()+1+"/"+x.getDate()+"/"+ x.getYear() + " 11:00 PM"
	}
	var releaseDate = prompt("Enter the release date [time] below. " + 
		"The time is optional. If not entered, publishing will take place at 12:00 AM on the date specified.",formattedNow)
	// Javascript doesn't like the : in the URL, so we change it to a dash 
	// and change back again in the agent
	var newURL = "/servlet/" + servletName + "?c=" + channel + "&docID=" +
	documentID + "&cmd=changeStatus&status=2&eff=" + replaceSubstring(replaceSubstring(releaseDate," ","+"),":","-")
	window.location.href = newURL
	return true
}
/* for for later for this function - dy
function publishLaterAjax(channel) {
	var x = new Date()
	if (document.layers) {
		var formattedNow = x.getMonth()+1+"/"+x.getDate()+"/"+(x.getYear()+1900 ) + " 11:00 PM"
	}
	else {
		var formattedNow = x.getMonth()+1+"/"+x.getDate()+"/"+ x.getYear() + " 11:00 PM"
	}
	var releaseDate = prompt("Enter the release date [time] below. " + 
		"The time is optional. If not entered, publishing will take place at 12:00 AM on the date specified.",formattedNow)
	// Javascript doesn't like the : in the URL, so we change it to a dash 
	// and change back again in the agent
	var newURL = "/servlet/" + servletName + "?c=" + channel + "&docID=" +
	documentID + "&cmd=changeStatusAjax&status=2&eff=" + replaceSubstring(replaceSubstring(releaseDate," ","+"),":","-")

	ajaxRequest(newURL,"publishlater")
	return true
}
*/
function invokeParentSelector(rkey) {
	winTitle = "ParentSelector"
	var db = dbPath.substr(dbPath.indexOf(".com")+4)
	var channel = db.substring(db.lastIndexOf("/")+1,db.indexOf("."))
	abURL = "/servlet/" + servletName + "?c=" + channel + 
		"&rkey=" + rkey + "&cmd=selectParent"
	wwidth=450
	wheight=575
	opts = 'width=' + wwidth + ',height=' + wheight + ',resizable=yes, scrollbars=yes' 
	var x = window.open( abURL,winTitle, opts)
	x.focus()
}

function handleOnLoad() {
	thisPage = window.location.href
	var x = thisPage.indexOf("&WhatsNew")
//	var y = thisPage.indexOf("&rc=")
//	var z = thisPage.indexOf("&rcURL=")
//	if ( y > 0) {
//		displayPopUp("/dcms/dcmsutil.nsf/frmPopupMsg?Readform&rc=" + 
//			thisPage.substring(thisPage.indexOf("&rc=") + 4, z) +
//			thisPage.substring(z),830,470,"404PopUp")
//	} else 
	if ( x > 0 ) {
		if (siteSubscription != "none") {
			sourceURL = window.location.href.substring(0,x)
			sourceSite = replaceSubstring(siteSubscription, " ", "+")
			newURL="/webserv/whatsnew.nsf/frmWhatsNewItemPopUp?OpenForm&Site="+ sourceSite 
			if (thisIsARedirectPage()) {
				newURL += ("&URL="+ sourceURL +
				"&Title=" + document.forms[0].PageTitleTX.value +
				"&Summary=" + document.forms[0].dSummaryTX.value)
				
			}
			goToDomino(newURL)
		}
	} 
}
function thisIsARedirectPage() {
	f = window.document.forms[0]
	if (f) {
		if (f.Form) {
			if (f.Form.value == "frmRedirectTo") {
				return true
			} else {
				return false
			}
		} else {
			return false
		}	
	} else {
		return false;
	}
}

function getWhatsNewDirectory() {
	if ( (myURL.indexOf("test.") > -1) || (myURL.indexOf("uat.") > -1) ) {
		return "webserv"
	} else {
	 	return "webserv"
	}	
}
// begin EUD stability code
function delayJS(milliSec){
	var date = new Date();
	var curDate = null;
	do { curDate = new Date(); } 
	while(curDate-date < milliSec);
}
function handleOnUnload() {
// THIS FUNCTION MUST NOT BE MOVED TO CERT OR PROD
	var urlString= logoutURL+'?windowClose=true'; 
	if (typeof(window.innerWidth)!='number') {
		if (window.event.clientX < 0 && window.event.clientY < 0){//user is closing the window
			try{
				window.location.href=urlString;
				if(urlString){
					delayJS(3000);
				}
			}catch(e1) {
				loc = window.location.href;
				index = loc.indexOf('.com'); 
				if(index > -1){
					loc = loc.substring(0,(index+'.com'.length));
				} 
				loc = loc + urlString;					
				try{
					window.location.href = loc ;
					if(urlString){
						delayJS(3000);
					}
				}catch(e2) {
					try{
						window.location.replace(loc);
						if(urlString){
							delayJS(3000);
						}
					}catch(e3) {
						window.open(loc,'_parent');
						if(urlString){
							delayJS(3000);
						}							
					}
				}
			}
		}
	}else{
		//no action need to taken since it is fire fox browser		
	}
// this is code to close websphere session on window closes
/*	if (typeof(window.innerWidth)=='number') {
		//no action need to be taken since it is fire fox browser
	}else{
		if (window.opener) {
			// don't do anything if it is a popup
		} else {
			if (window.event.clientX < 0 && window.event.clientY < 0)	{
			//user is closing the window
				window.location.href=logoutURL+"?windowClose=true";
			}
		}
	}
	*/
// end code for EUD stability
//alert("in handleOnUnload")
//	closeWindows()    // this function is in sfCommon
//	persistWindows()
//	alert(document.cookie)
	
}

function replaceSubstring(input,searchString,replaceString) {
	var newString = input	
	while (newString.indexOf(searchString) > -1) {
		newString = newString.replace(searchString,replaceString)
	}
	return newString
}
function launchApplication(abURL, title) {
//alert("abURL=" + abURL)
	var width='670'
	var height = '580'
	var wTitle = "windowTitle"
	if (title) {
		wTitle=title
	}
	opts = 'width=' + width + ',height=' + height + ',resizable,scrollbars,toolbar'; 
	var newWindow = addWindow(abURL, wTitle, opts) //window.open( abURL, wTitle, opts); 
	newWindow.focus()
}

function goToRootURL() {
	if (myURL.indexOf("localhost") > -1) {
		if (channel=="aos" || channel=="ifgbonds") {
			window.location.href = 
			"http://localhost:9080/servlet/" + servletName +
			"?c=" + channel
		}
		else {
			window.location.href = 
			"http://localhost:9080/servlet/" + servletName +
			"?c=ffichome"
		}
	}
	else {
		window.location.href = "/"
	} 
}
function decodeChannel() {
	var cTemp = ""
	var cLoc = myURL.indexOf("c=")
	if (cLoc>-1) {
		cTemp = myURL.substring(cLoc+2)
		cLoc = cTemp.indexOf("&")
		if ( cLoc > -1) {
			cTemp = cTemp.substring(0,cLoc)
		}
	}
//	alert(cTemp)
	return cTemp
}

function goToDomino(dominoURL) {
// dy new code to test
//alert("goToDomino:" + dominoURL)
//alert(dominoURL.indexOf("frmAdd"))
	if (dominoURL.indexOf("frmAdd") > -1) {
//	alert("here we go!")
	
//	wwidth=650
//	wheight=550
//	opts = 'width=' + wwidth + ',height=' + wheight + ',resizable=yes, scrollbars=yes' 
//	DCMSEditorWindow = window.open( abURL,"DCMSEditor", opts)
//	DCMSEditorWindow.focus()
	
	
	
	
	
		launchDCMSEditor(dominoURL)
	} else {
//

//alert(dominoURL)
	var URL = "";   // later...maybe websealRootURL();
	if (myURL.indexOf("localhost") > -1) {
		if (channel=="aos") {
			URL= "http://agentdev.firemansfund.com"
		}
		else {
//epc move			if (channel=="epc") {
//				URL= "http://epcdev.ffic.com"
//			}
//			else {
				URL= "http://fficdev.firemansfund.com"
//			}
		}
	}
	URL += dominoURL
	launchDCMSEditor(URL)
//	goTo("app:" + URL) 
	}
}

popupWinArray = new Array()
var winIndex = -1

function invokeTableEditor( tableName, tableTitle, cols, rows, fieldCol1, titleCol1, fieldCol2, titleCol2, 
fieldCol3, titleCol3, fieldCol4, titleCol4   ) { 
	winIndex += 1
	col1 = fieldCol1
	col2 = fieldCol2
	col3 = fieldCol3
	col4 = fieldCol4
	tName = tableName
	tTitle = tableTitle
	col1Label=titleCol1   
	col2Label=titleCol2   
	col3Label=titleCol3   
	col4Label=titleCol4
	numColumns = cols
	numRows = rows
	if (document.layers) {
		browser = 'nn' 
		lineSize=22
		baseHeight = 240
	}
	else {
		browser="ie"
		lineSize=23
		baseHeight = 238		
	}
//	if (junctionName()=="") {
//		abURL = '/wps/dcms/html/TabEditDCMS.html'
//		abURL = websealRootURL() + '/wps/dcms/html/TabEditDCMS.html'
//	} else {
		abURL = junctionName() + '/wps/dcms/html/TabEditDCMS.html'
//		alert(abURL)
//	}
//	abURL = websealRootURL() + '/wps/dcms/html/TabEditDCMS.html'
	wheight = baseHeight + (numRows*lineSize)
	switch (numColumns) {
		case 4: wwidth = ( browser == "nn") ? "770" : "780"; break
		case 3:	wwidth = ( browser == "nn") ? "600" : "620"; break
		case 2: wwidth = ( browser == "nn") ? "518" : "528"; break
		case 1: wwidth = ( browser == "nn") ? "518" : "528"; break
	}
	opts = 'width=' + wwidth + ',height=' + wheight + ',resizable=yes, scrollbars=yes'; 
	popupWinArray[winIndex]=window.open( abURL,tTitle, opts); 
	popupWinArray[winIndex].focus()
}
	//
function refreshTables() {
	for (var k in popupWinArray) {
		if (!popupWinArray[k].closed) {
			popupWinArray[k].handleSubmit()
			delete popupWinArray[k]
		}
	}
}
function resetOpener(url) {
	if (!window.opener) {
		var win = displayPopUp(url,800,600,"DCMSMain")
		win.focus()
	}
	else {
		window.opener.location.href = url
		window.opener.focus()
	}		
}

//
//01-07-2004
//added to fix the list item issue
//
//05-25-2005
//stylePosition var changed from 'stylePosition = "list-style-position: inside;'
//to 'stylePosition = "margin-left: 4px;'
//removed font size and family 
//
/*function listItemFix(){
var stylePosition;
if(navigator.appName =="Microsoft Internet Explorer") {
	stylePosition = ""//"margin-left: 4px;";
	} else {
	stylePosition = "margin-left: 4px;";
	}

document.write("<style>");
document.write("li{");    // was li
document.write(stylePosition);
document.write("}");
document.write("</style>");
}

//listItemFix();

*/
// from a previous version
function listItemFix(){
var stylePosition;
if(navigator.appName =="Microsoft Internet Explorer") {
	stylePosition = "list-style-position: inside;";
	} else {
	stylePosition = "";
	}

document.write("<style>");
document.write("li{");
document.write("font-size: 12px;");
document.write("font-family: Verdana;");
document.write(stylePosition);

document.write("</style>");
}
// remove this when the new list styles are implemented.
//listItemFix(); //commented out 20061105-dy

//added 20070306 MDESOUZA
//DCS Multitrack function for webtrends
function dcsMultiTrack(){
if (arguments.length%2==0){
for (var i=0;i<arguments.length;i+=2){
if (arguments[i].indexOf('WT.')==0){
WT[arguments[i].substring(3)]=
arguments[i+1];
}
else if (arguments[i].indexOf('DCS.')==0){
DCS[arguments[i].substring(4)]=
arguments[i+1];
}
else if (arguments[i].indexOf('DCSext.')==0){
DCSext[arguments[i].substring(7)]=
arguments[i+1];
}
}
var dCurrent=new Date();
DCS.dcsdat=dCurrent.getTime();
dcsTag();
}
}
// End dcsMultiTrack Function


// 20070512 MDESOUZA -  moved from aosTemplate to DCMSLib
function AOSlogin(){//now user is in ffic domain and trying to access aos login page
	urlString   = location.href;
	domainStPoint   = urlString.indexOf("//");
	domainEndPoint  = urlString.indexOf(".");
	domainName  = urlString.substring(domainStPoint+2,domainEndPoint);

/*	     if (domainName.toLowerCase() =="www"){
        location.href='https://agentdesktop.firemansfund.com/jctwps/wps/myportal/agent';
      }else if (domainName.toLowerCase() =="fficuat" || domainName.toLowerCase() == "agentuat"){
        location.href='https://agentdesktopuat.firemansfund.com/jctwps/wps/myportal/agent';
      }else if (domainName.toLowerCase() =="fficcert"|| domainName.toLowerCase() == "agentcert"){
        location.href='https://agentdesktopcert.firemansfund.com/jctwps/wps/myportal/employee';
      }else if (domainName.toLowerCase() =="ffictest"|| domainName.toLowerCase() == "agenttest"){
        location.href='https://agentdesktoptest.firemansfund.com/wpstest/wps/myportal/agent';
      }else if (domainName.toLowerCase() =="fficdev"|| domainName.toLowerCase() == "agentdev"){
        location.href='https://agentdesktopdev.firemansfund.com/wpsdev/wps/myportal/agent';
      }else if (urlString.indexOf("localhost") > -1 ){
        location.href='/wps/dcms/html/splashfficcom.html';
      }else{
        location.href='https://agent.firemansfund.com/wps/dcms/html/splashfficcom.html';
      }
      */
           if (domainName.toLowerCase() =="www"){
        location.href='https://lb01.firemansfund.com/jct05/PDEntitlements/entitlements?f=AOS';
      }else if (domainName.toLowerCase() =="fficuat" || domainName.toLowerCase() == "agentuat"){
        location.href='https://lbuat.firemansfund.com/jct05/PDEntitlements/entitlements?f=AOS';
      }else if (domainName.toLowerCase() =="fficcert"|| domainName.toLowerCase() == "agentcert"){
        location.href='https://lb02.firemansfund.com/jct05/PDEntitlements/entitlements?f=AOS';
      }else if (domainName.toLowerCase() =="ffictest"|| domainName.toLowerCase() == "agenttest"){
        location.href='https://lb03.firemansfund.com/wastest05/PDEntitlements/entitlements?f=AOS';
      }else if (domainName.toLowerCase() =="fficdev"|| domainName.toLowerCase() == "agentdev"){
        location.href='https://lb04.firemansfund.com/wasdev05/PDEntitlements/entitlements?f=AOS';
      }else if (urlString.indexOf("localhost") > -1 ){
        location.href='/wps/dcms/html/splashfficcom.html';
      }else{
        location.href='https://agent.firemansfund.com/wps/dcms/html/splashfficcom.html';
      }
}
function togglePublisherReaderView(viewState) {
// change the cookie and reload the page
//	alert(viewState)
	if (viewState=="Publisher") {
		WM_setCookie("DCMSViewToggle","Reader")
	}
	else {
		WM_setCookie("DCMSViewToggle","Publisher")
	}
	window.location.href = window.location.href
}

/*
function moveBothOnResize() {
	moveLogoOnResize()
	moveActionBoxOnResize()
}
	
function moveLogoOnResize() {
	var winSize
	if (document.body) {
		winSize = document.body.clientWidth
	} else {
		winSize = window.innerWidth
	}
	var myDiv = document.getElementById("logoDiv")
	var newPos = ( (winSize - 778) / 2) + 6
	myDiv.style.left = Math.max(newPos, 6) + "px"
}

function moveActionBoxOnResize() {
	var winSize
	if (document.body) {
		winSize = document.body.clientWidth
	} else {
		winSize = window.innerWidth
	}
	var myActionBox = document.getElementById("ActionBox")
	var newPos = (winSize - 778) / 2
	myActionBox.style.left = Math.max(newPos, 0) + "px"
}
*/
