﻿
// This function determines the brower of the user and loads the correct css file.
function getBrowserCss() 
{
     if (navigator.appName.indexOf('Internet Explorer') != -1) 
     {
         document.write('<link href="/styles/ie.css" rel="styleSheet" type="text/css" />'); 
     }
     else 
     {
	     document.write('<link href="/styles/mozilla.css" rel="styleSheet" type="text/css" />');
     }
}

// This function prevents the user from entering more than maxLength characters of a textbox
function doKeypress(control)
{
    maxLength = control.attributes["maxLength"].value;
    value = control.value;

    if (maxLength && value.length > maxLength - 1)
    {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
    }
}

// Cancel default behavior
function doBeforePaste(control)
{
    maxLength = control.attributes["maxLength"].value;

    if(maxLength)
    {
        event.returnValue = false;
    }
}

// Cancel default behavior and create a new paste routine
function doPaste(control)
{
    maxLength = control.attributes["maxLength"].value;
    value = control.value;

    if(maxLength)
    {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
        var oTR = control.document.selection.createRange();
        var iInsertLength = maxLength - value.length + oTR.text.length;
        var sData = window.clipboardData.getData("Text").substr(0, iInsertLength);
        oTR.text = sData;
    }
}

//'*****************************************************************************
//'* handleEnter()
//'*
//'* Parameters:
//'*   defaultButton (string) - the button to be clicked
//'*
//'* Return:
//'*   NA
//'*
//'* This subroutine should be added to the onkeydown event of each input control.
//'*
//'* I.E.: Add to Server-Side OnPageLoad event for each input control: 
//'*  TextBox1.Attributes.Add("onkeydown", "return handleEnter('btnF1_Submit');")
//'*
//'* Each time a user presses a key when the input control has focus the 
//'* subroutine determines if enter was pressed and clicks the defaultButton 
//'* provided. Note: It ensure the default button is a valid object. If it  
//'* is not then it does nothing.
//'*****************************************************************************
function handleEnter(defaultButton)
{

    if (navigator.appName.indexOf('Internet Explorer') != -1) 
    {
        //if the user pressed the enter key	
	    if(event.keyCode == 13)
	    {	
	        var isObject = new String(document.getElementById(defaultButton));
	        
	        //ensure the defaultButton is a valid object and it exists
		    if (isObject.indexOf('[object') != -1)
		    {	
		        //click the button provided
			    document.getElementById(defaultButton).click();
		    } 
    		
		    //enter key was hit, always return false
		    return false;
	    }	
	}
	
	//enter key was not pressed, return true
	return true; 	
}

//'*****************************************************************************
//'* handleNoDefaultButton()
//'*
//'* Parameters:
//'*   NA
//'*
//'* Return:
//'*   NA
//'*
//'* This subroutine should be added to the body tag's onkeypress event:
//'*
//'* I.E.: <BODY onkeydown="return handleNoDefaultButton();">
//'*
//'* Each time a user presses a button the subroutine determines if enter was pressed.
//'* If it was the subroutine returns false so the default button (first button
//'* on page is not clicked.
//'*****************************************************************************
function handleNoDefaultButton()
{
    if (navigator.appName.indexOf('Internet Explorer') != -1) 
    {
	    if(event.keyCode == 13)
	    {	
		    return false;
	    }
	}
	
	return true;
}
