//// FONT SIZE CHANGER by O.G and otherz ////

// If you want to use the automatic fontsize changing by the cookie, you
// have to call this .js file after your 'classes are outputed'.

// Wrong:
// <html><body>
// <javascript src="fontsizechanger.js"></script>
// <font class="myclass">text</font>
// </body></html>
//
// Right:
// <html><body>
// <font class="myclass">text</font>
// <javascript src="fontsizechanger.js"></script>
// </body></html>

var fontsizes     = new Array("hirszoveg_0", "hirszoveg_1", "hirszoveg_2");
var fontsizes_cim = new Array("hircim_0",    "hircim_1",    "hircim_2");
var fontindex     = 0;
var cookieName    = "sztfontcookie";

function getElementsByClassName(ClassName,tagName,parentElement){
	var elements=new Array();
	if (parentElement) {
		var d = parentElement;
	} else {
		var d = document;
	}
	var allElements;

	if (tagName) allElements = d.all && d.all.tags(tagName) || d.getElementsByTagName && d.getElementsByTagName(tagName);
	else {
		if (parentElement) {
			allElements = d.getElementsByTagName("*");
		} else {
			allElements = d.getElementsByTagName("*");
			// d.all
		}
	}

	for (var i=0,len=allElements.length; i<len; i++) {
		if (allElements[i].className==ClassName) {
			elements[elements.length] = allElements[i];
		}
	}
	return elements;
}

function changeIt() { // Nem hasznaljuk :)
	if (!document.styleSheets) return;
	var theRules = new Array();
	if (document.styleSheets[1].cssRules)
		theRules = document.styleSheets[1].cssRules
	else if (document.styleSheets[1].rules)
		theRules = document.styleSheets[1].rules
	else return;
	theRules[theRules.length-1].style.backgroundColor = 'transparent';
}

function changefontsize(oldclass, newclass) {

	elements = getElementsByClassName(oldclass,"","");

	for (i=0; i < elements.length; i++) {

		elements[i]["className"] = newclass;

		// Object properties (some)
		// className = "textclass" // the name of the class
		// title = ""
		// runtimeStyle = ??
		// style = [object]
		// isDisabled = ???
		// disabled = false
		// all = object
		// sourceIndex (48)
		// attributes = [object]

		//megmutatja az object 'elemeit' (hosszu lista)
		//for (prop in elements[i]) {
		//	alert(prop + " = " + elements[i][prop]);
		//}

		//elements[i].title = "hirszoveg";
		//elements[i].style.setProperty('fontSize','8 px', null);
		//elements[i].style.fontSize = "8 px";
		//elements[i].style.font-size = "8 px";

//		var x = elements[i];
//		styleProp = "font-size";
//		if (window.getComputedStyle) {
//			// ez leginkabb Mozilla-val muxik :)
//			var y = window.getComputedStyle(x,null).getPropertyValue("font-size");
//
//			x = document.getElementById('hirszoveg');
//
//			x.style.setProperty('fontSize', '6');
//			//x.style.setProperty('color', '#440055', null);
//
//		} else if (x.currentStyle) {
//			var y = eval('x.currentStyle.' + styleProp);
//		}
	}
}
    
function incfontsize() {
	if (fontindex+1 < fontsizes.length) {
		o = fontindex;
		n = ++fontindex;
		changefontsize(fontsizes[o], fontsizes[n]);
		changefontsize(fontsizes_cim[o], fontsizes_cim[n]);
		SetCookie(cookieName, n, exp);
	}
}
  
function decfontsize() {
	if (fontindex-1 >= 0) {
		o = fontindex;
		n = --fontindex;
		changefontsize(fontsizes[o], fontsizes[n]);
		changefontsize(fontsizes_cim[o], fontsizes_cim[n]);
		SetCookie(cookieName, n, exp);
	}
}


///// COOKIE PART /////

var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function SetCookie (name, value) {
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = "/";
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
}

function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1) endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}
	return null;
}

var cookieValue = GetCookie(cookieName);

if (cookieValue != null) {
	if (cookieValue >= 0 && cookieValue < fontsizes.length) {
		fontindex = cookieValue;
		o = 0;
		n = fontindex;
		changefontsize(fontsizes[o], fontsizes[n]);
		changefontsize(fontsizes_cim[o], fontsizes_cim[n]);
	}
}
