﻿//jQuerified clock

var clockId = "#clock";
var format = "HH:mm | dd MMMM yyyy";

$(function(){setInterval("clock();", 500);});

function GetMonth(nMonth) { var aMonth = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); return aMonth[nMonth]; }
function GetDayName(nDay) { var aDay = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); return aDay[nDay]; }
function clock() {
	var clockDiv = $(clockId);
	if(clockDiv.length == 0)
	{
		alert("page needs '" + clockId + "' element");
		return;
	}

	clockDiv = clockDiv[0];
	var oDate = new Date();

	var ret = format.replace("HH", (oDate.getHours() < 10 ? "0" : "") + oDate.getHours());
	ret = ret.replace("mm", (oDate.getMinutes() < 10 ? "0" : "") + oDate.getMinutes());
	ret = ret.replace("dddd", GetDayName(oDate.getDay()));
	ret = ret.replace("dd", (oDate.getDate() < 10 ? "0" : "") + oDate.getDate());
	ret = ret.replace("MMMM", GetMonth(oDate.getMonth()));
	ret = ret.replace("MM", ((oDate.getMonth() + 1) < 10 ? "0" : "") + (oDate.getMonth() + 1));
	ret = ret.replace("yyyy", oDate.getFullYear());
	ret = ret.replace("yy", oDate.getFullYear().toString().slice(2));

	clockDiv.innerHTML = ret;
	clockDiv.title = ret;
}
//jquery read and write cookies
//set is .... $.cookie("logoLeft", val, {path:"/"});
//read is ... $.cookie("logoLeft");
//delete is . $.cookie("logoLeft", null);
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
