﻿function loadstuff(type) {
	
	var external	= getElementsByClassName(document, 'a', 'external');
	var colbox		= getElementsByClassName(document, 'input', 'color');
	var help		= getElementsByClassName(document, 'a', 'help');
	var helpbox		= getElementsByClassName(document, 'li', 'helpbox');
	var allhelp		= document.getElementById('allhelp');


	if (type == 'cms') {
		if(allhelp) {
			allhelp.href = '#';
			allhelp.title = 'show all help';
			allhelp.onclick = function() {
		        this.title = this.title=='show all help' ? 'hide all help' : 'show all help';
		        this.innerHTML = this.title=='hide all help' ? 'hide all help' : 'show all help';
				for(var i = 0; i < helpbox.length; i++) {
					helpbox[i].style.display = this.title=='hide all help' ? 'block' : 'none';
				}
				return false;
			};
		}
	
		if(help) {
			for(var i = 0; i < help.length; i++) {
				help[i].href = '#';
				help[i].title = 'show help';
				var bfhlp = help[i].id + 'box';
				bfhlpbox = document.getElementById(bfhlp);
				bfhlpbox.style.display = 'none';
				help[i].onclick = function() {
					var hlp = this.id + 'box';
					hlpbox = document.getElementById(hlp);
					hlpbox.style.display = hlpbox.style.display=='none' ? 'block' : 'none';
			        this.title = this.title=='show help' ? 'hide help' : 'show help';
					return false;
				};
			}
		}
	} else {
		if(allhelp) {
			allhelp.href = '#';
			allhelp.title = 'Show All Help';
			allhelp.onclick = function() {
		        this.title = this.title=='Show All Help' ? 'Hide All Help' : 'Show All Help';
		        this.innerHTML = this.title=='Hide All Help' ? 'Hide All Help' : 'Show All Help';
				for(var i = 0; i < helpbox.length; i++) {
					helpbox[i].style.display = this.title=='Hide All Help' ? 'block' : 'none';
				}
				return false;
			};
		}
	
		if(help) {
			for(var i = 0; i < help.length; i++) {
				help[i].href = '#';
				help[i].title = 'Show Help';
				var bfhlp = help[i].id + 'box';
				bfhlpbox = document.getElementById(bfhlp);
				bfhlpbox.style.display = 'none';
				help[i].onclick = function() {
					var hlp = this.id + 'box';
					hlpbox = document.getElementById(hlp);
					hlpbox.style.display = hlpbox.style.display=='none' ? 'block' : 'none';
			        this.title = this.title=='Show Help' ? 'Hide Help' : 'Show Help';
					return false;
				};
			}
		}
	}

	if(colbox) {
		for(var i = 0; i < colbox.length; i++) {
			if(colbox[i].id=='textcolour') {
				colbox[i].onchange = function() {
					document.getElementById("wysiwygIframe").contentWindow.document.body.style.color = this.value;
				};
			}
			if(colbox[i].id=='backcolour') {
				colbox[i].onchange = function() {
					document.getElementById("wysiwygIframe").contentWindow.document.body.style.backgroundColor = this.value;
				};
			}
		}
	}

	if(external) {
		for(var i = 0; i < external.length; i++) {
			var extlink = external[i];
			extlink.target = "_blank";
		}
	}

}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + '=');
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(';',c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return '';
}

function delCookie(c_name) {
	document.cookie = c_name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;path=/;';
}

function hideDrops() {
	var drops = document.getElementsByTagName('select');
	for (i = 0; i < drops.length; i++) {
		drops[i].style.display = 'none';
	// or
	// drops[i].style.visibility = 'hidden'
	}
}

function showDrops() {
	var drops = document.getElementsByTagName('select');
	for (i = 0; i < drops.length; i++) {
		drops[i].style.display = 'inline';
	// or
	// drops[i].style.visibility = 'visible'
	}
}

/* onload functions */

function startup(type) {
	loadstuff(type);
}

