var imgDir = 'template/images/';

function findObj(theObj, theDoc)
{
	var p, i, foundObj;
	if(!theDoc) theDoc = document;
	if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
	{
		theDoc = parent.frames[theObj.substring(p+1)].document;
		theObj = theObj.substring(0,p);
	}

	if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];

	for (i=0; !foundObj && i < theDoc.forms.length; i++)
		foundObj = theDoc.forms[i][theObj];

	for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
		foundObj = findObj(theObj,theDoc.layers[i].document);

	if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
	
	return foundObj;
}


function getTxt(objId,e)
{
	with (document)
	{ 
		if (getElementById) var obj = getElementById(objId);
		if (obj) return (e==1)?escape(obj.value):obj.value;
	}
}

function popUp(URL,i,w,h) {
	l=(screen.width-w)/2;
	t=(screen.height-h)/2;
	window.open(URL, i, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width='+w+',height='+h+',left='+l+',top='+t);
}
/*----[ COMMENT ]----------------------------------------------------------------------------*/

function comment()
{
	var idx = arguments[0];
	var box = (arguments[1])?arguments[1]:0;
	var tbox = findObj('commentbox');
	
	if (box==0) {	
		var xname = getTxt('xname',1);
		var xcomment = getTxt('xcomment',1);	
		if (xname!='' && xcomment!='') {
			tbox.innerHTML = 'Commenting...';
			var mx = new Ajax.Updater('commentbox', 'modules/news/comments.php', { parameters: { id: idx, ccname: xname, ccoment: xcomment }});
		} else {
			alert('Please enter a name and comment');	
		}
	} else {
		var mx = new Ajax.Updater('commentbox', 'modules/news/comments.php', { parameters: { id: idx, show: 'box' }});
	}
}


/*----[ RATING ]----------------------------------------------------------------------------*/

function init_rating(idx,l)
{
	var sml = findObj(l);
	sml.innerHTML = '<div id="stars" style="cursor: pointer;cursor: hand;" align="right"></div>'+click_a_star;
	rateover(0,idx);
}

function rateover(r,idx)
{
	var xstars = findObj('stars');
	var n = imgDir+'ico_grayrate.gif';
	var o = imgDir+'ico_rate.jpg';
	
	var star = '';
	for (i=1;i<=5;i++)
	{
		img  = (i<=r)?o:n;
		star+= '<img src="../common/'+ img +'" width="18" height="18" onclick="ratethis('+ i +','+ idx +');" onmousemove="rateover('+ i +','+ idx +');" />';
	}
	xstars.innerHTML=star;
}

function ratethis(r,idx)
{
	var mx = new Ajax.Updater('ratebar', 'modules/news/ratethis.php', {
		parameters: { id: idx, star: r }
	});
}

/*----[ ARCHIVE ]----------------------------------------------------------------------------*/

function typeset(t,v,d,x)
{
	var mx = new Ajax.Updater(d, 'modules/news/archive_setdisplaytype.php', {
		parameters: { t: t, v: v, x: x, d: d }
	});
}

function archivelist(d,c)
{
	
	if (d=='') d='x';
	if (c=='') c='x';

	new Ajax.Updater('archiveList', 'modules/news/archive_display.php', {  
		parameters: { c: c, d: d }
	});
}

/*----[ NEWS DISPLAY ]----------------------------------------------------------------------------*/

function displayNews(id,le)
{
	var mx = new Ajax.Updater('newsContent', 'modules/news/news_display_content.php', { parameters: { i: id, l: le }});
}
function displayIntroduction(id,le,ux)
{
	var mx = new Ajax.Updater('newsContent', 'modules/news/news_display_content.php', { parameters: { ex: id, l: le , ue: ux }});
}

function switchLang(id,le)
{
	var ln = (le=='en')?'dv':'en';
	var img = imgDir+ln+'_but_read.gif';
	var bt = findObj('switchLang');
	var box = findObj('newsContent');
	ln = "'"+ln+"'";
	
	box.className = le + '_newsbox';
	box.innerHTML = 'Loading...';
	
	bt.innerHTML = '<a href="#" onclick="switchLang('+id+','+ln+');return false;"><img src="../common/'+img+'" border="0"></a>';
	displayNews(id,le);
}

/*----[ GALLERY ]----------------------------------------------------------------------------------*/
function comment_gallery()
{
	var idx = ""+arguments[0];
	var box = (arguments[1])?arguments[1]:0;
	
	var tbox = findObj('commentbox');
	
	if (box==0) {	
		var xname = getTxt('xname',1);
		var xcomment = getTxt('xcomment',1);	
		if (xname!='' && xcomment!='') {
			tbox.innerHTML = 'Commenting...';
			var mx = new Ajax.Updater('commentbox', 'modules/gallery/comments.php', { parameters: { id: idx, ccname: xname, ccoment: xcomment }});
		} else {
			alert('Please enter a name and comment');	
		}
	} else {
		var mx = new Ajax.Updater('commentbox', 'modules/gallery/comments.php', { parameters: { id: idx, show: 'box' }});
	}
}
function DispItem(){
	var id  = arguments[0];

	var mbox = findObj('mediax');
	mbox.innerHTML = 'Loading...';
	var mx = new Ajax.Updater('mediax', 'modules/gallery/gallery_display_item.php', { parameters: { i: id }});
	comment_gallery(id,1);
}

function startShow()
{
	var x = findObj('lnkStartShow');
	if (x) Lightbox.prototype.start(x);
}




/*----[ LEFT MENU ]--------------------------------------------------------------------------*/

/* initialize functionality */
mnuHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" mnuhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" mnuhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", mnuHover);


