var MIN_SUBMENU_ITEMS_COUNT = 6
var V3_SUBMENU_ITEMS_COUNT = MIN_SUBMENU_ITEMS_COUNT + 1
var MIN_MAINMENU_ITEMS_COUNT = 4

var currentTab = null
var currentSubTab = null
var m_localization = ""
var helpWindow = null;

var TAB_INNER_CELL_STRING = 'tabInnerCell'


function getTableObj(getMainTab)
{
	tableForSearch = "iwayTabControl"
	
	if ((getMainTab!=null) && (typeof("getMainTab")!="undefined") && (getMainTab=="mainTab"))
		tableForSearch = "iwayMainTabControl";
	
	var tblObj	= document.getElementById (tableForSearch)
	if (tblObj == null || typeof(tblObj) == "undefined")
	{
		if (window.parent != null && isFrameExist(window.parent, "banner"))
		{
			tblObj = window.parent.frames["banner"].document.getElementById (tableForSearch);
			if (tblObj)
				tblObj.container = window.parent.frames["banner"];
		}
		if (tblObj == null || typeof(tblObj) == "undefined")
		{
			if (window.parent != null && isFrameExist(window.parent, "menu"))
			{
				tblObj = window.parent.frames["menu"].document.getElementById (tableForSearch);
				if (tblObj)
					tblObj.container = window.parent.frames["menu"];
			}
			if (tblObj == null || typeof(tblObj) == "undefined")				
			{
				if (window.parent != null && isFrameExist(window.parent, "LeftMenu"))
				{
					tblObj = window.parent.frames["LeftMenu"].document.getElementById (tableForSearch);
					if (tblObj)
						tblObj.container = window.parent.frames["LeftMenu"];
				}
			}
		}
	}
	return tblObj
}

function checkNotInEditorMode()
{
	if (clientFindFrameAnyLevel("skinButtons") == null)
	{
		return true
	}
	else
	{
		iwayMessageBox("Mouse Clicks","Mouse click abilities have been disabled for the Preview mode.")	
		return false
	}
}

function isFrameExist(windowObj, frameName)
{
	for (var i=0;i < windowObj.frames.length;i++)
		if (windowObj.frames[i].name == frameName)
			return true
	return false
}

function changeTabs (tabId)
{
	var tblObj	= getTableObj()
	var subMenuCnt = getTableSubMenuCnt(tblObj)
	
	var cell_number = 0;
	var cellCounter = 0;
	switch (tabId)
	{
		case "jobTrack":
			cellCounter = parent.namesArr["jobTrack"].length;
			cell_number = 1;
			break
		case "template":
			cellCounter = parent.namesArr["template"].length
			cell_number = 2;
			break
		case "admin":
			cellCounter = parent.namesArr["admin"].length
			cell_number = 3;
			break
	};

	if (tblObj != null && typeof(tblObj) != "undefined")
	{
		if (tblObj.getAttribute("hideEmpty") == "true" && tblObj.getAttribute("saveSpace") == "false" || tabId == "jobTrack" || tabId == "admin")
			subTabShift = 0
		else
			switch (tblObj.getAttribute("tabAlign")) // Template admin - calculate shift
			{
				case "left":
					subTabShift = 0
					break
				case "center":
					subTabShift = Math.ceil((subMenuCnt - cellCounter)/2)
					break
				case "right":
					subTabShift = subMenuCnt - cellCounter
					break
			}	

		resetTabText();
		
		if (tblObj.getAttribute("shapeType") != 'column')
		{
			var hide_v3_items = cellCounter > tblObj.rows[0].cells.length;
			var current_cell_num = 0;
			for (var i = 0 ; (i < cellCounter) && (i<V3_SUBMENU_ITEMS_COUNT); i++)
			{	
				if (!((hide_v3_items && 
				       (tabId == "jobTrack") && (parent.idArr[tabId][i] == "Received"))
				      ||
				      (hide_v3_items && 
				       (tabId == "admin") && (parent.idArr[tabId][i] == "UserGroups"))))
				{
					var cellObj	= tblObj.rows[0].cells[current_cell_num + subTabShift]
					if (cellObj != null)
					{
						cellObj.style.visibility = "visible"	
						cellObj.style.display = ""	

						if (parent.namesArr[tabId] != null)
						{
							var tmpID = cellObj.id.substr(0, TAB_INNER_CELL_STRING.length) //For Backward Compatablity
							var tmp_element = document.getElementById(TAB_INNER_CELL_STRING+i)
							var innerCellObj = (tmpID == TAB_INNER_CELL_STRING)?cellObj:tmp_element
							if (innerCellObj == null) //For Backward Compatablity (before I've put the 'tabInnerCell' id
								innerCellObj = cellObj
							if (innerCellObj != null)
								innerCellObj.innerHTML = parent.namesArr[tabId][i]
						}
						if (parent.targetArr[tabId] != null && parent.hrefsArr[tabId] != null)
						{
							cellObj.setAttribute("target", '"' + parent.targetArr[tabId][i] + '"')
							cellObj.setAttribute("href", '"' + parent.hrefsArr[tabId][i] + '"')
						}
						cellObj.onclick = new Function ("unHighlightAllSubTabs();highlightSubTab(" + (current_cell_num + subTabShift) + ");submitLink("+cellObj.getAttribute('target')+", "+ cellObj.getAttribute('href') + ")")
						current_cell_num++;
					}
				}
			}
		}
		else
		{
			var hide_v3_items = cellCounter > tblObj.rows.length;		
			var current_cell_num = 0;
			for (var i = 0 ; i < cellCounter; i++)
			{	
				if (!((hide_v3_items && 
				       (tabId == "jobTrack") && (parent.idArr[tabId][i] == "Approval"))
				      ||
				      (hide_v3_items && 
				       (tabId == "admin") && (parent.idArr[tabId][i] == "UserGroups"))))
				{
				  if (tblObj.rows.length > (current_cell_num + subTabShift))
					 {
					    var cellObj	= tblObj.rows[current_cell_num + subTabShift].cells[0]
					    if (cellObj != null)
					    {
						    cellObj.style.visibility = "visible"
						    cellObj.style.display = ""
						    if (parent.namesArr[tabId] != null)
						    {
							    var tmpID = cellObj.id.substr(0, TAB_INNER_CELL_STRING.length) //For Backward Compatablity
							    var tmp_element = document.getElementById(TAB_INNER_CELL_STRING+i)
							    var innerCellObj = (tmpID == TAB_INNER_CELL_STRING)?cellObj:tmp_element
							    if (innerCellObj == null) //For Backward Compatablity (before I've put the 'tabInnerCell' id
								    innerCellObj = cellObj
							    if (innerCellObj != null)
								    innerCellObj.innerHTML = parent.namesArr[tabId][i]
						    }
						    if (parent.targetArr[tabId] != null && parent.hrefsArr[tabId] != null)
						    {
							    cellObj.setAttribute("target", '"' + parent.targetArr[tabId][i] + '"')
							    cellObj.setAttribute("href",  '"' + parent.hrefsArr[tabId][i] + '"')
						    }
						    cellObj.onclick = new Function ("unHighlightAllSubTabs();highlightSubTab(" + (current_cell_num + subTabShift) + ");submitLink("+cellObj.getAttribute('target')+", "+ cellObj.getAttribute('href') + ")")
						    current_cell_num++;
					    }
					 }
				}
			}
		}
	}
}

function getTableSubMenuCnt(tblObj)
{
	if (tblObj!=null && typeof(tblObj) != "undefined")
	{
		if (tblObj.getAttribute("shapeType") != 'column')
			return tblObj.rows[0].cells.length
		else
			return tblObj.rows.length
	}
	else
		return 6
}

function highlightTabMenu(tabId, subTabId)
{
	var tblObj	= getTableObj("mainTab");
	if (!tblObj)
	    tblObj	= getTableObj("subTab");
	if (tblObj)
	{
		var subMenuCnt = getTableSubMenuCnt(tblObj);
		var tabChanged = false;
		if (currentTab != tabId)
		{
			currentTab = tabId;
//Start: added by rnd 
if (tblObj.container == null || (typeof(tblObj.container) =="undefined") )
{

	if (tblObj)
		tblObj.container = window.parent.frames["banner"];
		
}
//End: added by rnd 
			tblObj.container.changeTabs(tabId);  // running in the table's container to get event handlers from the container window
			tabChanged = true;
		}
		if (subTabId == "" || subTabId == null)
			subTabId = 0
		else
			subTabId--		//Since "clientDB_js".bannerPressButton indexes from 1 (not from 0) ###fix 3540
			
		if (tblObj.getAttribute("hideEmpty") == "true" && tblObj.getAttribute("saveSpace") == "false" || tabId == "jobTrack" || tabId == "admin")
			subTabShift = 0
		else
			switch (tblObj.getAttribute("tabAlign")) // Template admin - calculate shift
			{
				case "left":
					subTabShift = 0
					break
				case "center":
					subTabShift = Math.ceil(subMenuCnt/2) -1 
					break
				case "right":
					subTabShift = subMenuCnt - 3
					break
			}
//		if (currentSubTab != subTabId || tabChanged)  // no real need #### fix 3540
		{
			unHighlightAllSubTabs()
			highlightSubTab(subTabId + subTabShift)
			currentSubTab = subTabId + subTabShift
		}
	}
	else
		setLeftMenuVisibility(tabId!="orderJob") 
}

function resetTabText()
{
	var tblObj	= getTableObj()
	if (tblObj != null && typeof(tblObj) != "undefined")
	{
		if (tblObj.getAttribute("shapeType") != 'column')
		{
			rowCounter = 1
			columnCounter = tblObj.rows[0].cells.length
		}
		else
		{
			rowCounter = tblObj.rows.length
			columnCounter = 1
		}

		var items_count = V3_SUBMENU_ITEMS_COUNT		
		
		for (var i = 0 ; (i < columnCounter) && (i < items_count); i++)
			for (var j = 0 ; (j < rowCounter) && (j < items_count); j++)
			{	
				var cellObj = tblObj.rows[j].cells[i]
				if (cellObj != null)
				{
					if (tblObj.getAttribute("hideEmpty") == "true")
					{
						if (tblObj.getAttribute("saveSpace") == "true")
							cellObj.style.visibility = "hidden"	
						else
							cellObj.style.display = "none"							
					}
					var tmpID = cellObj.id.substr(0, TAB_INNER_CELL_STRING.length) // For Backward Compatablity
					var tmp_element = document.getElementById(TAB_INNER_CELL_STRING+i)
					var innerCellObj = (tmpID == TAB_INNER_CELL_STRING)?cellObj:tmp_element
					if (innerCellObj == null) //For Backward Compatablity (before I've put the 'tabInnerCell' id
						innerCellObj = cellObj;
					if (innerCellObj != null)
						innerCellObj.innerHTML = "";
					cellObj.onclick = "";
					cellObj.setAttribute("target", "");
					cellObj.setAttribute("href", "");
					cellObj.style.cursor = 'default';
					if (tblObj.getAttribute("selectedType") == "color")
						cellObj.style.backgroundColor = (typeof(tblObj.getAttribute("notSelectedBgColor")) == "undefined" || tblObj.getAttribute("notSelectedBgColor") == "null")?"transparent":tblObj.getAttribute("notSelectedBgColor")
					else
						cellObj.style.backgroundImage = "url(" + tblObj.getAttribute("unselectedImage") + ")"
				}
			}
	}
}

function unHighlightAllMainTabs()
{
	var tblObj	= getTableObj("mainTab")
	if (tblObj != null && typeof(tblObj) != "undefined")
	{
		if (tblObj.getAttribute("shapeType") != 'column')
		{
			rowCounter = 1
			columnCounter =  tblObj.rows[0].cells.length
		}
		else
		{
			rowCounter = tblObj.rows.length
			columnCounter = 1
		}
		
		var items_count = MIN_MAINMENU_ITEMS_COUNT
		
		for (var i = 0 ; (i < columnCounter) && (i < items_count); i++)
			for (var j = 0 ; (j < rowCounter) && (j < items_count); j++)
			{
				var cellObj = tblObj.rows[j].cells[i]
				if (cellObj != null)
				{
					cellObj.style.cursor = 'pointer'
					cellObj.style.color = (typeof(tblObj.getAttribute("notSelectedForeColor")) == "undefined" || tblObj.getAttribute("notSelectedForeColor") == "null")?"black":tblObj.getAttribute("notSelectedForeColor")
					
					var unselectedFontValue = tblObj.getAttribute("unselectedFont");
					if ((unselectedFontValue != null) && (unselectedFontValue != "")) 
						cellObj.style.fontFamily = unselectedFontValue;
					var unselectedFontSizeValue = tblObj.getAttribute("unselectedFontSize");
					if ((unselectedFontSizeValue != null) && (unselectedFontSizeValue != ""))
						cellObj.style.fontSize = unselectedFontSizeValue;
					var unselectedTextAlignmentValue = tblObj.getAttribute("unselectedTextAlignment");
					cellObj.style.textAlign = ((unselectedTextAlignmentValue != null) && (unselectedTextAlignmentValue != "")) ? unselectedTextAlignmentValue : '';
					
					cellObj.style.fontWeight = (tblObj.getAttribute("boldUnselFont")=="true") ? "bold" : "normal"
					cellObj.style.fontStyle = (tblObj.getAttribute("italicUnselFont")=="true") ? "italic" : "normal"
					cellObj.style.textDecoration = (tblObj.getAttribute("underlineUnselFont")=="true") ? "underline" : "none"
					if (tblObj.getAttribute("selectedType") == "color")
						cellObj.style.backgroundColor = (typeof(tblObj.getAttribute("notSelectedBgColor")) == "undefined" || tblObj.getAttribute("notSelectedBgColor") == "null")?"transparent":tblObj.getAttribute("notSelectedBgColor")
						
					else
						cellObj.style.backgroundImage = "url(" + tblObj.getAttribute("unselectedImage") + ")"
				}
			}
	}
}

function unHighlightAllSubTabs()
{
	var tblObj	= getTableObj()
	if (tblObj != null && typeof(tblObj) != "undefined")
	{
		if (tblObj.getAttribute("shapeType") != 'column')
		{
			rowCounter = 1
			columnCounter =  tblObj.rows[0].cells.length
		}
		else
		{
			rowCounter = tblObj.rows.length
			columnCounter = 1
		}
		
		var items_count = V3_SUBMENU_ITEMS_COUNT
		
		for (var i = 0 ; (i < columnCounter) && (i < items_count); i++)
			for (var j = 0 ; (j < rowCounter) && (j < items_count); j++)
			{
				var cellObj = tblObj.rows[j].cells[i]
				if (cellObj != null)
				{
					cellObj.style.cursor = 'pointer'
					cellObj.style.color = (typeof(tblObj.getAttribute("notSelectedForeColor")) == "undefined" || tblObj.getAttribute("notSelectedForeColor") == "null")?"black":tblObj.getAttribute("notSelectedForeColor")
					
					var unselectedFontValue = tblObj.getAttribute("unselectedFont");
					if ((unselectedFontValue != null) && (unselectedFontValue != "")) 
						cellObj.style.fontFamily = unselectedFontValue;
					var unselectedFontSizeValue = tblObj.getAttribute("unselectedFontSize");
					if ((unselectedFontSizeValue != null) && (unselectedFontSizeValue != ""))
						cellObj.style.fontSize = unselectedFontSizeValue;
					var unselectedTextAlignmentValue = tblObj.getAttribute("unselectedTextAlignment");
					cellObj.style.textAlign = ((unselectedTextAlignmentValue != null) && (unselectedTextAlignmentValue != "")) ? unselectedTextAlignmentValue : '';
					
					cellObj.style.fontWeight = (tblObj.getAttribute("boldUnselFont")=="true") ? "bold" : "normal"
					cellObj.style.fontStyle = (tblObj.getAttribute("italicUnselFont")=="true") ? "italic" : "normal"
					cellObj.style.textDecoration = (tblObj.getAttribute("underlineUnselFont")=="true") ? "underline" : "none"
					if (tblObj.getAttribute("selectedType") == "color")
						cellObj.style.backgroundColor = (typeof(tblObj.getAttribute("notSelectedBgColor")) == "undefined" || tblObj.getAttribute("notSelectedBgColor") == "null")?"transparent":tblObj.getAttribute("notSelectedBgColor")
						
					else
						cellObj.style.backgroundImage = "url(" + tblObj.getAttribute("unselectedImage") + ")"
				}
			}
	}
}


function SetMainPageFrameToWaitMessage(p_function, menuID, subMenuID, newUrl, newTarget)
{
	var pleaseWaitLinkWithParameters = "/newsway/versions/250/site/iway/PleaseWait.asp?callbackfunction="+p_function+"&menuID="+menuID+"&subMenuID="+subMenuID+"&newUrl="+clientEncodeUrlAsUTF8(newUrl)+"&newTarget="+clientEncodeUrlAsUTF8(newTarget);

	if (clientFindFrameAnyLevel('page') != null)
		clientFindFrameAnyLevel('page').location.href = pleaseWaitLinkWithParameters
	else
	{
		var iwaytopElement = clientFindFrameAnyLevel('iwaytop');
		if (iwaytopElement != null)
		{
			var pageElement = iwaytopElement.document.getElementById ("page");
			if (pageElement)
				pageElement.src = pleaseWaitLinkWithParameters;
		}
	}
}

function iwayMainMenuFunction(current_element, tabId, subTabId)
{
	SetMainPageFrameToWaitMessage("doInnerChangeTopMenuItem_Skin", tabId, subTabId, current_element.getAttribute('href'), current_element.getAttribute('target'))
}

function CallbackMessage(p_function, p_menuID, p_subMenuID, newUrl, newTarget)
{
	var menuID = "";
	if ((typeof(p_menuID)!= "undefined") && (p_menuID!=""))
		menuID = p_menuID;
		
	var subMenuID = "";
	if ((typeof(p_subMenuID)!= "undefined") && (p_subMenuID!=""))	
		subMenuID = p_subMenuID;
	eval(p_function +"(menuID,subMenuID,newUrl,newTarget)")
}

function doInnerChangeTopMenuItem_Skin(menuID, subMenuID, newUrl, newTarget)
{
	if ((typeof(menuID)=="undefined") || (menuID == null) || (menuID=='') ||
		(typeof(subMenuID)=="undefined") || (subMenuID == null) || (subMenuID==''))
	{
		unHighlightAllSubTabs();
		submitLink(newTarget, newUrl);
	}
	else
	{
		unHighlightAllSubTabs();
		submitLink(newTarget, newUrl);
		highlightTabMenu(menuID, subMenuID);	
	}
}

function highlightMainTab(mainTabId)
{
	var tblObj	= getTableObj("mainTab")
	if (tblObj != null && typeof(tblObj) != "undefined")
	{
		if (tblObj.getAttribute("shapeType") != 'column')
		{
			rowIndex = 0
			colIndex = mainTabId
		}
		else
		{
			rowIndex = mainTabId
			colIndex = 0
		}
		var cellObj = tblObj.rows[rowIndex].cells[colIndex]
		if (cellObj != null)
		{
			cellObj.style.cursor = 'default'
			cellObj.style.color = (typeof(tblObj.getAttribute("selectedForeColor")) == "undefined" || tblObj.getAttribute("selectedForeColor") == "null")?"black":tblObj.getAttribute("selectedForeColor")
			
			var selectedFontValue = tblObj.getAttribute("selectedFont");
			if ((selectedFontValue != null) && (selectedFontValue != "")) 
				cellObj.style.fontFamily = selectedFontValue;
			var selectedFontSizeValue = tblObj.getAttribute("selectedFontSize");
			if ((selectedFontSizeValue != null) && (selectedFontSizeValue != ""))
				cellObj.style.fontSize = selectedFontSizeValue;
			var selectedTextAlignmentValue = tblObj.getAttribute("selectedTextAlignment");
			cellObj.style.textAlign = ((selectedTextAlignmentValue != null) && (selectedTextAlignmentValue != "")) ? selectedTextAlignmentValue : '';
			
			cellObj.style.fontWeight = (tblObj.getAttribute("boldSelFont")=="true") ? "bold" : "normal"
			cellObj.style.fontStyle = (tblObj.getAttribute("italicSelFont")=="true") ? "italic" : "normal"
			cellObj.style.textDecoration = (tblObj.getAttribute("underlineSelFont")=="true") ? "underline" : "none"
			if (tblObj.getAttribute("selectedType") == "color")
				cellObj.style.backgroundColor = (typeof(tblObj.getAttribute("selectedBgColor")) == "undefined" || tblObj.getAttribute("selectedBgColor") == "null")?"transparent":tblObj.getAttribute("selectedBgColor")
			else
				cellObj.style.backgroundImage = "url(" + tblObj.getAttribute("selectedImage") + ")"
		}
	}	
}

function highlightSubTab(subTabId)
{
	var tblObj	= getTableObj()
	if (tblObj != null && typeof(tblObj) != "undefined")
	{
		if (tblObj.getAttribute("shapeType") != 'column')
		{
			rowIndex = 0
			colIndex = subTabId
		}
		else
		{
			rowIndex = subTabId
			colIndex = 0
		}
		var cellObj = tblObj.rows[rowIndex].cells[colIndex]
		if (cellObj != null)
		{
			cellObj.style.cursor = 'default'
			cellObj.style.color = (typeof(tblObj.getAttribute("selectedForeColor")) == "undefined" || tblObj.getAttribute("selectedForeColor") == "null")?"black":tblObj.getAttribute("selectedForeColor")

			var selectedFontValue = tblObj.getAttribute("selectedFont");
			if ((selectedFontValue != null) && (selectedFontValue != "")) 
				cellObj.style.fontFamily = selectedFontValue;
			var selectedFontSizeValue = tblObj.getAttribute("selectedFontSize");
			if ((selectedFontSizeValue != null) && (selectedFontSizeValue != "")) 
				cellObj.style.fontSize = selectedFontSizeValue;
			var selectedTextAlignmentValue = tblObj.getAttribute("selectedTextAlignment");
			cellObj.style.textAlign = ((selectedTextAlignmentValue != null) && (selectedTextAlignmentValue != "")) ? selectedTextAlignmentValue : '';

			cellObj.style.fontWeight = (tblObj.getAttribute("boldSelFont")=="true") ? "bold" : "normal"
			cellObj.style.fontStyle = (tblObj.getAttribute("italicSelFont")=="true") ? "italic" : "normal"
			cellObj.style.textDecoration = (tblObj.getAttribute("underlineSelFont")=="true") ? "underline" : "none"
			if (tblObj.getAttribute("selectedType") == "color")
				cellObj.style.backgroundColor = (typeof(tblObj.getAttribute("selectedBgColor")) == "undefined" || tblObj.getAttribute("selectedBgColor") == "null")?"transparent":tblObj.getAttribute("selectedBgColor")
			else
				cellObj.style.backgroundImage = "url(" + tblObj.getAttribute("selectedImage") + ")"

	        subMenu_setTabIndex(cellObj,false);
		}
	}	
}

function submitLink(target, href)
{
	var IsExternalLink = false;
	if ((href.toLowerCase().indexOf("http://") == -1) && (href.toLowerCase().indexOf("https://") == -1))
	{
		var param = window.location.search.substr(1);
		if ((param.length > 0) && (href.search(param) <= 0))
		{
			var m = /\?/
			if (href.search(m)<= 0)
				href += "?" + param
			else
				href += "&" + param
		}
	}
	else
		IsExternalLink = true;
		
	var formObj = getHtmlObjById("linkForm")
	if (formObj != null)
	{
		formObj.action = href;
		formObj.target = target;
		if (IsExternalLink && href.indexOf("?")==-1)	
			formObj.method = 'get'
		else
			formObj.method = 'post'


		if (clientIsMac()) //Mac has to have at least one field in form
		{
			if (document.getElementById('justInput') == null)
			{
				var submitBtn = document.createElement('input');
				submitBtn.style.display= 'none';
				submitBtn.id ='justInput';
				formObj.appendChild(submitBtn);			
			}
		}
		formObj.submit();

		var cell_number = -1;
		cell_tymporary_id = href.substring(20,href.length);
		
		switch (cell_tymporary_id)
		{
			case "route_newJob.asp":
			case "route_lp_orderFromPPCatalog.asp":
			case "route_lp_orderSet.asp":
			case "route_lp_orderFromPBComputer.asp":
				cell_number = 0;
				break;
			case "route_trackReadyToOrder.asp":
				cell_number = 1;
				break;
			case "route_templateBank.asp":
				cell_number = 2;
				break;
			case "route_customerGeneral.asp":
				cell_number = 3;
				break;
			default:
				switch (currentTab)
				{
					case "jobTrack":
						cell_number = 1;
						break;
					case "template":
						cell_number = 2;
						break;
					case "admin":
						cell_number = 3;
						break;
				}
				break
		}			
		if (cell_number >= 0)
		{
			unHighlightAllMainTabs()
			highlightMainTab(cell_number)

			var contentFrames = clientFindFramesetAnyLevel('contentframeset');
			if ((contentFrames!=null) && 
				(typeof(contentFrames)!="undefined") && 
				(contentFrames.getAttribute("guiVersion") == "v3"))
				setLeftMenuVisibility(cell_number != 0);
		}
	}
}

function submitSpecialLink(linkUrl, alwaysOnTop)
{
	if (clientFindFrameAnyLevel("page") != null)
		submitLink("page", linkUrl)
	else
	{
		if (alwaysOnTop == "true")
			window.showModelessDialog("/newsway/versions/250/site/iway/App/SkinEditor/setNewswaySessionsAndRedirect.asp?linkUrl=" + linkUrl,window,'help=no;resizable=yes;titlebar=yes;status=no;toolbar=no;menubar=no;location=no;dialogWidth:700px;dialogHeight:510px')
		else
			window.open("/newsway/versions/250/site/iway/App/SkinEditor/setNewswaySessionsAndRedirect.asp?linkUrl=" + linkUrl, '', 'resizable=yes,scrollbars=auto,directories=no,menubar=no,status=no,titlebar=no,toolbar=no,height=510px,width=700px,help=no')
	}
}

function submitLogin()
{
	var actionUrl = "/newsway/versions/250/site/iway/App/SkinEditor/setNewswaySessionsAndRedirect.asp";
	//IID = "";
	actionUrl += "?IID=" + IID;
	actionUrl += "&transferUrl=/newsway/interfaces/ByPassLogin.asp";

	var formObj = getHtmlObjById("loginForm")
	if (formObj) {
		var user_name = "";
		if (document.getElementById("iwayUsername"))
			user_name = document.getElementById("iwayUsername").value
		else if (document.getElementById("username"))
			user_name = document.getElementById("username").value
		
		var user_password = "";
		if (document.getElementById("iwayPassword"))
			user_password = document.getElementById("iwayPassword").value
		else if (document.getElementById("password"))
			user_password = document.getElementById("password").value
		
		formObj.username.value = user_name;
		formObj.password.value = user_password;
		formObj.localizationsection.value = m_localization;
		formObj.action = actionUrl;
		formObj.target = "loginFrame"
		formObj.submit()
	}
}


function submitIfEnter()
{
	if (window.event) {
		var code = event.keyCode
		if (code == 13)
			submitLogin()
	}
}

function do_onload(defaultPageType, defaultPageUrl)
{
	// main menu substitution
	var tblObj	= getTableObj("mainTab")
	if (tblObj != null && typeof(tblObj) != "undefined")
	{
		if (tblObj.getAttribute("shapeType") == 'column')
		{
			for (var i=0 ; i < parent.mainMenuNamesArr.length; i++)
				if (parent.mainMenuNamesArr_visibility[i])
				{
					tblObj.rows[i].cells[0].innerHTML = parent.mainMenuNamesArr[i];
					tblObj.rows[i].cells[0].style.display = "";
				}
				else
					clearMainMenuCell(tblObj.rows[i].cells[0]);
		}
		else
		{
			for (var i = 0 ; i < parent.mainMenuNamesArr.length; i++)
				if (parent.mainMenuNamesArr_visibility[i])
				{
					tblObj.rows[0].cells[i].innerHTML = parent.mainMenuNamesArr[i];
					tblObj.rows[0].cells[i].style.display = "";
				}
				else
					clearMainMenuCell(tblObj.rows[0].cells[i]);
		}
	}

	var p_Url = "";
	if (defaultPageType == null || defaultPageUrl == null)
	{
		p_Url = "/newsway/interfaces/route_newJob.asp"
	}
	else 
	{
		var wasHighlightedTabMenu = false;
		if (defaultPageType == "internal")
		{
			var arr = defaultPageUrl.split("|")
			if (arr[1] != null && arr[2]!= null && arr[1] != "null" && arr[2]!= "null")
			{
				highlightTabMenu(arr[1], Number(arr[2]))
				wasHighlightedTabMenu = true;
			}
			p_Url = arr[0];
		}
		else
		{
			p_Url = defaultPageUrl
		}
		
		var UrlSplit = p_Url.split("/")
		if ((defaultPageType == "internal") &&
			(p_Url.toLowerCase() != "/newsway/interfaces/route_newjob.asp") && 
			(UrlSplit[UrlSplit.length-1].toLowerCase() != "launchpad.html") &&
			(defaultPageUrl.indexOf("CreateJob")==-1) && 
			(defaultPageUrl.indexOf("CreateSet")==-1) && 
			(defaultPageUrl.indexOf("OrderCheckout")==-1))
		{
			setLeftMenuVisibility(true);
		}
		else
		{
			if (!wasHighlightedTabMenu)
			{
				unHighlightAllMainTabs();
				if (defaultPageType == "internal")
					highlightMainTab(0);
			}
		}
	}
	SetMainPageFrameToWaitMessage("do_InnerOnload", "", "", p_Url, "page")
}

function do_InnerOnload(menuID, subMenuID, newUrl, newTarget)
{
	submitLink(newTarget, newUrl)
}

function clearMainMenuCell(cellObject)
{
	cellObject.innerHTML = "";
	//cellObject.onclick = "";
	//cellObject.style.cursor = "default";
	cellObject.style.display = "none";
}

function do_onunload()
{
	if (helpWindow != null) 
	{		
		helpWindow.close();
		helpWindow = null;
	}
}

function showHelpWindow(helpURL, alwaysOnTop) 
{
	if (helpWindow == null)
	{
		if (alwaysOnTop == "true")
			helpWindow = window.showModelessDialog(helpURL,window,'help=no;resizable=yes;titlebar=yes;status=no;toolbar=no;menubar=no;location=no;dialogWidth:550px;dialogHeight:600px')
		else
			helpWindow = window.open(helpURL, 'help', 'resizable=yes,scrollbars=auto,directories=no,menubar=no,status=no,titlebar=no,toolbar=no,height=600px,width=550px,help=no')
	}
}

function changeHelpPage(helpPageVPath) {
	if (helpWindow != null && typeof(helpWindow.changeHelpPage) != "undefined") {
		helpWindow.changeHelpPage(helpPageVPath);
	}
}

function helpWindowClosed() {
	helpWindow = null;
}

function selectLanguage(language)
{
	m_localization = language

	var cb = new callback();
	cb.setURL('/Newsway/Versions/250/Site/IWay/App/SkinEditor/changeLanguage.asp');
	cb.addVar('localizationsection', language);
	cb.setHandler(function(a){iwayMessageBoxWithParams("Language Selection","<span class='bigFont'>_nw_value:languageName_</span> language was selected and will be used in the main application window after login.", language);});
	cb.send();
}

function defValue(val, defVal)
{
	if (val == "" || val == null)
		return defVal
	else
		return val
}

function getCookie (name) 
{
	var dcookie;
	var dataFrameElement = clientFindFrameAnyLevel("dataFrame");
	if (dataFrameElement != null)
		dcookie = dataFrameElement.document.cookie; 
	else
		dcookie = document.cookie; 
		
	var cname = name + "=";
	var clen = dcookie.length;
	var cbegin = 0;
	while (cbegin < clen) 
	{
		var vbegin = cbegin + cname.length;
		if (dcookie.substring(cbegin, vbegin) == cname) 
		{ 
			var vend = dcookie.indexOf (";", vbegin);
			if (vend == -1) vend = clen;
			return unescape(dcookie.substring(vbegin, vend));
		}
		cbegin = dcookie.indexOf(" ", cbegin) + 1;
		if (cbegin == 0) break;
	}
	return null;
}

//In case there is more than one object, get the first in the collection
function getHtmlObjById(objId)
{

	var obj = document.getElementById(objId)
	if (obj == null)
	{
		var LeftMenuFrame = clientFindFrameAnyLevel("LeftMenu")
		if (LeftMenuFrame != null)
			obj = LeftMenuFrame.document.getElementById(objId)
	}
	
	if ((obj != null) && (typeof(obj.length) != "undefined"))
	{

		if (obj.length && obj.length > 1 && String(obj.tagName) == "undefined")
		{
			return obj[0]
		}
		else
		{
			return obj
		}
	}
	else
		return obj
}


function moveToStartPage(pLogoutUrl, pDefaultUrl)
{
	var temp_url = getLogoutUrl(pLogoutUrl)
	if (temp_url == "")
		temp_url = pDefaultUrl;
	clientGetIWayTopContainer().location.href = temp_url;
}


function getLogoutUrl(logoutUrl)
{
	var url;
	if (logoutUrl == "login")
		url = getCookie ('logoutURL')
	else
		url = logoutUrl;
		
	if (url == null)
		url = ""; 
	return url;
}


function logout(logoutUrl)
{
	if ((logoutUrl != "login") && (logoutUrl != ""))
		clientGetIWayTopContainer().location.href = logoutUrl
	else
	{
		var Frame_contentframeset = clientFindFramesetAnyLevel('contentframeset');
		var iway_logout = null;
		if ((Frame_contentframeset != null) && (typeof(Frame_contentframeset)!="undefined"))
			iway_logout = clientFindFramesetAnyLevel('contentframeset').getAttribute('iway_logout');
		if ((iway_logout!=null) && (typeof(iway_logout)!="undefined") && (iway_logout!=""))
			clientGetIWayTopContainer().location.href = iway_logout
		else
		{
			if (logoutUrl == "login")
				moveToStartPage(logoutUrl, "/iway")
			else
			{	
				if (logoutUrl != "")
					clientGetIWayTopContainer().location.href = logoutUrl
				else
					moveToStartPage(logoutUrl, "/newsway/home.asp")
			}
		}
	}
}


function clientIsMac()
{
	var ret = true
	try {
		ret = (navigator.appVersion.search(/mac/i) >= 0);
	} catch (ex) {}
	return ret 
}


function clickElem(elem, target, href)
{
	if (this.elem)
		this.elem.style.border = "";

	this.elem = elem;
	this.elem.style.border = "1px outset";

	var is_not_orderJobs = (elem.getAttribute("activateName") != "Start");
	setLeftMenuVisibility(is_not_orderJobs);

	submitLink(target, href)
}


function setLeftMenuVisibility(visible)
{
	var contentFrames = clientFindFramesetAnyLevel('contentframeset');
	if (!contentFrames)
		return;

	if (visible)
		contentFrames.cols = contentFrames.getAttribute('miway_cols_orig')
	else
	{
		contentFrames.cols = '0px,*';
		currentTab = null;
		resetTabText();
	}
}


// tab-key and arrow navigation for the tabs
		var subMenu_lastFocusedObj = null;
		var subMenu_lastFocusedObjRestore = null;		

		function subMenu_setTabIndex(obj,temp)
		{
			if (subMenu_lastFocusedObj)
			{
				subMenu_lastFocusedObj.onblur = null;
				subMenu_lastFocusedObj.tabIndex = -1;
			}
			if (temp)
				obj.onblur = subMenu_restoreTabIndex;
			else
				subMenu_lastFocusedObjRestore = obj;
			subMenu_lastFocusedObj = obj;
			obj.tabIndex = 0;	
			if (temp)
				obj.focus();
			
		}
		
		function subMenu_restoreTabIndex()
		{
			if (subMenu_lastFocusedObjRestore)
				subMenu_setTabIndex(subMenu_lastFocusedObjRestore,false);
		}
		
		
		function subMenu_tabPress(evntObj)
		{
			if (!subMenu_lastFocusedObj)
				return;
			var keycode = controls_getKeyCode( evntObj );
		
			var moveCells = 0;
			if (keycode == 40) //down key
				moveCells = 1;
			else if (keycode == 38) //up key
				moveCells = -1;
			if (!moveCells)
				return;
			//get current cell
			//var row = document.getElementById("tabRow");
			var currentIDSelectedCell = String(subMenu_lastFocusedObj.id).replace("tabInnerCell","");
			if (isNaN(currentIDSelectedCell))
			    return;
	        var next = Number(currentIDSelectedCell)+moveCells;
			var nextCell = document.getElementById ("tabInnerCell"+next);
			if (!nextCell)
			    return;
            if (nextCell.style.visibility == "hidden" || nextCell.style.display == "none")
                return;
            try
            {
   		        subMenu_setTabIndex(nextCell,true);
   		    }
   		    catch(e)
   		    {
   		        subMenu_setTabIndex(subMenu_lastFocusedObj,true);
   		    }
		}		

