// Creates a new cookie
// Usage: fnCreateCookie('mycookie','N',365)
function fnCreateCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
}


// Reads a created cookie
// Usage: fnReadCookie('mycookie')
function fnReadCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


// Init Onload fontsize
function fnIniFontSize(){
	var strCookie = fnReadCookie('DevitecFontSize');
	if (strCookie){
		fnFontSize(strCookie);
	}
}


// Sets the fontsize
// Usage: fnFontSize('N')
function fnFontSize(size){

	var documentFontSize = "80%";
	var documentLineHeight = "1.7";

	if (typeof(size) === "undefined" || typeof(size) === "object"){
		alert(this.id);
	}

	if (size == "N"){
		documentFontSize = "80%";
		documentLineHeight = "1.7";
	}
	if (size == "L"){
		documentFontSize = "96%";
		documentLineHeight = "1.7";
	}
	if (size == "A"){
		documentFontSize = "103%";
		documentLineHeight = "1.7";
	}

	// Save settings
	fnCreateCookie("DevitecFontSize", size, 365);
	
	var oElement = document.getElementsByTagName("body")[0];
	if (oElement){
		oElement.style.fontSize = documentFontSize;
		//oElement.style.lineHeight = documentLineHeight;
	}
	
	return false;
}



// Adds custom events to objects
function addEvent(obj, evType, fn, useCapture){

	if (obj.addEventListener && 1 === 0){
		obj.addEventListener(evType, fn, useCapture);
		return true;
	}else if (obj.attachEvent && 1 === 0){
		var r = obj.attachEvent("on" + evType);
		return r;
	}else{
		// Try adding the old way
		obj.onclick = fn;
		return true;
	}
}


// Function to toggle the visibility of a single DIV-ID.
function fnToggleLayer(strLayer) {

	if(strLayer != '') {
		oDiv = document.getElementById(strLayer);

		// Find out if div is hidden or visible
		strClassnames = oDiv.className;
		rExp = /hidden/gi;
		strResults = strClassnames.search(rExp)

		// Remove any of the classes if present
		rExp = /visible|hidden/gi;
		strClassnames = strClassnames.replace(rExp, "")
		
		// Add the correct class depending on the first search
		if(strResults === -1){
			strClassnames = strClassnames + ' hidden';
		}else{
			strClassnames = strClassnames + ' visible';
		}

		oDiv.className = strClassnames;

		return false;
	}
}


