function view_image(file_name){

/**
	$('#car_img').fadeOut(
		function(event){
			$('#car_img img').remove();
			$("#car_img").append('<img src="./car_img/' + file_name + '">');
			$("#car_img").fadeIn();
		}
	);
**/

	$('#car_img').fadeOut(
		function(event){
			$("#car_img").attr("src", "./car_img/" + file_name);
			$("#car_img").load(function () {
				//フェードイン	
				$("#car_img").fadeIn();  
			});
		}
	);
}

function gard_box(mode){

	if(mode == true){
		var nWidth, nHeight;

		if (typeof document.body.style.maxHeight == "undefined") { 
			// IE6, older browsers 
			nWidth = document.body.clientWidth;
			nHeight = document.body.scrollHeight;
		}else{
			// IE 7, mozilla, safari, opera 9 
			//nWidth = document.documentElement.clientWidth;
			nWidth = document.documentElement.clientWidth || document.body.clientWidth || document.body.scrollWidth;
			nHeight = document.body.scrollHeight || document.documentElement.clientHeight || document.body.clientHeight;
		}
		$('#gardBox').css('width',nWidth);
		$('#gardBox').css('height',nHeight);
		$('#gardBox').show();
	}else{
		$('#gardBox').hide();
	}
}

function car_reg_confirm() {
	if(window.confirm('登録しますか？')){
		gard_box(true);
		return true;
	}else{
		return false;
	}
}

function car_delete(){
	if(window.confirm('削除しますか？')){
		gard_box(true);
		location.href = "car_delete.php?seq_no="+$('#seq_no_v').text();
	}
}

function edit_clear(){

	$('#seq_no_v').text('');
	
	return true;
}

function load_car_edit(xml){
	var event = new Object();
	var data = $(xml);
	var entries,entry;
	var i,j;

	event.target = new Object();

	//DATA BASE定義読み込み
	entries = data.children('carInfo');
	for (i = 0, j = entries.length; i < j; i++) {
		entry = $(entries[i]);
		$("#seq_no").val(entry.children('seq_no').text());
		$("#seq_no_v").text(entry.children('seq_no').text());

		$("#car_name").val(decodeURIComponent(entry.children('car_name').text()));
		$("#price").val(entry.children('price').text());
		$("#model_year").val(decodeURIComponent(entry.children('model_year').text()));
		$("#mileage").val(decodeURIComponent(entry.children('mileage').text()));
		$("#mot").val(decodeURIComponent(entry.children('mot').text()));
		$("#mission").val(decodeURIComponent(entry.children('mission').text()));
		$("#color").val(decodeURIComponent(entry.children('color').text()));
		$("#body_type").val(decodeURIComponent(entry.children('body_type').text()));
		if(entry.children('maintenance_type').text() == '1'){
			$('#maintenance_type1').attr('checked', true);
		}else{
			$('#maintenance_type0').attr('checked', true);
		}
		if(entry.children('repair_flag').text() == '1'){
			$('#repair_flag1').attr('checked', true);
		}else{
			$('#repair_flag0').attr('checked', true);
		}
		if(entry.children('security_flag').text() == '1'){
			$('#security_flag1').attr('checked', true);
		}else{
			$('#security_flag0').attr('checked', true);
		}
	}
}


$(function() {

	$('#LOGO').click(
		function(event){
			location.href = "./";
		}
	);

	$('.car_list_detail').click(
	function(event){
//			alert('car_list_detail');
//			alert($(this).attr('seq_no'));
//			location.href = "car_detail.php?car_no="+$(this).attr('seq_no');
		}
	);

	$(".car_list_tr").hover(
		function(){
			$(this).css("background-color", "#FDFDBD");
		},
		function(){
			$(this).css("background-color", "#FFFFFF");
		}
	);

	$(".thumbnail").hover(
		function(){
			$(this).css("background-color", "#FDFDBD");
		},
		function(){
			$(this).css("background-color", "#FFFFFF");
		}
	);

	$('.car_list_detail').click(
		function(event){
//			alert('car_list_detail');
//			alert($(this).attr('seq_no'));
			location.href = "car_detail.php?car_no="+$(this).attr('seq_no');
		}
	);

	$(".car_edit_tr").hover(
		function(){
			$(this).css("background-color", "#FDFDBD");
		},
		function(){
			$(this).css("background-color", "#FFFFFF");
		}
	);

	$('.car_edit_detail').click(
		function(event){
//			alert('car_edit_detail');
//			alert($(this).attr('seq_no'));
			$.ajax({
				url: 'get_car_info.php?seq_no=' + $(this).attr('seq_no'),
				type: 'GET',
				dataType: 'xml',
				cache: false,  
				timeout: 60000, 
				success: load_car_edit
			});
		}
	);

});

