function phone_mask(){
   $.mask.masks.tel = {mask: '(999) 999 99 99'};
   $(".phone").setMask();	
}

function BuyukHarf(e){
	var nesne = e.target ? e.target : e.srcElement;
	var basilantus = e.keyCode ? e.keyCode : e.charCode;
	var str = String.fromCharCode(basilantus);
	if ((basilantus < 97 || basilantus > 122) && !isTRChar(basilantus)) 
		return true;
	if (basilantus == 105) 
		str = 'İ';
	if (nesne.createTextRange) {
		nesne.caretPos = document.selection.createRange();
		nesne.focus(nesne.caretPos);
		nesne.caretPos.text = str.toUpperCase();
		return false;
	}
	else {
		var pos = nesne.selectionStart;
		nesne.value = nesne.value.substr(0, pos) + str.toUpperCase() + nesne.value.substr(pos);
		pos++;
		nesne.setSelectionRange(pos, pos);
		return false;
	}
}

function isTRChar(key){
	var trchar = [231, 246, 252, 287, 305, 351];
	for (var i = 0; i < trchar.length; i++) {
		if (trchar[i] == key) 
			return true;
	}
	return false;
}

function publishRecord(ajaxURL, id){
	if (confirm("İşlemi onaylıyor musunuz?")) {	  	  	
	  	var pubType = $('#publish'+id).attr('pubType'); 
	  		  	
	  	$.ajax({

			   beforeSend: function(){
					$("#loader"+id).show();
				    $('#container'+id).attr('bgcolor','#dddddd');
			   },
			   complete: function(){
			      	$("#loader"+id).hide();
			   },
	  		
	  		type: "POST",
	  		url: ajaxURL,
	  		data: "id=" + id + "&pubType=" + pubType,
	  		cache: false,
	  		success: function(responseText, responseCode){
				if(responseText == 1){
					if(pubType == 1){
						$('#publish'+id).attr('pubType',0);
						$('#publish'+id).html('Yayından Kaldır');
						$('#container'+id).attr('bgcolor','#fafafa');					
					}
					else{
						$('#publish'+id).attr('pubType',1);
						$('#publish'+id).html('Yayınla');
						$('#container'+id).attr('bgcolor','#fafafa');
					}
				window.location.reload();
				}				
				else
					alert(responseText);						
	  		}
	  	});
	}
}

function removeFromVitrin(ajaxURL, id){
	if (confirm("İşlemi onaylıyor musunuz?")) {	  	  	
	  	var vitType = $('#vitrin'+id).attr('vitType'); 
	  		  	
	  	$.ajax({
			   beforeSend: function(){
					$("#loader"+id).show();
				    $('#container'+id).attr('bgcolor','#dddddd');
			   },
			   complete: function(){
			      	$("#loader"+id).hide();
			   },
	  		
	  		type: "POST",
	  		url: ajaxURL,
	  		data: "id=" + id + "&vitType=" + vitType,
	  		cache: false,
	  		success: function(responseText, responseCode){
				if(responseText == 1){
					if(vitType == 2){
						$('#vitrin'+id).attr('vitType',0);
						$('#vitrin'+id).html('Vitrinden Çıkar');
						$('#container'+id).attr('bgcolor','#fafafa');					
					}
					else{
						$('#vitrin'+id).attr('vitType',2);
						$('#vitrin'+id).html('Vitrine Ekle');
						$('#container'+id).attr('bgcolor','#fafafa');
					}				
				}				
				else
					alert(responseText);						
	  		}
	  	});
	}
}

function addUserToVitrin(ajaxURL, action, id){
	if (id == 0) {
		var id = $('#realtors').val();
		if (id == null) {
			alert('Emlakçı seçiniz !');
			return false;
		}
	}

  	if (confirm("İşlemi onaylıyor musunuz?")) {
		
		$.ajax({
			beforeSend: function(){
				$("#loader").show();
				$('#container').attr('style', 'background-color:#dddddd');
			},
			complete: function(){
				$("#loader").hide();
			},
			
			type: "POST",
			url: ajaxURL,
			data: "id=" + id + "&action=" + action,
			cache: false,
			success: function(responseText, responseCode){
				//alert(responseText);
				$('#in_vitrin').html(responseText);
				$('#container').attr('style', 'background-color:#fff');
			}
		});
	}	
}

function extendIlanTime(ajaxURL, id){

	if (confirm("İşlemi onaylıyor musunuz?")) {	  	  		  	
	  		  	
	  	$.ajax({	  		
		   beforeSend: function(){
				$("#loader"+id).show();
		   },
		   complete: function(){
		      	$("#loader"+id).hide();
		   },
	  		type: "POST",
	  		url: ajaxURL,
	  		data: "emlak_id=" + id,
	  		cache: false,
	  		success: function(responseText, responseCode){
				if(responseText == 1){					
					window.location.reload();
				}				
				else
					alert(responseText);						
	  		}
	  	});
	}
}

function addToMyWebVitrin(ajaxURL, action, id){

	if (confirm("İşlemi onaylıyor musunuz?")) {	  	  		  	
	  		  	
	  	$.ajax({	  		
		   beforeSend: function(){
				$("#loader"+id).show();
		   },
		   complete: function(){
		      	$("#loader"+id).hide();
		   },
	  		type: "POST",
	  		url: ajaxURL,
	  		data: "emlak_id=" + id + "&action=" + action,
	  		cache: false,
	  		success: function(responseText, responseCode){
				if(responseText == 1){					
					window.location.reload();
				}				
				else
					alert(responseText);						
	  		}
	  	});
	}
}

function showDeleteForm(id,page_type){
	record_id = id;
	ptype = page_type;	
	$( "#dialog:ui-dialog" ).dialog( "destroy" );		
	$( "#dialog-form" ).dialog({
				autoOpen: false,
				height: 280,
				width: 380,
				modal: true,
				title: "Emlak İlanınızı Silme Nedeniniz?",
				buttons: {
					"Onayla": function() {						
						var svalue = $("input[@name=r1]:checked").val();
						if (svalue == '' || svalue == null || svalue == undefined){
							$('#error').html('Lütfen Silme nedeninizi işaretleyiniz !');		
							return false;
						}
						else{
							var url = '/emlaks/delete/'+record_id+'/1/'+ptype+'/'+svalue;
							window.location=url;
							$( this ).dialog( "close" );
						}							

					},
					'İptal': function() {
						$( this ).dialog( "close" );
						$( "#dialog:ui-dialog" ).dialog( "destroy" );
					}
				},
			close: function() {
				var s = $("input[@name=r1]:checked");					
				s.attr('checked',false);
				$('#error').html("");
				}	
			});
	$( "#dialog-form" ).dialog( "open" );			
}

