addLoadEvent(processHreview);


var countDocument = 0;
var getFirstChar="";
var azArray= new Array();
var globalCheckFirstChar="";




function processHreview(){  

   tmp = document.getElementsByTagName('div');

 
   for (var i=0;i<tmp.length;i++)
   {			  
      if (tmp[i].className == "summary"){ 
         countDocument++;
      }
   }
   	
	writeSearchFilter(countDocument);
	
	     
}




 
function hideDiv(){
	 
   //document.getElementById("SD").className='showDesc1';
   //document.getElementById("HD").className='hideDesc1';


   tmp2 = document.getElementsByTagName('div');
 
   for (var x=0;x<tmp2.length;x++){
      if (tmp2[x].className == "description"){ 
         tmp2[x].style.display="none"; 
	}

      if (tmp2[x].className == "url"){ 
         tmp2[x].style.display="none";
	}  	
   }
                                                                                                                                                                                                                      	
	//getHeight4Hide();

}


function showDiv(){
	
   //document.getElementById("SD").className='showDesc';
   //document.getElementById("HD").className='hideDesc';

   tmp = document.getElementsByTagName('div');
 
   for (i=0;i<tmp.length;i++){	     
      if (tmp[i].className == "url"){ 
         tmp[i].style.display="block"; 
	}

      if (tmp[i].className == "description"){ 
         tmp[i].style.display="block";
	} 	
   }
						
	//getHeight4Hide();

} 



function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
} 
}


var selectViewString;
if (getQueryVariable("layout") == "show"){

addLoadEvent(getHeight);

selectViewString = "<span id=\"moveRight\"><a href=\"#\" onclick=\"redirectURL('show');\" class=\"showDesc\" id=\"SD\">Show details</a> ";
selectViewString += "| <a href=\"#\" onclick=\"redirectURL('hide');\" class=\"hideDesc\" id=\"HD\">Show headings only</a></span>";
}
else if (getQueryVariable("layout") == "hide"){

addLoadEvent(hideDiv);
addLoadEvent(getHeight);


selectViewString = "<span id=\"moveRight\"><a href=\"#\" onclick=\"redirectURL('show');\" class=\"showDesc1\" id=\"SD\">Show details</a> ";
selectViewString += "| <a href=\"#\" onclick=\"redirectURL('hide');\" class=\"hideDesc1\" id=\"HD\">Show headings only</a></span>";
}
else{
addLoadEvent(getHeight);
selectViewString = "<span id=\"moveRight\"><a href=\"javascript:showDiv();\" class=\"showDesc\" id=\"SD\">Show details</a> ";
selectViewString += "| <a href=\"javascript:hideDiv();\" class=\"hideDesc\" id=\"HD\">Show headings only</a></span>";
}



function showHideDetailsBuffer(){

   document.writeln(selectViewString);
}



function writeSearchFilter(countDocument)
{
	filterBuffer=new String();

	if (countDocument == 0){
	   filterBuffer += "<div class=\"clb\">Sorry, no catalogued documents were found within this category.</div>";
	   filterBuffer += "<br><br>Suggestions:";
	   filterBuffer += "<blockquote>- Make sure you navigated through the categories correctly.<br>- Try different categories.<br>- Try more general categories.<br>- Try catalogued search as provided above.<br>- Try the above navigation links.<br>- Try the advanced search below. </blockquote>";
	   filterBuffer += "<br>";
	   filterBuffer += "<blockquote>";
	   filterBuffer += "<b>Advanced Search</b>";
	   filterBuffer += "<form name=\"coveo_form\" action=\"http://dcssearchz1.nt.gov.au/CES4/ntg.aspx\">";
	   filterBuffer += "<INPUT type=\"hidden\" name=\"sk\" value=\"ntg\">";
	   filterBuffer += "<input size=25 name=\"q\" value=''>";
	   filterBuffer += " <input type=\"submit\" value=\"Search\">";
	   filterBuffer += "</form>";
	   filterBuffer += "</blockquote>";
	}
	else{
	   filterBuffer += "<form name=\"filterform\" method=\"post\" action=\"javascript:gotoFilterSearch();\">";
	   filterBuffer += countDocument + " document(s) found.";
	   filterBuffer += "Filter keyword(s) within result set: ";
	   filterBuffer += "  <input alt=\"FilterKeywordInput\" type=\"text\" name=\"filterfield\" />";
	   filterBuffer += "  <select name=num>";
	   filterBuffer += "    <option value=\"\" selected>- Default -";
	   filterBuffer += "    <option value=\"10\">10 results";
	   filterBuffer += "    <option value=\"20\">20 results";
	   filterBuffer += "    <option value=\"30\">30 results";
	   filterBuffer += "    <option value=\"50\">50 results";
	   filterBuffer += "    <option value=\"100\">100 results";
	   filterBuffer += "  </select>";
	   filterBuffer += "  <button onclick=\":javascript:gotoFilterSearch()\">Go</button>";
	   filterBuffer += "</form>";
	   filterBuffer += "<script>initialfocus();</script>";
	}

	document.getElementById("showFilter").innerHTML = filterBuffer;
}
 

function gotoFilterSearch()
{
	var currPathname=window.location.pathname;
	var arrayPath=currPathname.split("/");
	var documentRoot="dmzMetadata";
	if(arrayPath.length>2){
	var documentRoot=arrayPath[1];
	}

	var pathname=window.location.protocol+"//"+window.location.host+"/"+documentRoot;;

	myFormAction=pathname+"/Subject?" + window.location.search.substring(1) + "&filterfield=" + document.filterform.filterfield.value;
	

	window.location.href=myFormAction;
	
}

function redirectURL(viewClicked){

	//Basically the getHeight does not work properly when show and hide div using firefox. Therefore
	//for the time being we used redirect in order to get the height of the right side div.
	

	var currPathname=window.location.pathname;
	var arrayPath=currPathname.split("/");
	var documentRoot="ntg4";

	var pathname=window.location.protocol+"//"+window.location.host+"/"+documentRoot;;

	var queryStringPath;
	queryStringPath = window.location.search.substring(1);


	if (viewClicked == 'show'){
	   queryStringPath = queryStringPath.replace('hide', 'show');
	}
	else{
	   queryStringPath = queryStringPath.replace('show', 'hide');
	}

	myFormAction=pathname+"/Subject?" + queryStringPath;
	

	window.location.href=myFormAction;

}


