var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-17195174-2']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
  
$(document).ready(function(){
	var urlwakaf = 'http://www.wakafquran.org';
	web=document;
	address=escape(web.URL);
	addressSplit=address.split('/project');

	var myOpen=function(hash) { hash.w.fadeIn('1000',function(){ }); }; 
	var myClose=function(hash) { hash.w.fadeOut('1000',function(){ hash.o.remove(); }); };
	$('#dialog').jqm({onHide:myClose, onShow:myOpen}); 	

	
		

	$('table.detail_part_table tr:nth-child(2) td:nth-child(4) input[type=checkbox]').attr('checked', '"checked"');
	buyId = $('table.detail_part_table tr:nth-child(2) td:nth-child(4) input[type=checkbox]').val();
	
	$('#buy_id_jemput').val(buyId);	
	$('#buy_id_transfer').val(buyId);		
		
	$('table.detail_part_table tr td input[type=checkbox]').click(function(){
		buyId = $(this).val();
		$('#buy_id_jemput').val(buyId);	
		$('#buy_id_transfer').val(buyId);	

	});	
	
	$('.radio_pilihan').click(function(){
		pilih = $(this).val();
		$('#pilih_transfer').val(pilih);	
	});
	
	
	$('#konfirmasi_bank').submit(function(eve){
		eve.preventDefault();
			
			$.ajax({
				url: "/user/konfirmasi_pembayaran_transfer",
				type: "POST",
				dataType: "html",
				data: $(this).serialize(), 
				beforeSend: function(){

					/* $('#imageloading').show('normal');
					$('#reg_status').remove();	*/
				},
				
				success: function(html){
					// $('#imageloading').hide('normal');
					if(html ==""){
						$('#thnk').jqm({onHide:myClose, onShow:myOpen}); 
						$('#thnk').jqmShow();
						$('.btnsenddata').attr('type="button"')	;				
					}
					else{
						$('#validation_div').html(html);	
					}
					
					/*if(html == ''){
						$('#reg_status').remove();
						window.location.href = urlwakaf+'/cart';
					}*/
				}
			});			
	});	
	
	$('#konfirmasi_jemput').submit(function(eve){
		eve.preventDefault();
			
			$.ajax({
				url: "/user/konfirmasi_pembayaran_jemput",
				type: "POST",
				dataType: "html",
				data: $(this).serialize(), 
				beforeSend: function(){

					/* $('#imageloading').show('normal');
					$('#reg_status').remove();	*/
				},
				
				success: function(html){
					// $('#imageloading').hide('normal');
					
					if(html ==""){
						$('#thnk').jqm({onHide:myClose, onShow:myOpen}); 
						$('#thnk').jqmShow();					
						$('.btnsenddata').attr('type="button"');	
					}
					else{
						$('#validation_div').html(html);	
					}
					

					
					/*if(html == ''){
						$('#reg_status').remove();
						window.location.href = urlwakaf+'/cart';
					}*/
				}
			});			
	});		
		
	
	 $('#to_akun_setting').click(function(){
		
		$('.btn_akun_setting a').trigger('click');
	
	}); 
	

	
	


	/* window.location.href = 'http://www.ilmuwebsite.com'; */

	$('.pelajari_vacc').click(function(eve){
		eve.preventDefault(eve);
		$('.donasi_vacc').slideToggle('fast');
	});

	$(document).ready(function(){
		
		$('.modal').modalpop({speed:100});
	});

	
   $("input.file_upload").filestyle({ 
       image: urlwakaf+'/template/frontend/images/choose-file.png',
       imageheight : 32,
       imagewidth : 138,
       width : 260
   });
	
	$('#nama_publikasi').click(function(){
		$('#name_type_1').attr('checked', '"checked"');
	
	});
	
	$.get('/cart/pilihan_dana', function(html){
			if(parseFloat(html)){
				$('#pilihanoperasional').val(html);
			}
			
			else{
				$('#pilihanoperasional').val('15%');
			}
		
		});
		
		
	$('.batal').click(function(eve){
		
		var val = $(this).siblings().val();	

	
		// alert(val);	
		eve.preventDefault();
		//var valQty = 0;
		//var valRowid = $(this).siblings('.rowid').val();
		var valDel = $(this).siblings().val();	
		
		$.post('/user/delete_wakaf', {
			 delId: valDel
		}, function(html){
				$('.row'+val).fadeOut('slow');
				/*$('.total'+valRowid).html(html).fadeIn();
				$('.value'+valRowid).fadeOut('slow');
				$('em.operasionalpersen').load('/cart/pilihan_dana').fadeOut().fadeIn();
				$('.operasional').load('/cart/dana_operasional_bwa_look').fadeOut().fadeIn();
				$('.totalBayarLitle').load('/cart/total_donasi').fadeOut().fadeIn();
				$('span#totalBayar').load('/cart/total_donasi').fadeOut().fadeIn();
				$('#totalcartstrong').load('/cart/total_donasi').fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);*/
			});
	});		
	
	
	
	$('.valinput').keyup(function(){
	  var charLength = $(this).val().length;
	  var name =  $(this).attr('id').split('_');
	  var siblings = parseInt(name[1]) + 1;
 		if(charLength == 4){
			
			$('#val_'+siblings).focus();
			// siblings('#val_'+name).focus()
			// alert(name);
		}

		
	});
	
	
	$('.btn_akun_setting a').click(function(){
		$(this).removeClass().addClass('green').siblings().removeClass().addClass('default');
		
		
		var atr = $(this).attr('id');
		if(atr=='alamat_surat_link'){
			$('#rekening_donasi_pribadi').hide();	
			$('#info').hide();
			$('#alamat_surat').show();
		}
		
		else if(atr=='rekening_donasi_pribadi_link'){
			$('#alamat_surat').hide();
			$('#info').hide();			
			$('#rekening_donasi_pribadi').show();			
		}
		
				
		else {
			$('#rekening_donasi_pribadi').hide();			
			$('#alamat_surat').hide();
			$('#info').show();	
			
		} 
	});
	

	/* untuk 15% */
	
	$('#form_reg_user').submit(function(eve){
			eve.preventDefault();
			var namaDepan = $('#nama_depan').val();

			// replace in here ... 
			$.ajax({
				url: "/user/reg/true",
				type: "POST",
				dataType: "html",
				data: $(this).serialize(),
				beforeSend: function(){
					$('#imageloading').show('normal');
					$('#reg_status').remove();	
				},
				
				success: function(html){
					$('#imageloading').hide('normal');
					$('#imageloading').after('<h7 id="reg_status">'+html+'</h7>');
					if(html == ''){
						$('#reg_status').remove();
						window.location.href = urlwakaf+'/cart';
					}
				}
			});
						
	});	
	

	
	

	
		
	$('#loginbutton').click(function(){
		var valLoginButton = $(this).val();		
			if(valLoginButton == 'Login!'){
			$('#user_login_form').slideToggle(200);
			$('#user_login_form_in_login').slideToggle(200);
					
				$(this).attr('value','Daftar');
				$('#ask_user').html('Member Baru?').fadeOut('fast').fadeIn('fast');
				$('title').html('User Login | Badan Wakaf Al-Quran');
				$('#tell_user').html('Bila Anda belum punya akun, Daftar terlebih dahulu atau jika Anda sudah pernah daftar, Anda bisa menggunakan form login sebelah kiri.');
			}
			
			else if(valLoginButton == 'Daftar'){
				$(this).attr('value','Login!');
				$('#user_login_form').slideToggle(200);
				$('#user_login_form_in_login').slideToggle(200);	
							
				$('title').html('User Registration | Badan Wakaf Al-Quran');
				$('#ask_user').html('Apakah Anda sudah menjadi wakif member BWA?').fadeOut('fast').fadeIn('fast');;
				$('#tell_user').html('Silahkan klik login untuk login sebagai member wakif. Bila Anda belum punya akun Daftar terlebih dahulu. Gunakan form Daftar sebelah kiri.');
			}
		});
	
	
	$('#pilihanoperasional').change(function(eve){
		var valPilihanoperasional = $(this).val();
		$.post('/cart/dana_operasional_bwa', {
			 pilihanoperasional: valPilihanoperasional
		}, function(html){
				$('.operasional').html(html).fadeOut().fadeIn();
				$('em.operasionalpersen').load('/cart/pilihan_dana').fadeOut().fadeIn();
				$('.totalBayarLitle').load('/cart/total_donasi').fadeOut().fadeIn();
				$('span#totalBayar').load('/cart/total_donasi').fadeOut().fadeIn();
				$('#totalcartstrong').load('/cart/total_donasi').fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
				
			});		
			
		
		
	});
	
	$('.qty').keyup(function(eve){
		eve.preventDefault();
		var valQty = $(this).val();
		var valRowid = $(this).siblings('.rowid').val();
		var valPrice = $(this).siblings('.price').val();
		$(this).parents('tr.value').children('tr.value td.total').text(valPrice);
		
		$.post('/cart/update_cart', {
			 rowid: valRowid, qty:valQty, price:valPrice
		}, function(html){
				$('.total'+valRowid).html(html).fadeOut().fadeIn();
				$('.operasional').load('/cart/dana_operasional_bwa_look').fadeOut().fadeIn();
				$('em.operasionalpersen').load('/cart/pilihan_dana').fadeOut().fadeIn();
				$('.totalBayarLitle').load('/cart/total_donasi').fadeOut().fadeIn();
				$('span#totalBayar').load('/cart/total_donasi').fadeOut().fadeIn();			
				$('#totalcartstrong').load('/cart/total_donasi').fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
			});
	});
	
	$('.btnDelete').click(function(eve){
		eve.preventDefault();
		var valQty = 0;
		var valRowid = $(this).siblings('.rowid').val();
		
		$.post('/cart/update_cart', {
			 rowid: valRowid, qty:valQty
		}, function(html){
				$('.total'+valRowid).html(html).fadeIn();
				$('.value'+valRowid).fadeOut('slow');
				$('em.operasionalpersen').load('/cart/pilihan_dana').fadeOut().fadeIn();
				$('.operasional').load('/cart/dana_operasional_bwa_look').fadeOut().fadeIn();
				$('.totalBayarLitle').load('/cart/total_donasi').fadeOut().fadeIn();
				$('span#totalBayar').load('/cart/total_donasi').fadeOut().fadeIn();
				$('#totalcartstrong').load('/cart/total_donasi').fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
			});
	});	
		
	$('.choices').attr('checked', '"checked"');
	
	
	$('.btn_bank').click(function(){
		$('.konfirmasi_bank').slideDown().siblings('.konfirmasi_jemput').slideUp();
		$('.validate_form').hide();
	
	});
	
	$('.btn_jemput').click(function(){
		$('.konfirmasi_jemput').slideDown().siblings('.konfirmasi_bank').slideUp();
		$('.validate_form').hide();
	});
	

	
	
	
	$('.choices').click(function(){
		var choicesval = $(this).val();
		if ($(this).is(":checked")){
			$('.cat_id_'+choicesval).show('fast');
			
			alert($(this).is(":checked").length());
			
		}else{
			$('.cat_id_'+choicesval).hide('fast');
		}
		
		
	
	});
});
	
	

	/*$('.form_wakaf').submit(function(eve){
			eve.preventDefault();
			var idwakaf = $(this).children('.id').val();
			
			
			// replace in here ... 
			$.ajax({
				url: "/program/add_wakaf",
				type: "POST",
				dataType: "html",
				data: $(this).serialize(),
				beforeSend: function(){
					$('#messagewakaf').fadeOut('slow');
					$('#messagewakaf').remove();
					$('#imageloading'+idwakaf).show('normal');
					
				},
				
				success: function(html){
					
					$('#totalcartstrong').text(html).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300);
					$('#imageloading'+idwakaf).after('<h7 id="messagewakaf">Terima kasih, <a href="/cart">Keranjang Donasi</a> Anda telah di update, Silahkan <a href="/cart">Klik disini</a> untuk pembayaran! </h7>');
					$('#messagewakaf').fadeIn('slow');
					$('#messagewakaf').css('display','block');
					
					$('#imageloading'+idwakaf).hide('normal');
				}
			});
						
	});	*/
	
    
	


	
	/*$('#formcart').ready(function(){
		var valPilihanoperasional = $('#pilihanoperasional').val();
		$.post('/cart/dana_operasional_bwa', {
			 pilihanoperasional: valPilihanoperasional
		}, function(html){
				$('.operasional').html(html).fadeOut().fadeIn();
				$('em.operasionalpersen').load('/cart/pilihan_dana').fadeOut().fadeIn();
				$('.totalBayarLitle').load('/cart/total_donasi').fadeOut().fadeIn();
				$('span#totalBayar').load('/cart/total_donasi').fadeOut().fadeIn();
				$('#totalcartstrong').load('/cart/total_donasi');
			});	
	})*/


			/*var quantity = $(this).children('.qty').val();
			var idwakaf = $(this).children('.id').val();
			var namewakaf = $(this).children('.name').val();
			var pricewakaf = $(this).children('.price').val();
			
			$.post('/program/add_wakaf', {
				qty:quantity, id:idwakaf, name:namewakaf, price:pricewakaf
			}, 
				function(html){
					$('#totalcartstrong').text(html);
					
				}); */
			
			// $(this).children('.paketwakaf').after('<br />Anda telah menambahkan wakaf..<br />');

		
		
		// console.log(qty)
		/*$.get('/program/add_wakaf', function(html){
			if(parseFloat(html)){
				$('#totalcartstrong').text(html);
			}
			
			else{
				$('#totalcartstrong').text('gagal');
			}
		
		});	
	});
	
	$('#test').live('click', function(eve){
		eve.preventDefault();
		$.get('/program/task', function(html){
			if(parseFloat(html)){
				$('#test').text(html);
				
			}
			
			else{
				$('#test').text('gagal');
			}
		
		});
	});*/


