/* ------------ Allow only number in Input boxes ------*/
function AllowNumericOnly(e)
{
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        if((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode == 8))
        {
           
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        if ((e.charCode >= 48 && e.charCode <= 57) || (e.charCode == 0))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

/* ------------ Allow only Amount in Input boxes ------*/
function AllowAmountOnly(e)
{
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        if((e.keyCode >= 48 && e.keyCode <= 57) ||(e.keyCode == 46)|| (e.keyCode == 8))
        {
           
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        if ((e.charCode >= 48 && e.charCode <= 57) || (e.charCode == 46)|| (e.charCode == 0))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

function AllowAmountOnly(e,obj)
{
    var oKey;
    
	if( navigator.userAgent.toLowerCase().indexOf("msie") != -1 )
	{ 
		oKey = e.keyCode;
	}
	else if( navigator.product == "Gecko" )
	{
		oKey = e.which;
	}
		
	if( (( oKey > 47) && ( oKey < 58)) || oKey == 8 || oKey == 0 || oKey == 46)
    {
        if(oKey == 46 && obj.value.indexOf(".") != -1)
        {	 
                     
            return false;
        }
       
	    return true;
    }
	return false;
}

/*
Used to allow custom characters. Pass all the custom chars in seconde parameter.
Example if you want to allow '(' and ')' then call this function as 
                 fnAllowCustomChars( event , '('')' )
*/
function fnAllowCustomChars( eObj , sChars )
{
    var oKey;
    
	if( navigator.userAgent.toLowerCase().indexOf("msie") != -1 )
	{ 
		oKey = eObj.keyCode;
	}
	else if( navigator.product == "Gecko" )
	{
		oKey = eObj.which;
	}
    
	if( ( oKey > 64 && oKey < 91 ) || ( oKey > 96 && oKey <123 ) || ( oKey > 47 && oKey < 58 ) || oKey == 8 || oKey == 0 )
	{
		return true;
	}
	else 
	{
	    var sAllowChars = new String( sChars );  
	    //var cChar       = "'" + String.fromCharCode( oKey ) + "'";
	    var cChar       = String.fromCharCode( oKey );
	    if( sAllowChars.indexOf( cChar ) != -1 )
	    {
	        return true;
	    }
	}
	return false;
};
    
/*Paste alphanumeric only*/
function pasteAlphaNumberOnly()
{
     var data = clipboardData.getData("Text");
     var regExp = /^[A-Z][a-z][0-9]|\s*$/;
     if(! regExp.test( String( data ) ) )
     {
        event.returnValue = false;
     } 
};

/*Paste alphabets only*/
function pasteAlphaOnly()
{ 
    var data = clipboardData.getData("Text");
    var regExp = /^([A-Z]|[a-z])*$/;
    if(! regExp.test( String( data ) ) )
    {
        event.returnValue = false;
    } 
}; 

 /*Paste numbers only*/
 function pasteNumberOnly()
 { 
      var data = clipboardData.getData("Text");
      var regExp = /^[0-9]*$/;
      if(! regExp.test( String( data ) ) )
      {
        event.returnValue = false;
      } 
 };

/*Paste numbers only*/
 function pasteNumericOnly()
 { 
      var data = clipboardData.getData("Text");
      var regExp = "[0-9/.]*";
      if(! regExp.test( String( data ) ) )
      {
        event.returnValue = false;
      } 
 } ;

/*Fix the max length of multiline textbox
    usage: onkepress="return checkTextAreaMaxLength(this,event,'50')"
*/

function checkTextAreaMaxLength(textBox,e, length)
{
   
        var mLen = textBox["MaxLength"];
        if(null==mLen)
            mLen=length;
        
        var maxLength = parseInt(mLen);
        if(!checkSpecialKeys(e))
        {
         if(textBox.value.length > maxLength-1)
         {
            if(window.event)/*IE*/
              e.returnValue = false;
            else/*Firefox*/
                e.preventDefault();
         }
    }   
};

function checkSpecialKeys(e)
{
    if(e.keyCode !=8 && e.keyCode!=46 && e.keyCode!=37 && e.keyCode!=38 && e.keyCode!=39 && e.keyCode!=40)
        return false;
    else
        return true;
};

/*Open model dilog box*/
function modalWin(url) 
{
    if (window.showModalDialog) 
    {
        window.showModalDialog(url,'name','dialogWidth:800px;dialogHeight:600px;resizable=yes');
    } 
    else 
    {
        window.open(url,'name','height=600px,width=800px,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=yes,resizable=yes,modal=yes');
    }
    return false;
} 
function modalWin2(url) 
{
    if (window.showModalDialog) 
    {
         window.showModalDialog(url,'name','dialogWidth:600px;dialogHeight:520px;resizable=yes');
    } 
    else 
    {
        window.open(url,'name','height=540px,width=600px,toolbar=no,directories=no,status=no,continued from previous linemenubar=no,scrollbars=yes,resizable=yes,modal=yes');
    }
    return false;
} 

function MakeButtonOneClickOnly(validationGroup,e) 
{
    if (typeof(Page_ClientValidate) == 'function')
        Page_ClientValidate(validationGroup);

    if(Page_IsValid)
    {
        document.forms[0].submit();
        window.setTimeout("disableButton('" + 
        e.id + "')", 0);
    }
    else
    {
        return false;
    }
}

function disableButton(buttonID) 
{
    //__('#' + buttonID).val('Wait...');
    __('#' + buttonID).attr('disabled','disabled');
}
