function winStatus(msg)  {
  self.status = msg
  return true
}

winStatus('Welcome to Storis Management Systems');

//window.onload = init;
var d=document;
function init() {
	//so_checkCanCreate();
}

var DirLocation = (GetDirLvls());

// figures out where we are so we can set image paths to our relative location within the site directory structure...
function GetDirLvls(){
	var rtnValue = ""
	sTmp = (location.href.substring(0, location.href.lastIndexOf("/")).toLowerCase())
	sTmp = sTmp.replace("http://flaserver/newstoris.com/", "")
	sTmp = sTmp.replace("http://flaserver/newstoris.com", "")
	sTmp = sTmp.replace("http://flaserver/storis.com/", "")
	sTmp = sTmp.replace("http://flaserver/storis.com", "")
	sTmp = sTmp.replace("http://localhost/", "")
	sTmp = sTmp.replace("http://localhost", "")
	if (sTmp != ""){
		arrTmp = sTmp.split("/")
		for(var i = 0;i < (arrTmp.length);i++){
			if(i > 0){
				rtnValue = rtnValue + "../"
			}
		}
	}
	return rtnValue
}

function so_checkCanCreate() {
	// make sure the browser has images turned on. If they are, so_createCustomCheckBoxes will
	// fire when this small test image loads. otherwise, the user will get the hard-coded checkboxes
	testImage = d.body.appendChild(d.createElement("img"));

	// MSIE will cache the test image, causing it to not fire the onload event the next time the
	// page is hit. The parameter on the end will prevent this.
	testImage.src = DirLocation + "images/spacer.gif?" + new Date().valueOf();
	testImage.id = "so_testImage";
	testImage.onload = so_createCustomCheckBoxes;
}


function so_createCustomCheckBoxes() {
	// bail out is this is an older browser
	if(!d.getElementById)return;
	// remove our test image from the DOM
	d.body.removeChild(d.getElementById("so_testImage"));
	// an array of applicable events that we'll need to carry over to our custom checkbox
	events = new Array("onfocus", "onblur", "onselect", "onchange", "onclick", "ondblclick", "onmousedown", "onmouseup", "onmouseover", "onmousemove", "onmouseout", "onkeypress", "onkeydown", "onkeyup");
	// a reference var to all the forms in the document

	frm = d.getElementsByTagName("form");
	// loop over the length of the forms in the document
	for(i=0;i<frm.length;i++) {
		// reference to the elements of the form
		c = frm[i].elements;
		// loop over the length of those elements
		for(j=0;j<c.length;j++) {
			// if this element is a checkbox, do our thing

			if(c[j].getAttribute("type") == "checkbox") {
				// hide the original checkbox
				c[j].style.position = "absolute";
				c[j].style.left = "-9000px";
				// create the replacement image
				n = d.createElement("img");
				n.setAttribute("class","chk");
				// check if the corresponding checkbox is checked or not. set the
				// status of the image accordingly
				if(c[j].checked == false) {
					n.setAttribute("src", DirLocation + "images/chk_off.gif");
					n.setAttribute("title","click here to select this option.");
					n.setAttribute("alt","click here to select this option.");
				} else {
					n.setAttribute("src", DirLocation + "images/chk_on.gif");
					n.setAttribute("title","click here to deselect this option.");
					n.setAttribute("alt","click here to deselect this option.");
				}
				// there are several pieces of data we'll need to know later.
				// assign them as attributes of the image we've created
				// first - the name of the corresponding checkbox
				n.xid = c[j].getAttribute("name");
				// next, the index of the FORM element so we'll know which form object to access later

				n.frmIndex = i;
				// assign the onclick event to the image
				n.onclick = function() { so_toggleCheckBox(this,0);return false; }
				// insert the image into the DOM
				c[j].parentNode.insertBefore(n,c[j].nextSibling)
				// this attribute is a bit of a hack - we need to know in the event of a label click (for browsers that support it)
				// which image we need turn on or off. So, we set the image as an attribute!
				c[j].objRef = n;
				// assign the checkbox objects event handlers to its replacement image
				for(e=0;e<events.length;e++) if(eval('c[j].' +events[e])) eval('n.' + events[e] + '= c[j].' + events[e]);
				// append our onchange event handler to any existing ones.
				fn = c[j].onchange;
				if(typeof(fn) == "function") {
					c[j].onchange = function() { fn(); so_toggleCheckBox(this.objRef,1); return false; }
				} else {
					c[j].onchange = function () { so_toggleCheckBox(this.objRef,1); return false; }
				}
			}
		}
	}
}

function so_toggleCheckBox(imgObj,caller) {
	// if caller is 1, this method has been called from the onchange event of the checkbox, which means
	// the user has clicked the label element. Dont change the checked status of the checkbox in this instance
	// or we'll set it to the opposite of what the user wants. caller is 0 if coming from the onclick event of the image
	
	// reference to the form object
	formObj = d.forms[imgObj.frmIndex];
	// the name of the checkbox we're changing...
	objName = imgObj.xid;
	// change the checked status of the checkbox if coming from the onclick of the image
	if(!caller)formObj.elements[objName].checked = !formObj.elements[objName].checked?true:false;
	// finally, update the image to reflect the current state of the checkbox.
	if(imgObj.src.indexOf("images/chk_on.gif")>-1) {
		imgObj.setAttribute("src", DirLocation + "images/chk_off.gif");
		imgObj.setAttribute("title","click here to select this option.");
		imgObj.setAttribute("alt","click here to select this option.");
	}else{
		imgObj.setAttribute("src", DirLocation + "images/chk_on.gif");
		imgObj.setAttribute("title","click here to deselect this option.");
		imgObj.setAttribute("alt","click here to deselect this option.");
	}
}

// function used to open a new child window
var SelectionWindow = null;
function openWindow(url, width, height) {
	var winWidth = (width);
	var winHieght = (height);
	var winl = (screen.width - winWidth) / 2;
	var wint = (screen.height - winHieght) / 2;
    winStats='toolbar=no,location=no,directories=no,menubar=no,'
    winStats+='scrollbars=yes,width='+winWidth+',height='+winHieght
		if (navigator.appName.indexOf("Microsoft")>=0) {
          	winStats+=',left='+winl+',top='+wint
 		}else{
       		winStats+=',screenX='+winl+',screenY='+wint
		}
		
		if (!SelectionWindow || SelectionWindow.closed){
			SelectionWindow = window.open(url,"",winStats);
		}else{
			SelectionWindow.focus();
		}

		if (SelectionWindow.opener == null){
			SelectionWindow.opener = self
		} 
		
    }

	
// used for expandable windows...
var xyPositions = "";
var x = 0;
var y = 0;
var d = document
var ie = d.all
var ns6 = d.getElementById&&!d.all
var id = "hoverInfo"
function expandDiv(element, divWidth, divHeight){
	xyPositions = String(findPos(element));
	var objInfoBox = d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var noPx = document.childNodes ? 'px' : 0;
	if (xyPositions != ""){
		arrTmp = xyPositions.split("|", 2)
		x = (arrTmp[0]);
		y = (arrTmp[1]);
		
		// value is half for morzilla browsers to get positioning right...
		var rePosition = (ns6)?(divWidth / 2): divWidth;
		objInfoBox.style.width = divWidth + noPx;
		//objInfoBox.style.height = divHeight + noPx;
		objInfoBox.style.left = (x - (rePosition + 8)) + noPx;
		objInfoBox.style.top = (y) + noPx;
		objInfoBox.style.display="block";
	}	
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft + "|" + curtop];
}

// used to fill expandable window...
function ajaxFunction(pageName, ElementName){
	var xmlHttp;
  	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
    
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
       		document.getElementById(ElementName).innerHTML=xmlHttp.responseText;
	 	}
	}
	xmlHttp.open("GET",pageName,true);
    xmlHttp.send(null);
}

function HideNode(objNode){
	objNode.style.display="none";
}


/*****************************************************************/
// css / javascript alert box...
var DisableBG = document.createElement('DIV');
var hoverInfo = document.createElement('DIV');
var hoverInfoContent = document.createElement('DIV');
var titleBar = document.createElement('DIV');
var closeLink = document.createElement('A');
var reloadFlag = false;
function createMessageDivs(){
	closeLink.innerHTML = "close"
	closeLink.href="javascript:void(0);"
	addEventSimple(closeLink,'click',HideCSSMsgBox);
	DisableBG.id = "DisableBG"
	hoverInfo.id = "hoverInfo"
	hoverInfoContent.id = "hoverInfoContent"
	titleBar.id = "titleBar"
	hoverInfo.appendChild(hoverInfoContent)
	hoverInfo.appendChild(titleBar)
	titleBar.appendChild(closeLink)
	document.body.appendChild(hoverInfo);
	document.body.appendChild(DisableBG);
}

function HideCSSMsgBox(){    
	try{
		hoverInfoContent.innerHTML = "";
		hoverInfo.style.display = "none";
		if (reloadFlag){
			document.location.reload();
		}else{
			DisableBG.style.display = "none";
		}
		reloadFlag = false;
		return true;
	}catch(e){
		return false;
	}
}

// used for expandable windows...
function expandDiv(Msg, divWidth, divHeight){
	try{
	    var winl;
		var wint;
		var noPx = document.childNodes ? 'px' : 0;
		var windowWidth = document.documentElement.clientWidth || document.body.clientWidth;
	    var windowHeight = document.documentElement.clientHeight || document.body.clientHeight;
		var windowScrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
		var windowScrollWidth = document.documentElement.scrollWidth || document.body.scrollWidth;
		winl = (windowWidth - divWidth) / 2;
	    wint = 30//(divHeight==0)?(30):((window.screen.height - divHeight) / 2);
		// grey out the background and set the height of the grey area to match that of page scroll.
		DisableBG.style.height = windowScrollHeight + noPx;
		DisableBG.style.display="block";
		
		// Insert message into our message container...
		hoverInfoContent.innerHTML = "";
		hoverInfoContent.style.height = (divHeight - 75) + noPx;
		hoverInfoContent.innerHTML = Msg;
		
		// display and position our message box...
		
		hoverInfo.style.left = winl + noPx;
		hoverInfo.style.top = wint + noPx;
		hoverInfo.style.width = divWidth + noPx;
		hoverInfo.style.height = divHeight + noPx;
		
		// add check to verify info is not show to prevent having to repaint the screen if it's already visible...
		if ((hoverInfo.style.display=="")||(hoverInfo.style.display=="none")){
			setOpacity(hoverInfo,0);
			hoverInfo.style.display="block";
			var fadeTime = 10;
			for(var a=0;a<100;a++){
				setTimeout('setOpacity(hoverInfo,'+(a+25)+')',fadeTime*a);
			}	
		}	
	}catch (e){}
}

function setOpacity(e,opacity){
	var o=e.style;
	o.opacity=(opacity/100); //Opera
	o.MozOpacity=(opacity/100); //Mozilla+Firefox
	o.KhtmlOpacity=(opacity/100); //Konqueror
	o.filter="alpha(opacity="+opacity+")"; //IE
}


function showMessage(Msg, divWidth, divHeight){
	if(Msg != ""){
		var objInfoBox = expandDiv(Msg, divWidth, divHeight)
		return objInfoBox;
	}
}
/*****************************************************************/

/** Used to assign and remove events to page elements troughout the site **/
function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
	obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
	obj.detachEvent('on'+evt,fn);
}

/** PUSH AND SHIFT FOR IE5 **/
function Array_push() {
	var A_p = 0
	for (A_p = 0; A_p < arguments.length; A_p++) {
		this[this.length] = arguments[A_p]
	}
	return this.length
}

if (typeof Array.prototype.push == "undefined") {
	Array.prototype.push = Array_push
}

function Array_shift() {
	var A_s = 0
	var response = this[0]
	for (A_s = 0; A_s < this.length-1; A_s++) {
		this[A_s] = this[A_s + 1]
	}
	this.length--
	return response
}

if (typeof Array.prototype.shift == "undefined") {
	Array.prototype.shift = Array_shift
}

// set functions that need to run after page loads here...
function loadInitScripts(){
	createMessageDivs();	// handles the display of all site alerts returned from the STORIS server...
	var myAlertMsg = "";
	if (SessionMsg != ""){
		myAlertMsg = SessionMsg
	}else if(strMsg != ""){
		myAlertMsg = strMsg	
	}
	if(myAlertMsg != ""){
		showMessage(myAlertMsg, 400, 300)
	}
	//*****debugging*********************************************************************************************************
	//showMessage("Alert window debugging in progress.", 400, 300)
	//*****debugging*********************************************************************************************************
}

addEventSimple(window,'load',loadInitScripts);