var timeOutID;
var menuStyle;
var menuHideID;
var linkStyle;
var linkHideID;

function menuDropDown(menuID, linkID, mouseover) 
{
	if (menuID != menuHideID){
		if (menuHideID) {
			menuStyle.display	= 'none';
			linkStyle.backgroundImage = 'url(\'../img/nav_main_but_' + linkHideID + '.gif\')';
		}
		linkHideID	= linkID;
		menuHideID	= menuID;
	}	
	
	var linkElem	= document.getElementById('level_' + linkID);
	linkStyle		= linkElem.style;
	var menuElem	= document.getElementById(menuID);
	menuStyle		= menuElem.style;
	
	if (mouseover){
		menuStyle.display 	= 'block';
		linkStyle.backgroundImage = 'none';
		clearTimeout(timeOutID);
	} else {
		timeOutID 	= setTimeout("menuStyle.display	= 'none';linkStyle.backgroundImage	= 'url(/img/nav_main_but_" + linkHideID + ".gif)';", 500);
	}
}


function clearMenu() 
{
	if (linkHideID){
		if (menuHideID) {
			
			var linkElem	= document.getElementById('level_' + linkHideID);
			linkStyle		= linkElem.style;
			var menuElem	= document.getElementById(menuHideID);
			menuStyle		= menuElem.style;
			menuStyle.display			= 'none';
			linkStyle.backgroundImage	= 'url(\'../img/nav_main_but_' + linkHideID + '.gif\')';
		}
	}
		
}


// The Ajax to PHP function
function doAjax(actionID, queryString, returnID, doFunctie) {
	var ajaxRequest;  // The variable that makes Ajax possible!
	//var host	= 'http://production.jungleminds.nl/';
	var host	= 'http://www.jungleminds.com/';
	
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e){
			try {
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				return false;
			}
		}
	}
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if (ajaxRequest.readyState == 4){
			//if (actionID == 'rate') {
			//	rateResponse(4);
			//}		
			if (ajaxRequest.responseText && returnID){
				if (doFunctie)
					setTimeout(doFunctie, 0);
				
				document.getElementById(returnID).innerHTML = ajaxRequest.responseText;
			}
			
		}
	}
	
	ajaxRequest.open('GET', host + 'ajax.php?actionID=' + actionID + '&' + queryString, true);
	ajaxRequest.send(null);
	
	return false;
}

// Change the image validation image
function createImg(lastID, charCount, firstChars, lastChars, imgFolder)
{
	num	= Math.random();
	num	= num.toString();
	num	= num.substr(firstChars.length, num.length);
	num	= firstChars + num + lastChars;
	
	document.getElementById('img' + lastID).src		= imgFolder + 'imageValidation.php?validText=' + num;
	document.getElementById('hid' + lastID).value	= num.substr(0, Number(charCount + firstChars.length + lastChars.length));
	
	return false;
}

// Function to submit a form with onclick or onchangle
function submitForm(frmID) {
	document.getElementById(frmID).submit();
}


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';
}


function toggleLayerFilter( whichLayer, wichLink ) {
	  var elem, vis, linkelem, linkClass;
	  
	  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';
	  
  	  if( document.getElementById ) // this is the way the standards work
	    linkelem = document.getElementById( wichLink );
	  else if( document.all ) // this is the way old msie versions work
	      linkelem = document.all[wichLink];
	  else if( document.layers ) // this is the way nn4 works
	    linkelem = document.layers[wichLink];
		
		linkClass = linkelem.className; 
		
	 	if(linkClass == 'orange_down') { 
			linkelem.className = 'orange_right';
		}else if(linkClass == 'orange_right') {
			linkelem.className = 'orange_down';
		}else if(linkClass == 'blue_down') {
			linkelem.className = 'blue_right';
		}else if(linkClass == 'blue_right') {
			linkelem.className = 'blue_down';
		}
	 }

// Remove word from an input field
function searchTekst(id, standaardWaarde, hide) 
{
	var element = document.getElementById(id);
	
	//focus op tekstbox met standaardtekst > verwijder standaardtekst
	if (hide && element.value == standaardWaarde) {
		element.value = '';
		document.getElementById('form_search_submit').style.backgroundPosition = 'top';
		document.getElementById('form_search_input').style.backgroundPosition = 'top left';
		document.getElementById('form_search_input').style.borderColor = '#5699ca';
		document.getElementById('form_search_input').style.color = '#333333';
	}
	//blur uit leeg tekstbox > ivt standaardtekst toevoegen
	else if (!hide && element.value == '') {
		element.value = standaardWaarde;
		document.getElementById('form_search_submit').style.backgroundPosition = 'bottom';
		document.getElementById('form_search_input').style.backgroundPosition = 'bottom left';
		document.getElementById('form_search_input').style.borderColor = '#666666';
		document.getElementById('form_search_input').style.color = '#666666';
	}
	
	return false;
}

// Remove word from an input field
function nbTekst(id, standaardWaarde, hide) 
{
	var element = document.getElementById(id);
	
	//focus op tekstbox met standaardtekst > verwijder standaardtekst
	if (hide && element.value == standaardWaarde) {
		element.value = '';
		document.getElementById('form_nb_submit').style.backgroundPosition = 'top';
		document.getElementById('email_field').style.backgroundPosition = 'top left';
		document.getElementById('email_field').style.borderColor = '#5699ca';
		document.getElementById('email_field').style.color = '#333333';
	}
	//blur uit leeg tekstbox > ivt standaardtekst toevoegen
	else if (!hide && element.value == '') {
		element.value = standaardWaarde;
		document.getElementById('form_nb_submit').style.backgroundPosition = 'bottom';
		document.getElementById('email_field').style.backgroundPosition = 'bottom left';
		document.getElementById('email_field').style.borderColor = '#666666';
		document.getElementById('email_field').style.color = '#666666';
	}
	
	return false;
}

// Remove word from an input field
function hideTekst(id, standaardWaarde, hide) 
{
	var element = document.getElementById(id);
	
	//focus op tekstbox met standaardtekst > verwijder standaardtekst
	if (hide && element.value == standaardWaarde) {
		element.value = '';
	}
	//blur uit leeg tekstbox > ivt standaardtekst toevoegen
	else if (!hide && element.value == '') {
		element.value = standaardWaarde;
	}
	
	return false;
}

// Color a field when pressed
function textboxFocus(id, isFocus) 
{
	var element = document.getElementById(id);
	
	if (isFocus) {
		element.style.backgroundColor = '#fafafa';
		element.style.borderColor = '#575757';
	}else{
		element.style.backgroundColor = '#ffffff';
		element.style.borderColor = '#4892c7';
	}
}

function openWindow(naarPagina, width, height, location)
{
	if (!width)
		width		= 650;
	
	if (!height)
		height		= 580;
	
	if (!location)
		location	= 1;
	
	w = window.open(naarPagina, '', 'top=0,left=0,width=' + width + ',height=' + height + ',location=' + location + ',status=0,menubar=1,directories=0,toolbar=0,resizable=0,scrollbars=1');
	w.focus();
	
	return false;
}

// JavaScript Document
function switchLayer(layerID, Lnum)
{
	for (var i = 1; i < Lnum;){
		var targetLayer 	= document.getElementById('layer_' + i);
		var targetLayerLink = document.getElementById('layerLink_' + i);
		if(targetLayer.style.display == 'block') {				
			targetLayer.style.display	= 'none';
		}
		if(targetLayerLink.className  == 'active') {				
			targetLayerLink.className 	= 'regular';
		}
		i++;	
	}
	
	var displayLayer				= document.getElementById('layer_' + layerID);
	displayLayer.style.display		= 'block';
		
	var displayLayerLink 			= document.getElementById('layerLink_' + layerID);
	displayLayerLink.className 		= 'active';
	
}

// Used for the stars rating system (onmouseover, onmouseout)
function starsOver(starID, totalScore, over)
{
	var i;
	var starImg		= new Object();
	var imgRoot		= 'img/stars/';
	var starFile	= '';
	var checkScore	= 0;
	var fileExtend	= '';
	var beoordelingen		= new Array('Niks', 'Redelijk', 'OK', 'Goed', 'Top');
	
	if (over){
		fileExtend	= '_over';
	}else{
		var fileExtend	= '';		
	}
	
	for (i = 1; i <= starID; ++i){
		starImg 	= document.getElementById('star_' + i);
		
		if (starImg.src.indexOf('filled') > 0)
			starImg.src = imgRoot + 'star_filled' + fileExtend + '.gif';
		else
			starImg.src = imgRoot + 'star_empty' + fileExtend + '.gif';
	}

	document.getElementById('showRate').innerHTML = beoordelingen[starID-1];
}

// For the starts rate
function rateResponse(ajResponse)
{		
	var ajaxDisplay1		= document.getElementById('actionTitle');
	ajaxDisplay1.innerHTML	= 'Bedankt voor uw beoordeling';


	var i = 0;
	var starImg		= new Object();
	var imgRoot		= 'img/stars/';
	var starFile	= '';
	var beoordelingen		= new Array('Niks', 'Redelijk', 'OK', 'Goed', 'Top');

	
	for (i = 1; i <= ajResponse; i++){
		starImg 				= document.getElementById('star_' + i);
		starImg.src 			= imgRoot + 'star_filled.gif';
		starImg.onclick			= '';
		starImg.onmouseover		= '';
		starImg.onmouseout		= '';
		starImg.style.cursor	= 'auto';
		alert(starImg.src);
	}
	
	for (i; i < 6; i++){
		starImg 				= document.getElementById('star_' + i);
		starImg.src 			= imgRoot + 'star_empty.gif';
		starImg.onclick			= '';
		starImg.onmouseover		= '';
		starImg.onmouseout		= '';
		starImg.style.cursor	= 'auto';
		alert(starImg.src);
	}

	
	document.getElementById('showRate').innerHTML		= beoordelingen[ajResponse];
	document.getElementById('rateCount').innerHTML		= Number(document.getElementById('rateCount').innerHTML) + 1;
	document.getElementById('myrateCount').innerHTML	= '[Mijn beoordeling: ' + beoordelingen[ajResponse] +']';
}

function reactieComment(id, title) 
{
	var targetInput = document.getElementById('type');
	var targetHeader = document.getElementById('reactionHeader');
	targetInput.value = id;
	targetHeader.innerHTML = 'Reactie op ' + title;
	targetHeader.style.display = 'block';
}
