/*************************************
 * Common 
 *************************************/

/*************************************
 * Robohelp Links
 *************************************/
var helpLinks = {
	"simpleSearch": "index.html#simple_search.htm",
	"advancedSearch": "index.html#advanced_search.htm",
	"citationSearch": "index.html#retrieve_by_citation.htm",
	"aboutGovtPubs": "index.html#about_government_publications.htm",
	"FR": "index.html#about_federal_register.htm",
	"BILLS": "index.html#about_congressional_bills.htm",
	"BUDGET": "index.html#about_budget_of_the_united_states_government.htm",
	"CDOC": "index.html#about_congressional_documents.htm",
	"CHRG": "index.html#about_congressional_hearings.htm",
	"CREC": "index.html#about_congressional_record.htm",
	"CRPT": "index.html#about_congressional_reports.htm",
	"CPD": "index.html#about_compilation_of_presidential_documents.htm",
	"PLAW": "index.html#about_public_and_private_laws.htm",
	"CRI": "index.html#about_congressional_record_index.htm",
	"ECONI": "index.html#about_economic_indicators.htm",
	"LSA": "index.html#about_list_of_cfr_sections_affected.htm",
	"HOB": "index.html#about_history_of_bills.htm",
	"CPRT": "index.html#about_congressional_committee_prints.htm",
	"CCAL": "index.html#about_congressional_calendars.htm",
	"CFRPARTS": "index.html#about_cfr_parts_affected_from_the_federal_register.htm",
	"GOVMAN": "index.html#about_united_states_government_manual.htm",
	"GAOREPORTS": "index.html#about_gao_reports_and_comptroller_general_decisions.htm",
	"CRECB": "index.html#about_congressional_record_bound_edition.htm",
	"ERP": "index.html#about_economic_report_of_the_president.htm",
	"CDIR": "index.html#about_congressional_directory.htm",
	"STATUTE": "index.html#about_united_states_statutes_at_large.htm"
}

/*************************************
 * Web Trends Variables
 *************************************/
var COLLECTION_TYPE_SINGLE   = "Single Collection";
var COLLECTION_TYPE_MULTIPLE = "Multiple Collection";
var SEARCH_TYPE_BASIC        = "Basic Search";
var SEARCH_TYPE_ADVANCED     = "Advanced Search";
var SEARCH_TYPE_CITATION     = "Citation Search";

var COLLECTION_CODE_ALL="All Collection";

var ACTION_SEARCH    = "Search";
var ACTION_RETRIEVAL = "Retrieval";

var FILE_TYPE_TEXT     = "Text";
var FILE_TYPE_PDF      ="PDF";
var FILE_TYPE_ZIP      ="Zip";
var FILE_TYPE_METADATA ="Metadata";
var FILE_TYPE_HTML ="Html";
var FILE_TYPE_XML ="XML";
var FILE_TYPE_XLS ="XLS";

var RETRIEVAL_TYPE_SEARCH_RESULTS  = "Search Results";
var RETRIEVAL_TYPE_CONTENT_DETAIL  = "Content Details";
var RETRIEVAL_TYPE_CITATION        = "Citation";
var RETRIEVAL_TYPE_BROWSE          = "Browse Collections";


/*************************************
 * Basic Search 
 *************************************/
 
 function setFocusTextField(){
	 if (document.getElementById('basic-search-box')!=null) {
	 	document.getElementById('basic-search-box').focus();
 	}	 	
 }
 
 function resetForm(){
	try 
	{
		resetResultForm();
	}
	catch(e)
	{
		//alert("resetResultForm function not found");
	}
 }
 
function validateSimpleSearch(frm) 
{	
	var queryString = frm.st.value.trim();
	//if (queryString.length == 0)
	//{
		//document.getElementById('show-basic-search-error').style.visibility="visible";
		//frm.st.value = "";
		//frm.st.focus();
 //	}
	//else
	//{
		if (frm.id == "resultForm")
		{
			try 
			{
				resetResultForm();
			}
			catch(e)
			{
				//alert("resetResultForm function not found");
			}
		}
		//capture web trends parameters	   	 
/*		 var userParamsArray=new Array();
		 
		 var typeOfSearch= new Object();
	 	 typeOfSearch.name="typeOfSearch";
	 	 typeOfSearch.value="Basic Search";
	 	 
	 	 var typeofCollection= new Object();
	 	 typeofCollection.name="typeofCollection";
	 	 typeofCollection.value="Multi Collection";
	 	 
	 	 var collectionCode= new Object();
	 	 collectionCode.name="collectionCode";
	 	 collectionCode.value="All Collection";
	 	 
		 userParamsArray[0]=typeOfSearch;
		 userParamsArray[1]=typeofCollection;
		 userParamsArray[2]=collectionCode;
		 //invoke webtrends script
 		 logSearchStats(userParamsArray);*/
 		 //for basic search,its across all collections and multipel collections
		 var typeOfSearch=SEARCH_TYPE_BASIC;
		 var typeofCollection=COLLECTION_TYPE_MULTIPLE;
	     var collectionCode=COLLECTION_CODE_ALL;
			     
 		 logSearchStats(typeOfSearch,typeofCollection,collectionCode,frm.action,"Search Results");
		 frm.submit();
	//}
}
 
/*************************************
 * Advanced Search 
 *************************************/
 	 
	  //Form ID referenced in the java scripts.	
	  var ADVANCED_SEARCH_FORM_ID="searchpage";
	  
	  //available and selected publication IDs
	  var AVAILABLE_PUBLICATIONS_ID="searchpage_newAvailableList";
	  var SELECTED_PUBLICATIONS_ID="searchpage_newSelectedList";
	  
	  
	  var PREFIX_SEARCH_METADATA="idSearchInMetadata";
	  
     /**
	  	Java Script Constant Variables for publication dates
	  **/
	  var ID_PUBLICATION_DATE="idPublicationDate";
	  var PUBLICATION_DATE_ALL_DATES="All Dates";
	  var PUBLICATION_DATE_DATES_BETWEEN="Date is between";
	  var PUBLICATION_DATE_IS="Date is";
	  var PUBLICATION_DATE_AFTER="Date is after";
	  var PUBLICATION_DATE_BEFORE="Date is before";  
	  
	  //max number of allowed search criteria	
	  var MAX_SEARCH_CRITERIA=6;
	  
	  
	//------------------START JAVA SCRIPT ADD/REMOVE PUBLICATIONS----------------------------------
	 
	 /*
	 Following methods are used for moving collections from available to selected collections list.
	 
	 */
	 function addOption(theSel, theText, theValue){
	  var newOpt = new Option(theText, theValue);
	  var selLength = theSel.length;
	  theSel.options[selLength] = newOpt;
	 }
	
	 function deleteOption(theSel, theIndex){ 
	  var selLength = theSel.length;
	  if(selLength>0)
	  {
	    theSel.options[theIndex] = null;
	  }
	 }
	
	 function moveOptions(theSelFrom, theSelTo){
	  var selLength = theSelFrom.length;
	  var selectedText = new Array();
	  var selectedValues = new Array();
	  var selectedCount = 0;
	  
	  var i;
	  
	  // Find the selected Options in reverse order
	  // and delete them from the 'from' Select.
	  for(i=selLength-1; i>=0; i--)
	  {
	    if(theSelFrom.options[i].selected)
	    {
	      selectedText[selectedCount] = theSelFrom.options[i].text;
	      selectedValues[selectedCount] = theSelFrom.options[i].value;
	      deleteOption(theSelFrom, i);
	      selectedCount++;
	    }
	  }
	  
	  // Add the selected text/values in reverse order.
	  // This will add the Options to the 'to' Select
	  // in the same order as they were in the 'from' Select.
	  for(i=selectedCount-1; i>=0; i--)
	  {
	    addOption(theSelTo, selectedText[i], selectedValues[i]);
	  }
	  
	  //sort only if necessary
	  if (selectedCount > 0) {
			selectNone(theSelTo, theSelFrom);
			selectSort(theSelTo);  	
	  }
  
}

	function selectNone(list1,list2){
	    list1.selectedIndex = -1;
	    list2.selectedIndex = -1;
	}
	function getSize(list){
	    var len = list.childNodes.length;
	    var nsLen = 0;
	    for(i=0; i<len; i++) {
	        if(list.childNodes.item(i).nodeType==1)
	            nsLen++;
	    }
	    if(nsLen<2)
	        return 2;
	    else
	        return nsLen;
	}
	 // -------------------------------------------------------------------
	//   Pass this function a SELECT object and the options will be sorted
	//   by their text (display) values (sort uses lower case values of elements)
	// -------------------------------------------------------------------
	function selectSort(obj) {
		if (!obj) { return; }
		if (!selectHasOptions(obj)) { return; }
		var o = new Array();
		for (var i=0; i<obj.options.length; i++) {
			o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
			}
		
		if (o.length==0) { return; }
		o = o.sort( 
			function(a,b) { 
				if ((a.text.toLowerCase()+"") < (b.text.toLowerCase()+"")) { return -1; }
				if ((a.text.toLowerCase()+"") > (b.text.toLowerCase()+"")) { return 1; }
				return 0;
				} 
			);
	
		for (var i=0; i<o.length; i++) {
			obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}

	// -------------------------------------------------------------------
	//  Utility function to determine if a select object has an options array
	// -------------------------------------------------------------------
	function selectHasOptions(obj) {
		if ((!obj || obj!=null) && (!obj.options || obj.options!=null)) {
			return true;
		}
		return false;
	}
	//------------------END JAVA SCRIPT ADD/REMOVE PUBLICATIONS----------------------------------
	
	
	//-------------------------------------------------------------------------------------------
	//
	//					JAVA SCRIPT METHODS FOR EVERY ACTION ON THE SCREEN.
	//
	//-------------------------------------------------------------------------------------------

	 /**
	 function to handle when publication date changes. based on criteria,make dates visible and invisible.
	 */
	  function onChangePublicationDate(){
		 setSelectedCollections();
	     document.getElementById('dispatch').value ="dateChange";
		 document.getElementById(ADVANCED_SEARCH_FORM_ID).submit();
	  }
	 
	 /**
	 	function to handle add collections to selected collected from available collections.
	 */
	 
	 function handleAddCollections(){
		
		 moveOptions(document.getElementById(AVAILABLE_PUBLICATIONS_ID),document.getElementById(SELECTED_PUBLICATIONS_ID));
	 	 setSelectedCollections();	
	 	 document.getElementById('dispatch').value ="advancedsearch";
		 document.getElementById(ADVANCED_SEARCH_FORM_ID).submit();
	 }
	 
	  /**
	 	function to handle remove collections from selected collections to available collections.
	 */
	 function handleRemoveCollections(){
	 	moveOptions(document.getElementById(SELECTED_PUBLICATIONS_ID),document.getElementById(AVAILABLE_PUBLICATIONS_ID));
	 	setSelectedCollections();	
	 	document.getElementById('dispatch').value ="advancedsearch";
		document.getElementById(ADVANCED_SEARCH_FORM_ID).submit();
	 }
	 
	
	/**
	  Method called when add search criteria called on front end.	
	*/	
	
	 function onAddSearchCriteria(){
	 	 var totalFields = document.getElementById('searchpage_totalMetadataFields').value;
	 	 if(totalFields == MAX_SEARCH_CRITERIA){
	 		 return ;
	 	 }; 	
		 setSelectedCollections();
		 document.getElementById('dispatch').value ="addSearchCriteria";
		 document.getElementById(ADVANCED_SEARCH_FORM_ID).submit();
	  }
	
	
	  function onMetadataFieldChange(){
		 setSelectedCollections();
		 document.getElementById('dispatch').value ="advancedsearch";
		 document.getElementById(ADVANCED_SEARCH_FORM_ID).submit();
		 
	 	}
	  
	  function getSelectedCollectionLength(){
		return  document.getElementById(ADVANCED_SEARCH_FORM_ID).searchpage_newSelectedList.length;
	  }
	  
	  function setSelectedCollections(){
	  	 var totalLength=getSelectedCollectionLength();
		 for (var i = 0; i < totalLength; i++) {
				document.getElementById(ADVANCED_SEARCH_FORM_ID).searchpage_newSelectedList.options[i].selected = true;			
		 }
		 totalLength=document.getElementById(ADVANCED_SEARCH_FORM_ID).searchpage_newAvailableList.length;
		 for (var i = 0; i < totalLength; i++) {
				document.getElementById(ADVANCED_SEARCH_FORM_ID).searchpage_newAvailableList.options[i].selected = true;			
		 }
	  }
  
	  function doReset(){
		 document.getElementById('dispatch').value ="reset";
		 document.getElementById(ADVANCED_SEARCH_FORM_ID).submit();
			
	   }
	   
	  function doSearch(){

	   	 //to change the action from the form to advsearch  
	     var pathname = location.pathname;
	     var newPath = pathname.replace('advsearchpage','advsearch'); 
	   	 setSelectedCollections();
	   	 document.getElementById('dispatch').value ="advsearch";
	   	 document.getElementById(ADVANCED_SEARCH_FORM_ID).action= newPath;
	   	 
			//capture web trends parameters
		 var typeOfSearch = SEARCH_TYPE_ADVANCED; 
		 var typeofCollection = "";
		 var collectionCode="";
		 var length=getSelectedCollectionLength();
		 for (var i = 0; i < length; i++) {
				collectionCode += document.getElementById(ADVANCED_SEARCH_FORM_ID).searchpage_newSelectedList.options[i].value+",";			
		 }
		 collectionCode = collectionCode.substr(0,collectionCode.length - 1);
		 if(length >1){
		 	 typeofCollection=COLLECTION_TYPE_MULTIPLE;
		 }else{
		 	 if(collectionCode ==''){
 	 		 	typeofCollection=COLLECTION_TYPE_MULTIPLE;
		 	 }else{
			 	typeofCollection=COLLECTION_TYPE_SINGLE;
			 }
		 }

		 //capture web trends parameters	   	 
		 /*var userParamsArray=new Array();
		 var typeOfSearch= new Object();
	 	 typeOfSearch.name="typeOfSearch";
	 	 typeOfSearch.value="Advanced Search";
	 	 var typeofCollection= new Object();
	 	 typeofCollection.name="typeofCollection";
	 	 typeofCollection.value=collectionType;
	 	 var collectionCode= new Object();
	 	 collectionCode.name="collectionCode";
	 	 collectionCode.value=collectionCd;
	 	 
		 userParamsArray[0]=typeOfSearch;
		 userParamsArray[1]=typeofCollection;
		 userParamsArray[2]=collectionCode;
		 //invoke webtrends script
 		 logSearchStats(userParamsArray);*/
 		 logSearchStats(typeOfSearch,typeofCollection,collectionCode,newPath,"Search Results");
	   	 document.getElementById(ADVANCED_SEARCH_FORM_ID).submit();
	  }
	  
	  
 /*************************************
 * Search Results
 *************************************/
 
var SEARCH_FORM_ID="resultForm";
var NAVIGATOR="na";  
var NAVIGATOR_SELECTION="se";  
var FILTER_SELECTION="flr";  
var SEE_MORE="sm";  
var SORT_BY="sb";  
var PAGE_SIZE="ps";  
var CHECK_BOX_ID="cb";  
var CB_DEFAULT="false";  
var PAGE_SIZE_HIDDEN="psh";  
var SORT_BY_HIDDEN="sbh";  
var DEFAULT_PAGE_SIZE="10";  
var DEFAULT_SORT_BY="re";  
var SPLIT_SEPERATOR="_";
var ORIGINAL_SEARCH="originalSearch";

var COLLECDEPENT="true";
var COLLNOTDEPENT="false";
var ACCODENAV="accodenav";
var TIMEFRAME="timeFrame";

function replaceAll(text, strA, strB) 
{
    while ( text.indexOf(strA) != -1)
    {
        text = text.replace(strA,strB);
    }
    return text;
}

function chkfilter(obj){
		var splitNa = document.getElementById(NAVIGATOR).value.split(SPLIT_SEPERATOR);
	   	var splitSe = document.getElementById(NAVIGATOR_SELECTION).value.split(SPLIT_SEPERATOR);
   	
   		var resultNa =SPLIT_SEPERATOR;
	   	var resultSe =SPLIT_SEPERATOR;
	   	var newSelectSE=SPLIT_SEPERATOR;
	   	var newSelectNA=SPLIT_SEPERATOR;
	   	
   		var navIndex=0;
   		var  hasaccode=false;
		
		for(i = 0; i < splitSe.length; i++){
			//var objectid =  obj.id.replace('\\','');
			var objectid =  replaceAll(obj.id,'\\','');
   			if(splitSe[i]== objectid){
   				navIndex=i;
   			}
		}
  
		for(i = 0; i < splitNa.length; i++){
   			if(i==navIndex){
   				if(splitNa[i].indexOf(ACCODENAV) != -1){
   					hasaccode=true;
   				}
			}
		}

		if(hasaccode){
			//logic for the removiomg coll specific navs

			for(i = 0; i < splitSe.length; i++){
				//var objectid =  obj.id.replace('\\','');
				var objectid =  replaceAll(obj.id,'\\','');
				if(splitSe[i]!=objectid){
   					if(splitSe[i].length >1){
    					resultSe = resultSe + splitSe[i]+SPLIT_SEPERATOR; 
    				}
				}else{
					navIndex=i;
				}
   			}
   		
			for(i = 0; i < splitNa.length; i++){
   				if(i!=navIndex){
   					if(splitNa[i].length >1){
   						resultNa = resultNa + splitNa[i]+SPLIT_SEPERATOR; 
   					}
				}
			}
			
			var splitNaNew = resultNa.split(SPLIT_SEPERATOR);
	   		var splitSeNew = resultSe.split(SPLIT_SEPERATOR);
   			
   					
			for(i = 0; i < splitSeNew.length; i++){ //iterater for new selection array
				if(splitSeNew[i].indexOf(COLLECDEPENT) == -1){ //if not true then add to the selected
					if(splitSeNew[i].length >1){
						newSelectSE = newSelectSE + splitSeNew[i]+SPLIT_SEPERATOR; 
    					newSelectNA = newSelectNA + splitNaNew[i]+SPLIT_SEPERATOR; 
    				}
    			}
			}
			resultNa = newSelectNA;
			resultSe = newSelectSE;
					
		}else{
			//for normal navs whn collection is not selected
			for(i = 0; i < splitSe.length; i++){
				//var objectid =  obj.id.replace('\\','');
				var objectid =  replaceAll(obj.id,'\\','');
   				if(splitSe[i]!=objectid){
   					if(splitSe[i].length >1){
    					resultSe = resultSe + splitSe[i]+SPLIT_SEPERATOR; 
    				}
				}else{
					navIndex=i;
				}
   			}
   	
			for(i = 0; i < splitNa.length; i++){
   				if(i!=navIndex){
   					if(splitNa[i].length >1){
   						resultNa = resultNa + splitNa[i]+SPLIT_SEPERATOR; 
   					}
				}
			}
		}
		
				
		if(navIndex==0){
			document.getElementById('ercode').value = "1001";
		}
		
	  	document.getElementById(NAVIGATOR).value = resultNa;
		document.getElementById(NAVIGATOR_SELECTION).value = resultSe;
		document.getElementById(FILTER_SELECTION).value = obj.id;	
		document.getElementById(SEARCH_FORM_ID).submit();
}

function chkfilter1(obj){
    var splitNa = document.getElementById(NAVIGATOR).value.split(SPLIT_SEPERATOR);
   	var splitSe = document.getElementById(NAVIGATOR_SELECTION).value.split(SPLIT_SEPERATOR);
   	var resultNa =SPLIT_SEPERATOR;
   	var resultSe =SPLIT_SEPERATOR;
   	var navIndex=0;
	for(i = 0; i < splitSe.length; i++){
   	if(splitSe[i]!=obj.id){
   			if(splitSe[i].length >1){
    			resultSe = resultSe + splitSe[i]+SPLIT_SEPERATOR; 
    		}
		}else{
			navIndex=i;
		}
   	}
   	
	for(i = 0; i < splitNa.length; i++){
   		if(i!=navIndex){
   			if(splitNa[i].length >1){
   				resultNa = resultNa + splitNa[i]+SPLIT_SEPERATOR; 
   			}
		}
	}

    document.getElementById(NAVIGATOR).value = resultNa;
	document.getElementById(NAVIGATOR_SELECTION).value = resultSe;
	
   	document.getElementById(FILTER_SELECTION).value = obj.id;	
	document.getElementById(SEARCH_FORM_ID).submit();
}

function filterBuckets(na2,se2){
	document.getElementById(SEE_MORE).value = "";
	document.getElementById(FILTER_SELECTION).value = "";
		 
	var nav = document.getElementById(NAVIGATOR).value;
	nav = nav +SPLIT_SEPERATOR+na2;
	var sel = document.getElementById(NAVIGATOR_SELECTION).value;
	sel = sel +SPLIT_SEPERATOR+se2;
	document.getElementById(NAVIGATOR).value = nav;
	document.getElementById(NAVIGATOR_SELECTION).value = sel;
	document.getElementById(SEARCH_FORM_ID).submit();
}

function show(na){
	document.getElementById(FILTER_SELECTION).value = "";
	document.getElementById(SEE_MORE).value = na;
	document.getElementById(SEARCH_FORM_ID).submit();
}

function showless(na){
	document.getElementById(FILTER_SELECTION).value = "";
	document.getElementById(SEE_MORE).value = "";
	document.getElementById(SEARCH_FORM_ID).submit();
}

function resetResultForm(){
	var cbValue =	document.getElementById(CHECK_BOX_ID).checked;
    if(cbValue){
     	return ;
	}
	document.getElementById(ORIGINAL_SEARCH).value = "";
	document.getElementById(NAVIGATOR).value = "";
	document.getElementById(NAVIGATOR_SELECTION).value = "";
	document.getElementById(SEE_MORE).value = "";
	document.getElementById(FILTER_SELECTION).value = "";
	document.getElementById("dateBrowse").value = "";
	document.getElementById(SORT_BY).value = "";
	document.getElementById(PAGE_SIZE).value = "";

	//document.getElementById(SEARCH_FORM_ID).submit();
}

function setPageSizeHidden(obj){
	document.getElementById(PAGE_SIZE_HIDDEN).value=obj.value;
}

function doPageSizeSubmit(val){
	document.getElementById(PAGE_SIZE_HIDDEN).value=document.getElementById("ps"+val).value;
	var sbpsValue = document.getElementById(PAGE_SIZE_HIDDEN).value;
	var elementArr = document.getElementsByName(PAGE_SIZE);
	elementArr[0].value = sbpsValue;
	elementArr[1].value =sbpsValue;
	document.getElementById(SEARCH_FORM_ID).submit();
}

function setSortByHidden(obj){
	document.getElementById(SORT_BY_HIDDEN).value=obj.value;
}

function doSortBySubmit(val){
	document.getElementById(SORT_BY_HIDDEN).value=document.getElementById("sb"+val).value;
	var sbpsValue = document.getElementById(SORT_BY_HIDDEN).value;
	var elementArr = document.getElementsByName(SORT_BY);
	elementArr[0].value = sbpsValue;
	elementArr[1].value =sbpsValue;
	document.getElementById(SEARCH_FORM_ID).submit();
}

function submitForm(obj){
	document.getElementById(SEARCH_FORM_ID).submit();
}

 function onChangeCB(){
 	var cbValue =	document.getElementById(CHECK_BOX_ID).checked;
    if(cbValue){
   			//to remove the original search text
    		document.getElementById('basic-search-box').value="";
			document.getElementById('idLabelOSV').style.display="block";
    }else{
			document.getElementById('idLabelOSV').style.display="none";
			//document.getElementById('basic-search-box').value = gup('st');
			document.getElementById('basic-search-box').value = document.getElementById('hiddOrgSt').value;
    }
    return;
}		

function collapseNavTest(obj){
	var img = document.getElementById('img'+obj.id);        
    var dd = document.getElementById('dd'+obj.id);
    if (dd.style.display != 'block') 
    {
        img.src='images/minus.gif';
        img.alt='minus sign';
        dd.style.display='block';
     }
     else 
     {
         img.alt='plus sign';
         img.src='images/plus.gif';
         dd.style.display='none';            
     }
}
 
 
//temp function for browsing
function fb(featuredpub)
{
	alert('Featured Publication (' + featuredpub + ') not available yet'); 
}

// to get the url param
function gup( name ){ 
 name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
  var regexS = "[\\?&]"+name+"=([^&#]*)";  
  var regex = new RegExp( regexS );  
  var results = regex.exec( window.location.href ); 
   if( results == null )  
     return "";
       else
           return results[1];
}

    /** Function to handle browse by date submission
	 added for browse by date.
	 
	 */
	 
 function searchFromBrowse() {
	 var pathname = location.pathname;
	 var newPath = pathname.replace('datetab','datebrowsesearch'); 
     document.getElementById('dispatch').value ="browsedates";
  	 document.getElementById('browseDateForm').action= newPath;
  	 document.getElementById(browseDateForm).submit();
 } 
 
  /**
   Function to handle browse by cfrparts.	 
  */
  function searchFromBrowseCFR() {
     document.getElementById('dispatch').value ="submit";
  	 document.getElementById('browseCfrParts').submit();
  } 

/**
 This is the function that wraps calls to dcsMultiTrack() function to capture application specific events
 and to capture application specific parameters for reporting on the web trends side. 

 type Of Search -->Basic,Advanced,Citation
 type of Collection --> Single or Multiple
 collection Code -> Any valid colelction code
 resultURI--> URI of the resulting page. Since we are using dcsMultiTrack,in order to differentiate duplicate hits.
 resultPage Title --> Title to result page to differentiate duplicate hit

*/

function logSearchStats(typeOfSearch,typeOfCollection,collectionCode,resultURI,resultTitle){
	/*	
	 One of the way was passing objects to this method to handle any no. of parameters. This approach was dropped 
	as it needed a lot of code to create objects,addition of new parameters needed code change somewhere.
	
	*/
   //invoke webtrends script
   //'DCS.dcsuri' --> URI of the resulting page
   //WT.ti --> title of the resulting page
   resultTitle="US Government Printing Office - FDSys - "+resultTitle;
   resultTitle = escape(resultTitle);
  dcsMultiTrack('DCS.dcsuri',resultURI,'WT.ti',resultTitle,'DCSext.actionType',ACTION_SEARCH,'DCSext.typeOfSearch',typeOfSearch,'DCSext.typeOfCollection',typeOfCollection,'DCSext.collectionCode',collectionCode);
  	//just reset the variables
  DCSext.actionType = DCSext.typeOfSearch = DCSext.typeOfCollection = DCSext.collectionCode = "";
  
}	 

/**
 type Of Retrieval -->Search Results,Content Details,Citation
 file Type --> Text,PDF,HTML,XML,Zip..The type of file clicked by user
 collection Code -> Any valid colelction code
 resultURI--> URI of the resulting page. Since we are using dcsMultiTrack,in order to differentiate duplicate hits.
 resultPage Title --> Title to result page to differentiate duplicate hit
*/	 
function logRetrievalStats(typeOfRetrieval,collectionCode,fileType,resultURI,resultTitle){

	
//just treat both collection daily as well weekly compilation of presidential docuuments equal.
	if(collectionCode == 'WCPD'){
		collectionCode = 'CPD';
	}
	
	//invoke webtrends script
	// 'DCS.uri',window.location.pathname ,'WT.ti',document.title,
	 resultTitle="US Government Printing Office - FDSys - "+resultTitle;
	 resultTitle = escape(resultTitle);
	 dcsMultiTrack('DCS.dcsuri',resultURI,'WT.ti',resultTitle,'DCSext.actionType',ACTION_RETRIEVAL,'DCSext.typeOfRetrieval',typeOfRetrieval,'DCSext.fileType',fileType,'DCSext.collectionCode',collectionCode);
 	//just reset the variables
 	DCSext.actionType = DCSext.typeOfRetrieval = DCSext.fileType = DCSext.collectionCode = "";
}	 	 

/** added for the
* drop down display in search results */
function onChangeTimeFrame(obj)
{
window.location.href='search/browsedaterange.action?timeFrame='+obj.value;
}

function setTimeFrameHidden(obj){
	//alert(obj.value);
	document.getElementById('tfh').value=obj.value;
}

function doTimeframeSubmit(obj){
		document.getElementById(SEARCH_FORM_ID).submit();
}

/*
*	Added for the Scroll by
**/
function getScrollXY() {

	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
	//Netscape compliant
	scrOfY = window.pageYOffset;
	scrOfX = window.pageXOffset;

	//alert(scrOfY)

	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {

	//DOM compliant

	scrOfY = document.body.scrollTop;
	scrOfX = document.body.scrollLeft;

	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {

	//IE6 standards compliant mode

	scrOfY = document.documentElement.scrollTop;
	scrOfX = document.documentElement.scrollLeft;

	}

	document.getElementById('ycord').value = scrOfY;

}

	function setScrollXY(){
       if(document.getElementById('ycord') != undefined){
       var max = getheight();
	   var scrOfX = 0;	     
	   var scrOfY = document.getElementById('ycord').value;
	   if(scrOfY > max)
	       scrOfY = max;
      // alert(scrOfY);
	   window.scrollTo(scrOfX,scrOfY);	
      } else {
      	window.scrollTo(0,0);
      }	
	}
	
	function getheight(){
	   var d= document.documentElement;
	   var b= document.body;
	   var who= d.offsetHeight? d: b ;
	   return Math.max(who.scrollHeight,who.offsetHeight);
}


function goWithVars(value, counter)
{   
	//alert('value1='+value);
	 var  scrOfY = 0;
	      if( typeof( window.pageYOffset ) == 'number' ) {
   			 //Netscape compliant   			  
    			scrOfY = window.pageYOffset;
    	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
  		  //DOM compliant
    	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
   			 //IE6 standards compliant mode
    			scrOfY = document.documentElement.scrollTop;
    	  }	
	document.location = value + '&'+ 'ycord='+scrOfY;  
}	

function goWithVarsFR(value, counter)
{ 

	  var  scrOfY = 0;	 	
 	  var b = document.getElementsByTagName('base');

      if( typeof( window.pageYOffset ) == 'number' ) {
   			 //Netscape compliant   			  
    			scrOfY = window.pageYOffset;
   	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
  		  	 //DOM compliant
   	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
   			 //IE6 standards compliant mode
    			scrOfY = document.documentElement.scrollTop;
   	  }
    	  
      if (b && b[0] && b[0].href) {	
   			if (b[0].href.substr(b[0].href.length-1) == '/' && value.charAt(0) == '/')
    				value = value.substr(1);
   					value = b[0].href + value;   	   
 	  } 	 	  			 	  		 	  	
	document.location = value + '&'+ 'ycord='+scrOfY;  
}    
			