$(function() {

	$('.fa-info-circle').click(function(){
    	var adID = this.id;
    	$('#type').val('image_manager_detail');
    	$('#adID').val(adID);
		submitForm();
	});

	$('#from').datepicker({
		// カレンダーの設定
		dateFormat	: 'yy/mm/dd'
	});

	$('#to').datepicker({
		// カレンダーの設定
		dateFormat	: 'yy/mm/dd'
	});

	if($('#from').val() == '') {
		$('#from:text').datepicker().datepicker('setDate', nowStr);
	}

	if($('#to').val() == '') {
		$('#to:text').datepicker().datepicker('setDate','today');
	}

	$("#btnSearch").click(function() {
		$('#type').val('');
		$('#type_search').val('search');
		submitForm('searchForm');
	});

	$("#btnSearchAds").click(function() {
		$('#type').val('image_manager');
		$('#type_search').val('search');
		submitForm('searchForm');
	});

	$("#btnSave").click(function() {
		$('#type').val('save');
		submitForm();
	});

	$("#btnUpdate").click(function() {
		$('#type').val('update');
		submitForm();
	});

	$("#btnSearchAll").click(function() {
		actionSearchAll();
	});
	
	$("#btnManager").click(function() {
		$('#type').val('image_manager');
		submitForm();
	});

	$("#btnRecords").click(function() {
		$('#type').val('');
		submitForm();
	});

	$("#btnConfirm").click(function() {
		$('#type').val('upload');
		submitForm();
	});

	$("#btnComplete").click(function() {
		$('#type').val('complete');
		submitForm();
	});

	$('#btnList').click(function() {
		$('#type').val('');
		submitForm();
	});

	$('#btnUpload').click(function() {
		$('#type').val('image_manager_upload');
		submitForm();
	});

	$('#btnAdUpload').click(function() {
		$('#type').val('image_upload_complete');
		submitForm();
	});

	$('#btnSequence').click(function(){
		var elements = [];
		$("#sortable tr").each(function(){
		   elements.push(this.id); 
		});

		$.ajax({
	      url:'../api/saveSequence.php',
	      type: 'post',
	      dataType: 'text',
	      data: {
	        sequence: elements,
	        location: $('#slocation').find(':selected').text(),
	        language: $('#slanguage').find(':selected').text(),
	      }
	      ,
	      success: function(data) {
				alert('Sucessfully saved sequence');
		  }
	    });
		


	});
	
	
});

/**
 * 検索を行う
 */
function actionSearch() {
	$('#type_search').val('search');
	submitForm('searchForm');
}

function deleteAd(id) {
	
	var x = confirm("Are you sure you to delete this ad?");
	if(x == true){
		$('#type').val('delete');
		$('#adID').val(id);
		$('#language').val($('#slanguage').find(':selected').text());
		$('#location').val($('#slocation').find(':selected').text());
		submitForm("acForm");
	}
	
}











    	

