var ElementUtil = new Object();
ElementUtil.getElementPosition = function(elt){
  var position = new Object();    
  if(elt.style.position == "absolute") {
	position.left = parseInt(elt.style.left);
	position.top = parseInt(elt.style.top);
  }
  else {
	position.left = ElementUtil.calcPosition(elt, "Left");      
	position.top = ElementUtil.calcPosition(elt, "Top");      
  }  
  return position;
}

ElementUtil.calcPosition = function(elt, dir){
	var tmpElt = elt;
	var pos = parseInt(tmpElt["offset" + dir]);
	while(tmpElt.tagName != "BODY" && tmpElt.tagName != "HTML") {
		tmpElt = tmpElt.offsetParent;
		pos += parseInt(tmpElt["offset" + dir]);
	}
	return pos;
}

ElementUtil.getElementDimension = function(elt) {
  var dim = new Object();
  dim.width = elt.offsetWidth;
  dim.height = elt.offsetHeight;
  return dim;
}


function changeDistricts(id)
{
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'selectDistCntr.php?action=getDistricts&id=' + gE('province').value;
	ajaxObject.onCompletion = function(){ 
		gE('districts_div').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function pageTransparency()
{
	position = ElementUtil.getElementPosition( document.getElementById('wholePage') );      
	dimension = ElementUtil.getElementDimension( gE('wholePage') ); 
	
	obj = gE('transDiv1');
	sE(obj);
	obj.style.left 	 = position.left;
	obj.style.top 	 = position.top;
	obj.style.width  = dimension.width;
	obj.style.height = dimension.height;

	obj = gE('transDiv2');
	sE(obj);
	obj.style.left 	 = position.left;
	obj.style.top 	 = position.top;
	obj.style.width  = dimension.width;
	obj.style.height = dimension.height;
	
	obj = gE('transDiv3');
	sE(obj);
	obj.style.left 	 = position.left;
	obj.style.top 	 = position.top;
	obj.style.width  = dimension.width;
	obj.style.height = dimension.height;

	items = document.getElementsByTagName('SELECT');
	for(i=0; i<items.length; i++)
		items[i].disabled = true;

}
function removeTransparency()
{
	obj = gE('transDiv1');
	hE(obj);

	obj = gE('transDiv2');
	hE(obj);

	obj = gE('transDiv3');
	hE(obj);

	items = document.getElementsByTagName('SELECT');
	for(i=0; i<items.length; i++)
		items[i].disabled = false;
}
function changeCenters()
{
	if(!validNum(gE('year'), 'Year', true))
		{gE('district').selectedIndex= 0; return false;}
		
	if(!validLenght(gE('year'), 4, 4, 'Year'))	
		{gE('district').selectedIndex= 0; return false;}
		
	if( ! validSelectRequired(gE('segment'), 'Segment') )
		{gE('district').selectedIndex= 0; return false;}

	if( ! validSelectRequired(gE('province'), 'Province') )
		return false;
		
	if( ! validSelectRequired(gE('district'), 'District') )
		return false;

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.setVar('province', gE('province').value );
	ajaxObject.setVar('year', gE('year').value );
	ajaxObject.setVar('segment', gE('segment').value );

	ajaxObject.requestFile = 'selectDistCntr.php?action=getCenters&id=' + gE('district').value;
	ajaxObject.onCompletion = function(){ 
		hE2(gE('selectionDiv'));
		gE('centersDiv').innerHTML = ajaxObject.response;
		gE('msgArea').innerHTML = '';
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "" )
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	return result;
}
function validSelectRequired(formField,fieldLabel)
{
	var result = true;
	var index = formField.selectedIndex;
	if ( formField.options[index].value == "" )
	{
		alert('Please select a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	
	return result;
}
function allDigits(str)
{
	return inValidCharSet(str,"0123456789-");
}

function inValidCharSet(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}
function validNum(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allDigits(formField.value))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}
function validLenght(str,minimum,maximum,label)
{ 
	//str.isPrototypeOf();
	_str = new String(str.value);
	
	var result = true;
	if (_str.length > maximum){
		alert(label+" length must not be more than "+maximum+" characters");
		str.focus();	
		result = false;
	}
	else if(_str.length < minimum){
		alert(label+" length must not be less than "+minimum+" characters");
		str.focus();	
		result = false;
	}

	return result;
}

availableFields = new Array(1, 2, 3, 4, 5, 7, 8, 9, 11, 12);
function validate()
{
	if(!gE('idsCounter'))return false;
	num = gE('idsCounter').value;

	if(!validNum(gE('year'), 'Year', true))
		return false;
		
	if(!validLenght(gE('year'), 4, 4, 'Year'))	
		return false;
		
	if( ! validSelectRequired(gE('segment'), 'Segment') )
		return false;

	if( ! validSelectRequired(gE('province'), 'Province') )
		return false;
		
	if( ! validSelectRequired(gE('district'), 'District') )
		return false;
		
	for(i=0; i<num; i++)
	{
		if( validate_anyOneSelected( gE('idsArray'+i).value ) ){
			if(!validate_allSelected( gE('idsArray'+i).value ))
				return false;
		}
	}
	return true;
}
function validate_anyOneSelected(id)
{
	for(ii=0; ii<availableFields.length; ii++)
	{
		if( gE('col_'+id+'_'+availableFields[ii]).value !='' )
			return true;
	}
	return false;
}
function validate_allSelected(id)
{
	for(ii=0; ii<availableFields.length; ii++)
	{
		if(!validRequired(gE('col_'+id+'_'+availableFields[ii]), "Enter Text"))
			return false;
	}
	return true;
}
function toNum(thisItem)
{
	num = parseInt(thisItem.value);
	if(isNaN(num)){ num = 0; thisItem.value = ''}
	else thisItem.value = num;
	return num;
}
function toNumII(number)
{
	num = parseInt(number);
	if(isNaN(num)){ return 0;}
	//else return Math.round(number * 100) / 100;
	else return Math.round(number);
}
function toNumII2(number)
{
	num = parseInt(number);
	if(isNaN(num)){ return 0;}
	else return Math.round(number * 100) / 100;
}
function toNumII3(number)
{
	num = parseInt(number);
	if(isNaN(num)){ return 0;}
	else return Math.round(number * 10) / 10;
}
function calculate(rowId, colId)
{
	var num = gE('idsCounter').value;
	//for(i=0; i<num; i++)
	{
		//thisLine = gE('idsArray'+i).value;
		thisLine = rowId;
		//if( validate_anyOneSelected( thisLine ) )
		{
			// calculation for "Total"
			value = toNum(gE('col_'+ thisLine + '_' + '1') ) +
					toNum(gE('col_'+ thisLine + '_' + '2') ) ;
			if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '0').value = value;

			// calculation for "Total # of Diagnostic Smear Examined"
			value =  (toNum(gE('col_'+ thisLine + '_' + '3') ) * 1 ) +
					 (toNum(gE('col_'+ thisLine + '_' + '4') ) * 2 ) +
					 (toNum(gE('col_'+ thisLine + '_' + '5') ) * 3 )
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '6').value = value;

			// calculation for "Total # +ve Diagnostic Smear"
			value =  (toNum(gE('col_'+ thisLine + '_' + '7') ) * 1 ) +
					 (toNum(gE('col_'+ thisLine + '_' + '8') ) * 2 ) +
					 (toNum(gE('col_'+ thisLine + '_' + '9') ) * 3 )
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '10').value = value;

			//Caculation for Suspect Positivity Rate
			a = toNum(gE('col_'+ thisLine + '_' + '7') ) + toNum(gE('col_'+ thisLine + '_' + '8') ) + toNum(gE('col_'+ thisLine + '_' + '9') )
			value = toNumII( a  );
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '13').value = value;
			
			//Caculation for Smear Positivity Rate
			a = toNum(gE('col_'+ thisLine + '_' + '10') ) + toNum(gE('col_'+ thisLine + '_' + '12') )
			b = toNum(gE('col_'+ thisLine + '_' + '6') ) + toNum(gE('col_'+ thisLine + '_' + '11') );
			value = toNumII3(a / b * 100 );
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '14').value = value;
			
			//Caculation for Smear Exam / Suspect
			a = toNum(gE('col_'+ thisLine + '_' + '6') ) / toNum(gE('col_'+ thisLine + '_' + '1') )
			value = toNumII3( a );
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '15').value = value;
			
			if(!validate_anyOneSelected(thisLine))
				gE('col_'+ thisLine + '_' + '6').value = gE('col_'+ thisLine + '_' + '10').value = gE('col_'+ thisLine + '_' + '11').value = gE('col_'+ thisLine + '_' + '13').value = gE('col_'+ thisLine + '_' + '14').value = gE('col_'+ thisLine + '_' + '15').value = '';

	//Coloring Management
	if(colId==1||colId==3||colId==4||colId==5)
	{
			val = toNum(gE('col_'+ thisLine + '_' + '3') ) + toNum(gE('col_'+ thisLine + '_' + '4') ) + toNum(gE('col_'+ thisLine + '_' + '5') );
			if(toNum(gE('col_'+ thisLine + '_' + '1') ) != val )
			{
				gE('col_'+ thisLine + '_' + '1').style.backgroundColor = '#CC3333';	
				gE('col_'+ thisLine + '_' + '1').style.border='1px solid #7F9DB9';	
				gE('col_'+ thisLine + '_' + '3').style.backgroundColor = '#CC3333';	
				gE('col_'+ thisLine + '_' + '3').style.border='1px solid #7F9DB9';	
				gE('col_'+ thisLine + '_' + '4').style.backgroundColor = '#CC3333';	
				gE('col_'+ thisLine + '_' + '4').style.border='1px solid #7F9DB9';	
				gE('col_'+ thisLine + '_' + '5').style.backgroundColor = '#CC3333';	
				gE('col_'+ thisLine + '_' + '5').style.border='1px solid #7F9DB9';	
			}
			else
			{
				gE('col_'+ thisLine + '_' + '1').style.backgroundColor = '#FFFFFF';	
				gE('col_'+ thisLine + '_' + '1').style.border='1px solid #7F9DB9';	
				gE('col_'+ thisLine + '_' + '3').style.backgroundColor = '#FFFFFF';	
				gE('col_'+ thisLine + '_' + '3').style.border='1px solid #7F9DB9';	
				gE('col_'+ thisLine + '_' + '4').style.backgroundColor = '#FFFFFF';	
				gE('col_'+ thisLine + '_' + '4').style.border='1px solid #7F9DB9';	
				gE('col_'+ thisLine + '_' + '5').style.backgroundColor = '#FFFFFF';	
				gE('col_'+ thisLine + '_' + '5').style.border='1px solid #7F9DB9';	
			}
	}



			
		}
	}
	var initilize = '';
	for(j=0; j<16; j++)
		initilize += 'var total_'+ j + ' = 0;';
	eval ( initilize );

	switch(colId)
	{
			case '1': 	var calArray = new Array(0, 1); break;
			case '2': 	var calArray = new Array(0, 2, 11); break;
			case '3': 	var calArray = new Array(3, 6); break;
			case '4': 	var calArray = new Array(4, 6); break;
			case '5': 	var calArray = new Array(5, 6); break;
			case '7': 	var calArray = new Array(7, 10); break;
			case '8': 	var calArray = new Array(8, 10); break;
			case '9': 	var calArray = new Array(9, 10); break;
			case '11': 	var calArray = new Array('11'); break;
			case '12': 	var calArray = new Array('12'); break;
			default:	var calArray = new Array();  break;
	}
	for(j=0; j<calArray.length; j++)
	{
		for(i=0; i<num; i++)
		{
			thisLine = gE('idsArray'+i).value;	
			val = toNum( gE('col_'+ thisLine + '_' + calArray[j] ) );
			eval('total_'+ calArray[j] + '+= val'   );
		}
		eval( 'val = total_' + calArray[j] );
		if(val == '' ) val = '0';
		gE( 'total_'+calArray[j] ).value = val;
	}

	a = toNum( gE( 'total_7' ) ) + toNum( gE( 'total_8' ) ) + toNum( gE( 'total_9' ) );
	value = toNumII( a  );
	//if(value == 0 ) value = '';
	gE( 'total_13' ).value = value;
	
	a = toNum( gE( 'total_11' ) ) + toNum( gE( 'total_6' ) );
	if( a == 0 ) gE( 'total_14' ).value = 0;
	else{
		b = toNum( gE( 'total_10' ) ) + toNum( gE( 'total_12' ) );
		value = toNumII3( b / a * 100 );
		if(val == '' ) val = '0';
		gE( 'total_14' ).value = value;
	}
	
	if( toNum( gE( 'total_1' ) ) == 0 ) gE( 'total_15' ).value = 0;
	else{
		value = toNumII3( toNum( gE( 'total_6' ) ) / toNum( gE( 'total_1' ) )  );
		if(val == '' ) val = '0';
		gE( 'total_15' ).value = value;
	}
	
	//Coloring Management
	if(colId==1||colId==3||colId==4||colId==5)
	{
			val = toNum(gE('total_3') ) + toNum(gE('total_4') ) + toNum(gE('total_5') );
			if(toNum(gE('total_1') ) != val )
			{
				gE('total_1').style.backgroundColor = '#CC3333';	
				gE('total_1').style.border='1px solid #7F9DB9';	
				gE('total_3').style.backgroundColor = '#CC3333';	
				gE('total_3').style.border='1px solid #7F9DB9';	
				gE('total_4').style.backgroundColor = '#CC3333';	
				gE('total_4').style.border='1px solid #7F9DB9';	
				gE('total_5').style.backgroundColor = '#CC3333';	
				gE('total_5').style.border='1px solid #7F9DB9';	
			}
			else
			{
				gE('total_1').style.backgroundColor = '#FFFFFF';	
				gE('total_1').style.border='1px solid #7F9DB9';	
				gE('total_3').style.backgroundColor = '#FFFFFF';	
				gE('total_3').style.border='1px solid #7F9DB9';	
				gE('total_4').style.backgroundColor = '#FFFFFF';	
				gE('total_4').style.border='1px solid #7F9DB9';	
				gE('total_5').style.backgroundColor = '#FFFFFF';	
				gE('total_5').style.border='1px solid #7F9DB9';	
			}
	}
	
}
var DigCenterChecked = new Array();
function afb_calculate(rowId, colId)
{
	var num = gE('idsCounter').value;
	//for(i=0; i<num; i++)
	{
		//thisLine = gE('idsArray'+i).value;
		thisLine = rowId;
		//if( validate_anyOneSelected( thisLine ) )
		{
			// calculation for "Total"
			value = toNum(gE('col_'+ thisLine + '_' + '2') ) +
					toNum(gE('col_'+ thisLine + '_' + '3') ) +
					toNum(gE('col_'+ thisLine + '_' + '4') ) ;
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '5').value = value;

			// calculation for "Total"
			value = toNum(gE('col_'+ thisLine + '_' + '7') ) +
					toNum(gE('col_'+ thisLine + '_' + '8') ) +
					toNum(gE('col_'+ thisLine + '_' + '9') ) +
					toNum(gE('col_'+ thisLine + '_' + '10') ) +
					toNum(gE('col_'+ thisLine + '_' + '11') ) ;
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '12').value = value;

			//Caculation for Aggrement
			a = toNum(gE('col_'+ thisLine + '_' + '6') );
			b = toNum(gE('col_'+ thisLine + '_' + '5') );
			value = toNumII3( a / b  * 100 );
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '13').value = value;
			
			//Caculation for Major Error
			a = toNum(gE('col_'+ thisLine + '_' + '7') ) + toNum(gE('col_'+ thisLine + '_' + '8') );
			value = toNumII( a );
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '14').value = value;
			
			//Caculation for Minor Error
			a = toNum(gE('col_'+ thisLine + '_' + '9') ) + toNum(gE('col_'+ thisLine + '_' + '10') ) + toNum(gE('col_'+ thisLine + '_' + '11') );
			value = toNumII( a );
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '15').value = value;
			
			//Caculation for FPR
			a = toNum(gE('col_'+ thisLine + '_' + '8') ) + toNum(gE('col_'+ thisLine + '_' + '10') );
			b = toNum(gE('col_'+ thisLine + '_' + '2') ) + toNum(gE('col_'+ thisLine + '_' + '3') );
			value = toNumII3( a / b * 100 );
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '16').value = value;
			
			//Caculation for FNR
			a = toNum(gE('col_'+ thisLine + '_' + '7') ) + toNum(gE('col_'+ thisLine + '_' + '9') );
			b = toNum(gE('col_'+ thisLine + '_' + '4') );
			value = toNumII3( a / b * 100 );
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '17').value = value;
			
			//Caculation for Sen
			a = toNum(gE('col_'+ thisLine + '_' + '5') ) - ( toNum(gE('col_'+ thisLine + '_' + '4')) + toNum(gE('col_'+ thisLine + '_' + '8')) + toNum(gE('col_'+ thisLine + '_' + '10')) );
			b = toNum(gE('col_'+ thisLine + '_' + '7')) + toNum(gE('col_'+ thisLine + '_' + '9'));
			value = toNumII3( a / (a+b) * 100 );
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '18').value = value;

			//Caculation for Spc
			a = toNum(gE('col_'+ thisLine + '_' + '4') ) - ( toNum(gE('col_'+ thisLine + '_' + '7')) + toNum(gE('col_'+ thisLine + '_' + '9')) );
			b = toNum(gE('col_'+ thisLine + '_' + '8')) + toNum(gE('col_'+ thisLine + '_' + '10'));
			value = toNumII3( a / (a+b) * 100 );
			//if(value == 0 ) value = '';
			gE('col_'+ thisLine + '_' + '19').value = value;
			
			if(!abf_validate_anyOneSelected(thisLine))
				gE('col_'+ thisLine + '_' + '5').value = gE('col_'+ thisLine + '_' + '12').value = gE('col_'+ thisLine + '_' + '13').value = gE('col_'+ thisLine + '_' + '14').value = gE('col_'+ thisLine + '_' + '15').value = gE('col_'+ thisLine + '_' + '16').value = gE('col_'+ thisLine + '_' + '17').value = gE('col_'+ thisLine + '_' + '18').value = gE('col_'+ thisLine + '_' + '19').value = '';
			
			//Coloring Management
			if(  colId==2||colId==8  || colId==4||colId==7  ||colId==3||colId==10 )
			{
				colC1 = ((colId==2||colId==8)?2:((colId==4||colId==7)?4:((colId==3||colId==10)?3:'')));
				colC2 = ((colId==2||colId==8)?8:((colId==4||colId==7)?7:((colId==3||colId==10)?10:'')));
				if(  toNum(gE('col_'+ thisLine + '_' + colC1) ) < toNum(gE('col_'+ thisLine + '_' + colC2) )  )
				{
					gE('col_'+ thisLine + '_' + colC1).style.backgroundColor = '#CC3333';	
					gE('col_'+ thisLine + '_' + colC1).style.border='1px solid #7F9DB9';	
					//gE('col_'+ thisLine + '_' + colC1).style.width='24px';	
					gE('col_'+ thisLine + '_' + colC1).style.height='20px';	
					
					gE('col_'+ thisLine + '_' + colC2).style.backgroundColor = '#CC3333';	
					gE('col_'+ thisLine + '_' + colC2).style.border='1px solid #7F9DB9';	
					gE('col_'+ thisLine + '_' + colC2).style.width='24px';	
					gE('col_'+ thisLine + '_' + colC2).style.height='20px';	
				}
				else
				{
					gE('col_'+ thisLine + '_' + colC1).style.backgroundColor = '#FFFFFF';	
					gE('col_'+ thisLine + '_' + colC1).style.border='1px solid #7F9DB9';	
					//gE('col_'+ thisLine + '_' + colC1).style.width='24px';	
					gE('col_'+ thisLine + '_' + colC1).style.height='20px';	
					
					gE('col_'+ thisLine + '_' + colC2).style.backgroundColor = '#FFFFFF';	
					gE('col_'+ thisLine + '_' + colC2).style.border='1px solid #7F9DB9';	
					gE('col_'+ thisLine + '_' + colC2).style.width='24px';	
					gE('col_'+ thisLine + '_' + colC2).style.height='20px';	
				}
			}
			//Coloring Management

			//Coloring Management 5 Totald
			colC1 = toNum(gE('col_'+ thisLine + '_' + '6') ) + toNum(gE('col_'+ thisLine + '_' + '7') ) + toNum(gE('col_'+ thisLine + '_' + '8') ) + toNum(gE('col_'+ thisLine + '_' + '9') ) + toNum(gE('col_'+ thisLine + '_' + '10') ) + toNum(gE('col_'+ thisLine + '_' + '11') ) ;
			if(  toNum(gE('col_'+ thisLine + '_' + '5') ) != colC1  )
			{
				gE('col_'+ thisLine + '_' + '5').style.backgroundColor = '#CC3333';	
				gE('col_'+ thisLine + '_' + '5').style.border='1px solid #7F9DB9';	
				//gE('col_'+ thisLine + '_' + '5').style.width='24px';	
				gE('col_'+ thisLine + '_' + '5').style.height='20px';	
			}
			else
			{
				gE('col_'+ thisLine + '_' + '5').style.backgroundColor = '#CCCCCC';	
				gE('col_'+ thisLine + '_' + '5').style.border='1px solid #7F9DB9';	
				//gE('col_'+ thisLine + '_' + '5').style.width='24px';	
				gE('col_'+ thisLine + '_' + '5').style.height='20px';	
			}
			//Coloring Management

		}
	}
	
	if( gE('col_'+ thisLine + '_' + '2').value != '' && gE('col_'+ thisLine + '_' + '3').value != '' &&
		gE('col_'+ thisLine + '_' + '4').value != '' && gE('col_'+ thisLine + '_' + '6').value != '' &&												   
		gE('col_'+ thisLine + '_' + '7').value != '' && gE('col_'+ thisLine + '_' + '8').value != '' &&
		gE('col_'+ thisLine + '_' + '9').value != '' && gE('col_'+ thisLine + '_' + '10').value != '' &&
		gE('col_'+ thisLine + '_' + '11').value != '' ){
		flag=false;
		for(j=0; j<DigCenterChecked.length; j++){
			if(DigCenterChecked[j] == thisLine)flag = true;
		}
		if(!flag) DigCenterChecked.push(thisLine);
	}
	else{
		flag= -1;
		for(j=0; j<DigCenterChecked.length; j++){
			if(DigCenterChecked[j] == thisLine)flag = j;
		}
		if(flag != -1){ 
			DigCenterChecked[flag] = DigCenterChecked[DigCenterChecked.length-1];
			DigCenterChecked.pop();
		}
	}
	gE('diagnosticCkecked').innerHTML = DigCenterChecked.length;
	
	MajErrors = 0;
	for(i=0; i<num; i++)
	{
		thisLine = gE('idsArray'+i).value;	
		if( gE('col_'+ thisLine + '_14' ).value > 0) MajErrors++;
	}
	gE('diagnosticMajErr').innerHTML = MajErrors;
	var initilize = '';
	for(j=2; j<20; j++)
		initilize += 'var total_'+ j + ' = 0;';
	eval ( initilize );

	switch(colId)
	{
			case '2': 	var calArray = new Array(2,5); break;
			case '3': 	var calArray = new Array(3,5); break;
			case '4': 	var calArray = new Array(4,5); break;
			case '6': 	var calArray = new Array(6,12); break;
			case '7': 	var calArray = new Array(7,12); break;
			case '8': 	var calArray = new Array(8,12); break;
			case '9': 	var calArray = new Array(9,12); break;
			case '10': 	var calArray = new Array(10,12); break;
			case '11': 	var calArray = new Array(11,12); break;
			default:	var calArray = new Array();  break;
	}
	for(j=0; j<calArray.length; j++)
	{
		for(i=0; i<num; i++)
		{
			thisLine = gE('idsArray'+i).value;	
			val = toNum( gE('col_'+ thisLine + '_' + calArray[j] ) );
			eval('total_'+ calArray[j] + '+= val'   );
		}
		eval( 'val = total_' + calArray[j] );
		if(val == '' ) val = '0';
		gE( 'total_'+calArray[j] ).value = val;
	}

	a = toNum( gE( 'total_6' ) );
	b = toNum( gE( 'total_5' ) );
	value = toNumII3( a / b * 100);
	//if(value == 0 ) value = '';
	gE( 'total_13' ).value = value;

	a = toNum( gE( 'total_7' ) ) + toNum( gE( 'total_8' ) ) ;
	value = toNumII( a  );
	//if(value == 0 ) value = '';
	gE( 'total_14' ).value = value;
	
	a = toNum( gE( 'total_9' ) ) + toNum( gE( 'total_10' ) ) + toNum( gE( 'total_11' ) );
	value = toNumII( a  );
	//if(value == 0 ) value = '';
	gE( 'total_15' ).value = value;
	
	a = toNum( gE( 'total_8' ) ) + toNum( gE( 'total_10' ) );
	b = toNum( gE( 'total_2' ) ) + toNum( gE( 'total_3' ) );
	value = toNumII( a / b * 100 );
	//if(value == 0 ) value = '';
	gE( 'total_16' ).value = value;

	a = toNum( gE( 'total_7' ) ) + toNum( gE( 'total_9' ) );
	b = toNum( gE( 'total_4' ) );
	value = toNumII3( a / b * 100 );
	//if(value == 0 ) value = '';
	gE( 'total_17' ).value = value;

	//Caculation for Sen
	a = toNum( gE( 'total_5' ) ) - (toNum( gE( 'total_4' ) ) + toNum( gE( 'total_8' ) ) + toNum( gE( 'total_10' ) ));
	b = toNum( gE( 'total_7' ) ) + toNum( gE( 'total_9' ) );
	value = toNumII3( a / (a+b) * 100 );
	//if(value == 0 ) value = '';
	gE( 'total_18' ).value = value;

//Caculation for Spc
	a = toNum( gE( 'total_4' ) ) - (toNum( gE( 'total_7' ) ) + toNum( gE( 'total_9' ) ));
	b = toNum( gE( 'total_8' ) ) + toNum( gE( 'total_10' ) );
	value = toNumII3( a / (a+b) * 100 );
	//if(value == 0 ) value = '';
	gE( 'total_19' ).value = value;
	
	
	//Coloring Management
	if(  colId==2||colId==8  || colId==4||colId==7  ||colId==3||colId==10 )
	{
		colC1 = ((colId==2||colId==8)?2:((colId==4||colId==7)?4:((colId==3||colId==10)?3:'')));
		colC2 = ((colId==2||colId==8)?8:((colId==4||colId==7)?7:((colId==3||colId==10)?10:'')));
		if(  toNum(gE('total_' + colC1) ) < toNum(gE('total_' + colC2) )  )
		{
			gE('total_' + colC1).style.backgroundColor = '#CC3333';	
			gE('total_' + colC1).style.border='1px solid #7F9DB9';	
			gE('total_' + colC1).style.width='24px';	
			gE('total_' + colC1).style.height='20px';	
			gE('total_' + colC2).style.backgroundColor = '#CC3333';	
			gE('total_' + colC2).style.border='1px solid #7F9DB9';	
			gE('total_' + colC2).style.width='24px';	
			gE('total_' + colC2).style.height='20px';	
		}
		else
		{
			gE('total_' + colC1).style.backgroundColor = '#FFFFFF';	
			gE('total_' + colC1).style.border='1px solid #7F9DB9';	
			gE('total_' + colC1).style.width='24px';	
			gE('total_' + colC1).style.height='20px';	
			gE('total_' + colC2).style.backgroundColor = '#FFFFFF';	
			gE('total_' + colC2).style.border='1px solid #7F9DB9';	
			gE('total_' + colC2).style.width='24px';	
			gE('total_' + colC2).style.height='20px';	
		}
	}
	//Coloring Management
	//Coloring Management 5 Totald
	colC1 = toNum(gE('total_6') ) + toNum(gE('total_7') ) + toNum(gE('total_8') ) + toNum(gE('total_9') ) + toNum(gE('total_10') ) + toNum(gE('total_11') ) ;
	if(  toNum(gE('total_5') ) != colC1  )
	{
		gE('total_5').style.backgroundColor = '#CC3333';	
		gE('total_5').style.border='1px solid #7F9DB9';	
		gE('total_5').style.width='24px';	
		gE('total_5').style.height='20px';	
	}
	else
	{
		gE('total_5').style.backgroundColor = '#CCCCCC';	
		gE('total_5').style.border='1px solid #7F9DB9';	
		gE('total_5').style.width='24px';	
		gE('total_5').style.height='20px';	
	}
	//Coloring Management

}

function selecitonBack()
{
	pageTransparency();
	gE('centersDiv').innerHTML = '<br /><br /><br /><span style="font-size:25px;">Select District ....</span><br /><br /><br />';
	sE2(gE('selectionDiv'));
	removeTransparency();
}
function onProvinceChange()
{
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'genrateReport.php?action=getDistricts&id=' + gE('province').value;
	ajaxObject.onCompletion = function(){ 
		gE('districts_div').innerHTML = ajaxObject.response;
		gE('centers_div').innerHTML = '<select class="pxSelect" id="center" name="center"><option value="0">All</option></select>';
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function onDistrictChange()
{
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'genrateReport.php?action=getCenters&id=' + gE('district').value;
	ajaxObject.onCompletion = function(){ 
		gE('centers_div').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}

function generateReport()
{
	if(!validNum(gE('year'), 'Year', true))
		{gE('district').selectedIndex= 0; return false;}
		
	if(!validLenght(gE('year'), 4, 4, 'Year'))	
		{gE('district').selectedIndex= 0; return false;}
		
	if( ! validSelectRequired(gE('segment'), 'Segment') )
		{gE('district').selectedIndex= 0; return false;}

	if( ! validSelectRequired(gE('province'), 'Province') )
		return false;
		
	if( ! validSelectRequired(gE('district'), 'District') )
		return false;
		
	if( ! validSelectRequired(gE('center'), 'center') )
		return false;

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.setVar('year', gE('year').value );
	ajaxObject.setVar('segment', gE('segment').value );
	ajaxObject.setVar('province', gE('province').value );
	ajaxObject.setVar('district', gE('district').value );
	ajaxObject.setVar('center', gE('center').value );

	ajaxObject.requestFile = 'genrateReport.php?action=generateReport';
	ajaxObject.onCompletion = function(){ 
		hE2(gE('selectionDiv'));
		gE('centersDiv').innerHTML = ajaxObject.response;
		gE('msgArea').innerHTML = '';
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}

function sE2i(e){l?e.display='':e.style.display='';}

function SummaryView(rowIds)
{
	rows = rowIds.split(/,/g);
	for(i=0; i<rows.length; i++)
	{
		hE2( gE(rows[i]) );
	}
}

function DetailView(rowIds)
{
	rows = rowIds.split(/,/g);
	for(i=0; i<rows.length; i++)
	{
		sE2i( gE(rows[i]) );
	}
}
function getCentersList(id)
{
	if( ! validSelectRequired(gE('province'), 'Province') )
		return false;
		
	if( ! validSelectRequired(gE('district'), 'District') )
		return false;

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'centersForm.php?action=getCenters&id=' + gE('district').value;
	ajaxObject.onCompletion = function(){ 
		hE2(gE('selectionDiv'));
		gE('centersDiv').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function insertCenter()
{
	if( ! validSelectRequired(gE('province'), 'Province') )
		return false;
		
	if( ! validSelectRequired(gE('district'), 'District') )
		return false;

	if( ! validRequired(gE('center'), 'Center') )
		return false;
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'centersForm.php?action=insertCenters&id=' + gE('district').value;
	ajaxObject.setVar('center', gE('center').value );
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function deleteCenter(id)
{
	res = window.confirm('Are you sure you want to delete this record');
	if (!res) return;
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'centersForm.php?action=deleteCenter&id=' + gE('district').value;
	ajaxObject.setVar('center', id );
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function editCenterPopup(center, obj)
{
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'centersForm.php?action=editCenterPopup&id=' + gE('district').value;
	ajaxObject.setVar('center', center );
	ajaxObject.onCompletion = function(){ 
		gE('popupDiv').innerHTML = ajaxObject.response;
		position = ElementUtil.getElementPosition( gE(obj) );      
		dimension = ElementUtil.getElementDimension( gE('popupDiv') ); 
		gE('popupDiv').style.left =300;
		gE('popupDiv').style.top = position.top - 100;
		sE2(gE('popupDiv'));
	};	
	ajaxObject.runAJAX();		
}
function cancelButton()
{
	hE2(gE('popupDiv'));
	gE('popupDiv').innerHTML = '';
	removeTransparency();
}
function updateCenter()
{
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'centersForm.php?action=updateCenter&id=' + gE('district').value;
	ajaxObject.setVar('center', gE('centerEdit').value );
	ajaxObject.setVar('centerId', gE('centerEditId').value );
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		cancelButton();
	};	
	ajaxObject.runAJAX();		
}
function getDistrictsList()
{
	if( ! validSelectRequired(gE('province'), 'Province') )
		return false;
		
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'districtsForm.php?action=getDistricts&id=' + gE('province').value;
	ajaxObject.onCompletion = function(){ 
		hE2(gE('selectionDiv'));
		gE('centersDiv').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function insertDistrict()
{
	if( ! validSelectRequired(gE('province'), 'Province') )
		return false;

	if( ! validRequired(gE('district'), 'District') )
		return false;

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'districtsForm.php?action=insertDistricts&id=' + gE('province').value;
	ajaxObject.setVar('district', gE('district').value );
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function deleteDistrict(id)
{
	res = window.confirm('Are you sure you want to delete this record');
	if (!res) return;
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'districtsForm.php?action=deleteDistrict&id=' + gE('province').value;
	ajaxObject.setVar('district', id );
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function editDistrictPopup(district, obj)
{
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'districtsForm.php?action=editDistrictPopup&id=' + gE('province').value;
	ajaxObject.setVar('district', district );
	ajaxObject.onCompletion = function(){ 
		gE('popupDiv').innerHTML = ajaxObject.response;
		position = ElementUtil.getElementPosition( gE(obj) );      
		dimension = ElementUtil.getElementDimension( gE('popupDiv') ); 
		gE('popupDiv').style.left =300;
		gE('popupDiv').style.top = position.top - 100;
		sE2(gE('popupDiv'));
	};	
	ajaxObject.runAJAX();		
}
function updateDistrict()
{
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'districtsForm.php?action=updateDistrict&id=' + gE('province').value;
	ajaxObject.setVar('district', gE('districtEdit').value );
	ajaxObject.setVar('districtId', gE('districtEditId').value );
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		cancelButton();
	};	
	ajaxObject.runAJAX();		
}
function insertProvince()
{
	if( ! validRequired(gE('province'), 'Province') )
		return false;

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'provinceForm.php?action=insertProvince';
	ajaxObject.setVar('province', gE('province').value );
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function deleteProvince(id)
{
	res = window.confirm('Are you sure you want to delete this record');
	if (!res) return;
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'provinceForm.php?action=deleteProvince';
	ajaxObject.setVar('province', id );
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function editProvincePopup(province, obj)
{
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'provinceForm.php?action=editProvincePopup';
	ajaxObject.setVar('province', province );
	ajaxObject.onCompletion = function(){ 
		gE('popupDiv').innerHTML = ajaxObject.response;
		position = ElementUtil.getElementPosition( gE(obj) );      
		dimension = ElementUtil.getElementDimension( gE('popupDiv') ); 
		gE('popupDiv').style.left =300;
		gE('popupDiv').style.top = position.top - 100;
		sE2(gE('popupDiv'));
	};	
	ajaxObject.runAJAX();		
}
function updateProvince()
{
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'provinceForm.php?action=updateProvince';
	ajaxObject.setVar('province', gE('provinceEdit').value );
	ajaxObject.setVar('provinceId', gE('provinceEditId').value );
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		cancelButton();
	};	
	ajaxObject.runAJAX();		
}
function getDAReport(tblId)
{
	if( ! validRequired(gE('year'), 'year') )
		return false;

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'dataAccuracyForm.php?action=getDAReport&tblId='+tblId;
	ajaxObject.setVar('year', gE('year').value );
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		cancelButton();
	};	
	ajaxObject.runAJAX();		
}
function openRows(ident)
{
	hE2(gE( ident+'open' ));
	sE2(gE( ident+'close' ));

	obj = gE('parentTable');
	objs = obj.getElementsByTagName('TR');
	for(i=0; i<objs.length; i++)
	{
		str = objs[i].id.toString().substr(0, ident.length);
		if( str == ident )
			sE2i( objs[i] );
	}
}
function closeRows(ident)
{
	sE2(gE( ident+'open' ));
	hE2(gE( ident+'close' ));

	obj = gE('parentTable');
	objs = obj.getElementsByTagName('TR');
	for(i=0; i<objs.length; i++)
	{
		str = objs[i].id.toString().substr(0, ident.length);
		str1 = objs[i].id.toString().substr(0, ident.length+4);
		
		if( str == ident )
		{
			if(objs[i])
			{
				hE2( objs[i] );
			}
		}
		else if( str1 == 'sub_'+ident )
		{
			if(objs[i])
			{
				hE2( objs[i] );
				idd = objs[i].id.toString().substr(0, objs[i].id.toString().lastIndexOf('_'));
				if(gE(idd+'_close'))hE2(gE(idd+'_close'));
				if(gE(idd+'_open'))sE2(gE(idd+'_open'));
			}
		}
	}
	if( objs.length )
	{
		
	}
}
function annualRep(year)
{
	if( ! year ){
		alert('Year value missing!');
		return false;
	}

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'annualRepCenterWise.php?action=annual&year='+year;
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		cancelButton();
	};	
	ajaxObject.runAJAX();		

}

function insertUser()
{
	if( ! validRequired(gE('userName'), 'User Name') )
		return false;
	if( ! validRequired(gE('password'), 'Password') )
		return false;
	if( ! validRequired(gE('firstName'), 'First Name') )
		return false;
	if( ! validRequired(gE('lastName'), 'Last Name') )
		return false;
	if( gE('password').value != gE('rePassword').value ){
		alert('Passwords does not match');
		gE('password').value = ''
		gE('rePassword').value = '';
		gE('password').focus();		
		return false;
	}

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.setVar('userName', gE('userName').value );
	ajaxObject.setVar('password', gE('password').value );
	ajaxObject.setVar('firstName', gE('firstName').value );
	ajaxObject.setVar('middleName', gE('middleName').value );
	ajaxObject.setVar('lastName', gE('lastName').value );
	ajaxObject.setVar('checkedProvinces', gE('checkedProvinces').value );
	ajaxObject.requestFile = 'userManagement_s.php?action=insertUser';
	ajaxObject.onCompletion = function(){ 
		if(ajaxObject.response == 'ALREADY EXIST'){
			alert('User name already exists!');
		}
		else gE('centersDiv').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();
}
function insertBatch()
{
	if( ! validNum(gE('year'), 'Year', true) )
		return false;
	if( ! validSelectRequired(gE('month'), 'Quarter') )
		return false;
	if( ! validSelectRequired(gE('batch'), 'batch') )
		return false;

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.setVar('year', gE('year').value );
	ajaxObject.setVar('month', gE('month').value );
	ajaxObject.setVar('batch', gE('batch').value );
	ajaxObject.requestFile = 'batchManagement_s.php?action=insertBatch';
	ajaxObject.onCompletion = function(){ 
		if(ajaxObject.response == 'ALREADY EXIST'){
			alert('Batch already exists!');
		}
		else gE('centersDiv').innerHTML = ajaxObject.response;
		removeTransparency();
	};	
	ajaxObject.runAJAX();
}
function markProvinces(ident)
{
	if(!ident)ident='';
	obj = gE('provChecked'+ident);
	objs = obj.getElementsByTagName('INPUT');
	gE('checkedProvinces'+ident).value = '';
	for(i=0; i<objs.length; i++)
	{
		if( objs[i].type.toString().toLowerCase()== 'checkbox' && objs[i].checked == true )
		{
			if( gE('checkedProvinces'+ident).value == '' ) gE('checkedProvinces'+ident).value = objs[i].value;
			else	gE('checkedProvinces'+ident).value += ','+objs[i].value;
		}
	}
}
function editUserPopup(id, obj)
{
	pageTransparency()
	items = document.getElementsByTagName('SELECT');
	for(i=0; i<items.length; i++)
		hE(items[i]);
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'userManagement_s.php?action=editUserPopup';
	ajaxObject.setVar('id', id );
	ajaxObject.onCompletion = function(){ 
		gE('popupDiv').innerHTML = ajaxObject.response;
		position = ElementUtil.getElementPosition( gE(obj) );      
		dimension = ElementUtil.getElementDimension( gE('popupDiv') ); 
		gE('popupDiv').style.left =200;
		gE('popupDiv').style.top = position.top - 300;
		sE2(gE('popupDiv'));
	};	
	ajaxObject.runAJAX();		
}
function showHiddenSelect()
{
	cancelButton();
	items = document.getElementsByTagName('SELECT');
	for(i=0; i<items.length; i++)
		sE(items[i]);
}
function editUser(id)
{
	if( ! validRequired(gE('userName_edit'), 'User Name_edit') )
		return false;
	if( ! validRequired(gE('password_edit'), 'Password_edit') )
		return false;
	if( ! validRequired(gE('firstName_edit'), 'First Name_edit') )
		return false;
	if( ! validRequired(gE('lastName_edit'), 'Last Name_edit') )
		return false;
	if( gE('password_edit').value != gE('rePassword_edit').value ){
		alert('Passwords does not match');
		gE('password_edit').value = ''
		gE('rePassword_edit').value = '';
		gE('password_edit').focus();		
		return false;
	}

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.setVar('userName', gE('userName_edit').value );
	ajaxObject.setVar('password', gE('password_edit').value );
	ajaxObject.setVar('firstName', gE('firstName_edit').value );
	ajaxObject.setVar('middleName', gE('middleName_edit').value );
	ajaxObject.setVar('lastName', gE('lastName_edit').value );
	ajaxObject.setVar('checkedProvinces', gE('checkedProvinces_edit').value );
	ajaxObject.setVar('id', id );
	ajaxObject.requestFile = 'userManagement_s.php?action=editUser';
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		cancelButton();
		removeTransparency();
	};	
	ajaxObject.runAJAX();
}
function deleteUser(id)
{
	cond = window.confirm('Are you sure you want to delete this user');
	if(!cond) return false;
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'userManagement_s.php?action=deleteUser&id='+id;
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		cancelButton();
		removeTransparency();
	};	
	ajaxObject.runAJAX();
}
function deleteBatch(batch, year, month)
{
	cond = window.confirm('Are you sure you want to remove this Batch Permission');
	if(!cond) return false;
	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.requestFile = 'batchManagement_s.php?action=deleteBatch&batch='+batch+'&year='+year+'&month='+month;
	ajaxObject.onCompletion = function(){ 
		gE('centersDiv').innerHTML = ajaxObject.response;
		cancelButton();
		removeTransparency();
	};	
	ajaxObject.runAJAX();
}
function deleteCheck()
{
	cond = window.confirm('Are you sure you want to delete this record');
	return cond;
}
function afb_changeCenters()
{
	if(!validNum(gE('year'), 'Year', true))
		{gE('district').selectedIndex= 0; return false;}
		
	if(!validLenght(gE('year'), 4, 4, 'Year'))	
		{gE('district').selectedIndex= 0; return false;}
		
	if( ! validSelectRequired(gE('segment'), 'Segment') )
		{gE('district').selectedIndex= 0; return false;}

	if( ! validSelectRequired(gE('province'), 'Province') )
		return false;
		
	if( ! validSelectRequired(gE('district'), 'District') )
		return false;

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.setVar('province', gE('province').value );
	ajaxObject.setVar('year', gE('year').value );
	ajaxObject.setVar('segment', gE('segment').value );

	ajaxObject.requestFile = 'selectDistCntr.php?action=get_afb_Centers&id=' + gE('district').value;
	ajaxObject.onCompletion = function(){ 
		hE2(gE('selectionDiv'));
		gE('centersDiv').innerHTML = ajaxObject.response;
		gE('msgArea').innerHTML = '';
		
		preLoadCounters();
		
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
abf_availableFields = new Array(2, 3, 4, 6, 7, 8, 9, 10, 11);
function abf_validate()
{
	if(!gE('idsCounter'))return false;
	num = gE('idsCounter').value;

	if(!validNum(gE('year'), 'Year', true))
		return false;
		
	if(!validLenght(gE('year'), 4, 4, 'Year'))	
		return false;
		
	if( ! validSelectRequired(gE('segment'), 'Segment') )
		return false;

	if( ! validSelectRequired(gE('province'), 'Province') )
		return false;
		
	if( ! validSelectRequired(gE('district'), 'District') )
		return false;
		
	for(i=0; i<num; i++)
	{
		if( abf_validate_anyOneSelected( gE('idsArray'+i).value ) ){
			if(!abf_validate_allSelected( gE('idsArray'+i).value ))
				return false;
		}
	}
	return true;
}
function abf_validate_anyOneSelected(id)
{
	for(ii=0; ii<abf_availableFields.length; ii++)
	{
		if( gE('col_'+id+'_'+abf_availableFields[ii]).value !='' )
			return true;
	}
	return false;
}
function abf_validate_allSelected(id)
{
	for(ii=0; ii<abf_availableFields.length; ii++)
	{
		if(!validRequired(gE('col_'+id+'_'+abf_availableFields[ii]), "Enter Text"))
			return false;
	}
	return true;
}
function afb_generateReport()
{
	if(!validNum(gE('year'), 'Year', true))
		{gE('district').selectedIndex= 0; return false;}
		
	if(!validLenght(gE('year'), 4, 4, 'Year'))	
		{gE('district').selectedIndex= 0; return false;}
		
	if( ! validSelectRequired(gE('segment'), 'Segment') )
		{gE('district').selectedIndex= 0; return false;}

	if( ! validSelectRequired(gE('province'), 'Province') )
		return false;
		
	if( ! validSelectRequired(gE('district'), 'District') )
		return false;
		
	if( ! validSelectRequired(gE('center'), 'center') )
		return false;

	pageTransparency()
	ajaxObject = new sack();	
	ajaxObject.setVar('year', gE('year').value );
	ajaxObject.setVar('segment', gE('segment').value );
	ajaxObject.setVar('province', gE('province').value );
	ajaxObject.setVar('district', gE('district').value );
	ajaxObject.setVar('center', gE('center').value );

	ajaxObject.requestFile = 'genrateReport.php?action=afb_generateReport';
	ajaxObject.onCompletion = function(){ 
		hE2(gE('selectionDiv'));
		gE('centersDiv').innerHTML = ajaxObject.response;
		gE('msgArea').innerHTML = '';
		removeTransparency();
	};	
	ajaxObject.runAJAX();		
}
function preLoadCounters()
{
	var num = gE('idsCounter').value;
	MajErrors = 0; checkedCenters = 0;
	DigCenterChecked = Array();
	for(i=0; i<num; i++)
	{
		thisLine = gE('idsArray'+i).value;	
		if( gE('col_'+ thisLine + '_14' ).value > 0) MajErrors++;
		// check only few values ... if enetred
		if( gE('col_'+ thisLine + '_' + '3').value !='' || gE('col_'+ thisLine + '_' + '4').value !='' || gE('col_'+ thisLine + '_' + '5').value !=''  )
		{
			checkedCenters++;
			DigCenterChecked.push(thisLine);
		}
	}
	gE('diagnosticMajErr').innerHTML = MajErrors;
	gE('diagnosticCkecked').innerHTML = DigCenterChecked.length;
	
}