﻿// JScript File

    var browserName = navigator.appName.toUpperCase(); //Get browser name
    
    //Gets key code according to the browser
    function ReturnKeyCodeOnKeyPress(e)
    {        
        if ((e == "undefined" || e == null) && browserName=="NETSCAPE")       
            return;
                
        if (browserName=="NETSCAPE")                            
            return  e.charCode
        else
            return event.keyCode
    }
    
    //Stops event according to the browser.
    function StopEvent(e)
    {     
        if ((e == "undefined" || e == null) && browserName=="NETSCAPE")       
            return;
            
        if (browserName=="NETSCAPE")                            
            e.preventDefault()
        else
            event.keyCode=""
        return
    }

    // sets value in given control
    // parameter one: ClientId of the control in which value is to be set.
    // parameter two: Value that is to be set in control.
    function SetCtrlValue(ctrlClientId,Value)
    {
        if ($get(ctrlClientId) == null)
            return
       
        ctrl = $get(ctrlClientId) 
        if (ctrl.tagName.toUpperCase() == "INPUT")
        {
            if(ctrl.type.toUpperCase() == "TEXT" || ctrl.type.toUpperCase() == "HIDDEN")
            {
                ctrl.value = Value;
            }    
            else if(ctrl.type.toUpperCase() == "CHECKBOX" || ctrl.type.toUpperCase() == "RADIO")
            {
                ctrl.checked = Value;
            }
        }
        else if(ctrl.tagName.toUpperCase() == "SPAN" || ctrl.tagName.toUpperCase() == "DIV" || ctrl.tagName.toUpperCase() == "TD")
        {
            ctrl.innerHTML = Value;
        }
        else if(ctrl.tagName.toUpperCase() == "SELECT")
        {
            ctrl.value = Value;
        }
    }
    
    // gets value of given control
    // parameter one: ClientId of the control whose value is to be retrive.
    function GetCtrlValue(ctrlClientId)
    {
        if ($get(ctrlClientId) == null)
            return ""
       
        ctrl = $get(ctrlClientId) 
        if (ctrl.tagName.toUpperCase() == "INPUT")
        {
            if(ctrl.type.toUpperCase() == "TEXT" || ctrl.type.toUpperCase() == "HIDDEN")
            {
               return ctrl.value;
            }    
            else if(ctrl.type.toUpperCase() == "CHECKBOX" || ctrl.type.toUpperCase() == "RADIO")
            {
                return ctrl.checked;
            }
        }
        else if(ctrl.tagName.toUpperCase() == "SPAN" || ctrl.tagName.toUpperCase() == "DIV" || ctrl.tagName.toUpperCase() == "TD")
        {
            return ctrl.innerHTML;
        }
        else if(ctrl.tagName.toUpperCase() == "SELECT")
        {
            return ctrl.value;
        }
    }
    
     ////////////////////////// Script for checking Numeric with Decimal ([0-9] & [.]) /////////////////////////
    /* Allow numeric values With Decimal*/
    function CheckValues(obj,type)
    {//debugger
        var CtrlValue = GetCtrlValue(obj.id)
        if (CtrlValue == "")
            return;
            
        var arr = GetChar_Message(type)
        if (arr==null || arr[0]=="")
            return;
        for (var i = 0; i < CtrlValue.length; i++) 
        {
  	        if (arr[0].indexOf(CtrlValue.charAt(i)) == -1) 
  	        {
  	            alert (arr[1]);
  	            obj.focus();
          	    return false;
  	        }
        }
    }
    /* Allow  numeric values */
    function AllowNumbers(e)
    {
        /*if (x!=48 && x!=49 && x!=50 && x!=51 && x!=52 && x!=53 && x!=54 && x!=55 && x!=56 && x!=57 && x!=8)*/                
        var x = ReturnKeyCodeOnKeyPress(e)                     
        if ((x<48 || x>57) && x!=0 && x!=8 && x!=9)
        /* 48 to 58 for 0 to 9, 8 for back space, */
        {
            StopEvent(e)               
        }
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////// 
     
    function GetChar_Message(type)
    {
        var arr = new Array;
        arr[0] = ""
        arr[1] = ""
        
        if (type.toUpperCase() == "D")
        {
            arr[0] = "0123456789."
            arr[1] = "Alphabetic characters not allowed.\n Please remove them and try again."            
        }
        if (type.toUpperCase() == "N")
        {
            arr[0] = "0123456789"
            arr[1] = "Alphabetic characters not allowed.\n Please remove them and try again."            
        }
        return arr
    }
