﻿// JavaScript File
//====================Default Button Click Event (work for link button also)=====================
//=============Work on all browsers=====================
function clickButton(e,buttonid) {
    //debugger;
    var bt = document.getElementById(buttonid);
    if (typeof(bt) == 'object') {
        if (navigator.appName.indexOf("Netscape") > -1) {
            //The following if construct is used for link button click on mozilla
            if(e.keyCode == 13) {
                if (bt && typeof(bt.click) == 'undefined') {
                    bt.click =  addClickFunction1(bt);
                }//The following else construct is used for image button click on mozilla
                else if (bt && typeof(bt.click) == 'function') {
                    eval(bt.onclick());
                    //return false;                    
                }
            }
        }
        if (navigator.appName.indexOf("Microsoft Internet Explorer") > -1) {
            if (event.keyCode == 13) {
                bt.click();
                return false;
            }
        }
    }
}

function addClickFunction1(bt) {
    //debugger;
    var result = true;
    if (bt.onclick) result = bt.onclick();
    if (typeof(result) == 'undefined' || result) {            
        //eval(bt.href); //In FireFox 3. It is not working (Syntax error shows) that's why I have used window.location to postback
        //var tmpFunc = new Function(bt.href);
        //tmpFunc(); 
        window.location = bt.href;                      
    }
}
//====================End of Default Button Click Event (work for link button also)===================

//=====================Work only on IE=======================================
function doClick(buttonName,e)
{
//the purpose of this function is to allow the enter key to 
//point to the correct button to click.
    //alert(buttonName);
    var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

    if (key == 13)
    {
        //Get the button the user wants to have clicked
        var btn = document.getElementById(buttonName);
        if (btn != null)
        { //If we find the button click it
            
            btn.click();
            //event.keyCode = 0;
            //return false;            
            //e.preventDefault();                                    
        }
    }
}
//=====================End of Work only on IE=======================================
