// from:
// http://www.white-hat-web-design.co.uk/articles/js-fontsize.php
var rsJQ = null;
var minFont=10;
var maxFont=22;
function increaseFontSize(theSize) {
	var p = document.getElementsByTagName('div');
	for(i=0;i<p.length;i++) {
		if((p[i].className == "postContent" || p[i].className == "postContainer" || p[i].className == "postComments" || p[i].className.indexOf("faqcontainer")!=-1 || p[i].className == "downloadContainer" || p[i].className == "downloadCategory")) {
			for(j=0;j<p[i].childNodes.length;j++) {
			 	var child = p[i].childNodes[j];
				if(child.style && child.className != 'postFacts' && child.className != 'page-numbers') {
					if(child.style.fontSize) {
						var s = parseInt(child.style.fontSize.replace("px",""),10);
					} else {
					  	var s = 12;
					}
					if(s!=maxFont && theSize==null) {
						s += 1;
					} else s = parseInt(theSize,10);
					child.style.fontSize = s+"px"
					saveFontSize(s);
				}
			}			
		}
	}
}
function decreaseFontSize() {
	var p = document.getElementsByTagName('div');
	for(i=0;i<p.length;i++) {
		if((p[i].className == "postContent" || p[i].className == "postContainer" || p[i].className == "postComments" || p[i].className.indexOf("faqcontainer")!=-1 || p[i].className == "downloadContainer" || p[i].className == "downloadCategory")) {
			for(j=0;j<p[i].childNodes.length;j++) {
			 	var child = p[i].childNodes[j];
				if(child.style && child.className != 'postFacts' && child.className != 'page-numbers') {
					if(child.style.fontSize) {
						var s = parseInt(child.style.fontSize.replace("px",""));
				    } else {
				        var s = 12;
				    }
				    if(s!=minFont) {
				        s -= 1;
				    }
					child.style.fontSize = s+"px"
					saveFontSize(s);
				}
			}			
		}
	}
}
function setFontSize() 
{
	if(rsJQ.cookie('AirPlusFontCookie')) {
		increaseFontSize(rsJQ.cookie('AirPlusFontCookie'));
	}
}
function saveFontSize(mysize)
{
	rsJQ.cookie('AirPlusFontCookie', mysize, { expires: 7, path: '/' });
}

function hideAltPosition()
{
	document.getElementById("divRSAltPosition").style.display = "none";
	document.getElementById("rsAltPosition").value = "";
}

function showAltPosition()
{
	var selectPos = document.getElementById("rsPosition");
	document.getElementById("rsPositionIdx").value = selectPos.selectedIndex;
	if(selectPos.options[selectPos.selectedIndex].value == "Other") {
		document.getElementById("divRSAltPosition").style.display = "block";
	} else hideAltPosition(); 
}

function showSearch(status)
{
	var obj = document.getElementById("divSearch");
	var aObj = document.getElementById("searchLink");
	if(status==1) {
		aObj.className = "searchActive"; 
		obj.style.display = "block"; 
    	obj.style.zIndex = 3;
		if(document.getElementById("s").value=="") document.getElementById("s").value="Search item";
	} else {
		aObj.className = "btnSearch"; 
		obj.style.display = "none"; 
	} 
}
function rayAddEvent(elm, evType, fn, useCapture)
{
	if (elm.addEventListener)
	{
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent)
	{
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else
	{
		elm['on' + evType] = fn;
	}
}
function rsCheckComment()
{
	var f = document.commentform;
	if(document.getElementById("author")) {
		if(document.getElementById("author").value=='') {
			alert("Please enter your name."); 
			document.getElementById("author").focus();
			return;
		}
	}
	if(document.getElementById("email")) {
		if(document.getElementById("email").value=='') {
			alert("Please enter your e-mail address."); 
			return;
		} else {
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(document.getElementById("email").value)) {
				alert("Please provide a valid e-mail address.");
				document.getElementById("email").focus();
				return;
			}
		}
	}
	if(document.getElementById("securitycode")) {
		if(document.getElementById("securitycode").value=='') {
			alert("Please enter the security code."); 
			document.getElementById("securitycode").focus();
			return;
		}
	}
	var inst = tinyMCE.getInstanceById("comment");
	if(inst.getContent().length<15) {
		alert("Your comment must be at least 15 characters."); 
		return;
	} else document.getElementById("comment").value = inst.getContent();
	f.submit();
}
function rsCheckPost(myState)
{
	var f = document.tdomf_form1;
	if(document.getElementById("whoami_name")) {
		if(document.getElementById("whoami_name").value=='') {
			alert("Please enter your name."); 
			document.getElementById("whoami_name").focus();
			return;
		}
	}
	if(document.getElementById("whoami_email")) {
		if(document.getElementById("whoami_email").value=='') {
			alert("Please enter your e-mail address."); 
			return;
		} else {
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(document.getElementById("whoami_email").value)) {
				alert("Please provide a valid e-mail address.");
				document.getElementById("whoami_email").focus();
				return;
			}
		}
	}
	if(document.getElementById("content_title")) {
		if(document.getElementById("content_title").value=='') {
			alert("Please enter the post title."); 
			document.getElementById("content_title").focus();
			return;
		}
	}
	var inst = tinyMCE.getInstanceById("content_content");
	if(inst.getContent().length<15) {
		alert("Your post must be at least 15 characters."); 
		return;
	}
	if(document.getElementById("imagecaptcha_1")) {
		if(document.getElementById("imagecaptcha_1").value=='') {
			alert("Please enter the security code."); 
			document.getElementById("imagecaptcha_1").focus();
			return;
		}
	}
	//if(myState=="preview") tdomfSubmit1('preview');
	//else tdomfSubmit1('post');
	f.submit();
}
function rsCheckAlternatingDiv()
{
	// downloads
	jQuery("div.downloadCategory:even").css("background-color", "#f2f2f2");
	jQuery("div.downloadCategory:odd").css("background-color", "#f6f6f6");
	jQuery("div.downloadContainer").find("div.downloadCategory:first").css("border-top","1px solid #999");
	// footer
	jQuery("ul#footerNavUL").find("a.footerNavNormal:first").css("background","transparent");
}
function rsCheckURL()
{
	var myLoc = window.location.search;
	if(myLoc.indexOf("e=1")!=-1) {
		alert("The security code you have entered is incorrect. Please try again.");
	}
	if(window.location.href.indexOf("#comment-")!=-1) {
		alert("Thank you for your comment! Your comment has been sent successfully and is awaiting approval.");
	}
	if(myLoc.indexOf("print=1")!=-1) {
		// remove links
		var anchors = document.getElementsByTagName("a");
		for(var i=0; i < anchors.length; i++){
			var a = anchors[i];
			var href = a.href;
			if (href.indexOf("javascript:window.print()")== -1)
			{
			    a.setAttribute("href","#",0);
			    a.setAttribute("target","",0);
			}	
		}
	}
}
function rsPrint() 
{
	var myLoc = window.location.search;
	if(myLoc.indexOf("?")!=-1) printWin = window.open(window.location+"&print=1", "Print", "width=530,height=600,left=100,top=200,scrollbars=yes");
	else printWin = window.open(window.location+"?print=1", "Print", "width=530,height=600,left=100,top=200,scrollbars=yes");
 	return;
}
function init() 
{
	rsJQ = jQuery.noConflict();
	setFontSize();
	rsCheckAlternatingDiv();
	rsCheckURL();
}

//try {
	//document.execCommand("BackgroundImageCache", false, true);
//} catch(err) {}

rayAddEvent(window, 'load', init, false);