// JavaScript Document

$(document).ready(function(){
						   
//Clear Form						   
$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
  else if (tag == 'select')
   this.selectedIndex = 0;  
  });
};	

//Eğer checkbox işaretlenmişse yanındaki textfield alanıda boş geçilmemlidir.
//begin degerGir
$.fn.degerGir = function (){
var secenek = $(this).attr("id").replace("_deger","");
var deger = "Harf olmadan KM değeri";
if($("#"+secenek).is(":checked")){
	if($(this).val() == ""){
		if(secenek == "duraklama"){
			deger = "Dakika";
		}
		alert($(this).attr("id")+ " alanı boş geçilemez. "+deger+" giriniz.");
		return true;
	}else{
		return false;
	}
	}
};
//end degerGir


//Remove login cookie with ajax post.
//begin exit
$.fn.exit = function (url){
$(this).bind('click',function(){
		$.ajax({
        type:'POST',
        dataType:'json',
        data:"cmd=set_cikis",
        url: 'index.php/ajaxask',
        success: function(json){
			location.href = url;
		},
        error:function(){
			
		}
        });					  
});
};
//end exit

//metin içindeki str de geçen değeri atıp değere ulaşır.
//replaces begin

$.replaceAll = function (txt, replace, with_this) {
  return txt.replace(new RegExp(replace, 'g'),with_this);
};

$.replace_Editor = function (icerik){
	icerik=$.replaceAll(icerik,"&ccedil;","ç");
	icerik=$.replaceAll(icerik,"&quot;","\"");
	icerik=$.replaceAll(icerik,"&#39;","'");
	icerik=$.replaceAll(icerik,"&gt;",">");
	icerik=$.replaceAll(icerik,"&lt;","<");
	icerik=$.replaceAll(icerik,"&uuml;","ü");
	icerik=$.replaceAll(icerik,"ouml;","ö");
	icerik=$.replaceAll(icerik,"ouml;","ö");
	icerik=$.replaceAll(icerik,"&copy;","©");
	icerik=$.replaceAll(icerik,"&reg;","®");
	
	icerik=$.replaceAll(icerik,"&Ccedil;","Ç");
	icerik=$.replaceAll(icerik,"&Uuml;","Ü");
	icerik=$.replaceAll(icerik,"Ouml;","Ö");
	icerik=$.replaceAll(icerik,"&nbsp;"," ");
	icerik=$.replaceAll(icerik,"&","");
	return icerik;	
};

$.replace_id = function (obj,str){
	return obj.attr("id").replace(str,"");	
};


$.replace_out = function (obj,str){
	return obj.replace(str,"");	
};
//replaces end


$.addslashes = function (str){
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}
$.stripslashes = function (str){
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}




$.fn.closeDivClick = function(obj){
	$(this).bind('click',function(){
		obj.css("display","none");						  
	});
	
};

$.fn.showDivClick = function(obj){
	$(this).bind('click',function(){
		obj.css("display","block");						  
	});
	
};

isDigit = function(e) {

   return ( digit );
};

      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
	  
  
	  

timeControl = function(e){
	var val = $(this).val();

	var format 	= e.data.format;
	var size	= format.length;
	var mesaj 	= e.data.msg;
	var charCode = e.keyCode;
	var patt=/\d/g;
	
	var charCode = (e.which) ? e.which : e.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 96 || charCode > 105))
		size = 0;
	else
		size = format.length;
	
	if(size < $(this).val().length){
		$(this).val(val.substring(0,size));
		alert(mesaj);	
	}
	
	if($(this).val().length == 2){
		//İlk 2 karakter digit ise
		var patt=/^(\d)(\d)/g;

		if(patt.test(val)){
			$(this).val(val+":");	
		}
	}
	
	

};

						   
});						   
