
// ÊËÀÑÑ Table
			
function Table(tobj) { this.object = tobj; }

Table.prototype.Cell = function(i,j) {
	return this.object.rows[i].cells[j];
}
	
Table.prototype.SetText = function(i,j,text) {
	var cell = this.Cell(i,j);
	if(cell.hasChildNodes()) cell.removeChild(cell.firstChild);
	cell.appendChild(document.createTextNode(text));
}
	
Table.prototype.SetHref = function(i,j,text, href) {
	var cell = this.Cell(i,j);
	if(cell.hasChildNodes()) cell.removeChild(cell.firstChild);
	var a = document.createElement("A");
	a.appendChild(document.createTextNode(text));
	a.href = href;
	cell.appendChild(a);
}

// ÊËÀÑÑ Calendar

function Calendar(tableId, href, cy, cm, cd)
{
    if(cy) {
	    var D = new Date(cy,cm-1,cd);
    } else {
        var D = new Date();
    }
	this.Table = new Table(document.getElementById(tableId));
	this.Year = D.getFullYear();
	if(this.Year<1900) this.Year += 1900;
	this.Month = D.getMonth();
	this.Day = D.getDate();
    
	this.CurrentYear = this.Year;
	this.CurrentMonth = this.Month;
	this.CurrentDay = this.Day;

    this.Href = href;
	this.Months = new Array(
		"ßíâàðü","Ôåâðàëü","Ìàðò","Àïðåëü","Ìàé","Èþíü","Èþëü",
		"Àâãóñò","Ñåíòÿáðü","Îêòÿáðü","Íîÿáðü","Äåêàáðü");
	this.Redraw();
}

Calendar.prototype.Redraw = function() {
	for(j=0;j<7;j++) { this.Table.SetText(1,j,""); this.Table.Cell(1,j).id=''; }
	for(j=0;j<7;j++) { this.Table.SetText(5,j,""); this.Table.Cell(5,j).id=''; }
	for(j=0;j<7;j++) { this.Table.SetText(6,j,""); this.Table.Cell(6,j).id=''; }

	var D = new Date(this.Year, this.Month, 1, 12, 0, 0);
	this.Table.SetText(0,1, this.Months[this.Month]+", "+this.Year+"ã.");
	var wdStart = D.getDay();
	if(--wdStart<0) wdStart = 6;
	var ts = 12 * this.Year + this.Month + 1;
	var m1 = ts % 12; var y1 = (ts - m1) / 12;
	var wdEnd = new Date(y1, m1, 1, 12, 0, 0).getDay();
	if(--wdEnd<0) wdEnd = 6;
	if(--wdEnd<0) wdEnd = 6;

	var week = 0; var wd;
	
	var Today = new Date;
	Today = {
				"day" 	: Today.getDate(),
				"month"	: Today.getMonth(),
				"year"	: Today.getFullYear()
			};
	if(Today["year"]<1900) Today["year"] += 1900;
	
	for(var d=1;d<28;d++) {
		wd = (d+wdStart-1)%7;
		var h = this.Href;
		h = h.replace(/%D%/,d);
		h = h.replace(/%M%/,this.Month+1);
		h = h.replace(/%Y%/,this.Year);
//        alert(Today["day"]+' '+Today["month"]+' '+Today["year"]+' >= '+d+' '+this.Month+' '+this.Year+' = '+((Today["year"]+''+Today["month"]+''+Today["day"]>=this.Year+''+this.Month+''+this.day)))
//         alert((Today["year"]*360+Today["month"]*30+Today["day"])+' >= '+(this.Year*360+this.Month*30+d)+' = '+((Today["year"]*360+Today["month"]*30+Today["day"]>=this.Year*360+this.Month*30+d)))
        if(Today["year"]*360+Today["month"]*30+Today["day"]>=this.Year*360+this.Month*30+d)
            this.Table.SetHref(week+1,wd,d,h);  
        else
            this.Table.SetText(week+1,wd,d);
		this.Table.Cell(week+1,wd).id='';
		if((this.CurrentDay==d)&&(this.CurrentMonth==this.Month)&&(this.CurrentYear==this.Year))
			this.Table.Cell(week+1,wd).id='current';
		if((Today["day"]==d)&&(Today["month"]==this.Month)&&(Today["year"]==this.Year))
			this.Table.Cell(week+1,wd).id='today';
		if(wd==6) week++;
	}
	for(var d=28;d<=31;d++) {
		wd = (d+wdStart-1)%7;
		var h = this.Href;
		h = h.replace(/%D%/,d);
		h = h.replace(/%M%/,this.Month+1);
		h = h.replace(/%Y%/,this.Year);
        if(Today["year"]*360+Today["month"]*30+Today["day"]>=this.Year*360+this.Month*30+d)
            this.Table.SetHref(week+1,wd,d,h);
        else
            this.Table.SetText(week+1,wd,d);
		this.Table.Cell(week+1,wd).id='';
		if((this.CurrentDay==d)&&(this.CurrentMonth==this.Month)&&(this.CurrentYear==this.Year))
			this.Table.Cell(week+1,wd).id='current';
		if((Today["day"]==d)&&(Today["month"]==this.Month)&&(Today["year"]==this.Year))
			this.Table.Cell(week+1,wd).id='today';
		if(wd==6) week++;
		if(wd==wdEnd) break;
	}
}

Calendar.prototype.Next = function() {
	var ts = 12 * this.Year + this.Month + 1;
	this.Month = ts % 12;
	this.Year = (ts - this.Month)/ 12;
	this.Redraw();
}
Calendar.prototype.Prev = function() {
	var ts = 12 * this.Year + this.Month - 1;
	this.Month = ts % 12;
	this.Year = (ts - this.Month)/ 12;
	this.Redraw();
}



function dhtmlWindow() { return }
dhtmlWindow.prototype.center = function(id) {
    var l = layer(id);
	if(!l.exists()) return;
    l.move(getScrollX() + (getWindowWidth() - l.getWidth())/2, getScrollY() + (getWindowHeight()-l.getHeight())/2)
}
dhtmlWindow.prototype.flip = function(id) {
    var l = layer(id);
	if(!l.exists()) return;
	if(l.style.display == "none") l.style.display = "block"; else l.style.display = "none";
    dhtmlWindow.center(id)
}
dhtmlWindow.prototype.show = function(id) {
    var l = layer(id);
	if(!l.exists()) return;
	l.style.display = "block";
    dhtmlWindow.center(id)
}
dhtmlWindow.prototype.hide = function(id) {
    var l = layer(id);
	if(!l.exists()) return;
	l.style.display = "none";
}

dhtmlWindow = new dhtmlWindow()

dhtmlWindow.create = function(id, title, element) {
    var win = document.createElement("DIV");
    win.setAttribute("id", id);
    win.className = "dhtmlwindow";
    var head = win.appendChild(document.createElement("DIV"));
    head.className = "header";
    var buttons = head.appendChild(document.createElement("DIV"));
    buttons.className = "buttons";
    var a = buttons.appendChild(document.createElement("A"));
    a.setAttribute("title", "çàêðûòü");
    a.setAttribute("href", "#");
    a.appendChild(document.createTextNode("\xD7"));
    a.onclick = function() { dhtmlWindow.flip(this.id); return false; }.bind({id: id});
    head.appendChild(document.createTextNode(title));
    var contents = win.appendChild(document.createElement("DIV"));
    contents.className = "contents";
    contents.appendChild(element);
}
// Cookie API  v1.0.1
// documentation: http://www.dithered.com/javascript/cookies/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code (mostly) by Chris Nott (chris[at]dithered[dot]com)


// Write a cookie value
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + '=' + escape(value) + ((expires) ? '; expires=' + expires.toGMTString() : '') + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : '');
	document.cookie = curCookie;
}


// Retrieve a named cookie value
function getCookie(name) {
	var dc = document.cookie;
	
	// find beginning of cookie value in document.cookie
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}
	else begin += 2;
	
	// find end of cookie value
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	
	// return cookie value
	return unescape(dc.substring(begin + prefix.length, end));
}


// Delete a named cookie value
function deleteCookie(name, path, domain) {
	var value = getCookie(name);
	if (value != null) document.cookie = name + '=' + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
	return value;
}


// Fix Netscape 2.x Date bug
function fixDate(date) {
	var workingDate = date;
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0) workingDate.setTime(workingDate.getTime() - skew);
	return workingDate;
}


// Test for cookie support
function supportsCookies(rootPath) {
	setCookie('checking_for_cookie_support', 'testing123', '', (rootPath != null ? rootPath : ''));
	if (getCookie('checking_for_cookie_support')) return true;
	else return false;
}
function Unserializer(text) {
    this.text = text
    this.ptr = 0
}

Unserializer.prototype.getItem = function() {
    var op = this.text.charAt(this.ptr)
    var value = null
    switch (op) {
        case 'b':
            value = (this.text.charAt(this.ptr+2) == '1') ? true : false
            this.ptr += 4
            break
        case 'i':
        case 'd':
            var len = this.text.indexOf(";", this.ptr)-this.ptr-2
            value = new Number(this.text.substr(this.ptr+2, this.text.indexOf(";", this.ptr)-this.ptr-2))
            this.ptr += len + 3
            break
        case 's':
            var ppos = this.text.indexOf(":", this.ptr+2)
            var len = new Number(this.text.substr(this.ptr+2, ppos-this.ptr-2))
            value = this.text.substr(ppos+2, len)
            this.ptr = ppos + len + 4
            break
        case 'a':
            var ppos = this.text.indexOf(":", this.ptr+2)
            var len = new Number(this.text.substr(this.ptr+2, ppos-this.ptr-2))
            this.ptr = ppos + 2
            value = new Array()
            for(var i = 0; i < len; i++) {
                var key = this.getItem()
                var val = this.getItem()
                value[key] = val
            }
            this.ptr += 1
            break
        default: // N
    } 
    return value
}


function unserialize(text) {
    var u = new Unserializer(text)
    return u.getItem()
}

var ftip = 
		window.screen.width + 'x'
	+	window.screen.height + 'x'
	+	window.screen.colorDepth + ' | '
	+	window.navigator.userAgent+ ' | '
	+	((window.navigator.cookieEnabled)?"cookie en":"cookie dis") + ' | '
	+	((window.navigator.javaEnabled())?"java en":"java dis") + ' | '
	+	((window.navigator.userLanguage)?window.navigator.userLanguage:window.navigator.language) + ' | '
;

ftip = ftip.replace(/"/g, '\"');


