/*
FileName  : Validations.js
Purpose	  : Generalized Functions used in DailyReport.asp,DailyCollection.asp
Functions :
			assigncounters()
			additems()
			initialize()
NOTE : Before using this file, place the below code : Global Variables

<script language=javascript>
  var arrMain = new Array(<%=strTemp%>);  
  var curCounter = '<%=Request.form("counter")%>';
</script>
		
*/
 //OLD : var arrMain=new Array("c1;Counter 1","c2;Counter 2","c3;Counter 3","c4;Counter 4","c5;Counter 5")
  
  //This function adds the counters into dropdown
  
   function assigncounters()
	  {
	   var i,spos;
	   var opt;
	   var s1,s2;
		
	   //remove the existing items
	   for(i=1;i<document.f.counter.options.length;i++)
				{
					document.f.counter.remove(i);
				}
		//invoke the function
		
	   additems(document.f.counter,arrMain,document.f.ccc.value);
	   	
	  }
	
	//Adds the Counters Based on the Condition, with Reqd. Object parameters
	//OLD : var arrMain=new Array("c1;Counter 1","c2;Counter 2","c3;Counter 3","c4;Counter 4","c5;Counter 5")
	
	function additems(objName,arTemp,strVal)
	{
	
		var pos=1;
		var s1,s2,s3;
		
		var aa=new String(arTemp);
		  //alert(aa);	    	 
		
		for(i=0;i<arTemp.length;i++)
			  {
			  s1=new String(arTemp[i]);
			  s1=s1.substring(0,s1.indexOf(";"))
			  s2=new String(arTemp[i]);
			  //s1= s2.substring(s2.indexOf(";")+1)
			  
			  if (s1.indexOf("Bjunction")>=0)
				s2="B" + s2.substring(s2.indexOf(";")+1) 
			  else			  
			   s2="Counter " + s2.substring(s2.indexOf(";")+1)
			  
			  s3=new String(s2);
			  
			  if ( s1.indexOf("Bjunction")>=0)			  
				s3=s3.substring(s3.indexOf(" ")+1)	  
			  else
				s3="C"+s3.substring(s3.indexOf(" ")+1)	    
			  
			  //alert(s3)
			  opt = new Option(s2,s3)
			 
			  if(strVal=="")
			  {
			     objName[pos++]=opt;
			  }
			  else if(s1==strVal)
			  {
				  objName[pos++]=opt;
			  }
			  
			}
	}
	
	//Used to Assign the Selected Value into DropDown
	function assigndefault()
	{
		var i;
		var comp;
		comp=curCounter;
		for(i=0;i<document.f.counter.options.length;i++)
		{
			if(document.f.counter.options[i].value==comp)
			  {
				document.f.counter.options[i].selected=true;
			  }
		}
	}
	
	//Call this function during Body_OnLoad Event
	function initialize()
	{
		//init();
		assigncounters();
		assigndefault();
	}
	

