// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires : "") +
        (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    now = now.toGMTString();
    if (f.author != undefined)
       setCookie('mtcmtauth', f.author.value, now, '/', '', '');
    if (f.email != undefined)
       setCookie('mtcmtmail', f.email.value, now, '/', '', '');
    if (f.url != undefined)
       setCookie('mtcmthome', f.url.value, now, '/', '', '');
}

function forgetMe (f) {
    deleteCookie('mtcmtmail', '/', '');
    deleteCookie('mtcmthome', '/', '');
    deleteCookie('mtcmtauth', '/', '');
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';
}

function hideDocumentElement(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'none';
}

function showDocumentElement(id) {
    var el = document.getElementById(id);
    if (el) el.style.display = 'block';
}

var commenter_name;

function individualArchivesOnLoad(commenter_name) {

    hideDocumentElement('trackbacks-info');



    if (document.comments_form) {
        if (document.comments_form.email != undefined &&
            (mtcmtmail = getCookie("mtcmtmail")))
            document.comments_form.email.value = mtcmtmail;
        if (document.comments_form.author != undefined &&
            (mtcmtauth = getCookie("mtcmtauth")))
            document.comments_form.author.value = mtcmtauth;
        if (document.comments_form.url != undefined && 
            (mtcmthome = getCookie("mtcmthome")))
            document.comments_form.url.value = mtcmthome;
        if (mtcmtauth || mtcmthome) {
            document.comments_form.bakecookie.checked = true;
        } else {
            document.comments_form.bakecookie.checked = false;
        }
    }
}

function writeTypeKeyGreeting(commenter_name, entry_id) {

}




var D = {
	
	_tag: function(tag, parent) {
			var par = parent || document;
						
			return par.getElementsByTagName(tag);
		},
	
	_class: function(classname, tag, parent)	{
			var matches = [];
			var par = parent || document;
			
			var els = this._tag(tag, parent);
			var elsl = els.length;
			
			for(var i=0; i<elsl; i++) {
					if (els[i].className == classname)
						matches.push(els[i]);
				}
			
			if (matches.length == 1)
				return matches[0];
			
			return matches.length == 0 ? false : matches;
			
		
		},
	_id: function(id) {
			return document.getElementById(id);
		},
	
	_attr: function(attr, value, tag, parent) {

			var matches = [];
			var par = parent || document;
			
			var els = this._tag(tag, parent);
			var elsl = els.length;
			
			for (var i=0; i<elsl; i++) {
					if (els[i].getAttribute(attr) == value)
						matches.push(els[i]);
				}
			
			if (matches.length == 1)
				return matches[0];
			
			return matches.length == 0 ? false : matches;
			
				
		},
		_index: function(obj) {
					var parent_node = obj.parentNode;
					if (!parent_node)
						throw "nodeIndex: Missing parent for " + obj;
					
					for (var i = 0, cnt = 0, node, nodes = parent_node.childNodes; node = nodes[i]; i++) {
						if (node.tagName) {
							if (node === obj)
								return cnt;
							
							cnt++;
						}
					}
					return null;
		},	
		E: {
				add: function(obj, evt, func) {
					
					if (document.addEventListener)
						obj.addEventListener(evt, func, false);
					else if(document.attachEvent)
						obj.attachEvent('on'+evt,func);
					
					
					},
				remove: function(obj, evt, func) {
						obj.removeEventListener(evt, func, false);
					},
			
				get: function(e, p) {
						e = e || window.event;
						
						if (p)
							D.E.pd(e);
						
						return t = e.target || e.srcElement;
					
					},
				pd: function(e) {
						if (e.stopPropagation) {
							 e.stopPropagation();
							 
						} else if(e.cancelBubble) { 
							e.cancelBubble = true;
							
						} else {
						
							if (e.preventDefault) {
								e.preventDefault();
							} else {
								e.returnValue = false; 
								return false; 
							}
						}
						
						
					}
			
			},
		Parent: {
				_attr: function(obj, attr, value) {
						if (!obj)
							return false;

						pn = obj.parentNode;
			
						if (!pn || pn.nodeName.toLowerCase() == 'html')
							return false;
							
						if (pn && (pn.getAttribute(attr) == value)) {
								return pn;
							}
			
						return D.Parent._attr(pn, attr, value);

					
					}
			
			}
		
	
	}
	
	
	
var Util = {
		
		clean: function(parobj) {
			var notWhiteSpaceNode = /\S/;
				
			for (i=0;i<parobj.childNodes.length;i++){
				if ((parobj.childNodes[i].nodeType == 3) && (!notWhiteSpaceNode.test(parobj.childNodes[i].nodeValue))) {
					parobj.removeChild(parobj.childNodes[i]);
						i--;
				}
			}
		}
	
	
	}
	
	
	
Pane = {
	
	Init: function() {
			panes = D._attr('name', 'panel', 'div')
			total = panes.length;
			for (var i=0; i<total; i++) {
				var ul = D._class('tab_panes', 'ul', panes[i]);
				if (ul) {
					Util.clean(ul);
					ull = ul.childNodes.length;
					for (var j = 0; j<ull; j++) {
						D.E.add(ul.childNodes[j], 'click', Pane.Switch)
						ul.childNodes[j].className = 'tab_' + (j + 1);
					}
				}
					
			}
		},
	
	Switch: function(e) {
			li = D.E.get(e, true);
			ind = D._index(li);
			panel = D.Parent._attr(li, 'name', 'panel');
			
			panel.className = 's_'+ (ind + 1);
			
		}

	}


window.onload = function() {
Pane.Init();
$('div#authors .acc').accordion(0)
if (location.search.match('action=print')) {
		window.print(); 
        }
}

/*** -------------------------  ***/
function require(script_name, path) {
pth = path || 'http://mtlabs.blawgs.pro/js/'
document.write('<script language="javascript" src="'+pth+script_name+'.js"></script>');
}

require('jquery');
require('common');
/*** -------------------------  ***/



