/* Main Frameless Frameset code */
function localiseStyles(){
	if(document.getElementById){
		if(document.styleSheets != null && document.styleSheets.length != 0){
			var PageStyles = document.styleSheets[1];
			if(PageStyles.deleteRule){ // W3C, Moz, IE5Mac
				PageStyles.deleteRule(1);
				PageStyles.insertRule('@import url("Styles/'+currentPage+'.css");', PageStyles.cssRules.length);
			}else if(PageStyles.imports){ // IEWin
				PageStyles.imports[1].href = "Styles/"+currentPage+".css";
			}
		}else{ // Opera & any others
			var PageStyles = document.getElementById("GlobalStyles");
			if(window.opera && navigator.userAgent.search(/Opera[\s\/][7]/) != -1){
				var head = PageStyles.parentNode
				head.removeChild(PageStyles);
				head.innerHTML += '<style type="text/css" media="screen" id="GlobalStyles">@import url("Styles/Global.css"); @import url("Styles/'+currentPage+'.css");</style>';
			}
			PageStyles.innerHTML = '@import url("Styles/Global.css"); @import url("Styles/'+currentPage+'.css");'
		}
	}
}
function init(){
	// Iterate through document links and replace with new code if target is not found
	
	// Using innerHTML instead of DOM 2 because IE doesn't
	// recognize setAttribute("id".. for an iframe???
	if(document.body.innerHTML){
		document.body.innerHTML += '<iframe id="ifrContent" name="ifrContent" frameborder="0" onload="changeDocument()" src="about:blank"></iframe>';
	}
	// Need this because IE5.0 has no onLoad or onReadyStateChange event
	if(navigator.userAgent.indexOf("MSIE 5.0")!=-1&&!window.opera){ // IE5
		window.ifrContentURL = false;
		ifrTimer = setInterval("checkFrameSrc()", 500);
	}
	window.content = document.getElementById("Content");
	window.subNav = document.getElementById("SubNav");
	window.ifrContent = document.getElementById("ifrContent");
	//linkFrame("defaultStretch")
}
function checkFrameSrc(){
	if(ifrContentURL != document.frames["ifrContent"].document.URL){
		var tmpURL = ifrContentURL;
		window.ifrContentURL = document.frames["ifrContent"].document.URL;
		if(tmpURL) 
			changeDocument();
	}
}
function changeDocument(){
	window.ifrContentDoc = (ifrContent.contentDocument) ? ifrContent.contentDocument : (ifrContent.contentWindow) ? ifrContent.contentWindow.document : (document.frames["ifrContent"].document != document) ? document.frames["ifrContent"].document : null;
	localiseStyles();
	// Update Page Title
	document.title = ifrContentDoc.title;
	// Update Page Content
	content.innerHTML = ifrContentDoc.getElementById("Content").innerHTML;
	subNav.innerHTML = ifrContentDoc.getElementById("SubNav").innerHTML;
}
function linkFrame(page){
	window.currentPage = page;
	ifrContent.src = page+".aspx?content=true";
	return false;
}

/* Utility functions for use with IE7 */
function addClass(element, className) {
    if (!hasClass(element, className)) {
        if (element.className) element.className += " " + className;
        else element.className = className;
    }
};

function removeClass(element, className) {
    var regexp = new RegExp("(^|\\s)" + className + "(\\s|$)");
    element.className = element.className.replace(regexp, "$2");
};

function hasClass(element, className) {
    var regexp = new RegExp("(^|\\s)" + className + "(\\s|$)");
    return regexp.test(element.className);
};
/* Form Scripts */
function focusFormElement(){
	if(this.value == this.defaultValue){
		this.value = "";
	}
}
function blurFormElement(){
	if(this.value == ""){
		this.value = this.defaultValue;
	}
}
function addFormEvents(){
	var arrForms = document.getElementsByTagName("FORM"), arrElements, form, element;
	for(var f = 0; f < arrForms.length; ++f){
		form = arrForms[f];
		arrElements = form.elements;
		for(var e = 0; e < arrElements.length; ++e){
			element = arrElements[e];
			if(element.type && element.type.indexOf("text") != -1){
				element.onfocus = focusFormElement;
				element.onblur = blurFormElement;
			}
		}
	}
}
/* End form Scripts */
/* Fix IE anchor scrolling problem */
function pageToTop(){
		setTimeout("window.scrollTo(0,0)", 50);
}
function addAnchorEvents(){
	if(document.links && window.scrollTo){
		var arrAnchors = document.links;
		for(var a = 0; a < arrAnchors.length; ++a){
			if(arrAnchors[a].hash){
				arrAnchors[a].onclick = pageToTop;
			}
		}
	}
}
/* Enable IE dropmenus */
sfHover = function(){
	if(document.getElementById){
		var sfEl = (document.getElementById("Nav")) ? document.getElementById("Nav") : document.getElementById("NavMain");
		var sfEls = sfEl.getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
/* Statistics Tracking */
function OneStat_Pageview(){
	var d=document;
	document.getElementById("OneStat").innerHTML = "Statistics";
	if(location.href.indexOf("karunaretreats.com") != -1){
		var sid="190011";
		var CONTENTSECTION="";
		var CUSTOMDATA="";
		var osp_URL=d.URL;
		var osp_Title=d.title;
		var t=new Date();
		var p="http"+(d.URL.indexOf('https:')==0?'s':'')+"://stat.onestat.com/stat.aspx?tagver=2&sid="+sid;
		p+="&url="+escape(osp_URL);
		p+="&ti="+escape(osp_Title);
		p+="&section="+escape(CONTENTSECTION);
		p+="&custom="+escape(CUSTOMDATA);
		p+="&rf="+escape(parent==self?window.document.referrer:top.document.referrer);
		p+="&tz="+escape(t.getTimezoneOffset());
		p+="&ch="+escape(t.getHours());
		p+="&js=1";
		p+="&ul="+escape(navigator.appName=="Netscape"?navigator.language:navigator.userLanguage);
		if(typeof(screen)=="object"){
			p+="&sr="+screen.width+"x"+screen.height;p+="&cd="+screen.colorDepth;
			p+="&jo="+(navigator.javaEnabled()?"Yes":"No");
		}
		document.getElementById("OneStat").innerHTML = '<a href="http://www.onestat.com/aspx/login.aspx?sid='+sid+'" target=_blank><img id="ONESTAT_TAG" border="0" src="'+p+'" alt="This Site Tracked by OneStat.com">OneStat</a>';
	}
}
function replaceLinks(){
	if(document.links){
		var arrAnchors = document.links;
		for(var a = 0; a < arrAnchors.length; ++a){
			if(arrAnchors[a].className && arrAnchors[a].target == "_blank"){
				arrAnchors[a].onclick = function(){
					window.open(this.href, "karunaWin", "toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,width=640,height=480,top="+(screen.availHeight/2-240)+",left="+(screen.availWidth/2-320));
					return false;
				};
			}
		}
	}

}
/* Initiate Scripts */
arrLoadFunctions = [];
function addLoadFunction(){
	for(var i = 0; i < arguments.length; ++i){
		arrLoadFunctions[arrLoadFunctions.length] = arguments[i];
	}
}
addLoadFunction(replaceLinks, addFormEvents, OneStat_Pageview);
function initiate(){
	for(var i = 0; i < arrLoadFunctions.length; ++i){
		arrLoadFunctions[i]();
	}
	if(document.all && window.attachEvent){
		addAnchorEvents();
		sfHover();
	}
}
window.onload = initiate;




/* bookmarksite script © Dynamic Drive DHTML code library http://www.dynamicdrive.com */

function bookmarksite(title,url){
if (window.sidebar)window.sidebar.addPanel(title, url, ""); // firefox
else if(window.opera && window.print){
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)window.external.AddFavorite(url, title);
else alert("Sorry, this browser doesn\'t support this bookmarking script. Please use the browser's bookmark/favourites menu or button, or try the keyboard keys \"Ctrl\" and \"D\" simultaneously.")
}
