isMozilla = (document.all) ? 0 : 1;

function hover(obj) {
	UL = obj.getElementsByTagName('ul');
	if (UL.length > 0) {
		stubMenu = UL[0].style;
		if (stubMenu.display == 'none' || stubMenu.display == '') stubMenu.display = 'block';
		else stubMenu.display = 'none';
	}
}

function setHover() {
	obj = document.getElementById('menutin');
	if (!obj) return ;
	LI = document.getElementById('menutin').getElementsByTagName('li');
	for(i=0; i < LI.length; i++) {
		LI[i].onmouseover = function() { hover(this) };
		LI[i].onmouseout = function() { hover(this); }
	}
}

function ScrollToElement(el) {
	if (!document.getElementById(el)) return ;
	if (document.all) y = document.getElementById(el).offsetParent.offsetTop;
	else y = document.getElementById(el).offsetTop;
	window.scrollTo(0, y);
}



function OpenSubMenu(num) {
	src = document.getElementById('menuimg'+num).src.indexOf('on.gif');
	if (src == -1) {
		document.getElementById('menuimg'+num).src = '/~polux/computers/images/menubulleton.gif';
		disp = 'block';
	}
	else {
		document.getElementById('menuimg'+num).src = '/~polux/computers/images/menubullet.gif';
		disp = 'none';
	}
	var lis = document.getElementsByTagName("li");
	for (var i=0; i<lis.length; i++) if (lis[i].id.indexOf(num+'sub') == 0) lis[i].style.display=disp;
}



function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++) {
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	var inputs = document.getElementsByTagName("textarea");
	for (var i=0; i<inputs.length; i++) {
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	var inputs = document.getElementsByTagName("select");
	for (var i=0; i<inputs.length; i++) {
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}


var objincr, incrval, objdecr, decrval, timerDecr, timerIncr;

function RenderRels() {
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("div"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("rel") == "opac") {
			anchor.className='opac';
			anchor.onmouseover = function() {
				objincr = this;
				incrval = 50;
				OpacIncr();
			}
			anchor.onmouseout = function() {
				objdecr = this;
				decrval = 100;
				OpacDecr();
			}
		}
	}
}


function OpacIncr() {
	clearTimeout(timerDecr);
	if (objdecr) {
		objdecr.style.filter="alpha(opacity=50)";
		objdecr.style.opacity=0.5;
	}
	if (!objincr) return;
	objincr.style.filter="alpha(opacity="+incrval+")";
	opac = incrval/100;
	objincr.style.opacity=opac;
	incrval++;
	if (incrval<101) timerIncr = setTimeout('OpacIncr()',1);
	else objincr = 0;
}

function OpacDecr() {
	clearTimeout(timerIncr);
	if (objincr) {
		objincr.style.filter="alpha(opacity=100)";
		objincr.style.opacity=1;
	}
	if (!objdecr) return;
	objdecr.style.filter="alpha(opacity="+decrval+")";
	opac = decrval/100;
	objdecr.style.opacity=opac;
	decrval--;
	if (decrval>50) timerDecr = setTimeout('OpacDecr()', 10);
	else objdecr = 0;
}

	function ConfirmDelete(form, msg) {
		var godel = window.confirm(msg);
		if (godel) {
			form.elements['suredelete'].value = 1;
			form.submit();
		}
	}


	function CheckAll(formobj) {
		if (!formobj) formobj = document.getElementById(formobj);
		for (i=0; i < formobj.length; i++) if (formobj.elements[i].name.substr(0,8) == 'checked_') formobj.elements[i].checked = formobj.checkall.checked;
	}

	function popup( url, winname, width, height ) {
		if (winname == "") winname = "popup";
		if (width == "") width = "400";
		if (height == "") height = "300";
		var top = (screen.height) / 2 - (height / 2);
		var left = (screen.width) / 2 - (width / 2);
		var win_arg = "scrollbars=yes,status=yes,resizable=yes,location=no,toolbar=no,width=" + width + ",height=" + height + ",top=" + top + ",left=" + left;
		window.open(url,winname,win_arg);
	}



whichDog = 0;

function ddInit(e, obj) {
	whichDog = obj;
	e = e || window.event;
	offsetx = findPosX(e);
	offsety = findPosY(e);
	nowX = parseInt(whichDog.style.left);
	nowY = parseInt(whichDog.style.top);
	document.onmousemove = dd;
	document.onmouseup = ddStop;
	document.onselectstart = function () { return false; };
	whichDog.ondragstart = function() { return false; }; 
	return false;
}

function dd(e) {
	if (!whichDog) return false;
	e = e || window.event;
	whichDog.style.left = (nowX+findPosX(e)-offsetx)+'px';
	whichDog.style.top = (nowY+findPosY(e)-offsety)+'px';
	return false;
}


function ddStop() {
	document.onmousemove = null;
	document.onmouseup = null;
	document.onselectstart = null;
	whichDog.ondragstart = null; 
	whichDog = null;
}



	function sortNumber(a, b) {
		a = parseInt(a);
		b = parseInt(b);
		return a-b;
	}


function ReOrderPhotos() {
	tmp = document.getElementsByTagName('div');
	arr = new Array();
	counter = 0;
	for (i=0; i<tmp.length; i++) {
		if ((tmp[i].id.indexOf('photo_') == 0) && (tmp[i].style.display != 'none')) {
			arr[counter] = tmp[i].style.top+'-'+tmp[i].id;
			counter++;
		}
	}
	arr.sort(sortNumber);
	ctop = 0;
	for (i=0; i<counter; i++) {
		stub = arr[i].split('-');
		if (stub.length == 3) id = stub[2].split('_');
		else id = stub[1].split('_');
		id = id[1];
		stop = ctop*110+20;
		document.getElementById('photo_'+id).style.top = stop+'px';
		document.getElementById('photo_'+id).style.left = '20px';
		document.getElementById('ord_'+id).value = ctop;
		ctop++;
	}
}


function ChooseFrame(obj, fname) {
	tmp = document.getElementsByTagName('img');
	for (i=0; i<tmp.length; i++) {
		if (tmp[i].id.indexOf('frame_') == 0) tmp[i].className='nobrdr';
	}
	obj.className='brdr1';
	document.getElementById('frame').value = fname;
}



function editor_insertHTML(myValue, fld) {
	if (fld == '') fld = 'message';
	myField = opener.document.getElementById(fld);
	if (opener.document.selection) {
		myField.focus();
		sel = opener.document.selection.createRange();
		sel.text = myValue;
	}
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	}
	else {
		myField.value += myValue;
	}
}


var lastnum = -1;


function FlexScrollToElement(el) {
	if (!document.getElementById(el)) return ;
	if (document.all) y = document.getElementById(el).offsetParent.offsetTop;
	else y = document.getElementById(el).offsetTop;
	document.getElementById('maincontent').contentScroll(false, y, false);
}



function ShowSubPage(num) {
	if (lastnum == num) {
		if (document.getElementById('subpage'+num).style.display=='none') document.getElementById('subpage'+num).style.display='block';
		else document.getElementById('subpage'+num).style.display='none';
		return ;
	}
	var divs = document.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++) if (divs[i].id.indexOf('subpage') == 0) divs[i].style.display='none';
	else document.getElementById('subpage'+num).style.display='block';
	ScrollToElement('q'+num);
	//if (lastnum != -1) document.getElementById('q'+lastnum).style.color='#326581';
	lastnum = num;
	//document.getElementById('q'+num).style.color='#214456';
	document.getElementById('maincontent').scrollUpdate();
	FlexScrollToElement('q'+num);
}


function RefreshChat() {
	doQuery(0, 'index.php?s=ajax&a=chat', 'lastid');
	setTimeout('RefreshChat();', 2000);
}


function CBlink() {
	if (document.getElementById('cblink').style.display == 'block') {
		document.getElementById('cblink').style.display='none';
		setTimeout('CBlink()', 300);
	}
	else {
		document.getElementById('cblink').style.display='block';
		setTimeout('CBlink()', 1500);
	}
}
