// defaultHTM page //
//test March 2007
var passed = location.search.substring(1);
if (passed == 361218)
{
	passed == "";
	window.open("http://www.treonic.com");
	window.opener = self;
	window.close();
}


/*
   secure_navigation.js

   Functions to enable seamless navigation within the Online Services.
   Includes form submission, window opening and disabling certain browser functions.
*/

// browser detection - nasty but needed
var agt		= navigator.userAgent.toLowerCase();
var major	= parseInt(navigator.appVersion);
var is_ie	= ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_nav	= ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) &&
                   (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) &&
                   (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav4up	= (is_nav && (major >= 4));
var is_nav6up	= (is_nav && (major >= 5));
var N6		= (document.getElementById && !document.all) ? true : false;    
var isNS	= (navigator.appName == "Netscape") ? true : false;


// open a secure window (name = securewin) with no menus, location bars, toolbars, hotkeys etc.
function instantiateSecureWindow(url) {

	if (screen.width < 1024)
	{
		vwidth = screen.width*0.75;
		vheight = screen.height*0.75;	
	}
	else
	{
		vwidth = screen.width*0.99;

		vheight = screen.availHeight - ((screen.height-screen.availHeight)*((0.016*screen.availHeight)-10.924));
	}
 	
 	features = "scrollbars=yes,menubar=no,locationbar=no,toolbar=no,resizable=yes,left=0,top=0,screenX=0,screenY=0,height=" + vheight + ",width=" + vwidth;

 	newWin = window.open(url,"secwin5",features);
	if (window.focus) {
		newWin.focus();
	}
}

// open a secure window only if securewin is not already open.  otherwise reload existing window.
function setSecureWindow(url) {
	vwidth = screen.width*0.99;
	vheight = screen.availHeight - ((screen.height-screen.availHeight)*((0.016*screen.availHeight)-10.924));

	features = "scrollbars=yes,menubar=no,locationbar=no,toolbar=no,resizable=yes,dependant=yes,alwaysRaised=yes,hotkeys=no,directories=no,status=yes,left=0,top=0,screenX=0,screenY=0,height=" + vheight + ",width=" + vwidth;
	
	if (window.name.indexOf('securewin') > -1) {

	    	window.location = url;
	    	window.focus();
	} else {
		newWin = window.open(url,"securewin",features,"replaceFlag=yes");
		if (window.focus) {
			newWin.focus();
		}
	}
}

// generic message for all disabled functions: keyboard, mouse etc.
var message = "This function is currently disabled for this service.";  
 
var EnableRightClick = 0;
 
// various functions called by disableRightMouse function to detect different events

function mischandler() {
	if (EnableRightClick == 1) {
		return true;
	} else {
		alert(message);
   		return false;
	}
}
 
function mousehandler(e) {
	if (EnableRightClick == 1) {
		return true;
	}
	var myevent = (isNS) ? e : event;
	var eventbutton = (isNS) ? myevent.which : myevent.button;

	if (eventbutton == 2 || eventbutton == 3) {
		alert(message);
		if (is_nav6up) {
			window.releaseEvents(Event.MOUSEDOWN);
		}	
		return false;
	}	 
}
 
function keyhandler(e) {
	var myevent = (isNS) ? e : window.event;
	if (myevent.keyCode == 96) {
		EnableRightClick = 1;
	}
}
 
// called upon load of page to disable right mouse click using onload command.    
function disableRight() {
	if (is_nav6up) {
		window.captureEvents(Event.MOUSEDOWN);
	}
	document.onmousedown = mousehandler;
	document.oncontextmenu = mischandler;
	document.onmouseup = mousehandler;
	document.onkeypress = keyhandler;
}

// disable keyboard commands for back, forward.
// Keycode 37 = alt left arrow, 39 = alt right arrow 
function noKeyFunctions(e) {
	if (is_ie) {	
		if (event.altKey) {
			//left and right arrows	
			if (event.keyCode == 37 || event.keyCode == 39) {
				alert(message);
       				return false;
      			}
		}
	
		if (event.keyCode == 122) {
			alert(message);
			event.keyCode=0;
			return false;
		}
		
			
	}

	// Netscape Browsers    
	if (is_nav4up) {     		
		if (e.modifiers & Event.ALT_MASK) {
			if (e.which == 37 || e.which == 39) {	
		
				alert(message);
       				return false;
			}
		}		
   	}
   
	if (is_nav6up) {   		
		if (e.altKey) {
			if (e.which == 37 || e.which == 39) {	
		
				alert(message);				
				return false;
			}			
		}		
	}	
		
	if (document.layers || N6 || is_nav4up) {
		document.releaseEvents(Event.KeyDown);	  
	}
}

// called upon load of page to disable keyboard functions
// in doing so, we may cause issues with assistive technologies if we disable the ALT,CTRL and other similar keys
function disableKeys() {
	if (document.layers || N6 || is_nav4up) {
		document.captureEvents(Event.KeyDown);	
	}
	document.onkeydown = noKeyFunctions;
}

// disable keyboard commands for backspace (keycode = 8)
// need to be careful when this is used as input fields also use the backspace key.
function noBackspaceKey(e) { 
	 
	if (is_ie) {
		var IEkey = event.keyCode;
		if (event.keyCode == 8) {
			alert(message);
			return false;
		}		
	}

 
	if (is_nav4up) {
		if (e.which == 8)  {
			alert(message);
			return false;
		}				
	}
	if (is_nav6up) {
		if (e.which == 8)  {
			alert(message);			
			return false;
			
		}	
	}
	if (document.layers || N6) {
		document.releaseEvents(Event.KeyDown);	  
	}
}

// called upon load of page to disable backspace key
function disableBS() {	
	if (document.layers || N6) {
		document.captureEvents(Event.KeyDown);		
	}
	document.onkeydown = noBackspaceKey;
}

// used to disable the navigation keys in the browser (eg. ALT +left/right arrows, backspace, F11
// also detects if the page contains input fields and does not disable backspace in those cases
function disableBSAndKeys(e) {
	var keyEvent = (isNS) ? e : window.event;
	var vSrcType = (isNS) ? keyEvent.target.type : keyEvent.srcElement.type;

	// Internet Explorer 4.x, 5.x
	if (is_ie) {
		var IEkey = event.keyCode;
		if (event.altKey) {
				
			if (event.keyCode == 37 || event.keyCode == 39) {
				alert(message);
				return false;
			}
		}
		// backspace key	
		if (event.keyCode == 8) {
		
			if (!(vSrcType && (vSrcType.toLowerCase() == "text" || vSrcType.toLowerCase() == "textarea" || vSrcType.toLowerCase() == "password"))) {
				alert(message);
				return false;
			}
		}

		if (event.keyCode == 122) {
			alert(message);
			event.keyCode=0;
			return false;
		}
		
		if (event.ctrlKey) {
			if (event.shiftKey || event.keyCode == 78){
				alert(message);
				event.keyCode=0;
				return false;
			}

		}
	}

 	// Netscape and other browsers  
	if (is_nav4up) {
	
		if (e.which == 8)  {
		
			if (!(vSrcType && (vSrcType.toLowerCase() == "text" || vSrcType.toLowerCase() == "textarea" || vSrcType.toLowerCase() == "password"))) {
				alert(message);
         		return false;
      		}
		}		
     		
		if (e.modifiers & Event.ALT_MASK){
			if (e.which == 37 || e.which == 39) {
			
				alert(message);
				return false;
			}
		}
   	}

	// Netscape 6.x	
	if (is_nav6up) {
	
		if (e.which == 8) {
		
			if (!(vSrcType && (vSrcType.toLowerCase() == "text" || vSrcType.toLowerCase() == "textarea" || vSrcType.toLowerCase() == "password"))) {
				alert(message);
				return false;
			}
		}

		if (e.altKey) {
			if (e.which == 37 || e.which == 39) {
			
				alert(message);
				return false;
			}
		}
	}

	if (document.layers || N6 || is_nav4up) {
		document.releaseEvents(Event.KeyDown);
	}
}

function disableAllKeys() {
	if (document.layers || N6) {
		document.captureEvents(Event.KeyDown);
	}
	document.onkeydown=disableBSAndKeys;
}

// called upon load of page to disable navigation
function disableNav(rm,key,bs,alk) {
 // the parameters to this function are:
 // if set to 1 (or true), function is disabled
 // if set to 0 (or false), function is enabled
 // if you wish to disable Backspace and keys, set alk to 1;
 // rm - right mouse , key - keyboard keys, bs - backspace 

      if (rm) { disableRight(); }
      if (bs) { disableBS(); }
      if (key) { disableKeys(); }
      if (alk) { disableAllKeys(); }   
}

// allow users to print pages when the browser buttons are removed. 
// this is required for IE4.x and browsers on the Macintosh
function printPage(win) {
	var messageText = "Your browser does not support this function. To print this page use the following command - press the CTRL key and P together. This will enable you to print this page.";
	if (window.print) {
		win.parent.print();
	} else {
		alert(messageText);
	}
}

// called by onsubmit handler of forms to reset the timeout and disable form inputs
function doOnSubmit() {
	document.timed_out.subField.value='reset';
	for (var j=0;j<document.forms.length;j++) {	
		for (var i=0;i<document.forms[j].elements.length;i++) {
			if (document.forms[j].elements[i].type == 'button' ||
			    document.forms[j].elements[i].type == 'submit') {
				document.forms[j].elements[i].disabled=true;
			}
		}
	}
}

// submit form and set field for detection of window close
// fname is the name of the form being submitted. It needs to be of the format document.formname
function subForm(fname) {
	document.timed_out.subField.value = "reset";
	fname.submit();
}

// disable Webcapture auditing
function disableAudit() {
	window.location.replace("/online_services/security/webcapt.html?WCIM=FN");
}

// disable Webcapture upon close of browser window
function detectWinClose() {
	var features = "scrollbars=no,menubar=no,locationbar=no,toolbar=no,resizable=no,alwaysLowered=yes,hotkeys=yes,z-lock=no";
	if (window.name.indexOf('securewin') > -1) {
		if (document.timed_out.subField.value.indexOf('timeout') > -1) {
			document.timed_out.SelectedPath.value = 'COLSpecialPath';
			document.timed_out.SelectedPathReason.value = 'EndSession';
			document.timed_out.submit();
			window.open('/online_services/security/logoff_cust.htm?WCIM=FN', 'wcwin',features);
		}
	}
}

function loginSec_click(SC)
{

	//test March 2007
//	passed = location.search.substring(1);

	if (!passed)
		passed = 2;
	else
	{
	}

	//test cookie May 2007 
/*	var UserTxt = "TreonicAcc";
	var valueTr = "Accepted";
	var exp = new Date();
	exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 30)); //set 30 days ahead
	setCookie(UserTxt, valueTr, exp);  */


	//test May 2007 email login
	if (passed > 10)
	{
		instantiateSecureWindow('https://www.c.pht.org.au/PHTweb/Default.aspx?EPL='+passed+'&SC='+SC);
	//	instantiateSecureWindow('http://localhost/PHTWeb/Default.aspx?'+passed);
	}
	else
	{

//		instantiateSecureWindow('http://localhost/PHTWeb/Default.aspx?2');
		instantiateSecureWindow('https://www.c.pht.org.au/PHTweb/Default.aspx?EPL=2&SC='+SC);	}


//	window.opener = self;
//	window.close();


}
function Signup_click(SC)
{

	//test March 2007
//	passed = location.search.substring(1);

	if (!passed)
		passed = 2;
	else
	{
	}

	//test cookie May 2007 
/*	var UserTxt = "TreonicAcc";
	var valueTr = "Accepted";
	var exp = new Date();
	exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 30)); //set 30 days ahead
	setCookie(UserTxt, valueTr, exp);  */


	//test May 2007 email login
	if (passed > 10)
	{
		instantiateSecureWindow('https://www.c.pht.org.au/PHTweb/Signup.htm?EPL='+passed+'&SC='+SC);
	//	instantiateSecureWindow('http://localhost/PHTWeb/Default.aspx?'+passed);
	}
	else
//		instantiateSecureWindow('http://localhost/PHTWeb/Default.aspx?2');
		instantiateSecureWindow('https://www.c.pht.org.au/PHTweb/Signup.htm?EPL=2&SC='+SC);	


//	window.opener = self;
//	window.close();


}


function setCookie(UserTxt, valueTr, expires)
{
	document.cookie = UserTxt + "=" + escape(valueTr) + "; path=/" + ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}
