/*  	
	Brown Paper Bab - Web Studio - Web Design - Web Creation - Web Hosting - Internet - Intranet
	Version 1.1
	Created: 19th Feb 2006
	By: info@brownpaperbag.com.au
	Modified: 
		23rd Feb 2006 RB Added HighlightNav function
*/
//<![CDATA[
function OpenModal(url){
	var oVals;
	s = document.getElementById('greyout');
	s.style.visibility = 'visible';
	oVals = window.showModalDialog(url,'', 'dialogHeight:430px;dialogWidth:500px;center:yes;status:no')
	if (oVals){
		if (oVals.Update) {
			window.location.reload(true);
		}else{
			s.style.visibility = 'hidden';
		}
	}else{window.location.reload(true);}
}
function oModal(url,x,y){
	var oVals;
	var strWinOpts = "dialogHeight: " + y + "px; dialogWidth: " + x + "px; center:yes; help:no; resizable:no; scroll:no; status:no;"
	s = document.getElementById('greyout');
	s.style.visibility = 'visible';
	oVals = window.showModalDialog(url,'', strWinOpts)
	if (oVals){
		if (oVals.Update) {
			window.location.reload(true);
		}else{
			s.style.visibility = 'hidden';
		}
	}else{s.style.visibility = 'hidden';}
}
	
function OpenModalNoRefresh(url, x, y){
	var oVals;
	var strWinOpts = "dialogHeight: " + y + "px; dialogWidth: " + x + "px; center:yes; help:no; resizable:no; scroll:no; status:no;"
	s = document.getElementById('greyout');
	s.style.visibility = 'visible';
	oVals = window.showModalDialog(url,'', strWinOpts)
	if (oVals){
			s.style.visibility = 'hidden';
			//window.location.reload(false);

	}else{s.style.visibility = 'hidden';}
}
var current = null;

// Page load events
function WinLoad(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() { 
			oldonload();
			func();
		}
	}
};
/*  Display Date and Time in the Cookie Trail */
function DateTime(){
	var thetime=new Date();
	var nhours=thetime.getHours();
	var nmins=thetime.getMinutes();
	var nsecn=thetime.getSeconds();
	var nday=thetime.getDay();
	var nmonth=thetime.getMonth();
	var ntoday=thetime.getDate();
	var nyear=thetime.getYear();
	var AorP=" ";
	
	if (nhours>=12) AorP="P.M.";
	   else AorP="A.M.";
	
	if (nhours>=13) nhours-=12;
	if (nhours==0) nhours=12;
	if (nsecn<10) nsecn="0"+nsecn;
	if (nmins<10) nmins="0"+nmins;
	
	if (nday==0) nday="Sunday";
	if (nday==1) nday="Monday";
	if (nday==2) nday="Tuesday";
	if (nday==3) nday="Wednesday";
	if (nday==4) nday="Thursday";
	if (nday==5) nday="Friday";
	if (nday==6) nday="Saturday";


	if (nmonth==0) nmonth="Jan";
	if (nmonth==1) nmonth="Feb";
	if (nmonth==2) nmonth="Mar";
	if (nmonth==3) nmonth="Apr";
	if (nmonth==4) nmonth="May";
	if (nmonth==5) nmonth="Jun";
	if (nmonth==6) nmonth="Jul";
	if (nmonth==7) nmonth="Aug";
	if (nmonth==8) nmonth="Sep";
	if (nmonth==9) nmonth="Oct";
	if (nmonth==10) nmonth="Nov";
	if (nmonth==11) nmonth="Dec";

	if (nyear<=99) nyear= "19"+nyear;
	if ((nyear>99) && (nyear<2000)) nyear+=1900;
	
	var clock = document.getElementById('Clock');
	if (clock) clock.innerHTML=nhours+":"+nmins+":"+nsecn+" "+AorP+" "+nday+", "+ntoday+"-"+nmonth+"-"+nyear;
	setTimeout('DateTime()',1000);
};
//WinLoad(DateTime);

function setNav(){
	var url = location.href;
	//url = url.replace(/\.aspx.*/,"");
	url = url.toLowerCase();
	el = document.getElementById('Nav');
	if (el){
		Anchors = el.getElementsByTagName("a");
		for (var i=0;i<Anchors.length;i++){
			el = Anchors[i];
			//alert(el.href.toLowerCase() + ' = ' +  url);
			if (el.href.toLowerCase() == url){ 
				
				var Imgs = el.getElementsByTagName("img");
				var SplStr = Imgs[0].src.split('.');
				Imgs[0].src = SplStr[0] + '_ovr.' + SplStr[1];
			};
		}
	}
	

}

//WinLoad(setNav);





var Logout = false;

function SessionTimeoutWarning(){
	setTimeout('TimeoutWarning()', 1680000);
	
}

//setTimeout('TimeoutWarning()', 1680000);
//setTimeout('ForceLogout()', 1800000 );

function TimeoutWarning(){
	var el = document.getElementById('ScnMsg');
	Logout = true;
	el.innerHTML = '<table class="Data"><col width="380px" /><col width="20px" /><tr><th>Information</th><th><a href="" id="clsMsgBox" id="hideMsgBox" onclick="hideMsgBox(); return false;"><img src="/img/btn_close.gif" width="17" height="17" onmouseover="ImgSwp(this);" onmouseout="ImgSwp(this);"></a></th></tr><tr><td colspan="2" class="Info">Your session has been idle for more then 20mins and will be logged out in 1 minute. <br><br>If you are currently using the system<b>click CLOSE immediately to continue.</b>.<div style="text-align:right; margin-top:12px;"><a href="" onclick="hideMsgBox(); return false;"><img src="/img/btn_close_lrg.gif" width="69" height="25" onclick="CancelLogout()" onmouseover="ImgSwp(this);" onmouseout="ImgSwp(this);"></a></div></td></tr></table>';
	el.style.display = 'block';
	
	setTimeout('ForceLogout()', 120000 );
}
function CancelLogout(){
	Logout = false;
	setTimeout('TimeoutWarning()', 1680000);
}
function ForceLogout(){
	if (Logout){
		window.location = "/logoff.aspx";
	}
}
//WinLoad(SessionTimeoutWarning);
/* Functions to fix on sreen messages */
function checkOverlaySupport(){
	if(navigator.userAgent.indexOf("Windows")!=-1&&typeof document.body!="undefined"&&typeof document.body.insertAdjacentHTML!="undefined"&&!window.opera&&navigator.appVersion.indexOf("MSIE 5.0")==-1)return true;
	else return false;
};
function setShim(el) {
	/*	if (!document.getElementById('HelpShim')){document.body.insertAdjacentHTML("beforeEnd",'<iframe id="HelpShim" src="about:blank" style="position:absolute; left:0; top:0; z-index:5; visibility:hidden" scrolling="no" frameborder="0"></iframe>');}
		var Shim = document.getElementById('HelpShim');
		if (Shim&&el){
			Shim.style.width=el.offsetWidth+"px";
			Shim.style.height=el.offsetHeight+"px";
			Shim.style.top=el.offsetTop+"px";
			Shim.style.left=el.offsetLeft+"px";
		}
		Shim.style.visibility="visible"; */
};
function fixMessages(){
	var Overlay = checkOverlaySupport();
 	var Help = document.getElementById('Help');
	if (Help && Help.style.display != 'none' && Overlay) { setShim(Help); }
 	var MsgBox = document.getElementById('ScnMsg');
	if (MsgBox && MsgBox.style.display == 'block' && Overlay) { setShim(MsgBox);}
};
//WinLoad(fixMessages);

function confirmDelete(Name){
	if(confirm("Are you sure you want to delete this item from the database?\n\nNote: If you select 'Ok' the action cannot be undone.")){return true;}else{return false;}
}

/* Image Swapper */
function ImgSwp(oButton) {  // Image swapper
	var ext = oButton.src.substring(oButton.src.lastIndexOf("."), oButton.src.length)
	var path = oButton.src.substring(0, oButton.src.lastIndexOf("/")+1)
	var file = oButton.src.substring(oButton.src.lastIndexOf("/")+1,oButton.src.lastIndexOf("."))
	if (oButton != current){
		oButton.src = (((i = file.indexOf("_ovr")) >= 0) ) ? path + file.substring(0, file.lastIndexOf("_")) + ext : path + file + "_ovr" + ext;
	}

};
/*  Hides the help window */
function hideMsgBox(){
	var MsgBox = document.getElementById('ScnMsg');
	//var Shim = document.getElementById('HelpShim');
	MsgBox.style.display = 'none';
	//if (Shim) Shim.style.visibility="hidden";
};

/*  Opens the Case Plan Report */
function openReport(url) {
	var posx = (screen.availWidth-680)/2;
	var posy = (screen.availHeight-500)/2;
	var windowString = 'toolbar=yes,location=no,menubar=yes,status=no,titlebar=no,resizable=yes,directories=no,scrollbars=yes,copyhistory=no,width=680,height=500,left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
	oWin = window.open(url, "Report", windowString);
	oWin.focus();
};

/*  Opens the Main CSNet Window */
function CSNet(el){
	var url = el.href;
	var sizeX = 1024;
	var sizeY = 742;
	var posx = (screen.availWidth-sizeX)/2;
	var posy = (screen.availHeight-sizeY)/2;
	var windowString = 'toolbar=no,location=no,menubar=no,status=no,titlebar=no,resizable=no,directories=no,scrollbars=no,copyhistory=no,width='+sizeX+',height='+sizeY+',left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
	oWin = window.open('', 'CSnet', windowString);
	oWin.location = url;
	oWin.focus();
};

function openWin( location, name, sizeX, sizeY ) {
  var posx = (screen.availWidth-sizeX)/2;
  var posy = (screen.availHeight-sizeY)/2;
  var windowString = 'toolbar=no,location=no,menubar=no,status=no,titlebar=no,resizable=no,directories=no,scrollbars=no,copyhistory=no,width='+sizeX+',height='+sizeY+',left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
  oWin = window.open(location, name, windowString);
  oWin.focus();
};
/* XMLPost */
function AJAXInteraction(url, callback) {
    var req = init();
    req.onreadystatechange = processRequest;
        
    function init() {
      if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
    
    function processRequest () {
      // readyState of 4 signifies request is complete
      if (req.readyState == 4) {
	// status of 200 signifies sucessful HTTP call
        if (req.status == 200) {
          if (callback) callback(req.responseText);
        }
      }
    }

    this.doGet = function() {
      // make a HTTP GET request to the URL asynchronously
      req.open("GET", url, true);
      req.send(null);
    }
}


//]]>