 /**
 *@param string a date value  say 21/01/1999
 *@return boolean true if a valid date format else false 
 *
 * THIS IS NOT THE FUNCTION TO VALIDATE DATE, THIS IS USED FOR DATE FIELD ONBLUR
 *
 */
function validateDateFormat(fld){	
	if(fld.value.length > 0 ){
		if(!isValidDateFormat(fld.value)){
			fld.value='';
			fld.focus();
			return false;
		}	
		return true;
	}
}
/**
*
* viewDetail is for view page
*/

function openView(id,className,height,width){	
		var url = 'view.action?id='+id+'&className='+className+'&viewCount=0';		
		var settings = "width="+width+",height="+height+",resizable=yes,scrollbars=yes";		
		win = window.open(url,'viewwin',settings);
	} 
	
function openAllView(id,className,height,width){	
		var url = 'view.action?id='+id+'&className='+className+'&viewCount=1&showAll=1';		
		var settings = "width="+width+",height="+height+"resizable=yes,scrollbars=yes";
		
		win = window.open(url,'viewwin',settings);
	}
function openReportWindow(url){	
		var settings = "left=15,top=15,width=700,height=550,toolbar=no,scrollbars=yes,location=no,directories=no,status=no,menubar=no,resizable=yes";	
		var arr=url.indexOf("?");		
		if(arr>-1){
			url=url+'&reportFormat=pdf&reportDisplay=inline';			
		}else{
			url=url+'?reportFormat=pdf&reportDisplay=inline';	
		}
		win = window.open(url,'reportwin',settings);
	}
	
	function openReportWithFormat(url,rf,rd){	
		var settings = "left=15,top=15,width=700,height=550,toolbar=no,scrollbars=yes,location=no,directories=no,status=no,menubar=no,resizable=yes";	
		url=url+'&reportFormat='+rf+'&reportDisplay='+rd;		
		win = window.open(url,'reportwin',settings);
	}
	//Close all report/view popups.
	function closeChildWindow(){
	  if (win && win.open && !win.closed){
	   	win.close();
	   }
	}
/**
* Method Used for Pagination
*
*/	
function goNext(sc,mc,sortBy,ord,t){			
		url = 'startCount='+sc+'&maxCount='+mc+'&sortBy='+sortBy+'&od='+ord+'&totalSize='+t;
		addMore(url);
	}
	function goNextPage(sc,mc,sortBy,ord,t){	
		url = 'page.firstRow='+sc+'&page.pageSize='+mc+'&page.orderBy='+sortBy+'&page.order='+ord+'&page.recordCount='+t;
		addMore(url);
	}
	
	function openWin(url,settings){	
		var win = window.open(url,'viewwin',settings);
	} 
/**
*  Method used for Text area max length check	
*
*/	
function textAreaCounter(field, maxlimit) {

var pattern = /[\n\t\f\r]/g;
var fieldVal = field.value;
var fieldLen = field.value.length;
var mCount = fieldVal.match(pattern);

if(mCount != null && (mCount).length >0){
  spLen = (mCount).length*2;
  fieldLen = fieldLen+spLen;
  }
  spLen = 0;
	if (fieldLen > maxlimit) {	    
		field.value = field.value.substring(0, maxlimit);
		mCount = fieldVal.match(pattern);
		if(mCount != null){
			spLen = (mCount).length*2;
		}
		field.value = field.value.substring(0, maxlimit-spLen);	
	}
}
 
function openPref(){	
	window.open('upPopulate.action','CampusDimensions','left=100,top=75,width=500,height=400,toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');		
} 

function checkBoxVal(field){
	var obj = document.getElementsByName(field);
	var countOfChecked=0;
	var len = obj.length; 	
	var sel="";
	if(len>0){
			for(var i=0;i<len;i++){
				if(obj[i].checked){				
					countOfChecked++;
					if(countOfChecked == 1){
						sel=obj[i].value;			
					}else{
						sel=sel+","+obj[i].value;			
						}
		 		}
			}	
		}
  return sel;
}
function checkBoxCheck(field,stat){
	var obj = document.getElementsByName(field);
	var len = obj.length; 	

	if(len>0){
			for(var i=0;i<len;i++){
				if(stat==1){
					obj[i].checked = true;
				}else
				{
					obj[i].checked = false;
				}
			}	
		}
}

function getValueCount(val){
	if(val.length <=0)
		return 0;

	var obj = val.match(/,/g);	
	if(obj && obj.length > 0)
		return obj.length+1;
	else
		return 1;
}

<!-- for validating checkbox -->
function isChecked(boxFld){
	var bIds = document.getElementsByName(boxFld);
	for(i=0;i<bIds.length;i++){
		if(bIds[i].checked){
			return true;
		}		
	}
	return false;
}


<!-- Methods only for Grid -->
	
	var rowToEdit ;
	var selDivImg = '<img src="images/pointer.gif" style="width:9px;height:11px;"/>'; 	
function gridFillRow(fldArray,valArray,strVal,widArray,rowId,tableId,aBtnId,eBtnId) { 
	//if(!validateGrid())
	//	return false;
	
	if(fldArray.length <= 0 || valArray.length <= 0){
		return;
	}	
	var tablem = document.all ? document.all[tableId] : document.getElementById(tableId);
	var lastRow = tablem.rows.length;	
	var row = tablem.insertRow(tablem.rows.length);		
	var v = (tablem.rows.length-1);
	var val;
	var hidStr="<input type=\"hidden\" id=\"gridOrder\" name=\"gridOrder\" value=\""+v+"\" >";
		hidStr=hidStr+"<input type=\"hidden\" id=\"rowId\" name=\"rowId\" value=\""+rowId+"\" >";
		hidStr=hidStr+"<input type=\"hidden\" id=\"ids\" name=\"ids\" value=\""+rowId+"\" >";
										
			var cl = row.insertCell(0);	
			cl.vAlign="bottom";	
			cl.innerHTML = '<div id="selectDiv'+v+'" style="visibility:hidden;width:16px;height:16px;">'+selDivImg+'</div>';
			
			for(i=0;i<fldArray.length;i++){  
			 	//val = document.getElementById(fldArray[i]+i);	
			 	val = valArray[i];	

			 	if(val != undefined){		 	
					var cell = row.insertCell(i+1);			
					hidStr=hidStr+"<input type=\"hidden\" id=\""+fldArray[i]+"\" name=\""+fldArray[i]+"\" value=\""+val+"\" >";
					c = isCombo(val);				
					 if(c == true){				
					  	//cell.innerHTML = val.options[val.selectedIndex].text;	
					  	cell.innerHTML = strVal[i];
					  	val=-1;
					  }else {
						//cell.innerHTML = val.value;	
						cell.innerHTML = strVal[i];				
						}										
					val.value="";	
				}			
			}			
			
			if(fldArray.length >0){
				var cell = row.insertCell(fldArray.length+1);	
				cell.align='center';
				cell.innerHTML = '<a href=\"javascript:void(0);\" onclick=\"deleteRow(this,\''+tableId+'\',\''+fldArray+'\',\''+aBtnId+'\',\''+eBtnId+'\')\"><img src="images/delete.gif" border="0" height="15" width="15"><\a>&nbsp;<a href=\"javascript:void(0)\" onclick=\"fillRow(this,\''+fldArray+'\',\''+tableId+'\',\''+aBtnId+'\',\''+eBtnId+'\')\"><img src="images/edit.gif" border="0" height="15" width="15"><\a>'+hidStr;				
			}		
		formatTable(null,tableId);	
}

function addRow(fldArray,widArray,tableId,aBtnId,eBtnId) { 
	var tablem = document.all ? document.all[tableId] : document.getElementById(tableId);
	var lastRow = tablem.rows.length;		
	
	if(!validateGridAdd(fldArray,(tablem.rows.length-1)))
		return;
	
	var row = tablem.insertRow(tablem.rows.length);	
	var v = (tablem.rows.length-1);
	
	var hidStr="<input type=\"hidden\" id=\"gridOrder\" name=\"gridOrder\" value=\""+v+"\" >";	
	var cl = row.insertCell(0);
	cl.vAlign="bottom";	
	cl.innerHTML = '<div id="selectDiv'+v+'" style="visibility:hidden;width:16px;height:16px;valign:middle;">'+selDivImg+'</div>';
	
			for(i=0;i<fldArray.length;i++){  
			 	val = document.getElementById(fldArray[i]+i);			 	
				var cell = row.insertCell(i+1);			
				hidStr=hidStr+"<input type=\"hidden\" id=\""+fldArray[i]+"\" name=\""+fldArray[i]+"\" value=\""+val.value+"\" >";
				c = isCombo(val);					
				 if(c == true){				
				  	cell.innerHTML = val.options[val.selectedIndex].text;	
				  	val.value=-1;
				  }else {
					cell.innerHTML = val.value;				
					}				
				val.value="";				
			}			
			
			if(fldArray.length >0){
				var cell = row.insertCell(fldArray.length+1);	
				cell.align='center';
				cell.innerHTML = '<input type=\"hidden\" id=\"ids\" name=\"ids\" value=\"-1\" ><a href=\"javascript:void(0);\" onclick=\"deleteRow(this,\''+tableId+'\',\''+fldArray+'\',\''+aBtnId+'\',\''+eBtnId+'\')\"><img src="images/delete.gif" border="0" height="15" width="15"><\a>&nbsp;<a href=\"javascript:void(0)\" onclick=\"fillRow(this,\''+fldArray+'\',\''+tableId+'\',\''+aBtnId+'\',\''+eBtnId+'\')\"><img src="images/edit.gif" border="0" height="15" width="15"><\a>'+hidStr;				
			}
			
		formatTable(row,tableId);	
}

function isCombo(fld){
	var agt=navigator.userAgent.toLowerCase();		
	if(agt.indexOf("msie")==-1 )
	{		
		if(fld instanceof HTMLSelectElement)
		{			
			return true;
		}	
		return false;
	}
	else
	{	
		if(typeof(fld.options) != 'undefined')
		{			
			return true;
		}	
		return false;
	}	
}
function fillRow (row,fldArray1,tableId,aBtnId,eBtnId) { 	
	var tablem = document.all ? document.all[tableId] : document.getElementById(tableId);
	var fldArray = fldArray1.split(',');
	
	var obj = row.parentNode;
	var r = obj.parentNode;	
	var cells = r.cells;
	rno = r.getAttribute('id');	
	for(i=0;i<cells.length-2;i++){ 	
		var val = document.getElementById(fldArray[i]+i);		
		var fl = document.getElementsByName(fldArray[i]);	
		
		c = isCombo(val);	
		if(c == true){							
			for(k=0;k<val.options.length;k++){				
				if(val.options[k].value == fl[rno-2].value)
					val.options[k].selected = true;
			}
		}
		else {			
			val.value = cells[i+1].innerHTML;		
			}
	}
	var eButton = document.all ? document.all[eBtnId] : document.getElementById(eBtnId);
	var aButton = document.all ? document.all[aBtnId] : document.getElementById(aBtnId);
	
	doAddImage(aButton,true);
	doEditImage(eButton,false);
	//disableImage(aButton,aBtnId);
	//aButton.disabled=true;	
//	eButton.disabled=false;		
	rowToEdit=r;
	formatTable(rowToEdit,tableId);	
}


function editRow(fldArray,tableId,aBtnId,eBtnId){	
		
	var eButton = document.all ? document.all[eBtnId] : document.getElementById(eBtnId);	
	var aButton = document.all ? document.all[aBtnId] : document.getElementById(aBtnId);		
	var tablem = document.all ? document.all[tableId] : document.getElementById(tableId);	 
	allIds = document.getElementsByName("ids");	 
	
	var v = (rowToEdit.getAttribute("id"));
	if(!validateGridEdit(fldArray,(v-2) )){		
		return false;
		}
	doAddImage(aButton,false);
	doEditImage(eButton,true);	
	//aButton.disabled=false;
	//eButton.disabled=true;
	
	var hidStr="<input type=\"hidden\" id=\"gridOrder\" name=\"gridOrder\" value=\""+v+"\" >";
	hidStr=hidStr+"<input type=\"hidden\" id=\"ids\" name=\"ids\" value=\""+allIds[v-2].value+"\" >";		
		var cels = rowToEdit.cells;			
			for(i=0;i<cels.length-2;i++){  	
			var val = document.getElementById(fldArray[i]+i);	
			
			hidStr=hidStr+"<input type=\"hidden\" id=\""+fldArray[i]+"\" name=\""+fldArray[i]+"\" value=\""+val.value+"\" >";
						
			c = isCombo(val);				
				 if(c == true){				
				  	cels[i+1].innerHTML = val.options[val.selectedIndex].text;	
				  	val.value=-1;
				  }else {					
					cels[i+1].innerHTML = val.value;				
					}		
			//cels[i].innerHTML = val.value;
			val.value = "";	
		}
		if(cels.length >0){			
			cels[cels.length-1].innerHTML = '<a href="javascript:void(0)" onclick="deleteRow(this,\''+tableId+'\',\''+fldArray+'\',\''+aBtnId+'\',\''+eBtnId+'\')"><img src="images/delete.gif" border="0" height="15" width="15"><\a>&nbsp;<a href="javascript:void(0)" onclick="fillRow(this,\''+fldArray+'\',\''+tableId+'\',\''+aBtnId+'\',\''+eBtnId+'\')"><img src="images/edit.gif" border="0" height="15" width="15"><\a>'+hidStr;				
			}
	
	formatTable(rowToEdit,tableId);				
}

function deleteRow(tbl, tableId,fldArray,aBtnId,eBtnId) {	
	var eButton = document.all ? document.all[eBtnId] : document.getElementById(eBtnId);	
	var aButton = document.all ? document.all[aBtnId] : document.getElementById(aBtnId);
	var tablem = document.all ? document.all[tableId] : document.getElementById(tableId);
	var obj = tbl.parentNode;
	var r = obj.parentNode;	
	
	if(!validateGridDelete( fldArray, parseInt(r.getAttribute('id'))-2))
		return false;
	
	tablem.deleteRow(r.getAttribute('id'));	
	
	var fldArr = fldArray.split(',');
	for(i=0;i<fldArr.length;i++){
		var val = document.getElementById(fldArr[i]+i);
		c = isCombo(val);	
		if(c == true){						
			val.value=-1;
		  }else {					
			val.value = "";				
		}		
	}
	doAddImage(aButton,false);
	doEditImage(eButton,true);
	//aButton.disabled=false;
	//eButton.disabled=true;
	formatTable(null,tableId);
}
function formatTable(activeRow,tableID) {
	var tablem = document.all ? document.all[tableID] : document.getElementById(tableID);
	var rows = tablem.rows;
	for (var i = 2; i < rows.length; i++) {
		if((i%2) == 0)
			rows[i].style.backgroundColor="#f9f8f6";		
		else
			rows[i].style.backgroundColor="#eeebe9";		
			
		rows[i].setAttribute('id', i);
		showDiv(true,"selectDiv"+i);		
		}
		if(activeRow != null){
			activeRow.style.backgroundColor="#cecec9";					
			showDiv(false,"selectDiv"+activeRow.getAttribute('id'));
		}		
	}
	
function doAddImage(btnId,status){	
	if(status){		 
		btnId.style.backgroundImage='url("images/inactive/add.gif")';
	} else{
		btnId.style.backgroundImage='url("images/active/add.gif")';
	}	
	btnId.disabled=status;		
}

function doEditImage(btnId,status){
	if(status){		 
		btnId.style.backgroundImage='url("images/inactive/edit24x24.gif")';
	} else{
		btnId.style.backgroundImage='url("images/active/edit24x24.gif")';
	}	
	btnId.disabled=status;	
}

var DHTML = (document.getElementById || document.all || document.layers);	
function showDiv(flag,divId)
{
	if (!DHTML) return;
	var x = new getDocumentObj(divId);
	x.style.visibility = (flag) ? 'hidden' : 'visible'
}
function getDocumentObj1(name){
 return document.getElementById(name);
}

function getDocumentObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}