
//Pop-up window
var upWn = null;
function Download1(urlNo,mpid,asnid,cid,stid,viewg,raw,adj,pct,ltr,max,rno){
		var features = "scrollbars=no,locationbar=no,statusbar=no,personalbar=no,menubar=no,resize=no,width=10px,height=10px";
		var winName = "upWind";
		var theURL = "grreport" + urlNo + "dwn.aspx";
			theURL += "?viewg=" + viewg + "&mpid=" + mpid + "&asnid=" + asnid + "&cid=" + cid + "&stid=" + stid + "&ra=" + raw + "&ad=" + adj + "&pc=" + pct + "&ltr=" + ltr + "&mx=" + max + "&rno=" + rno;
		
		// if window not open then open
		CloseMyWind1();
		
		//new window
		 upWn = window.open(theURL,winName,features);
		 upWn.blur();
	}
	function CloseMyWind1(){
		if(upWn != null){
			if(!upWn.closed) {
			//close existing, then open new
			upWn.close();
			}
		}
	}
var myWind3 = null;
function newWindow3(theURL)
	{
		var features = "scrollbars=yes,menubar=yes,resize=yes,width=700px,height=500px";
		var winName = "hlpWindow";
		
		// if window not open then open
		CloseMyWind3();
		
		//new window
		 myWind3 = window.open(theURL,winName,features);
	}
	function CloseMyWind3()
	{
		if(myWind3 != null)
		{
			if(!myWind3.closed) {
			//close existing, then open new
			myWind3.close();
			}
		}
	}
//check delete
		function CheckDelete(index,cntrId)
		{
			var a = window.confirm("Are you sure you want to delete this item?");
			if(a == true)
			{
				
				//form1.submit;
				var theform = document.frmPg;
				theform.deleteItem.value = index;
				theform.cntrId.value = cntrId;				
				theform.submit();
			}			
		}

		function ChkDelSt(index,cntrId,stName)
		{
			var a = window.confirm("Are you sure you want to delete " + stName + "?");
			if(a == true)
			{
				//form1.submit;
				var theform = document.frmPg;
				theform.deleteItem.value = index;
				theform.cntrId.value = cntrId;				
				theform.submit();
			}			
		}


function HndlKeyInp(e, inp)
{
	//DataGrid1__ctl2_txtGrade  14, 15, 16
	//DataGrid1__ctl2_txtRsn
	//DataGrid1__ctl2_chkDcnt
   if(e.which){ 
	keycode = e.which;
	}
	else {
	keycode = e.keyCode;  
	}
	
		var hdn = document.getElementById("hdnTxt");

	//Get the controls' index - make it a Number
	var inpId = inp.id;
	var indx = inpId.indexOf("__ctl");
		indx +=5;
	var ctlNumber = inpId.charAt(indx); // first number
	if(inpId.charAt(indx + 1) != "_")
	{
		ctlNumber += inpId.charAt(indx + 1);
		if(inpId.charAt(indx +2) != "_")
		{
			ctlNumber += inpId.charAt(indx +2);
		}
	}
	var newCtlNo = parseInt(ctlNumber);
		
	//Enter ----------- --------------------------------
	if(keycode==13 ){
	  	if(inpId.indexOf("chkDcnt") > 0){ //Check or Uncheck box
			if(inp.checked){
			inp.checked = false;
			}
			else{
			inp.checked = true;
			}
		return false;
		}	
		else{ //not check box
			newCtlNo +=1
			var nextGrInp = "Dg1__ctlX_txtGrade";
			var nextInpId = nextGrInp.replace("X",newCtlNo);
			var nextInp = document.getElementById(nextInpId);
			if(nextInp){
			nextInp.focus();
			nextInp.select();
			}
		return false;	
		}	
	}
	
	//down arrow or Up --------------------------------
	if(keycode==40 || keycode==38){
		if(keycode==38 ){  //up arrow
			newCtlNo -= 1;
		}else { //Enter or down arrow
		newCtlNo += 1;
		}
		var nextInpId = inpId.replace(ctlNumber,newCtlNo);
		var nextInp = document.getElementById(nextInpId);
		//alert("nextInp.id:" + nextInp.id);
		if(nextInp){
		nextInp.focus();
		nextInp.select();
		}
	return false;	
	}
	
	//left arrow ----------------------------------------------
	if(keycode==37 ){  
		//1. check which input
		//2. move in correct direction to next
		if(inpId.indexOf("chkDcnt") > 0) //check box
		{
			var nextInpId = inpId.replace("chkDcnt","txtGrade");
			var nextInp = document.getElementById(nextInpId);
			if(nextInp){
				nextInp.focus();
				nextInp.select();
			}
		return false;
		}
		else if(inpId.indexOf("Rsn") > 0){  //input
			var nextInpId = inpId.replace("txtRsn","chkDcnt");
			var nextInp = document.getElementById(nextInpId);
			if(nextInp){
				hdn.select();
				nextInp.focus();
			}
		return false;
		}
		else{  //move up a line if possible
			var nextInpId = inpId.replace("Grade","Rsn");
				newCtlNo -=1;
				nextInpId = nextInpId.replace(ctlNumber,newCtlNo);
			var nextInp = document.getElementById(nextInpId);
			if(nextInp){
				inp.blur();
				nextInp.focus();
				nextInp.select();
			}
		return false;
		}		
	}
	
	//right arrow ----------------------------------------------
	if(keycode==39 ){  
		//1. check which input
		//2. move in correct direction to next
		if(inpId.indexOf("chkDcnt") > 0)
		{
			//same ctlNo
			var nextInpId = inpId.replace("chkDcnt","txtRsn");
			var nextInp = document.getElementById(nextInpId);
			if(nextInp){
				nextInp.focus();
				nextInp.select();
			}
		return false;
		}
		else if(inpId.indexOf("Grade") > 0){
			//same ctlNo
			var nextInpId = inpId.replace("txtGrade","chkDcnt");
			var nextInp = document.getElementById(nextInpId);
			if(nextInp){
				hdn.select();
				nextInp.focus();
			}
		return true;
		}
		else{
			//move up a line if possible
			var nextInpId = inpId.replace("Rsn","Grade");
				newCtlNo +=1;
				nextInpId = nextInpId.replace(ctlNumber,newCtlNo);
			var nextInp = document.getElementById(nextInpId);
			if(nextInp){
				nextInp.focus();
				nextInp.select();
			}
		return false;
		}
	}
	
return true;	
 
}

