/// Site Announcement
/// @20101005 ~ 20101008
/// Insert it as the first child of the HEAD tag
/*
    <script language="JavaScript" type="text/javascript" src="http://domain/popup/migration20101015/siteannouncement.js"></script>
    <script language="JavaScript" type="text/javascript">
	//<!--
	try {
		var x = new shtec.siteannouncement();
		//x.setfromdatetime(new Date(2010, 9, 8)).show(); //2010 Month(9)=Oct 8
		x.setcookiepath('_SITE_IDENTITY_').setsitelabel('_SITE_NAME_ Website Temporary Suspension').show();
	} catch(e) { }
	// -->
    </script>
*/

var shtec = (function() {
    function siteannouncement() {
        this.sitelabel = "Website Temporary Suspension";
        this.fromtime = new Date(2009, 1, 1);
        this.totime = new Date(2030, 11, 31);
        this.cookiePath = "";
    }
    siteannouncement.prototype.setcookiepath = function(path) {
        this.cookiePath = path;
        return this;
    };
    /// fromtime: Date() object
    siteannouncement.prototype.setfromdatetime = function(fromtime) {
        this.fromtime = fromtime;
        return this;
    };
    /// totime: Date() object
    siteannouncement.prototype.settodatetime = function(totime) {
        this.totime = totime;
        return this;
    };
    siteannouncement.prototype.setsitelabel = function(newlabel) {
        this.sitelabel = newlabel;
        return this;
    };
    siteannouncement.prototype.popupMaintenanceNotice = function(width, height, announcementurl) {
        if (window.innerWidth) {
            LeftPosition = (window.innerWidth - width) / 2;
            TopPosition = ((window.innerHeight - height) / 4) - 50;
        } else {
            LeftPosition = (parseInt(window.screen.width) - width) / 2;
            TopPosition = ((parseInt(window.screen.height) - height) / 2) - 50;
        }
        attr = 'resizable=no,scrollbars=yes,width=' + width + ',height=' +
        height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
        TopPosition + '';

        var popWin = open('about:blank', 'mt_wnd', attr);
        //popWin.document.clear();
        popWin.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
        popWin.document.write('<html><head><title>' + this.sitelabel + '</title>');
        popWin.document.write('<style type="text/css">html, body {margin: 0; padding: 0; border: 0; overflow: hidden; font-family: Tahoma, Arial; font-size: 0.88em;}</style>');
        popWin.document.write('</head>');
        popWin.document.write('<body><div align="center">');
        popWin.document.write('<img src="' + announcementurl + '" border="0" alt="" width="' + width + '" height="' + height + '" />');
        popWin.document.write('</div></body></html>');
        return this;
    };
    siteannouncement.prototype.show = function(width, height, url) {
        var currentTime = new Date();

        if (currentTime >= this.fromtime && currentTime <= this.totime) {
            if (this.getCookie("offme") != "1") {
                this.popupMaintenanceNotice(width, height, url);
                this.offme();
            }
        }
        return this;
    };
    siteannouncement.prototype.offme = function() {
        this.setCookie("offme", "1");
        return this;
    };
    siteannouncement.prototype.getCookie = function(c_name) {
	c_name = c_name + this.cookiePath;
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(c_name + "=");
            if (c_start != -1) {
                c_start = c_start + c_name.length + 1;
                c_end = document.cookie.indexOf(";", c_start);
                if (c_end == -1) c_end = document.cookie.length;
                return unescape(document.cookie.substring(c_start, c_end));
            }
        }
        return "";
    };
    siteannouncement.prototype.setCookie = function(c_name, value) { //, expiredays) {
        //var exdate = new Date();
        //exdate.setDate(exdate.getDate() + expiredays);
        document.cookie = c_name + this.cookiePath + "=" + escape(value) + ";";   //path=/" + WHERE + ";";
        // + ((expiredays == null) ? "" : ";path=/av;expires=" + exdate.toUTCString());
    };
    return { siteannouncement: siteannouncement };
})();

