$(document).keyup(function(e) {
  if (e.keyCode == 13) {  }     // enter
  if (e.keyCode == 27) { $.unblockUI();  }   // esc
});



/*---------------------------------------Validation Setup------------------------------------------------*/
	$.validity.setup({ outputMode:"label" });
	$.extend($.validity.messages, {
		require:"Bu alanı boş bırakmayınız!",
		match:"Bu alanı kontrol ediniz!'",
		email:"Geçerli bir eposta adresi giriniz!",
		nonHtml:"Bu alana geçersiz karakterler girdiniz!",
		generic:"Alan değeri geçersiz!"
	});
/*---------------------------------------------------------------------------------------------------------*/
jQuery.fn.Message = function() { //this gonderilen eleman(lar)
  	var args= arguments[0] || {}; //bunlar da gönderilen parametreler
    var mode= args.mode;
    var m= args.message;
	var button= args.button;
	var ev= args.ev;
	var modal= args.modal;
	$.unblockUI();
	$('#Message').remove(); //alert(this.children('#Message').length +"-------"+ mode);
	var div= document.createElement('div');
	div.setAttribute('class', 'Dialog');		
	div.setAttribute('id', 'Message');	
	this.append(div);	
	var html= "<div style='background-color:#FFFFFF;'>";

			switch (mode)
			{
				case 'wait':
					html+="<img src='/res/i/wait1.gif' id='Icon'/>";		
				break;	
				case 'success':
					html+="<img src='/res/i/icon/i01.png' id='Icon'/>";		
				break;	
				case 'error':
					html+="<img src='/res/i/icon/i02.png' id='Icon'/>";		
				break;	
				case 'warning':
					html+="<img src='/res/i/icon/i03.png' id='Icon'/>";		
				break;	
				case 'modal':
					html+="<img src='/res/i/icon/i04.jpg' id='Icon'/>";		
				break;	

			}
			if(m != "")
			{
				html+="<h5>" +m+ "</h5>";					
			}
			if(button)
			{
				html+= "<input type='button' class='button' value='Tamam' id='OK'/>";
				if(ev != "")
				{
					html+= "<script type='text/javascript'>"; 
					html+= "$('#OK').click(function() {" +ev+ ";});	";
					html+= "</script>";
				}
			}
			if(modal)
			{
				html+="<div style='margin:auto !important; clear:both; width:140px;'>"
				html+= "<input type='button' class='button' value='Devam' id='Devam' style='float:left; margin:5px;'/>";
				html+= "<input type='button' class='button' value='İptal' id='Iptal' style='float:left; margin:5px;'/>";
			}
			html+="</div>";
			div.innerHTML= html;
			$('#Message').Dialog();
};
$.fn.serializeObject = function()
{
    var o = {};
    var a = this                
				.find("input, textarea, hidden")
                .not("#__VIEWSTATE,#__EVENTVALIDATION")
				.serializeArray();
    $.each(a, function() {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push($.trim(this.value) || '');
			
        } else {
            o[this.name] = $.trim(this.value) || '';
        }
    });
    return o;
};
$.fn.Dialog = function()
{
		$.blockUI({ 
			message: $(this),			
			css: { width:'570px', top:'150px', background: 'none', border:'none'},
			onUnblock : function(){
				$(this).remove();
                }
		});
}


function resetCaptcha()
{
	//document.getElementById("captcha").value= ""; //ie8 burada native js istedi...
	jQuery.each($("img[alt='captcha']"), function() {
		this.setAttribute("src","/res/i/captcha.aspx?data=" + new Date().getTime());
		});
}

$.fn.resetCaptcha = function()
{
	$(this).attr("src","/res/i/captcha.aspx?data=" + new Date().getTime());
}

function openWindow(theURL) 
{ //v2.0
  window.open(theURL,'','scrollbars=yes,width=550,height=400,resizable=no');
}
