﻿

function ChangeLangauge(e,hdId){
   document.getElementById(hdId).value = e.getAttribute("culture") ;

}

function replaceAll(text, strA, strB) 
{
	while ( text.indexOf(strA) != -1)
    {
	 text = text.replace(strA,strB);
    }
   return text;
}
        
function doKeypress(e,evt){
    var maxLength = e.getAttribute("length")
    if(maxLength != null){
        maxLength = parseInt(maxLength);
        var $selection
        if (document.selection){
        // if IE
         $selection=document.selection.createRange().text;
         if($selection.length >= 1)
	        evt.returnValue = true;
         else if(e.value.length > maxLength-1){
            evt.returnValue = false;
         }
        }else if (typeof e.selectionStart != 'undefined'){
           //if Firefox
           $selection = e.value.substring(e.selectionStart, e.selectionEnd)
           if($selection.length >= 1)
	            evt.returnValue = true;
           else if(e.value.length > maxLength-1){
                if(evt.keyCode != 8)
                    evt.preventDefault();
           }
        }
           
    }
}

// Cancel default behavior
function doBeforePaste(e,evt){
    var maxLength = e.getAttribute("length");
    if(maxLength != null){
        if (document.selection)
            evt.returnValue = false;
        else
            evt.preventDefault();
        
    }
}

// Cancel default behavior and create a new paste routine
function doPaste(e,evt){
    var maxLength = e.getAttribute("length")
    if(maxLength != null){
        if (document.selection){
            var oTR = document.selection.createRange();
            evt.returnValue = false;
            var iInsertLength = maxLength - e.value.length + oTR.text.length;
            var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
            oTR.text = sData;
        }
        else{
            //evt.preventDefault();
        }
    }
}

function doBlur(e,evt){
    var maxLength = e.getAttribute("length");
    if(maxLength != null){
        var iInsertLength = maxLength - e.value.length;
        if (!document.selection){
            e.value = e.value.substr(0,maxLength);
        }
    }
}


