
/*Change History*/
/*************************************************************************************************************************
    Date        Marker      By              Issue Description
 -------------------------------------------------------------------------------------------------------------------------
 10/09/2006     [001]       MM              F12 should not work on popup screen -sonam
 10/11/2006     [002]       MM              New function added to handle check box click
 15/04/2008     [DOH-001]   HS              Change the background color of scrolling.
 ***************************************************************************************************************************/

var selectedRow = -1;
var topRowCountNotScrollable = -1;
var bottomRowCountNotScrollable = -1;
var unitRowCount = -1;
var isFocusTrue = false;
function check(obj)
{
	
	newSelectedRow = obj.rowIndex;
	if(newSelectedRow > topRowCountNotScrollable - 1)
	{
		//obj.style.backgroundColor="#999999";
		newSelectedRow = Math.floor(newSelectedRow/unitRowCount)*unitRowCount;
		if (newSelectedRow != selectedRow)
		{
			swapBGColorsUnSelected(newSelectedRow);
			copyCurrentSelectedValues(newSelectedRow);
			swapBGColorsSelected(selectedRow);
			selectedRow = newSelectedRow;
		}
	}
	if(isFocusTrue)
	{
		screenFocusHandler();
	}
}

var strCurrentRowColor = "#FFFFFF";

function swapBGColorsSelected(selectedRowIndex)
{		
	for(i=0;i<unitRowCount;i++)
	{	
	    if (Table1.rows[selectedRowIndex+i] != undefined )
        {		
		    Table1.rows[selectedRowIndex+i].style.backgroundColor = strCurrentRowColor;				
		}
	}
}

function swapBGColorsUnSelected(selectedRowIndex)
{			
	for(i=0;i<unitRowCount;i++)
	{
	    if (Table1.rows[selectedRowIndex+i] != undefined )
        {
			strCurrentRowColor = Table1.rows[selectedRowIndex+i].style.backgroundColor;
			Table1.rows[selectedRowIndex+i].style.backgroundColor ="#919a23";     // ="#EFEFEF"; //[DOH-001]
		}
	}
}

function foc(selectedRowFromPage,topRowCountNotScrollableFromPage,bottomRowCountNotScrollableFromPage,unitRowCountFromPage, isFocusTrueFromPage)
{
	
	isFocusTrue = isFocusTrueFromPage;
	selectedRow = selectedRowFromPage;
	topRowCountNotScrollable = topRowCountNotScrollableFromPage;
	bottomRowCountNotScrollable = bottomRowCountNotScrollableFromPage;
	unitRowCount = unitRowCountFromPage; 
	//TR2.focus();
	//selectedRow = 3;
	//selectedKey = TR3.id;
	swapBGColorsUnSelected(selectedRow);
	//Table1.rows[selectedRow].style.backgroundColor="#999999";
	copyCurrentSelectedValues(selectedRow);
	
	if(isFocusTrue)
	{
		screenFocusHandler();
	}
	
	
}

function foc1(selectedRowFromPage,topRowCountNotScrollableFromPage,bottomRowCountNotScrollableFromPage,unitRowCountFromPage, isFocusTrueFromPage)
{		
	//selectedRowFromPage =0;
    //topRowCountNotScrollableFromPage =0;
    var blnFound=false;
    
    for( var i = 0; i < Table1.rows.length -1 ;i++)			
	{	
	    //alert( fnTrim(Table1.rows(i).cells(0).innerText));		       
	    if ( typeof( Table1.rows(i).cells(0).innerText) != 'undefined' ) 
	    {
	        if ( fnTrim(Table1.rows(i).cells(0).innerText) > 0  && blnFound ==false)			
	        {
	            selectedRowFromPage=i;
	            topRowCountNotScrollableFromPage=i;
	            blnFound=true;
		        
	        }
	        if (  fnTrim(Table1.rows(i).cells(0).innerText)> 0 && topRowCountNotScrollableFromPage > 0   )			
	        {
	            bottomRowCountNotScrollableFromPage=i;			       			         
	        }				        		    
	    } 
	}  
	     bottomRowCountNotScrollableFromPage = (Table1.rows.length - bottomRowCountNotScrollableFromPage) ;
	     //alert('topRowCountNotScrollableFromPage ' + '  '+ topRowCountNotScrollableFromPage+ 'selectedRowFromPage ' + '  '+ selectedRowFromPage  + ' bottomRowCountNotScrollableFromPage ' + bottomRowCountNotScrollableFromPage+ ' unitRowCountFromPage' + unitRowCountFromPage + ' isFocusTrueFromPage ' + isFocusTrueFromPage);
	     foc(selectedRowFromPage,topRowCountNotScrollableFromPage,bottomRowCountNotScrollableFromPage,unitRowCountFromPage, isFocusTrueFromPage);
	 
}

function handleKey(isScrolling, isAltMenu, isShiftMenu, isPagination)
{
	key = window.event.keyCode;
	
	var obj
    obj=window.event.srcElement;
    
    var screenname = new String();
	screenname=document.location.href.substring(document.location.href.lastIndexOf('/')+1,document.location.href.lastIndexOf('.'))
	

    if (screenname.toUpperCase()=='GOODSINWARDDETAILS' || screenname.toUpperCase()=='ORDERDETAILS' || screenname.toUpperCase()=='PDADETAILS')
    {
        	
        //IF ALT, CTRL KEY NOT PRESSED
        
        if (!(window.event.ctrlKey) && !(window.event.altKey))
        {
            if ((key >= 65 &&  key <= 90 ) || (key >= 48 &&  key <= 57 ) || (key >= 96 &&  key <= 105 ))
            {
                if (screenname.toUpperCase()=='GOODSINWARDDETAILS')
                {
                    if ((document.forms[0].txtGINumber.value=='') && (obj.id != 'txtGINumber'))
                    {
                        alert("Please click 'NEW' to generate new Goods Inward No before proceeding.");
                        window.event.keyCode = 0;
		                window.event.cancelBubble = true;
		                window.event.returnValue = false;
		                return false;
		            }
                        
                }
                else if (screenname.toUpperCase()=='ORDERDETAILS')
                {
                    if ((document.forms[0].txtGONo.value=='') && (obj.id != 'txtGONo'))
                    {
                        alert("Please click 'NEW' to generate new Order No before proceeding.");
                        window.event.keyCode = 0;
		                window.event.cancelBubble = true;
		                window.event.returnValue = false;
		                return false;
		            }                
                
                }
                else if (screenname.toUpperCase()=='PDADETAILS')
                {
                    if ((document.forms[0].txtPDA.value=='') && (obj.id != 'txtPDA'))
                    {
                        alert("Please click 'NEW' to generate new PDA No before proceeding.");
                        window.event.keyCode = 0;
		                window.event.cancelBubble = true;
		                window.event.returnValue = false;
		                return false;
		            }                
                    
                }
            }
        }
    
    }
	
	//alert(key);
	/* Handling of Keys F1 to F12*/
	switch (key)
	{
		case 112:handleKeyF1();break;// F1
		case 113:handleKeyF2();break;// F2
		case 114:handleKeyF3();break;// F3
		case 115:handleKeyF4();break;// F4
		case 116:handleKeyF5();break;// F5
		case 117:handleKeyF6();break;// F6
		case 118:handleKeyF7();break;// F7
		case 119:handleKeyF8();break;// F8
		case 120:handleKeyF9();break;// F9
		case 121:handleKeyF10();break;// F10
		case 122:handleKeyF11();break;// F11
		case 13:event.cancelBubble=true;handleKeyEnter();break;//Enter
		//[001]case 123:if () window.location.href="../ImpactMain/Welcome.aspx";break;// F12
		case 123:
		//alert(window.location.href.toUpperCase().indexOf('POPUP'));
		if (window.location.href.toUpperCase().indexOf('POPUP')== -1 ) 
		window.location.href="../ImpactMain/Welcome.aspx";
		break;// F12
		
		
		default:
		        onKeyDown();
    		break;
	}
	
	if(isPagination)
	{
		switch (key)
		{
			//case 36:getFirstPage();break;   //home
			//case 35:getLastPage();break;    //end
			case 33:getPreviousPage();break;//pageup
			case 34:getNextPage();break;    //pagedown
		}

	}
	
	if(isScrolling && key == 38) //up key
	{
		if(selectedRow < topRowCountNotScrollable + unitRowCount)
		{
			swapBGColorsSelected(selectedRow);
			//Table1.rows[selectedRow].style.backgroundColor="F7F7F7";
			selectedRow = Table1.rows.length-bottomRowCountNotScrollable;
			swapBGColorsUnSelected(selectedRow);
			//Table1.rows[selectedRow].style.backgroundColor="#999999";
			copyCurrentSelectedValues(selectedRow);
		}
		else
		{
			swapBGColorsSelected(selectedRow);
			//Table1.rows[selectedRow].style.backgroundColor="F7F7F7";
			swapBGColorsUnSelected(selectedRow-unitRowCount);
			//Table1.rows[selectedRow-unitRowCount].style.backgroundColor="#999999";

			selectedRow = selectedRow-unitRowCount;
			copyCurrentSelectedValues(selectedRow);
		}
		if(isFocusTrue)
		{
			screenFocusHandler();
		}
	}
	else if(isScrolling && key == 40) //down key
	{
		if(selectedRow > Table1.rows.length-bottomRowCountNotScrollable - unitRowCount)
		{
			swapBGColorsSelected(selectedRow);
			//Table1.rows[selectedRow].style.backgroundColor="F7F7F7";
			selectedRow = topRowCountNotScrollable;
			swapBGColorsUnSelected(selectedRow);
			//Table1.rows[selectedRow].style.backgroundColor="#999999";
			copyCurrentSelectedValues(selectedRow);
		}
		else
		{
			selectedRow = selectedRow+unitRowCount;
			//alert("Selected Row Count"+selectedRow);
			swapBGColorsSelected(selectedRow-unitRowCount);
			swapBGColorsUnSelected(selectedRow);
			//Table1.rows[selectedRow].style.backgroundColor="F7F7F7";

			//Table1.rows[selectedRow+unitRowCount].style.backgroundColor="#999999";

			copyCurrentSelectedValues(selectedRow);
		}
		if(isFocusTrue)
		{
			screenFocusHandler();
		}
	}
	
	var prefix = '';

	if (isAltMenu && window.event.altKey) prefix += 'a';
	else
	if (isShiftMenu && window.event.shiftKey) prefix += 's';
	if(prefix == 'a')
	{
        //alert(key);
        var obj = null;	    
    	for(i=0;i<document.forms[0].length;i++)
        {
    	    if (document.forms[0].elements[i].type=="button")
	        {
	            if (document.forms[0].elements[i].getAttribute("onclick") != null)
	            {
	                var strClickAttribute = new String();
	                strClickAttribute=document.forms[0].elements[i].getAttribute("onclick").toString().toUpperCase()
	                strClickAttribute = strClickAttribute.substring(38,40);
	                if (strClickAttribute == key)
	                {
	                    //status=document.forms[0].elements[i].id
	                    obj=document.forms[0].elements[i];
    	                break;
    	            }
	            }
    
	        }
        }

        if (obj!=null)
        {
            if (!obj.disabled)
                altMenuHandler(key);    
        }
		
		noAltLeftRightArrow(key);
		
		window.event.keyCode = 0;
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		return false;
		
	}
	else 
	if(isShiftMenu && prefix == 's')
	{
		shiftMenuHandler(key);
	}
	
	if (window.event && (window.event.keyCode > 111 && window.event.keyCode < 123))
	{
		//alert("Hi");
		window.event.keyCode = 0;
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		return false;
	}
}

//Block RIGHT CLICK*******************************
//************************************************
function nocontextmenu()
{ 
    event.cancelBubble = true 
    event.returnValue = false; 
    return false; 
} 

function norightclick(e) 
{ 
    if (window.Event) 
    { 
        if (e.which !=1) 
            return false; 
    } 
    else if (event.button !=1) 
    { 
        event.cancelBubble = true 
        event.returnValue = false; 
        return false; 
    } 
}
//[002]
function handleCheckbox()
{
}
//[002]
document.oncontextmenu = nocontextmenu; 
document.onmousedown = norightclick; 
//***********************************************

//Block backspace, Control N onKeyDown***********
//***********************************************
function onKeyDown() 
{    
    if  (   (event.altKey) || 
            ( 
                (event.keyCode == 8) && 
                (
                    event.srcElement.type != "text" &&
                    event.srcElement.type != "textarea" &&
                    event.srcElement.type != "password"
                )
		    ) || 
		    ( (event.ctrlKey) && (event.keyCode == 78) ) 
		    ||  (event.keyCode == 116)
        ) 
 	{ 	 
 		event.keyCode = 0;
 		event.returnValue = false;
 	}
 	
 	if (event.keyCode == 93)
 	{   
 	    alert("Sorry this key has been disabled!"); 	    
 		event.keyCode = 0;
 		event.returnValue = false;
 	} 	
 }
function noAltLeftRightArrow(key) 
{    
    switch(key)
    {
        case 37:
        case 39:
        {
            alert("Sorry this key has been disabled!");
	        break;
	    }
	}
}
//***********************************************