﻿
// JScript1 File
  //Phone numbers
    function IntegerNumberPhone(e, text_box) 
    {  
	var tb_value=new String(text_box.value);

        var iKeyCode = 0; 
        if (window.event) 
            iKeyCode = window.event.keyCode 
        else
            if (e) 
                iKeyCode = e.which;

        if (tb_value.charAt(0)==' ')              
        {
            tb_value=tb_value.substring(1, tb_value.length);
            text_box.value=tb_value;
        }       
                
        if(iKeyCode!=8 && iKeyCode!=16 && iKeyCode!=17 && iKeyCode!=18 && 
            iKeyCode!=37 && iKeyCode!=39 && iKeyCode!=36 && iKeyCode!=9)
            {
                if(iKeyCode>=96 && iKeyCode<=105)
                {
                }
                else
                    if(iKeyCode>=48 && iKeyCode<=57)
                    {
                    }
                else
                {
                    var temp_str="";
                    var last_char;
                    var i;
                    for(i=0; i<tb_value.length; i++)
                    {
                        last_char=tb_value.charAt(i);
                        
                        if(last_char=='0'||last_char=='1'||
                            last_char=='2'||last_char=='3'||
                            last_char=='4'||last_char=='5'||
                            last_char=='6'||last_char=='7'||
                            last_char=='8'||last_char=='9'|| 
                            last_char==' '||last_char=='/'||last_char=='-'||
                            last_char==';'||last_char==',')
                        {
                            temp_str+=last_char;
                        }
                        else
                        {
                            temp_str+="";
                        }
                    }
                
                    text_box.value=temp_str;
                    tb_value=new String(text_box.value);
                }
            }
    }
    
    function IntegerNumber1(e, text_box) 
    {  
        var tb_value=new String(text_box.value);

        var iKeyCode = 0; 
        if (window.event) 
            iKeyCode = window.event.keyCode 
        else
            if (e) 
                iKeyCode = e.which;

        if (tb_value.charAt(0)=='0')              
        {
            tb_value=tb_value.substring(1, tb_value.length);
            text_box.value=tb_value;
        }       
                
        if(iKeyCode!=8 && iKeyCode!=16 && iKeyCode!=17 && iKeyCode!=18 && 
            iKeyCode!=37 && iKeyCode!=39 && iKeyCode!=36 && iKeyCode!=9)
            {
                if(iKeyCode>=96 && iKeyCode<=105)
                {
                }
                else
                    if(iKeyCode>=48 && iKeyCode<=57)
                    {
                    }
                else
                {
                    var temp_str="";
                    var last_char;
                    var i;
                    for(i=0; i<tb_value.length; i++)
                    {
                        last_char=tb_value.charAt(i);
                        
                        if(last_char=='0'||last_char=='1'||
                            last_char=='2'||last_char=='3'||
                            last_char=='4'||last_char=='5'||
                            last_char=='6'||last_char=='7'||
                            last_char=='8'||last_char=='9')
                        {
                            temp_str+=last_char;
                        }            
                    }
                
                    text_box.value=temp_str;
                    tb_value=new String(text_box.value);
                }
            }
    }



//multiline textbox maxLength

function doInput(event,ctrl)
{
   var maxLength=ctrl.attributes["maxLength"].value;
   if(ctrl.value.length==maxLength)  
   {
    ctrl.value=ctrl.value.substring(0,maxLength);
    event.preventDefault();
   }
   if (ctrl.value.length > maxLength)
   {
     ctrl.value=ctrl.value.substring(0,maxLength);
    //alert('VAL380: Максималната должина на текстот во ова поле е '+maxLength+' знаци');
   }
}


function doKeypress(control)
{
    maxLength = control.attributes["maxLength"].value;
    value = control.value;
    if(maxLength && value.length > maxLength-1)
    {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
        //alert('VAL380: Максималната должина на текстот во ова поле е '+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;
    }
    value = control.value;
    if(maxLength && value.length > maxLength-1)
    {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
        //alert('VAL390: Максималната должина на текстот во ова поле е '+maxLength+' знаци.\r\nОстанатиот дел од пренесениот текст ќе биде отсечен!');
    }
}
//end multiline textbox maxLength