function FindCinemaByCity(is_movie, city_id, city_name){
try{
	var get_cinema_content;
	var get_cinema_type = document.getElementsByName( "cinema_type" );	
	var cinema_type_value = "";
	for (i=0; i< get_cinema_type.length; i++ ) {
		 if(get_cinema_type[i].checked == true ) {
			cinema_type_value = get_cinema_type[i].value;
		 }
	}

 if (cinema_type_value == '0' )
    get_cinema_content = $('#city_'+city_id).html()
 else
    get_cinema_content = $('#city_'+city_id+'_'+cinema_type_value).html()
	

 var movie_id = $('#movie_id').val();
 $('#span_city_name').html(city_name)
 dropdowncontent.hidediv("city_content");
 $('#cinema_id').val("");
 $('#span_cinema_name').html("Select Cinema");
 
 if (!(get_cinema_content == "" || get_cinema_content == "undefined"))
   $('#cinema_content').html(get_cinema_content)
 else
 	$('#cinema_content').html($('#no_cinema_list').html())
	
 $('#span_ticket_price_'+movie_id).html("");
 
 if (is_movie) {
    ClearDateShow(movie_id)
	ClearTimeShow(movie_id)
	$('#ticket_price_'+movie_id).val("0");
	$('#div_synopsis_'+movie_id).animate({ height: "hide" }, { duration: 500 });
 }
 
anchorobj=$('#link_cinema_content').get(0);
anchorobj.onclick(anchorobj);
}catch(err) {}
}
//=============================================================================================================

function RefreshCinemaOption(){
try{
 $('#cinema_id').val("");
 $('#span_city_name').html("Select City")
 $('#span_cinema_name').html("Select Cinema");	 
}catch(err) {}
}
//=============================================================================================================

function SetCinemaSelected(is_movie, cinema_id, cinema_name) {
try{
 $('#cinema_id').val(cinema_id);
 $('#cinema_name').val(cinema_name);
 $('#span_cinema_name').html(cinema_name);
 var movie_id = $('#movie_id').val();
  
   $('#span_ticket_price_'+movie_id).html("");
   
   if (is_movie) {
	GetDate(cinema_id, document.getElementById("movie_id").value)
	ClearTimeShow(movie_id);
	$('#div_synopsis_'+movie_id).animate({ height: "show" }, { duration: 500 });
 }
 
 dropdowncontent.hidediv("cinema_content"); 
}catch(err) {}	
}
//=============================================================================================================

function GetMoviePrice(is_movie, movie_id) {
try{
  var get_sid		 = $('#sid').val()
  var get_cinema_id  = $('#cinema_id').val()
  var date_show      = $('#date_show_'+movie_id).val()
  var time_show      = $('#time_show_'+movie_id).val()
  $('#ticket_price_'+movie_id).html("");
  
  
  if (is_movie) {
	  get_cinema_id = $('#cinema_id_movie').val()
  }
  
  if ( time_show.length > 1 ) {
	
	  OpenPopupLoading("Please wait...");
	  	$.ajax({
			type: "POST",
			url: "ajax_request.php",
			data: 'ajax_order=get_schedule_price&sid='+get_sid+'&cinema_id='+trim(get_cinema_id)+'&movie_id='+trim(movie_id)+'&date_show='+trim(date_show)+'&time_show='+trim(time_show),
			cache: false,
			async: false,
			success: function(data){
				if(data == 0 || data == "")
					OpenPopupAlert("Maaf, jadwal yang anda inginkan tidak ditemukan. Silahkan melakukan pemilihan jam tayang lain.");
				else {
					$('#ticket_price_'+movie_id).val(data)
					$('#span_ticket_price_'+movie_id).html("Price: <span>Rp."+number_format(data)+"</span>");
					ClosePopupDialog();
				}
			},
			error:function(){
				 OpenPopupAlert("Maaf, sedang terjadi permasalahan dalam sistem kami. Silahkan ulangi beberapa saat lagi.");
			}
		});
  }
  else {
	  OpenPopupAlert("Silahkan untuk melakukan pemilihan tanggal tayang terlebih dahulu.");
  }
  
}catch(err) {}	
}
//=============================================================================================================	

function BookingByCinema() {
try{
  var get_sid		   = $('#sid').val()
  var get_cinema_id    = $('#cinema_id').val()
  var get_cinema_name  = $('#cinema_name').val()
  dropdowncontent.hidediv("cinema_content"); 
  dropdowncontent.hidediv("city_content"); 
  if (get_cinema_id.length > 1 && $('#span_cinema_name').html() != "Select Cinema") {
	  OpenBannerLoading("Please wait...");
	  	$.ajax({
			type: "POST",
			url: "ajax_request.php",
			data: 'ajax_order=set_booking_by_cinema&sid='+get_sid+'&cinema_id='+trim(get_cinema_id)+'&cinema_name='+trim(get_cinema_name),
			cache: false,
			async: false,
			success: function(data){
				if(data == 1 )
					setTimeout("window.location='gui.booking_cinema.php?sid="+get_sid+"'", 3000)
				else 
					OpenPopupAlert("Maaf, sedang terjadi permasalahan dalam sistem kami. Silahkan ulangi beberapa saat lagi.");
			},
			error:function(){
				 OpenPopupAlert("Maaf, sedang terjadi permasalahan dalam sistem kami. Silahkan ulangi beberapa saat lagi.");
			}
		});
  }
  else {
	  OpenPopupAlert("Silahkan untuk melakukan pemilihan bioskop terlebih dahulu.");
  }
  
}catch(err) {}
}
//=============================================================================================================

function GetTime(is_movie, cinema_id, movie_id, date_show) {
try{
  var get_sid = $('#sid').val()
  $('#movie_id').val(movie_id)
  var get_time_show =$('#time_show_'+movie_id).get(0);
  if (is_movie) {
	  cinema_id = $('#cinema_id_movie').val()
  }
  ClearTimeShow(movie_id)
  if (cinema_id.length > 1 && movie_id.length > 1 && date_show.length > 1) {
	  $.ajax({
			type: "POST",
			url: "ajax_request.php",
			data: 'ajax_order=get_movie_time&sid='+trim(get_sid)+'&cinema_id='+trim(cinema_id)+'&movie_id='+trim(movie_id)+'&date_show='+trim(date_show),
			cache: false,
			async: false,
			success: function(data){
				ClearTimeShow(movie_id)
				if (!(data == '0' || data == '')) {
					var arr_result = data.split(";");
					var value = '';
					var text = '';
					for (i=0; i < arr_result.length; i++) {
						 value = arr_result[i];
						 addOption(get_time_show, trim(value), trim(value));
					}
	   			}
			},
			beforeSend: function(){
     			 get_time_show.remove(0);
          		 addOption(get_time_show, "", "Loading..");
   			},
			error:function(){
				 OpenPopupAlert("Maaf, sedang terjadi permasalahan dalam sistem kami. Silahkan ulangi beberapa saat lagi.");
			}
		});
  }
  else if (date_show == '' ) {
	return false;
  }
  else {
	OpenPopupAlert("Pemesanan yang kamu masukkan tidak dapat diproses, silahkan untuk melakukan pemesanan ulang.");
  	return false;
  }
}catch(err) {}
}

//=============================================================================================================

function BookingConfirmation(is_movie, cinema_id, cinema_name, movie_id, movie_title) {
try {
	no_error = true;
	var error_message = "";
	
	if (is_movie) {
	   cinema_id    = $('#cinema_id_movie').val()
	   cinema_name  = $('#cinema_name_movie').val()
    }

    var date_show    = $('#date_show_'+movie_id).val()
	var time_show    = $('#time_show_'+ movie_id).val()
	var total_bought = $('#total_bought_'+movie_id).val()
	var surcharge 	 = $('#surcharge_'+movie_id).val()
	var member_to 	 = "";
	
	if ( cinema_id.length < 1 )  {
      error_message += "* Pilih bioskop terlebih dahulu.<br>";
	  no_error = false;
 	}
	
	if ( date_show.length < 1 )  {
      error_message += "* Silahkan untuk memilih tanggal tayang terlebih dahulu.<br>";
	  no_error = false;
 	}
	
	if ( time_show.length < 1 )  {
      error_message += "* Silahkan untuk memilih jam tayang terlebih dahulu.<br>";
	  no_error = false;
 	}
	
	if ( total_bought.length < 1 )  {
      error_message += "* Pilih jumlah tiket yang akan dibeli.<br>";
	  no_error = false;
 	}
	
	var ticket_price = $('#ticket_price_'+movie_id).val()
	 
	 if ( ticket_price.length < 1 || ticket_price == "0")  {
      error_message += "* Maaf, jadwal yang anda inginkan tidak ditemukan. Silahkan melakukan pemilihan jam tayang lain.<br>";
	  no_error = false;
 	}
  
	total_order = parseFloat(ticket_price * total_bought)+parseFloat(surcharge)
	
	var set_message =  '<table width="100%" cellpadding="0" cellspacing="0" border="0">'+
						  '<tr>'+
							'<td width="1%">&nbsp;</td>'+
							'<td colspan="3" height="30">Apakah kamu ingin melakukan pembelian tiket yang tertera dibawah ini:</td>'+
							'<td width="1%">&nbsp;</td>'+
						 '</tr>'+
						
						  '<tr>'+
							   '<td height="25">&nbsp;</td>'+
							   '<td width="33%" valign="middle">Cinema</td>'+
							   '<td width="5%" align="center" valign="middle">:</td>'+
							   '<td width="60%" valign="middle">'+cinema_name+'</td>'+
							   '<td>&nbsp;</td>'+
						   '</tr>'+
						   
						  '<tr>'+
							  '<td height="25">&nbsp;</td>'+
							  '<td valign="middle">Movie</td>'+
							  '<td align="center" valign="middle">:</td>'+
							  '<td valign="middle">'+movie_title+'</td>'+
							  '<td>&nbsp;</td>'+
							'</tr>'+
						
							'<tr>'+
							  '<td height="25">&nbsp;</td>'+
							  '<td valign="middle">Date</td>'+
							  '<td align="center" valign="middle">:</td>'+
							  '<td valign="middle">'+date_show+'</td>'+
							  '<td>&nbsp;</td>'+
							'</tr>'+
							
							'<tr>'+
							  '<td height="25">&nbsp;</td>'+
							  '<td valign="middle">Time</td>'+
							  '<td align="center" valign="middle">:</td>'+
							  '<td valign="middle">'+time_show+'</td>'+
							  '<td>&nbsp;</td>'+
							'</tr>'+
							'<tr>'+
							  '<td height="25">&nbsp;</td>'+
							  '<td valign="middle">Ticket Price</td>'+
							  '<td align="center" valign="middle">:</td>'+
							  '<td valign="middle">Rp.'+number_format(ticket_price)+'</td>'+
							  '<td>&nbsp;</td>'+
							'</tr>'+
							'<tr>'+
							  '<td height="25">&nbsp;</td>'+
							  '<td valign="middle">Number of Tickets</td>'+
							  '<td align="center" valign="middle">:</td>'+
							  '<td valign="middle">'+number_format(total_bought)+'</td>'+
							  '<td>&nbsp;</td>'+
							'</tr>'+
							'<tr>'+
							  '<td height="25">&nbsp;</td>'+
							  '<td valign="middle">Administration Fee</td>'+
							  '<td align="center" valign="middle">:</td>'+
							  '<td valign="middle">Rp.'+number_format(surcharge)+'</td>'+
							  '<td>&nbsp;</td>'+
							'</tr>'+
							'<tr>'+
							  '<td height="25">&nbsp;</td>'+
							  '<td valign="middle">Total Amount</td>'+
							  '<td align="center" valign="middle">:</td>'+
							  '<td valign="middle">Rp.'+number_format(total_order)+'</td>'+
							  '<td>&nbsp;</td>'+
							'</tr>' +
							'<tr>'+
							'<td width="1%">&nbsp;</td>'+
							'<td colspan="3"><font style="color:#FF0000;">*Tiket yang sudah terbeli tidak dapat ditukar atau dikembalikan.</font></td>'+
							'<td width="1%">&nbsp;</td>'+
						    '</tr>';
	
	set_message += '</table>';
						
	   if (no_error) {
		   parm_confirm[0] = cinema_id;
		   parm_confirm[1] = cinema_name;
		   parm_confirm[2] = movie_id;
		   parm_confirm[3] = movie_title;
		   parm_confirm[4] = date_show;
		   parm_confirm[5] = time_show;
		   parm_confirm[6] = total_bought;
		   parm_confirm[7] = member_to;
	   	   OpenPopupConfirm("PopupBookingHandle", set_message);
	   }
	   else
	       OpenPopupAlert(error_message);
		   
  }catch(err) {}
}
//=============================================================================================================

function PopupBookingHandle(this_confirm) {
try {
	var get_sid = $('#sid').val()
	if(this_confirm) {
		OpenBannerLoading("Please wait...");
		var set_parm = '&sid='+get_sid+'&cinema_id='+trim(parm_confirm[0])+'&cinema_name='+trim(parm_confirm[1])+
					   '&movie_id='+trim(parm_confirm[2])+'&movie_title='+trim(parm_confirm[3])+
					   '&date_show='+trim(parm_confirm[4])+'&time_show='+trim(parm_confirm[5])+
					   '&total_bought='+trim(parm_confirm[6])+'&member_to='+trim(parm_confirm[7])
		$.ajax({
			type: "POST",
			url: "ajax_request.php",
			data: 'ajax_order=validation_booking'+set_parm,
			cache: false,
			async: false,
			success: function(data){
				if(data == 1 )
				 setTimeout("window.location='gui.booking_seat.php?sid="+get_sid+"'", 3000)
				else
				 setTimeout( function(){OpenPopupAlert(data)}, 3000);
			},
			error:function(){
				 OpenPopupAlert("Maaf, sedang terjadi permasalahan dalam sistem kami. Silahkan ulangi beberapa saat lagi.");
			}
		});
	}
	else 
		return false;
}catch(err) {}
}
//=============================================================================================================

function BookingByMovie(movie_id, movie_title) {
	
try{
  var get_sid = $('#sid').val()
  if (movie_id.length > 1 && movie_title.length > 1 ) {
	   OpenBannerLoading("Please wait...");
	  	$.ajax({
			type: "POST",
			url: "ajax_request.php",
			data: 'ajax_order=set_booking_by_movie&sid='+get_sid+'&movie_id='+trim(movie_id)+'&movie_title='+trim(movie_title),
			cache: false,
			async: false,
			success: function(data){
				if(data == 1 )
					setTimeout("window.location='gui.booking_movie.php?sid="+get_sid+"'", 3000)
				else 
					OpenPopupAlert("Maaf, sedang terjadi permasalahan dalam sistem kami. Silahkan ulangi beberapa saat lagi.");
			},
			error:function(){
				 OpenPopupAlert("Maaf, sedang terjadi permasalahan dalam sistem kami. Silahkan ulangi beberapa saat lagi.");
			}
		});
  }
  else {
	 OpenPopupAlert("Silahkan untuk melakukan pemilihan film terlebih dahulu.");
  }
  
}catch(err) {}
}
//=============================================================================================================

function GetDate(cinema_id, movie_id) {
try{
  var get_sid = $('#sid').val()
  $('#movie_id').val(movie_id)
  var get_date_show =$('#date_show_'+movie_id).get(0);
  ClearDateShow(movie_id)

  if (cinema_id.length > 1 && movie_id.length > 1) {
	   $.ajax({
			type: "POST",
			url: "ajax_request.php",
			data: 'ajax_order=get_movie_date&sid='+trim(get_sid)+'&cinema_id='+trim(cinema_id)+'&movie_id='+trim(movie_id),
			cache: false,
			async: false,
			success: function(data){
				ClearDateShow(movie_id)
				if (!(data == '0' || data == '')) {
					var arr_result = data.split(";");
					var value = '';
					var text = '';
					for (i=0; i < arr_result.length; i++) {
						 value = arr_result[i];
						 addOption(get_date_show, trim(value), trim(value));
					}
	   			}
			},
			beforeSend: function(){
     			 get_date_show.remove(0);
          		 addOption(get_date_show, "", "Loading..");
   			},
			error:function(){
				 OpenPopupAlert("Maaf, sedang terjadi permasalahan dalam sistem kami. Silahkan ulangi beberapa saat lagi.");
			}
		});
  }
  else {
	 OpenPopupAlert("Silahkan untuk melakukan pemilihan bioskop terlebih dahulu.");
  	return false;
  }
}catch(err) {}
}

//=============================================================================================================

function ClearDateShow(movie_id) {
  var get_date_show = document.getElementById("date_show_"  + movie_id);
  for(i=get_date_show.options.length-1;i>=0;i--) {
	  get_date_show.remove(i);
  }
  addOption(get_date_show, "", "[ Select Date ]");
}
//=============================================================================================================

function ClearTimeShow(movie_id) {
  var get_time_show = document.getElementById("time_show_"  + movie_id);
  for(i=get_time_show.options.length-1;i>=0;i--) {
	  get_time_show.remove(i);
  }
  addOption(get_time_show, "", "[ Select Time ]");
}
//=============================================================================================================

function MtixMovieNoSchedule() {
 OpenPopupAlert("<b>Perhatian:</b><br>1.&nbsp;Untuk Selasa, Rabu, Kamis dan Jum'at pembelian tiket melalui M-Tix<br>&nbsp;&nbsp;&nbsp; hanya bisa dilakukan untuk jam tayang pada hari yang sama,pembelian ditutup pada pukul 11:00 WIB.<br>2.&nbsp;Untuk jadwal tayang Sabtu, Minggu dan Senin tiket bisa dipesan sejak hari Jum'at.<br>3.&nbsp;Untuk pembelian tiket pada pemutaran film di jam tayang dan hari yang sama, ditutup pada pukul 11:00 WIB.<br>4.&nbsp;Untuk informasi bertransaksi menggunakan M-Tix selengkapnya bisa dilihat di <a href='gui.mtix_faq.php?sid={sid}'>FAQ</a>");
 return false;
}
//=============================================================================================================

