

//Validate the search string.
//If the string is empty do not submit the page.
function validateSearchString(searchText)
{	
	searchText = trim(searchText);
	
	if(searchText == '')
	{
		alert('Please enter one or more search words.');
		return false;
	}
	else
	{		
		return true;
	}
}


function Browseris () {
	var agt=navigator.userAgent.toLowerCase();
	this.osver=1.0;
	if (agt)
	{
		var stOSVer=agt.substring(agt.indexOf("windows ")+11);
		this.osver=parseFloat(stOSVer);
	}
	this.major=parseInt(navigator.appVersion);
	this.nav=((agt.indexOf('mozilla')!=-1)&&((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible')==-1)));
	this.nav6=this.nav && (this.major==5);
	this.nav6up=this.nav && (this.major >=5);
	this.nav7up=false;
	if (this.nav6up)
	{
		var navIdx=agt.indexOf("netscape/");
		if (navIdx >=0 )
			this.nav7up=parseInt(agt.substring(navIdx+9)) >=7;
	}
	this.ie=(agt.indexOf("msie")!=-1);
	this.aol=this.ie && agt.indexOf(" aol ")!=-1;
	if (this.ie)
		{
		var stIEVer=agt.substring(agt.indexOf("msie ")+5);
		this.iever=parseInt(stIEVer);
		this.verIEFull=parseFloat(stIEVer);
		}
	else
		this.iever=0;
	this.ie4up=this.ie && (this.major >=4);
	this.ie5up=this.ie && (this.iever >=5);
	this.ie55up=this.ie && (this.verIEFull >=5.5);
	this.ie6up=this.ie && (this.iever >=6);
	this.winnt=((agt.indexOf("winnt")!=-1)||(agt.indexOf("windows nt")!=-1));
	this.win32=((this.major >=4) && (navigator.platform=="Win32")) ||
		(agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1);
	this.mac=(agt.indexOf("mac")!=-1);
	this.w3c=this.nav6up;
	this.safari=(agt.indexOf("safari")!=-1);
	this.safari125up=false;
	if (this.safari && this.major >=5)
	{
		var navIdx=agt.indexOf("safari/");
		if (navIdx >=0)
			this.safari125up=parseInt(agt.substring(navIdx+7)) >=125;
	}
}
var browseris=new Browseris();
var bis=browseris;

function wcaSearchKeyDown(event, strUrl, controlID, buttonClick)
{
    if (wcaIsKeyDownSubmit(event) || buttonClick == true)
	{

	    GoSearch(null, controlID, null, true, false, null, null, null, null, strUrl, 'This Site', 'This List', 'This Folder', 'Related Sites', '\u002f_layouts\u002fOSSSearchResults.aspx');
	    return false;
	}
	return true;
}



function wcaIsKeyDownSubmit(event)
{
	if (event !=null)
	{
		var charCode;
		var bKeyModifiers;
		if (browseris.ie)
		{
			charCode=event.keyCode;
			bKeyModifiers=event.altKey || event.ctrlKey;
		}
		else
		{
			charCode=event.which;
			bKeyModifiers=event.modifers &
			(event.ALT_MASK | event.CONTROL_MASK);
		}
		if ((charCode==13) && !bKeyModifiers)
			return true;
	}
	return false;
}




function setRootCSS(item)
	   	{

	   		var _returnedItem;
	   		if(item.get_level() == 0)
	   		{
	   			_returnedItem = item.get_element();
	   			_returnedItem.className = _returnedItem.className + " wcSelected";
	   		}
	   		else
	   		{
	   			_returnedItem = getRootLevel(item.get_parent());
	   		}
			return;
		}
	
		function findItem(items)
	   	{

	   		var url = location.href.replace("http://","");
	   		var url = url.substring(url.indexOf('/'));
			for (var i=0; i < items.get_count(); i++)
			{
				if(items.getItem(i).get_navigateUrl() == url )

				{




					 return items.getItem(i);
				}
			}
			return;
		}


	   function onPanelBarLoad(panelBar, args)
	   {
		 
  {

		  var panelItem = panelBar.get_expandedItem();
		  if(panelItem)
		  {
		  		setRootCSS(panelItem);
		   }
		  else
		  {
		  		var panelItems = panelBar.get_items();
		   		if(panelItems.get_count() > 0)
		   		{
		   			panelItem = findItem(panelItems);
		   			if(panelItem)
					{
					  	setRootCSS(panelItem);
					 }
				} 
		  }
	   }


	   }

		function ExpandItem(panelbar, args)
       	{   
			if(args.get_item().get_items.Count != 0 && args.get_item().get_expanded() == false)   
			{   
			 args.get_item().set_expanded(true);   
			}   
			else   
			{   
			  args.get_item().set_expanded(false);   
			}   
       	}

var min=70;
var max=140;


function IncreaseFont(){
var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));	 
	 s = parseInt(p[i].style.fontSize.replace("%",""));
      } else {
         var s = 100;
      }
      if(s!=max) {
         s += 10;
      }
      p[i].style.fontSize = s+"%";
      setCookie("userFontSize", s);
   }
     
     if (typeof resizeUL == 'function') 
     {
         resizeUL();
     }
  
  
  
}

function DecreaseFont(){
   var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
	 s = parseInt(p[i].style.fontSize.replace("%",""));
      } else {
         var s = 100;
      }
      if(s!=min) {
         s -= 10;
      }
      p[i].style.fontSize = s+"%"
      setCookie("userFontSize", s);	
   }
   if (typeof resizeUL == 'function') {
       resizeUL();
   }
}


function setUserFontSize(ufs){
   var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      p[i].style.fontSize = ufs+"%";
   }
   if (typeof resizeUL == 'function') {
       resizeUL();
   }
}


function createCookie(){
	var now = new Date();
	var userFontSize = getCookie("userFontSize");
	if (!userFontSize) {
		userFontSize = setCookie("userFontSize", 100, 2);		
	}else{
  		setUserFontSize(userFontSize);
	}
	EmailPage();
}


function setCookie(name, value) {
  var curCookie = name + "=" + value;
  document.cookie = curCookie;
}


function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0){
			return null;
		}
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1){
		end = dc.length;
	}

	return unescape(dc.substring(begin + prefix.length, end));
}

/*function PrintPage(){
    var OLECMDID = 7;
	if (navigator.appName == "Microsoft Internet Explorer"){
		var PROMPT = 1;
	    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	    document.body.insertAdjacentHTML('beforeEnd', WebBrowser); 
	    WebBrowser1.ExecWB(OLECMDID, PROMPT);
	    WebBrowser1.outerHTML = "";
	}else{
		window.print();
	}
}*/
function PrintPage(){   
    str=document.getElementById("PrintZone").innerHTML;
    strHeader = document.getElementById("PrintZone_header").innerHTML;
    strFooter = document.getElementById("PrintZone_footer").innerHTML;
    newwin=window.open('','printwin','left=100,top=100,scrollbars=yes,width=820,height=600');
    newwin.document.open();
    newwin.document.write('<html><head><title>WorkCover NSW - Print Page</title>\n');
    newwin.document.write('<link type="text/css" rel="stylesheet" href="/_layouts/styles/wcastyles/wcaprint.css" />\n');
    newwin.document.write('</head>\n');
    newwin.document.write('<body>\n');
    newwin.document.write('<table width="100%" cellpadding="5"><tr><td>\n');
    newwin.document.write(strHeader);
    newwin.document.write(str);
    newwin.document.write(strFooter);
    newwin.document.write('</td></tr></table>');
    newwin.document.write('</body></html>');
    newwin.document.close();
    newwin.print();
}
function EmailPage(){
	var SubjectLine=top.document.title; 
    var BodyText= top.location.href;
    var Message = '<A HREF="mailto:?SUBJECT=' + escape(SubjectLine) + '&BODY=' + escape(BodyText) + '"><img src="/_layouts/Images/wcaImages/iconEmail.gif" alt="Email this page" /><span>Email</span><\/A>';
    var MessageIE = '<A HREF="mailto:?SUBJECT=' + (SubjectLine) + '&BODY=' + (BodyText) + '"><img src="/_layouts/Images/wcaImages/iconEmail.gif" alt="Email this page" /><span>Email</span><\/A>';
    if(document.all){
        document.getElementById("EmailDiv").innerHTML = MessageIE; 
    }else{ 
        document.getElementById("EmailDiv").innerHTML = Message; 
    }
}

sFocus = function(sfEls) {
    for (var i = 0; i < sfEls.length; i++) {
        sfEls[i].onfocus = function() {
            this.className += " sfocus";
        }
        sfEls[i].onblur = function() {
            this.className = this.className.replace(new RegExp(" sfocus\\b"), "");
        }
    }
}
function setFocus(type, tag, parentId) {
    if (window.attachEvent) {
        window.attachEvent("onload", function() {
            var sfEls = (parentId == null) ? document.getElementsByTagName(tag) : document.getElementById(parentId).getElementsByTagName(tag);
            type(sfEls);
        });
    }
}

/**************Premium Estimator functions *****************/
function checkJS(fldId)
{
    document.getElementById(fldId).value="enabled";
}

function wicSearchKeyDown(event, strUrl, controlID, buttonClick, js, msg, searchEntryKeywordValidator)  
{
    if(wcaIsKeyDownSubmit(event) || buttonClick == true)
	{
	    if (document.getElementById(msg)) {document.getElementById(msg).style.display='none';}
    	if (document.getElementById(searchEntryKeywordValidator)) {document.getElementById(searchEntryKeywordValidator).style.display='none';}
	    //if (document.getElementById(searchEntryErrorMessage)) {document.getElementById(searchEntryErrorMessage).style.display='none';}
	
	    var k = document.forms[0].elements[controlID].value;
        k = k.replace( /\s*$/, '' );
       
       if(k == '')
       {     
           document.getElementById(msg).style.display='block'; 
           alert("Please enter a business activity or WorkCover Industry Classification Code before clicking on Search");          
           return false;
       }      
       else
       {
           document.getElementById(msg).style.display='none';
	       document.forms[0].submit();
	   }
	    
	    //wicGoSearch(null, controlID, null, true, false, null, null, null, null, strUrl, 'This Site', 'This List', 'This Folder', 'Related Sites', '\u002f_layouts\u002fOSSSearchResults.aspx',js,msg);
	    return false;
	}
	return true;
}

function wicGoSearch(PmtId, TbId, HdQId, bApQ, bSc, DDId, HdSId, HdLId, HdFId, Url, thisSite, thisList, thisFolder, relatedSites, csUrl,js,msg)
{

    try 
    {
    AddSearchoptionsToQuery();
    }
    catch(e) {}
    var k = document.forms[0].elements[TbId].value;
    k = k.replace( /\s*$/, '' );
    var ui = '1';
    if (PmtId){
        ui = document.forms[0].elements[PmtId].Value;
    }                                                   
    if(k == '' || ui == '0'){
       
       document.getElementById(msg).style.display='block';
       alert("Please enter a business activity or WorkCover Industry Classification Code before clicking on Search");
        if(null != event){
            event.returnValue = false;
            return false;
        }
        else return;
    }                               
    var sch = '?k=' + encodeURIComponent(k);

    if(null != HdQId){
        var sa = document.forms[0].elements[HdQId].value;     
        if (bApQ)
            sch += canonicalizedUtf8FromUnicode(" "+sa);
        else
            sch += '&a='+canonicalizedUtf8FromUnicode(" "+sa);              
    }
    if(bSc){
        var s='', cs='', u='', selVal='';
        var d = document.forms[0].elements[DDId];
        var fIsCS = false;
        s = d.options[d.selectedIndex].text;
        selVal = d.options[d.selectedIndex].value;
        if (selVal==thisSite){
            cs =selVal; s='';
            u=document.forms[0].elements[HdSId].value;
            fIsCS = true;            
        }
        if (selVal==thisList){
            cs =selVal; s='';
            u=document.forms[0].elements[HdLId].value; 
            fIsCS = true;         
        }
        if (selVal==thisFolder){
            cs =s; s='';
            u=document.forms[0].elements[HdFId].value;   
            fIsCS = true;        
        }
        if (s == relatedSites) {
            s = d.options[d.selectedIndex].value;
            fIsCS = true;
        }
        if(fIsCS)
        {
            Url = csUrl;
        }
        if (s != ''){                               
            sch += "&s=" + encodeURIComponent(s);
            if (d.options[d.selectedIndex].value != '' && !fIsCS) {
                Url = d.options[d.selectedIndex].value;
            }        
        }
        if (cs != ''){          
            sch += "&cs=" + encodeURIComponent(cs);
        }
        if (u != ''){
            sch += '&u=' + encodeURIComponent(u);
        }                                
    }
    sch +="&s=wic";
    sch +="&js=" + js;
  
    var F=document.forms[0];

    try {external.AutoCompleteSaveForm(F);} catch (err) {}

    window.location = Url + sch;

    try {if(null    != event) event.returnValue = false;} catch (err) {}
    return; 
}

function isSearchResultSelected(elem1, elem2)
{
    var elem1 = document.forms[0].elements[elem1];
    var elem2 = document.getElementById(elem2);
    
    // set var radio_choice to false
    var radio_choice = false;

    if (elem1 == null) // if search returns nothing

    {
        radio_choice = false;
    }
    else if (elem1.length == null) // if search returns only 1 result
    {
        if (elem1.checked) { radio_choice = true; }
    }
    else if (elem1.length > 0) // if search returns more than 1 result
    {
        // Loop from zero to the one minus the number of radio button selections
        for (counter = 0; counter < elem1.length; counter++)
        {
            // If a radio button has been selected it will return true
            // (If not it will return false)
            if (elem1[counter].checked)
            {
                radio_choice = true; 
                break;
            } 
        } 
    }
    
    if (!radio_choice)
    {
        elem2.style.display = "block";
        alert("Please select a WIC before clicking next");
    }
     
    return radio_choice;
}
function IsEmployeeApprenticeChanged(elem1, elem2, elem3)
{
    var elem1 = document.getElementById(elem1);
    
    var sel = elem1.options[elem1.selectedIndex].value;
    if(sel=='Yes')
    {
        document.getElementById(elem2).style.display='block';
       
        
    }
    else{ 
    document.getElementById(elem2).style.display='none';    
    
    }
 }
/**************End Premium Estimator functions *************/
setFocus(sFocus, "INPUT");
setFocus(sFocus, "TEXTAREA");


