//2010-07-12 Baris Yazganc abone.tmd

	var forceGiftSelection=false;
	
	function editAddress(adresID) {
		$.colorbox({href:"/?p=AddressBook&view="+adresID});
	}
	
	
	
	function updateAddressID(abonelikID) {
		var c= confirm("Aboneliklerinizin teslimat ve fatura adreslerini değiştirmek istediğinize emin misiniz?");
		if(c) {
			$("#update_address_of_abonelik_"+abonelikID).submit();
		}
	}
	
	function checkProfileUpdateForm() {
		var c= confirm("Bilgilerinizi güncellemek istediğinize emin misiniz?");
		if(c) {
			return true;
		}
		else {
			return false;
		}
	}
	
	function checkEditAddressForm(adresID) {
		var formData=$("#editAddressForm").serialize();
		$.ajax({
			   type: "POST",
			   data:formData,
			   dataType: 'json',
			   url: "/?p=AddressBook&action=add_new",			   
			   cache: false,
			   success: function(jsonObject){
					if(jsonObject.has_error == 1) {
						alert("Lütfen aşağıdaki hataları düzelterek tekrar deneyin\n\n"+jsonObject.error_text);
					}
					else {
						var c= confirm("Adres bilgilerinizi güncellemek istediğinize emin misiniz?");
						if(c) {
							updateAddress(formData,adresID);
							//window.location.href=window.location.href;
						}
						else {
						}
					}
			   }
		 });
	}
	
	
	
	function checkNewAddressForm() {
		var formData=$("#newAddressForm").serialize();
		$.ajax({
			   type: "POST",
			   data:formData,
			   dataType: 'json',
			   url: "/?p=AddressBook&action=add_new",			   
			   cache: false,
			   success: function(jsonObject){
					if(jsonObject.has_error == 1) {
						alert("Lütfen aşağıdaki hataları düzelterek tekrar deneyin\n\n"+jsonObject.error_text);
					}
					else {
						var c= confirm("Yeni adres kaydetmek istediğinize emin misiniz?");
						if(c) {
							saveNewAddressForm(formData);
							//window.location.href=window.location.href;
						}
						else {
						}
					}
			   }
		 });
	}
	
	function updateAddress(data,adresID) {
		$.ajax({
			   type: "POST",
			   data:data+"&adres_id="+adresID,
			  // dataType: 'json',
			   url: "/?p=AddressBook&action=update",			   
			   cache: false,
			   success: function(jsonObject){
					if(jsonObject == 1) {
						alert("Adres bilgileriniz güncellendi.");
						window.location.href = window.location.href;
					}
					else {
						alert("Bir hata oluştu!.\n\nLütfen Tekrar Deneyin...");
					}
			   }
		 });
	}
	
	
	function saveNewAddressForm(data) {
		$.ajax({
			   type: "POST",
			   data:data,
			  // dataType: 'json',
			   url: "/?p=AddressBook&action=addToDB",			   
			   cache: false,
			   success: function(jsonObject){
					if(jsonObject == 1) {
						alert("Adres bilgileriniz kaydedildi");
						window.location.href = window.location.href;
					}
					else {
						alert("Bir hata oluştu!.\n\nLütfen Tekrar Deneyin...");
					}
			   }
		 });
	}

	function FormatCreditCard(thisis) {
		var tempstr,newstr,str,i,str2 ;
		i = 0;
		
		thisis.value = trimNumber(thisis.value);
		str = thisis.value;
		
		while ( 20 > i) {
			str = str.replace(" ", "");
			i = i + 1;
		}
		
		if (str.length > 4) 
		{
			tempstr = str;
			newstr = "";
			i = 0;
			while (tempstr.length > 4)
			{
				newstr = newstr + tempstr.substr(0, 4) + " ";
				tempstr = tempstr.substr(4);
			}
			thisis.value = newstr + tempstr;
		}

		return true;
	}
	
	function popSozlesme() {
		var selectedOdemeTipi = $("input[name='odeme_tipi']:checked").val();
		var selectedAsset= $("input[name='asset_id']:checked").val();
		var url='/?p=Sozlesme&use_ssl=1&payment='+selectedOdemeTipi+'&asset_id='+selectedAsset;
		
		mypopup(url,'Satis Sozlesmesi',500,500);
	}
	
	function toggleSozlesme() {
		var sozlesme= $("input[name='satis_sozlesmesi']:checked").val();
		if(sozlesme) {
			$("#btn_save").show();
		}
		else {
			$("#btn_save").hide();
		}
	}
	
	
	function changePaymentMethod() {
		var selectedOdemeTipi = $("input[name='odeme_tipi']:checked").val();
		var selectedAsset= $("input[name='asset_id']:checked").val();
		

		if(selectedOdemeTipi > 0) {

			if(selectedAsset > 0) {
				$("#sozlesmeContainer").show();
			}

			if(selectedOdemeTipi == 30) {
				$("#payment_30").show();
				$("#payment_80").hide();
				$("#paymentProperties").show();
			}
			else if(selectedOdemeTipi == 40) {
				$("#paymentProperties").hide();
				$("#payment_80").hide();
				$("#payment_30").hide();
			}
			else if(selectedOdemeTipi == 50) {
				$("#paymentProperties").hide();
			}
			else if(selectedOdemeTipi == 80) {
				$("#payment_30").hide();
				$("#payment_80").show();
				$("#paymentProperties").show();
				$("#mobil_odeme_uzat").attr("checked","checked");
			}
			
		}
		else {
			$("#paymentProperties").hide();
			$("#sozlesmeContainer").hide();
		}
			
	}



	function enableSemt(obj,initialLoad) {
		var sehirID=obj.value;
		if(sehirID > 0) {
			$("#semtSelection").show();
		}
		else {
			$("#semtSelection").hide();
		}
		if(initialLoad == 0) {
			$("#semt_tanim").val("");
			$("#semt_id").val("");
		}
		
	}
	
	function startSemt() {
		$("#new_semt").val("");
		var selectedSemtID=$("#semt").val();
		if(selectedSemtID == "-99") {
			$("#customSemt").show();
		}
		else {
			$("#customSemt").hide();
		}
	}
	
	function newSemt() {
		var sehirID=$("#sehir").val();
		if(sehirID == 0) {
			alert("Lütfen önce bir şehir seçin");
		}
		else {
			$("#customSemt").show();
			$("#customSemt").css("visibility","visible");
			$("#semt").val("-99");
		}
	}
	
	function getSemtListOfSehir(sehirObjName,selectedSemtID,containerName,useSSL) {
		var selectedSehirID=$("#"+sehirObjName).val();
		$("#customSemt").hide();
		if(selectedSehirID > 0) {
			
			$.ajax({
				   type: "POST",
				   data:"sehir_id="+selectedSehirID+"&semt_id="+selectedSemtID,
				   dataType: 'json',
				   url: "/?p=AddressBook&action=getSemtListOfSehir&use_ssl="+useSSL,			   
				   cache: false,
				   success: function(jsonObject){
						$("#"+containerName).html(jsonObject.semt_list);
				   }
				 });
		}
		else {
			$("#"+containerName).html("");
		}
	}
	
	function getFaturaExraFields(objName) {
		var adresTipi =$("input[name='"+objName+"']:checked").val();
		if(adresTipi == 1) {
			$("#FaturaKisiselTC").show();
			$("#FaturaKurumsal1").hide();
			$("#FaturaKurumsal2").hide();
			$("#FaturaKurumsal3").hide();
			$("#FaturaKisiselAd").show();
			$("#FaturaKisiselSoyad").show();
		}
		else if(adresTipi == 2) {
			$("#FaturaKisiselTC").hide();
			$("#FaturaKisiselAd").hide();
			$("#FaturaKisiselSoyad").hide();
			$("#FaturaKurumsal1").show();
			$("#FaturaKurumsal2").show();
			$("#FaturaKurumsal3").show();
		}
	}
	
	function checkSubsciptionForm(step) {
		
		var message = "";
		var assetID=$("input[name='asset_id']:checked").val();
		var odemeTipi=$("input[name='odeme_tipi']:checked").val();
		
		
		
		if( !assetID ) {
			message = message + "\n" + '* Bir abonelik seçin.';
		}
		
		if($("#musteri_id").val() > 0) {
			if( $("#teslimat_adres_id").val() == "") {
				//alert("yeni girilen teslimat adresi alanlarını kontrol et");
			}
			
			if( $("#fatura_adres_id").val() == "") {
				//alert("yeni girilen Fatura adresi alanlarını kontrol et");
			}
		}
		
		if(kampanyaVar) {
			var kampanyaID=$("input[name='kampanya_id']:checked").val();
			if(!kampanyaID) {
				message = message + "\n" + '* Bir kampanya seçin.';
			}
			
			if(forceGiftSelection == true) {
				var hediyeObj=document.getElementsByName("hediyeler");
				var totalSelect=0;
				var lastSelectedIndex="";
				$(".hediyecheckboxList") .each(function(i,item){
					if(item.checked) {
						totalSelect++;
					}
				} );
				if(totalSelect < minHediyeCount) {
					message = message + "\nLütfen en az "+minHediyeCount+", en fazla "+maxHediyeCount+" adet hediye Seçin";
					
				}
			}
		}
		
		if(step ==3) {
			if( !odemeTipi ) {
				message = message + "\n" + '* Ödeme şekli seçin.';
			}
			else {
				if(odemeTipi == 30) {
					if( trim($("#kk_adsoyad").val()) == "") {
						message = message + "\n" + '* Kredi kartı üzerindeki ad soyad';
					}
					if( trim($("#kk_no").val()) == "") {
						message = message + "\n" + '* Kredi kartı numaranızı girin.';
					}
					if( trim($("#kk_cvv").val()) == "") {
						message = message + "\n" + '* Kredi kartı güvenlik numaranızı girin.';
					}
					if( $("#kk_exp_month").val() == "" || $("#kk_exp_year").val() == "") {
						message = message + "\n" + '* Kredi kartı son kullanma tarihini girin.';
					}
				}
				else if(odemeTipi == 80) {
					if($("#mobil_odeme_cep").val() == "") {
						message = message + "\n" + '* Mobil ödeme için GSM No. Yazınız';
					}
				}
			}
		}
		if (message !== '') {
			message+="\n\n\n www.turkuvazabone.com";
			alert("Lütfen Aşağıdaki Hataları Düzeltin\n"+message);
			return false;
		} 
		else {
			
			if($("#musteri_id").val() == "" && message == "") {
				//$.colorbox({href:"https:///?p=Musteriler&action=login&use_ssl=1"});
				window.location.href = "/uye_girisi.html";
				return false;
			}
			else {
				var c=confirm("Verdiğiniz bilgiler doğrultusunda aboneliğiniz başlatılacaktır.\nDevam etmek istiyormusunuz?");
				if(c) {
					$("#abonelik_step").val(2);
					$("#abonelik_form").submit();
				}
			}
		}
		
	}
	
	
	function newAddress() {
		$.colorbox({href:"/?p=AddressBook&action=new"});
	}
	
	
	function changeTeslimatAdres() {
		var adresID = $("#teslimat_adres_id").val();
		if(adresID != "") {
			$("#abonelik_form").submit();
		}
		else {
			$("#teslimat_adres_tanim").val("");
			$("#teslimat_posta_kodu").val("");
			$("#teslimat_ad").val("");
			$("#teslimat_soyad").val("");
			$("#teslimat_irtibat_tel").val("");
			$("#teslimat_adresi").val("");
			$("#teslimat_sehir").val("");
			
			$("#teslimat_ad").attr("readonly","");
			$("#teslimat_soyad").attr("readonly","");
			$("#teslimat_adres_tanim").attr("readonly","");
			$("#teslimat_sehir").attr("disabled","");
			$("#teslimat_semt").attr("disabled","");
			$("#teslimat_irtibat_tel").attr("readonly","");
			$("#teslimat_adresi").attr("readonly","");
			$("#teslimat_posta_kodu").attr("readonly","");
			
			
			
			getSemtListOfSehir('teslimat_sehir',0,'teslimat_semt');
			$(".teslimat_adres_tip_id") .each(function(i,item){
				if(item.checked) {
					item.checked=false;
				}
				item.disabled="";
			} );
			
		}
	}
	
	function changeFaturaAdres() {
		var adresID = $("#fatura_adres_id").val();
		if(adresID != "") {
			$("#abonelik_form").submit();
		}
		else {
			$("#fatura_adres_tanim").val("");
			$("#fatura_ad").val("");
			$("#fatura_soyad").val("");
			$("#fatura_irtibat_tel").val("");
			$("#fatura_adresi").val("");
			$("#fatura_sehir").val("");
			$("#fatura_posta_kodu").val("");
			
			$("#fatura_tc_kimlik_no").val("");
			$("#fatura_unvan").val("");
			$("#fatura_vergi_no").val("");
			$("#fatura_vergi_dairesi").val("");
			$("#fatura_ad").val("");
			$("#fatura_soyad").val("");
			
			$("#FaturaKisiselTC").hide();
			$("#FaturaKurumsal1").hide();
			$("#FaturaKurumsal2").hide();
			$("#FaturaKurumsal3").hide();
			$("#FaturaKisiselAd").hide();
			$("#FaturaKisiselSoyad").hide();
			
			$("#fatura_adres_tanim").attr("readonly","");
			$("#fatura_posta_kodu").attr("readonly","");
			$("#fatura_ad").attr("readonly","");
			$("#fatura_soyad").attr("readonly","");
			$("#fatura_sehir").attr("disabled","");
			$("#fatura_semt").attr("disabled","");
			$("#fatura_irtibat_tel").attr("readonly","");
			$("#fatura_adresi").attr("readonly","");
			$("#fatura_tc_kimlik_no").attr("readonly","");
			$("#fatura_unvan").attr("readonly","");
			$("#fatura_vergi_no").attr("readonly","");
			$("#fatura_vergi_dairesi").attr("readonly","");
			$("#fatura_ad").attr("readonly","");
			$("#fatura_soyad").attr("readonly","");
			
			
			
			
			getSemtListOfSehir('fatura_sehir',0,'fatura_semt');
			$(".fatura_adres_tip_id") .each(function(i,item){
				if(item.checked) {
					item.checked=false;
				}
				item.disabled="";
			} );
		}
	}
	
	function resetCrmTicketForm() {
		$("#gorusme_konu_id").val("");
		$("#yayin_id").val("");
		$("#aciklama").val("");
		$("#diger_konu").val("");
		$("#kategori_id").val("");
	}
	
	function toggleCRMKonu() {
		var konuID=$("#gorusme_konu_id").val();
		if(konuID == -1) {
			$("#subjectOther").show();
		}
		else {
			$("#subjectOther").hide();
			$("#diger_konu").html("");
		}
	}
	
	
	function makeLogin() {
		var message="";
		
		if( trim($("#username").val()) == "") {
			message = message + "\n" + '* Eposta veya GSM No Girin.';
		}
		if( trim($("#password").val()) == "") {
			message = message + "\n" + '* Şifrenizi girin';
		}
		
		if (message !== '') {
			message+="\n\n\n www.turkuvazabone.com";
			alert("Lütfen Aşağıdaki Hataları Düzeltin\n"+message);
			
		} 
		else {
			$("#loginFormContainer").hide();
			$("#loginFormLoader").show();
			$.ajax({
				   type: "POST",
				   data:"username="+trim($("#username").val())+"&password="+trim($("#password").val()),
				   //dataType: 'json',
				   url: "/?p=Login&action=do",			   
				   cache: false,
				   success: function(jsonObject){
						if(jsonObject == "ok") {
							$("#abonelik_form").submit();
							return true;
						}
						else {
							$("#password").val("");
							$("#loginErrorLabel").html("<b>Hatalı E-posta/GSM No. veya şifre girdiniz.</b>");
							$("#loginFormContainer").show();
							$("#loginFormLoader").hide();
							return false;
						}
				   }
				 });
		}
		
	}
	
	
	function getHediyelerOfKampanya(selectedKampanya,selectedHediyeler) {
		var kampanyaID="";
		if(selectedKampanya == 0) {
			kampanyaID=$("input[name='kampanya_id']:checked").val();
		}
		else {
			kampanyaID=selectedKampanya;
		}
		$("#hediyeLoader").show();
		$("#hediyeContainer").hide();
		if(kampanyaID == 0 || !kampanyaID) {
			$("#hediyeContainer").hide();
			$("#hediyeLoader").hide();
		}
		else {
			$.ajax({
				   type: "POST",
				   data:"kampanya_id="+kampanyaID+"&selected_hediye_list="+selectedHediyeler,
				   //dataType: 'json',
				   url: "/?p=Hediyeler&action=getKampanyaHediyeler&use_ssl=1",			   
				   cache: false,
				   success: function(jsonObject){
						$("#hediyeLoader").hide();
						$("#hediyeContainer").html(jsonObject);
						$("#hediyeContainer").show();
				   }
				 });
			//$("#kampanyaContainer").show();
		}
	}
	
	function controlHediyeCount(obj,min,max) {
		var totalSelect=0;
		var lastSelectedIndex="";
		$(".hediyecheckboxList") .each(function(i,item){
			if(item.checked) {
				totalSelect++;
				if(totalSelect > max) {
					alert("En Fazla "+max+" Adet Hediye Seçebilirsiniz");
					obj.checked=false;
				}
			}
		} );
		
	}	
	
	
	
	
	function getPaymentMethods(assetID) {
			$.ajax({
				   type: "POST",
				   data:"asset_id="+assetID,
				   dataType: 'json',
				   url: "/?p=AjaxTools&action=getPaymentType",			   
				   cache: false,
				   success: function(jsonObject){
					if(jsonObject.PaymentType == 1) {
						$("#mobilPayment").show();
					}
					else {
						$("#mobilPayment").hide();
					}
					
				   }
			 });
		
		
		
	}
	
	var kampanyaVar=false;
	
	function toggleKampanyalar(selectedKampanyaID) {
		$("#kampanyaLoader").show();
		$("#kampanyaContainer").hide();
		
		$("#hediyeContainer").hide();
		$("#hediyeLoader").hide();
		
		var assetID= $("input[name='asset_id']:checked").val();
		if(assetID == 0) {
			$("#kampanyaContainer").hide();
			$("#kampanyaLoader").hide();
		}
		else {
			$.ajax({
				   type: "POST",
				   data:"asset_id="+assetID+"&kampanya_id="+selectedKampanyaID,
				   //dataType: 'json',
				   url: "/?p=Kampanya&action=getAssetKampanyalar&use_ssl=1",			   
				   cache: false,
				   success: function(jsonObject){
						if(jsonObject == "yok") {
							kampanyaVar=false;
							$("#kampanyaContainer").html("");
						}
						else {
							kampanyaVar=true;
							$("#kampanyaContainer").html(jsonObject);
						}
						$("#kampanyaLoader").hide();
						
						$("#kampanyaContainer").show();
						//getPaymentMethods(assetID);
						
				   }
				 });
			//$("#kampanyaContainer").show();
		}
	}
	
	
	function getBaslangicTarihi(assetID) {
		var assetID =$("#asset_id").val();
		var yayinID=$("#yayin_id").val();
		if(yayinID > 0) {
			$.ajax({
				   type: "POST",
				   data:"yayin_id="+yayinID,
				   dataType: 'json',
				   url: "/?p=Assets&action=find_start_date",			   
				   cache: false,
				   success: function(jsonObject){
						$("#baslangic_tarihi_month").val(jsonObject.baslangic_tarihi_month);
						$("#baslangic_tarihi_year").val(jsonObject.baslangic_tarihi_year);
						$("#baslangic_tarihi_day").val(jsonObject.baslangic_tarihi_day);
						
						calculateBitisTarihi(jsonObject,assetID);
				   }
				 });
		}
	}
	
	function calculateBitisTarihi(baslangicDateJson,assetID) {
		var buildStartDate=baslangicDateJson.baslangic_tarihi_year+"-"+baslangicDateJson.baslangic_tarihi_month+"-"+baslangicDateJson.baslangic_tarihi_day;
		$.ajax({
			   type: "POST",
			   data:"asset_id="+assetID+"&baslangic_tarihi="+buildStartDate,
			  dataType: 'json',
			   url: "/?p=Abonelikler&action=calculate_end_date",			   
			   cache: false,
			   success: function(jsonObject){
					$("#bitis_tarihi_month").val(jsonObject.bitis_tarihi_month);
					$("#bitis_tarihi_year").val(jsonObject.bitis_tarihi_year);
					$("#bitis_tarihi_day").val(jsonObject.bitis_tarihi_day);
			   }
			 });
	}
	
	
	function resetDates() {
		$("#baslangic_tarihi_month").val("");
		$("#baslangic_tarihi_year").val("");
		$("#baslangic_tarihi_day").val("");
		
		$("#bitis_tarihi_month").val("");
		$("#bitis_tarihi_year").val("");
		$("#bitis_tarihi_day").val("");
	}
	
	
	function getAssetsForAbonelik(obj) {
		var yayinID=$("#"+obj).val();
		$("#assetContainerLoader").show();
		resetDates();
		$("#assetContainer").hide();
		if(yayinID > 0) {
			$.ajax({
				   type: "POST",
				   data:"yayin_id="+yayinID,
				   url: "/?p=Assets&action=getAssets",			   
				   cache: false,
				   success: function(jsonObject){
						$("#assetContainerLoader").hide();
						$("#assetListContainer").html(jsonObject);
						$("#assetListContainer").show();
						$("#assetContainer").show();

				   }
				 });
		}
		else {
			$("#assetContainerLoader").hide();
			$("#assetContainer").hide();
			$("#assetListContainer").html("");
		}
	}
	
	function setField(x,layerName){
		$("#"+layerName).val(x);
	}

	
	
	
	function checkAssetForm() {
		var errorString='';
		if( $("#yayin_id").val() =="" ) {
			errorString+="\n" + '* Dergi Seçiniz';
		}
		
		if( trim($("#asset_tanim").val()) =="" ) {
			errorString+="\n" + '* Asset Tanımı Giriniz';
		}
		
		if( trim($("#asset_aciklama").val()) =="" ) {
			errorString+="\n" + '* Asset Açıklaması Giriniz';
		}
		
		if( trim($("#asset_fiyati").val()) =="" ) {
			errorString+="\n" + '* Asset Fiyatı Giriniz';
		}
		
		if( $("#yayin_id").val() > 0) {
			if( $("#asset_sure_tip").val() =="" ) {
				errorString+="\n" + '* Asset Süresi Giriniz';
			}
		}
		
		if (errorString !== '') {
			errorString+="\n\n Turkuvaz Digital Media";
			alert("Lütfen Aşağıdaki Hataları Düzeltin\n\n"+errorString);
			return false;
		} 
		else {
			return true;
		}
		
	}

	function navigateFrame(url,target) {
		$("#"+target).attr('src', url);
	}
	
	
	function checkAssetType(obj) {
		var assetTipi = $("input[name='asset_tipi']:checked").val();
		if(assetTipi == 1) {
			$("#containerInternetSales").show();
		}
		else {
			$("#containerInternetSales").hide();
		}
	}
	
	function getAbonelikSureleri(obj,selectedSureID) {
		var yayinID=$("#"+obj).val();
		$("#abonelikSureleriloaderDiv").show();
		$("#abonelikSureleriContainer").hide();
		$("#abonelikSureleriOfYayin").hide();
		if(yayinID > 0) {
			
			$.ajax({
				   type: "POST",
				   data:"yayin_id="+yayinID+"&sure_id="+selectedSureID,
				   url: "/?p=Assets&action=getAbonelikSureleri",			   
				   cache: false,
				   success: function(jsonObject){
						$("#abonelikSureleriloaderDiv").hide();
						$("#abonelikSureleriOfYayin").html(jsonObject);
						$("#abonelikSureleriOfYayin").show();
						$("#abonelikSureleriContainer").show();
				   }
				 });
			

		}
		else {
			$("#abonelikSureleriloaderDiv").hide();
			$("#abonelikSureleriOfYayin").hide();
			$("#abonelikSureleriContainer").hide();
		}
	}
	
	
	function getKampanyalarOfYayin(obj,selectedKampanyaID) {
		var yayinID=$("#"+obj).val();
		$("#loaderDiv").show();
		$("#KampanyaContainer").hide();
		$("#KampanyaListOfYayin").hide();
		if(yayinID > 0) {
			
			$.ajax({
				   type: "POST",
				   data:"yayin_id="+yayinID+"&kampanya_id="+selectedKampanyaID,
				   url: "/?p=Kampanya&action=select",			   
				   cache: false,
				   success: function(jsonObject){
						$("#loaderDiv").hide();
						$("#KampanyaListOfYayin").html(jsonObject);
						$("#KampanyaListOfYayin").show();
						$("#KampanyaContainer").show();
				   }
				 });
			

		}
		else {
			$("#loaderDiv").hide();
			$("#KampanyaListOfYayin").hide();
			$("#KampanyaContainer").hide();
		}
	}
	
	function toggleAssetActivationForCallCenter(assetID,objVal) {
		$("#AssetActivatorCallCenterLoader_"+assetID).show();
		$("#asset_callcenter_radio_"+assetID).hide();
		
		var activationStatus=$('#'+objVal).attr('checked');
		if(activationStatus) {
			activationStatus=1;
		}
		else {
			activationStatus=0;
		}
		$.ajax({
			   type: "POST",
			   data:"activationStatus="+activationStatus+"&assetID="+assetID,
			   url: "/?p=Assets&action=callCenterActivation",			   
			   cache: false,
			   success: function(jsonObject){
					$("#AssetActivatorCallCenterLoader_"+assetID).hide();
					$("#asset_callcenter_radio_"+assetID).show();
			   }
			 });
	}
	
	
	function toggleAssetActivationForInternet(assetID,objVal) {
		$("#AssetActivatorLoader_"+assetID).show();
		$("#asset_radio_"+assetID).hide();
		
		var activationStatus=$('#'+objVal).attr('checked');
		if(activationStatus) {
			activationStatus=1;
		}
		else {
			activationStatus=0;
		}
		$.ajax({
			   type: "POST",
			   data:"activationStatus="+activationStatus+"&assetID="+assetID,
			   url: "/?p=Assets&action=onlineActivation",			   
			   cache: false,
			   success: function(jsonObject){
					$("#AssetActivatorLoader_"+assetID).hide();
					$("#asset_radio_"+assetID).show();
			   }
			 });
	}
	
	
	
	function toggleKampanyaActivationForCallCenter(kampanyaID,objVal) {
		$("#KampanyaActivatorCallCenterLoader_"+kampanyaID).show();
		$("#kampanya_callcenter_radio_"+kampanyaID).hide();
		
		var activationStatus=$('#'+objVal).attr('checked');
		if(activationStatus) {
			activationStatus=1;
		}
		else {
			activationStatus=0;
		}
		$.ajax({
			   type: "POST",
			   data:"activationStatus="+activationStatus+"&kampanyaID="+kampanyaID,
			   url: "/?p=Kampanya&action=callCenterActivation",			   
			   cache: false,
			   success: function(jsonObject){
					$("#KampanyaActivatorCallCenterLoader_"+kampanyaID).hide();
					$("#kampanya_callcenter_radio_"+kampanyaID).show();
			   }
			 });
	}
	
	function toggleKampanyaActivationForInternet(kampanyaID,objVal) {
		$("#KampanyaActivatorLoader_"+kampanyaID).show();
		$("#kampanya_radio_"+kampanyaID).hide();
		
		var activationStatus=$('#'+objVal).attr('checked');
		if(activationStatus) {
			activationStatus=1;
		}
		else {
			activationStatus=0;
		}
		$.ajax({
			   type: "POST",
			   data:"activationStatus="+activationStatus+"&kampanyaID="+kampanyaID,
			   url: "/?p=Kampanya&action=onlineActivation",			   
			   cache: false,
			   success: function(jsonObject){
					$("#KampanyaActivatorLoader_"+kampanyaID).hide();
					$("#kampanya_radio_"+kampanyaID).show();
			   }
			 });
	}
	

	function validate(form) {
		var message = "";
		
		form.user.value = trim(form.user.value);
		form.password.value = trim(form.password.value);
	
		if (form.user.value == "") {
			message = message + "\n" + '* Kullanıcı Adı giriniz:';
		}
	
		if (form.password.value == "") {
			message = message + "\n" + '* Şifre giriniz:';
		}
	
		if (message !== '') {
			alert('Aşağıda belirtilen eksikleri tamamlayıp tekrar deneyin;\n' + message + '\n\n' + 'Bilgi İşlem Merkezi');
			return false;
		} else {
			return true;
		}
	}
	
	function check(form) {
	    if (validate(form))
	        form.submit();
	}
	function trim(s) {
		s = s.replace(/^\s*/,'').replace(/\s*$/, '');
		return s;
	}
	function RpopUp(URL,W,H) 
	{
		LeftPosition = screen.width ? (screen.width - W)/2 : 100;
		//TopPosition = screen.height ? (screen.height - H)/2: 100;
		TopPosition = 10;

		id = 1;
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + W + ",height=" + H + ",left=" + LeftPosition + ",top=" + TopPosition + "');");
		//eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + W + ",height=" + H + ",left=200,top=5');");
	}
	isFocus = 0;

	function FormatPhoneNumber(thisis) {
		var tempstr,newstr,str,i,str2 ;
		var commapos,aftercomma,commacount;
		i=0;

		if (isFocus == 1)
		{
			isFocus = 0; 
			return false; 
		}
		
		thisis.value = trimNumber(thisis.value);
		str = thisis.value;
		
		while ( 15 > i) {
			str = str.replace(" ", "");
			i = i + 1;
		}
		
		if (str.length > 9) 
		{
			tempstr = str;
			newstr = "";
			newstr = tempstr.substr(0, 4) + " " + tempstr.substr(4, 3) + " " + tempstr.substr(7, 2) + " " + tempstr.substr(9); 
			thisis.value = newstr;
		}
		else if (str.length > 7) 
		{
			tempstr = str;
			newstr = "";
			newstr = tempstr.substr(0, 4) + " " + tempstr.substr(4, 3) + " " + tempstr.substr(7); 
			thisis.value = newstr;
		}
		else if (str.length > 4) 
		{
			tempstr = str;
			newstr = "";
			newstr = tempstr.substr(0, 4) + " " + tempstr.substr(4); 
			thisis.value = newstr;
		}
	}


	function Only_Numeric(e) {	
		var whichCode = (window.Event) ? e.which : e.keyCode;
		//alert(whichCode);
		if (whichCode == 13) return true;  // Enter
		if (whichCode == 44) return true;  // Comma
		if (whichCode > 57 ) return false;
		if (whichCode < 48 && whichCode > 13) return false;
	}
	function trimNumber(s) {
		s = s.replace(/^\s*/,'').replace(/\s*$/, '');
		return s;
	}
	
	
	function checkKampanyaForm() {
		var errorString="";
		
		if( trim($("#kampanya_tanim").val()) =="") {
			$("#kampanya_tanim").val("");
			errorString+="* KAMPANYA ADI GİRİNİZ\n";
		}
		if( trim($("#kampanya_aciklama").val()) =="") {
			$("#kampanya_aciklama").val("");
			errorString+="* KAMPANYA AÇIKLAMASI GİRİNİZ\n";
		}
		if( trim($("#baslangic_tarihi").val()) =="") {
			$("#baslangic_tarihi").val("");
			errorString+="* BAŞLANGIÇ TARİHİ GİRİNİZ\n";
		}
		if( trim($("#bitis_tarihi").val()) =="") {
			$("#bitis_tarihi").val("");
			errorString+="* BİTİŞ TARİHİ GİRİNİZ\n";
		}
		
		if( errorString != '' ) {
			errorString+="\n\n Turkuvaz Digital Media";
			alert("Lütfen Aşağıdaki Hataları Düzeltin\n\n"+errorString);
			return false;
		}
		else {
			var askConfirm=confirm("Kaydetmek istediğinize emin misiniz?");
			if(askConfirm)
				return true;
			else
				return false;
		}
	}
	
	function checkHediyeForm() {
		var errorString='';
		if( trim($("#hediye_tanim").val()) =="") {
			$("#hediye_tanim").val("");
			errorString+="* HEDİYE TANIMI\n";
		}
		if( errorString != '' ) {
			errorString+="\n\n Turkuvaz Digital Media";
			alert("Lütfen Aşağıdaki Hataları Düzeltin\n\n"+errorString);
			return false;
		}
		else {
				return true;
		}
		
	}
	

	function checkMusteriForm() {
		var hasErrors=false;
		var errorString="";
		
		var musteriTipi = $("input[name='musteri_tipi']:checked").val();
		var adresTipi = $("input[name='adres_tipi']:checked").val();
		var cinsiyet = $("input[name='cinsiyet']:checked").val();
		
		if( !musteriTipi) {
			errorString+="* MÜŞTERİ TİPİ SEÇİNİZ\n";
		}
		if( trim($("#ad").val()) =="") {
			$("#ad").val("");
			errorString+="* AD GİRİNİZ\n";
		}
		if( trim($("#soyad").val()) =="") {
			$("#soyad").val("");
			errorString+="* SOYAD GİRİNİZ\n";
		}
		if( !cinsiyet) {
			errorString+="* CİNSİYET BELİRTİN\n";
		}
		if( trim($("#eposta").val()) =="") {
			$("#eposta").val("");
			errorString+="* E-POSTA ADRESİ GİRİNİZ\n";
		}
		if( !adresTipi) {
			errorString+="* ADRES TİPİ SEÇİNİZ\n";
		}
		if( trim($("#adres").val()) =="") {
			$("#adres").val("");
			errorString+="* ADRES GİRİNİZ\n";
		}
		if( trim($("#sehir").val()) ==0) {
			$("#sehir").val("");
			errorString+="* ŞEHİR SEÇİN\n";
		}
		if( trim($("#semt_tanim").val()) =="") {
			$("#semt_tanim").val("");
			errorString+="* SEMT GİRİN\n";
		}
		
		if ( $("#tel1").val() == "" &&  $("#tel2").val() == "" && $("#msisdn").val() == "" ){
			
			errorString = errorString + "\n" + '* ENAZ BİR TELEFON NO GİRİNİZ!';
		}
		else
		{
			if ( $("#tel1").val() != "" && (checkNum($("#tel1").val()) == 0 || $("#tel1").val().length < 13)){
				errorString = errorString + "\n" + '* HATALI TELEFON NO 1!';
			}
			
			if ($("#tel2").val() != "" && (checkNum($("#tel2").val()) == 0 || $("#tel2").val().length < 13)){
				errorString = errorString + "\n" + '* HATALI TELEFON NO 2!';
			}		
			
			if ($("#msisdn").val() != "" && (checkNum($("#msisdn").val()) == 0 || $("#msisdn").val().length < 13)){
				errorString = errorString + "\n" + '* HATALI CEP TEL NO!';
			}		
		}
		
		if ($("#fax").val() != "" && (checkNum($("#fax").val()) == 0 || $("#fax").val().length < 13)){
			errorString = errorString + "\n" + '* HATALI FAKS NO!';
		}
		
		
		if( errorString != '' ) {
			errorString+="\n\n Turkuvaz Digital Media";
			alert("Lütfen Aşağıdaki Hataları Düzeltin\n\n"+errorString);
			return false;
		}
		else {
			var askConfirm=confirm("Kaydetmek istediğinize emin misiniz?");
			if(askConfirm)
				return true;
			else
				return false;
		}
	}
	
	function checkNum(data) {      // checks if all characters 
		var valid = "0123456789 ";     // are valid numbers or a "."
		var ok = 1; var checktemp;
		for (var i=0; i<data.length; i++) {
			checktemp = "" + data.substring(i, i+1);
			if (valid.indexOf(checktemp) == "-1") return 0; }
		return 1;
	}
	
	function closeWindow() {
		var co=confirm("Kapatmak istediğinize emin misiniz?");
		if(co) {
			window.close();
		}
	}
	
	function mypopup(url,name,w,h){
		w = w ? w : 600;
		h = h ? h : 600;	
		t = screen.availHeight/2 - h/2;
		l = screen.availWidth/2 - w/2;	
		window.open(url,name,'width='+w+',height='+h+',top='+t+',left='+l+',toolbars=no,resizable=1,scrollbars=1');	
	}

