//---------------------------------------------
function IsValidTime(timeStr) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(A|a|P|p)(M|m))?$/;

var matchArray = timeStr.match(timePat);

if (matchArray == null) {
alert("The time you entered is not valid. Please try again!");
return false;
}

hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
return false;
}

if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
alert("You must specify AM or PM.");
return false;
   }
}

if  (hour > 12 && ampm != null) {
alert("You can't specify AM or PM for military time.");
return false;
}
if (minute<0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
return false;
}
return true;
}


function CheckTimeFormat(objName,checkempty){
    
    if (checkempty){
       if (objName.value == null || objName.value == ""){
           objName.select();
           alert("The time here cannot be empty!");
           objName.focus();
           return false;
       }
    }
    
    if (objName.value != null && objName.value != ""){
         if (! IsValidTime(objName.value)){
            objName.select();
            objName.focus();
            return false;
         }
    }
    
    return true;
    
}
   
   

function number_round(val,vallength){
   val = Math.round(val*Math.pow(10,vallength))/Math.pow(10,vallength);
   return val;
}

function checknumber(objName){
   var inputvalue = new String();
   
   if (objName.value != null && objName.value != ""){
      inputvalue = objName.value;
      for(i=0;i<=inputvalue.length;i++){
      if (isNaN(inputvalue.substring(i,1))){
         objName.select();
         alert("The number you entered is not valid. Please try again!");
         objName.focus();
         return false;
      }
      }
   }else{
     objName.value = "0";
   }
   
   return true;      
}

function checknumber2(objName){
   var inputvalue = new String();
   
   if (objName.value != null && objName.value != ""){
      inputvalue = objName.value;
      for(i=0;i<=inputvalue.length;i++){
      if (isNaN(inputvalue.substring(i,1))){
         objName.select();
         alert("The number you entered is not valid. Please try again!");
         objName.focus();
         return false;
      }
      }
   }
   return true;      
}


function checknumber_float(objName){
   var inputvalue = new String();
   
   if (objName.value != null && objName.value != ""){
      inputvalue = objName.value;
      for(i=0;i<=inputvalue.length;i++){
      if (isNaN(inputvalue.substring(i,1)) && inputvalue.substring(i,1) !="."){
         objName.select();
         alert("The number you entered is not valid. Please try again!");
         objName.focus();
         return false;
      }
      }
   }else{
     objName.value = "0";
   }
   
   objName.value = number_round(objName.value,2);
   
   return true;      
}

function checknumber_float2(objName){
   var inputvalue = new String();
   
   if (objName.value != null && objName.value != ""){
      inputvalue = objName.value;
      if (inputvalue.indexOf("-",0)==0)
          inputvalue = inputvalue.substring(1,inputvalue.length);
      for(i=0;i<=inputvalue.length;i++){
      if (isNaN(inputvalue.substring(i,1)) && inputvalue.substring(i,1) !="."){
         return false;
      }
      }
   }
   
   return true;      
}

function checknumber_float3(objName){
   var inputvalue = new String();
   
   if (objName.value != null && objName.value != ""){
      inputvalue = objName.value;
      if (inputvalue.indexOf("-",0)==0)
          inputvalue = inputvalue.substring(1,inputvalue.length);
      for(i=0;i<=inputvalue.length;i++){
      if (isNaN(inputvalue.substring(i,1)) && inputvalue.substring(i,1) !="."){
         return false;
      }
      }
   }else{
     objName.value = "0";
   }
   
   return true;      
}

function checknumber_float_general(objName,PresionLength){
   var inputvalue = new String();
   
   if (objName.value != null && objName.value != ""){
      inputvalue = objName.value;
      for(i=0;i<=inputvalue.length;i++){
      if (isNaN(inputvalue.substring(i,1)) && inputvalue.substring(i,1) !="."){
         objName.select();
         alert("The number you entered is not valid. Please try again!");
         objName.focus();
         return false;
      }
      }
   }else{
     objName.value = "0";
   }
   
   objName.value = number_round(objName.value,PresionLength);
   
   return true;      
}
function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

function CheckEmailMore(ObjName,chkempty){
      
      if (chkempty){
       if (ObjName.value == null || ObjName.value == ""){
           ObjName.select();
           alert("Email cannot be empty!");
           ObjName.focus();
         return false;
       }
      }
      
      if (ObjName.value != null && ObjName.value != ""){ 
       if (! emailCheck(ObjName.value)){
          ObjName.select();
          ObjName.focus();
          return false;
       }    
      }
      
      return true;
      
      
}    

//-------------------------------------
function ClosePopWindow(refreshopener)
{
	window.close();
	if (refreshopener==true) window.opener.location.reload;
}

function PopWindow(url,name,left,top,width,height)
{
	if (url=="") return;
	if (name=="") name="_blank";
	
	var sFeature="directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no";
	
	if (left!="") sFeature = sFeature+ ",left=" + left;
	if (top!="") sFeature = sFeature+ ",top=" + top;
	if (width!="") sFeature = sFeature+ ",width=" + width;
	if (height!="") sFeature = sFeature+ ",height=" + height;
	
	window.open(url,name,sFeature);
}
//-------------------------------------

function number_round(val,vallength)
	{
		val = Math.round(val*Math.pow(10,vallength))/Math.pow(10,vallength);
		return val;
	}
	
//--------------------------------------

function TotalFee_Caculation(txtFee,txtRegister,txtDiscount,txtGST,txtGrant,TotalFieldID)
	{ 
	
	var rtn;
	
	rtn = parseFloat(txtFee.value);
	if (isNaN(rtn)) rtn = 0;
	
	if(txtDiscount!=null)
	{		
		if(txtDiscount.value!="" && !isNaN(parseFloat(txtDiscount.value))) 
			rtn = rtn - parseFloat(txtDiscount.value);
	}
	
	if(txtRegister!=null)
	{
		if(txtRegister.value!="" && !isNaN(parseFloat(txtRegister.value))) 
			rtn = rtn + parseFloat(txtRegister.value);
	}
	
	if(txtGST!=null)
	{
		if(txtGST.value!="" && !isNaN(parseFloat(txtGST.value))) 
			rtn = rtn * (1+ parseFloat(txtGST.value)/100.);
	}
	
	if(txtGrant!=null)
	{		
		if(txtGrant.value!=""&& !isNaN(parseFloat(txtGrant.value))) 
			rtn = rtn - parseFloat(txtGrant.value);
	}
	
	rtn = number_round(rtn,2);
	
	var e = document.getElementById(TotalFieldID);
	if( e != null ) e.innerHTML = rtn;
	
	}

//--------------------------------------
                         
function GSTAndTotalFee_Caculation(txtFee,txtRegister,rdnFixDiscount,txtDiscount,txtGSTPercentage,txtGrant,GSTFieldID,TotalFieldID)
	{ 
	var rtn, GST , e
	
	rtn = parseFloat(txtFee.value);
	if (isNaN(rtn)) rtn = 0;
	
	if(txtDiscount!=null)
	{		
		if(txtDiscount.value!="" && !isNaN(parseFloat(txtDiscount.value))) 
		{
			if (rdnFixDiscount != null && rdnFixDiscount.checked)
				rtn = rtn - parseFloat(txtDiscount.value)
			else
				rtn = rtn * (1.0 - parseFloat(txtDiscount.value)/100.0)
		}
	}
	
	if(txtRegister!=null)
	{
		if(txtRegister.value!="" && !isNaN(parseFloat(txtRegister.value))) 
			rtn = rtn + parseFloat(txtRegister.value);
	}
	
	if(txtGSTPercentage!=null)
	{
		if(txtGSTPercentage.value!="" && !isNaN(parseFloat(txtGSTPercentage.value))) 
		{
			GST = rtn * parseFloat(txtGSTPercentage.value)/100.0 ;
			rtn = rtn * (1+ parseFloat(txtGSTPercentage.value)/100.0);
		}
			
		if(GSTFieldID!="")
		{
			e = document.getElementById(GSTFieldID);
			if( e != null ) e.innerHTML = number_round(GST,2);
		}			
	}
	
	if(txtGrant!=null)
	{		
		if(txtGrant.value!=""&& !isNaN(parseFloat(txtGrant.value))) 
			rtn = rtn - parseFloat(txtGrant.value);
	}
	
	rtn = number_round(rtn,2);
	
	e = document.getElementById(TotalFieldID);
	if( e != null ) e.innerHTML = rtn;
	
	}

//--------------------------------------

function Discount_Caculation(txtDiscountD,txtDiscountP,txtFee,bFixDiscountChanged)
{
	if(txtFee==null || txtFee.text=="") return;
	if(txtDiscountD==null || txtDiscountD.text=="") return;
	if(txtDiscountP==null || txtDiscountP.text=="") return;
	
	var Total = parseFloat(txtFee.value);
	
	if(bFixDiscountChanged==true)
	{
		if(txtDiscountD!=null && txtDiscountD!="" && !isNaN(parseFloat(txtDiscountD.value)))
			txtDiscountP.value = number_round(parseFloat(txtDiscountD.value)/Total*100.0,2);
	}
	else
	{
		if(txtDiscountP!=null && txtDiscountP!="" && !isNaN(parseFloat(txtDiscountP.value)))
			txtDiscountD.value = number_round(parseFloat(txtDiscountP.value)*Total/100.0,2);
	}
}

function GSTAndTotalFee_CaculationByUnitsWithoutRegFee(txtFee,txtUnits,txtDiscount,DiscountFeeFieldID,txtGSTP,GSTFieldID,TotalFieldID)
	{ 
	var rtn, GST , discountfee, e
	
	if(txtFee==null) return;
	
	rtn = parseFloat(txtFee.value);
	if (isNaN(rtn)) rtn = 0;
		
	if(txtDiscount!=null)
	{		
		if(txtDiscount.value!="" && !isNaN(parseFloat(txtDiscount.value))) 
		{
			rtn = rtn - parseFloat(txtDiscount.value);
			discountfee = rtn;
			
			if( DiscountFeeFieldID != null )DiscountFeeFieldID.value = number_round(discountfee,2);
		}
	}
	
	if (txtUnits!=null)
	{
		if (txtUnits.value=="") txtUnits.value=1;
	
		if (!isNaN(parseFloat(txtUnits.value)))
			rtn = rtn * parseFloat(txtUnits.value);
	}
	
	if(txtGSTP!=null)
	{
		if(txtGSTP.value!="" && !isNaN(parseFloat(txtGSTP.value))) 
		{
			GST = rtn * parseFloat(txtGSTP.value)/100.0 ;
			rtn = rtn * (1+ parseFloat(txtGSTP.value)/100.0);
		}
			
		if(GSTFieldID!="")
		{
			//e = document.getElementById(GSTFieldID);
			//if( e != null ) e.innerHTML = number_round(GST,2);
			GSTFieldID.value = number_round(GST,2);
		}			
	}
	
	rtn = number_round(rtn,2);
	
	//e = document.getElementById(TotalFieldID);
	//if( e != null ) e.innerHTML = rtn;
	
	TotalFieldID.value = rtn;
	
	}
	
function GSTAndTotalFee_CaculationByUnits(txtFee,txtUnits,txtDiscount,DiscountFeeFieldID,txtRegister,txtGSTP,GSTFieldID,TotalFieldID)
	{ 
	var rtn, GST , discountfee, e
	
	if(txtFee==null) return;
	
	rtn = parseFloat(txtFee.value);
	if (isNaN(rtn)) rtn = 0;
		
	if(txtDiscount!=null)
	{		
		if(txtDiscount.value!="" && !isNaN(parseFloat(txtDiscount.value))) 
		{
			rtn = rtn - parseFloat(txtDiscount.value);
			discountfee = rtn;
			
			if( DiscountFeeFieldID != null )DiscountFeeFieldID.value = number_round(discountfee,2);
		}
	}
	
	if (txtUnits!=null)
	{
		if (txtUnits.value=="") txtUnits.value=1;
	
		if (!isNaN(parseFloat(txtUnits.value)))
			rtn = rtn * parseFloat(txtUnits.value);
	}
	
	if(txtRegister!=null)
	{
		if(txtRegister.value!="" && !isNaN(parseFloat(txtRegister.value))) 
			rtn = rtn + parseFloat(txtRegister.value);
	}
	
	if(txtGSTP!=null)
	{
		if(txtGSTP.value!="" && !isNaN(parseFloat(txtGSTP.value))) 
		{
			GST = rtn * parseFloat(txtGSTP.value)/100.0 ;
			rtn = rtn * (1+ parseFloat(txtGSTP.value)/100.0);
		}
			
		if(GSTFieldID!="")
		{
			//e = document.getElementById(GSTFieldID);
			//if( e != null ) e.innerHTML = number_round(GST,2);
			GSTFieldID.value = number_round(GST,2);
		}			
	}
	
	rtn = number_round(rtn,2);
	
	//e = document.getElementById(TotalFieldID);
	//if( e != null ) e.innerHTML = rtn;
	
	TotalFieldID.value = rtn;
	
	}
	
function GSTAndTotalFee_CaculationByUnitsWithGSTAmt(txtFee,txtUnits,txtDiscount,DiscountFeeFieldID,txtRegister,GSTFieldID,TotalFieldID)
	{ 
	var rtn, GST , discountfee, e
	
	if(txtFee==null) return;
	
	rtn = parseFloat(txtFee.value);
	if (isNaN(rtn)) rtn = 0;
		
	if(txtDiscount!=null)
	{		
		if(txtDiscount.value!="" && !isNaN(parseFloat(txtDiscount.value))) 
		{
			rtn = rtn - parseFloat(txtDiscount.value);
			discountfee = rtn;
			
			if( DiscountFeeFieldID != null )DiscountFeeFieldID.value = number_round(discountfee,2);
		}
	}
	
	if (txtUnits!=null)
	{
		if (txtUnits.value=="") txtUnits.value=1;
	
		if (!isNaN(parseFloat(txtUnits.value)))
			rtn = rtn * parseFloat(txtUnits.value);
	}
	
	if(txtRegister!=null)
	{
		if(txtRegister.value!="" && !isNaN(parseFloat(txtRegister.value))) 
			rtn = rtn + parseFloat(txtRegister.value);
	}
	
		if(GSTFieldID!="")
		{
				if(GSTFieldID.value!="" && !isNaN(parseFloat(GSTFieldID.value))) 
			rtn = rtn +parseFloat(GSTFieldID.value);
		}			
	
	rtn = number_round(rtn,2);
	
	//e = document.getElementById(TotalFieldID);
	//if( e != null ) e.innerHTML = rtn;
	
	TotalFieldID.value = rtn;
	
	}

//--------------------------------------
function Grant_CalculationByUnits(type,txtUnitFee,txtUnitAmt,txtUnits,txtGrantAmt,txtPax,chkGSTIncluded,txtGSTP,txtNetGrant)
{
    var rtn,vUnit
	
	if(txtUnitAmt==null) return 0;
	
	rtn = 0;
	if(txtUnitAmt.value!="" & !isNaN(txtUnitAmt.value))
		rtn = parseFloat(txtUnitAmt.value);
	
	if(type==null) return;
	
	if(type.value=="PERCENT" || type.value=="%")
	{	
		txtUnits.value=1;
		if(txtUnitFee!= null && !isNaN(parseFloat(txtUnitFee.value)))
				rtn = rtn * parseFloat(txtUnitFee.value)/100.0
		else	rtn = 0;	
	}
	
	
	if (txtUnits!=null)
		{
			if (txtUnits.value=="") txtUnits.value=1;
	
			if (!isNaN(parseFloat(txtUnits.value)))
				rtn = rtn * parseFloat(txtUnits.value);
		}
		
	rtn = number_round(rtn,2);
	
	if(txtGrantAmt!=null)		
		txtGrantAmt.value = rtn;
	
	if (txtPax!=null)
	{
		if (txtPax.value=="") txtPax.value=1;
	
		if (!isNaN(parseFloat(txtPax.value)))
			rtn = rtn * parseFloat(txtPax.value);
			
	}
	
	if (chkGSTIncluded!=null && chkGSTIncluded.checked==false)
	{
		if(txtGSTP!=null && !isNaN(parseFloat(txtGSTP.value)))
			rtn = rtn * (1 + parseFloat(txtGSTP.value)/100.0)
	}
	
	rtn = number_round(rtn,2);
	
	if (txtNetGrant!=null) txtNetGrant.value = rtn;
	
}


function Grant_Calculation(txtGrantAmt,txtPax,chkGSTIncluded,txtGSTP,txtNetGrant)
{
	rtn = parseFloat(txtGrantAmt.value);
	if (isNaN(rtn)) rtn = 0;
		
	if (txtPax!=null)
	{
		if (txtPax.value=="") txtPax.value=1;
	
		if (!isNaN(parseFloat(txtPax.value)))
			rtn = rtn * parseFloat(txtPax.value);
	}
	
	if (chkGSTIncluded!=null && chkGSTIncluded.checked==false)
	{
		if(txtGSTP!=null && !isNaN(parseFloat(txtGSTP.value)))
			rtn = rtn * (1 + parseFloat(txtGSTP.value)/100.0)
	}
	
	rtn = number_round(rtn,2);
	
	if (txtNetGrant!=null) txtNetGrant.value = rtn;
}

//-------------------------------------------------

function NetFee_TotalFeeWithGrant(txtFeeWithGST, chkGrant, txtNetGrant, txtNetFee)
{
	rtn = parseFloat(txtFeeWithGST.value);
	if (isNaN(rtn)) rtn = 0;
		
	//if (chkGrant.checked)
	//{
		if (txtNetGrant.value=="") txtNetGrant.value=0;
	
		if (!isNaN(parseFloat(txtNetGrant.value)))
			rtn = rtn - parseFloat(txtNetGrant.value);
	//}
	
	rtn = number_round(rtn,2);
	
	if (txtNetFee!=null) txtNetFee.value = rtn;
}

//-----------------------------------------
function GetControl_AttnCheckAll(ControlName)
{
  for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	
		var e = document.forms[0].elements[i];
		if (e.name.indexOf(ControlName)>=0 && e.type=='checkbox')	
		{
			return e;
		}	
	}
	return null;
}

function chkAll_AttnOnClick(ControlName,AllEnrIDs)
{   var chkAll = GetControl_AttnCheckAll(ControlName);
	if(chkAll==null) return;
	
	var itemarray = ControlName.split('@');
	var chkName = itemarray[1]+'@'+itemarray[2]
	
	
	for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	var e = document.forms[0].elements[i];
		if (e.name.indexOf(chkName)>=0 && e.type=='checkbox')	e.checked = chkAll.checked;
	}
	//CalAllAttnPercentage(AllEnrIDs);
}

function chkAll_AttnOnClick2(ControlName,AllEnrIDs)
{   var chkAll = GetControl_AttnCheckAll(ControlName);
	if(chkAll==null) return;
	
	var itemarray = ControlName.split('@');
	var chkName = itemarray[1];
	
	
	for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	var e = document.forms[0].elements[i];
		if (e.name.indexOf(chkName)>=0 && e.type=='checkbox')	e.checked = chkAll.checked;
	}
	//CalAllAttnPercentage(AllEnrIDs);
}


function chkSelect_AttnOnClick(ControlName,AllEnrIDs)
{
	var itemarray1 = ControlName.split('@');
	var chkName = itemarray1[1]+'@'+itemarray1[2]
	
	var chkAll = GetControl_AttnCheckAll('CheckAll@'+chkName);
	
	
	var j, k
	 
	 if(chkAll==null) return;
	 	
	 j = 0;
	 
    for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	var e = document.forms[0].elements[i];
               if ((e.name.indexOf(chkName)>=0) && (e.name.indexOf('CheckAll@'+chkName)<0)  && (e.type=='checkbox') )
               {
					if (!e.checked){
						j=1;
					}
			    }
	 } 
	    
	  if(j == 1 ) 
	{		chkAll.checked = false;
	}
	  else 		
	{		chkAll.checked = true;
	}
	  
	//CalAttnPercentage(itemarray1[0]);
	  		
	//CalAllAttnPercentage(AllEnrIDs); 
	
}

function chkSelect_Init(chkName)
{
	var chkAll = GetControl_AttnCheckAll('CheckAll@'+chkName);
	
	
	var j, k
	 
	 if(chkAll==null) return;
	 	
	 j = 0;
	 
    for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	var e = document.forms[0].elements[i];
               if ((e.name.indexOf(chkName)>=0) && (e.name.indexOf('CheckAll@'+chkName)<0)  && (e.type=='checkbox') )
               {
					if (!e.checked){
						j=1;
					}
			    }
	 } 
	    
	  if(j == 1 ) 
	{		chkAll.checked = false;
	}
	  else 		
	{		chkAll.checked = true;
	}
	  
}

function CalAllAttnPercentage(AllEnrIDs)
{  
	var itemarray = AllEnrIDs.split('@');
	
	for (var i=0;i<itemarray.length;i++)
	{
	  CalAttnPercentage(itemarray[i]);
	}
}

function  CalAttnPercentage(EnrID){
      var checkednumber, total;
      
      total=0;
      checkednumber = 0;
      for (var i=0;i<document.forms[0].elements.length;i++){
	       e = document.forms[0].elements[i];
	       if (e.name.indexOf(EnrID+"@",0)>=0 && e.type=='checkbox'){
	             if (e.checked){
	                checkednumber = checkednumber+1;
	             } 
	        total = total + 1;
	       }
      } 
      
      var attnPercentage = number_round(checkednumber*100/total,2);
      //attnPercentage = attnPercentage + "%";
      
      //alert(attnPercentage);
      for (var i=0;i<document.forms[0].elements.length;i++)
	 {	var e = document.forms[0].elements[i];
		if (e.name.indexOf('AttendPercentage@'+EnrID)>=0)	
		{
		  e.value = attnPercentage+'%';
		  return;
		}
	 }
      	       

}
//------------------------------------------
			
function GetControl_CheckAll()
{
   for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	
		var e = document.forms[0].elements[i];
		if (e.name.indexOf('chkAll')>=0)	
		{
			return e;
		}	
	}
	return null;
}
//----------------------------------------------------
function chkAll_OnClick()
{
	var chkAll = GetControl_CheckAll();
	if(chkAll==null) return;
	
	for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	var e = document.forms[0].elements[i];
		if (e.name.indexOf('chkSelect')>=0)	e.checked = chkAll.checked;
	}
}

//-------------------------------------------------

function chkSelect_OnClick()
{
	var chkAll = GetControl_CheckAll();
	var j, k
	 
	 if(chkAll==null) return;
	 	
	 j = k = 0;
	 
    for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	var e = document.forms[0].elements[i];
               if (e.name.indexOf('chkSelect')>=0){
					j++;
					if (!e.checked){
						chkAll.checked = false;
						return;
					}
					else k++;				
				}
	     } 
	    
	  if(j == k || j!=0 ) 
			chkAll.checked = true
	  else 		
			chkAll.checked = false;
	     
}
//================================================================
function GetControl_CheckAllByName(CheckAllName)
{
   for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	
		var e = document.forms[0].elements[i];
		if (e.name.indexOf(CheckAllName)>=0)	
		{
			return e;
		}	
	}
	return null;
}
//----------------------------------------------------
function chkAll_OnClickByName(CheckAllName,chkSelectName)
{
	var chkAll = GetControl_CheckAllByName(CheckAllName);
	if(chkAll==null) return;
	
	for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	var e = document.forms[0].elements[i];
		if (e.name.indexOf(chkSelectName)>=0)	e.checked = chkAll.checked;
	}
}

//-------------------------------------------------

function chkSelect_OnClickByName(CheckAllName,chkSelectName)
{
	var chkAll = GetControl_CheckAllByName(CheckAllName);
	var j, k
	 
	 if(chkAll==null) return;
	 	
	 j = k = 0;
	 
    for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	var e = document.forms[0].elements[i];
               if (e.name.indexOf(chkSelectName)>=0){
					j++;
					if (!e.checked){
						chkAll.checked = false;
						return;
					}
					else k++;				
				}
	     } 
	    
	  if(j == k || j!=0 ) 
			chkAll.checked = true
	  else 		
			chkAll.checked = false;
	     
}

//-------------------------------------------------

function chkSelect_OnClickByNameOR(CheckAllName,chkSelectName)
{
	var chkAll = GetControl_CheckAllByName(CheckAllName);
	var j, k
	 
	 if(chkAll==null) return;
	 	
	 j = k = 0;
	 
    for (var i=0;i<document.forms[0].elements.length;i++)
	{ 	var e = document.forms[0].elements[i];
               if (e.name.indexOf(chkSelectName)>=0){
					j++;
					if (e.checked){
						chkAll.checked = true;
						return;
					}
					else k++;				
				}
	     } 
	    
	  if(j == k || j!=0 ) 
			chkAll.checked = false
	  else 		
			chkAll.checked = true;
	     
}
//-->
