var showEffects=false;
var isie = navigator.appName == 'Microsoft Internet Explorer';
var isie6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var onLoadQueue = new Array;
var startedUpload = false;
//rental
function onLoad(){
	try{
		RedrawAllTrees();
	} catch(e) {
		/*do nothing */
	}
	 
	Tooltip.init();
	dw_event.add(window, "unload", Tooltip.unHookHover, true);
	try{ datePickerController.create(); } catch(e) { };
	
	fixPNG();
	
	if(typeof(moreOnLoad)!='undefined')
		moreOnLoad();
	return false;	
}


function openWindow(url,width,height){
	window.open(url ,"_blank","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+width+",height="+height);
}

function fixPNG(){
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphEDUFlightageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}
}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function setSelectValue(newvalue,selobj){
	if (newvalue.length > 0){
		for (var x=0; x < selobj.length; x++){
			if(selobj[x].value == newvalue){
				selobj.selectedIndex = x;	
			}
		}
	}
}

function setRadioValue(newvalue,selobj){
	if (newvalue.length > 0){
		for (var x=0; x < selobj.length; x++){
			if(selobj[x].value == newvalue){
				selobj[x].checked = true;	
			}
		}
	}
}


function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function SetCookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ){
		expires = expires * 1000 * 60 * 60;
	}
	
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function GetCookie(name) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function fadeBg(){
	var pagesize = getPageSizeWithScroll();
	var windowsize = getWindowSize();
	var fadepurplebg = document.createElement('div');

	fadepurplebg.className = 'TB_overlayBG';
	fadepurplebg.setAttribute('id','TB_overlay');
	
	var divheight;
	
	if(pagesize[1]>document.body.offsetHeight)
		divheight = pagesize[1];
	else if (windowsize[1] > document.body.offsetHeight)
		divheight = windowsize[1];
	else
		divheight = document.body.offsetHeight
	
	fadepurplebg.style.height = divheight+'px';

	document.body.appendChild(fadepurplebg)
}


function removefade(){
	if (showEffects){
		new Effect.Fade('fadepurplebg',{duration:1})
		setTimeout("document.body.removeChild(document.getElementById('fadepurplebg'))",2001)
	} else
		document.body.removeChild(document.getElementById('fadebg'));
}


function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {
		// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		// all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else {
		// works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
	}     arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);

	return arrayPageSizeWithScroll;
} 

function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Array(myWidth,myHeight);

}


function fadePurple(newid){
	fadeBg();
}

function removefadePurple(id){
	if(typeof(id)=='undefined')
		id='';
		
	if (showEffects){
		new Effect.Fade('fadepurplebg',{duration:1})
		setTimeout("document.body.removeChild(document.getElementById('TB_overlay'))",2001)
	} else
		document.body.removeChild(document.getElementById('TB_overlay'));
}

function showWidePopup(popuptext,nobackfade,notinviewport,newdivname){
	var sidecontent='<img src="/images/ContactSupport.png" width="145" height="112" alt="Contact Support" /><map name="associatemap"><area coords="34,32,113,119" shape="rect" href="http://www.iia.net.au/" alt="Internet Industry Association" target="_blank" /><area coords="33,121,118,206" shape="rect" href="http://www.lawyersalliance.com.au/" alt="Australian Lawyers Allicance" target="_blank" /></map><img src="/images/Associates.png" width="145" height="300" usemap="associatemap" />';
	
	showPopup(popuptext,nobackfade,notinviewport,newdivname,sidecontent)
}

function showPopup (popuptext,nobackfade,notinviewport,newdivname,extendedcontent){	
	if(typeof(newdivname)=='undefined')
		newdivname=''

	if(typeof(extendedcontent)=='undefined')
		extendedcontent=''

	var contentcontainer = document.createElement('div');
	contentcontainer.setAttribute('id','TB_window')
	contentcontainer.style.marginLeft="-355px";
	contentcontainer.style.width="710px";
	contentcontainer.style.display="block";
	
	contentcontainer.innerHTML=popuptext;

	document.body.appendChild(contentcontainer);
//	hideElements();
	fixPNG();
	  if(navigator.appName =='Microsoft Internet Explorer')
                {
                                var scriptelements = contentcontainer.getElementsByTagName('script');
                                for (i =0;i<scriptelements.length;i++)
                                {
                                                if(scriptelements[i].innerHTML!="")
                                                {
                                                                window.execScript(scriptelements[i].innerHTML); //IE script execution for window session
                                                }
                                                //eval(scriptelements[i].innerHTML);
                                }
                }

	
}

function closePopup(divid){
	if (showEffects){
		new Effect.SlideUp(divid,{duration:1})
		setTimeout("document.body.removeChild(document.getElementById('"+divid+"'));",2001)
	} else
		document.body.removeChild(document.getElementById(divid));
		
	showElements();
}

function fixStretchMarks(yamum, divid){
	if(typeof(yamum)=='undefined')
		yamum='';

		
	if(document.getElementById('fadepurplebg'+yamum)){
		var pagesize = getPageSizeWithScroll();
		var windowsize = getWindowSize();
		
		if(pagesize[1]>document.body.offsetHeight)
			var divheight = pagesize[1];
		else if (windowsize[1] > document.body.offsetHeight)
			var divheight = windowsize[1];
		else
			var divheight = document.body.offsetHeight
		
		var popheight = 0;

		/*Its bad practice I know, but it IS possible for there to be more than one div
		  with the the ID containertext, however if there is it should have been created
		  without the create background flag, and thus this won't run. Anyway, this screws
		  up IE. So here's a bandaid. Dry your eyes.
		  
		  Also, I know that if this height is used (as it will in IE when the div is longer than
		  the existing page, the grey div will actually be extended past the bottom of the div by its
		  existing height. And you know what? The general consensus is that this is OK. So don't complain.
		*/
		var containers = document.getElementsByClassName('containertext');
		for (var x=0; x<containers.length; x++)
			if (containers[x].offsetHeight > popheight)
				popheight=containers[x].offsetHeight;

		if(popheight > divheight)
			divheight += popheight		//This is addition because the div doesn't sit at the top of the page and if we just added
										//then it would be too short because of the top-of-page-offset. I could fix this but the JS
										//overhead isn't worth it, and I can't be bothered.

		document.getElementById('fadepurplebg'+yamum).style.height = divheight+'px';
	}
}

function setAvatar(avid){
	var spans = document.getElementsByTagName('span');
	for (var x=0;x<spans.length;x++)
		if(spans[x].id.indexOf('avatar')>-1)
			if(spans[x].id=='avatar-'+avid)
				spans[x].className='avatar-on';
			else
				spans[x].className='avatar-off';
				
	document.getElementById('avatarval').value = avid;
}

function gup(name){
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

function hideElements(){
	if (navigator.appName == 'Microsoft Internet Explorer'){
		var p = document.getElementsByTagName('select');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "hidden";
		}
		
		p = document.getElementsByTagName('object');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "hidden";
			p[i].style.width = "0px";
		}
	} else {
		p = document.getElementsByTagName('embed');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "hidden";
			p[i].style.width = "0px";
		}
	}	
}

function showElements(){
	if (navigator.appName == 'Microsoft Internet Explorer'){
		var p = document.getElementsByTagName('select');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "visible";
		}
		
		p = document.getElementsByTagName('object');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "visible";
			p[i].style.width = "";
		}
	} else {
		p = document.getElementsByTagName('embed');
		for(i=0;i<p.length;i++) {
			p[i].style.visibility = "visible";
			p[i].style.width = "";
		}
	}
}

function hideFormElements(div){
	var tds = div.getElementsByTagName('select');
	for (var x=0; x<tds.length; x++)
		tds[x].style.visibility = 'hidden';
	
	var tds = div.getElementsByTagName('input');
	for (var x=0; x<tds.length; x++)
		tds[x].disabled = true;

	var tds = div.getElementsByTagName('textarea');
	for (var x=0; x<tds.length; x++)
		tds[x].disabled = true;

}

function showFormElements(div){
	var tds = div.getElementsByTagName('select');
	for (var x=0; x<tds.length; x++)
		tds[x].style.visibility = 'visible';
	
	var tds = div.getElementsByTagName('input');
	for (var x=0; x<tds.length; x++)
		tds[x].disabled = false;

	var tds = div.getElementsByTagName('textarea');
	for (var x=0; x<tds.length; x++)
		tds[x].disabled = false;
}

function createGraph(chartType,chartXML,chartDiv){
	 var chart = new FusionCharts('/FusionChart/Charts/'+chartType+'.swf', "ChartId", "570", "350");
	 chart.setDataURL(chartXML);		   
	 chart.render(chartDiv);

//	document.location.href=chartXML
}

function showQuestions(status){
	var query = 'APPNAME=EDUFlight&PRGNAME=PortalQuestionsAjax&ARGUMENTS=-N'+status
	ajaxPost('POST','', query)
}

function checkUpload(qstid) {
	var frmexists = document.getElementById('upfile').contentWindow.document.body.innerHTML.substr(1,5).search(/form/i) > -1;
	
	if (frmexists){
		var ifm = document.getElementById('upfile').contentWindow.document.form1;
		var stardedupl = ifm.submitted.value == 'yes' || startedUpload;
		var filetoup = ifm.filename.value != '';
	}
	
	if (!filetoup && frmexists) {
		document.form1.question.value = '';
		document.form1.subbut.disabled = false;
		showQuestions(document.getElementById('qstrange').value);
		document.getElementById('ok').style.display='block';
		document.getElementById('up').style.display='none';
		startedUpload = false;
	} else {
		if (!stardedupl && frmexists){
			ifm.filenumber.value = qstid;
			document.getElementById('ok').style.display='none';
			document.getElementById('up').style.display='block';
			upFile();
			startedUpload = true;
		}
	
		setTimeout('checkUpload('+qstid+')',500);
	}
}

function upFile(qstid){
	document.getElementById('upfile').contentWindow.document.form1.submit();
}

function showAnswer(qst){
	var query = 'APPNAME=EDUFlight&PRGNAME=PortalAnswer&ARGUMENTS=-N'+qst;
	ajaxPopUp('POST','',query)
}

function showCodedAnswer(qst){
	var query = 'APPNAME=EDUFlight&PRGNAME=QuestionCodedAnswer&ARGUMENTS=-N'+qst;
	ajaxPopUp('POST','',query);
}

function getQuestions(year, topic, own, page){
	if(typeof(page)=='undefined')
		page = '';
	document.getElementById('kbquestions').innerHTML='<p style="text-align:center"><img src="/images/ajax-loader-2.gif"><br>Loading Questions...</p>';
	var query = 'APPNAME=EDUFlight&PRGNAME=PortalKBQs&ARGUMENTS=-A'+year+',-A'+topic+',-A'+own+',-N'+page;
	ajaxPost('POST','',query)
}

function goPage(p){
	getQuestions(document.form1.year[document.form1.year.selectedIndex].value,document.form1.topic[document.form1.topic.selectedIndex].value, isOwn(), p);
}

function checkFileName(filename){
	var query = 'APPNAME=EDUFlight&PRGNAME=PortalCheckFilename&ARGUMENTS=-A'+filename;
	ajaxPost('POST','',query)
}

function validFileTypes(){
	var query = 'APPNAME=EDUFlight&PRGNAME=PortalValidFiles';
	ajaxPopUp('POST','',query)
}

function explainResult(r){
	var query = 'APPNAME=EDUFlight&PRGNAME=PortalExplainResult&ARGUMENTS=-A'+r;
	ajaxPopUp('POST','',query)
}

function explainCID(){
	ajaxPopUp('GET','/portal-compid.html','')
}

function explainOverdue(){
	ajaxPopUp('GET','/portal-overdue.html','')
}

function assignCIDName(cid){
	var query = 'APPNAME=EDUFlight&PRGNAME=PortalAssignScreen&ARGUMENTS=-A'+cid;
	ajaxPopUp('POST','',query)
}
function viewResDetails(f){
	var query = 'APPNAME=EDUFlight&PRGNAME=PortalResResult&ARGUMENTS=-A'+f;
	ajaxPopUp('POST','',query)
}

function viewMathsDictionaryTopic(id){
	var query = 'APPNAME=EDUFlight&PRGNAME=PortalDictTopic&ARGUMENTS=-N'+id;
	ajaxPopUp('POST','',query)
}

function updateDictionaryViews(){
	if (document.getElementById('dictrecent')){
		var query = 'APPNAME=EDUFlight&PRGNAME=PortalDictionaryViews';
		ajaxPost('POST','',query)
	}
}

function doDictSearch(){
	document.getElementById('dictsearchres').innerHTML='<div style="text-align:center;"><img src="/images/ajax-loader-2.gif" /><br>Searching...</div>';
	var query = 'APPNAME=EDUFlight&PRGNAME=PortalDictionarySearch&ARGUMENTS=-A'+document.getElementById('dictsearchterm').value;
	ajaxPost('POST','',query)
}

function openWindow(url,width,height){
	window.open(url ,"_blank","toolbar=0,scrollbars=0location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height);
}

function startChat(){
	var frm = document.frmnewchat;
		if(frm.fname.value == ''){
		alert ('You must enter your first name!');
		frm.fname.focus();
	} else {
		document.getElementById('startresponse').innerHTML = 'Loading...';
		ajaxPost('POST','',create_request_string(frm));
	}
}


function noSpaces(inputString) {
  var searchForSpaces = /\ /
  return searchForSpaces.test(inputString);
}

function repChar(conStr,inChar,outChar) {
  var conStr = conStr.split(inChar);
  conStr = conStr.join(outChar);
  return conStr.length;
}

function isValidEmail(str) {
   return (str.indexOf(".") <= 0 || str.indexOf("@") <= 0);
}

function isNotaNumber (inputString){
  return isNaN(inputString);
}

var g_a;
function showActions(e, a){
	doStaticTooltip(e,document.getElementById('actions-'+a).innerHTML, a);
	if(document.getElementById('butactions-'+a))
		document.getElementById('butactions-'+a).src = '/images/action-off-on.png';
		
	g_a = a;
}

function doStaticTooltip(e, msg, a) {
	hideStaticTip(true);
	Tooltip.followMouse = false;
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
//  var helpText = '<div style="width:246px"><div class="rego-small"><div align="center"><div id="registration-small"><img src="/hr-images/popupheadings/hrpanel-actions.png" height="65" width="156" alt="Actions" /><a href="#" onclick="hideActions(\''+a+'\'); return false;" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Image33\',\'\',\'/jl-images/register-head-close-black.png\',1)"><img src="/jl-images/register-head-close.png" alt="Close" name="Image33" width="90" height="65" border="0" id="Image33" /></a><div class="contentcontainer-small"><div class="containertext-small" id="containertext">'+msg+'</div></div><img src="/hr-images/containerfooter-small.png" height="25" width="246" alt="Jobs Live&trade;" /></div></div></div></div>';
	var helpText = '<div class="actions"><div class="actionscontent">'+msg+'</div></div>';
//	helpText = msg;
	Tooltip.show(e, helpText);
	fixPNG();
}

function hideStaticTip(instant) {
	Tooltip.followMouse = true;
	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
	if (instant)
		Tooltip.hide();
	else
		Tooltip.timerId = setTimeout("Tooltip.hide()", 100);
	if(document.getElementById('butactions-'+g_a))
		document.getElementById('butactions-'+g_a).src = '/images/action-off.png';
}

Tooltip.tipOutCheck = function(e) {
  e = dw_event.DOMit(e);
  // is element moused into contained by tooltip?
  var toEl = e.relatedTarget? e.relatedTarget: e.toElement;

  if (document.getElementById('tipDiv') != toEl && !contained(toEl, document.getElementById('tipDiv')))
  	Tooltip.hide();
}

// returns true of oNode is contained by oCont (container)
function contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}

Tooltip.unHookHover = function () {
    var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;
    if (tip) {
        tip.onmouseover = null; 
        tip.onmouseout = null;
        tip = null;
    }
}

function showLoginBox(blah){
	document.getElementById('navitems').style.display=blah?'none':'block';
	document.getElementById('navlogin').style.display=blah?'block':'none';
}

function showQuote(){
	ajaxPopUp('GET','/quote.html','');	
}

function getQuoteDetails(val){
	document.getElementById('quotedetails').innerHTML='<div style="text-align:center;"><img src="/images/ajax-loader.gif" width="66" height="66" alt="Loading..." /></div>'
	var query="APPNAME=Rental&PRGNAME=getquotedetails&ARGUMENTS=-A"+val
	ajaxPost('POST','',query);
}

	function chkQuoteForm(frmObj){
		if(frmObj.qname.value==''){
			alert ('Must enter your name');
			frmObj.qname.focus();
			return false;
		} else if(frmObj.qemail.value=='' && frmObj.qphone.value=='' && frmObj.qfax.value==''){
			alert ('Must enter either phone, fax, or email detals');
			frmObj.qphone.focus();
			return false;
		} else if(frmObj.qrentalcity.value==''){
			alert ('Must enter the city the rental will take place in');
			frmObj.qrentalcity.focus();
			return false;
		} else 
			return true;
	}


function showProduct(id){
	ajaxPopUp('POST','','APPNAME=Rental&PRGNAME=WebProductDetail&ARGUMENTS=-N'+id);
}
