function reloadCaptcha() {
	var img = document.getElementById('cappic');
	img.src = '/lib/frmcaptcha.php?rld=' + Math.random();
	return false;
}

function rldContent(t, txt) {
	if (t.value == txt) {
		t.value = '';
	}
}

function rldContent2(t, txt) {
	if (t.value == '') {
		t.value = txt;
	}
}

function CheckLoginForm(frm, uname, upass) {
	if (frm.uname.value == uname) {
		frm.uname.value = '';
	}
	
	if (frm.upass.value == upass) {
		frm.upass.value = '';
	}

	return true;

}

// MENU START
function menuHide(sm) {
	sm.style.display = 'none';
}

function menuShow(sm) {
	var parUl = sm.parentNode;
	while (true) {
		if (parUl.nodeName.toLowerCase() == 'ul') break;
		parUl = parUl.parentNode;
	}
	if (parUl.id == 'menu') {
		sm.style.top = sm.parentNode.offsetHeight + 'px';
		sm.style.left = sm.parentNode.offsetLeft + 'px';
	} else {
		sm.style.top = sm.parentNode.offsetTop + 'px';
		sm.style.left = (sm.parentNode.offsetLeft + sm.parentNode.offsetWidth) + 'px';
	}
	sm.style.display = 'block';
}

function MenuOver(ev) {
	if (!ev) var ev = window.event;
	var from = ev.srcElement || ev.target;
	while (from) {
		if (from.nodeName.toLowerCase() == 'li') break;
		from = from.parentNode;
	}
	if (!from) return;
	
	var sm = from.getElementsByTagName('ul')[0];
	if (sm) {
		menuShow(sm);
	}
}

function MenuOut(ev) {
	if (!ev) var ev = window.event;
	var from = ev.srcElement || ev.target;
	var to = ev.toElement || ev.relatedTarget;
	
	while (from) {
		if (from.nodeName.toLowerCase() == 'li') break;
		from = from.parentNode;
	}
	if (!from) return;
	
	while (to) {
		if (to.nodeName.toLowerCase() == 'ul') break;
		to = to.parentNode;
	}
	
	if (!to) DropdownMenuInit(document.getElementById('menu'));
	
	var sm = from.getElementsByTagName('ul')[0];
	if (sm) {
		if (to && sm.id == to.id) return;
		menuHide(sm);
	}
}

function DropdownMenuInit(element) {
	var chld = element.childNodes;
	for (var i = 0; i < chld.length; i ++) {
		if (chld[i].nodeName.toLowerCase() != 'li') continue;
		var sm = chld[i].getElementsByTagName('ul')[0];
		if (sm) {
			menuHide(sm);
			DropdownMenuInit(sm);
		}
	}
}

function ActivateMenu(id) {
	var m = document.getElementById(id);
	DropdownMenuInit(m);
	m.onmouseover = function(ev) {MenuOver(ev);};
	m.onmouseout = function(ev) {MenuOut(ev);};
}
// MENU END

// correctly handle PNG transparency in Win IE 5.5 & 6.
function correctPNG() {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5 && version < 7.0) && (document.body.filters)) {
		for(var i=0; i<document.images.length; i++) {
			var img = document.images[i];
			var imgName = img.src.toUpperCase();
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
				var imgID = (img.id) ? "id='" + img.id + "' " : "";
				var imgClass = (img.className) ? "class='" + img.className + "' " : "";
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
				var imgStyle = "display:inline-block;" + img.style.cssText;
				if (img.align == "left") imgStyle = "float:left;" + imgStyle;
				if (img.align == "right") imgStyle = "float:right;" + imgStyle;
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
					+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
					+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
					+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
				img.outerHTML = strNewHTML;
				i = i-1;
			}
		}
	}
}

// Gallery
function GetPhoto(id, pref) {
	var gallery = document.getElementById('gallery');
	var bigphoto = document.getElementById('bigphoto');
	var imgs = gallery.getElementsByTagName('img');
	
	for (var i = 0; i < imgs.length; i++) {
		var imgclass = imgs[i].className;
		if (imgclass == 'default') {
			bigphoto.className = 'visible';
			imgs[i].src = '/showimg.php?filename=' + pref + '_' + id + '.jpg';
		}
	}
}

function popUp(img,name,width,height) {
	var opened = false;
	var win;
   	if (opened == false) {
		win = open(img,name,"status=0,scrollbars=1,menubar=0,toolbar=0,location=0,resizeable=0,width=" + width + ",height=" + height + ",left=" + ((screen.width-width)/2) + ",top=" + ((screen.height-height)/2));
	} else if (opened == true) {
		if (win.closed == false)
		win.close(); 
		win = window.open(img,name,"status=0,scrollbars=1,menubar=0,toolbar=0,location=0,resizeable=0,width=" + width + ",height=" + height + ",left=" + ((screen.width-width)/2) + ",top=" + ((screen.height-height)/2));
	}
	opened = true;
}

var picWin = false;
function picPopUp( img, name, width,height ){
	if (picWin.closed == false){
		picWin.location = img;
		picWin.focus();
	}else{	
		picWin = window.open(img,name,"status=0,scrollbars=1,menubar=0,toolbar=0,location=0,resizeable=1,width=" + width + ",height=" + height + ",left=" + ((screen.width-width)/2) + ",top=" + ((screen.height-height)/2));
	}
}
