//------------------------------------------------------------
// BUTIK JS FUNCTIONS
//------------------------------------------------------------
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

function contTel(temp){   

	tempstring = temp.value;
    ch = tempstring.substring(tempstring.length -1 ,tempstring.length);
    if((ch == "0") && (tempstring.length == 1))
         temp.value = tempstring.substring(0 ,tempstring.length-1);


}






//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 == 'ö')
            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;
}



//EMail alanını kontrol ediyor

function isEMail(temp)
{ 
        if(temp.value.length != 0){
        cutTurkishCharacters(temp);
        trimAllSpaces(temp);
	if (temp.value.indexOf ('@',0) == -1 || temp.value.indexOf ('.',0) == -1){      
		alert("E-MAIL adresinde  \"@\" ve \".\" işaretleri olmalıdır.")      
		temp.select();      
		temp.focus();      
	}   }
} 





// 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;
  

} 


// gerekli kontrolleri yapıyor...
function controlField(temp,ch1,ch2,ch3,ch4,ch5,f1,f2,f3,f4,f5,f6){   
        
        tempstring = temp.value;   
		tempChar = "";
 
		//yanyana iki boşluk olmaz
		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'){//kullanılan işaretlerden 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 = "İ"; 
                }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 = "";
	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 >= "0") && ("9" >= ch) && (ct < "0") && (ct > "9"))  {         
		       //tempstr = tempstr + ch + ct.toUpperCase(); 
               
			   
                if(ct == 'i'){
                 tempChar = "İ"; 
                }else{
                 tempChar = ct.toUpperCase(); 
				}
				tempstr = tempstr + ch + tempChar; 

			   
                i++;
                }
                else
                {
                tempstr = tempstr + ch; 
                }
                
      	   } 
        //alert("f2   *" + tempstr + "*");
        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; 
                }
                
      	   } 
        //alert("f3   *" + tempstr + "*");
        tempstring = tempstr;
        }


        if (f5 == 'Y'){//yanyana iki bosluk olmaz
               
		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 (f4 == 'Y'){//Boşluktan 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;
                //tempstr = tempstr + ct.toUpperCase(); 
                if(ct == 'i'){
                 tempChar = "İ"; 
                }else{
                 tempChar = ct.toUpperCase(); 
				}
				tempstr = tempstr + tempChar; 
				//alert("f4 de eklendi" + ct.toUpperCase() )
                i++;
                }
                else
                {
                //alert("f4******" + ch);
                tempstr = tempstr + ch; 
                }
                
      	   } 
        //alert("f4   *" + tempstr + "*");
        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;
}


// 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çersindeki 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 karakterin harf ve rakam olup olmadığına bakıyor 
function isCharNumericAll(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 < "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){         
		}
        else
        {
       
        tempstr = tempstr + ch; 
          }
                
	}   
     temp.value = tempstr;
}
// 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!");
    }
}

