/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(function(){
    formSetCSS();
    state_hover();
    menu_hover();
    showMenuItems('1');
    //goURL('common/a.html');
    //解決 IE6 z-index 浮動區塊問題
    $('#div_Detail > .overlay').bgiframe();
    $('#div_Detail_2 > .overlay').bgiframe();
    $('#div_Alert > .overlay').bgiframe();

});

function formSetCSS(){
    $('input[type="text"]').addClass("input_text");
}
//state
function state_hover(){
    $(".state-default").hover(
        function(){
            $(this).addClass("state-hover");
        },
        function(){
            $(this).removeClass("state-hover");
        }
        )
}

//menu
function menu_hover(){
    $(".menu-titles").hover(
        function(){
            $(this).addClass("menu-titles-hover");
        },
        function(){
            $(this).removeClass("menu-titles-hover");
        }
        )
    //
    $(".menu-items").hover(
        function(){
            $(this).addClass("menu-items-hover");
        },
        function(){
            $(this).removeClass("menu-items-hover");
        }
        )
}
//
//打開主要畫面之函式
function goURL(argURL){
    $.ajax({
        url: argURL,
        cache:false,
        error: function(msq){
            //$("#div_content").html('<div class="message">連結失敗!</div>');

            goAlert("結果","連結失敗.");
        },
        success: function(msg){

            $("#div_content").empty().html(msg);
        }
    });
}
function inc(argTarget,argPath){
	$.ajax({
		url: argPath,
                cache:false,
		error: function(msq){
                    alert("error");
			$(argTarget).html("抱歉，主頁("+argPath+")不存在！");
		},
		success: function(msg){
			$(argTarget).empty().html(msg);
		}
	});
}

function goMain(argURL,argFormId,argData){
    var data;
    if(argFormId==''){
        data = argData;
    }
    else{
        data = $(argFormId).serialize()+argData;
    }

    $.ajax({
        type: "POST",
        url: argURL,
        data: data,
        cache:false,
        error: function(msq){
            //goAlert("結果","連結失敗.");
            goAlert("結果",XMLHttpRequest.responseText);
        },
        success: function(msg){

            $("#div_content").empty().html(msg);
        }
    });
}

//打開Detail畫面之函式
function goDetail(argURL,argTitle,argData){
    $("#div_Detail .content > .header > .title").html(argTitle);
    $.ajax({
        type: "POST",
        url: argURL,
        data: argData,
        cache:false,
        error: function(XMLHttpRequest, textStatus, errorThrown){
            //$("#div_Detail .content > .contain").html('<div class="message">連結失敗!</div>');
            goAlert("結果",XMLHttpRequest.responseText);
        },
        success: function(msg){
            $("#div_Detail").show();
            UI_Resize();
            $(window).scrollTop(0);
            $("#div_Detail .content").empty().html(msg);
        }
    });
}
//關閉Detail畫面之函式
function closeDetail(){
    $("#div_Detail").hide();
    UI_Resize();
}

//

//關閉Alert畫面之函式
function closeAlert(){
    $("#div_Alert").hide();
    UI_Resize();
}
//UI_Resize
function UI_Resize(){
    $("#div_Detail > .overlay").css("width",$(window).width());
    $("#div_Detail > .overlay").css("height",$(window).height());
    $("#div_Detail_2 > .overlay").css("width",$(window).width());
    $("#div_Detail_2 > .overlay").css("height",$(window).height());
    //
    $("#div_Alert > .overlay").css("width",$(window).width());
    $("#div_Alert > .overlay").css("height",$(window).height());
}
$(window).resize(function(){
    UI_Resize();
});
//UI_Scroll
function UI_Scroll(){
    $("#div_Detail > .overlay").css("top",$(window).scrollTop());
    $("#div_Detail > .overlay").css("left",$(window).scrollLeft());
    $("#div_Detail_2 > .overlay").css("top",$(window).scrollTop());
    $("#div_Detail_2 > .overlay").css("left",$(window).scrollLeft());
    //
    $("#div_Alert > .overlay").css("top",$(window).scrollTop());
    $("#div_Alert > .overlay").css("left",$(window).scrollLeft());
}
$(window).scroll(function(){
    UI_Scroll();
});
//Menu函式
function showMenuItems(argTarget){
    /*
		var arr = new Array();
		arr[arr.length] = "1";
		arr[arr.length] = "2";
		arr[arr.length] = "3";
		arr[arr.length] = "4";
		arr[arr.length] = "5";
		//
		for(var i=0;i < arr.length ; i++){
			if(argTarget == arr[i]){
				$("#menu_items_"+arr[i]).show();
				$("#menu-titles_"+arr[i]+" span").addClass("menu-icon-site");
			}else{
				$("#menu_items_"+arr[i]).hide();
				$("#menu-titles_"+arr[i]+" span").removeClass("menu-icon-site");
			}
		}
		*/

    var t = $("#menu_items_"+argTarget);
    var t2 = $("#menu-titles_"+argTarget+" span");
    if(t.css("display") == "none"){
        t.show();
        t2.addClass("menu-icon-site");
    }else{
        t.hide();
        t2.removeClass("menu-icon-site");
    }

}


//檢查數字
function validateNunber(theVar){
    var regExpression = /^[0-9]*$/;
    return regExpression.test(theVar);
}




