﻿var ie, op, ff;
if (typeof ie == 'undefined') {
	ie = op = ff = false;
	var browser = window.navigator.appName;
	if (browser == 'Opera') op = true;
	else if (browser == 'Microsoft Internet Explorer') ie = true;
	else if (browser == 'Netscape') ff = true;
}
function getElementsByClass(searchClass, node, tag) {
	var classElements = [];
	if (typeof node == 'undefined')
		node = document;
	if (typeof tag == 'undefined')
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (var i = 0; i < elsLen; i++)
		if (pattern.test(els[i].className))
			classElements.push(els[i]);
	return classElements;
}
//Array.prototype.contains = new function (value) {
//	var i;
//	for (i = 0; i < this.length; ++i)
//		if (this[i] === value)
//			return true;
//	return false;
//}
function $() {
	var elements = [];
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
function EscapeHTML(str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
};
function Toggle(el) {
	el.style.display = (el.style.display == 'none' ? '' : 'none');
}
function CookieGet(name) {
	var start = document.cookie.indexOf(name + "=");
	if (start == -1)
		return null;
	var len = start + name.length + 1;
	var end = document.cookie.indexOf(';', len);
	if (end == -1)
		end = document.cookie.length;
	return unescape(document.cookie.substring(len, end));
}
function CookieSet(name, value, expires, path, domain, secure) {
	var today = new Date();
	today.setTime(today.getTime());
	if (expires)
		expires = expires * 1000 * 60 * 60 * 24;
	var expires_date = new Date(today.getTime() + expires);
	document.cookie = name + '=' + escape(value) +
		((expires) ? ';expires=' + expires_date.toGMTString() : '') +
		((path) ? ';path=' + path : '') +
		((domain) ? ';domain=' + domain : '') +
		((secure) ? ';secure' : '');
}
//function CookieDelete(name, path, domain) {
//	if (CookieGet(name))
//		document.cookie = name + '=' +
//			((path) ? ';path=' + path : '') +
//			((domain) ? ';domain=' + domain : '') +
//			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
//}
function ImagePopupOpen(aImagePath, aImgWidth, aImgHeight, aTitle) {
    if (typeof popupHandles == 'undefined')
        popupHandles = [];
    if (typeof popupImages == 'undefined')
        popupImages = [];
    var clearSlot = -1;
    for (var i = 0; i < popupHandles.length; ++i)
        if (popupHandles[i] == -1) {
            if (clearSlot == -1)
                clearSlot = i;
        } else
            if (popupHandles[i].closed) {
                popupHandles[i] = -1;
                popupImages[i] = '';
                if (clearSlot == -1)
                    clearSlot = i;
            } else
                if (popupImages[i] == aImagePath) {
                    popupHandles[i].focus();
                    return;
                }
    if (clearSlot == -1)
        clearSlot = popupHandles.length;

    var leftpos = parseInt((screen.width - aImgWidth - 10)/2);
    var toppos = parseInt((screen.height - aImgHeight - 30)/2);
    var w = window.open('','','width='+aImgWidth+',height='+aImgHeight
		+',resizable=yes,status=no,menubar=no,location=no,scrollbars=no,toolbar=no,left='
		+leftpos+',top='+toppos+',screenX='+leftpos+',screenY='+toppos);
	if (w) {
        popupHandles[clearSlot] = w;
        popupImages[clearSlot] = aImagePath;
        w.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'
		    +((typeof aTitle == 'undefined')?'Screenshot':aTitle)
		    +'</title></head><body style="background: url('
		    +document.getElementsByTagName('BASE')[0].href+aImagePath
		    +') no-repeat center center; padding: 0; margin: 0; height: 100%;"></body></html>');
        w.document.close();
    }
}
function ToggleMenu(node) {
	node.nextSibling.style.display = (node.nextSibling.style.display == 'none') ? '' : 'none';
	node.parentNode.className = (node.parentNode.className == 'lm_opened') ? 'lm_closed' : 'lm_opened';
}
function XmlHttpGet(type) {
	var http_request;
	if (window.XMLHttpRequest) { // W3C browsers
		http_request = new XMLHttpRequest();
		http_request.overrideMimeType(type);
	}
	else if (window.ActiveXObject) // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert('Your browser do not allow AJAX!');
				return null;
			}
		}
	return http_request;
}
function XmlHttp(type) {
	var core = XmlHttpGet(type);
	var callbackParams;
	this.Get = function(url, callback, cParams) {
		if (!core || (core.readyState != 0/*UNINITIALIZED*/ && core.readyState != 4/*COMPLETED*/))
			return null;
		if (cParams)
			callbackParams = cParams;
		core.open('GET', url, true);
		core.onreadystatechange = function() {
			if (core.readyState == 4)
				if (core.status == 200)
					callback(core.responseText, callbackParams);
		};
		core.send(null);
		return true;
	}
	this.Post = function(url, postParams, callback, cParams) {
		if (!core || (core.readyState != 0/*UNINITIALIZED*/ && core.readyState != 4/*COMPLETED*/))
			return null;
		if (cParams)
			callbackParams = cParams;
		core.open('POST', url, true);
		core.onreadystatechange = function() {
			if (core.readyState == 4)
				if (core.status == 200)
					callback(core.responseText, callbackParams);
		};
		core.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		core.send(postParams);
		return true;
	}
	if (!core)
		return null;
}
function zoomImg(t, width) {
	if (t.width == width) {
		var img = new Image();
		img.src = t.src;
		t.width = img.width;
		t.height = img.height;
	} else {
		var w = width;
		var h = w*t.height/t.width;
		t.width = w;
		t.height = h;
	}
}