var IE = document.all ? true : false

function enterPressed(e) {

	var characterCode;

	if (e && e.which) characterCode = e.which;
	else {

		e = event;
		characterCode = e.keyCode;

	}

	return characterCode == 13 ? true : false;

}

String.prototype.pad = function(l, s, t){
	return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
		+ 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
		+ this + s.substr(0, l - t) : this;
};

function dateDiff (startDate, stopDate) {

	date_1 = new Date (
		parseInt (startDate.substring(0, 4)),
		parseInt (startDate.substring(5, 7)) - 1,
		parseInt (startDate.substring(8, 10))
	);
	date_2 = new Date (
		parseInt (stopDate.substring(0, 4)),
		parseInt (stopDate.substring(5, 7)) - 1,
		parseInt (stopDate.substring(8, 10))
	);

	day	= 1000 * 60 * 60 * 24;

	return (Math.abs (Math.ceil ((date_2.getTime() - date_1.getTime()) / day)));

}

function dateMonth(month) {

	switch (month) {

		case 'Jan': return '01';
		case 'Feb': return '02';
		case 'Mar': return '03';
		case 'Apr': return '04';
		case 'May': return '05';
		case 'Jun': return '06';
		case 'Jul': return '07';
		case 'Aug': return '08';
		case 'Sep': return '09';
		case 'Oct': return '10';
		case 'Nov': return '11';
		case 'Dec': return '12';

	}

}

function transformDate(date) {

	day	= date.substring (0, 2);
	month	= date.substring (3, 6);
	year	= date.substring (7, 11);

	return year + '-' + dateMonth(month) + '-' + day;

}

function getX(e) {

        return IE ? event.clientX : e.pageX;

}

function getY(e) {

        return IE ? event.clientY : e.pageY;

}

function go2(url) {

	document.location.href = url;

}

function xmlhttp () {

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
			// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}

	return http_request;

}

function makeActive(id) {
        var item = parent.frames['leftMenu'].document.getElementById('menu');
        var elements = item.getElementsByTagName('li');

        for (i = 0; i < elements.length; i++) {
                elements[i].type = 'circle';
        }

        parent.frames['leftMenu'].document.getElementById(id).type='disc';
}

function xwin(url, name, width, height, features){
	var l = (window.screen.availWidth) ? (window.screen.availWidth - width)/2 : 0;
	var t = (window.screen.availHeight) ? (window.screen.availHeight - height)/2 : 0;
	if (typeof(features) == 'string')
		features = ',' + features;

	var w = window.open(url, name, 'top=' + t + ',left=' + l + ',height=' + height + ',width=' + width + ', scrollbars=auto' + features);
	if (!w) return;
	w.resizeTo(width, height);
	return w;
}

function sortField(file, field, mode) {
	window.location.href = file + '.php?sortField=' + field + '&sortMode=' + mode;
}

function deleteItem(file, id) {
	if (confirm ('Are you sure?'))
		window.location.href = file + '.php?deleteId=' + id;
}

function checkAll (object) {
	var elems = object.form.elements;
	for (var i = 0; i < elems.length; i++) {
		var elem = elems[ i ];
		if (elem.type == 'checkbox' && elem != this) {
			elem.checked = object.checked;
		}
	}
}

function debugElement(elem) {
	str = "";
	j = 0;
	for (i in elem) {
		//str+="<center><big>" + i + "</big></center><br/>\n";
		str+=i + "\n";
		j++;
		if (j==20) {
			//document.write(str);
			alert(str);
			str="";
			j = 0;
		}
	}
}
