/*
Program Purpose
**********************************************************************
Used in conjuction with paging.asp for viewing query results on a html 
page and being able to sort and view results per page
**********************************************************************

Bug Fix notes or code changes
**********************************************************************
Original Programmer: Anu
1)
Change Id : WITX030005
date      : 05/08/2003
Author    : Priority Support
purpose   : Fixes for Netscape 7.0

' Change Id	: WI2.1_ENC_AT_6
' Date	: 08-12-2003
' Author	: Priority Support
' Comments	: 1. 'Find It' should find subsequent matches. 
'		  2. Implement the Arizona version of putting help text within Find It box. WIAZ030002

**********************************************************************
*/

//this function is used when the find it button is clicked and tries to select the keyword entered.
function selectItem(num,objTextItem,objSelectItem,frm) {
		
			var str;
			var i;
			var pos,selectText;
			var objSelectItem
			var len
			
			if(document[frm][objSelectItem]==null)
			 document[frm][objSelectItem].selectedIndex=-1
			
			len = document[frm][objSelectItem].length -1; 
			
												
			if (num == "true" ) {
				str = document[frm][objTextItem].value;
			}
			
			/** WI2.1_ENC_AT_6 **/
			var intSelectedIndex;
			/*****************/
			
			str = str.toUpperCase();
			
			if (num == "true" ) {

				/************************ WI2.1_ENC_AT_6 ***********************/
				intSelectedIndex = eval(document[frm][objSelectItem].selectedIndex);
				if (eval(intSelectedIndex) <= 0){
					intSelectedIndex = 0;
				}
				else{
					intSelectedIndex = eval(intSelectedIndex) + 1;
				}	
				/************************************************************/				
				
				var flag = "false";	
				/************************************************/
				// Find the occurance...
				for(i=0; i<= len; i++) {
					selectText = document[frm][objSelectItem][i].text;
					selectText = selectText.toUpperCase();
					pos = selectText.indexOf(str);
					if(pos>=0) 
					{
						flag = "true";
						break;
					}
				}
				/************************************************/


				for(i=intSelectedIndex;i<= len ;i++) {
					selectText = document[frm][objSelectItem][i].text;
					selectText = selectText.toUpperCase();
					pos = selectText.indexOf(str);
					/***************** WI2.1_ENC_AT_6 ********************/
					if (i == eval(len)-1){
						if(flag=="true")
							i=0;
					}	
					
					if (pos >= 0 ) {
						document[frm][objSelectItem][0].selected = false;
						if(eval(intSelectedIndex)!=0)
							document[frm][objSelectItem][eval(intSelectedIndex)-1].selected = false;
						document[frm][objSelectItem][i].selected = true;
						window.status = '';
						break;
					}
					else {
						window.status = 'Not found';
					}
					/*****************************************************/
				}
			}
		}
	
	// function is redundant as of now.but might be used later.do not delete it.
	function test(){
		var index1;
		var str,len,selectText,pos;
		
		
		index1 = document.frmDataAnalysis.occupn.selectedIndex;
			
		
		if (index1 != -1) {
			// WITX030005
			//document.frmDataAnalysis.careerID.value = document.frmDataAnalysis.occ1.options[index1].value;
			
			/************************ WI2.1_ENC_AT_6 ***********************/
			if (document.frmDataAnalysis.findIt1.value == 'Enter an Occupation')
				document.frmDataAnalysis.findIt1.value = '';
			/*************************************************************/
		}
	}
				
				
	//this is used when the select/clear all check boxes are clicked in data Analysis pages.
	function selectAll_click(checkBoxName,selectBoxName,frm, functionCall) {
	
	/*
		functionCall:- 
		Y - call refillcombos function
		P - call refillcombos function with Paremeter
		N = do not call refillcombos function
	
	*/
		if (checkBoxName.checked == true ) {
			for(var i=0; i< selectBoxName.options.length;i++) { 
				selectBoxName.options[i].selected = true;
				if (functionCall == 'Y') {
					Refillcombos();
				}
				else {
					if (functionCall == 'P') {
						Refillcombos(2);
					}
					else {
						// do not call any functions
					
					}
				
				}	
			}
			
			//in refillcombos function u would have unselected the select box,that is why u need to reset the value here
			checkBoxName.checked = true ;		
		}
		else {
			
			selectBoxName.selectedIndex = -1
		}		
		
	}
	
	
	//this is used when the select/clear all check boxes are clicked in data Analysis pages.
	function selectMax_click(checkBoxName,selectBoxName,frm, functionCall,maxLength) 
	{
	
	/*
		functionCall:- 
		Y - call refillcombos function
		P - call refillcombos function with Paremeter
		N = do not call refillcombos function
	
	*/
	    var length=selectBoxName.options.length;
	    if(length<maxLength)
	     maxLength=length;
	     
	    // find first selected checkbox - Jason added this
	    var intSelectedIndex = selectBoxName.selectedIndex;
	    // if no selected index then set selected as the first option - Jason added this
	    if(intSelectedIndex < 0) 
	    { 
			intSelectedIndex = 0
		}
		else
		{
			maxLength = (maxLength + intSelectedIndex <= length) ? maxLength + intSelectedIndex: length;
		}
	    
	    for(var i=0; i< selectBoxName.options.length;i++) 
	    { 
		 selectBoxName.options[i].selected = false;
		}
	    //alert(intSelectedIndex);     
	    if (checkBoxName.checked == true ) {
			for(var i=intSelectedIndex; i< maxLength;i++) { 
				selectBoxName.options[i].selected = true;
				if (functionCall == 'Y') {
					Refillcombos();
				}
				else {
					if (functionCall == 'P') {
						Refillcombos(2);
					}
					else {
						// do not call any functions
					
					}
				
				}	
			}
			
			
			//in refillcombos function u would have unselected the select box,that is why u need to reset the value here
			checkBoxName.checked = true ;		
		}
		else {
			
			selectBoxName.selectedIndex = -1
		}		
		
	}
	
	
	
	function setCheckBoxStatus(checkBoxName,selectBoxName,frm) {
		var blnSelectAll;
		
		blnSelectAll = false;
		for (var i = 0 ;i < selectBoxName.options.length;i++) {
			if ( selectBoxName.options[i].selected == true ) {
				blnSelectAll = true;
			
			}
			else {
				blnSelectAll = false;
				break;
			}
		}
			
		if (blnSelectAll == true ) 
			checkBoxName.checked = true;
		else
			checkBoxName.checked = false;	
	


	}	
	
	
	function setSelectedValues(hiddenField,listBox)
	{
	 var arrAreaIndex;
	 if(hiddenField.value!="") 
	 {
		hidSelected=hiddenField.value;
		arrAreaIndex=hidSelected.split(",");
		for(i=0;i<=arrAreaIndex.length;i++) 
		{
		//WITX030005
		//if(listBox.options[i] !=null) 
		//	listBox.options[i].selected=false;  		 

		if(listBox[i] !=null) 
			listBox[i].selected=false;  		 
	    }
	
		for(i=0;i<=arrAreaIndex.length;i++) 
		{
		//WITX030005	
		//if(listBox.options[arrAreaIndex[i]] !=null) 
		//	listBox.options[arrAreaIndex[i]].selected=true;  		 
		
		if(listBox[arrAreaIndex[i]] !=null) 
			listBox[arrAreaIndex[i]].selected=true;
	    }
	  }  
	
	}
	
	function setSelectedValuetoHidden(hiddenField,listBox)
	{
	 var areaIndex="";
	 for(i=0;i<=listBox.options.length;i++) 
	 {
	 // WITX030005
	 // if(listBox.options[i]!=null)
	  if(listBox[i]!=null)
	   {
	    //WITX030005	
	    //if(listBox.options[i].selected)
	    if(listBox[i].selected)
	    { 
	     areaIndex+=i+",";
	     } 
	    } 
	  }
	 hiddenField.value=areaIndex
	}
	
	
	function validateListBox(listBox,size)
    {
     var itemCount=0;
	 for(i=0;i<=listBox.options.length;i++) 
	 {
	   //WITX030005	
	   //if(listBox.options[i]!=null)
	   if(listBox[i]!=null)
	   {
	    //WITX030005	
	    //if(listBox.options[i].selected)
	    if(listBox[i].selected)
	     itemCount+=1;
	   } 
	  }
	  if (itemCount> size)  
	   return true;
	  else
	   return false; 
	}
	
	
	
 function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}