﻿$(document).ready(function(){
	
	$(document).pngFix();
	
	$(".main-contents h3:first-child").css("margin-top","5px");
	
	$("#login-layer-close").click(function(){
		disablePopup();
	});
	
	$(".layer-popup-background").click(function(){
		disablePopup();
	});
	
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

    $("input[type=text]").addClass("text-input");
    $("input[type=text]").focus( function() {
        $(this).addClass("text-input-active");
    });
    $("input[type=text]").blur( function() {
        $(this).removeClass("text-input-active");
    });
    
    $("table.table-normal th:first-child").css("background-image","url('/Static/Images/Common/bg_table_header_cap.gif')");
    $("table.table-normal th:first-child").css("background-position","left top no-repeat");
    $("div.number-box span:last-child a").css("border-right","none");
    
    $("#page-map li:last-child").addClass("last");
    $("dd:last-child").css("border-bottom","none");
    
    $("form").after("<div class=\"layer-popup-background\"></div>");
});


var popupStatus = 0;
var layerBackground = null;

function loadPopup(){
	if(popupStatus==0){
		$(".layer-popup-background").css({
			"opacity": "0.7"
		});
		$(".layer-popup-background").fadeIn("fast");
		$("#login-layer").fadeIn("fast");
		popupStatus = 1;
		
		$("#txt_id").focus();
	}
}

function disablePopup(){
	if(popupStatus==1){
		$("#login-layer").fadeOut("fast");
		$(".layer-popup-background").fadeOut("fast");
		popupStatus = 0;
	}
}

function focusID(){
    $("#id").focus();
}

function centerPopup(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#login-layer").height();
	var popupWidth = $("#login-layer").width();

	$("#login-layer").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
	$(".layer-popup-background").css({
		"height": windowHeight
	});
	
	$("#id").focus();
}

// 공용 layer 함수
var popupStatus2 = 0;

function loadLayerPopup( classNameArg )
{
    pubCenterPopup( classNameArg );
    pubLoadPopup( classNameArg );
}

function loadLayerDownPopup(classNameArg, scrollY) {
    pubDownPopup(classNameArg, scrollY);
    pubLoadPopup(classNameArg);
}

function pubLoadPopup( classNameArg ){
	if(popupStatus2==0){
		$(".layer-popup-background").css({
			"opacity": "0.7"
		});
		$(".layer-popup-background").fadeIn("fast");
		$("."+classNameArg).fadeIn("fast");
		popupStatus2 = 1;
	}
}

function pubDisablePopup( classNameArg ){
	if(popupStatus2==1){
		$("."+classNameArg).fadeOut("fast");
		$(".layer-popup-background").fadeOut("fast");
		popupStatus2 = 0;
	}
}

function pubDisablePopupWithR(url) {
    location.href = url;
}

function pubCenterPopup( classNameArg ){

    var realHeight = $("form").height();
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("."+classNameArg).height();
	var popupWidth = $("."+classNameArg).width();
    
    if( popupHeight > windowHeight - 20 )
    {
        $("."+classNameArg).css({
		    "position": "absolute",
		    "top": 20,
		    "left": windowWidth/2-popupWidth/2
	    });
    }
    else
    {
	    $("."+classNameArg).css({
		    "position": "absolute",
		    "top": windowHeight/2-popupHeight/2,
		    "left": windowWidth/2-popupWidth/2
	    });
	}
	
	$(".layer-popup-background").css({
		"height": realHeight
	});
}

function pubDownPopup(classNameArg, scrollY) {

    var realHeight = $("form").height();
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("." + classNameArg).height();
    var popupWidth = $("." + classNameArg).width();

    if (popupHeight > windowHeight - 20) {
        $("." + classNameArg).css({
            "position": "absolute",
            "top": scrollY,
            "left": windowWidth / 2 - popupWidth / 2
        });
    }
    else {
        $("." + classNameArg).css({
            "position": "absolute",
            "top": scrollY,
            "left": windowWidth / 2 - popupWidth / 2
        });
    }

    $(".layer-popup-background").css({
        "height": realHeight
    });
}

// 비 활성화 시 높이 58px ,활성화 168 
var SIZE_OVER = "168px";
var SIZE_OUT  = "58px";

function gnbResize( toSize )
{
	if( toSize == "over" )
	{
        $("#GNB-wrapper p").css("height", SIZE_OVER);
	}
	else
	{
	    $("#GNB-wrapper p").css("height", SIZE_OUT);
	}
}

function quickResize( toSize )
{
	var SIZE_WIDE       = "190px";
	var SIZE_NARROW     = "52px";

	if( toSize == "over" )
	{
        $("#quick-menu").css("width", SIZE_WIDE);
        $("#quick-menu object").css("margin-left", "0");
	}
	else
	{
	    $("#quick-menu").css("width", SIZE_NARROW);
	    $("#quick-menu object").css("margin-left", "-138px");
	}
}

function logger( msg )
{
    alert( "msg: " + msg );
}


// Chart Tab
$( function() {
    $("#graph li img").click(function()
    {
        var chartType = $(this).attr("alt");
        
        if( chartType == "혈압" )
        {
            $("#chart-hd").css("display","none");
            $("#chart-hp").css("display","block");
            $("#chart-fat").css("display","none");
        }
        else if( chartType == "혈당" )
        {
            $("#chart-hd").css("display","block");
            $("#chart-hp").css("display","none");
            $("#chart-fat").css("display","none");
        }
        else
        {
            $("#chart-hd").css("display","none");
            $("#chart-hp").css("display","none");
            $("#chart-fat").css("display","block");
        }
        
        $("#graph li img").css("margin-top","-19px");
        $(this).css("margin-top","0");
    });
    /*
    $("#chart-table li img").click(function()
    {
        var chartType = $(this).attr("alt");
        
        if( chartType == "혈압" )
        {
            $("#table-hd").css("display","none");
            $("#table-hp").fadeIn();
            $("#table-fat").css("display","none");
        }
        else if( chartType == "혈당" )
        {
            $("#table-hd").fadeIn();
            $("#table-hp").css("display","none");
            $("#table-fat").css("display","none");
        }
        else
        {
             $("#table-hd").css("display","none");
            $("#table-hp").css("display","none");
            $("#table-fat").fadeIn();
        }
        
        $("#chart-table li img").css("margin-top","-19px");
        $(this).css("margin-top","0");
    });*/
})
