function isValidCard(CreditCard){
   var Validity = false;
   var LN = CreditCard.length;
   if ((15 <= LN) && (LN <= 16)) {
      LN --;
      CheckSum = 0;
      Dbl = false;
      if (LN==14) {
         var start  = 0;
         var end    = 7;
         var offset = 1;
         var cc;
         var ccresu = 0;
         var j;
         var a;
         var result=0;
         cc = new Array();
         cardnumber = new Array();
         for ( j=0;j< CreditCard.length; j++) {
            cardnumber[j] = CreditCard.substring(j,j+1);
         }
         for ( j=start;j<end; j++) {
            cc[j] = cardnumber[(j*2)+offset] * 2;
            if (cc[j]>9) {
               ccresu += Math.floor((cc[j]/10) + (cc[j]%10));
            } else {
               ccresu += cc[j];
            }
         }
         for ( j=start;j< end + offset; j++) {
            result += cardnumber[(j*2)+1-offset]-0;
         }
         result += ccresu;
         result = result%10;
         if (result != 0)
            return(Validity);
      } else {
         for (Idx = LN; Idx >= 0; Idx --) {
            Digit = CreditCard.substr(Idx, 1);
            if (("0" <= Digit && Digit <= "9")  || Digit == " " || Digit == "-") {
               if (Digit != " " && Digit != "-") {
                  Digit -= "0";
                  if (Dbl) {
                     Digit += Digit;
                     if (Digit > 9)
                        Digit -= 9;
                  }
                  Dbl = !Dbl;
                  CheckSum += Digit;
                  if (CheckSum > 9) {
                     CheckSum -= 10;
                  }
               }
            } else {
               return(Validity);
            }
         }
         if (CheckSum!=0)
            return(Validity);
         else
            return(true);
      }
   }
}

function LeapYear(intYear) {
 if (intYear % 100 == 0) {
  if (intYear % 400 == 0) { return true; }
 }
 else {
  if ((intYear % 4) == 0) { return true; }
 }
 return false;
}


function verifyDate (intYear,intMonth,intDay) {
 if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intDay > 31 || intDay < 1)) {
 return false;
 }
 if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intDay > 30 || intDay < 1)) {
 return false;
 }
 if (intMonth == 2) {
  if (intDay < 1) {
   return false;
  }
  if (LeapYear(intYear) == true) {
   if (intDay > 29) {
    return false;
   }
  }
  else {
   if (intDay > 28) {
    return false;
   }
  }
 }
 return true;
}

function findComboValue(tempcombo,searchvalue){
var found = false;
var index = 0;
var strlength = searchvalue.length;
if(strlength > 0){
if(tempcombo.selectedIndex == -1){tempcombo.selectedIndex = 0;}
while(!found && index < tempcombo.length){
// field may be object reference or key
  if(tempcombo.options[index].value.length >= strlength){
    if(stringToUpperStr(tempcombo.options[index].value.substring(0,strlength)) == searchvalue){
     found = true;
     tempcombo.selectedIndex = index;
    }
	else
	{
	   index++;
	 }
  }
  else{
   index++;
  }
}
}
}

function setFocus(Ctrl) {
	Ctrl.focus();
	return false;
}

function checkBoxSetter (checkBox,hiddenField) {
    if (!(checkBox.checked))
       hiddenField.value = checkBox.value;
    else {
       if (checkBox.value=="Y")
         hiddenField.value = "N";
       else if (checkBox.value=="0")
         hiddenField.value = "1";
       else if (checkBox.value=="N")
         hiddenField.value = "Y";
       else if (checkBox.value=="1")
         hiddenField.value = "0";
    }
}

function concatTwoFields(temp1,temp2,temp3)
{
  temp1.value = temp2.value + temp3.value;
  ////alert(temp1.value);
}

function concatTwoFieldsAndChar(temp1,temp2,temp3,ch)
{
  temp1.value = temp2.value + ch + temp3.value;
  //alert(temp1.value);
}

function concatStringField(temp1,temp2)
{
  temp2.value = temp1 + temp2.value ;
  ////alert(temp1.value);
}


function concatThreeFields(temp1,temp2,temp3,temp4)
{
  tempstring = temp2.value + temp3.value + temp4.value;
  if(tempstring.length == 10) {
   temp1.value = tempstring.length;
  }
  else {
   temp1.value = "";
  }
  //alert(temp1.value);
}

function concatThreeDateFields(temp1,temp2,temp3,temp4)
{

  temp1.value = temp2.value + "-" + temp3.value + "-" + temp4.value;
  //alert(temp1.value);
}

//trims leading and trailing spaces
function trimSpaces(temp)
{
  //trailing
  while(''+temp.value.charAt(temp.value.length-1)==' ')
  temp.value=temp.value.substring(0,temp.value.length-1);

  //leading
  while(''+temp.value.charAt(0)==' ')
   temp.value=temp.value.substring(1,temp.value.length);
}

// textbox'a girilen ilk karakter 0 olamaz
// onKeyUp() EVENTINDE KULLANILABILIR, onBlur() EVENTINDE ISE YARAMAZ. CUNKU METOD SON KARAKTERI SILMEYE AYARLI
function contTel(temp, length){
	tempstring = temp.value;
	if ( (tempstring.length == 1) || ((tempstring.length==4) && (length == 10)) ) {
		ch = tempstring.substring(tempstring.length-1 ,tempstring.length);
		if(ch == "0")
			temp.value = tempstring.substring(0 ,tempstring.length-1);
	}
}

//textbox'a girilen ilk karakter 0 olamaz
//type of parameter temp: textbox(<input type="text")
//type of parameter len: integer(textbox a girilmesi gereken input'un uzunlugu)
//usage: girilen sayilarin 1. ve 4. karakterlerinin 0 olup olmamasını kontrol eder.
//3 karakterli prefixlerde, 7 karakterli telefonlarda ve 10 karakterli telefon nolarda kullanilabilir.
//return: 1. ve ya 4. karakterde 0 bulursa, false dondurur.
//SUBMIT METODUNA BASILDIGINDA CALISTIRILAN VALIDATE() METODU ICINDE KULLANILABILIR
function checkPhone(temp, len){
	var tempstring = temp.value;
    if ( containsTurkishCharacters(temp) ) {
			cutTurkishCharacters(temp);
			return false;
	}
  if(tempstring.length != len)
        return false;
	//alert(tempstring.length);
	if (tempstring.charAt(0) == 0 && (tempstring.length == 3 || tempstring.length == 7))
		return false;
	if ( (tempstring.charAt(0) * tempstring.charAt(3) == 0) && (tempstring.length == 10) )
		return false;
	return true;
}

//karakter siniri olan form alanlari icin.
//onKeyUp ve onSubmit'te kullanilabilir.
function checkTextLength(myFormElement, size, elementLabel, language){
	var length = myFormElement.value.length;
	if (length > size){
		alert(elementLabel + " alanına en fazla " + size + " karakter girişi yapabilirsiniz.");
		myFormElement.value = myFormElement.value.substring(0, size);
		return false;
	}
	return true;
}

//trims all spaces PARAMETER IS OBJ
function trimAllSpaces(temp)
{
	tempstring = temp.value;
	tempstr = "";
	for (var i = 0; i < tempstring.length; i++){
		var ch = tempstring.substring(i, i + 1);
		if (ch == ' '){
		}
        else
        {
        tempstr = tempstr + ch;
          }

	}

     temp.value = tempstr;
}

//trims all spaces PARAMETER IS STRING
function trimAllSpacesStr(tStr)
{

	tempstring = tStr;
    tempstr = "";
	for (var i = 0; i < tempstring.length; i++){
		var ch = tempstring.substring(i, i + 1);
		if (ch == ' '){
		}
        else
        {
        tempstr = tempstr + ch;
          }

	}

     return tempstr;

}

// textbox'a girilen TÜRKÇE karakteri kabul etmiyor
function noTurkishCharacters(temp){
	 tempstring = temp.value;
         ch = tempstring.substring(tempstring.length -1 ,tempstring.length);

         if (ch == 'ı' || ch == 'İ' || ch == 'Ş' || ch == 'ş' || ch == 'Ğ' || ch == 'ğ'
            || ch == 'Ç' || ch == 'ç' || ch == 'Ü' || ch == 'ü' || ch == 'Ö' || ch == 'ö')
            temp.value = tempstring.substring(0 ,tempstring.length-1);
}


// türkçe karakterleri eng yapıyo.
function convertToEnglish(tStr){

	tempstring = tStr;
	tempstr = "";
    tempch = '';
	for (var i = 0; i < tempstring.length; i++){

		var ch = tempstring.substring(i, i + 1);
        tempch = ch;
		if (ch == 'İ') {tempch = 'i';}
		if (ch == 'I') {tempch = 'i';}
        if (ch == 'ı') {tempch = 'i';}
        if (ch == 'Ş') {tempch = 's';}
        if (ch == 'ş') {tempch = 's';}
        if (ch == 'Ğ') {tempch = 'g';}
        if (ch == 'ğ') {tempch = 'g';}
        if (ch == 'Ç') {tempch = 'c';}
        if (ch == 'ç') {tempch = 'c';}
        if (ch == 'Ü') {tempch = 'u';}
        if (ch == 'ü') {tempch = 'u';}
        if (ch == 'Ö') {tempch = 'o';}
        if (ch == 'ö') {tempch = 'o';}

      	tempstr = tempstr + tempch;

     }


    return tempstr;

}

//türkçe karakterleri cut ediyo...
function cutTurkishCharacters(temp)
{
	tempstring = temp.value;
	tempstr = "";
	for (var i = 0; i < tempstring.length; i++){
		var ch = tempstring.substring(i, i + 1);
		if (ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
            && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö')
			tempstr = tempstr + ch;
    }
    temp.value = tempstr;
}

//Turkce karakterin olup olmadigini kontrol ediyor.
//Varsa true donduruyor
function containsTurkishCharacters(temp)
{
	tempstring = temp.value;
	tempstr = "";
	for (var i = 0; i < tempstring.length; i++){
		//alert('ch: ' + ch);
		var ch = tempstring.substring(i, i + 1);
		if (ch == 'İ' || ch == 'ı' || ch == 'Ş' || ch == 'ş' || ch == 'Ğ' || ch == 'ğ'
            || ch == 'Ç' || ch == 'ç' || ch == 'Ü' || ch == 'ü' || ch == 'Ö' || ch == 'ö'){
            //alert('ch: ' + ch);
			return true;
		}
    }
    return false;
}

//form submit ederken calistirilan validate metodu icinde kullanilmali
//isEmail metodu hata verince bunu yazdim. ama arada herhangi bir fark yok isEmail ile isEmail2 arasinda??????????
function isEmail2(temp, language){

	var missingAt, missingDot, wrongBeginningCharacter,
		duplicateCharacter, lengthIsZero, incorrectEmail, turkishCharacters;
	
	//initialize alert messages based on the language
	if (language == "EN") {
		missingAt =  "You must include \"@\" sign in your e-mail address.";
		missingDot = "You must include \".\" sign in your e-mail address.";

		wrongBeginningCharacter = "E-mail address cannot start with \"@\".";
		duplicateCharacters = "E-mail address cannnot contain multiple \"@\" characters.";
		lengthIsZero = "Please enter your E-MAIL address!";
		incorrectEmail ="Please correct your E-MAIL address!";
		turkishCharacters = "Your E-MAIL address cannot contaion Turkish characters!";
	}
	else {
		missingAt = "E-POSTA adresinde  \"@\" işareti eksik";
		missingDot = "E-POSTA adresinde  \".\" işareti eksik!";
		wrongBeginningCharacter = "E-POSTA adresi \"@\" karakteri ile başlayamaz.";
		duplicateCharacters = "E-POSTA adresinde  birden fazla \"@\" işareti olamaz.";
		lengthIsZero = "Lütfen E-POSTA adresinizi giriniz!";
		incorrectEmail = "Lütfen E-POSTA adresinizi doğru giriniz!";
		turkishCharacters = "E-POSTA adresiniz Türkçe karakter içeremez.";
	}

	//alert('isEmail2');
    //hatali karakterlerin silindikten sonra, email adresinin boyutu 0 degilse kontrollere devam
    if (temp.value.length != 0) {
		//@ ve ya . karakteri eksik
		//alert('isEmail2');
        if (temp.value.indexOf('@', 0) == -1 ) {
            alert(missingAt);
            return false;
        }

	    else if ( (temp.value.indexOf('.', 0) == -1) ) {
            alert(missingDot);
            return false;
        }

		//@ isareti ile baslayamaz
		else if (temp.value.indexOf('@') == 0) {
			alert(wrongBeginningCharacter);
			return false;
		}

		//2 tane @ isareti olamaz
		else if (temp.value.substring(temp.value.indexOf('@') + 1).indexOf('@') != -1) {
			alert(duplicateCharacters);
			return false;
		}

		//son noktadan sonra 1 ve ya 0 karakter varsa hata verir.
		//noktadan sonra 1 karakter:temp.value.length - temp.value.lastIndexOf(".")=2
		//noktadan sonra 0 karakter:temp.value.length - temp.value.lastIndexOf(".")=1
		else if ( (temp.value.length - temp.value.lastIndexOf(".")) <= 2 ){
			alert(incorrectEmail);
			return false;
		}

		//@'ten sonra nokta kullanilmis mi?
		else if ( (temp.value.lastIndexOf(".") - temp.value.lastIndexOf("@")) <= 2 ){
			alert(incorrectEmail);
			return false;
		}

		//turkce karakter kontrolu
		else if ( containsTurkishCharacters(temp) ) {
			alert(turkishCharacters);
			cutTurkishCharacters(temp);
			return false;
		}
		
		//invalid karakter kontrolu
		else if ( !isCharNumericAll(temp,'@', '.', '-', '_', '') ) {
			alert(incorrectEmail);
			return false;
		}
		//alert('containsTurkishCharacters(temp)' + containsTurkishCharacters(temp));
	}
	else {
		alert(lengthIsZero);
		return false;
    }

	//alert(temp.value);
	return true;
}

//EMail alanini kontrol ediyor
//ikinci parametre kullanilan dilin parametresi
function isEMail(temp, language){
	var missingAt, missingDot, wrongBeginningCharacter,
		duplicateCharacter, lengthIsZero, incorrectEmail;

	//initialize alert messages based on the language
	if (language == "EN") {
		missingAt =  "You must include \"@\" sign in your e-mail address.";
		missingDot = "You must include \".\" sign in your e-mail address.";

		wrongBeginningCharacter = "E-mail address cannot start with \"@\".";
		duplicateCharacters = "E-mail address cannnot contain multiple \"@\" characters.";
		lengthIsZero = "Please enter your E-MAIL address!";
		incorrectEmail ="guiclass/isEmail/English message is missing";
	}
	else {
		missingAt = "E-POSTA adresinde  \"@\" işareti eksik";
		missingDot = "E-POSTA adresinde  \".\" işareti eksik!";
		wrongBeginningCharacter = "E-POSTA adresi \"@\" karakteri ile başlayamaz.";
		duplicateCharacters = "E-POSTA adresinde  birden fazla \"@\" işareti olamaz.";
		lengthIsZero = "Lütfen E-POSTA adresinizi giriniz!";
		incorrectEmail = "Lütfen E-POSTA adresinizi doğru giriniz!";
	}

    trimAllSpaces(temp);
    noTurkishCharacters(temp);
    isCharNumericAll(temp,'@', '.', '-', '_', '');

	//@ isaretinden sonraki son noktadan sonraki kisimlarda alfanumerik karakterler disindaki karakteri filtreler.
	fieldAfterAt = temp.value.substring(temp.value.lastIndexOf('@')+1);

	if (fieldAfterAt.lastIndexOf('.') != -1){
		lastField = temp.value.substring(temp.value.lastIndexOf('.')+1);
		firstFields = temp.value.substring(0,temp.value.lastIndexOf('.')+1);
		lastField = isCharAllStr(lastField);
		temp.value = firstFields + lastField;
	} else {
		//@ isaretinden sonra hic nokta kullanilmamis
		alert(missingDot);
		return false;
	}


    //hatali karakterlerin silindikten sonra, email adresinin boyutu 0 degilse kontrollere devam
    //alert("2 " + temp.value.indexOf('.', temp.value.indexOf('@'));
    if (temp.value.length != 0) {

		//@ ve ya . karakteri eksik
        if (temp.value.indexOf('@', 0) == -1 ) {
            alert(missingAt);
            return false;
        }
	    else if ( (temp.value.indexOf('.', 0) == -1) ) {
            //alert("son noktanın indexi" + temp.value.indexOf('.', temp.value.indexOf('@') );
            alert(missingDot);
            return false;
        }

		//@ isareti ile baslayamaz
		else if (temp.value.indexOf('@') == 0) {
			alert(wrongBeginningCharacter);
				return false;
		}

		//2 tane @ isareti olamaz
		else if (temp.value.substring(temp.value.indexOf('@') + 1).indexOf('@') != -1) {
			alert(duplicateCharacters);
				return false;
		}

		//son noktadan sonra 1 ve ya 0 karakter varsa hata verir.
		//noktadan sonra 1 karakter:temp.value.length - temp.value.lastIndexOf(".")=2
		//noktadan sonra 0 karakter:temp.value.length - temp.value.lastIndexOf(".")=1
		else if ( (temp.value.length - temp.value.lastIndexOf(".")) <= 2 ){
			alert(incorrectEmail);
			return false;
		}

    }
    else {
		alert(lengthIsZero);
		return false;
    }

	//alert('doru');
	return true;
}

function filterCountryCode(temp){

	//@ isaretinden sonraki son noktadan sonraki kisimlarda alfanumerik karakterler disindaki karakteri filtreler.
	fieldAfterAt = temp.value.substring(temp.value.lastIndexOf('@')+1);

	if (fieldAfterAt.lastIndexOf('.') != -1){
		lastField = temp.value.substring(temp.value.lastIndexOf('.')+1);
		firstFields = temp.value.substring(0,temp.value.lastIndexOf('.')+1);
		lastField = isCharAllStr(lastField);
		temp.value = firstFields + lastField;
	}
	/*
	else {
		//@ isaretinden sonra hic nokta kullanilmamis
		alert(missingDot);
		return false;
	}
	*/
}

// ilk karakteri büyük harf yapıyor
function firstCharToUpper(temp)
{
  tempstring = temp.value;
  tempstr = tempstring.substring(0,1);

//  for (var i = 0; i < tempstring.length; i++){
//    var ch = tempstring.substring(i, i + 1);
//    tempstr = tempstr + ch.toLowerCase();
//  }

   for (var i = 1; i < tempstring.length; i++){
   var ch = tempstring.substring(i, i + 1);
   if((ch == "İ") || (ch == "I")) {
     if(ch == "İ")ch = "i";
     if(ch == "I")ch = "ı";
   }else{
	ch =  ch.toLowerCase();
   }
  tempstr = tempstr + ch;
  }
  tempstring = tempstr;
  if(tempstring.substring(0,1) == 'i')
  temp.value = 'İ' + tempstring.substring(1, tempstring.length);
  else
  temp.value = tempstring.substring(0,1).toUpperCase() + tempstring.substring(1, tempstring.length);
 //alert("upper" + temp.value);
}

// bütün karakterleri büyük harfe çeviriyor.
function stringToUpper(temp)
{
  tempstring = temp.value;
  //temp.value = tempstring.toUpperCase();
  tempstr="";

   for (var i = 0; i < tempstring.length; i++){
   var ch = tempstring.substring(i, i + 1);
   if(ch == "i") {
     ch = "İ";
   }else{
	ch =  ch.toUpperCase();
   }
   tempstr = tempstr + ch;
   }

   temp.value = tempstr;
}

// parameter olarak string alıyor bütün karakterleri büyük harfe çeviriyor.
function stringToUpperStr(temp)
{
  tempstring = temp;
  tempstr="";

   for (var i = 0; i < tempstring.length; i++){
   var ch = tempstring.substring(i, i + 1);
   if(ch == "i") {
     ch = "İ";
   }else{
	ch =  ch.toUpperCase();
   }
   tempstr = tempstr + ch;
   }

  return tempstr;
}

// bütün karakterleri kucuk harfe çeviriyor.
function stringToLower(temp)
{
  tempstring = temp.value;
  tempstr="";

   for (var i = 0; i < tempstring.length; i++) {
   	var ch = tempstring.substring(i, i + 1);
   	if(ch == "i") { ch = "İ";}
	else          { ch =  ch.toLowerCase();}
   	tempstr = tempstr + ch;
   }
   temp.value = tempstr;
}

// gerekli kontrolleri yapiyor...
// f1: kullanilan isaretlerden sonra ilk karakter büyük
// f2: Rakamdan sonra ilk karakter büyük
// f3: noktadan sonra bosluk yoksa ekle
// f5: yanyana iki bosluk olmaz
// f6: rakamdan sonra bosluk ekle. bu kontrol f2'den sonra yapilmalidir.
// f4: Bosluktan sonra ilk karakter büyük
function controlField(temp, ch1, ch2, ch3, ch4, ch5, f1, f2, f3, f4, f5, f6) {

    tempstring = temp.value;
    tempChar = "";

    //yanyana iki bosluk olmaz. standart bir kontrol
    tempstr = "";
    for (var i = 0; i < tempstring.length; i++) {
        var ch = tempstring.substring(i, i + 1);
        var ct = tempstring.substring(i + 1, i + 2);
        if ((ch == ' ') && (ct == ' ')) {
        }
        else
        {
            tempstr = tempstr + ch;
        }
    }
    tempstring = tempstr;

    if (f1 == 'Y') {//kullanilan isaretlerden sonra ilk karakter büyük
        tempstr = "";
        for (var i = 0; i < tempstring.length; i++) {
            var ch = tempstring.substring(i, i + 1);
            var ct = tempstring.substring(i + 1, i + 2);

            if ((ch == ch1 || ch == ch2 || ch == ch3 || ch == ch4 || ch == ch5) &&
                (ct != ch1 && ct != ch2 && ct != ch3 && ct != ch4 && ct != ch5)) {
                //tempstr = tempstr + ch + ct.toUpperCase();

                if (ct == 'i') {
                    tempChar = "I";
                } else {
                    tempChar = ct.toUpperCase();
                }
                tempstr = tempstr + ch + tempChar;


                i++;
            }
            else
            {
                tempstr = tempstr + ch;
            }
        }
        //alert("f1   *" + tempstr + "*");
        tempstring = tempstr;
    }

    if (f2 == 'Y') {//Rakamdan sonra ilk karakter büyük
        tempstr = "";
        var numbers = "0123456789";
        for (var i = 0; i < tempstring.length; i++) {
            var ch = tempstring.substring(i, i + 1);
            var ct = tempstring.substring(i + 1, i + 2) ;


            if (( numbers.indexOf(ch) >= 0 ) && ( numbers.indexOf(ct) < 0)) { //ch: rakam; ct: harf
                if (ct == 'i') {
                    tempChar = "I";
                } else {
                    tempChar = ct.toUpperCase();
                }
                tempstr = tempstr + ch + tempChar;
                i++;
            }
            else
            {
                tempstr = tempstr + ch;
            }
        }
        tempstring = tempstr;
    }

    if (f3 == 'Y') {//noktadan sonra bosluk yoksa ekle
        tempstr = "";
        for (var i = 0; i < tempstring.length; i++) {
            var ch = tempstring.substring(i, i + 1);
            var ct = tempstring.substring(i + 1, i + 2) ;
            if ((ch == '.') && (i <= tempstring.length - 2) && (ct != ' ')) {
                tempstr = tempstr + ch + '';
            }
            else {
                tempstr = tempstr + ch;
            }
        }
        tempstring = tempstr;
    }

    if (f4 == 'Y') {//Bosluktan sonra ilk karakter büyük
        tempstr = "";
        for (var i = 0; i < tempstring.length; i++) {
            var ch = tempstring.substring(i, i + 1);
            var ct = tempstring.substring(i + 1, i + 2) ;
            if (ch == ' ' && ct != ' ') {
                tempstr = tempstr + ch;
                if (ct == 'i') {
                    tempChar = "I";
                } else {
                    tempChar = ct.toUpperCase();
                }
                tempstr = tempstr + tempChar;
                i++;
            }
            else {
                tempstr = tempstr + ch;
            }
        }
        tempstring = tempstr;
    }

    if (f5 == 'Y') {//kelime icinde bosluk kullanmak yasak

        tempstr = "";

        for (var i = 0; i < tempstring.length; i++) {
            var ch = tempstring.substring(i, i + 1);
            if (ch == ' ') {
            }
            else {
                tempstr = tempstr + ch;
            }
        }
        tempstring = tempstr;
    }

    if (f6 == 'Y') { //rakamdan hemen sonra bosluk ekle.
        var numbers = "0123456789";
        var tempstr = "";

        for (i = 0; i <= tempstring.length; i++) {
            tempchar = tempstring.charAt(i);
            nexttempchar = tempstring.charAt(i+1);

            //siradaki karakter bir rakamsa,
            //rakamdan hemen sonraki karakter sayi degilse,
            //rakamdan hemen sonraki karakter bosluk degilse, rakamdan sonra bir bosluk ekler.
            if ( (numbers.indexOf(tempchar) >= 0)
                && (nexttempchar != " ")
                    && (numbers.indexOf(nexttempchar) == -1 ) ) {
                tempstr = tempstr + tempchar + " ";
            } else {
                tempstr = tempstr + tempchar;
            }
        }
        tempstring = tempstr;
    }
    temp.value = tempstring;

}

//String içersinde ki harfleri alıyor sadece
function isCharAll(temp,ch1,ch2,ch3,ch4,ch5){
	tempstring = temp.value;
	tempstr = "";
	for (var i = 0; i < tempstring.length; i++){
		var ch = tempstring.substring(i, i + 1);
		if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ' &&
            ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
            && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö'
            && ch != ch1  && ch != ch2  && ch != ch3  && ch != ch4  && ch != ch5){
		}
        else
        {
        tempstr = tempstr + ch;
          }

	}
     temp.value = tempstr;
}

//string'in icerisindeki karakterin harf olup olmadigina bakiyor
function isCharAllStr(tempstring, ch1, ch2, ch3, ch4, ch5) {

    tempstr = "";
    for (var i = 0; i < tempstring.length; i++) {
        var ch = tempstring.substring(i, i + 1);
        //alert("ch: " + ch);
        if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ' &&
            ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
            && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö'
            && ch != ch1  && ch != ch2  && ch != ch3  && ch != ch4  && ch != ch5){
        }
        else
        {
            tempstr = tempstr + ch;
            //alert("tempstr: " + tempstr);
        }

    }
    tempstring = tempstr;
    return tempstring;
}

// textbox'a girilen karakterin harf olup olmadığına bakıyor
function isChar(temp,ch1,ch2,ch3,ch4,ch5){

	tempstring = temp.value;
        ch = tempstring.substring(tempstring.length -1 ,tempstring.length);

  	if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ' &&
            ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
            && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö'
            && ch != ch1  && ch != ch2  && ch != ch3  && ch != ch4  && ch != ch5)
             temp.value = tempstring.substring(0 ,tempstring.length-1);
}

//String içersinde ki rakamları alıyor sadece
function isNumericAll(temp,ch1,ch2,ch3,ch4,ch5){
	tempstring = temp.value;
	tempstr = "";
	for (var i = 0; i < tempstring.length; i++){
		var ch = tempstring.substring(i, i + 1);
		if ((ch < "0" || "9" < ch)  && ch != ch1  && ch != ch2  && ch != ch3  && ch != ch4  && ch != ch5){
		}
        else
        {
        tempstr = tempstr + ch;
        }

	}
    temp.value = tempstr;
}



// textbox'a girilen karakterin rakam olup olmadığına bakıyor
function isNumeric(temp,ch1,ch2,ch3,ch4,ch5){

	tempstring = temp.value;
    ch = tempstring.substring(tempstring.length -1 ,tempstring.length);

    if ((ch < "0" || "9" < ch)  && ch != ch1  && ch != ch2  && ch != ch3  && ch != ch4  && ch != ch5)
                     temp.value = tempstring.substring(0 ,tempstring.length-1);


}

//textbox'a girilen rakamların başındaki 0 (sıfır) ları siler
function deleteZerosAtBegining(temp) {
	tempstring = temp.value;
	var i = 0;
	for (; i < tempstring.length; i++){
		var ch = tempstring.substring(i, i+1);
		if(ch != "0")
			break;
	}
	tempstr = tempstring.substring(i, tempstring.length);
	temp.value = tempstr;
}

// textbox'a girilen karakterin harf ve rakam olup olmadigina bakiyor
// AYRICA girilen metinde harf, rakam ve ya parametrelerle gecilmis karakterlerin disinda bir karakter varsa, false donduruyor.
function isCharNumericAll(temp,ch1,ch2,ch3,ch4,ch5){
	var isCorrect = true;
	tempstring = temp.value;
	tempstr = "";
	for (var i = 0; i < tempstring.length; i++){
		var ch = tempstring.substring(i, i + 1);
		if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch)) && ch != ' ' &&
            ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
            && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö'
            && ch != ch1  && ch != ch2  && ch != ch3  && ch != ch4  && ch != ch5){
          	//do nothing
			isCorrect = false;
			//break kullanilabilir mi?
		}
        else
        {
        tempstr = tempstr + ch;
        }
	}
     temp.value = tempstr;
	 return isCorrect;
}

// textbox'a girilen karakterin harf ve rakam olup olmadığına bakıyor
//
function isCharNumeric(temp,ch1,ch2,ch3,ch4,ch5){

	tempstring = temp.value;
        ch = tempstring.substring(tempstring.length -1 ,tempstring.length);

  	if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch < "0" || "9" < ch)) && ch != ' ' &&
            ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
            && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö'
            && ch != ch1  && ch != ch2  && ch != ch3  && ch != ch4  && ch != ch5)

             temp.value = tempstring.substring(0 ,tempstring.length-1);


}

// girilen string'in uzunluğunu kontrol ediyor!
function contWord(temp,strlen){

	tempstring = temp.value;
        if(tempstring.length != strlen && tempstring.length != 0){
    	alert(strlen + " haneden az giriş yapılamaz.");
        temp.focus();
    }
}


// girilen string'in uzunluğu strlen'den fazla ise string'i cut ediyor.!

function cutWord(temp,strlen){

	tempstring = temp.value;
    if(tempstring.length > strlen ){
        temp.value = tempstring.substr(0,strlen);
        alert("Girilen değer " + strlen + " haneden fazla olduğu için \'" + temp.value + "\' olarak değiştirilmiştir!");
    }
}




// hüviyet no alanına yazılanları kontrol ediyor

function isHuviyetNo(temp1,temp2,temp3){


    if(temp2.value == "Pasaport" && temp3.value == ""){
    	alert("Lütfen Kullanıcının Uyruğu bilgisini Giriniz!");
        temp1.value = "";
        temp1.focus();
	return;

    }

   if(temp2.value == ""){
    	alert("Lütfen Kullanıcının Hüviyet Türü bilgisini giriniz!");
        temp1.value = "";
        temp1.focus();
	return;

    }

/*   if(temp2.value == "Vergi Levhası"){
    	alert("Lütfen Vergi Dairesi Adı ve No'sunu giriniz!");
        temp1.value = "";
        return;

    }
*/

}





function isHuviyetNoAll(temp1,temp2,temp3){

    if(temp1.value == "") return;

    tempstring = temp1.value;
    tempstr = "" ;

////////////////////////////////// Eğer  Nüfus Cüzdanı Seçilmişse////////////////////

    if(temp2.value == "Nüfus Cüzdanı"){

    if(tempstring.length != 10)
    {
    	alert("V09-123456 formatında bilgi giriniz!");
        temp1.value = "";
        temp1.focus();
        return;

    }
    ch = tempstring.substring(0,1);

    if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ' &&
            ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
            && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö')

     {

		alert("V09-123456 formatında bilgi giriniz!");
                temp1.value = "";
                temp1.focus();
		return;
     }
     else
     {
		tempstr  = tempstring.substring(0,1).toUpperCase() +tempstring.substring(1,2).toUpperCase()+tempstring.substring(2,3).toUpperCase()+ tempstring.substring(3, tempstring.length);

      }

     ch = tempstring.substring(3,4);

     if(ch!="-")
     {
		alert("V09-123456 formatında bilgi giriniz!");
        temp1.value = "";
        temp1.focus();
	return;

      }

   	for (var i = 4; i < 10; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("V09-123456 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();
            return;

		}
     }

   	temp1.value = tempstr;
        return;
	}

///////////////////////////////////////Eğer Ehliyet seçilmişse//////////////////////////////

if((temp2.value == "Ehliyet") && (tempstring.length != "")){

    if(tempstring.length != 18)
    {
    	alert("0123456-28.10.1999 formatında bilgi giriniz!");
        temp1.value = "";
	    return;

    }

   	for (var i = 0; i < 7; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("0123456-28.10.1999 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();
            return;

		}
     }


     if((tempstring.substring(7,8) !="-") ||(tempstring.substring(10,11) !=".") ||(tempstring.substring(13,14) !="."))
     {
		alert("0123456-28.10.1999 formatında bilgi giriniz!");
        temp1.value = "";
        temp1.focus();
	return;

      }


   	for (var i = 8; i < 10; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("0123456-28.10.1999 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();
            return;

		}
     }


   	for (var i = 11; i < 13; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("0123456-28.10.1999 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();
            return;

		}
     }



   	for (var i = 14; i < 18; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("0123456-28.10.1999 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();
            return;

		}
     }

   	temp1.value = tempstring;
        return;
	}



///////////////////////////////////////Eğer Pasaport seçilmişse//////////////////////////////

if(temp2.value == "Pasaport" && temp3.value == "TURKEY"){

    if(tempstring.length != 11)
    {
    	alert("TR-A-123456 formatında bilgi giriniz!");
        temp1.value = "";
        temp1.focus();

	    return;

    }

   for (var i = 0; i < 2; i++){
 	var ch = tempstring.substring(i, i + 1);
	if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ' &&
                    ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
                     && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö'  ){

                     alert("TR-A-123456 formatında bilgi giriniz!");
                     temp1.value = "";
                     temp1.focus();

		     return;



		}
     }


     if((tempstring.substring(2,3) !="-") ||(tempstring.substring(4,5) !="-"))
     {
		alert("TR-A-123456 formatında bilgi giriniz!");
                temp1.value = "";
                temp1.focus();
		return;

      }



     var ch = tempstring.substring(3,4);
     if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ' &&
           ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
           && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö'  ){

             alert("TR-A-123456 formatında bilgi giriniz!");
             temp1.value = "";
             temp1.focus();
	     return;

	}







     for (var i = 5; i < 11; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("TR-A-123456 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();

			return;

		}
     }



   	temp1.value = tempstring;
        return;
	}



}























function isHuviyetNoAllPrePaid(temp1,temp2,temp3){

    if(temp1.value == "") return;
    tempstring = temp1.value;
    tempstr = "" ;

////////////////////////////////// Eğer  Nüfus Cüzdanı Seçilmişse////////////////////

    if(temp2.value == "T"){//Nüfus Cüzdanı

    if(tempstring.length != 10)
    {
    	alert("V09-123456 formatında bilgi giriniz!");
        temp1.value = "";
        temp1.focus();
        return;

    }
    ch = tempstring.substring(0,1);

    if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ' &&
            ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
            && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö')

     {

		alert("V09-123456 formatında bilgi giriniz!");
                temp1.value = "";
                temp1.focus();
		return;
     }
     else
     {
		tempstr  = tempstring.substring(0,1).toUpperCase() +tempstring.substring(1,2).toUpperCase()+tempstring.substring(2,3).toUpperCase()+ tempstring.substring(3, tempstring.length);

      }

     ch = tempstring.substring(3,4);

     if(ch!="-")
     {
		alert("V09-123456 formatında bilgi giriniz!");
        temp1.value = "";
        temp1.focus();
	return;

      }

   	for (var i = 4; i < 10; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("V09-123456 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();
            return;

		}
     }

   	temp1.value = tempstr;
        return;
	}

///////////////////////////////////////Eğer Ehliyet seçilmişse//////////////////////////////

if((temp2.value == "D") && (tempstring.length != "")){

    if(tempstring.length != 18)
    {
    	alert("0123456-28.10.1999 formatında bilgi giriniz!");
        temp1.value = "";
	    return;

    }

   	for (var i = 0; i < 7; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("0123456-28.10.1999 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();
            return;

		}
     }


     if((tempstring.substring(7,8) !="-") ||(tempstring.substring(10,11) !=".") ||(tempstring.substring(13,14) !="."))
     {
		alert("0123456-28.10.1999 formatında bilgi giriniz!");
        temp1.value = "";
        temp1.focus();
	return;

      }


   	for (var i = 8; i < 10; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("0123456-28.10.1999 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();
            return;

		}
     }


   	for (var i = 11; i < 13; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("0123456-28.10.1999 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();
            return;

		}
     }



   	for (var i = 14; i < 18; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("0123456-28.10.1999 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();
            return;

		}
     }

   	temp1.value = tempstring;
        return;
	}



///////////////////////////////////////Eğer Pasaport seçilmişse//////////////////////////////

if(temp2.value == "N" && (temp3.value == "TURKEY"  || temp3.value == "Türkiye")){

    if(tempstring.length != 11)
    {
    	alert("TR-A-123456 formatında bilgi giriniz!");
        temp1.value = "";
        temp1.focus();

	    return;

    }

   for (var i = 0; i < 2; i++){
 	var ch = tempstring.substring(i, i + 1);
	if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ' &&
                    ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
                     && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö'  ){

                     alert("TR-A-123456 formatında bilgi giriniz!");
                     temp1.value = "";
                     temp1.focus();

		     return;



		}
     }


     if((tempstring.substring(2,3) !="-") ||(tempstring.substring(4,5) !="-"))
     {
		alert("TR-A-123456 formatında bilgi giriniz!");
                temp1.value = "";
                temp1.focus();
		return;

      }



     var ch = tempstring.substring(3,4);
     if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ' &&
           ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
           && ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö'  ){

             alert("TR-A-123456 formatında bilgi giriniz!");
             temp1.value = "";
             temp1.focus();
	     return;

	}







     for (var i = 5; i < 11; i++){
 		var ch = tempstring.substring(i, i + 1);
		if (ch < "0" || "9" < ch){
			alert("TR-A-123456 formatında bilgi giriniz!");
            temp1.value = "";
            temp1.focus();

			return;

		}
     }



   	temp1.value = tempstring;
        return;
	}



}




//////////////////////////////////////////////////////////////////
// En az x harf/rakam içermelidir, hepsi harf/rakam olamaz kontrollerini yapar.
// f1: x -- En az x rakam içermelidir
// f2: y -- En az y harf içermelidir
// f3: Hepsi aynı harf olamaz

function controlCharNum(temp, f1, f2, f3) {
	tempstring = temp.value;
	
	if(tempstring == '') return true;

	var charNum = 0;
	var numNum = 0;
	var f1OK = false;
	var f2OK = false;
	var f3OK = false;
	
	if(f1 == '') f1OK = true;
	if(f2 == '') f2OK = true;
	if(f3 != 'Y') f3OK = true;
	
    	for (var i = 0; i < tempstring.length && (!f1OK || !f2OK || !f3OK) ; i++) {
    		var ch = tempstring.substring(i, i + 1);
            
		if (!f1OK && (ch >= "0" && "9" >= ch)) {
			numNum ++;
			if(numNum == f1) f1OK = true;
		}
			
		if (!f2OK && (((ch >= "a" && "z" >= ch) || (ch >= "A" && "Z" >= ch)) || 
            		ch == 'İ' || ch == 'ı' || ch == 'Ş' || ch == 'ş' || ch == 'Ğ' || ch == 'ğ'
            		|| ch == 'Ç' || ch == 'ç' || ch == 'Ü' || ch == 'ü' || ch == 'Ö' || ch == 'ö')) {
		
			charNum ++;
			if(charNum == f2) f2OK = true;
		}
			
		if(((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && 
			ch != 'İ' && ch != 'ı' && ch != 'Ş' && ch != 'ş' && ch != 'Ğ' && ch != 'ğ'
			&& ch != 'Ç' && ch != 'ç' && ch != 'Ü' && ch != 'ü' && ch != 'Ö' && ch != 'ö') 
			f3OK = true;
		
		if(!f3OK ) {
			var sonrakiCh = tempstring.substring(i+1, i + 2);
			if(ch == 'İ') 
				ch = 'i';
			else if (ch == 'I')
				ch = 'ı';
			else
				ch = ch.toLowerCase();
					
			if(sonrakiCh == 'İ') 
				sonrakiCh = 'i';
			else if (sonrakiCh == 'I')
				sonrakiCh = 'ı';
			else
				sonrakiCh = sonrakiCh.toLowerCase();
				
			if(sonrakiCh != '' && ch != sonrakiCh) f3OK = true;
		}
	}

	if(!f1OK) {
		alert('Girdiğiniz değer en az ' + f1 + ' rakam içermeli.');
		temp.focus();
		return false;
	}
	
    	if(!f2OK) {
		alert('Girdiğiniz değer en az ' + f2 + ' harf içermeli.');
		temp.focus();
		return false;
	}
	
	if(!f3OK) {
		alert('Girdiğiniz değer sadece aynı harfleri içermemeli.');
		temp.focus();
		return false;
	}
	
	return true;
}

