var flash_loaded = false;
var page = "";

function init_img(){
	//$("img[id^='companyimg']").show();
	$.each($("img[id^='companyimg']"),function(key,value){
		img_resize(this);
		/*
		var w = $("#" + value.id).width();
		var h = $("#" + value.id).height();
		$("#" + value.id).attr("alt",w + "_" + h);
		h = Math.ceil(h * (282/w));
		w = 282;
		
		if( w >= h ){
			h = Math.ceil(h * (282/w));
			w = 282;
		}else{
			w = Math.ceil(w * (212/h));
			h = 212;
		}
		
		$("#" + value.id).width(w);
		$("#" + value.id).height(h);
		$("#" + value.id).show();
		*/
		//optval += '<option value="' + value['id'] + '">' + value['pref'] + "</option>";
	});
}

function img_resize(imgobj){
	var w = $(imgobj).width();
	var h = $(imgobj).height();
	var cnt = parseInt($(imgobj).attr("name"));
	cnt++;
	$(imgobj).attr("name",cnt);
	
	if( (w <= 30 || h <= 30 ) && cnt <= 10 ){
		setTimeout(img_resize,500,[imgobj]);
	}else{
		if( w <= 30 || h <= 30 ){
			h = 212;
			w = 282;
		}else{
			h = Math.ceil(h * (282/w));
			w = 282;
		}
		$(imgobj).width(w);
		$(imgobj).height(h);
		$(imgobj).show();
	}
	
}

function removeFavarite(id){
	if( confirm("この求人情報を気になる求人一覧から削除します。\nよろしいですか？") ){
		//alert(id + " - " + $.cookie('o_'+id));
		$.cookie('o_'+id,null,{path: '/'});
		location.reload();
	}
}

function removeFavariteHw(id){
	if( confirm("この求人情報を気になる求人一覧から削除します。\nよろしいですか？") ){
		//alert(id + " - " + $.cookie('o_'+id));
		$.cookie('n_'+id,null,{path: '/'});
		location.reload();
	}
}

$(function(){
	//$(":text").css("padding","2px");
	
	//$("#lat_data").val("");
	//$("#lng_data").val("");
	//$("#level_data").val("");
	
	page = $("#p").val();
	
	//setTimeout(init_img,500);

	$.each($("div[id^='id_']"),function(key,value){
		var id = parseInt(value.id.toString().split("_")[1]);
		
		if( $.cookie('o_'+id) == null )
			$("#addFavarite" + id).show();
		else
			$("#addedFavarite" + id).show();
	});
});

function p_submit(){
	document.forms[1].method = "POST";
	document.forms[1].action = "./";
	document.forms[1].submit();
}

function prev_page(){
	page--;
	if( page < 1 )
		page = 1;
		
	$("#p").val(page);
	p_submit();
}
function next_page(){
	page++;
	if( page > $("#lp").val() )
		page = $("#lp").val();
		
	$("#p").val(page);
	p_submit();
}
function top_page(){
	$("#p").val(1);
	p_submit();
}
function last_page(){
	$("#p").val($("#lp").val());
	p_submit();
}
function change_page(id){
	$("#p").val($("#pagelist" + id).val());
	p_submit();
}


function view_detail(c,o){
	location.href = "/search/detail.php?c=" + c + "&o=" + o;
}
