
/*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
 16/11/2009     [003]       HS              Browser Related Issues.
 ***************************************************************************************************************************/

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++)
	{	
	    //[003]start
	    /*
	    if (Table1.rows[selectedRowIndex+i] != undefined )
        {		
		    Table1.rows[selectedRowIndex+i].style.backgroundColor = strCurrentRowColor;				
		}
		*/
	    if (document.getElementById("Table1").rows[selectedRowIndex+i] != undefined )
        {		
		    document.getElementById("Table1").rows[selectedRowIndex+i].style.backgroundColor = strCurrentRowColor;				
		}
		//[003]end
	}
}

function swapBGColorsUnSelected(selectedRowIndex)
{			
	for(i=0;i<unitRowCount;i++)
	{
	    //[003]start
	    /*
	    if (Table1.rows[selectedRowIndex+i] != undefined )
        {
			strCurrentRowColor = Table1.rows[selectedRowIndex+i].style.backgroundColor;
			Table1.rows[selectedRowIndex+i].style.backgroundColor="#D0E2FA";
		}
		*/
	    if (document.getElementById("Table1").rows[selectedRowIndex+i] != undefined )
        {
			strCurrentRowColor = document.getElementById("Table1").rows[selectedRowIndex+i].style.backgroundColor;
			document.getElementById("Table1").rows[selectedRowIndex+i].style.backgroundColor="#D0E2FA";
		}
		//[003]end
	}
}

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();
	}
	
	
}

//[003]start
/*
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 foc1(selectedRowFromPage,topRowCountNotScrollableFromPage,bottomRowCountNotScrollableFromPage,unitRowCountFromPage, isFocusTrueFromPage)
{		
	//selectedRowFromPage =0;
    //topRowCountNotScrollableFromPage =0;
    var blnFound=false;
    
    for( var i = 0; i < document.getElementById("Table1").rows.length -1 ;i++)			
	{	
	    //alert( fnTrim(Table1.rows(i).cells(0).innerText));		       
	    if ( typeof( document.getElementById("Table1").rows[i].cells[0].innerHTML) != 'undefined' ) 
	    {
	        if ( fnTrim(document.getElementById("Table1").rows[i].cells[0].innerHTML) > 0  && blnFound ==false)			
	        {
	            selectedRowFromPage=i;
	            topRowCountNotScrollableFromPage=i;
	            blnFound=true;
		        
	        }
	        if (  fnTrim(document.getElementById("Table1").rows[i].cells[0].innerHTML)> 0 && topRowCountNotScrollableFromPage > 0   )			
	        {
	            bottomRowCountNotScrollableFromPage=i;			       			         
	        }				        		    
	    } 
	}  
	     bottomRowCountNotScrollableFromPage = (document.getElementById("Table1").rows.length - bottomRowCountNotScrollableFromPage) ;
	     //alert('topRowCountNotScrollableFromPage ' + '  '+ topRowCountNotScrollableFromPage+ 'selectedRowFromPage ' + '  '+ selectedRowFromPage  + ' bottomRowCountNotScrollableFromPage ' + bottomRowCountNotScrollableFromPage+ ' unitRowCountFromPage' + unitRowCountFromPage + ' isFocusTrueFromPage ' + isFocusTrueFromPage);
	     foc(selectedRowFromPage,topRowCountNotScrollableFromPage,bottomRowCountNotScrollableFromPage,unitRowCountFromPage, isFocusTrueFromPage);
	 
}
//[003]end

function handleKey(isScrolling, isAltMenu, isShiftMenu, isPagination, e)
{	    
	//[003]start
	//key = window.event.keyCode;	
	var obj    
	var key = null;
    if (window.navigator.appVersion.indexOf("MSIE")==-1)
    {                
        //Mozialla, Safari browser -----------------------------------        
        // Get the ASCII value of the key that the user entered
        if(e.charCode!=null && e.charCode!=undefined && e.charCode > 0)
        {
            key=e.charCode;
            obj=e.target;
        }       
        else if (e.which!=null && e.which!=undefined)
        {
            key=e.which;
            obj=e.target;            
        }
     }
     else
     {     
        key = window.event.keyCode;
        obj=window.event.srcElement;        
     }
    //[003]end
	
//	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
        //[003]start
        if (window.navigator.appVersion.indexOf("MSIE")==-1)
        {
            //Mozialla, Safari browser -----------------------------------
            if (!(e.ctrlKey) && !(e.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.");                            
                            //e.which = 0;
		                    e.stopPropagation();
		                    e.preventDefault();                            
                            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.");
                            //e.which = 0;
		                    e.stopPropagation();
		                    e.preventDefault();
                            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.");
                            //e.which = 0;
		                    e.stopPropagation();
		                    e.preventDefault();
                            return false;
                        }                
                        
                    }
                }
            }
        }
        else
        {        
        //[003]end
            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;
                        }                
                        
                    }
                }
            }
        }  //[003]
    }
	
	
	/* 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
		//[003]start
		//case 13:event.cancelBubble=true;handleKeyEnter();break;//Enter
		
		case 13:
		if (window.navigator.appVersion.indexOf("MSIE")==-1)
        {  
            //e.cancelBubble=true;handleKeyEnter();break;//Enter
            e.stopPropagation();handleKeyEnter();break;//Enter
        }
        else
        {
        	event.cancelBubble=true;handleKeyEnter();break;//Enter
        }    
		//[003]end       
		
		//[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:
		        //[003]onKeyDown();		        
		        onKeyDown(e);       //[003]
    		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";
			//[003]selectedRow = Table1.rows.length-bottomRowCountNotScrollable;
			selectedRow = document.getElementById("Table1").rows.length-bottomRowCountNotScrollable;        //[003]
			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
	{
	    //[003]if(selectedRow > Table1.rows.length-bottomRowCountNotScrollable - unitRowCount)
		if(selectedRow > document.getElementById("Table1").rows.length-bottomRowCountNotScrollable - unitRowCount)      //[003]
		{
			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 = '';

//[003]start
    if (window.navigator.appVersion.indexOf("MSIE")==-1)
    {      
        if (isAltMenu && e.altKey) prefix += 'a';
	    else
	    if (isShiftMenu && e.shiftKey) prefix += 's';
    }
    else
    {
//[003]end
	    if (isAltMenu && window.event.altKey) prefix += 'a';
	    else
	    if (isShiftMenu && window.event.shiftKey) prefix += 's';
	}   //[003]
	
	if(prefix == 'a')
	{    
        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();
	                //[003]start	                		                
	                var ipos1 = strClickAttribute.lastIndexOf("(");
	                var ipos2 = strClickAttribute.lastIndexOf(")");
	                
	                if(ipos1 != -1 && ipos2 != -1)
	                {
	                    strClickAttribute = strClickAttribute.substring(ipos1+1, ipos2);
	                }
//	                if (window.navigator.appVersion.indexOf("MSIE")==-1)
//                    {
//	                    strClickAttribute = strClickAttribute.substring(26,28);	                    
//                    }                  
//                    else
//                    {                       
//                        strClickAttribute = strClickAttribute.substring(strClickAttribute.length-5, strClickAttribute.length-3);
//                    }                      
                    //[003]end  
	                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);
		
		//[003]start
		/*
		window.event.keyCode = 0;
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		return false;
		*/
		if (window.navigator.appVersion.indexOf("MSIE")==-1)
        { 
		    //e.which=0;		   
		    e.stopPropagation();
		    e.preventDefault();		    
		    return false;
        }
        else
        {  
		    //window.event.keyCode = 0;
		    window.event.cancelBubble = true;
		    window.event.returnValue = false;
		    return false;
		}
		//[003]end
		
	}
	else 
	if(isShiftMenu && prefix == 's')
	{
		shiftMenuHandler(key);
	}
	
	//[003]START
	/*
	    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;
        }
    */	    
	
	if (window.navigator.appVersion.indexOf("MSIE")==-1)
    {
        if (e && (e.which > 111 && e.which < 123))
	    {   
		    //e.which = 0;
		    e.stopPropagation();
		    e.preventDefault();
		    return false;
	    }
    }
    else
    {
	    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;
	    }
	}
	//[003]END
}

//Block RIGHT CLICK*******************************
//************************************************
function nocontextmenu(e)
{ 
    //[003]start
    /*
    event.cancelBubble = true 
    event.returnValue = false; 
    return false; 
    */    
    if (window.navigator.appVersion.indexOf("MSIE")==-1)
    {
        e.stopPropagation();
	    e.preventDefault();
	    return false;
    }
    else
    {
        event.cancelBubble = true 
        event.returnValue = false; 
        return false; 
    }
    //[003]end
} 

function norightclick(e) 
{ 
    if (window.Event) 
    { 
        //[003]start
        /*
        if (e.which !=1)       
            return false; 
        */
        if (window.navigator.appVersion.indexOf("MSIE")==-1)
        {
            if (e.which !=1)       
                return false; 
        }
        else
        {
            if (window.event.keyCode !=1)       
                return false; 
        }
        //[003]end
    } 
    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***********
//***********************************************
//[003] start
/*
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 onKeyDown(e) 
{ 
    if (window.navigator.appVersion.indexOf("MSIE")==-1)
    {     
        if  (   (e.altKey) || 
                    ( 
                        (e.charCode == 8) && 
                        (
                            e.target.type != "text" &&
                            e.target.type != "textarea" &&
                            e.target.type != "password"
                        )
		            ) || 
		            ( (e.ctrlKey) && (e.charCode == 78) ) 
		            ||  (e.charCode == 116)
                ) 
 	        {  
 		        //e.charCode = 0;
 	            e.preventDefault();
 	        }
         	
 	        if (e.charCode == 93)
 	        {   
 	            alert("Sorry this key has been disabled!"); 	     		       
 		        //e.charCode = 0;
 	            e.preventDefault();
 	        } 	
    }
    else
    {
        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;
 	    } 	
 	 }
 	    
 } 
//[003] end 
 
function noAltLeftRightArrow(key) 
{    
    switch(key)
    {
        case 37:
        case 39:
        {
            alert("Sorry this key has been disabled!");
	        break;
	    }
	}
}
//***********************************************