if (top!=self.parent)
top.location=self.parent.location; 

var inc=0;

function sendTestEmail() {
	if (xmlhttp.readyState!=0 && xmlhttp.readyState!=4) {
		setTimeout("sendTest",250);
		return;
	}
	var email=document.getElementById('testemail').value;
	var msgID=document.getElementById('msgID').value;

	inc=inc+1;
	var url = "http://"+document.location.host+"/knowledge-bank/lists/rlist.php?nolist=1&action=sendTest&testemail="+email+"&msgID="+msgID+"&inc="+inc;

	xmlhttp.open('GET', url); 
	xmlhttp.onreadystatechange = function() { 
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			if (xmlhttp.responseText==1){
				alert('Test message sent');
			} else {
				alert('Test message failed to send');
			}
			xmlhttp.onreadystatechange=function(){};
		} 
	} 
	xmlhttp.send(null); 
}

function loadTemplate() {
	if (!confirm('Loading a template will overwrite any changes you have not saved.  Continue?')) {
		return;
	}

	if (xmlhttp.readyState!=0 && xmlhttp.readyState!=4) {
		setTimeout("loadTemplate",250);
		return;
	}

 	tplateID=document.getElementById('template').options[document.getElementById('template').selectedIndex].value;

	var browser;
	//if (document.getElementById('contenttext___Frame').contentWindow.document.getElementById('eEditorArea').contentWindow.document.styleSheets[0].insertRule) browser='FF';
	if (FCKeditorAPI.GetInstance('contenttext').EditingArea.Document.styleSheets[0].insertRule) browser='FF';
	else browser='IE';

	inc=inc+1;
	var url = "http://"+document.location.host+"/knowledge-bank/lists/rlist.php?nolist=1&action=getTPlate&tplateID="+tplateID+"&browser="+browser+"&inc="+inc;

	xmlhttp.open('GET', url); 
	xmlhttp.onreadystatechange = function() { 
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var script =xmlhttp.responseText.indexOf('<style>');
		var stop =xmlhttp.responseText.indexOf('</style>');	
		
		var myref;
		if (stop) {
			var myref=FCKeditorAPI.GetInstance('contenttext').EditingArea.Document.styleSheets[0];
			if (myref.insertRule) {
				var len=myref.cssRules.length;
				for (var i=0;i<len;i++) myref.deleteRule(0);
				
				var css=xmlhttp.responseText.substring(script+7,stop);
				var rules=css.split('|');
				for (var i=0;i<rules.length;i++) {
					myref.insertRule(rules[i],i);
				}
			} else {

				var len=myref.rules.length;
				for (var i=0;i<len;i++) myref.removeRule(0);
				
				var css=xmlhttp.responseText.substring(script+7,stop);

				var rules=css.split('|');
				for (var i=0;i<rules.length;i++) {

					eval('myref.addRule('+rules[i]+')');
				}
			}
		//	eval(xmlhttp.responseText.substring(script+7,stop));
			stop=stop+8;
		}
		FCKeditorAPI.GetInstance('contenttext').EditingArea.Document.body.innerHTML=xmlhttp.responseText.substring(stop);
		
		} 
	} 
	xmlhttp.send(null); 

	document.getElementById('tplateID').value=tplateID;
}

function loadTerms() {
	if (!confirm('Loading default terms & conditions will overwrite any changes you have not saved.  Continue?')) {
		return;
	}

	if (xmlhttp.readyState!=0 && xmlhttp.readyState!=4) {
		setTimeout("loadTerms",250);
		return;
	}

	inc=inc+1;
	var url = "http://"+document.location.host+"/knowledge-bank/lists/rlist.php?nolist=1&action=getTerms&inc="+inc;

	xmlhttp.open('GET', url); 
	xmlhttp.onreadystatechange = function() { 
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

			document.getElementById('terms').value=xmlhttp.responseText;

		} 
	} 
	xmlhttp.send(null); 
}
var xmlhttp=false; 
/*@cc_on @*/ 
/*@if (@_jscript_version >= 5) 
// JScript gives us Conditional compilation, we can cope with old IE versions. 
// and security blocked creation of the objects. 
try { 
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
} catch (e) { 
	try { 
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	} catch (E) { 
		xmlhttp = false; 
	} 
} 
@end @*/ 
if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 
	xmlhttp = new XMLHttpRequest(); 
} 

function loadBtns() {
	if (navigator.appName && (navigator.appName.indexOf("Microsoft") >= 0)) {  // IE users only need apply

        // Get all the button items within the menu and apply onhover effects
        var lis=document.getElementsByTagName("INPUT");  
        for (i=0; i<lis.length; i++) {

            if(lis[i].type=="button" || lis[i].type=="submit"){
             	lis[i].onmouseover=function() {	
					this.style.cursor="hand";
                }
                lis[i].onmouseout=function() {                       
				this.style.cursor="pointer";
                }
            }
        }
    }
}

if (window.addEventListener){
	window.addEventListener("load", loadBtns, false);
} else if (window.attachEvent){
	window.attachEvent("onload", loadBtns);
} 

/* swap visibility of divs */
function swapDiv(show,hide) {
	document.getElementById(show).style.display='block';
	document.getElementById(hide).style.display='none';
	return false;
}

/* Tab manager */
function showTab(tabid,parentid) {
	var parent=document.getElementById(parentid+'container');
	var tab=parent.firstChild;

    while(tab){
		if (tab.className) tab.style.display='none';
		tab=tab.nextSibling;
    }
	document.getElementById(tabid).style.display='block';

	var parent=document.getElementById(parentid+'header');
	var tab=parent.firstChild;

    while(tab){
		if (tab.className) tab.className=tab.className.replace(/sel/g,"norm");
		tab=tab.nextSibling;
    }
	document.getElementById(tabid+'_h').className=document.getElementById(tabid+'_h').className.replace(/norm/g,"sel");
}
