function cleartext(id) {
	d = document.getElementById(id);
	d.value = '';
}


/*
// used to hide the thumbnail menu bars (covers the background image wih)
function changeColor(id, color) { 
element = document.getElementById(id); 
event.cancelBubble = true; 
element.style.background = color; 
*/

// used in the filemanager to select all checkboxes
function select_all(){
	var f;
	var i;
	var b;
	var state;

	f = document.theform;
	state = f.all.checked;

	for(i=0; i<f.length; i++){
		b = f.elements[i];

		// if(b.name.indexOf('sel') >= 0){ 
		if(b.type == 'checkbox' && b.name == 'sel[]' ){
			b.checked = state;
		}
	}
}

// used for the synonym manager to show hide edit boxes
function shownode(node){
		if (document.getElementById){
			if (document.getElementById(node).style.display == 'inline'){
				document.getElementById(node).style.display = 'none';
				document.getElementById('_'+node).style.display = 'inline';
			}else{
				document.getElementById(node).style.display = 'inline';
				document.getElementById('_'+node).style.display = 'none';
			}
		}
}

// tooltip functions
function showdiv(id){
	d = document.getElementById(id);
	if(!d) return;
	d.style.display = "block";
}

function hidediv(id){
	d = document.getElementById(id);
	if(!d) return;
	d.style.display = "none";
}




// used to toggle the 'More categories' of the Relevant categories box
function toggleLayer( whichLayer )
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if( vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined )
		vis.display = ( elem.offsetWidth != 0 && elem.offsetHeight != 0 ) ? 'block':'none';
	vis.display = ( vis.display == '' || vis.display == 'block' ) ? 'none':'block';
}

// used to toggle the 'More categories' of the Relevant categories box
function hideLayer( whichLayer )
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	if(elem){
		vis = elem.style;
		vis.display = 'none';
		}
}

// used to toggle the 'More categories' of the Relevant categories box
function showLayer( whichLayer )
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	if(elem){
		vis = elem.style;
		vis.display = 'block';
		}
}

// Clear default form value script- 
function clearText(theField){
	
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( theField );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[theField];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[theField];

	if(elem.value == 'Enter Keywords') elem.value = "";
} 

// Clear default form value script- 
function resetText(theField){
	
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( theField );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[theField];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[theField];

	elem.value = "";
} 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// scripts for treeview
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Close all folders and redirect to root
// called when the root of the tree is clicked (Textures)
function collapseTreeRedirect()
{
	// hide div with relevant categories
	// TODO: Hide the layer instead of toggle
	
	hideLayer('relevanttable');
	
	// clear text field
	resetText('searchtextfield');
	
	//hide all folders //
	window.parent.treeframe.clickOnNodeObj(window.parent.treeframe.foldersTree);
	//restore first level //
	window.parent.treeframe.clickOnNodeObj(window.parent.treeframe.foldersTree);
	window.parent.treeframe.highlightObjLink(window.parent.treeframe.foldersTree);
	
	window.parent.baseframe.location="textures.php?c=0&t=browse";
}

// Redirect
// Hides the <div> with the relevant categories and redirects the baseframe
function treeRedirect(newlocation)
{
	// hide div with relevant categories
	hideLayer('relevanttable');
	
	// clear text field
	resetText('searchtextfield');
	
	window.parent.baseframe.location=newlocation;
}

// Close all folders
function collapseTree()
{
	//restore first level
	window.parent.treeframe.clickOnNodeObj(window.parent.treeframe.foldersTree);
	// highlight first level
	window.parent.treeframe.highlightObjLink(window.parent.treeframe.foldersTree);
}

// Load a page as if a node on the tree was clicked (synchronize frames)
// (Highlights selection if highlight is available.)
// Also used when a folder is clicked in the content window to synch the tree

function loadSynchPage(linkID) 
{
	var folderObj;
	docObj = window.parent.treeframe.findObj(linkID);
	docObj.forceOpeningOfAncestorFolders();
	window.parent.treeframe.clickOnNodeObj(docObj); // open folder
	window.parent.treeframe.clickOnLink(linkID,docObj.link,'window'); 	
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Menus
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Contents for menu 1 (About)
var menu1=new Array()
menu1[0]='<a href="news.php" target="baseframe">News</a>'
menu1[1]='<a href="content.php?action=about" target="baseframe">About</a>'
menu1[3]='<a href="content.php?action=showcase" target="baseframe">Showcase</a>'
menu1[4]='<a href="contributors.php" target="baseframe">Photographers</a>'
menu1[5]='<a href="content.php?action=license" target="baseframe">License</a>'
menu1[6]='<a href="content.php?action=faq" target="baseframe">FAQ</a>'
menu1[7]='<a href="content.php?action=contact" target="baseframe">Contact</a>'

//Contents for menu 2 (Textures)
var menu2=new Array()
menu2[0]='<a href="textures.php" target="baseframe">Browse</a>'
menu2[1]='<a href="textures.php?t=latest" target="baseframe">Latest Textures</a>'
menu2[2]='<a href="advancedsearch.php" target="baseframe">Search Tips</a>'
menu2[3]='<a href="skies.php" target="_top">Panoramic Skies</a>'
// menu2[1]='<a href="content.php?action=searchbycolour" target="baseframe">Search by Colour</a>'

//Contents for menu 3 (Tutorials)
var menu3=new Array()
menu3[1]='<a href="content.php?action=tutorials" target="baseframe">Tutorials</a>'
		
var menuwidth='180px' //default menu width
var menubgcolor='#252b3b'  //menu bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes") document.onclick=hidemenu

