function clickTab(sName,id){
    var frm = document.frm;
    var action = ""
    var isPop = false;
	var divname = "";

    switch(sName){
        case "area":
            action = "/search/line/arealist.php?area_id="+id;
            isPop = true;
			divname = "#dialog1";
            break;
        case "line":
            action = "/search/line/linelist.php?area_id="+id;
            isPop = true;
			divname = "#dialog2";
            break;
        case "keyword_top":
            var parentHeight = $("body").attr('scrollHeight');
            var parentWidth  = $("body").attr('scrollWidth');
            $(".ui-widget-overlay").css("height", parentHeight+"px");
            $(".ui-widget-overlay").css("width", parentWidth+"px");
            frm.action = "/search/stock/stock_list.php?mode=search_top&area_id="+id;
            frm.target="_self";
            frm.submit();
            $("#loading").show();
            return;
            break; 
        default:
            break;
    }

    $.ajax({
        url: action,
        global: false,
        type: "POST",
        data: $("form").serialize(),
        dataType: "html",
        beforeSend:function(){
            var parentHeight = $("body").attr('scrollHeight');
            var parentWidth  = $("body").attr('scrollWidth');
            $(".ui-widget-overlay").css("height", parentHeight+"px");
            $(".ui-widget-overlay").css("width", parentWidth+"px");
            $("#loading").show();
        },
        success: function(msg){
            $("#loading").hide();
			if ( isPop == true ) {
                $(divname).empty();
                $(divname).html(msg);
                $(divname).dialog('open');
                $(divname).removeClass('ui-dialog-content');
				$(divname).removeClass('ui-widget-content');
				var popHeight= $(divname).attr('scrollHeight');
                var parentHeight = $("body").attr('scrollHeight');
				if(popHeight > parentHeight){
                    $(".ui-widget-overlay").css("height", popHeight+"px");
				}else{
                    $(".ui-widget-overlay").css("height", parentHeight+"px");
				}
            }else{
                $("#search_list").empty();
                $("#search_list").html(msg);
	            setParam();
            }
        }
    });
}


function setParam () {
	// title切り替え
    if (typeof($("#hid_title").attr("value")) != "undefined") {
	    document.title = $("#hid_title").attr("value");
    }

	// h1切り替え
	var h1_obj = document.getElementsByTagName("h1")[0]; 
    if (typeof($("#hid_h1").attr("value")) != "undefined") {
        h1_obj.innerHTML = $("#hid_h1").attr("value");
    }

	// h2切り替え
	var h2_obj = document.getElementById("search_title_comment"); 
    if (typeof($("#hid_h2").attr("value")) != "undefined") {
        h2_obj.innerHTML = $("#hid_h2").attr("value");
    }

	// pankuzu切り替え
	var pangkuzu_obj = document.getElementById("pangkuzu"); 
	var header_area_name_obj = document.getElementById("header_area_name"); 
    if (typeof($("#hid_pangkuzu").attr("value")) != "undefined") {
        pangkuzu_obj.innerHTML = $("#hid_pangkuzu").attr("value");
        header_area_name_obj.innerHTML = $("#hid_pangkuzu").attr("value");
    }

	//var metas = document.getElementsByTagName("meta"); 

	// keywords切り替え
	//document.getElementsByTagName("meta")[1].content = $("#hid_keywords").attr("value");
	// description切り替え
	//document.getElementsByTagName("meta")[2].content = $("#hid_description").attr("value");
}

function beforeClick(sName,val) {
    var objName = "";
    var isFinish = false;

    switch(sName){
        case "station_id_select":
            objName = "input[id='"+val+"']";
            $(objName).each(function() {
                     if($(this).attr("checked")==false){
                       $(this).attr("checked",true);
                     }
                     isFinish = true;
            });
            break;
        default:
            objName = "#"+val;
            break;
    }
    if (isFinish != true) {
        $(objName).attr('checked',!$(objName).attr('checked'));
    }
}

function ftnOnkeydown_Enter_Keyword_Top(str_id,str_param1,str_param2){
    var obj_ins = document.getElementById(str_id);
    if( obj_ins == null || obj_ins == "undefined"){
            return false;
    }
    else{
       if( obj_ins.value == ""){
           return false;
       }
       else{
           clickTab(str_param1,str_param2);
           return true;
       }
       return false;
    }
    return false;
}

