function StringBuffer() { 
   this.buffer = []; 
} 

StringBuffer.prototype.append = function append(string) { 
   this.buffer.push(string); 
} 

StringBuffer.prototype.toString = function toString() { 
   return this.buffer.join(""); 
} 

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "")
}

var m_db

function clientFindFrameAnyLevel( frameName ) {
	var win = clientFindFrameRecursive(clientFindTopLevelWindow(), frameName)
	if (win == null) {
		win = clientFindFrameRecursive(clientFindTopLevel(), frameName)
	}
	return win
}

function clientFindFramesetAnyLevel(framesetID) {
	var win = clientFindFramesetRecursive(clientFindTopLevelWindow(), framesetID)
	if (win == null) {
		win = clientFindFramesetRecursive(clientFindTopLevel(), framesetID)
	}
	return win
}

function clientFindTopLevel() {
	var win = window;
	var parentWin = win;
	for (var i = 0; i < 20; i++) {
		if (typeof(win.parentWindow) == "object" && win.parentWindow != null && typeof(win.parentWindow.name) == "string") {
			parentWin = win.parentWindow;
		} else if (typeof(win.parent) == "object" && win.parent != null) {
			parentWin = win.parent;
		}
		if (win == parentWin) {
			break;
		}
		win = parentWin;
	}
	return parentWin;
}

function clientFindTopLevelWindow() {
	var win = window;
	var parentWin = win;
	for (var i = 0; i < 20; i++) {
		if (typeof(win.parent) == "object" && win.parent != null) {
			parentWin = win.parent;
		}
		if (win == parentWin) {
			break;
		}
		win = parentWin;
	}
	return parentWin;
}


function clientFindTopLevelFromDialog() {
	var lastWin = window;
	var curWin = lastWin;
	for (var i = 0; i < 20; i++) {
		curWin = tryFindHigherWindow(curWin)
		if (lastWin == curWin)
		{
			break;
		}
		lastWin = curWin;
	}
	return curWin;
}


function tryFindHigherWindow(curWin)
{
	var candidateWin = null;
	var levels = ["parentWindow", "parent", "top", "opener", "dialogArguments"];
	for (var i in levels)
	{
		var curProperty = levels[i];
		try
		{
			candidateWin = curWin[curProperty];
		}
		catch (ex)
		{
		}
		if (candidateWin != curWin && testWindowAccess(candidateWin))
		{
			curWin = candidateWin;
			break;
		}
	}
	return curWin;
}


function testWindowAccess(candidateWin)
{
	var hasAccess = false;
	try
	{
		if (candidateWin != null && typeof(candidateWin) == "object" && typeof(candidateWin.name) == "string")
		{
			candidateWin.testProp = "test";
			hasAccess = true;
		}
	}
	catch (x)
	{
	}
	return hasAccess;
}


function clientGetIWayTopWindow() {
	return clientFindFrameAnyLevel("iwaytop")
}

function clientGetIWayTopContainer() {
	var topWin = clientGetIWayTopWindow()
	if (topWin != null) {
		topWin = topWin.parent;
	}
	if (topWin == null) {
		topWin = window.top;
	}
	return topWin;
}

function clientGetFrameIndex(windowObj) {
	if (windowObj == null) {
		return -1
	}
	for (var i = 0; i < windowObj.parent.frames.length; i++) {
		if (windowObj.parent.frames[i] == windowObj) {
			return i
		}
	}
	return -1
}

function clientFindFrameRecursive( obj, framename )
{
	if (obj == null) {
		return null
	}
	var i
	var l = null
	
	try	{
		if (obj.name == framename) {
			return obj
		}
	} catch(e) {}
	
	if (obj.frames) {
		for( i=0 ; i<obj.frames.length;i++ )
		{
			try
			{
				l = clientFindFrameRecursive( obj.frames[i], framename )
			}
			catch (ex)
			{
				l = null ;
			}	
			if( l!=null )
				return l
		}
		return l
	}
	else {
		return null
	}
}

function clientFindFramesetRecursive(windowObj, framesetID) {
	if (windowObj == null) {
		return null
	}
	var fs = null
	
	try	{
		var framesetList = windowObj.document.getElementsByTagName("frameset")
		for (var i = 0; i < framesetList.length; i++) {
			if (framesetList.item(i).id == framesetID ) {
				return framesetList.item(i)
			}
		}
	} catch(x) {}
	
	for (var i = 0; i < windowObj.frames.length; i++) {
		fs = clientFindFramesetRecursive(windowObj.frames[i], framesetID)
		if (fs != null) {
			return fs
		}
	}
	return fs
}

function clientMultiLineToSingleLine(multiLine)
{
	var singleLine = multiLine.replace(/\r\n|\n|\r/g, "_nw_nl_")
	return singleLine
}

function clientSingleLineToMultiLine(singleLine)
{
	var multiLine = singleLine.replace(/_nw_nl_/g, "\r\n")
	return multiLine
}

function clientNotifyLoaded() {
	try {
		window.parent.childFrameLoaded(window.name)
	} catch (x) {}
}

function clientMakeAbsoluteUrl(relativeUrl) {
	var path = window.location.pathname
	var idx = path.lastIndexOf("/")
	if (idx >= 0) {
		path = path.substring(0, idx)
	}
	return window.location.protocol + "//" + window.location.host + path + "/" + relativeUrl
}

function clientLocalDateToIsoDate(localDate) {
	var ld = new Date(localDate)
	if (isNaN(ld)) {
		return ""
	}
	var isoDate = ld.getFullYear() + "-" + clientFormatNumber(ld.getMonth() + 1, "00") + "-" +
		clientFormatNumber(ld.getDate(), "00") + "T" +
		clientFormatNumber(ld.getHours(), "00") + ":" + clientFormatNumber(ld.getMinutes(), "00") +
		":" + clientFormatNumber(ld.getSeconds(), "00");
	var tzOffset = -ld.getTimezoneOffset()
	var sign = tzOffset >= 0 ? "+" : "-"
	tzOffset = Math.abs(tzOffset)
	var hh = clientFormatNumber(Math.round(tzOffset / 60), "00")
	var mm = clientFormatNumber(tzOffset % 60, "00")
	isoDate += sign + hh + ":" + mm
	return isoDate
}
	
function clientIsoDateToLocalDate(isoDate) {
	if (isoDate == null || isoDate == "") {
		return ""
	}
	var parts = isoDate.split("T")
	var date = parts[0]
	if (date.search(/(\d+)\-(\d+)\-(\d+)/) < 0 ) {
		return ""
	}
	var y = RegExp.$1
	var m = RegExp.$2
	var d = RegExp.$3
	var ld = y + "/" + m + "/" + d
	var time = parts.length > 1 ? parts[1] : ""
	var signIdx = time.indexOf("+")
	if (signIdx < 0) {
		signIdx = time.indexOf("-")
	}
	var sign = ""
	var offset = ""
	if (signIdx >= 0) {
		sign = time.charAt(signIdx)
		offset = time.substr(signIdx + 1)
		time = time.substring(0, signIdx)
	}
	if (time.search(/(\d+)\:(\d+)\:?(\d*)/) < 0) {
		return ld
	}
	var hh = RegExp.$1
	var mm = RegExp.$2
	var ss = RegExp.$3
	ld += " " + hh + ":" + mm + ":" + (ss != "" ? ss : "00")
	if (sign == "" || offset.search(/(\d+)\:(\d+)/) < 0) {
		return ld
	}
	var ohh = RegExp.$1
	var omm = RegExp.$2
	var t = Date.UTC(y, m - 1, d, Number(hh), Number(mm), Number(ss))
	var tzOffset = Number(ohh) * 60 + Number(omm)
	t -= Number(sign + "1") * tzOffset * 60 * 1000
	var ld = new Date(t)
	return ld.getFullYear() + "/" + clientFormatNumber(ld.getMonth() + 1, "00") + "/" +
		clientFormatNumber(ld.getDate(), "00") + " " +
		clientFormatNumber(ld.getHours(), "00") + ":" + clientFormatNumber(ld.getMinutes(), "00") +
		":" + clientFormatNumber(ld.getSeconds(), "00");
}

function clientFormatNumber(number, pattern) {
	if (isNaN(number) || pattern == null || pattern == "" ||
		Math.abs(number) > 1e18) {
		return number
	}
	var found = false
	if (pattern.indexOf(".") > 0) {
		found = pattern.search(/(0*)(\.)(0*)/) >= 0
	} else {
		found = pattern.search(/(0+)/) >= 0
	}
	var l = RegExp.$1
	var dot = RegExp.$2
	var r = (RegExp.$3).substring(0, 6)
	if (!found || (l.length == 0 && r.length == 0)) {
		return number
	}
	number = Number(number)
	if (Math.abs(number) < Number("0." + r + "5") || Math.abs(number) < 1e-6) {
		number = 0
	}
	var c = Number("1" + r)
	number = Math.round(number * c) / c
	var num = String(number)
	if (num.search(/(\-?)(\d+)(\.?)(\d*)/) < 0) {
		return num
	}
	var sign = RegExp.$1
	var nl = RegExp.$2
	var ndot = RegExp.$3
	var nr = RegExp.$4
	var count = l.length - nl.length
	for (var i = 0; i < count; i++) {
		nl = "0" + nl
	}
	count = r.length - nr.length
	if (count < 0) {
		nr = nr.substring(0, r.length)
	} else {
		for (i = 0; i < count; i++) {
			nr += "0"
		}
	}
	num = sign + nl + dot + nr
	return num
}

function IWayPopup(title, message, msgType, callbackFunction) {
	this.title = title || ""
	this.message = message || ""
	this.msgType = msgType || ""
	this.msgParams = ""
	this.buttons = ""
	this.defaultButtonIndex = "" // starts from 0
	this.textFieldDefault = ""
	this.width = ""
	this.height = ""
	this.htmlStr = ""
	this.popupType = ""
	this.callbackFunction = callbackFunction
	
	this.show = fnShow
}

function fnShow() {
	var urlParams = ""
	if (this.title != "") urlParams += "title=" + clientEncodeUrlAsUTF8(this.title) + "&"
	if (this.message != "") urlParams += "message=" + clientEncodeUrlAsUTF8(this.message) + "&"
	if (this.msgType != "") urlParams += "msgType=" + this.msgType + "&"
	var msgParamsStr = "";
	if (typeof(this.msgParams) == "object") {
		var size = this.msgParams.length;
		for (var i = 0; i < size; i++) {
			msgParamsStr += this.msgParams[i] + "_iw_delim_";
		}
	} else if (this.msgParams != "") {
		msgParamsStr = this.msgParams.replace(/;/g, "_iw_delim_");
	}
	if (msgParamsStr != "") urlParams += "msgParams=" + clientEncodeUrlAsUTF8(msgParamsStr) + "&"
	if (this.buttons != "") urlParams += "buttons=" + clientEncodeUrl(this.buttons) + "&"
	if (this.defaultButtonIndex != "") urlParams += "defaultButtonIndex=" + this.defaultButtonIndex + "&"
	if (this.textFieldDefault != "") urlParams += "textFieldDefault=" + clientEncodeUrlAsUTF8(this.textFieldDefault) + "&"
	if (this.width != "") urlParams += "width=" + parseInt(this.width) + "&"
	if (this.height != "") urlParams += "height=" + parseInt(this.height) + "&"
	if (this.htmlStr != "") urlParams += "htmlStr=" + clientEncodeUrlAsUTF8(this.htmlStr) + "&"
	if (this.popupType != "") urlParams += "popupType=" + clientEncodeUrlAsUTF8(this.popupType) + "&"
		
	var height = this.height;
	if (this.height == "") {
		height = this.message.split('_nw_nl_').length;
		height += this.message.split('<br>').length-1;
		height += msgParamsStr.split('_nw_nl_').length-1;
		height += msgParamsStr.split('<br>').length-1;
		height *= 15;
		height += 8*2 + 32 + 32	+ 5 //	margin + icon/title + buttons
	}
	var width = this.width != "" ? this.width : "420"
	height = Math.max(height, 201);
	width = Math.max(width, 201);
	var features = "dialogHeight:"+height+"px; dialogWidth:"+width+"; status:no;help:no;scroll:no"

	var url = window.location.protocol + "//" + window.location.host + "/newsway/versions/250/site/iway/app/promptdialog/promptdialog.asp?"
	var callbackFunction = this.callbackFunction
	var res = clientOpenDialog(url + urlParams, "", width, height, callbackFunction);
	return res
}

function iwayConfirm(title, message, msgType, callbackFunction) {
	return iwayConfirmWithParams(title, message, "", msgType, callbackFunction)
}

function iwayConfirmWithParams(title, message, msgParams, msgType, callbackFunction) {
	msgType = msgType || "question"
	var popup = new IWayPopup(title, message, msgType, callbackFunction)
	popup.buttons = /*markLCLZList:*/"Yes;No"
	popup.msgParams = msgParams
	popup.popupType = "confirm"
	return popup.show()
}

function iwayConfirmSave(title, message, msgType, callbackFunction) {
	return iwayConfirmSaveWithParams(title, message, "", msgType, callbackFunction)
}
	
function iwayConfirmSaveWithParams(title, message, msgParams, msgType, callbackFunction) {
	msgType = msgType || "question"
	var popup = new IWayPopup(title, message, msgType, callbackFunction)
	popup.buttons = "Yes;No;Cancel"
	popup.msgParams = msgParams
	popup.popupType = "confirmsave"
	return popup.show()
}

function iwayMessageBox(title, message, msgType, callbackFunction) {
	iwayMessageBoxWithParams(title, message, "", msgType, callbackFunction)
}

function iwayMessageBoxWithParams(title, message, msgParams, msgType, callbackFunction) {
	msgType = msgType || "info"
	var popup = new IWayPopup(title, message, msgType, callbackFunction)
	popup.msgParams = msgParams
	return popup.show()
}

function iwayInput(title, message, textFieldDefault, htmlStr, callbackFunction) {
	return iwayInputWithParams(title, message, "", textFieldDefault, htmlStr,callbackFunction)
}

function iwayInputWithParams(title, message, msgParams, textFieldDefault, htmlStr, callbackFunction) {
	var popup = new IWayPopup(title, message, "input", callbackFunction)
	popup.msgParams = msgParams
	popup.textFieldDefault = textFieldDefault || ""
	popup.htmlStr = htmlStr || ""
	popup.buttons = /*markLCLZList:*/"OK;Cancel"
	popup.popupType = "input"
	return popup.show()
}

function clientEncodeUrl(text) {
	if (text == null || text == "") {
		return ""
	} else if (typeof(text) != "string") {
		return text;
	}
	return escape(text).replace(/\+/g, "%2B")
}

function clientEncodeUrlAsUTF8(text) {
	if (text == null || text == "") {
		return ""
	} else if (typeof(text) != "string") {
		return text;
	}
	return clientEncodeUrl(clientConvertUCS2toUTF8(text))
}

function clientConvertUCS2toUTF8(text) {
	var t = ""
	var byteCountMark = new Array(0x00, 0x00, 0xC0, 0xE0)
	var size = text.length
	for (var i = 0; i < size; i++) {
		var byteCount = 0
		var code = text.charCodeAt(i)
		if (code < 0x80) {
			byteCount = 1
		} else if (code < 0x800) {
			byteCount = 2
		} else if (code < 0xFFFE) {
			byteCount = 3
		}
		switch (byteCount) {
			case 3:
				var c3 = (code | 0x80) & 0xBF
				code >>= 6
			case 2:
				var c2 = (code | 0x80) & 0xBF
				code >>= 6
			case 1:
				var c1 = code | byteCountMark[byteCount]
		}
		switch (byteCount) {
			case 1:
				t += String.fromCharCode(c1)
				break
			case 2:
				t += String.fromCharCode(c1, c2)
				break
			case 3:
				t += String.fromCharCode(c1, c2, c3)
				break
		}
	}
	return t
}

function clientXMLEncode(text)
{
	if (text == null) {
		return "";
	}
	return text.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/\'/g, "&apos;").replace(/\"/g, "&quot;");
}

function clientJsEncode(text) {
	if (text == null) {
		return "";
	}
	return text.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, '\\"');
}

function clientHtmlEncode(text) {
	if (text == null) {
		return "";
	}
	return text.replace(/&/g,"&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, '&quot;').replace(/'/g, '&#39;');
}

function clientFitImgToFrame(imgObj, width, height, margins)
{
	var origWidth,origHeight,newWidth,newHeight
	if (imgObj == null) return;

	if (typeof(imgObj.onreadystatechange) == "undefined") {
		imgObj.onreadystatechange = new Function("clientFitImgToFrame(this,'"+width+"','"+height+"','"+margins+"')")
	}
	if (imgObj.readyState == "complete") {
		try {
			origHeight=imgObj.clientHeight
			origWidth=imgObj.clientWidth
			if (width/origWidth < height/origHeight) {
				newWidth=width
				newHeight=origHeight*width/origWidth
			} else {
				newHeight=height
				newWidth=origWidth*height/origHeight
			}
			imgObj.style.width=newWidth
			imgObj.style.height=newHeight
			imgObj.style.left=(width-newWidth+margins)/2+margins
			imgObj.style.top=(height-newHeight+margins)/2+margins
		} catch (e) {
		}
	}
	else if (imgObj.readyState == "loading"){
	   try {
		imgObj.style.removeAttribute("width")
		imgObj.style.removeAttribute("height")
		}
		catch (e) {
		}
	}
}

function clientGetAllFrameNames() {
	var frameNames = "";
	var frameList = clientFindAllFramesRecursive(clientFindTopLevel());
	for (var i = 0; i < frameList.length; i++) {
		try {
			frameNames += frameList[i].name + ", ";
		} catch (ex) {}
	}
	return frameNames;
}

function clientFindAllFramesRecursive(rootFrame, frameList) {
	if (typeof(frameList) == "undefined" || frameList == null) {
		frameList = new Array();
	}
	if (rootFrame != null) {
		frameList[frameList.length] = rootFrame;
		for (var i = 0; i < rootFrame.frames.length; i++) {
			frameList = clientFindAllFramesRecursive(rootFrame.frames[i], frameList);
		}
	}
	return frameList;
}

function clientInsertCell(row, position) {
	var cell = null;
	if (typeof(position) == "undefined" || position < 0) {
		position = -1;
	}
	if (clientGetMsieVersion() != 6) {
		cell = row.insertCell(position);
	} else {
		var cellCount = row.cells.length;
		cell = window.document.createElement('TD')
		if (position == 0) {
			cell = row.insertAdjacentElement('afterBegin', cell);
		} else {
			cell = row.insertAdjacentElement('beforeEnd', cell)
		}
		if (position != 0 && position != -1 && position < cellCount) {
			for (var i = cellCount - 1; i >= position; i--) {
				row.cells[i].swapNode(cell);
			}
		}
	}
	return cell;
}

function clientGetMsieVersion()
{
	var ver = window.navigator.appVersion;
	var beginIndex = ver.indexOf("MSIE") + 5;
	var finishIndex = ver.indexOf(";", beginIndex);
	var verNumber = ver.substring(beginIndex, finishIndex);
	return (Number(verNumber));
}

function clientCompareVersions(strVer1, strVer2) {
	var result = 0;
	var v1 = strVer1.split(/[.,]/);
	var v2 = strVer2.split(/[.,]/);
	for (var i = 0; i < Math.max(v1.length, v2.length); i++) {
		result = (isNaN(v1[i]) ? 0 : Number(v1[i])) - (isNaN(v2[i]) ? 0 : Number(v2[i]));
		if (result != 0) {
			break;
		}
	}
	return result > 0 ? 1 : result < 0 ? -1 : 0;
}

function clientOpenCalendarDialog(paramsString, dlgCallback)
{
	var url = "/NewsWay/Versions/250/Site/IWay/Gui/Inc/calendar.asp?" + paramsString 
	var rv = clientOpenDialog(url, "", 460, 320, dlgCallback)
	return rv
}

function clientOpenUploadDialog(paramsString, dlgCallback)
{
	var url = "/newsway/versions/250/site/iway/app/genericupload/default.asp?" + paramsString;
	var rv = clientOpenDialog(url, "", 650, 370, dlgCallback)
	return rv;
}

function openPaperDialog( callbackname )
{
	var dialogURL = "/Newsway/ASPX/StockLibrary2/StockForPrintBuyer/PrintBuyerPaperView.aspx";
	iwayOpenDialog( dialogURL, "Paper", "", 850, 600, true, callbackname);
}


function clientShowPdfProof(pdfPath, paramsString, dlgCallback) {
	if (typeof(paramsString) == "undefined" || paramsString == null || paramsString == "") 
	{
		paramsString = "jobid=" + pdfPath;
	} else if (paramsString.search(/jobpath=/i) < 0 && paramsString.search(/jobid=/i) < 0) {
		paramsString += "&jobpath=" + pdfPath;
	}
	var url = "/newsway/versions/250/site/iway/app/jobproofing/default.asp?" + paramsString;
	var rv = "";
	rv = clientOpenDialog(url, "", 800, 560, dlgCallback)
	return rv;
}

function clientOpenIFormEditorDialog(paramsString, window, dlgCallback)
{
 	h = Math.min(window.screen.availHeight, 765);
	w = Math.min(window.screen.availWidth, 970);

	var url = "/newsway/versions/250/site/iway/app/expressEditor/defaultFrameset.asp?" + paramsString;
	var rv = clientOpenDialog(url, "", w, h, dlgCallback)
	return rv;
}

function bannerShowButtons( hideOrShow )
{
	var bannerFrame = clientFindFrameAnyLevel("banner")
	if (bannerFrame != null)
	{
		if( typeof(bannerFrame.showButtons) == "function" ) 
			bannerFrame.showButtons(hideOrShow);
	}

}

function bannerPressButton( status )
{
	var bannerFrame = clientFindFrameAnyLevel("banner")
	if (bannerFrame == null) 
		return;

	if( typeof(bannerFrame.pressButton) == "function" ) {
			bannerFrame.pressButton(status);
	} else if ( typeof(bannerFrame.unHighlightAllSubTabs) == "function" ) {
		bannerPressTab(bannerFrame, status)
	}
}
function bannerPressTab(bannerFrame, status)
{
	var subTabIdx = 0, pageLink = "";
	var statusLow = status.toLowerCase()
	if (statusLow.indexOf("design") != -1) {
		subTabIdx = 0;
		pageLink = "/newsway/interfaces/route_trackDesign.asp";
	} else if (statusLow.indexOf("shopping") != -1 || status.indexOf("order") != -1) {
		subTabIdx = 1;
		pageLink = "/newsway/interfaces/route_trackReadyToOrder.asp";
	} 
	else if (statusLow.indexOf("printing") != -1 ) {
		subTabIdx = 3;
		pageLink = "/newsway/interfaces/route_trackProduction.asp";
	}
	else if (statusLow.indexOf("shipping") != -1 ) {
		subTabIdx = 4;
		pageLink = "/newsway/interfaces/route_trackShipping.asp";
	}
	else if (statusLow.indexOf("received") != -1 ) {
		subTabIdx = 5;
		pageLink = "/newsway/interfaces/route_trackReceived.asp";
	} else {
		return;
	}
	bannerFrame.unHighlightAllSubTabs()
	bannerFrame.highlightSubTab(subTabIdx)
	bannerFrame.submitLink("page", pageLink)
}

function bannerSetStandardBanner( hideOrShow )
{
	var bannerFrame = clientFindFrameAnyLevel("banner")
	if (bannerFrame != null)
	{
		if( typeof(bannerFrame.setStandardBanner) == "function" ) 
			bannerFrame.setStandardBanner(hideOrShow);
	}

}

function bannerArrangeButtons( hideOrShow )
{
	var bannerFrame = clientFindFrameAnyLevel("banner")
	if (bannerFrame != null)
	{
		if( typeof(bannerFrame.arrangeButtons) == "function" ) 
			bannerFrame.arrangeButtons(hideOrShow);
	}

}

function bannerPseudoPressButton( hideOrShow )
{
	var bannerFrame = clientFindFrameAnyLevel("banner")
	if (bannerFrame != null)
	{
		if( typeof(bannerFrame.pseudoPressButton) == "function" ) 
			bannerFrame.pseudoPressButton(hideOrShow);
	}

}


function bannerArrangeStandardButtons()
{
	var bannerFrame = clientFindFrameAnyLevel("banner")
	if (bannerFrame != null)
	{
		if( typeof(bannerFrame.arrangeStandardButtons) == "function" ) 
			bannerFrame.arrangeStandardButtons();
	}

}


function menuShowUserInfo(jobcount, status)
{
	var menuFrame = clientFindFrameAnyLevel("menu")
	if (menuFrame != null)
	{
		if( typeof(menuFrame.showUserInfo) == "function" ) 
			menuFrame.showUserInfo(jobcount, status);
	}

}

function menuJobsInfo()
{
	var menuFrame = clientFindFrameAnyLevel("menu")
	if (menuFrame != null)
	{
		var jobsInfoObj = menuFrame.document.getElementById("jobsInfo")
		if ((jobsInfoObj != null) && (typeof(jobsInfoObj) != "undefined"))
			return jobsInfoObj;
	}
	return null;
}

function clientGetFileName(filePath,withExtention)
{
	var ret = ""
	var arr =  filePath.split(/[\/\\]/);
	if (withExtention==false) 
	{
		var index = arr[arr.length - 1].lastIndexOf(".")
		if( index<0 ) {
			ret =  arr[arr.length - 1];
		}
		else {
			ret = arr[arr.length - 1].substr(0,index) ;
		}
	}
	else 	{
		ret = arr[arr.length - 1];
	}
	if (typeof(ret)=="undefined") {
		ret = ""
	}
	return ret;	
}

function clientGetFileExtension(filename)
{
	var ext
	var index = filename.lastIndexOf(".")
	if( index<0) 
		ext=""
	else
		ext = filename.substr(index+1).toLowerCase()
	return ext
}

function clientGetFilePath(filePath)
{
	var ret = ""
	var i
	var arr =  filePath.split(/[\/\\]/);
	for (i=0;i<arr.length-1;i++)
	{
		ret = ret + "/" + arr[i];
	}
	return ret
}

function clientIsValidFileName(fileName)
{
	var isValid = true;
	if (fileName == null || fileName == "" || fileName.search(/[\\\/\:\*\?\"\<\>\|]/) >= 0) {
		isValid = false;
	}
	return isValid;
}

function clientIsMac()
{
	var ret = true
	try {
		ret = (window.navigator.appVersion.search(/mac/i) >= 0) || (clientBrowserType()=="gekko");
	} catch (ex) {}
	return ret 
}

function isAlphaNumeric(nameToCheck) {
	if (typeof(nameToCheck) == "undefined" || nameToCheck == null || nameToCheck == "") {
		return false;
	}
	return (nameToCheck.search(/[^ -\.\w]/) == -1);
}

function clientContainsOnlyAsciiChars(str)
{
	if (typeof(str) == "undefined" || str == null || str == "") {
		return true;
	}
	for (var i=0;i<str.length;i++)
	{
		var charCode = str.charCodeAt(i)
		if (charCode>127) {
			return false;
		}
	}
	return true;
}

function clientBrowserType()
{
	var agt = window.navigator.userAgent.toLowerCase();
	var is_gecko = (agt.indexOf('gecko') != -1);
	if (is_gecko) {
		return "gekko"
	}
	var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	if (is_ie) {
		return "ie"
	}
}

function clientOpenChildWindow(sURL, params, width, height, dlgCallback) 
{
	if (typeof(params) != "object" || params == null) {
		params = new Array()
	    params["dlgModeless"] = "true"
	}
	clientOpenDialog(sURL, params, width, height, dlgCallback) 
}

function clientOpenWindow(sURL , sName , sFeatures )
{
	var winObj = window
	while (winObj.dialogArguments && typeof(winObj.dialogArguments)=="object" && typeof(winObj.dialogArguments.open)!="undefined")
	{
		winObj = winObj.dialogArguments
	}
	return winObj.open(sURL , sName , sFeatures)
}

function clientOpenDialogWithCallback(sURL, params, width, height, dlgCallback)
{
	var ret = clientOpenDialog(sURL, params, width, height, dlgCallback) 
	if (ret)
	{
		clientCallFunction(dlgCallback, ret)
	}
}

function clientOpenDialog(sURL, params, width, height, dlgCallback) {
	var paramsStr = "";
	
	var dlgModeless = false
	
	if (sURL.indexOf("?")>=0) {
		var lastChar = sURL.charAt(sURL.length-1);
		if (lastChar!="&") {
				sURL += "&"
		}
	}
	else {
		sURL += "?"
	}
	
	if (typeof(params) == "object" && params != null) {
		for (var key in params) {
			paramsStr += key + "=" + clientEncodeUrlAsUTF8(String(params[key])) + "&" ;
		}
		if (params["dlgModeless"]=="true")
		{
			dlgModeless = true;
		}
	} else if (params != "") {
		paramsStr = params + "&";
	}
	if (paramsStr!="") {
		sURL += paramsStr;
	}
		
	
	var sFeatures = '';
	if (clientBrowserType()=="ie")
	{
		var delta = getIEModalSizeDelta();
		
		sFeatures += 'dialogWidth:' + (Number(width)+delta.x) + 'px';
		sFeatures += ';dialogHeight:' + (Number(height)+delta.y) + 'px';
		sFeatures += ';status:yes';
		sFeatures += ';help:no';
		sFeatures += ';resizable:yes';
		sFeatures += ';center:yes';
		
		var ret = null;
		if (dlgModeless)
		{
			try
			{
				ret = window.showModelessDialog(sURL , window, sFeatures)
			}
			catch(e){}
		}
		else
		{
			try
			{
				ret = window.showModalDialog(sURL , window, sFeatures)
			}
			catch(e){}
		}	
		
		return ret;
	}
	else {
	    var topWindowScreen = window.top.screen
		var LeftPos = (topWindowScreen.width) ? (topWindowScreen.width-width)/2 : 0;
		var TopPos = (topWindowScreen.height) ? (topWindowScreen.height-height)/2 : 0;
		
		sFeatures += 'width=' + width + 'px';
		sFeatures += ',height=' + height + 'px';
		sFeatures += ',top=' + TopPos + 'px';
		sFeatures += ',left=' + LeftPos + 'px';
		sFeatures += ',directories=no';
		sFeatures += ',location=no';
		sFeatures += ',menubar=no';
		sFeatures += ',resizable=yes';
		sFeatures += ',status=yes';
		sFeatures += ',toolbar=no';
		sFeatures += ',scrollbars=yes';
		sFeatures += ',modal=yes';
		sFeatures += ',alwaysRaised=yes';
		sFeatures += ',dependent=yes';
		sFeatures += ',dialog=yes';
						
		if (typeof(dlgCallback)!="undefined" && dlgCallback!="")
		{
			sURL += "dlgCallback=" + dlgCallback
		}	
		
		var ret = clientOpenWindow(sURL ,"_blank", sFeatures)
		return null;
	}
}

function clientCallDlgCallback(dlgCallback, retVal)
{
	if ( (typeof(dlgCallback)=="undefined") || (dlgCallback=="")) {return}
	if (typeof(parent.clientDlgCallback)!="undefined") {
		parent.clientCallDlgCallback( dlgCallback, retVal)
	}
	else {
		try {
			var openerWindow = window.opener
			if (!openerWindow) openerWindow = window.top.opener
			eval("openerWindow." + dlgCallback + "(retVal)")
		}
		catch (ex){ }	
	}
}

function clientCallFunction(funcName, arg)
{
	try {
		eval(funcName + "(arg)");
	}
	catch (ex) {}
}

function clientCloseModalDialog()
{
	if (window.dialogWidth) {
		window.top.close()
	} else {
		window.parent.hidePopWin(true)
	}
}

function checkPopupBlocker() {
	if (isPopupBlocker()) {
		var elem = window.document.getElementById("popupmsg");
		if (elem != null) {
			elem.style.display = "";
		}
	}
}

function isPopupBlocker() {
	var popup = clientOpenWindow("/newsway/versions/250/site/iway/empty.htm","","width=1,height=1,left=5000,top=5000,scrollbars=no");
	var blocked = true;
	if (popup) {
		blocked = false;
		popup.close();
	}
	return blocked;
}

function getIEModalSizeDelta()
{
	var dataWindow = clientFindTopLevelFromDialog();
	if (dataWindow.isModalDeltaSet)
	{
		return {'x' : dataWindow.modalDeltaX, 'y' : dataWindow.modalDeltaY};
	}

	dataWindow.isModalDeltaSet = true
	dataWindow.modalDeltaX = 0;
	dataWindow.modalDeltaY = 0;
	if (!window.showModalDialog)
	{
		return {'x' : dataWindow.modalDeltaX, 'y' : dataWindow.modalDeltaY};
	}

	var modalReqWidth = 400;
	var modalReqHeight = 400;
	var retObj = clientOpenDialog("/newsway/versions/250/site/iway/general/modalSizeGetter.html", "", modalReqWidth, modalReqHeight)
	if (retObj)
	{
		dataWindow.modalDeltaX = modalReqWidth - retObj.x;
		dataWindow.modalDeltaY = modalReqHeight - retObj.y;
	}
	return {'x' : dataWindow.modalDeltaX, 'y' : dataWindow.modalDeltaY};
}

function clientOpenEmailMessage(emailPath)
{
	var url = window.location.protocol + "//" + window.location.host + "/newsway/versions/250/site/iway/inc/showemail.asp"
	var ret = clientOpenDialog(url+"?path="+clientEncodeUrlAsUTF8(emailPath), "", 630, 450)
}

function clientOpenChangePasswordDialog(mode, loginName, userID)
{
    var url = window.location.protocol + "//" + window.location.host + "/newsway/versions/250/site/iway/gui/administration/users/changePassword.asp?" +
				"initiatedBy=" + mode + "&loginName=" + loginName + "&userID=" + userID;
	var ret = clientOpenDialog(url, "", 545, 405)	
}

function clientIsValidEmail(emails)
{
	if (typeof(emails)=="undefined" || emails=="" ) return false;
	var filter = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
	
	var emailsArr = emails.split(/[\s]*[;,][\s]*/);
	for (var i=0; i<emailsArr.length; i++)
	{
		var email = emailsArr[i].trim();
		if (!filter.test(email)) return false;
	}

	return true;				
}

/// A cross-browser alternative to swapNode() (which works in IE only)
/// Be careful with swaping table cells inside a row - might not always work
function swapBetweenNodes(node1, node2)
{
	if (node1.swapNode) {
		node1.swapNode(node2);
	} else {
		var tempNode = node1.cloneNode(1);
		var nodesParent = node1.parentNode;
		node2 = nodesParent.replaceChild(tempNode, node2);
		nodesParent.replaceChild(node2, node1);
		nodesParent.replaceChild(node1, tempNode);
		tempNode = null;	// Free it up
	}
}