//
// pdmweb.js
// 
// Copyright (C) 1999-2002 Solidworks Corporation
// All rights reserved.
//
function getAbsTop(i_obj) {
    if (i_obj == null) {
	reportError ("getAbsTop() -- passed in a NULL value.");
	return 0;
    }
    var pos = 0;
    var obj = i_obj;
    while (obj != null && obj.nodeName != "BODY") {
	pos += obj.offsetTop;
	obj = obj.parentNode;
    }
    return pos;
}

var m_bErrorReporting = true; // Error reporting is enabled

function allowErrorReporting(i_b) {
  m_bErrorReporting = i_b;
}

function isErrorReportingAllowed() {
  return m_bErrorReporting;
}

function reportError(i_str) {
    if (! isErrorReportingAllowed()) {  // 
        return 0;
    }
    reportLine(i_str, "_E_");
    if (confirm(top.IDS_PDMWEB_WEB_PORTAL_ERROR)) {
		window.open("log.html");
    }
    return true;
}

function reportWarning(i_str) {
    reportLine(i_str, "_W_");
}

function reportLine(i_str, i_type) {
    if (typeof(top.m_errorLog) != undefined) {
	top.m_errorLog += new Date().toUTCString() + " " + i_type + " " + i_str + "\r\n";
    }
}

function reportLog(i_str) {
    reportLine(i_str, "_L_");
}

function getAbsLeft(i_obj) {
    if (i_obj == null) {
	reportError ("getAbsLeft() -- passed in a NULL value.");
	return 0;
    }
    var pos = 0;
    var obj = i_obj;
    while (obj != null && obj.nodeName != "BODY") {
	pos += obj.offsetLeft;
	obj = obj.parentNode;
    }
    return pos;
}

function getFirstInSet(i_obj, i_strName) {
    if (i_obj == null) {
	reportError ("getFirstInSet(" + i_strName + ") -- i_obj is null.");
	return null;
    }

    var arrInstances = i_obj.getElementsByTagName(i_strName);
    if ((arrInstances != null) && (arrInstances.length > 0)) {
        return arrInstances[0];
    }
    return null;
}


function parseGet() {
    var obj = new Object();

    // Cannot use this.location.search, as it truncates
    // URLs with a '#' character (spr 243781, 243629)
    // var query=this.location.search.substring(1);

    var query = "";
	var strLocation = this.location.href;
	
	if (strLocation!="") {
		var params2=strLocation.split("?");
		if (params2.length>1) {
			for (var j=1;j<params2.length;j++) {
				query=query+params2[j];
			}
		}
		else {
            // Default back to using search
			query = this.location.search.substring(1);
		}
	}
	else
	{
        // Default back to using search
		query = this.location.search.substring(1);
	}

    if (query.length > 0){
		var name;
		var value;
        var params=query.split("&");
        for (var i=0 ; i< params.length ; i++){
            var pos = params[i].indexOf("=");
			if (pos == -1)
			{
				if (i>0)
				{
					// No "=" found and this isn't the first argument, so
					// append next param and & to previous value.
					// See spr 233323 for an example of why this is necessary
					value = value + "&" + params[i];
					obj[name] = value;
				}
			}
			else
			{
				// Found "=", so create new name, value pair
				name = params[i].substring(0, pos);
				value = params[i].substring(pos + 1);
				obj[name] = value;
			}
        }
    }
    return obj;
}

function checkboxCtrl_onclick(i_ctrl) {
    var arrInputs = i_ctrl.getElementsByTagName("input");
    if (arrInputs.length > 0) {
	if (arrInputs[0].type == "radio") {
	    arrInputs[0].checked = true; // To prevent unchecking...
	}
	else {
	    arrInputs[0].checked = ! arrInputs[0].checked;
	}
    }
    event.cancelBubble = true;
    return false;
}

function checkbox_onclick() {
    event.cancelBubble = true;
    return true;
}

//
// getXMLHttpRequest() 
// Returns the XML Http request
//
function getXMLHttpRequest() {
    var req = null;
    if (navigator.appName == "Microsoft Internet Explorer") {
        // req = new ActiveXObject("Msxml2.XMLHTTP");
	req = new ActiveXObject("Msxml2.XMLHTTP.3.0");
    }
    else {
        req = new XMLHttpRequest();
    }
    return req;
}

// getBaseUrl
// Return the base url of the current document's location
// For example, for "http://localhost/pdmweb/pdmwcgi.exe?Document=xxx&ZDoc=/xxx"
// return "http://localhost/pdmweb/" with a trailing "/".
function getBaseUrl() {
	var strLocation = document.location.href;
    var strBaseUrl = "";

	// First, get rid of the arguments in the document URL
	// e.g. "http://localhost/pdmweb/pdmwcgi.exe?Document=xxx&ZDoc=/xxx"
	// is trimmed to "http://localhost/pdmweb/pdmwcgi.exe".
    var arrTokens = strLocation.split("?");
    var strMainUrl;
	if (arrTokens.length > 1) {
		// There is a ? in strLocation, so take first portion of strLocation
		strMainUrl = arrTokens[0];
	}
	else {
		// There is no ? in strLocation, so use whole strLocation
		strMainUrl = strLocation;
	}

	// Second, get all but the last part of the main part URL.
	// e.g. "http://localhost/pdmweb/viewing.html" is trimmed to
	// "http://localhost/pdmweb/"
	var arrTokens2 = strMainUrl.split("/");
	// Copy all but the final portion of the path
    for (var i = 0 ; i < arrTokens2.length - 1 ; ++i) {
		strBaseUrl += arrTokens2[i] + "/";
    }

	return strBaseUrl;
}

// getPDMCGIUrl
// Return the Url to the pdmwcgi.exe file for the current server.
// (e.g. http://localhost/pdmweb/pdmcgi.exe in a default installation)
function getPDMCGIUrl() {
    var strURL = getBaseUrl() + "pdmwcgi.exe";
	return strURL;
}

//
// escapeCharsForEDrawings
//
// eDrawings does not handle some characters correctly, so we
// need to do something special here for them.  Note that
// we cannot encode in the normal way (e.g. # as %23) because
// eDrawings will recognize and undo that sort of encoding.
//
function escapeCharsForEDrawings(i_strArg) {

    if (typeof(i_strArg) != "string") {
        return i_strArg;
    }

	var regexp1 = /\%/g
	var regexp2 = /\ /g
	var regexp3 = /\!/g
	var regexp4 = /\#/g
	var regexp5 = /\$/g
	var regexp6 = /\&/g
	var regexp7 = /\'/g
	var regexp8 = /\(/g
	var regexp9 = /\)/g
	var regexp10 = /\+/g
	var regexp11 = /\,/g
	var regexp12 = /\-/g
	var regexp13 = /\=/g
	var regexp14 = /\[/g
	var regexp15 = /\]/g
	var regexp16 = /\^/g 

    var strTemp1 = i_strArg.replace(regexp1,"%25");
	var strTemp2 = strTemp1.replace(regexp2,"%20");
	var strTemp3 = strTemp2.replace(regexp3,"%21");
	var strTemp4 = strTemp3.replace(regexp4,"%zz");
	var strTemp5 = strTemp4.replace(regexp5,"%24");
	var strTemp6 = strTemp5.replace(regexp6,"%26");
	var strTemp7 = strTemp6.replace(regexp7,"%27");
	var strTemp8 = strTemp7.replace(regexp8,"%28");
	var strTemp9 = strTemp8.replace(regexp9,"%29");
	var strTemp10 = strTemp9.replace(regexp10,"%2b");
	var strTemp11 = strTemp10.replace(regexp11,"%2c");
	var strTemp12 = strTemp11.replace(regexp12,"%2d");
	var strTemp13 = strTemp12.replace(regexp13,"%3d");
	var strTemp14 = strTemp13.replace(regexp14,"%5b");
	var strTemp15 = strTemp14.replace(regexp15,"%5d");
	var strReturn = strTemp15.replace(regexp16,"%5e");

    return strReturn;
}

//
// escapeCharsForMost
//
// Escape characters for most applications (but not eDrawings).
//
function escapeCharsForMost(i_strArg) {

    if (typeof(i_strArg) != "string") {
        return i_strArg;
    }

	var regexp1 = /\%/g
	var regexp2 = /\ /g
	var regexp3 = /\!/g
	var regexp4 = /\#/g
	var regexp5 = /\$/g
	var regexp6 = /\&/g
	var regexp7 = /\'/g
	var regexp8 = /\(/g
	var regexp9 = /\)/g
	var regexp10 = /\+/g
	var regexp11 = /\,/g
	var regexp12 = /\-/g
	var regexp13 = /\=/g
	var regexp14 = /\[/g
	var regexp15 = /\]/g
	var regexp16 = /\^/g 

    var strTemp1 = i_strArg.replace(regexp1,"%25");
	var strTemp2 = strTemp1.replace(regexp2,"%20");
	var strTemp3 = strTemp2.replace(regexp3,"%21");
	var strTemp4 = strTemp3.replace(regexp4,"%23");
	var strTemp5 = strTemp4.replace(regexp5,"%24");
	var strTemp6 = strTemp5.replace(regexp6,"%26");
	var strTemp7 = strTemp6.replace(regexp7,"%27");
	var strTemp8 = strTemp7.replace(regexp8,"%28");
	var strTemp9 = strTemp8.replace(regexp9,"%29");
	var strTemp10 = strTemp9.replace(regexp10,"%2b");
	var strTemp11 = strTemp10.replace(regexp11,"%2c");
	var strTemp12 = strTemp11.replace(regexp12,"%2d");
	var strTemp13 = strTemp12.replace(regexp13,"%3d");
	var strTemp14 = strTemp13.replace(regexp14,"%5b");
	var strTemp15 = strTemp14.replace(regexp15,"%5d");
	var strReturn = strTemp15.replace(regexp16,"%5e");

    return strReturn;
}

//
// unescapeCharsForAll
//
// Do the opposite of what was done above in escape methods
// of both eDrawings and Most.
//
// Note that the order is opposite that of above methods,
// to avoid unescaping incorrectly.
//
function unescapeCharsForAll(i_strArg) {

    if (typeof(i_strArg) != "string") {
        return i_strArg;
    }

	var regexp16 = new RegExp("%5e","g"); 
	var regexp15 = new RegExp("%5d","g");
	var regexp14 = new RegExp("%5b","g");
	var regexp13 = new RegExp("%3d","g");
	var regexp12 = new RegExp("%2d","g");
	var regexp11 = new RegExp("%2c","g");
	var regexp10 = new RegExp("%2b","g");
	var regexp9 = new RegExp("%29","g");
	var regexp8 = new RegExp("%28","g");
	var regexp7 = new RegExp("%27","g");
	var regexp6 = new RegExp("%26","g");
	var regexp5 = new RegExp("%24","g");
	var regexp4 = new RegExp("%23","g");
	var regexp4b = new RegExp("%zz","g");
	var regexp3 = new RegExp("%21","g");
	var regexp2 = new RegExp("%20","g");
	var regexp1 = new RegExp("%25","g");

	var strTemp16 = i_strArg.replace(regexp16,"^");
	var strTemp15 = strTemp16.replace(regexp15,"]");
	var strTemp14 = strTemp15.replace(regexp14,"[");
	var strTemp13 = strTemp14.replace(regexp13,"=");
	var strTemp12 = strTemp13.replace(regexp12,"-");
	var strTemp11 = strTemp12.replace(regexp11,",");
	var strTemp10 = strTemp11.replace(regexp10,"+");
	var strTemp9 = strTemp10.replace(regexp9,")");
	var strTemp8 = strTemp9.replace(regexp8,"(");
	var strTemp7 = strTemp8.replace(regexp7,"'");
	var strTemp6 = strTemp7.replace(regexp6,"&");
	var strTemp5 = strTemp6.replace(regexp5,"$");
	var strTemp4 = strTemp5.replace(regexp4,"#");
	var strTemp4b = strTemp4.replace(regexp4b,"#");
	var strTemp3 = strTemp4b.replace(regexp3,"!");
	var strTemp2 = strTemp3.replace(regexp2," ");
    var strTemp1 = strTemp2.replace(regexp1,"%");

    return strTemp1;
}

//
// escapeSomeChars
//
// We only escape a few special characters here and not others
// because sometimes the arguments passed to getXMLDoc below
// have already been encoded (e.g. URL arguments) and using
// the browser's escape method would double encode the strings,
// causing all sorts of problems in the CGI executable.
//
// Right now this function only escapes '&' and '+'.
// It might be necessary to escape other characters in the future,
// but these are the only ones known to cause problems thus far.
function escapeSomeChars(i_strArg) {
    if (typeof(i_strArg) != "string") {
        return i_strArg;
    }
    var regexp = /&/g
    var regexp2 = /\+/g
    var strTemp = i_strArg.replace(regexp,"%26");
    var strReturn = strTemp.replace(regexp2,"%2b");
    return strReturn;
}

var regSingleQuote = /\'/g;

function escapeForXSL(i_strArg) {
    if (typeof(i_strArg) != "string") {
        return i_strArg;
    }
    return i_strArg.replace(regSingleQuote, "\\'");
}

//
// getXMLDoc
// Return the actual element
//
var tempI = 0 ;
function getXMLDoc(i_strReq) {
    // If there are additional parameters, include them in the request via
    // paired values
    var strOptions = "";
	var strLoginName = "";
	var strLoginPassword = "";
	var bPasswordInArgs = false;
    var cntArgs = arguments.length;
    if (cntArgs > 1) {
		if (cntArgs % 2 == 0) {
		    reportError("getXMLDoc() requires paired parameters");
		    return null;
		}

		for (var i = 1 ; i < cntArgs ; i=i+2) {
		    strOptions += arguments[i] + "=" + escapeSomeChars(arguments[i+1]) + "&";
			if (arguments[i] == "loginname") {
				strLoginName = arguments[i+1];
			}
			else if (arguments[i] == "loginpassword") {
				bPasswordInArgs = true;
				strLoginPassword = arguments[i+1];
			}
		}		
    }

    var req = getXMLHttpRequest();
    var curDate = new Date();
    var sec = curDate.getSeconds();
	var strURL = getPDMCGIUrl();
    var app = new App();
	var strUserInfo = ""
	if (strLoginName == "") {
		strUserInfo += "loginname=" + app.GetUser() + "&";
	}
	if (! bPasswordInArgs) {
		strUserInfo += "loginpassword=" + app.GetPassword() + "&";
	}
    var strParams = "Request=" + i_strReq + "&" + strOptions + strUserInfo + "rnd=" + sec;
    for (var p = 0 ; p < 10 ; ++p) { // Put a hard value in to prevent loop
		try {
			// Debug - uncomment to see requests sent to server
			//alert("request strURL="+strURL+" and strParams="+strParams);

			req.open("POST", strURL, false);
			req.setRequestHeader("Content-length", strParams.length);
			req.send(strParams);
			break;	    
		}
		catch (ex) {
		}
    }

    // Debug - uncomment to see responses from server
    //alert("response XML="+req.responseText);

    if (req.responseXML.documentElement == null) {
        if (req.responseXML.parseError.errorCode == -1072896760) {
            var r = new ActiveXObject("Msxml2.DOMDocument.3.0");
            var reg = new RegExp("\x00|\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x09|\x0B|\x0C|\x0E|\x0F|\x10|\x11|\x12|\x13|\x14|\x15|\x16|\x17|\x18|\x19|\x1A|\x1B|\x1C|\x1D|\x1E|\x1F", "g");
            r.loadXML(req.responseText.replace(reg, ""));
            return r.documentElement;
        }

        reportError("getXMLDoc(" + i_strReq + ") -- "
					+ req.responseXML.parseError.reason + "\r\n" + req.responseText);
    }
    if (p == 10) {
	reportError ("Could not instantiate object... (DEBUG: strURL: " 
	    + strURL + " strParams: " + strParams);
        return null;
    }
    return req.responseXML.documentElement;
}

function preloadImages() {
    var cntArgs = arguments.length;
    var img = null;
    for (var i = 0 ; i < cntArgs ; ++i) {
        img = new Image();
	img.src = "images/" + arguments[i];
    }
}

function addStack(i_strExisting, i_strNew) {
    var str = i_strExisting + "\r\n" + i_strNew;
    throw str;
}

function getUniqueWindowName() {
	var time = new Date();
	var name = "pdmweb" + time.getMinutes() + time.getSeconds() + time.getMilliseconds();
	return name;
}

function timerStart() {
    return new Date();
}

function timerEnd(i_str, i_date) {
    var endTime = new Date();
    var diffTime = new Date(endTime - i_date);
    var ms = (diffTime.getMilliseconds() + (1000 * diffTime.getSeconds()) +
	(60000 * diffTime.getMinutes()));
    alert ("Test: " + i_str + ", time elapsed in miliseconds:" + ms);
}

function AllowSelect() {
    event.cancelBubble = true;
    return true;
} 

function GetVaultError(i_objXML) {
	if (i_objXML != null) {
		try {
			var arrErr = i_objXML.getElementsByTagName("error");
			if (arrErr.length > 0) {
				return arrErr[0].getAttribute("num");
			}
		}
		catch (e) {
			return 1; // Unknown error
		}
	}
    return 0; // PDMW_ERROR_NONE
}

function HandleVaultError(i_objXML) {
    var vaultError = GetVaultError(i_objXML);
    switch(vaultError) {
	case '0': // No error
		break;
	case '22':
	    alert (top.IDS_PDMWEB_DOC_NOT_AVAIL);
		break;
	case '41':
	    alert (top.IDS_PDMWEB_VAULT_CANNOT_BE_CONTACTED);
		break;
	case '2000':
    	alert (top.IDS_PDMWEB_INVALID_LICENSE);
		break;
	default: 
	    alert (top.IDS_PDMWEB_UNSPECIFIED_ERROR_CONNECTING + vaultError);
		break;
    }
    return Number(vaultError).valueOf();
}

function makeArray() {
    for (i = 0; i<makeArray.arguments.length; i++)
        this[i] = makeArray.arguments[i];
}

var convert = new makeArray('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');

function returnBase(number,base) {
    if (number < base) var output = convert[number];
    else {
        var MSD = '' + Math.floor(number / base);
        var LSD = number - MSD*base;
        if (MSD >= base) var output = returnBase(MSD,base) + convert[LSD];
        else var output = convert[MSD] + convert[LSD];
    }
    return output;
}

function conv (i_num) {
    var a = i_num % 16;
    var b = (i_num - a)/16;
    return arrHex.charAt(b) + arrHex.charAt(a);
}

function convert_value(i_str) {
    if (i_str == null) {
        return "";
    }
    var strOut = "";
    var chrCode = 0;
    for (var i = 0 ; i < i_str.length ; ++i) {
	chrCode = i_str.charCodeAt(i);
	if (chrCode > 255) {
	    strOut += "#k" + returnBase(chrCode, 16);    
	}
	else {
	    strOut += "#" + returnBase(chrCode, 16);    
	}
    }
    return strOut;
}

function convert_value_z(i_str) {
    if (i_str == null) {
        return "";
    }
    var strOut = "";
    var chrCode = 0;
    for (var i = 0 ; i < i_str.length ; ++i) {
	chrCode = i_str.charCodeAt(i);
	if (chrCode > 255) {
	    strOut += "zk" + returnBase(chrCode, 16);    
	}
	else {
	    strOut += "z" + returnBase(chrCode, 16);    
	}
    }
    return strOut;
}

function selectSingleNode(i_node, i_strPath) {
	// Only valid in IE
	return i_node.selectSingleNode(i_strPath);
}

function selectNodes(i_node, i_strPath) {
	return i_node.selectNodes(i_strPath);
}

function dbgalert(i) {
	alert (i);
}

function getDateCode() {
  var str = "";
  try {
    var xmlObj = getXMLDoc("GetWebPortalDateCode");
    var node = selectSingleNode(xmlObj, "//webportaldatecode");
    str = node.getAttribute("datecode");
  }
  catch(ex) {
  }
  return str;
}

function getReadOnlyUserAllowedToOpenDocs() {
	var str = "";
	var bResponse = false;
	try {
		var xmlObj = getXMLDoc("GetGlobalSettings");
		var node = selectSingleNode(xmlObj,"//global_settings");
		str = node.getAttribute("read_only_user_allowed_to_open_docs");
		if (str=="1") {
			bResponse = true;
		}
	}
	catch(ex) {
	}
	return bResponse;
}

function getHasPDF(i_strDocName,i_strRevision)
{
	var str = "";
	var bResponse = false;
	try {
		var xmlObj = getXMLDoc("GetHasPDF","Document", i_strDocName,"Revision",i_strRevision);
		var node = selectSingleNode(xmlObj,"//has_pdf");
		str = node.getAttribute("has_pdf");
		if (str=="1") {
			bResponse = true;
		}
	}
	catch(ex) {
	}
	return bResponse;
}

function getPrettyVersionString() {
	var str = "";
	try {
		var xmlObj = getXMLDoc("GetPrettyVersionString");
		var node = selectSingleNode(xmlObj,"//pretty_version");
		str = node.getAttribute("pretty_string");
	}
	catch(ex) {
	}
	return str;
}

// Has the Administrator turned on the "Force User Login" setting?
function getForceUserLogin() {
	var str = "";
	var bResponse = false;
	try {
		var xmlObj = getXMLDoc("GetGlobalSettings");
		var node = selectSingleNode(xmlObj,"//global_settings");
		str = node.getAttribute("force_user_login");
		if (str=="1") {
			bResponse = true;
		}
	}
	catch(ex) {
	}
	return bResponse;
}

// Should we treat short extensions (.prt, .asm, .drw) as SW?
function getRecognizeShortExtensionsAsSW() {
	var str = "";
	var bResponse = false;
	try {
		var xmlObj = getXMLDoc("GetGlobalSettings");
		var node = selectSingleNode(xmlObj,"//global_settings");
		str = node.getAttribute("recognize_short_ext_as_sw");
		if (str=="1") {
			bResponse = true;
		}
	}
	catch(ex) {
	}
	return bResponse;
}

// Get view settings
// Returns a value that is a combination of
//	001	= allow view markup
//	010	= allow view measure
//	100	= allow view save
//
// so 0 = allow nothing
//    1 = allow view markup
//	  10 = allow view measure
//	  11 = allow view markup and measure
//    100 = allow view save
//    101 = allow view save and markup
//    110 = allow view save and measure
//    111 = allow view save, markup and measure
function getViewSettings() {
	var str = "";
	var bResponse = 0;
	try {
		var xmlObj = getXMLDoc("GetGlobalSettings");
		var node = selectSingleNode(xmlObj,"//global_settings");
		str = node.getAttribute("allow_markup");
		if (str=="1") {
			bResponse = bResponse + 1;
		}
		str = node.getAttribute("allow_measure");
		if (str=="1") {
			bResponse = bResponse + 10;
		}
		str = node.getAttribute("allow_save");
		if (str=="1") {
			bResponse = bResponse + 100;
		}
	}
	catch(ex) {
	}
	return bResponse;
}

// Are we using Windows Authentication?
function getWindowsAuthenticationEnabled() {
	var str = "";
	var bResponse = false;
	try {
		var xmlObj = getXMLDoc("GetGlobalSettings");
		var node = selectSingleNode(xmlObj,"//global_settings");
		str = node.getAttribute("windows_auth");
		if (str=="1") {
			bResponse = true;
		}
	}
	catch(ex) {
	}
	return bResponse;
}

// Return if the given cookie exists or not.
// Note that if a cookie exists but has a value of an empty string (e.g. an empty password),
// then there will be no '=' character after the cookie name.  So search only on the cookie name.
function cookieExists (strCookieName) {
	var iCookieStart = 0;
	var strSearch = strCookieName;

	// Look for cookie start
	iCookieStart = document.cookie.indexOf (strSearch);
	if (iCookieStart == -1) {
		// Cookie not found, return false
		return false;
	}

	return true;
}

// Get the value of the persistent cookie with the given name.
// If no such cookie is found, then return an empty string.
// Cookie names ARE case sensitive.  Note that if the cookie
// exists but has no value, there will be no '=' character
// after the cookie name and this function will return an empty
// string because it thinks the cookie doesn't exist - but that's ok.
function getPersistentCookie (strCookieName) {
	var iCookieStart = 0;
	var iValueStart = 0;
	var iValueEnd = 0;
	var strSearch = strCookieName + "=";

	// Look for cookie start
	iCookieStart = document.cookie.indexOf (strSearch);
	if (iCookieStart == -1) {
		// Cookie not found, return empty string
		return "";
	}
	iValueStart = iCookieStart + strSearch.length;

	// Look for cookie value end
	iValueEnd = document.cookie.indexOf (";", iValueStart);
	if (iValueEnd == -1) {
		// End of value is end of cookie
		iValueEnd = document.cookie.length;
	}

	return unescape(document.cookie.substring(iValueStart, iValueEnd));
}

// Get the value of the session cookie with the given name.
// If no such cookie is found, then return an empty string.
// Cookie names ARE case sensitive.
function getSessionCookie (strCookieName) {
	var iCookieStart = 0;
	var iValueStart = 0;
	var iValueEnd = 0;

	// Prepend an 's' to cookie to avoid losing empty strings (see setSessionCookie)
	var strSearch = strCookieName + "=s";

	// Look for cookie start
	iCookieStart = document.cookie.indexOf (strSearch);
	if (iCookieStart == -1) {
		// Cookie not found, return empty string
		return "";
	}
	iValueStart = iCookieStart + strSearch.length;

	// Look for cookie value end
	iValueEnd = document.cookie.indexOf (";", iValueStart);
	if (iValueEnd == -1) {
		// End of value is end of cookie
		iValueEnd = document.cookie.length;
	}

	return unescape(document.cookie.substring(iValueStart, iValueEnd));
}

// Session cookies have no expiration and hence are temporary and lost
// immediately when the browser session ends.  Since empty session cookies
// don't work (nothing gets saved), prepend all session cookies with 's'.
function setSessionCookie (strCookieName, strCookieValue) {
	document.cookie = strCookieName + "=s" + escape(strCookieValue) + "; path=/";
}

// Persistent cookies have an expiration date
function setPersistentCookie(strCookieName, strCookieValue) {
	document.cookie = strCookieName + "=" + escape(strCookieValue) +
		"; expires=" + top.m_persistDate.toGMTString() +
		"; path=/";
}

// Delete a session cookie by setting its value to an empty string
function deleteSessionCookie (strCookieName) {
	if (getSessionCookie(strCookieName) != "") {
		// Set value to empty string, as session cookies have no expiration
		document.cookie = strCookieName + "=; path=/";
	}
}

// Delete a persistent cookie by setting its expiration date to zero
function deletePersistentCookie (strCookieName) {
	if (getPersistentCookie(strCookieName) != "") {
		// Reset the cookie expiration date to zero, forcing it to expire immediately
		document.cookie = strCookieName + "=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}


// cursorEventWrapper creates a busy cursor on all windows and then 
// executes the desired event handler function
function cursorEventWrapper(i_func) {
  top.m_node = event.srcElement;
  top.m_keyCode = event.keyCode;
  top.m_stylefunc = i_func;
  startBusyCursor();
}

function slowCursorEventWrapper(i_func) {
  top.m_slowCursorChange = true;
  cursorEventWrapper(i_func);
}

function startBusyCursor() {
//  window.setTimeout(startBusyCursor_Impl, 10);
if (top.m_slowCursorChange == true) {
}
startBusyCursor_Impl();
}

function startBusyCursor_Impl() {
  top.m_inProgress = true;
  window.status = "Working";
  changeCursor("wait");
}

function endBusyCursor() {
  top.m_inProgress = false;
  window.status = top.IDS_PDMWEB_DONE;
  changeCursor("default");
}

function changeCursor(i_strNewCursor) {
  changeCursorLoop(top, i_strNewCursor);
  top.frames["frameTree"].document.body.style.cursor = i_strNewCursor;
}

function changeCursorLoop(i_wnd, i_strNewCursor) {
  if (i_wnd == null)
    return 0;
    for (var i = 0 ; i < i_wnd.frames.length ; ++i) {
      try {
        if (i_wnd.frames[i].name == "frameTree") {
        }
        else {
        var curBody = i_wnd.frames[i].document.body;
        if (curBody != null) {
          curBody.style.cursor = i_strNewCursor;
        }
        changeCursorLoop(i_wnd.frames[i]);
      }
    }
    catch(e) {
    }
  }
}



