// handle errors
function handleError() { return true; }
window.onerror = handleError;

// keep session alive
function keepsess(){
	ajax("", "save_session.php?what=keep&value=1");
	setTimeout("keepsess()", 180000);
}
setTimeout("keepsess()", 180000);

// swap/show/hide layers
function swapLayers(id) {
	hideLayer(cur_lyr);
	cur_lyr2=cur_lyr;
	cur_lyr = id;
	if (vis==false || cur_lyr2!=id){
		showLayer(id);vis=true;
		ajax("", "save_session.php?what=s_expand&value="+id)
	}
	else{
		vis=false;
		ajax("", "save_session.php?what=s_expand&value=")
	}
}
function showLayer(id) {
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) lyr.css.visibility = "visible";
	if (lyr && lyr.css) lyr.css.position = "";
}

function hideLayer(id) {
	var lyr = getElemRefs(id);
	//vis=false;
	if (lyr && lyr.css) lyr.css.visibility = "hidden";
	if (lyr && lyr.css) lyr.css.position = "absolute";
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

// set rating
function setRating(rating){
	ajax("updrtg", "setrating.php?id="+getid+"&rating="+rating);
}

function updrtg(res){
	ares = res.split("|");
	document.all.rtg.innerHTML=ares[0];
	document.all.rtg2.innerHTML=ares[1];
	showInfo(ares[2], ares[3], ares[4]);
}

// show infobox
function showInfo(info, title, ztime){
	nd(); if(popup_mode){overlib(info, CAPTION, title);}
	stoppops = true;
	setTimeout("nd(4331); stoppops = false;", ztime);
}

// add to bookmarks
function addtobk(id){
	ajax("updbk", "addbook.php?id="+id);
}
function updbk(res){
	ares = res.split("|");
	showInfo(ares[0], ares[1], ares[2]);
}

// send to friend
function sendfr(id){
	if(mail = prompt("Въведете е-мейл адреса на вашия приятел:", "")){
		ajax("updsendf", "sendfriend.php?id="+id+"&mail="+mail);
	}
}
function updsendf(res){
	ares = res.split("|");
	showInfo(ares[0], ares[1], ares[2]);
}
