/**
 * @author eerkan
 */

function Only_Numeric(e){
    //alert(window.event.srcElement.value);
    var whichCode = (window.Event) ? e.which : e.keyCode;
    
    if (whichCode == 13) 
        return true; // Enter
    //Modified By Mehmet
    //Thousand Seperator changed "." to ","
    //if (whichCode == 44) return true;  // Comma
    if (whichCode == 46) 
        return true; // Period (nokta)
    if (whichCode > 57) {
        return false;
    }
    if (whichCode < 48 && whichCode > 13) {
        return false;
    }
}

function numbersonly(e){
    var unicode = e.charCode ? e.charCode : e.keyCode;
    
    //if the key isn't the backspace key (which we should allow)
    if (unicode != 8 && unicode != 9) {
        //if not a number
        if ((unicode < 48 || unicode > 57)) {
            //disable key press
            if (unicode == 44 || unicode == 46 || unicode == 188) {
                return true;
            }
            else {
                return false;
            }
        }//end if
        else {
            // enable keypress
            return true;
        }//end else
    }//end if
    else {
        // enable keypress
        return true;
    }//end else
}//end function
function IsNumeric(strString){
    var strValidChars = "0123456789.,";
    var strChar;
    var blnResult = true;
    
    if (strString.length == 0) 
        return false;
    
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

function Amount_onkeyup(thisis, switchThousandSeperator){
    var thousandSeperator = ".";
    var decimalSeperator = ",";
    if (switchThousandSeperator) 
        thousandSeperator = ",";
    
    var tempstr, newstr, str, i, str2;
    var commapos, aftercomma, commacount;
    i = 0;
    str = thisis.value;    
    while (str.substr(0, 1) == "0") str = str.substr(1, str.length - 1) // ilk baslardaki sifiri kaldir.
    thisis.value = str
    while (str.indexOf(thousandSeperator) > 0) str = str.replace(thousandSeperator, "");    
    if (str.indexOf(decimalSeperator) < 0) {// çalışma
        commacount = 0;
        commapos = str.indexOf(";");
        
        if (commapos >= 0) {
            aftercomma = str.substr(commapos);
            str = str.substr(0, commapos);
        }
        else 
            aftercomma = "";
        
        if (str.length > 3) {
            tempstr = str;
            newstr = "";
            while (tempstr.length > 3) {
                newstr = thousandSeperator + tempstr.substr(tempstr.length - 3) + newstr;
                tempstr = tempstr.substr(0, tempstr.length - 3);
            }
            thisis.value = tempstr + newstr + aftercomma;
        }
        else {
            str = str.replace(thousandSeperator, "");
            thisis.value = str
        }
        
    }
    if (str.indexOf(",") != str.lastIndexOf(",")){
        thisis.value = str.substr(0,str.lastIndexOf(","));
    }

    
    return true;
}

function InterestRateControl(thisis,thisismaxlength){
    var interestrate=thisis.value;
    for(var i=0;i<5;i++)
    {
        interestrate=interestrate.replace(',','');
        interestrate=interestrate.replace('.','');
    }
    if(interestrate.length>1)
      {
        interestrate=interestrate.substring(0,1)+','+interestrate.substring(1,interestrate.length);
        thisis.value=interestrate;
        if(thisis.value.length>thisismaxlength)
            thisis.value=thisis.value.substring(0,thisismaxlength);
      } 
      else if(interestrate.length==1)
        thisis.value=interestrate+',';
      else
        thisis.value='';//Eğer ilk karakter . , ise
        
}
