function VirgulAyirici(deger){
      if (deger.value.length >= 3)
            { deger.value = new String(deger.value+"1");
              EditedTutar(deger);
              a = deger.value;
              b = deger.value.length - 1;
              deger.value = deger.value.substring(0,b);
             }   
  }

  function VirgulKoy(deger){
	deger.value=Comma(deger.value)
  }

  function Comma(SS) { var T='', S=String(SS), L=S.length-1, C, j
  for (j=0; j<=L; j++) {
    T+=C=S.charAt(j)
    if ((j < L) && ((L-j)%3 == 0) && (C != '-')) T+='.' }
  return T }



function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ',') || (s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}



function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }


function SayiKontrol(e,t) {

	olay = document.all ? window.event : e;
	tus = document.all ? olay.keyCode : olay.which;
	//alert(tus);
	//if(tus==8){t.value=""}
	if((tus<48||tus>57) && (tus != 8)) {
		if(document.all) { olay.returnValue = false; } else { olay.preventDefault(); }
	} else {
		if(t){
		VirgulAyirici(t);
		}
	}
}


function VirgulleriAt(deger,x)
{

	if (x!=1)
	var TmpStr,z,sonuc,j,y = deger.value
	else
	var TmpStr,z,sonuc,j,y = deger
    sonuc = false;
    for(z=0; z < y.length; z++)
          if (y.charAt(z) >= '1' && y.charAt(z) <= '9')
          { 
                TmpStr = y.charAt(z);
                j = z + 1;
                sonuc = true;
                z = y.length;
          }
   if (sonuc)
    {
        for(z=j; z < y.length; z++)
           if (y.charAt(z) >= '0' && y.charAt(z) <= '9')
               TmpStr = new String(TmpStr+y.charAt(z));
        str = TmpStr;
		if (x==null)
        deger.value=TmpStr
		else
		return TmpStr
	}
}

function EditedTutar(a) 
  { var str,str1,b,x,y,z,i,j,sonuc = false;
    var dolu = true;
    b = a.value;
    for(z=0; z < b.length; z++)
    {  if (b.charAt(z) >= '1' && b.charAt(z) <= '9')
        { 
          str1 = b.charAt(z);
          j = z + 1;
          sonuc = true;
          z = b.length;
        }
    }
    if (sonuc)
    {
      for(z=j; z < b.length; z++)
      {      
        if (b.charAt(z) >= '0' && b.charAt(z) <= '9')
          str1 = new String(str1+b.charAt(z));
      }  
      x = str1;
      y = x.length;
      z = y % 3;
      y = (y - z) / 3 + 1;
      if (z != 0)
        str = x.substring(0,z);
      for(i = 1; i < y ; i++)
        if (str != null)
          str = new String(str+"."+x.substring((z+(i-1)*3),(z+i*3)));
        else
          str = x.substring(0,3);
      a.value = new String(str);
   }  
   else
   { 
     sonuc = true;
     a.value = 0;
   }
   return sonuc;
  }


function FormatTextBox(o)
{
	if (o.value != "" && o.value != null && parseInt(o.value) != 0)
	{
		o.value = Comma(VirgulleriAt(o.value,1));
	}
	else
	{
		o.value = "0";
	}
}

function log(obj) {
	var val = obj.value;

	var count = 0;
	for (var i = 0; i < val.length; i++) {
		if (val[i] == ".") {
			count++;

		}
	}
	for (var i = 0; i < count; i++) {
		val = val.replace(".", "");
	}

	//val = val.replace(/./g, "");
	var test = val.replace(/\./g, "");
	if (test != "")
	{
		val = test;
		obj.value = FormatNumberBy3(val, ",", ".")
	}

	//var s=".";

	//val = val.replace(/./g, "")
	//console.log(val + "  " + count);
	//obj.value = FormatNumberBy3(val, ",", ".")
}

function FormatNumberBy3(num, decpoint, sep) {
	// check for missing parameters and use defaults if so
	if (arguments.length == 2) {
		sep = ",";
	}
	if (arguments.length == 1) {
		sep = ",";
		decpoint = ".";
	}
	// need a string for operations
	num = num.toString();
	// separate the whole number and the fraction if possible
	a = num.split(decpoint);
	x = a[0]; // decimal
	y = a[1]; // fraction
	z = "";


	if (typeof (x) != "undefined") {
		// reverse the digits. regexp works from left to right.
		var i = x.length-1;
		for (i = x.length - 1; i >= 0; i--)
			z += x.charAt(i);
		// add seperators. but undo the trailing one, if there
		z = z.replace(/(\d{3})/g, "$1" + sep);
		if (z.slice(-sep.length) == sep)
			z = z.slice(0, -sep.length);
		x = "";
		// reverse again to get back the number
		for (i = z.length - 1; i >= 0; i--)
			x += z.charAt(i);
		// add the fraction back in, if it was there
		if (typeof (y) != "undefined" && y.length > 0)
			x += decpoint + y;
	}
	return x;
}
