//declarations
var strInvalidTextChars = '';
var strServerRelative = '';
var urlShare = '';
var themeDir = '';
var bIsMobileSite = false;

//**********************************************
//Following functions used for table row highlighting

// alternate each row color
function alternate(id){ 
	if (document.getElementsByTagName) {  
   		var table = document.getElementById(id);   
   		var rows = table.getElementsByTagName("tr");   
   		for (i = 0; i < rows.length; i++) {
   			//manipulate rows 
    		if (rows[i].className.substring(0,16) == "tablelistheading") {
			} else if (rows[i].className != "blank") {
				if (i % 2 == 0) { 
		   			rows[i].className = "even"; 
	     		} else { 
	       			rows[i].className = "odd"; 
	     		}       
			}
		}
   	} 

	//manipulate cells 
	var cells = table.getElementsByTagName("td");   
	for (i = 0; i < cells.length; i++) {
		//manipulate cells
		if (cells[i].className.substring(0,16) == "tablelistheading") { 
   			cells[i].className = cells[i].className + " head"; 
		} else if (cells[i].className == "blank") {
			cells[i].id = "blank";
		} else {
	   		if (cells[i].innerHTML == "") cells[i].innerHTML = "&nbsp;";
			cells[i].id = "cell";
		} 
	} 

   	//set the rollover setting
   	rollover(id,'over');
}

// highlight row on over
var arrayOfRolloverClasses = new Array();
var activeRow = false;
var activeCell = false;

//check if we can ignore the mouseover highlight for this row as it has been overridden
function ignoreRow(thisRow) {
	if (!thisRow.className) {
		return false;
	} else if (thisRow.className.indexOf(" select") > -1) {
		return true;
	} else {
		return false;
	}
}

//highlight a row from a mouse over the row
function highlightTableRow() {
	//get the table object
	var tableObj = this.parentNode;
	if (tableObj.tagName != 'TABLE') tableObj = tableObj.parentNode;
	
	if (!ignoreRow(this)) {
		//if not the currently selected row, store the default class for the row 
		//so we can reset it when we move off the row
		if(this!=activeRow){
			this.setAttribute('origCl',this.className);
			this.origCl = this.className;
		}
		
		//set the row to the highlight style
		this.className = arrayOfRolloverClasses[tableObj.id];
	}
		
	//store the curently active row
	activeRow = this;
}

//reset a row back to its normal style
function resetRowStyle() {
	if (!ignoreRow(this)) {
		var origCl = this.getAttribute('origCl');
		if(!origCl)origCl = this.origCl;
		this.className=origCl;
	}
}

//set the appropriate rollover style for the row
function rollover(tableId,whichClass) {
	arrayOfRolloverClasses[tableId] = whichClass;
	
	//get the table/tbody/rows objects
	var tableObj = document.getElementById(tableId);
	var tBody = tableObj.getElementsByTagName('TBODY');
	if (tBody) {
		var rows = tBody[0].getElementsByTagName('TR');
	} else {
		var rows = tableObj.getElementsByTagName('TR');
	}

	//highlight each row
	for (var i=0;i<rows.length;i++) {
		if (
			rows[i].className == "blank" || 
			rows[i].className == "tablelistheading"
		) {
			//leave the row alone
		} else {
			//set the row's rollover mouse settings
			rows[i].onmouseover = highlightTableRow;
			rows[i].onmouseout = resetRowStyle;
		}
	}
}

//**********************************************
//Following functions used for window manipulation

function resizeOuterTo(w,h) {
 if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    top.outerWidth=w;
    top.outerHeight=h;
   }
   else top.resizeTo(w,h);
 }
}

//**********************************************
//Following functions used for dynamic help
 
var topOffsetAmount = 0;  // These are where the help items will appear relative to the field.
var leftOffsetAmount = 0;
var defaultMessage = "Move your mouse over a field to view a help tip...";

function SetDefault(thisObjectName,defaultText,thisClass) {
 	DisplayContents(thisObjectName,defaultText,thisClass);
}
 
function SetVisibility(thisObjectName, showIt) {  
    var thisObject = document.getElementById(thisObjectName);
    
    if (thisObject) {
		if (showIt)
	    	thisObject.style.visibility = "visible";
	    else
	    	thisObject.style.visibility = "hidden";
	}
}
 
function DisplayContents(thisObjectName,thisText,thisClass) {
    var thisObject = document.getElementById(thisObjectName);
    WriteContents(thisObjectName,thisText,thisClass);
    SetVisibility(thisObjectName, true);
}
 
function WriteContents(thisObjectName,thisText,thisClass) {
    var contents = "<TABLE align='top' border='0' cellpadding='0' cellspacing='0'><tr><td width='4'></td><td class='"+thisClass+"'> "+thisText+" </td><td width='4'></td></tr></TABLE>";
	var thisObject = document.getElementById(thisObjectName)    
 	if (thisObject) thisObject.innerHTML=contents;
}

function pSetDefault(thisObjectName,defaultText,thisClass) {
 	pDisplayContents(thisObjectName,defaultText,thisClass);
}
 
function pSetVisibility(thisObjectName, showIt) {  
    var thisObject = parent.document.getElementById(thisObjectName);
    if (thisObject) {
	    if (showIt)
	    	thisObject.style.visibility = "visible";
	    else
	    	thisObject.style.visibility = "hidden";
	}
}
 
function pDisplayContents(thisObjectName,thisText,thisClass) {
    var thisObject = parent.document.getElementById(thisObjectName);
    pWriteContents(thisObjectName,thisText,thisClass);
    pSetVisibility(thisObjectName, true);
}
 
function pWriteContents(thisObjectName,thisText,thisClass) {
	var contents = "<TABLE align='top' border='0' cellpadding='0' cellspacing='0'><tr><td width='4'></td><td class='"+thisClass+"'>"+thisText+"</td><td width='4'></td></tr></TABLE>";
    var thisObject = parent.document.getElementById(thisObjectName)    
 	if (thisObject) thisObject.innerHTML=contents;
}

//******************************************* 
//Other General Functions

//check for invalid characters in a string
function isNotValidChar(string,notallowed) {
  	for (var i=0; i< string.length; i++) {
    	if (notallowed.indexOf(string.charAt(i)) != -1)
        	return true;
    }
	return false;
}
function printWindow(url) {
	var mywindow = window.open(url, "print", 'width=800,height=700,left=50,top=50,status=1,scrollbars=1,toolbar=1,menubar=1,location=1,resizable')
  	fn_WindowFocus(mywindow);
}
//get absolute x,y positions of object on the screen 
function getObjectX(obj){
	return obj.offsetLeft + (obj.offsetParent ? getObjectX(obj.offsetParent) : obj.x ? obj.x : 0);
}
function getObjectY(obj){
	return (obj.offsetParent ? obj.offsetTop + getObjectY(obj.offsetParent) : obj.y ? obj.y : 0);
}
function getWindowX(){
	if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)>=5) {
	     return window.screenX;
	} else if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4) {
	     return window.screenLeft;
	} else {
		return 0;
	}
}
function getWindowY(){
	if (navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)>=5) {
	     return window.screenY;
	} else if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4) {
	     return window.screenTop;
	} else {
		return 0;
	}
}
//get window scroll position
function getScrollX() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function getScrollY() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
// Browser Window Size and Position, copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005
function getWindowWidth(){
	return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}
function getWindowHeight(){
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

// Browser version
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var Browser = {
  Version: function() {
    var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      // bah, IE again, lets downgrade version number
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}

function fn_ScaleMobileImages (strElementName,intMaxWidth) {
	//scale images down to fit in div
	var els = document.getElementById(strElementName).getElementsByTagName("img");
	for (var i=0; i<els.length;i++) {
		//display the image (as we default it not display:none to stop safari from scaling incorrectly)
		//if (els[i].className.indexOf('full-site-only') < 0) {
			els[i].style.display = "inline";
		//}
		//scale the image
		if (els[i].width && els[i].height) {
			var w = els[i].width;
			var h = els[i].height;
			if (w > intMaxWidth) {
				els[i].style.width = intMaxWidth + "px";
				els[i].style.height = Math.round((intMaxWidth/w)*h) + "px";
			}
		}
	}
}

//******************************************* 
//loop through all check boxes - if name matches the one selected then set the checked value to that chosen
function fn_selectboxes(thisBox) {
	var thisName = thisBox.name;
	for (var i = 0; i < document.form.elements.length; i++) {
	    var e = document.form.elements[i];
		if ((e.name != thisName) && (e.name.indexOf(thisName) == 0) && (e.type == 'checkbox')) {
			e.checked = thisBox.checked;
			eID = e.name.substring(thisName.length)
			fn_selectrow(thisName,eID);
	    }
	}
}

//highlight/restore the selected row
function fn_selectrow(thisName,thisId) {
	var e = document.getElementById(thisName+thisId);
	if (e) {
		//get parent row
		var p = e.parentNode.parentNode;
		if (p.nodeName != "TR") p = p.parentNode;
		if (e.checked) {
			//highlight (add select class, provided it is not already added)
			if (p.className.indexOf("select") == -1) {
				p.className += " " + "select";
			}
		} else {
			//restore (remove select class)
			if (p.className == "select") {
				p.className = "";
			} else {
				p.className = p.className.replace(" select","");
			}
		}
	}

}

//loop through all check boxes - if name matches the one selected then set the checked value to that chosen
function fn_checkselection(boxPrefix,showAlert) {
	for (var i = 0; i < document.form.elements.length; i++) {
	    var e = document.form.elements[i];
		if ((e.name != boxPrefix) && (e.name.indexOf(boxPrefix) == 0) && (e.type == 'checkbox')) {
			if (e.checked == true) {
				return true;
			}
	    }
	}
	if (showAlert) {
		alert ('You need to make your selections that this action applies to BEFORE taking this action.');
	}
	return false;
}

//open the time picker
function fn_TimePicker(strForm, eControl, bAllowIfReadOnly) {
	var bOpenWindow = true;

	if (!bAllowIfReadOnly) {
		if (eControl.readOnly == "Yes" || eControl.disabled) {
			bOpenWindow = false;
			alert ('Time selection not currently allowed.\n\nIf this event is flagged as an All Day Event, uncheck that option first.');
		}
	}
	//open the time picker window
	if (bOpenWindow) {
		var mywindow = window.open('timepicker.cfm?eForm='+strForm+'&eControl='+eControl.name+'&defaulttime='+eControl.value, "timepicker", 'width=225,height=100,left=200,top=200,status=no,scrollbars=no,resizable')
	  	fn_WindowFocus(mywindow);
	}
}

//hide/display a section on a web page
function WebPageDisplaySection(section) {

	//use the parent prefix as safari executes as though in an iframe; ff and ie okay with or without parent prefix.
	var eWebPage = parent.document.getElementById("webPage");
	var heightAdjust = 0;

	if (eWebPage.contentWindow.document.getElementById(section)) {
		var objSection = eWebPage.contentWindow.document.getElementById(section);
		
		//toggle display of the section
		if (objSection.className == "hiddenSection") {
			objSection.className = "";
			heightAdjust = (objSection.offsetHeight + 20);
		} else { 
			heightAdjust = (objSection.offsetHeight + 20) * -1;
			objSection.className = "hiddenSection";
		}
		
		//resize the webpage iframe so page still fits snugly
		if (heightAdjust != 0) {
			eWebPage.height = eWebPage.offsetHeight + heightAdjust;
		}
	}
}

//hiding/displaying sections on a page
function fn_ShowSection(section,show) {
	if (document.getElementById(section)) {
		var objSection = document.getElementById(section);
		if (show) {
			objSection.className = "";
		} else {
			objSection.className = "hiddenSection";
		}
	}
}

function fn_ToggleSection (strSectionName,strSectionType,strCaptionShow,strCaptionHide) {
	var strATag = 'a_' + strSectionName;
	
	//get elements
	var eATag = document.getElementById(strATag);
	var eSection = document.getElementById(strSectionType + '_' + strSectionName);
	var eHiddenClass = document.getElementById('class_' + strSectionType + '_' + strSectionName);
	
	//display/hide section
	if (eSection.className == "hiddenSection") {
		eSection.className = "";
		if (strCaptionHide == '') {
			eATag.innerHTML = expandInnerHTML('collapse');
		} else {
			eATag.innerHTML = "[ " + strCaptionHide + " ]";
		}
	} else {
		eSection.className = "hiddenSection";
		if (strCaptionShow == '') {
			eATag.innerHTML = expandInnerHTML('expand');
		} else {
			eATag.innerHTML = "[ " + strCaptionShow + " ]";
		}
	}
	if (eHiddenClass) eHiddenClass.value = eSection.className;
}

//show or hide an element
// example of initial html on page ... <div id="123" style="display:none">
function ShowHideElement(elementID) {
	var prop
	if (document.getElementById) 
		prop = document.getElementById(elementID).style
	else if (document.all)
		prop = document.all[elementID].style
	else if (document.layers)
		prop = document.layers[elementID]
	
	if (prop.display=='none')
		prop.display = ''
	else
		prop.display = 'none'
}

function fn_CheckFileType(fileName, fileControl, fileTitle, required, showAlert, fileExtArray, fileExtList) {
	//validate the extension of the file is valid  extensionList
    fileTypeValid = false;
	if (fileName == '') {
		if (required) {
			fileTypeValid = false;
			fileControl.focus();
			if (showAlert) { 
				alert (fileTitle + ' is required'); 
			}
		} else {
			fileTypeValid = true;
		}
	} else {
		while (fileName.indexOf("\\") != -1)
			fileName = fileName.slice(fileName.indexOf("\\") + 1);
			ext = fileName.slice(fileName.indexOf(".")).toLowerCase();
		    for (var i = 0; i < extArray.length; i++) {
				if (fileExtArray[i] == ext) { fileTypeValid = true; break; }
	   		}
			if (!fileTypeValid) {
				fileControl.focus();
				if (showAlert) { 
					alert (fileTitle + ' file type is invalid.\n\nThe following file types are allowed:\n\n' + fileExtList);
				}
			}
	}
	return fileTypeValid;
}

//form checking
function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
}

//take action loop
function fn_TakeActionLoop () {
	if (confirm('The Take Action Loop is designed for quick actions for multiple items at a time.\n\nWould you like to read more on how to use the Take Action Loop?')) {
		var mywindow = window.open('help.cfm?section=actions#actions', "help", 'width=900,height=700,left=50,top=50,status=1,scrollbars=1,toolbar=1,menubar=1,location=1,resizable=1');
	  	fn_WindowFocus(mywindow);
	}
}

//******************************************* 
//popup windows

//open choose picture window
function fn_ChoosePicture(server,strControl,strFunction) {
	var mywindow = window.open(server+'/choosepicture.cfm?eControl='+strControl+'&eFunction='+strFunction, "ChoosePicture", 'width=700,height=600,left=25,top=25,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//open the client builder
function fn_ClientBuilder(strForm, strControl) {
	var mywindow = window.open('clientbuilder.cfm?eForm='+strForm+'&eControl='+strControl, "clientbuilder", 'width=550,height=675,left=100,top=20,toolbar=no,status=no,scrollbars=no,resizable=no,location=no')
  	fn_WindowFocus(mywindow);
}

//open clipboard
function fn_ClipboardOpen(urlkey) {
	var mywindow = window.open('clipboard.cfm?urlkey='+urlkey, "Clipboard", 'width=700,height=300,left=25,top=25,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//post a comment
function fn_CommentPost(urlParams,linkType) {
	if (linkType == 'href') {
		var url = fn_EncryptURLParamsJS('commentpost.cfm', urlParams);
	} else {
		var url = 'commentpost.cfm?urlkey=' + urlParams;
	}
	var mywindow = window.open(url, "Comment", 'width=550,height=490,left=100,top=100,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//open the connect window
function fn_Connect(params) {
	var url = fn_EncryptURLParamsJS('connect.cfm', params);
	var mywindow = window.open(url, "connect", 'width=220,height=500,left=100,top=100,toolbar=no,status=no,scrollbars=1,resizable=no,location=no')
  	fn_WindowFocus(mywindow);
}

//open the email builder
function fn_EmailBuilder(strForm, strControl) {
	var mywindow = window.open('emailbuilder.cfm?eForm='+strForm+'&eControl='+strControl, "emailbuilder", 'width=550,height=375,left=100,top=100,toolbar=no,status=no,scrollbars=no,resizable=no,location=no')
  	fn_WindowFocus(mywindow);
}

//edit the gis plot
function fn_GISEditID(id) {
	return fn_GISEdit(id,'',0,0,0);
}

//edit the gis plot
function fn_GISEdit(id,src,srcid,lat,lng) {
	var mywindow = window.open('gisedit.cfm?id='+id+'&src='+escape(src)+'&srcid='+srcid+'&lat='+lat+'&lng='+lng, 'GetLocation', 'width=930,height=550,left=50,top=50,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
	return mywindow;
}

//view the gis plot
function fn_GISView(srcid,src,srclat,srclng,destid,dest,destlat,destlng,printpage,thirdparty) {
	var left = 50;
	var top = 50;
	var target = "PlotInfo";
	
	//set the page location
	if (printpage == "Y") {
		left = 100;
		top = 100;
		target = "_blank";
	}
	
	//build the url string
	var url = 'gisview.cfm';
	url += '?srcid='+srcid;
	url += '&src='+escape(src);
	url += '&srclat='+escape(srclat);
	url += '&srclng='+escape(srclng);
	url += '&destid='+destid;
	url += '&dest='+escape(dest);
	url += '&destlat='+escape(destlat);
	url += '&destlng='+escape(destlng);
	url += '&printpage='+printpage;
	url += '&thirdparty='+thirdparty;
	
	//open the window
	var mywindow = window.open(url, target, 'width=265,height=350,left='+left+',top='+top+',status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
	return mywindow;
}

//view the gis plot
function fn_GISViewID(id) {
	return fn_GISView(0,'',0,0,id,'',0,0,'N','N');
}

//open the group builder
function fn_GroupBuilder(strForm, strControl) {
	var mywindow = window.open('groupbuilder.cfm?eForm='+strForm+'&eControl='+strControl, "groupbuilder", 'width=550,height=675,left=100,top=20,toolbar=no,status=no,scrollbars=no,resizable=no,location=no')
  	fn_WindowFocus(mywindow);
}

//open heplTip
function fn_HelpTip(source,tips) {
	var mywindow = window.open('helptip.cfm?source='+source+'&tips='+encodeURIComponent(tips), "HelpTip", 'width=600,height=400,left=25,top=25,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//Important: fn_HTMLLinkOpen and fn_ImageUpload should always open the page at the same size.  
//If you change one, change the other.

//open htmllink insert window
function fn_HTMLLinkOpen(mode,content) {
	var mywindow = window.open('htmllinkedit.cfm?mode='+mode+'&content='+content, "Image", 'width=700,height=575,left=25,top=25,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//open the upload image screen
function fn_ImageUpload(mode,onupload,albumid,callerevent) {
	var url = 'playerimage.cfm?mode='+mode+'&onupload='+onupload+'&albumid='+albumid;
	if (callerevent != '') url=url+'&callerevent='+callerevent;
	var mywindow = window.open(url, "Image", 'width=700,height=520,left=25,top=25,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//open choose picture window
function fn_MenuFormat() {
	var mywindow = window.open('menuformat.cfm', "MenuFormat", 'width=560,height=400,left=150,top=150,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//post to message board
function fn_MessageBoard(params) {
	var url = fn_EncryptURLParamsJS('messageboardpost.cfm', params);
	var mywindow = window.open(url, "MessageBoard", 'width=510,height=340,left=100,top=100,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//manage news feeds
function fn_NewsFeed(params,linkType) {
	var url = '';
	if (linkType == 'href') {
		var url = fn_EncryptURLParamsJS('playerexternalfeed.cfm', params);
	} else {
		var url = 'playerexternalfeed.cfm?' + params;
	}
	var mywindow = window.open(url, "NewsFeed", 'width=450,height=450,left=100,top=50,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//apply media template
function fn_MediaTemplate(params) {
	var url = fn_EncryptURLParamsJS('playermediatemplate.cfm', params);
	var mywindow = window.open(url, "MediaTemplate", 'width=600,height=625,left=50,top=50,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//popup wizard
function fn_PopupWizard(root,client,wizard,startpage,params,width,height,left,top) {
	var url = root + '/_custom/wizards/' + client + '/' + wizard + '/' + startpage;
	if (params != '') { 
		url = fn_EncryptURLParamsJS(url, params);
	}
	var mywindow = window.open(url, wizard, 'width='+width+',height='+height+',left='+left+',top='+top+',status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//print the item - just the required content
function fn_PrintContent(page,urlParams,fontSize) {
	url = fn_EncryptURLParamsJS(page, urlParams) + '&printPage=Y&printContent=Y';
	if (fontSize != '') {
		url = url + '&fontSize=' + fontSize;
	}
	var mywindow = window.open(url, "print", 'width=750,height=700,left=50,top=50,status=1,scrollbars=1,toolbar=1,menubar=1,location=1,resizable')
  	fn_WindowFocus(mywindow);
}

//open report menu
function fn_ReportMenu(params) {
	var url = fn_EncryptURLParamsJS('_reporting/menu.cfm', params);
	var mywindow = window.open(url, "ReportMenu", 'width=590,height=570,left=50,top=50,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//open report
function fn_ReportOpen(urlkey) {
	var mywindow = window.open('_reporting/report.cfm?urlkey='+urlkey, "Report", 'width=850,height=675,left=50,top=30,status,scrollbars,resizable');
  	fn_WindowFocus(mywindow);
}

//open the report
function fn_ShowReport(reportURL) {
	var mywindow = window.open(reportURL, "report", 'width=800,height=700,left=50,top=50,status=1,scrollbars=1,toolbar=1,menubar=1,location=1,resizable=1')
  	fn_WindowFocus(mywindow);
}

//share the item
function fn_share() {
	var mywindow = window.open(urlShare, "share", 'width=630,height=560,left=100,top=100,status,scrollbars,resizable')		
  	fn_WindowFocus(mywindow);
}

//open the zoom window
function fn_Zoom(strZoomURL, strForm, strControl, defaultMsg) {
	var mywindow = window.open(strZoomURL + '?eForm='+strForm+'&eControl='+strControl+'&defaultMsg='+defaultMsg, "zoom", 'width=550,height=375,left=100,top=100,toolbar=no,status=no,scrollbars=no,resizable=no,location=no')
  	fn_WindowFocus(mywindow);
}

//open the zoom window (just to display some text - not for editing)
function fn_Zoom_ReadOnly(strZoomURL, strValue) {
	var mywindow = window.open(strZoomURL + '?editMode=readonly&value='+escape(strValue), "zoom", 'width=550,height=375,left=100,top=100,toolbar=no,status=no,scrollbars=no,resizable=no,location=no')
  	fn_WindowFocus(mywindow);
}

//window set focus
function fn_WindowFocus (mywindow) {
  	if (mywindow) {
		if (mywindow.opener == null)
		 	{ mywindow.opener = window; }
		if ( parseInt(navigator.userAgent.substring(8,9)) >=3 ) 
			{ mywindow.focus() }
	}
}

//******************************************* 
//trim functions
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function fn_SubMenuChange(sel) {
	//go to the selected link
	var val = sel.options[sel.selectedIndex].value;
	if (val != "") {
		if (val.substring(0,11) == 'Javascript:') {
			if (val.substring(11,27) == 'fn_MessageBoard:') {
				fn_MessageBoard(decodeURIComponent(val.substring(27,9999)));
			}
		} else {
			window.location.href = sel.options[sel.selectedIndex].value;
		}
		sel.selectedIndex = 0;
	}
}

//******************************************* 
//user setting
function fn_setting(setting,value) {
	var params = 'setting=' + encodeURIComponent(setting) + '&value=' + encodeURIComponent(value);
	var result = rpc_Call('','Session',params,'fn_setting_result');
}

function fn_setting_result(xmlDoc) {
	var success = rpc_SingleResult(xmlDoc,"success");
	var message = rpc_SingleResult(xmlDoc,"message");
	var setting = rpc_SingleResult(xmlDoc,"setting");
	var newValue = rpc_SingleResult(xmlDoc,"newValue");
	//update the screen display
	if (success && setting == 'SendNotifications') {
		//change the image and text display on the screen
		if (document.getElementById('usSNImg')) document.getElementById('usSNImg').src = 'images' + themeDir + '/sendnotifications' + newValue+ '.png';
		if (document.getElementById('usSNTitle')) document.getElementById('usSNTitle').innerHTML = '[' + newValue.toUpperCase() + ']';
		if (document.getElementById('usSNSwitch')) document.getElementById('usSNSwitch').innerHTML = '(Switch ' + ((newValue=='On') ? 'Off' : 'On') + ')';
	}
	//display a message to the user
	if (message != '') {
		//\n seems to get messed up somehow in the xml returned value, so replace new line strings chars with the new line code
		message = message.replace(/\(newline\)/g,"\n");
		//display the message
		alert(message);
	}
}

//******************************************* 
//get object properties
var MAX_DUMP_DEPTH = 3;
function dumpObj(obj, name, indent, depth) {
	if (depth > MAX_DUMP_DEPTH) {
		return indent + name + ": <Maximum Depth Reached>\n";
	}
	if (typeof obj == "object") {
		var child = null;
		var output = indent + name + "\n";
    	indent += "\t";
		for (var item in obj)
		{
			try {
				child = obj[item];
	        } catch (e) {
		 		child = "<Unable to Evaluate>";
			}
	        if (typeof child == "object") {
		 		output += dumpObj(child, item, indent, depth + 1);
			} else {
		 		if (item != 'outerHTML' && item != 'outerText' && item != 'innerText' && item != 'innerHTML' && item != 'cookie') {
					output += indent + item + ": " + child + "\n";
				}
			}
		}
		return output;
	} else {
    	return obj;
    }
}

//check for element in an array
function arrayGetPosition(arr,ele) {
	for (var i = 0; i < arr.length; i++) {
		if (arr[i] == ele) {
			return i;
		}
	}
	return -1; //item not found in the array
}

//******************************************* 
//display of web pages - use parent.document. so code works when called from within a iframe web page
function fn_WebPage(encryptedURL) {
	fn_ChangeSection('vwebpage','sView');
	fn_IconSectionMenuHighlight('vmenu','vwebpage');
	parent.document.getElementById('webPage').src = fn_EncryptURLParamsJS('webpageview.cfm', encryptedURL);
}

function fn_WebPageMenuDropdownListChange(e) {
	if (e.selectedIndex) {
		fn_WebPage(decodeURIComponent(e.value));
		e.selectedIndex = 0;
	}
}

//******************************************* 
//iframe prepare
function fn_iFrameLoad(iframeid,heightBuffer,target){

	var className = "";
	
	//set the height of the parent page so the web page fits 'perfectly' and doesn't need to scroll
	var theHeight = document['body'].offsetHeight;
	if (theHeight != 0) {
		parent.document.getElementById(iframeid).height = theHeight + heightBuffer;
	}
	
	//set target for links added to the page so they don't open in the iframe
	// only set to parent IF they don't have the class 'self'
	if (document.getElementsByTagName) {
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href")) {
				if (anchor.target == '' || anchor.target == '_self') {
					//check for assigned class
					className = "";
					if (anchor.getAttribute("class")) {
						className = anchor.getAttribute("class");
					}
					//set if not forced to 'self' class
					if (className != "self") {
						anchor.target = target;
					}
				}
			}
		} 
	}
}

//******************************************* 
//copy/paste

function pasteFromClipBoard(theField) {
	var val = document.getElementById(theField);
	val.focus();
	val.select();
	therange=val.createTextRange();
	therange.execCommand("Paste");
}

//******************************************* 
//search

function fn_checktag(frm,post) {
	if (trim(frm.tag.value) == "") {
		alert('Please enter the word[s] to search for');
		frm.tag.focus();
		return false;
	} else if (isNotValidChar(frm.tag.value,strInvalidTextChars)) {
		alert ('The word[s] to search for cannot contain the following characters: ' + strInvalidTextChars);
		frm.tag.focus();
		return false;
	} else {
		var searchWhat = document.getElementById('searchWhatBox').value;
		if (searchWhat == 'shopproduct' && !bIsMobileSite) {
			frm.action = 'shop.cfm?command=search&shop_search='+frm.tag.value;
		}
		if (post) {
			frm.submit();
		} else {
			return true;
		}
	}
}


//*********************************************
//highlight the save button

//display the tooltip
function tooltipShow (id, text, delay) {
  	//get elements
	var eleHighlight = document.getElementById(id);
  	var eleToolTip = document.getElementById('toolTip');
  	var l = getObjectX(eleHighlight);
	if (eleHighlight.offsetWidth) {
		l = l + eleHighlight.offsetWidth + 5;
	}
  	var t = getObjectY(eleHighlight) - 8;
	//display the tooltip
	eleToolTip.innerHTML = text;
	eleToolTip.style.left = l + "px";
	eleToolTip.style.top = t + "px";
	eleToolTip.style.display = "block";
	//hide after set delay time (delay=seconds)
	setTimeout ( "tooltipHide()", (delay * 1000) );
}

//hide the tooptip
function tooltipHide () {
  	var eleToolTip = document.getElementById('toolTip');
	eleToolTip.innerHTML = "";
	eleToolTip.style.display = "none";
}

//display the tagtip
function tagtipShow (ele, evt, text) {
  	//get elements
  	var eleTagTip = document.getElementById('tagTip');
  	var pw = getWindowWidth();
	var ew = 0;
	var eh = 0;
	var textWidth = '';
	
	//get position of the element
	var l = getObjectX(ele);
	var t = getObjectY(ele);
	if (ele.offsetWidth) {
		ew = ele.offsetWidth;
	}
	if (ele.offsetHeight) {
		eh = ele.offsetHeight;
	}

	//left position
	if ((l+ew) > (pw*(3/4))) {
		//if we are in the right quarter of the page, then display the tip on the left of the element
		if (l >= 260) {
			//only display if we have enough space to do so
			tagClassName = "tagTipLeft";
			l = l - 260;
			t = t + 18;
			if (text.length < 50) {
				//scale the width of the box down to fit the amount of text
				textWidth = Math.round(((text.length / 45) * 250)) + 'px';
			}
		} else {
			//place it underneath the element
			tagClassName = "tagTipRight";
			l = l + 20;
			t = t + eh + 2;
		}
	} else {
		//display to the right of the element
		tagClassName = "tagTipRight";
		l = l + ew;
		t = t + 18;
	}
	//display the tagtip
	eleTagTip.className = tagClassName;
	eleTagTip.innerHTML = "<div class='tagTip'" + (textWidth != '' ? " style='float:right;width:"+textWidth + "'" : '' ) + ">" + text + "</div>";
	eleTagTip.style.left = l + "px";
	eleTagTip.style.top = t + "px";
	eleTagTip.style.display = "block";
}

//hide the tagtip
function tagtipHide () {
  	var eleTagTip = document.getElementById('tagTip');
	eleTagTip.innerHTML = "";
	eleTagTip.style.display = "none";
}

//add an event to an element
function addEvent(ele, evType, fn) {
	elm = document.getElementById(ele);
	if (elm != null) {
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, false);
			return true;
		}
		else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		}
		else {
			elm['on' + evType] = fn;
		}
	}
}

function selectElement(ele) {
	document.getElementById(ele).select();
}

function expandInnerHTML(display) {
	if (display=='expand') {
		return "<img src='images" + themeDir + "/icons/expand.gif' title='Expand'>";
	} else {
		return "<img src='images" + themeDir + "/icons/collapse.gif' title='Collapse'>";
	}
}

//user setting
function usersetting() {

}
