var ns = (window.Event) ? true : false;   // test for Netscape 4 & 6
var nsie5 = (document.documentElement) ? true : false;
if (nsie5) {
  var ieStrict = (document.documentElement.clientWidth > 0) ? true : false;
}
var ns6 = (ns && nsie5);

//var ie6 = ( navigator.appVersion.indexOf("MSIE 6") > 1 ) ? true : false;

var ua = navigator.userAgent.toLowerCase();
var ie = (document.all && ua.indexOf("msie")>1) ? true : false; 
var mac = ( ie && (ua.indexOf("mac") > 1) ) ? true : false;
var ie5 = ( !mac && (ua.indexOf("msie 5.0") > 1) ) ? true : false;
var opera = (ua.indexOf("opera") != -1);
var safari = (ua.indexOf("safari") != -1);
var konq = (ua.indexOf("konquerer") != -1);

var checkBoxVal;
var submitted = 0;

var gTimeoutId = null;
var whenOpen = 0;
var menuStyle;
var gRow;
var menuOn = null;

var gMenuLink = null;
/* dhtml menu z-index must be 200+ */
/* these defaults should be overridden by specific site */
var gMenuStyles = null;
var gMenuXoffset = 80;
var gMenuXoffsetMac = 80;
var gMenuYoffset = 8;
var gMenuYoffsetMac = 0;
var gMenuYoffsetIe5 = 8;
var gQpMacAdjust = 0;
var wwEditor, fmWindow, _editor_version;

var gLang = getLang().substring(0,2).toLowerCase();

function getElem(elemID) {
	return document.getElementById(elemID);
}

function getFormElem(nameOrId, index) {
	var el = null;
	for (var i=0; i<document.forms.length; i++) {
		if (document.forms[i].elements[nameOrId]) {
			el = document.forms[i].elements[nameOrId];
			break;
		}
	}
	if (!el) {
		if (getElem(nameOrId)) {
			el = getElem(nameOrId);
		} else {
		/* in case elem is not in a form (illegal):*/
			inputs = document.getElementsByTagName("INPUT");
			for (var i=0; i<inputs.length; i++) {
				if (inputs[i].name == nameOrId) {
					el = inputs[i];
					break;
				}
			}
		}
	} 
	if (el && index != null && el.length) return el[index];
	return el; //index is null or zero (el is not array);
}

function getTextNode(elem) {
	if (elem) {
		if (elem.innerText) return elem.innerText;
		if (elem.nodeType != 3) { 
			return getTextNode(elem.firstChild);
		}
		return elem.nodeValue;
	}
	return "";
}

function brSetup() {
//alert("safari: "+safari+", opera: "+opera+", konq: "+konq+", mac: "+mac+", ns6: "+ns6+", nsie5: "+nsie5);
	if (!nsie5 || safari || opera || konq) {
            if (location.href.indexOf("home.html")>0 || location.href.indexOf("index.html")>0) { // dont annoy people by showing error on every page, only home pages
                    alert(msg_incorrectBrowser);
            }
            if (!nsie5) return;
	}
  	if (getElem("listTable")) { //test for bedrock list
    	listSetup();
  	}
  	document.onclick = hideMenu;
  	if (ns6) document.addEventListener("click", hideMenu, true);
  	document.onmouseover = overTest;
  	if (ns6) document.addEventListener("mouseover", overTest, true);
  	if (!mac && ua.indexOf("msie")!=-1) {
  		document.body.insertAdjacentHTML('beforeEnd','<!--[if gte IE 5.5000]><iframe id="menuShim" src="javascript:false;" scrolling="no" frameborder="0" style="position:absolute;display:none;z-index:199;"></iframe><![endif]-->');
  	}
  	submitted = 0; //reset var for mac
  	reportRequested = false;
  	checkForCalendar();
  	findCurrency();
    if (typeof reportPopup != "undefined") makeReportPopup(); 
  	if (getElem("loginForm")) {
        if (!navigator.cookieEnabled) alert(msg_CookiesDisabled);
        un = getFormElem("j_username");
        if (un) {
			un.focus();
			un.select();
        } 
    } 
	if (getElem("wwArea")) {
  		if (typeof HTMLArea == "undefined") { alert("WYSIweb did not load properly. Try refreshing the page, or contact support@wysiweb.com."); return; }
  		  	//alert('about to setupWw');
  		HTMLArea.loadPlugin("ContextMenu");
  		if (typeof wwStyleMenu == "object") {
  			HTMLArea.loadPlugin("CSS");
  		//} else {
  			//HTMLArea.loadPlugin("DynamicCSS");
  		}
  	 	HTMLArea.loadPlugin("TableOperations");
	  	if(HTMLArea.is_gecko) HTMLArea.loadPlugin("EnterParagraphs");
  	 	getElem("wwArea").form.reset(); 
		HTMLArea.init();
		//HTMLArea.onload = brWwSetup(); //unreliable
		ww = getElem("wysiWeb");
		// if ww is a form, it is normal ww page; otherwise ww is a td and ww is a field
		brWwSetup((ww && ww.tagName.toLowerCase() != "form"));
		//HTMLArea.replace("wwArea",config);
  	}
}
//var wwcount=0;
function brWwSetup(isField) { 
  if ( (HTMLArea.is_gecko && typeof EnterParagraphs=="undefined") || typeof TableOperations=="undefined"
  	|| HTMLArea.I18N == null || HTMLArea.I18N.tooltips == null || TableOperations.I18N==null )  { 
  	//only needed for first use after redeploy?
    setTimeout('brWwSetup('+isField+')',100); 
  } else { 
     wwEditor = new HTMLArea("wwArea");
     // wwEditor.config.height = (typeof _editor_height == "string") ? (_editor_height + "px") : "400px"; 
     wwEditor.config.height = (typeof _editor_height == "string") ? _editor_height : "400px"; 
     wwEditor.config.width = '100%';
     if (typeof _editor_version != "string") _editor_version = "Corporate";
     if (typeof _editor_cssPath == "string") {
     	wwEditor.config.pageStyle = '@import url(' + _editor_cssPath + ');';
	 } 
	 wwEditor.config.registerButton('moveLeft','Move Left','/wysiweb/images/moveleft.gif', true, function (editor) { 
    	editor.movePage("higher"); 
       } ); 
	 wwEditor.config.registerButton('moveRight','Move Right','/wysiweb/images/moveright.gif', true, function (editor) { 
    	editor.movePage("lower"); 
       } ); 
     wwEditor.config.registerButton('moveUp','Move Up','/wysiweb/images/moveup.gif', true, function (editor) { 
    	editor.movePage("higher"); 
       } ); 
	 wwEditor.config.registerButton('moveDown','Move Down','/wysiweb/images/movedown.gif', true, function (editor) { 
    	editor.movePage("lower"); 
       } ); 
     wwEditor.config.registerButton('deletePage','Delete Page','/wysiweb/images/delete_page.gif', true, function (editor) { 
    	editor.deletePage(); 
       } ); 
	 wwEditor.config.registerButton('save','Save','/wysiweb/images/save.gif',true, function(editor) { editor.wwSave(); } );
     wwEditor.config.registerButton('fileManager','File Manager','/wysiweb/images/file_manager.png', true, function() { 
    	if (typeof fmWindow == 'undefined' || fmWindow.closed) { 
    		urlInput = getFormElem('url') || getFormElem('content_url');
    		fmUrl = 'filemanager.html?url=' + urlInput.value;
    		if (urlInput.name != 'url') { //corporate version
    			fmUrl = '/wysiweb/popups/' + fmUrl;
    		}
    		//alert(fmUrl);
			//fmUrl = '/wysiweb/popups/filemanager.html?url=' + getFormElem('content_url').value; 
			//fmUrl = 'filemanager.html?url=' + getFormElem('url').value; 
    		fmWindow = window.open(fmUrl,'','scrollbars,status,width=495,height=440,resizable',true); 
  	  	} 
      	fmWindow.focus(); 
       } ); 
     wwEditor.config.registerButton('exit','Exit Editor','/wysiweb/images/exit.gif', true, function(editor) { 
    	editor.exitEditor(); 
       } ); 
       
     wwEditor.config.registerButton('newPage','New Page','/wysiweb/images/new.gif', true, function(editor) { 
     	if (_editor_version == "WYSIweb Pro") {
     		editor.newPage('pro');
     	} else {
     		editor.newPage();
     	}
     } );
	wwEditor.config.toolbar = [
    	[ 'save','fileManager','newPage','deletePage','moveUp','moveDown','moveLeft','moveRight','separator',
    	  'T[Heading:]','formatblock','bold','italic','strikethrough','subscript','superscript',
    	  'fontname','fontsize','forecolor', 'hilitecolor','separator', 'copy','cut','paste','separator',
    	  'undo','redo','separator','justifyleft','justifycenter','justifyright','separator', 
    	  'orderedlist','unorderedlist','outdent','indent','separator','inserthorizontalrule','inserttable','createlink','insertimage','separator','htmlmode' ] ]; 
    
    var toHide = "";
    var font_color = " fontname fontsize forecolor hilitecolor";
    var pageTools = " moveUp moveDown moveLeft moveRight deletePage ";
    switch(_editor_version) {
    	case "WYSIweb Demo":
    		toHide = pageTools + "fileManager newPage insertimage ";
    		break;
    	case "WYSIweb Basic": 
    		toHide = pageTools + "fileManager htmlmode insertimage ";
    		break;
    	case "WYSIweb Pro": 
    		toHide = pageTools;
    		//wwEditor.registerPlugin(DynamicCSS);
    		//wwEditor.config.hideSomeButtons(" DynamicCSS-class ");
    		break;  
    	case "WYSIweb Site":
    		wwEditor.config.toolbar[0].splice(0,0,'space');
    		wwEditor.config.toolbar[0].splice(0,0,'pageName');
    		wwEditor.config.toolbar[0].splice(0,0,'T[Page Name:]');
    		toHide = font_color;
    		if (_editor_horizontalMenu) {
    			toHide += " moveUp moveDown ";
			} else {
    			toHide += " moveLeft moveRight ";
			}
   			break;
    	case "Corporate": // Corporate
    		toHide = font_color + pageTools + "newPage ";
    		if (isField) {
    			toHide += "save ";
    		} 
    } 
    if (_editor_version != "Corporate") {
    	urlInput = getFormElem("url");
    	if (urlInput) wwEditor.config.baseURL = urlInput.value;
    }
    if (toHide != "") {
    	wwEditor.config.hideSomeButtons(toHide);
    }
    wwEditor.registerPlugin(ContextMenu);
    if (typeof wwStyleMenu == "object") wwEditor.registerPlugin(CSS, wwStyleMenu);
    wwEditor.registerPlugin(TableOperations);
    if (HTMLArea.is_gecko) wwEditor.registerPlugin(EnterParagraphs);
    wwEditor.generate();
    if (location.search.match(/ww_load_command=(.+)&/)) {
    	eval("wwEditor." + (RegExp.$1) + "()"); //execute command param
    }
  	return false; //what is this for?!
     
  } //end else 
} //end setup 

function fixOnClick(f) { //Hack. Needs to be integrated into editor.
	ta = getElem("wwArea");
	if (f) { //called by save btn 
		ta.value = ta.value.replace(/return false;p=/g, "p=");
		return true;
	} else {
		ta.value = ta.value.replace(/lick="p=/g, 'lick="return false;p=');
	}
}

function moveup() {
	// dummy function 
}

function quickPick() {
	// dummy function for when bedrock_list.js has not yet loaded
}

function checkForCalendar() {
	for (var i=0; i<document.images.length; i++) {
		if (document.images[i].className=="calendarIcon") {
			brAddScript("/bedrock/bedrock_calendar.js");
			break;
		}
	}
}

function brAddScript(fileName) {
	if (mac) {
		document.body.innerHTML += ('<scr' + 'ipt type="text/javascript" src="' + fileName + '"><\/script>');
	} else if (nsie5) {
		var s = document.createElement('script');
		s.src = fileName;
    	document.body.appendChild(s);
	}
}

function brAddEvent(elem, evType, fn, useCapture) {
// addEvent and removeEvent
// cross-browser event handling for IE5+ (not Mac),  NS6 and Mozilla
// By Scott Andrew
  if (elem.addEventListener) {
    elem.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elem.attachEvent) {
    return elem.attachEvent("on"+evType, fn);
  } else {
    alert(msg_incorrectBrowser);
  }
} 

function brCheckAdmin(evt) {  
	evt = (evt) ? evt : (window.event) ? window.event : ""; //get event object
	if (evt.shiftKey) {
		location.href = "/admin/";
	} else {
		location.href = "/"; //go to home page
	}
}

function findCurrency() {
    var inputs = document.getElementsByTagName("INPUT");
    if (inputs.length) {
        for (var i=0; i<inputs.length; i++) {
            if (inputs[i].type=="text" && inputs[i].className.indexOf("currency")!=-1
             && typeof inputs[i].onchange != "function") {
         	inputs[i].onchange = function() { formatCurrency(this); };
            }
        }
    }
    /*
    var tds = document.getElementsByTagName("TD");
    if (!tds.length) return;
    for (var i=0; i<tds.length; i++) {
        if (tds[i].className.indexOf("currency")!=-1) {
            inputs = tds[i].getElementsByTagName("INPUT");
            if (inputs.length) {
            for (var j=0; j<inputs.length; j++) {
                if (inputs[j].type=="text" && typeof inputs[j].onchange != "function") { */
                    /* 
                    if (typeof inputs[j].onchange == "function") {
                        funcRef = inputs[j].onchange;
                        if (funcRef != formatCurrency) {
                            inputs[j].prevOnChange = funcRef;
                            inputs[j].onchange = function() { formatCurrency(this); this.prevOnChange(); };
                        }
                    } else { */
                 /*       inputs[j].onchange = function() { formatCurrency(this); };
                    
                }
            }
            }
        }
    } */
}

function parseNum(str, lang) {
    if (!lang) lang = gLang;
    str = (lang=="fr") ? str.replace(/,/,".") : str.replace(/,/g,"");
    str = str.replace(/\s+/g,"").replace(/\$/g,"");
    if (str.indexOf("(")!=-1) { //negative
    	str = "-" + str.replace(/\x28/g,"").replace(/\x29/g,"");//remove parentheses
    }
    num = parseFloat(str, 10);
    if (isNaN(num)) return 0;
    return num;
}

function formatCurrency(inputObj, format, hideSymbol) {
    var lang = "en";
    if (!format) {
        if (gLang=="fr") { 
            format = "x,xx $";
        } else {
            format = "$x.xx";
        }
    }
    if (format.indexOf(".")!=-1) {
		period = ".";
		comma = ",";
    } else { //french
		period = ",";
		comma = " ";
		lang = "fr";
    }
    num = parseNum(inputObj.value, lang);
    if (num==0) return;
    var str = "" + Math.round(num * 100);
    while (str.length < 3) { // need at least 3 chars, so add leading zeros
		str = "0" + str;
    }
    decPoint = str.length - 2;
    str = str.substring(0,decPoint) + period + str.substring(decPoint,str.length);
    regex  = new RegExp('(-?[0-9]+)([0-9]{3})');
    //check for match to search criteria
    while(regex.test(str)) {
       //replace original string with first group match,
       //a comma, then second group match
       str = str.replace(regex, '$1' + comma + '$2');
    }
    if (period==".") {
        if (num<0) {
            str = "-$" + str.substring(1);
        } else {
            str = "$" + str;
        }
    } else { //french
        if (num<0) {
            str = "(" + str.substring(1) + "$)"; 
        } else {
            str = str + " $";
        }
    }
    if (format.indexOf("$")==-1 || hideSymbol) str = str.replace(/\$/,"");
    inputObj.value = str;
}

function getLang() {
    if (document.documentElement.lang != "") return document.documentElement.lang;
    var props = ["language","userLanguage","browserLanguage","systemLanguage"];
    for (var i in props) {
        if (navigator[props[i]]) return navigator[props[i]];
    }
    return "";
}

function brToggleClass(elem,classStr) {
	cn = elem.className;
	indexOfClassStr = cn.indexOf(classStr);
	if (indexOfClassStr == -1) { // add class if not found
		elem.className = (cn != "") ? (cn + " " + classStr) : classStr;
	} else { // otherwise remove
		elem.className = stripSpaces(cn.replace(classStr,""));
	}
}

function brAddClass(elem,classStr) {
	cn = elem.className;
	if (cn.indexOf(classStr) == -1) { // only add if not found
		//ie mac cant deal with leading whitespace
		elem.className = (cn != "") ? (cn + " " + classStr) : classStr;
	} 
}

function brRemoveClass(elem,classStr) { 
	elem.className = stripSpaces(elem.className.replace(classStr,""));
}

function makeEmail(recipient,domain) {
	if (!domain) domain = location.host;
	if (domain.indexOf("www")==0) domain = domain.substring(4);
	return (recipient + "@" + domain);
}

function emailLink(recipient,domain) {
	addr = makeEmail(recipient,domain);
	return '<a href="mailto:' + addr + '">' + addr + '</a>';
}

function brMail(recipient,domain) {
	document.write(emailLink(recipient,domain));
}

function mail(recipient) {
	document.write(emailLink(recipient));
}

function brFindEmails(elem) {
	if (!nsie5) return;
	if (getElem("wysiWeb")) return;
	for (var i = 0; i < document.links.length; i++) {
		href = document.links[i].href.toLowerCase();
		if (href.indexOf("ismail:")==0) {
			document.links[i].href = "mailto:" + convertEmail(href);
		}
	} 
	if (!elem) elem = document.body;
	do { //keep checking all html until we catch all instances
		html = elem.innerHTML;
		x = html.toLowerCase().indexOf("ismail:");
		if (x !=- 1) {
			endChunk = html.substring(x+7);
			startChunk = html.substring(0,x);
			addr = "";
			fullAddress = endChunk.match(/^[\w-_]+%[\w-_]+\.\w+\b/);
			if (fullAddress) {
				addr = fullAddress[0].split("%");
				addr = emailLink(addr[0],addr[1]);
				endChunk = endChunk.substring(fullAddress[0].length);					
			} else {
				recip = endChunk.match(/^[\w-_]+\b/);
				if (recip) {
					addr = emailLink(recip[0]);
					endChunk = endChunk.substring(recip[0].length);
				}
			}
			elem.innerHTML = startChunk + addr + endChunk;
		}
	} while (x != -1) 
}

function convertEmail(text) {
	addr = stripSpaces(text.substring(7));
	fullAddress = addr.match(/^[\w-_]+%[\w-_]+\.\w+\b/);
	if (fullAddress) {
		addr = fullAddress[0].split("%");
		return makeEmail(addr[0],addr[1]);
	} 
	if (addr.match(/^[\w-_]+$/)) {
		return makeEmail(addr);
	}
	return "";
}

function resetTimer() {
	today = new Date();
    whenOpen = today.getTime();
}

function overTest(e) {
  if (menuOn) {
    source = ns6 ? e.target : event.srcElement;
    if (source) {
	  if (source.tagName!="A") { 
        today = new Date();
        now = today.getTime();
        delay = 800;
        if ( (now - whenOpen) > delay ) { 
          hideMenu();
        }
      } else {
        resetTimer();
      } 
  	}
  } else if (gRow) {
  	brRemoveClass(gRow,"qpHilite");
  }
}

function hideMenu(e) {
 	if (!menuOn) return;
  	menuStyle = getElem(menuOn).style;
    if (menuOn=="quickPick") {
	  	if (window.event) {
			targetObj = event.srcElement;
		} else {
			if ( (e) && (typeof e == "object") && (e.target) ) {
				targetObj = e.target;
			}
		}
    	if (targetObj && targetObj.tagName=="A" && targetObj.id.indexOf("qp")==0) {
			//QP item selected; wait a bit before hiding menu
    		qpEnabled=false;
    		targetObj.style.cursor = "wait";
			gTimeoutId = setTimeout("restoreMenu('" + targetObj.id + "')",1000);
			return;
    	} else {
			menuStyle.visibility = "hidden";
      		brRemoveClass(gRow,"qpHilite");
      	}
	} else {
    	menuStyle.visibility = "hidden";
		loseHoverStyle();
	}
	if (getElem("menuShim")) {
		getElem("menuShim").style.display = "none";
	}
    menuOn = null;
}

function restoreMenu(linkId) {
	qpEnabled = getElem("qpCheck").checked;
	getElem(linkId).style.cursor = "auto";
	brRemoveClass(gRow,"qpHilite");
	if (menuOn) getElem(menuOn).style.visibility = "hidden";
	if (getElem("menuShim")) {
		getElem("menuShim").style.display = "none";
	}
}

function checkWindows() {
	if (ua.indexOf("windows") == -1) {
		document.write(' <strong class="red">You do not appear to be using Windows.</strong>');
	}
}

function checkCookies() {
	if (!navigator.cookieEnabled) {
		document.write(' <span class="red">Cookies appear to be disabled in your browser.</span>');
	}

}

function checkIE() {
	ieOffset = ua.indexOf("msie ");
	version = parseFloat(ua.substring(ieOffset + 5, ua.indexOf(";", ieOffset)));
	if (ieOffset != -1) {
		document.write(' <span class="red">You appear to be using IE version ' + version + '.</span> ');
	} else {
		document.write(' <strong class="red">You do not appear to be using Internet Explorer.</strong>');
	}
}

function showMenu(linkObj) {
	//if ( nsie5 && (!getElem('wysiWeb')) ) {  this line used in DairyCheq
	if (!nsie5) return;
	if (menuOn) hideMenu();
	linkPath = linkObj.pathname;
	slash = (linkPath.indexOf("\\")>-1) ? "\\" : "/";
	menuID="nav-" + linkPath.substring(linkPath.lastIndexOf(slash)+1,linkPath.lastIndexOf("."));
	if (!getElem(menuID)) return;  // make sure menu exists (page may not be fully loaded)
	var menu = getElem(menuID); //menuStyle = getElem(menuID).style;
	Xpos = getOffset(linkObj,"offsetLeft") + (mac ? gMenuXoffsetMac : gMenuXoffset); // + (ns6 ? 1 : 0);
	Ypos = getOffset(linkObj,"offsetTop") + (ie5 ? gMenuYoffsetIe5 : gMenuYoffset) + (mac ? gMenuYoffsetMac : 0); // + (ns6 ? 1 : 0);
	Xpos += "px"; Ypos += "px"; 
	with (menu.style) {
		left = Xpos; top = Ypos;
		visibility = "visible";
	}
	if (getElem("menuShim")) {
		with (getElem("menuShim").style) {
			left = Xpos; top = Ypos;
			height = menu.offsetHeight + "px";
			width = menu.offsetWidth + "px";
			display = "block";
		}
	}
	menuOn = menuID;
	keepHoverStyle(linkObj);
	resetTimer();
}

function keepHoverStyle(linkObj) {
	if (gMenuStyles) { //  where gMenuStyles[x] = new Array(cssProperty, hoverValue, defaultValue);
		for (i=0; i<gMenuStyles.length; i++) {
			eval("linkObj.style." + gMenuStyles[i][0] + " = '" + gMenuStyles[i][1] + "'");
		}
		gMenuLink = linkObj;
	}
}

function loseHoverStyle() {
	if (gMenuLink) {
		selected = (gMenuLink.className.indexOf("selected") != -1);
		for (i=0; i<gMenuStyles.length; i++) {
			restoreStyle = selected ? "" : gMenuStyles[i][2];
			eval("gMenuLink.style." + gMenuStyles[i][0] + " = '" + restoreStyle + "'");
		}
		gMenuLink = null;
	}
}

function getOffset(el,offset) { // from menubarAPI4.js, Copyright 2001 Garrett S. Smith, DHTMLkitchen.com
	return el[offset] + (el.offsetParent ? getOffset(el.offsetParent,offset) : 0);
}

function setSubmitCommand(val) {
	getFormElem("submitCommand").value = val;
}
	
function submitForm(val) {
	with (getFormElem("submitCommand")) {
		value = val;
		form.submit();
	}
}

function submit() {
	getElem("viewList").submit();
}

function verifySubmit() {
	if (!submitted) {
		submitted = 1;
		return true;
	} else {
		alert(msg_formSubmitted);
		return false;
	}
}

function executeIdCommand(command) {
	ls = getFormElem("listSelection");
	id = checkBoxVal;
	if ((id == null) || (id == "")) {
		if (!ls.length) ls = [ls]; //convert to array
		//if (f.listSelection.length == null) {
		//	id = f.listSelection.value;
		//} else {
		for (var i=0; i<ls.length; i++) {
			if (ls[i].checked) {
				id = ls[i].value;
				break;
			}
		}
	}

	if ((id != null) && (id != "")) {
		idurl = getFormElem(command).value;
		if (getFormElem(command + "Javascript") == null) {
			if (idurl.indexOf("?") == -1) {
				idurl = idurl + "?";
			} else {
				idurl = idurl + "&";
			}
			idurl = idurl + "id=" + id;
			changeLocation(idurl);
		} else {
			eval(idurl +"(" + id + ")");
		}			
	}
}

function changeLocation(location) {
	document.location.href = location;
}

function makePopUp(url,w,h,showMenuBar) {
	features = "status,titlebar,resizable,scrollbars,width="+w+",height="+h;
	if (showMenuBar) {
		features = "menubar," + features;
	} 
	newWindow = window.open(url,"PopUp",features);
	newWindow.focus();
}

function stripSpaces(str) { 
  //remove leading and trailing spaces
  return str.replace(/^\s*/, "").replace(/\s*$/, ""); 
}

function brFixLinks() {
//  make external links open in a new window 
  domain = location.host;
  j = document.links.length - 1;
  for (i=0; i<=j; i++)   {
    objLink = document.links[i];
    url = objLink.href;
    if (url.indexOf(domain) == -1 && url.indexOf("javascript") == -1) {
      objLink.target = "_blank";
      objLink.title = "Opens in new window";
    }
  }
}

function brFixTables() {
  if (nsie5) {
	tblArray = document.getElementsByTagName("TABLE"); 
	for (t=0; t<tblArray.length; t++) {
		elem = tblArray[t];
		if (elem.className=="data") {
			colourRows(elem);
		}
	}
  }
}
function colourRows(tbl) { //give even rows of table a grey stripe
  for (i=1; (i<tbl.rows.length && tbl.rows[i].className.indexOf("noStripes")==-1); i++) {
    if (tbl.rows[i].className.indexOf("subHeader")==-1) {
	  if (i%2==0) {
	    brAddClass(tbl.rows[i],"stripe");
	  }
	}
  }
}

function changeWizardPage(wizardPage) {
	with (getFormElem("wizardPage")) {
		value = wizardPage;
		form.submit();	
	}
}
/* not used?
function linkClicked() {
	if (reportRequested) {
		alert(msg_reportRequested);
		return false;
	} else {
		reportRequested = true;
		return true;
	}
}
*/

/*
** COOKIES.JS - JavaScript Cookies Library (version 1.1)
** =====================================================
**
** This library contains OOPed versions of the standard
** set of JS cookie functions: store, get, and del(ete).
**
** You may use and/or modify this JavaScript library
** provided that you maintain this copyright header.
**
** Copyright 1999, Richard Scott (version 1.1). All rights reserved.
**   Streamlined Cookie(), Cookie_store(), Cookie_get(), Cookie_del().
**   Removed document parameter from Cookie() constructor function.
**   Removed CookieTable() diagnostic tool.
**   Added explanatory comments.
**
** Copyright 1997, Christopher Doemel (version 1.0). All rights reserved.
**   There are several good JavaScript cookie libraries around.
**   One is Bill Dortch's public domain cookie functions
**   (at http://www.hidaho.com/cookies/cookie.txt), and another is David 
**   Flanagan's cookie example in JavaScript: The Definitive Guide, 
**   published by O'Reilly Press. This library combines the best features 
**   of both: The thoroughness of Dortch's cookie functions, and the 
**   object-oriented design of Flanagan's cookie example.
*/
function Cookie(name, expires, domain, path, isSecure)
{
  this.name     = name;
  this.expires  = expires;
  this.domain   = domain;
  this.path     = path;
  this.isSecure = isSecure;
}
function Cookie_get() {
  var theWholeCookie = document.cookie;
  var cookieStart = theWholeCookie.indexOf(this.name);
  if (cookieStart == -1)
    return "";  // The cookie wasn't found, so we return an empty string.
  else
    cookieStart += this.name.length + 1;  var cookieEnd = theWholeCookie.indexOf(";", cookieStart);
  if (cookieEnd == -1)
    cookieEnd = theWholeCookie.length;  var theCookie = theWholeCookie.substring(cookieStart, cookieEnd);
  return unescape(theCookie);
}

function Cookie_store(string)
  {
  document.cookie = 
    this.name + "=" + escape(string) + 
    ((this.expires) ? "; expires=" + this.expires.toGMTString() : "") + 
    ((this.path) ? "; path=" + this.path : "") + 
    ((this.domain) ? "; domain="  + this.domain : "") + 
    ((this.isSecure) ? "; secure" : "");
  }

function Cookie_del()
  {
  document.cookie = 
    this.name + "=" +
    ((this.expires) ? "; expires=" + (new Date(0)).toGMTString() : "") + 
    ((this.path) ? "; path=" + this.path : "") + 
    ((this.domain) ? "; domain=" + this.domain : "");
  }

new Cookie();  // need to create a "dummy" Cookie object first
Cookie.prototype.store = Cookie_store;
Cookie.prototype.get   = Cookie_get;
Cookie.prototype.del   = Cookie_del;
