//------------------------------------------------------------------------------
// Common
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// ZoomImage
//------------------------------------------------------------------------------
/*******************************************************************************
    関数名      ZoomImage
    機能        画像をクリックすると、別ウィンドウに画像を表示する。
    
    入力        sImg        画像ファイル名
                sImgClass   画像に設定するクラス名
*******************************************************************************/
function ZoomImage(sImg, sImgClass){
    aHtmlLines = new Array();
    var iCnt=0;
    var iTmpCnt=0;
    var sNavigator = GetNavigatorName();
    wImg = window.open('', '_blank');
    
    if(sNavigator == "Safari"){
        
        // ウィンドウサイズを取得する
        iWindowHeight = wImg.innerHeight;
        
    } else {
        // ウィンドウサイズを100%とする
        iWindowHeight = "100%";
    }

aHtmlLines[0] = "<html><head><title>ZOOM IN</title>";
aHtmlLines[1] = "<meta http-equiv='Content-Type' content='text/html;charset=Shift_JIS'>";
aHtmlLines[2] = "<link rel='stylesheet' href='../1tools/color_zoom.css' type='text/css'>";
aHtmlLines[3] = "</head><body scroll='auto' topmargin='0' leftmargin='0' marginheight='0' marginwidth='0'>";
aHtmlLines[4] = "<table border='0' cellpadding='0' cellspacing='0' width='100%' height='" + iWindowHeight + "'>";
aHtmlLines[5] = "<tr><td align='center' valign='center' width='100%' height='" + iWindowHeight + "'>";
aHtmlLines[6] = "<table border='0' cellpadding=0 cellspacing=0><tr>";
aHtmlLines[7] = "<td align='center' nowrap><a href='javascript:window.close()' title='ウィンドウを閉じる'><img src='" + sImg + "' class='" + sImgClass + "' border=0></a></td>";
aHtmlLines[8] = "</tr></table></td></tr></table></body></html>";
    
    wImg.document.open();
    for(iCnt=0; iCnt < 9; iCnt++){
        wImg.document.write(aHtmlLines[iCnt]);
    }
    wImg.document.close();
}


function GetNavigatorName(){
    if(navigator.IBM_HPR) return "HomepageReader";
    
    aName  = navigator.userAgent.toUpperCase();
    if (aName.indexOf("SAFARI") >= 0) return "Safari";
    if (aName.indexOf("CHIMERA") >= 0) return "Camino";
    
    aName = navigator.appName.toUpperCase();
    if (aName.indexOf("NETSCAPE") >= 0)  return "Netscape";
    if (aName.indexOf("MICROSOFT") >= 0) return "Explorer";
    return "";
}

//------------------------------------------------------------------------------
// Cookie(do common)
//------------------------------------------------------------------------------
var Cookie = {
    set : function(p_name, p_value, p_expires, p_path, p_domain, p_secure){
        var v_text = '';
        var v_text = p_name + '=' + escape(p_value);
        if (p_expires) {
            v_text = v_text + '; expires=' + p_expires.toGMTString(); 
        }
        if (p_path) { 
            v_text = v_text + '; path=' + p_path; 
        }
        if (p_domain) { 
            v_text = v_text + '; domain=' + p_domain; 
        }
        if (p_secure) { 
            v_text = v_text + ';' + p_secure; 
        }
        document.cookie = v_text;
    },
    
    get : function(p_name) {
        if (document.cookie) {
            index = document.cookie.indexOf(p_name, 0);
            if (index != -1) {
                var val_start = (document.cookie.indexOf('=', index) + 1);
                var val_end = document.cookie.indexOf(';', index);
                if (val_end == -1) { 
                    val_end = document.cookie.length; 
                }
                return(unescape(document.cookie.substring(val_start, val_end)));
            }
        }
        return(null);
    },

    save : function(sId, value, rimit) {
        var p_expires = new Date();
        if (value == '' ) { 
            value = 'null';
        }
        p_expires.setTime(p_expires.getTime() + (rimit * 30 * 24 * 60 * 60 * 1000));
        var p_path = '/';
        var p_domain = null;
        var p_secure = false;
        this.set(sId, value, p_expires, p_path, p_domain, p_secure);
    }
}

function CreateCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else { 
        expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/; domain=;";
}

function ReadCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') {
            c = c.substring(1,c.length);
        }
        if (c.indexOf(nameEQ) == 0) {
            return c.substring(nameEQ.length,c.length);
        }
    }
    return null;
}

//------------------------------------------------------------------------------
// setActiveStyleSheet
//------------------------------------------------------------------------------
function setActiveStyleSheet(title, reset) {
    var i, a, main;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
            a.disabled = true;
            if(a.getAttribute("title") == title) a.disabled = false;
        }
    }

    if (reset == 1) {
        CreateCookie("petit", title, 365);
    }
}

//------------------------------------------------------------------------------
// setStyle
//------------------------------------------------------------------------------
function setStyle(){
    var style = ReadCookie("petit");
    if (style != null) {
        setActiveStyleSheet(style, 0);
    }
}

//------------------------------------------------------------------------------
// Onload
//------------------------------------------------------------------------------
$(document).ready(function () {
    // font系CSSセット
    setStyle(); 
    SetShonanFrameTimer(gsCornerColor);
});
