//  **********************************************************************************
//  **	Scripts below created for SYSPRO web apps login form & MDI functionality.	**
//  **	Changes made to these functions might break the web based applications.		**
//  **	Do not edit unless you know what you're doing. johan.myburgh@za.syspro.com	**
//  **********************************************************************************

function LaunchWindow2( url, displayname, Pre){
		//window.event.cancelBubble = true;
		var container = document.getElementById("container");
		Currentid = container.childNodes.length+1;
		var newwin = document.createElement("<div vis='visible'  class='activewin' id='win" + Currentid + "' name='win" + Currentid + "' ' z='" + Currentid + "' style='display:block;height:expression(document.body.clientHeight-22);z-Index:" + Currentid + "'></div>");
		newwin.innerHTML = "<table class='activehead' id='table" + Currentid + "' name='table" + Currentid + "' cellpadding='0' cellspacing='0'>" +
			"<tr><td><span id='title" + Currentid + "' name='title" + Currentid + "'>&nbsp;" + displayname + "</span></td><td align='right'><table>" +
			"<tr valign='bottom'><td><img class='arrow' src='images/greyreload.gif' hover='images/redreload.gif' onmouseover='toggle(this)' onmouseOut='toggle(this)' onClick='ReQuery(" + Currentid + ")'></td>" +
			"<td><img class='arrow' id='toggle" + Currentid + "' name='toggle" + Currentid + "' src='images/greyhide.gif'  hover='images/redhide.gif' onmouseover='toggle(this)' onmouseOut='toggle(this)' onClick='minimize(" + Currentid + ")'></td>" +
			"<td><img class='arrow' id='close" + Currentid + "' name='close" + Currentid + "' src='images/greyclose.gif'  hover='images/redclose.gif' onmouseover='toggle(this)' onmouseOut='toggle(this)' onClick='CloseWin(" + Currentid + ")'></td>" +
			"</tr></table></td></tr></table>" +
			"<iframe style='z-index:" + Currentid + "' src='" + url + "' id='frame" + Currentid + "' name='frame" + Currentid + "' url='" + url + "'></iframe>"; 
		container.appendChild(newwin);
		newwin = null;
}

//  ******************************************
//  ** Login form scripts - Do not change	**
//  ******************************************
//Will reset login form 
function ResetLogon(){
	var txtuname = document.getElementById("txtuname");
	var lbl = document.getElementById("lblerror");
	var pwd = document.getElementById("txtpwd");
	txtuname.value = "";
	lbl.innerText = "";
	pwd.value = "";
}

//Will reset the error label
function ResetError(){
		var lbl = document.getElementById("lblerror");
		lbl.innerText = "";
		return false;
}

//Will validate the Username field(txtuname) on the login form.
function submitme(){
	var txtuname = document.getElementById("txtuname");
	var lbl = document.getElementById("lblerror");
	lbl.innerText = "";
	if (txtuname.value.length<1){
		var SetFocusTo = document.getElementById("txtuname");
		SetFocusTo.focus();
		return false;
	}else{
		return true;
	}
}

function AdvancedSearch()
{
	window.open("content/search/advancedSearch.htm", "AdvancedSearch", "resizable,scrollbars,status=no,Width=' + window.screen.width  * .85 + 'px,Height=' + window.screen.height * .7 + 'px'");
}

//Sets focus to the item element
function SetFirst(item){
	var SetFocusTo = document.getElementById(item);
	SetFocusTo.focus();
}

function About(){
	window.showModalDialog("about.aspx", "User", "dialogHeight:200px;dialogWidth:400px;status:0;resizable:0")
}

//Function to set title on main page
	function SetTitle(){
		var cook = document.cookie;
		var splitstring1 = cook.split("OperatorCode=");
		var pos = splitstring1[1].indexOf("&");
		var titleString = splitstring1[1].substring(0, pos);
		splitstring1 = cook.split("CompanyName=");
		pos = splitstring1[1].indexOf("&");
		titleString += " - " + splitstring1[1].substring(0, pos);
		document.title = titleString;
	}
	
//  *************************************************************************	
//  **  Functions for the main page relating to MDI windows and the menu	*
//  *************************************************************************
// Function that returns the parent DIV element that forms to window of the clicked item - !!
	function GetParentDiv(ClickedItem){
		var Element = ClickedItem.parentNode.parentNode.parentNode.parentNode.parentNode;
		return Element;
	}
// Function that resets the frame to display the form used to configure the current query. - !!
// Note this is only available for options that have the requery set to true in the menu file now stored on the server and accessed through the COMQMN Business object.
	function ReQuery(item){
		var Elem = GetParentDiv(item);
		var block = document.getElementById("container");
		for(i=0;i<block.childNodes.length;i++){
			if (block.childNodes(i).tagName == "DIV"){
				if (block.childNodes(i)==Elem){
					document.frames(i).document.getElementById("winframe").rows = "*,2px";
				}
			}
		}
		Elem = null;
		block = null;
	}
//Function adds the new window to the window menu - !!	
		function addWinMenu(Name){
			resetZ();
			var WinCounter;
			var block = document.getElementById("container");
			WinCounter = block.childNodes.length;
			windowMenu.add(new MenuItem(WinCounter + " - " + Name, "javascript:bringToFront(" + parseInt(WinCounter) + ")"));
			windowMenu.invalidate();
			ResetWinMenu();
			block = null;
		}
//Function maximizes all windows - !!
	function MaximizeWindows(){
		var block = document.getElementById("container");
		var winHeight = document.body.clientHeight-22;	
		var winWidth = document.body.clientWidth;	
		for(i=0;i<block.childNodes.length;i++){
			if (block.childNodes(i).tagName == "DIV"){
				var WindowItem = block.childNodes(i);
				WindowItem.style.display = "block";
				WindowItem.style.width = winWidth;
				WindowItem.style.height = winHeight;
				WindowItem.style.top = "0px";
				WindowItem.style.left = "0";
			}
		}
		block = null;
		WindowItem = null;
	}
//Function maximizes a window when the maximize button is clicked - !!
	function Maximize(item){
		var Elem = GetParentDiv(item);
		var winHeight = document.body.clientHeight-22;	
		var winWidth = document.body.clientWidth;	
		Elem.style.width = winWidth;
		Elem.style.height = winHeight;
		Elem.style.top = "0px";
		Elem.style.left = "0";
		Elem = null;
	}	
//Function minimizes all windows - !!
	function MinimizeWindows(){
		var block = document.getElementById("container");
		for(i=0;i<block.childNodes.length;i++){
			if (block.childNodes(i).tagName == "DIV"){
				var WindowItem = block.childNodes(i);  
				WindowItem.style.display = "none";     
			}
		}
		block = null;
		WindowItem = null;
	}
// Function minimizes a window when the minimize button is clicked - !!
	function Minimize(item){
		var Elem = GetParentDiv(item);
		Elem.style.display = "none";  
		Elem = null;
	}
// Function will close all windows, remove them from the HTML DOM, remove window items from the - !! 
// window menu and reset the CurrentId variable that increments when new windows are added - !!
	function CloseWindows(){	
		if (confirm("Are you sure you want to close all windows?")){
			var block = document.getElementById("container");
			var WindowItem;
			var current = windowMenu.items.length;
			while (current > 4){
				windowMenu.remove(windowMenu.items[current-1]);
				WindowItem = block.childNodes(current-5);
				WindowItem.removeNode(true);
				current--;	
			}
			windowMenu.invalidate();
		}
		ResetWinMenu();
		block = null;
		WindowItem = null;
	}
//Function will close a window when close is clicked, reset all other windows and reset window menu
	function CloseWindow(item){
		var Elem = GetParentDiv(item);
		Elem.removeNode(true);
		var removedNumber = parseInt(item);
		var current = windowMenu.items.length;
		while (current > 4){
			windowMenu.remove(windowMenu.items[current-1]);
			current--;	
		}
		windowMenu.invalidate();
		var block = document.getElementById("container");
		for(i=0;i<block.childNodes.length;i++){
			if (block.childNodes(i).tagName == "DIV"){
				var WindowItem = block.childNodes(i);
				windowMenu.add(new MenuItem((i + 1) + " - " + WindowItem.name, "javascript:bringToFront(" + (parseInt(i)+1) + ")"));
				WindowItem.z = i+1;
				WindowItem.style.zIndex = i+1;				
			}
		}
		ResetWinMenu();
		windowMenu.invalidate();
		Elem = null;
		block = null;
		WindowItem = null;
	}
	
//Function will show the about window (modal) when about is selected from the help menu - !!
	function About(){
		window.showModalDialog("about.aspx", "User", "dialogHeight:200px;dialogWidth:400px;status:0;resizable:0")
	}
//Function to put one window on top of all other when selected from the window menu item or selected via the window title - !!
	function bringToFront(item){
		resetZ();
		var block = document.getElementById("container");
		block.childNodes(parseInt(item)-1).style.zIndex = 1000;
		block.childNodes(parseInt(item)-1).style.display = "block";
		block = null;
	}
	
// Function  to reset the Z-Index of all the windows - !!
	function resetZ(){
		var block = document.getElementById("container");
		for(i=0;i<block.childNodes.length;i++){
			if (block.childNodes(i).tagName == "DIV"){
				var WindowItem = block.childNodes(i);
				WindowItem.style.zIndex = WindowItem.z;
			}
		}
		block = null;
	}
	
// Function that enables or disables the global items under the windows menu
	function ResetWinMenu(){
		if(windowMenu.items.length>4){
			windowMenu.items[0].disabled = false;
			windowMenu.items[1].disabled = false;
			windowMenu.items[2].disabled = false;
		}else{
			windowMenu.items[0].disabled = true;
			windowMenu.items[1].disabled = true;
			windowMenu.items[2].disabled = true;
		}
	}

//	Menu created code - Do not fiddle with this unless you know what you're doing 
//		- Johan, johan.myburgh@za.syspro.com,  SYSPRO - South Africa

var ie55 = /MSIE ((5\.[56789])|([6789]))/.test( navigator.userAgent ) &&
			navigator.platform == "Win32";

if ( !ie55 ) {
	window.onerror = function () {
		return true;
	};
}

function writeNotSupported() {
	if ( !ie55 ) {
		document.write( "<p class=\"warning\">" +
			"This script only works in Internet Explorer 5.5" +
			" or greater for Windows</p>" );
	}
}

function getQueryString( sProp ) {
	var re = new RegExp( sProp + "=([^\\&]*)", "i" );
	var a = re.exec( document.location.search );
	if ( a == null )
		return "";
	return a[1];
};

function changeCssFile( sCssFile ) {
	var loc = String(document.location);
	var search = document.location.search;
	if ( search != "" )
		loc = loc.replace( search, "" );
	loc = loc + "?css=" + sCssFile;
	document.location.replace( loc );
}

var cssFile = getQueryString( "css" );
if ( cssFile == "" )
	cssFile = "main/css/officexp.css";

document.write("<link type=\"text/css\" rel=\"StyleSheet\" href=\"" + cssFile + "\" />" );

