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 stringTrim() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};

var m_db;

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 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 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 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 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 iwayConfirmWithGivenButtonNames(title, message,msgType, callbackFunction, buttonNames) {
    return iwayConfirmWithGivenButtonNamesWithParams(title, message,"", msgType, callbackFunction, buttonNames)
}
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 iwayConfirmWithGivenButtonNamesWithParams(title, message, msgParams, msgType, callbackFunction, buttonNames) {
	msgType = msgType || "question"
	var popup = new IWayPopup(title, message, msgType, callbackFunction)
	popup.buttons = buttonNames
	popup.msgParams = msgParams
	popup.popupType = "newconfiguration"
	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, filterPaperString )
{
	if (typeof(filterPaperString) == "undefined" || filterPaperString == null)
		filterPaperString = "";
	
	var dialogURL = "/Newsway/ASPX/StockLibrary2/StockForPrintBuyer/PrintBuyerPaperView.aspx";
	iwayOpenDialog( dialogURL, "Paper", filterPaperString, 850, 600, true, callbackname);
}

//open actual usage dialog from iway - track jobs 
function openActualPreesSheetsCountDialog(sURL, callbackname )
{
	iwayOpenDialog( sURL, "iWay", "", 380, 180, 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 = getIFormMainUrl() + "?" + 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)
	}
}

// If returnNewWindowRef = true : Returns the new window's object ONLY in non-IE browsers !! (in IE returns null)
// If returnNewWindowRef = false : Returns null for non-IE browser. For IE returns the returnValue of the dialog

function clientOpenDialog(sURL, params, width, height, dlgCallback, returnNewWindowRef) {
	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 returnNewWindowRef ? null : 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 returnNewWindowRef ? ret : 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;	
	iwayLightWindow( { href: url, clickOnOuterDivWillDeactivate: false, width: 545, height: 425 });
}

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
	}
}

 // adds events to window load (support for all common browsers)
function addOnloadEvent(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else 
      window.onload = fnc;
  }
}

function addOnUnloadEvent(fnc)
{
	if ( typeof window.addEventListener != "undefined" )
	{
		window.addEventListener( "unload", fnc, false );
	}
	else if ( typeof window.attachEvent != "undefined" )
	{
		window.attachEvent( "onunload", fnc );
	}
	else if ( window.onunload != null )
	{
		var oldOnunload = window.onunload;
		window.onunload = function ( e )
		{
			oldOnunload( e );
			window[fnc]();
		}
	}
	else
	{
		window.onunload = fnc;
	}
}

// Light Window functions:


// The function closes any current active lightwindow refferenced on this page and returns the orignal orignater of the LightWindow
// parameters: id (optional), the LW ID which we want to close
function CloseLightWindow(id)
{	
	try
	{
		var lwWindow = ReturnFirstTopLWWindow(window,true,id);
		if(typeof(lwWindow.myLightWindow)!="undefined" && lwWindow.myLightWindow !== null)
		{
			if(id)
			{
				if(lwWindow.myLightWindow.id != id)
				{
					return;
				}
			}
			lwWindow.myLightWindow.deactivate();
			lwWindow.myLightWindow = null;
		}
  }
  catch(ex)
  {
  }
}

/// <summary>
/// Finds a child Element of the specified parentObj element according to desired ID [Cross Browser]. Replaces obj.all() in IE
/// </summary>
/// <param name="parentObj">DOM object to search from</param>
/// <param name="childId">ID to look for</param>
/// <returns>The matching object, null if not found</returns>
function getChildElementById(parentObj, childId)
{
	var childs = parentObj.childNodes;
	for (var i=0;i < childs.length;i++)
	{
		var child = childs[i];
		if (child.id == childId)
			return child;
		var lookInChild = getChildElementById(child, childId);
		if (lookInChild)
			return lookInChild;
	}
	return null;
}

/// <summary>
/// Adds an event listener [Cross Browser]
/// </summary>
/// <param name="obj">DOM object to add the event listener to</param>
/// <param name="type">String of the event name, without the "on" prefix, e.g. "click"</param>
/// <param name="handler">The handler function to run for the event</param>
function addEvent(obj, type, handler) {
	if (obj.addEventListener) {
		obj.addEventListener(type, handler, false);
	} else if (obj.attachEvent){
		obj["e" + type + handler] = handler;
		obj[type + handler] = function() { obj["e" + type + handler]( window.event ); }
		obj.attachEvent("on" + type, obj[type + handler]);
	}
}


/// <summary>
/// Removes an event listener [Cross Browser]
/// </summary>
/// <param name="obj">DOM object to remove the event listener from</param>
/// <param name="type">String of the event name, without the "on" prefix, e.g. "click"</param>
/// <param name="handler">The handler function to remove for the event</param>
function removeEvent(obj, type, handler) {
	if (obj.removeEventListener)
		obj.removeEventListener(type, handler, false);
	else if (obj.detachEvent)
	{
		if (obj[type + handler]) {
			obj.detachEvent( "on" + type, obj[type + handler] );
			obj[type + handler] = null;
			obj["e" + type + handler] = null;
		}
	}
}


/// <summary>
/// Cross browser function to create an empty XML manipulation object
/// </summary>
/// <param name="rootTagName">[optional] Tag name of root element</param>
/// <param name="namespaceURL">[optional] Namespace</param>
/// <returns>An XML object</returns>
function createNewXMLDocument(rootTagName, namespaceURL)
{
	if (typeof(rootTagName) == "undefined") {
		rootTagName = "";
	}
	if (typeof(namespaceURL) == "undefined") {
		namespaceURL = "";
	}
	
	if (document.implementation && document.implementation.createDocument) {
		// W3C standard
		return document.implementation.createDocument(namespaceURL, rootTagName, null);
	} else {
		// IE way
		var doc = new ActiveXObject("MSXML2.DOMDocument");
		if (rootTagName) {
			// Look for a namespace prefix
			var prefix = "";
			var tagname = rootTagName;
			var p = rootTagName.indexOf(':');
			if (p != -1) {
				prefix = rootTagName.substring(0, p);
				tagname = rootTagName.substring(p + 1);
			}
			if (namespaceURL) {
				if (!prefix)
					prefix = "a0"; // same as Firefox
			} else {
				// If no namespace, discard any prefix
				 prefix = "";
			}
			// Create the root element
			var text = "<" + 
			(prefix?(prefix+":"):"") + 
			tagname +
			(namespaceURL ? (" xmlns:" + prefix + '="' + namespaceURL +'"') : "") +
			"/>";
			doc.loadXML(text);
		}
		return doc;
	}
}

/// <summary>
/// Transforms an XML Island DOM object to an XML object [Cross Browser]. (in IE this was not needed as these objects are the same)
/// </summary>
/// <param name="domObject">The XML Island DOM object</param>
/// <returns>An XML object</returns>
function getXMLObject(domObject)
{
	if (domObject.documentElement) {
		return domObject;
	}
	
	var docElement = domObject.firstChild;
	while(docElement != null) {
		if (docElement.nodeType == 1 /*Node.ELEMENT_NODE*/)
			break;
		docElement = docElement.nextSibling;
	}
	var doc = createNewXMLDocument();
	if (docElement) {
		doc.appendChild(doc.importNode(docElement, true));
	}
	return doc;
}

/// <summary>
/// Gets an array of nodes matching a specified XPath query as child nodes of specified XML Node [Cross Browser - replaces xmlNodeObj.selectNodes() in IE]
/// </summary>
/// <param name="xmlNodeObj">The XML Node object</param>
/// <param name="xPathQuery">The XPath Query to look for</param>
/// <returns>An array of matching nodes (if non found, an emty array is returned). If can’t perform the task (incompatible browser), null is returned</returns>
function selectNodesFromXMLNode(xmlNodeObj, xPathQuery)
{
	var nodeArr = new Array();
	var node;
	if (window.ActiveXObject) {
		// Can't check for .selectNodes so this to find out if it's IE
		// IE way
		var nodes = xmlNodeObj.selectNodes(xPathQuery);
		while (node = nodes.nextNode())
		{
			nodeArr.push(node);
		}
	} else {
		// W3C way
		if (window.XPathEvaluator) {
			var xpe = new XPathEvaluator();
			var xpr = xpe.createNSResolver(xmlNodeObj);
			var xpResults = xpe.evaluate(xPathQuery, xmlNodeObj, xpr, 0, null);
			while (node = xpResults.iterateNext())
			{
				nodeArr.push(node);
			}
		} else {
			return null;
		}
	}
	return nodeArr;
}

/// <summary>
/// A cross-browser confirm function which always returns true or false.
/// In IE shows iWay confirm dialog, in other browsers shows the standard JavaScript confirm dialog
/// NOTE: None of the strings are translated by the function. Translations are the responsibility of the calling function
/// </summary>
/// <param name="title">Title of the dialog. Applicable only in IE</param>
/// <param name="message">The text of the confirm message</param>
/// <param name="msgType">Type of dialog to display. Applicable only in IE</param>
/// <returns>Always returns True or False according to user's decision</returns>
function iwayConfirmEx(title, message, msgType) {
	if (window.ActiveXObject) {
		// in IE
		return iwayConfirm(title, message, msgType);
	} else {
		return window.confirm(cleanUpStringForConfirm(message));
	}
}

/// <summary>
/// A cross-browser confirm function which always returns true or false.
/// In IE shows iWay confirm dialog, in other browsers shows the standard JavaScript confirm dialog
/// Interprets msgParams into the message string using the "_nw_value:ParamName_" convention
/// NOTE: None of the strings are translated by the function. Translations are the responsibility of the calling function
/// </summary>
/// <param name="title">Title of the dialog. Applicable only in IE</param>
/// <param name="message">The text of the confirm message</param>
/// <param name="msgParams">An array with params for the string, in the order they should appear</param>
/// <param name="msgType">Type of dialog to display. Applicable only in IE</param>
/// <returns>Always returns True or False according to user's decision</returns>
function iwayConfirmExWithParams(title, message, msgParams, msgType) {
	if (window.ActiveXObject) {
		// in IE
		return iwayConfirmWithParams(title, message, msgParams, msgType);
	} else {
		// Insert params into the message string
		if (typeof(msgParams) != "object") {
			var ar = new Array(msgParams);		// Only 1 value, insert into an array
			msgParams = ar;
		}
		var charPos = message.indexOf("_nw_value:");
		var endCharPos;
		var arrayPos = 0;
		while (charPos != -1) {
			endCharPos = message.indexOf("_", charPos + 10);
			if (endCharPos == -1) {
				// No ending underscore
				break;
			}
			var replaceValue = "";
			if (typeof(msgParams[arrayPos]) != "undefined") {
				replaceValue = msgParams[arrayPos];
			}
			message = message.substring(0, charPos) + replaceValue + message.substring(endCharPos + 1);
			
			arrayPos++;
			charPos = message.indexOf("_nw_value:");
		}
		message = cleanUpStringForConfirm(message);
		return window.confirm(message);
	}
}

/// <summary>
/// Private function for iwayConfirmEx() and iwayConfirmExWithParams(). Removes HTML tags and iway codes
/// </summary>
function cleanUpStringForConfirm(message)
{
	message = clientSingleLineToMultiLine(message); // Convert _nw_nl to new lines
	message = message.replace(/<[/]?br[^>]*?>/gi, "\n");
	message = message.replace(/<[/]?(span+)[^>]*?>/gi, "");
	return message;
}
// Returns the current acive lightwindow object
// parameters: id (optional), the LW ID which we want to get
function GetLightWindow(id)
{
	var lwWindow = ReturnFirstTopLWWindow(window,true,id);

    if(typeof(lwWindow.myLightWindow)!="undefined" && lwWindow.myLightWindow != null)
    {
        return lwWindow.myLightWindow;
    }
    return null;
}

// This is a legacy suppport function that tries to close any current open window or open lightwindow
// returns (in case of a light window) the originator of this call
function CloseWinOrLightWindow()
{	
    if(window.top.opener || window.opener || (typeof(dialogArguments) != "undefined" && dialogArguments)) // if this is a pop up (and therefore we have its opener) or a modal dialog
    {
        window.top.close();
    }
    else
    {
        CloseLightWindow();
    }
}

// Returns the first parent location for a LightWindow container and returns a new instance of the LightWindow
// object instance at that parent element
function createMostParentLightWindow()
{   
	var lwWindow = ReturnFirstTopLWWindow(window,false);

    if(checkElementForLightWindow(lwWindow))
    {
        myLightWindow = lwWindow.createNewLightWindow();
        return myLightWindow;
    }

    throw "No LightWindow was found at TOP";    
}

// parameters: id (optional), the LW ID where looking for
// ActiveLW : if true, return only an active LW window
function ReturnFirstTopLWWindow(winObj,ActiveLW,id)
{
	if(winObj && winObj.IsLightWindow && winObj.IsLightWindow == true)
	{
		if(!ActiveLW)
		{			
			return winObj;			
		}
		else
		{
			if(typeof(winObj.myLightWindow)!="undefined" && winObj.myLightWindow != null)
			{
				if(id) // if we need to return a specific id then:
				{	
					if(winObj.myLightWindow.id == id)
					{				
						return winObj;
					}
				}
				else
				{
					return winObj;
				}
			}
		}
	}
	if(winObj.parent == winObj)
	{
		return winObj;
	}
	return ReturnFirstTopLWWindow(winObj.parent,ActiveLW,id);
}

// checkes if the provided element is OK to start a light window on
function checkElementForLightWindow(obj)
{
    if(obj && typeof(obj.createNewLightWindow) != "undefined" && obj.document.getElementsByTagName('frameset').length < 1)
    {
        return true;
    }
    return false;
}


function LWPleaseWait(InfoDivID,widthLocal,heightLocal,setUnloadEvent)
{	
	var topLW = createMostParentLightWindow()
	topLW.activateWindow(
		{
			href: InfoDivID,
			type: 'inline',
			title: '',
			clickOnOuterDivWillDeactivate: false,
			windowRef: window,
			width: widthLocal,
			height: heightLocal,
			disableCancel: true,
			id: 'PleaseWait',
			onlyLoading: true
		}
	);        
	if(setUnloadEvent)
	{
	    setInterval("LightWindowUnloadTimer('PleaseWait')",100);
		addOnUnloadEvent(function(){try {CloseLightWindow('PleaseWait');} catch(ex){}});
	    topLW.UnloadOnWindowChnage();
	}
}

function LightWindowUnloadTimer(id)
{
    var lwWindow = GetLightWindow(id);
    if(lwWindow!= null) // in case the LWPleaseWait was called with setUnloadEvent = true, but someone is closing the LW manually
    {
        lwWindow.NotifyStillActive((new Date()).valueOf());
    }
}

// opens a URL in a new light window
function iwayLightWindow(options)
{
    /*
    var elementOptions = Object.extend({
			href : null,	// MANDATORY!		
			top : null,
			left : null,
			height : null, 
			width : null,		
			clickOnOuterDivWillDeactivate : false,
			disableCloseLink : false,			
			disableCancel : false
		}, options || {});
	*/
	
	var elementOptions = { 
			href : null,	// MANDATORY!		
			top : null,
			left : null,
			height : null, 
			width : null,		
			clickOnOuterDivWillDeactivate : false,
			disableCloseLink : false,			
			disableCancel : false,
			callContext : null,
			callbackFunctionName : null,
			id : null
			};
	if(options.href)
	{
		var url = options.href.split("?");
		if(url.length > 1)
		{
			elementOptions.href = "/NewsWay/Versions/250/Site/IWay/General/OpenDialog.asp?dialogURL=" + url[0] + "&newPageParams=" + encodeURIComponent(url[1]);
		}
		else
		{
			elementOptions.href = "/NewsWay/Versions/250/Site/IWay/General/OpenDialog.asp?dialogURL=" + url[0];			
		}
	}
	else
	{
		throw "No href parameter was passed to the iwayLightWindow function!";
	}
	if(options.top)
	{
	    elementOptions.top = options.top;
	}
	if(options.left)
	{
	    elementOptions.left = options.left;
	}
	if(options.height)
	{
	    elementOptions.height = options.height;
	}
	if(options.width)
	{
	    elementOptions.width = options.width;
	}
	if(options.clickOnOuterDivWillDeactivate)
	{
	    elementOptions.clickOnOuterDivWillDeactivate = options.clickOnOuterDivWillDeactivate;
	}
	if(options.disableCloseLink)
	{
	    elementOptions.disableCloseLink = options.disableCloseLink;
	}
	if(options.disableCancel)
	{
	    elementOptions.disableCancel = options.disableCancel;
	}
	if(options.callContext)
	{
		elementOptions.callContext= options.callContext;
	}
	if(options.callbackFunctionName)
	{
		elementOptions.callbackFunctionName= options.callbackFunctionName;
	}
	if(options.id)
	{
		elementOptions.id = options.id;
	}
		
	createMostParentLightWindow().activateWindow({ top: elementOptions.top, left: elementOptions.left, href: elementOptions.href, type: 'external', title: '', clickOnOuterDivWillDeactivate: elementOptions.clickOnOuterDivWillDeactivate, windowRef: window, width: elementOptions.width, height: elementOptions.height, disableCloseLink: elementOptions.disableCloseLink, disableCancel: elementOptions.disableCancel, callContext: elementOptions.callContext, callbackFunctionName: options.callbackFunctionName, id : elementOptions.id});
}
///I should move this code to a seperate custom field js file and add a javascript inclue to each page that use it
///check all inputs and validate (reqired) the ones that have "isMandatory=true"
function ValidateMandatoryFields()
{
	var inputs = document.getElementsByTagName("input");
	var selectBoxes = document.getElementsByTagName("select");
	if(!ValidatedInputs(inputs) || !ValidatedInputs(selectBoxes))
	{
		iwayMessageBox("Mandatory","Please check mandatory fields.");
		return false;
	}
	return true;
}

function ValidatedInputs(inputs)
{
	var inputsLength=inputs.length;
	var input;
	for(i=0;i<inputsLength;i++)
	{
		input = inputs[i];
		var isMandatoryAttr = input.getAttribute("isMandatory")
	    if(isMandatoryAttr ==undefined )
	    {
	        isMandatoryAttr = input.getAttribute("IsMandatory")
	    }
		if(isMandatoryAttr !=undefined )
		{
			if ( isMandatoryAttr != "" && isMandatoryAttr != null )
			{			   
				if(isMandatoryAttr.toLowerCase() == "true" && input.value == "")
				{
					return false;
				}
			}
		}		
	}
	return true;
}


function IsIE8Browser() // this method checks IE version regardless compatibility mode
{    
    var rv = -1;    
    var ua = navigator.userAgent;      
    var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})");    
    if (re.exec(ua) != null) 
    {        
        rv = parseFloat(RegExp.$1);    
    }    
    return (rv == 4);
}

function getIFormMainUrl()
{
	if (window.ActiveXObject) {
		// in IE
		return "/Newsway/Versions/250/Site/IWay/App/ExpressEditor/defaultFrameset.asp";
	} else {
		// Other browsers
		return "/Newsway/Versions/250/Site/IWay/App/ExpressEditorNew/defaultFrameset.asp";
	}
}
