var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {browserType= "gecko"}

function go(id,section_id)
{
	document.navigation_form.mode.value = 'browse';
	document.navigation_form.menu_id.value = id;
	document.navigation_form.section_id.value	= section_id;
	document.navigation_form.submit();
}

function goSection(id)
{
	document.navigation_form.mode.value = 'browse_section';
	document.navigation_form.section_id.value	= id;
	document.navigation_form.menu_id.value		= 0;
	document.navigation_form.content_id.value	= 0;
	document.navigation_form.submit();
}

function goContent(id)
{
	document.navigation_form.mode.value = 'browse_content';
	document.navigation_form.section_id.value	= 0;
	document.navigation_form.menu_id.value		= 0;
	document.navigation_form.content_id.value	= id;
	document.navigation_form.submit();
}

function changeLanguage(languageid)
{
	document.navigation_form.language_id.value = languageid;
	document.navigation_form.submit();
}

function siteSearch()
{
	document.navigation_form.value1.value = document.siteSearch_form.value1.value;
	document.navigation_form.mode.value = 'site_search';
	document.navigation_form.submit();
}

// ----------------------------------------------------------------------------------------------------------------------

function  findPosX(obj)
{
	var curleft = 0;
	if (browserType == "ie")
	{
		if (obj.offsetParent)
		{
			curleft = obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (browserType == "ie")
	{
		curtop = obj.offsetTop + obj.offsetHeight + 3;
		obj = obj.offsetParent;
	}
	else if (obj.offsetParent)
	{
		curtop += obj.offsetHeight;
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}

function hideMenu(menuid)
{
	hideMenuSlow(menuid);
}

function hideMenuFast(menuid)
{
	if (browserType == "gecko" )
		document.poppedLayer = eval('document.getElementById(\''+menuid+'\')');
	else if (browserType == "ie")
		document.poppedLayer = eval('document.all[\''+menuid+'\']');
	else
		document.poppedLayer = eval('document.layers[\'`'+menuid+'\']');
	document.poppedLayer.style.visibility = "hidden";
	delayhide	= 0;
	delaymenuid	= 0;
}

function hideMenuSlow(menuid)
{
	var delayTimeout	= 200;

	if(typeof delayhide == "undefined")
	{
		delayhide	= setTimeout("hideMenuFast('"+menuid+"')",delayTimeout);
		delaymenuid	= menuid;
	}
	else if(typeof delayhide == "number")
	{
		if(delayhide > 0)
			hideMenuFast(menuid);
		else
		{
			delayhide	= setTimeout("hideMenuFast('"+menuid+"')",delayTimeout);
			delaymenuid	= menuid;
		}
	}
}

function clearHideMenu(menuid)
{
	if((typeof delayhide != "undefined") && (typeof delaymenuid != "undefined"))
	{
		if(menuid == delaymenuid)
		{
			clearTimeout(delayhide);
			delayhide = 0;
			menuid	= 0;
			delaymenuid	= 0;
		}
	}
}

function showMenu(menuid)
{
	repositionLayer(menuid);
	clearHideMenu(menuid);
	if (browserType == "gecko" )
		document.poppedLayer = eval('document.getElementById(\''+menuid+'\')');
	else if (browserType == "ie")
		document.poppedLayer = eval('document.all[\''+menuid+'\']');
	else
		document.poppedLayer = eval('document.layers[\'`'+menuid+'\']');
	document.poppedLayer.style.visibility = "visible";
}

function repositionLayer(menuid)
{
	if (browserType == "gecko" )
	{
		document.floatingLayer = eval('document.getElementById(\''+menuid+'\')');
		document.referenceLayer = eval('document.getElementById(\''+menuid+'_ref\')');
	}
	else if (browserType == "ie")
	{
		document.floatingLayer = eval('document.all[\''+menuid+'\']');
		document.referenceLayer = eval('document.all[\''+menuid+'_ref\']');
	}
	else
	{
		document.floatingLayer = eval('document.layers[\'`'+menuid+'\']');
		document.referenceLayer = eval('document.layers[\'`'+menuid+'_ref\']');
	}
	if( (typeof document.floatingLayer != "undefined") && (typeof document.referenceLayer != "undefined") )
	{
	}

	// Move the floating menu layer
	var newX = findPosX(document.referenceLayer);
	var newY = findPosY(document.referenceLayer);
	document.floatingLayer.style.top = newY + 'px';
	document.floatingLayer.style.left = newX + 'px';
}

function hilightRow(theRow)
{
    // Get the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined')
	{
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined')
	{
        theCells = theRow.cells;
    }
    else
	{
        return false;
    }

	// Detect browser
    if (typeof(window.opera) == 'undefined')
        domDetect    = true;
    else
        domDetect    = false;

    // Set the new color...
	newColor	= '#00FF00';

    if (newColor)
	{
        var c = null;
		var rowCellsCnt = theCells.length;
        // with DOM compatible browsers except Opera
        if (domDetect)
		{
            for (c = 0; c < rowCellsCnt; c++)
			{
                theCells[c].setAttribute('bgcolor', newColor, 0);
            }
        }
        else
		{
            for (c = 0; c < rowCellsCnt; c++)
			{
                theCells[c].style.backgroundColor = newColor;
            }
        }
    }
}

// ----------------------------------------------------------------------------------------------------------------------

function moveContent(id,direction)
{
	document.navigation_form.mode.value = 'movecontent';
	document.navigation_form.value1.value = id;
	document.navigation_form.value2.value = direction;
	document.navigation_form.submit();
}

function newContent(id,position)
{
	document.navigation_form.mode.value = 'newcontent';
	document.navigation_form.menu_id.value = id;
	document.navigation_form.value1.value = position;
	document.navigation_form.submit();
}

function editContent(id)
{
	document.navigation_form.mode.value = 'editcontent';
	document.navigation_form.content_id.value = id;
	document.navigation_form.submit();
}

function saveContent()
{
	document.editContent_form.save.value = "yes";
	document.editContent_form.onsubmit();			// workaround browser bugs.
	document.editContent_form.submit();
}

function update()
{
	document.editContent_form.submit();
}

function fromNow()
{
	today		= new Date();
	day			= today.getDate();
	month		= today.getMonth()+1;
	year		= today.getFullYear();
	separator	= "/";

	document.editContent_form.goLive.value = day + separator + month + separator + year;
}

function toForever()
{
	document.editContent_form.goDead.value = 'forever';
}

function makeInvisible(id)
{
	document.navigation_form.mode.value = 'make_invisible';
	document.navigation_form.content_id.value = id;
	document.navigation_form.submit();
}

function makeVisible(id)
{
	document.navigation_form.mode.value = 'make_visible';
	document.navigation_form.content_id.value = id;
	document.navigation_form.submit();
}

// ----------------------------------------------------------------------------------------------------------------------

function editMenuSections()
{
	document.navigation_form.mode.value = 'editmenusections';
	document.navigation_form.value1.value = '';
	document.navigation_form.submit();
}

function addMenuSection(id)
{
	document.navigation_form.mode.value = 'addmenusection';
	document.navigation_form.value1.value = '';
	document.navigation_form.submit();
}

function editMenuSection(id)
{
	document.navigation_form.mode.value = 'editmenusection';
	document.navigation_form.value1.value = id;
	document.navigation_form.submit();
}

function hideMenuSection(id)
{
	document.navigation_form.mode.value = 'hidemenusection';
	document.navigation_form.value1.value = id;
	document.navigation_form.submit();
}

function showMenuSection(id)
{
	document.navigation_form.mode.value = 'showmenusection';
	document.navigation_form.value1.value = id;
	document.navigation_form.submit();
}

function moveMenuSection(id,direction)
{
	document.navigation_form.mode.value = 'movemenusection';
	document.navigation_form.value1.value = id;
	document.navigation_form.value2.value = direction;
	document.navigation_form.submit();
}

function editMenus(id)
{
	document.navigation_form.mode.value = 'editmenus';
	document.navigation_form.value1.value = id;
	document.navigation_form.submit();
}

function moveMenu(sectionid,menuid,direction)
{
	document.navigation_form.mode.value = 'movemenu';
	document.navigation_form.value1.value = sectionid;
	document.navigation_form.value2.value = menuid;
	document.navigation_form.value3.value = direction;
	document.navigation_form.submit();
}

function changeMenuOption(sectionid,menuid,direction)
{
	document.navigation_form.mode.value = 'changemenuoption';
	document.navigation_form.value1.value = sectionid;
	document.navigation_form.value2.value = menuid;
	document.navigation_form.value3.value = direction;
	document.navigation_form.submit();
}

function editMenu(menuid,sectionid)
{
	document.navigation_form.mode.value = 'editmenu';
	document.navigation_form.value1.value = menuid;
	document.navigation_form.value2.value = sectionid;
	document.navigation_form.submit();
}

function addMenu(id,pid)
{
	document.navigation_form.mode.value = 'addmenu';
	document.navigation_form.value1.value = id;
	document.navigation_form.value2.value = pid;
	document.navigation_form.submit();
}

// ----------------------------------------------------------------------------------------------------------------------

function showLanguages()
{
	document.navigation_form.mode.value = 'showlanguages';
	document.navigation_form.value1.value = '';
	document.navigation_form.submit();
}

function addLanguage()
{
	document.navigation_form.mode.value = 'addlanguage';
	document.navigation_form.value1.value = '';
	document.navigation_form.submit();
}

function editLanguage(languageid)
{
	document.navigation_form.mode.value = 'editlanguage';
	document.navigation_form.value1.value = languageid;
	document.navigation_form.submit();
}

function hideLanguage(languageid)
{
	document.navigation_form.mode.value = 'hidelanguage';
	document.navigation_form.value1.value = languageid;
	document.navigation_form.submit();
}

function showLanguage(languageid)
{
	document.navigation_form.mode.value = 'showlanguage';
	document.navigation_form.value1.value = languageid;
	document.navigation_form.submit();
}


// ----------------------------------------------------------------------------------------------------------------------

function manageImages(id)
{
	document.navigation_form.mode.value = 'manageimages';
	document.navigation_form.value1.value = 'height';
	document.navigation_form.value2.value = 'asc';
	document.navigation_form.submit();
}

function manageImages_sort(sort_order, param)
{
	document.navigation_form.mode.value = 'manageimages';
	document.navigation_form.value1.value = sort_order;
	document.navigation_form.value2.value = param;
	document.navigation_form.submit();
}

function manageImages_page(page)
{
	document.navigation_form.mode.value = 'manageimages';
	document.navigation_form.value3.value = page;
	document.navigation_form.submit();
}

function manageImages_properties(filename, width, height)
{
	window.open('manageimages_properties.php?filename='+filename+'&width='+width+'&height='+height,'properties','location=no,menubar=no,scrollbars=yes,status=no,width='+width+',height='+height);
}

function manageImages_upload()
{
	width = 400;
	height = 200;
	window.open('manageimages_upload.php','upload','location=no,menubar=no,scrollbars=yes,status=no,width='+width+',height='+height);
}

// ----------------------------------------------------------------------------------------------------------------------

function manageDownloads(id)
{
	document.navigation_form.mode.value = 'managedownloads';
	document.navigation_form.value1.value = '';
	document.navigation_form.value2.value = 'asc';
	document.navigation_form.submit();
}

function manageDownloads_sort(sort_order, param)
{
	document.navigation_form.mode.value = 'managedownloads';
	document.navigation_form.value1.value = sort_order;
	document.navigation_form.value2.value = param;
	document.navigation_form.submit();
}

function manageDownloads_page(page)
{
	document.navigation_form.mode.value = 'managedownloads';
	document.navigation_form.value3.value = page;
	document.navigation_form.submit();
}

function manageDownloads_properties(filename, width, height)
{
	window.open('managedownloads_properties.php?filename='+filename+'&width='+width+'&height='+height,'properties','location=no,menubar=no,scrollbars=yes,status=no,width='+width+',height='+height);
}

function manageDownloads_upload()
{
	width = 400;
	height = 200;
	window.open('managedownloads_upload.php','upload','location=no,menubar=no,scrollbars=yes,status=no,width='+width+',height='+height);
}

// ----------------------------------------------------------------------------------------------------------------------

function manageNews()
{
	document.navigation_form.mode.value = 'managenews';
	document.navigation_form.submit();
}

function saveNews()
{
	document.editContent_form.save.value = "yes";
	document.editContent_form.onsubmit();			// workaround browser bugs.
	document.editContent_form.submit();
}

function onPreview()
{
	var f_url = document.getElementById("f_url");
	var url = f_url.value;
	if (!url)
	{
		alert("You have to enter an URL first");
		f_url.focus();
		return false;
	}
	window.ipreview.location.replace(url);
	return false;
};

function hideShowMenus()
{
	if (browserType == "gecko" )
		document.poppedLayer = eval('document.getElementById(\'showmenus_div\')');
	else if (browserType == "ie")
		document.poppedLayer = eval('document.all[\'showmenus_div\']');
	else
		document.poppedLayer = eval('document.layers[\'`showmenus_div\']');
	document.poppedLayer.style.visibility = "hidden";
}

function showShowMenus()
{
	if (browserType == "gecko" )
		document.poppedLayer = eval('document.getElementById(\'showmenus_div\')');
	else if (browserType == "ie")
		document.poppedLayer = eval('document.all[\'showmenus_div\']');
	else
		document.poppedLayer = eval('document.layers[\'`showmenus_div\']');
	document.poppedLayer.style.visibility = "visible";
}

function textonly(param)
{
	document.navigation_form.textonly.value = param;
	document.navigation_form.submit();
}

function sitemap()
{
	document.navigation_form.mode.value = 'sitemap';
	document.navigation_form.submit();
}
