var flash_loaded = false;
var accessmapwin = null;

function attachImageViewer(){
	var flashvars = {};
	flashvars.c = $("#_c").val();
	
	var params = {};
	params.menu = "false";
	params.wmode = "transparent";
	params.bgcolor = "#FFFFFF";
	params.scaleMode = "noScale";
	params.allowScriptAccess = "always";
	
	var attributes = {};
	attributes.id = "externalImageViewer";
	attributes.name = "externalImageViewer";
	
	var expressinstall = "";
	//swfobject.embedSWF('http://' + document.URL.split("/")[2] + '/search/ImageViewer.swf?' + Number(new Date()), 'flash_image_viewer', '610', '415', '8.0.0', expressinstall, flashvars, params, attributes);
	swfobject.embedSWF('/search/ImageViewer.swf?' + Number(new Date()), 'flash_image_viewer', '610', '415', '8.0.0', expressinstall, flashvars, params, attributes);
}

function init_img(){
	//$("img[id^='companyimg']").show();
	$.each($("img[id^='companyimg']"),function(key,value){
		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 addFavarite(){
	var id = $("#_o").val();
	if( id != "" ){
		$.cookie('o_'+id,1,{expires: 1825,path: '/'});
		$("#addFavarite1").hide();
		$("#addFavarite2").hide();
		$("#addedFavarite1").show();
		$("#addedFavarite2").show();
	
		alert("この求人を気になる求人一覧へ追加しました。");
	}
}

$(function(){
	//$(":text").css("padding","2px");
	
	//$("#lat_data").val("");
	//$("#lng_data").val("");
	//$("#level_data").val("");
	
	attachImageViewer();
	
	if( $.cookie('o_'+ $("#_o").val()) == null ){
		$("#addFavarite1").show();
		$("#addFavarite2").show();
	}else{
		$("#addedFavarite1").show();
		$("#addedFavarite2").show();
	}
});


function inquiry(){
	tb_show('この企業へ問い合わせる','https://' + document.URL.split("/")[2] + '/search/inquiry.php?c=' + $("#_c").val() + '&TB_iframe=true&width=627&height=300',false);
}
function entry(){
	tb_show('この求人に応募する','https://' + document.URL.split("/")[2] + '/search/entry.php?c=' + $("#_c").val() + '&o=' + $("#_o").val() + '&TB_iframe=true&width=627&height=325',false);
}

function nologin_entry(){
	//if( confirm("求人への応募には、ログインが必要です。\n会員登録がまだの方は会員登録してください。\n会員登録ページへ移動しますか？") ){
	//	location.href = "/regist/";
	//}
	tb_show('この求人に応募する','https://' + document.URL.split("/")[2] + '/search/entry_nologin.php?c=' + $("#_c").val() + '&o=' + $("#_o").val() + '&TB_iframe=true&width=627&height=550',false);
}

function onThickboxLoaded(_title){
	$("#TB_title").empty();
	
	var html = "";
	
	//627 + 29 
	//style=\"background-image:url('/images/search/ttl_inquiry.gif');\"
	//var html = "<table border=\"1\" width=\"656\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><img src=\"/images/search/ttl_inquiry.gif\" width=\"656\" height=\"29\" />";
	//html += "<a href=\"#\" id=\"TB_closeWindowButton\" title=\"Close\"><img  src=\"/images/mypage/btn_close_off.gif\" onmouseover=\"this.src='/images/mypage/btn_close_on.gif'\" onmouseout=\"this.src='/images/mypage/btn_close_off.gif'\" alt=\"閉じる\" width=\"84\" height=\"22\" /></a></td></tr></table>";
	//html += "<div id=\"TB_closeAjaxWindow\"><a href=\"#\" id=\"TB_closeWindowButton\" title=\"Close\"><img style=\"margin:0px;padding:0px;\" src=\"/images/mypage/btn_close_off.gif\" onmouseover=\"this.src='/images/mypage/btn_close_on.gif'\" onmouseout=\"this.src='/images/mypage/btn_close_off.gif'\" alt=\"閉じる\" width=\"84\" height=\"22\" /></a></div></td></tr></table>";

	switch(_title){
		case "この企業へ問い合わせる":
			html = "<table border=\"0\" width=\"656\" height=\"29\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"right\" valign=\"top\" style=\"background-image:url('/images/search/ttl_inquiry.gif');\">";
			html += "<font style=\"font-size:1pt\"><br/></font><a href=\"#\" id=\"TB_closeWindowButton\" title=\"Close\"><img src=\"/images/mypage/btn_close_off.gif\" onmouseover=\"this.src='/images/mypage/btn_close_on.gif'\" onmouseout=\"this.src='/images/mypage/btn_close_off.gif'\" alt=\"閉じる\" width=\"84\" height=\"22\" /></a>&nbsp;</td></tr></table>";
			break;
		case "この求人に応募する":
			html = "<table border=\"0\" width=\"656\" height=\"29\" cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"right\" valign=\"top\" style=\"background-image:url('/images/search/ttl_entry.gif');\">";
			html += "<font style=\"font-size:1pt\"><br/></font><a href=\"#\" id=\"TB_closeWindowButton\" title=\"Close\"><img src=\"/images/mypage/btn_close_off.gif\" onmouseover=\"this.src='/images/mypage/btn_close_on.gif'\" onmouseout=\"this.src='/images/mypage/btn_close_off.gif'\" alt=\"閉じる\" width=\"84\" height=\"22\" /></a>&nbsp;</td></tr></table>";
			break;
	}


	
	$("#TB_title").append(html);
	
	$("#TB_closeWindowButton").click(tb_remove);
}

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

function nologin_inquiry(){
	if( confirm("企業への問い合わせには、ログインが必要です。\n会員登録がまだの方は会員登録してください。\n会員登録ページへ移動しますか？") ){
		location.href = "/regist/";
	}
}

function open_accessmap(id){
	var accessmapwin;
	switch(id){
		case 1:
			accessmapwin = window.open("/search/accessmap.php?c=" + $("#_c").val() + "&o=" + $("#_o").val(),"accessmapwin","width=650,height=450");
			break;
		case 2:
			accessmapwin = window.open("/search/accessmap.php?c=" + $("#_c").val(),"accessmapwin","width=650,height=450");
			break;
	}
	
}

