
var agt = navigator.userAgent.toLowerCase();
var agt_ver = parseInt(navigator.appVersion);
var is_mozilla = (navigator.product == "Gecko");
var is_opera = (agt.indexOf("opera") != -1);
var is_konqueror = (agt.indexOf("konqueror") != -1);
var is_webtv = (agt.indexOf("webtv") != -1);
var is_ie = ((agt.indexOf("msie") != -1) && (!is_opera) && (!is_webtv));
var is_netscape = ((agt.indexOf("compatible") == -1) && (agt.indexOf("mozilla") != -1) && (!is_opera) && (!is_webtv));
var is_win = (agt.indexOf("win" != -1));
var is_mac = (agt.indexOf("mac") != -1);

var B_open = 0;
var I_open = 0;
var U_open = 0;
var QUOTE_open = 0;
var CODE_open = 0;
var HTML_open = 0;

var bbtags   = new Array();

function stacksize(thearray) {
    for (i = 0 ; i < thearray.length; i++ ) {
        if ( (thearray[i] == "") || (thearray[i] == null) || (thearray == 'undefined') ) {
            return i;
        }
    }
    return thearray.length;
}

function pushstack(thearray, newval) {
    arraysize = stacksize(thearray);
    thearray[arraysize] = newval;
}

function popstack(thearray) {
    arraysize = stacksize(thearray);
    theval = thearray[arraysize - 1];
    delete thearray[arraysize - 1];
    return theval;
}

function closeall() {
    if (bbtags[0]) {
        while (bbtags[0]) {
            tagRemove = popstack(bbtags)
            document.editor.ta.value += "[/" + tagRemove + "]";
            if ( (tagRemove != 'FONT') && (tagRemove != 'SIZE') && (tagRemove != 'COLOR') ) { 
                eval("document.editor." + tagRemove + ".value = ' " + tagRemove + " '");
                eval(tagRemove + "_open = 0");
            }
        }
    }
    document.editor.tagcount.value = 0;
    bbtags = new Array();
    document.editor.ta.focus();
}


function add_code(NewCode) {
    document.editor.ta.value += NewCode;
    document.editor.ta.focus();
}

function alterfont(theval, thetag) {
    if (theval == 0)
        return;
    if(doInsert("[" + thetag + "=" + theval + "]", "[/" + thetag + "]", true))
        pushstack(bbtags, thetag);
    document.editor.ffont.selectedIndex  = 0;
    document.editor.fsize.selectedIndex  = 0;
    document.editor.fcolor.selectedIndex = 0;
}

function simpletag(thetag) {
    var tagOpen = eval(thetag + "_open");

    if (tagOpen == 0) {
        if(doInsert("[" + thetag + "]", "[/" + thetag + "]", true))
        {
            eval(thetag + "_open = 1");
            eval("document.editor." + thetag + ".value += '*'");

            pushstack(bbtags, thetag);
        }
    }
    else {
        // Find the last occurance of the opened tag
        lastindex = 0;

        for (i = 0 ; i < bbtags.length; i++ )
        {
            if ( bbtags[i] == thetag )
            {
                lastindex = i;
            }
        }

        // Close all tags opened up to that tag was opened
        while (bbtags[lastindex])
        {
            tagRemove = popstack(bbtags);
            doInsert("[/" + tagRemove + "]", "", false);
            if ( (tagRemove != 'FONT') && (tagRemove != 'SIZE') && (tagRemove != 'COLOR') ) {
                eval("document.editor." + tagRemove + ".value = ' " + tagRemove + " '");
                eval(tagRemove + "_open = 0");
            }
        }
    }
}


function tag_list() {
    var listvalue = "init";
    var thelist = "";
    while ( (listvalue != "") && (listvalue != null) ) {
        listvalue = prompt(list_prompt, "");
        if ( (listvalue != "") && (listvalue != null) ) {
            thelist = thelist+"[*]"+listvalue+"\n";
        }
    }
    if ( thelist != "" ) {
        doInsert( "[LIST]\n" + thelist + "[/LIST]\n", "", false);
    }
}

function tag_url() {
    var FoundErrors = '';
    var enterURL   = prompt(text_enter_url, "http://");
    var enterTITLE = prompt(text_enter_url_name, "My Webpage");

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }
    if (!enterTITLE) {
        FoundErrors += " " + error_no_title;
    }
    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }
    doInsert("[URL="+enterURL+"]"+enterTITLE+"[/URL]", "", false);
}


function tag_image() {
    var FoundErrors = '';
    var enterURL   = prompt(text_enter_image, "http://");

    if (!enterURL) {
        FoundErrors += " " + error_no_url;
    }
    if (FoundErrors) {
        alert("Error!"+FoundErrors);
        return;
    }
    doInsert("[IMG]"+enterURL+"[/IMG]", "", false);
}

function tag_email() {
    var emailAddress = prompt(text_enter_email, "");
    if (!emailAddress) {
        alert(error_no_email);
        return;
    }
    doInsert("[EMAIL]"+emailAddress+"[/EMAIL]", "", false);
}

// Meo: fixed for mozilla in 1.3

function doInsert(ibTag, ibClsTag, isSingle) {
    var isClose = false;
    var obj_ta = document.editor.ta;
    if(is_ie && is_win && (agt_ver >= 4)) {
        if(obj_ta.isTextEdit){
            obj_ta.focus();
            var sel = document.selection;
            var rng = sel.createRange();
            rng.collapse;
            if((sel.type == "Text" || sel.type == "None") && rng != null){
                if(ibClsTag != "" && rng.text.length > 0)
                    ibTag += rng.text + ibClsTag;
                else if(isSingle)
                    isClose = true;
                rng.text = ibTag;
            }
        }
        else {
            if(isSingle)
                isClose = true;
            obj_ta.value += ibTag;
        }
    }
    else {
        
        if(is_mozilla && obj_ta.selectionEnd) {
            var length = obj_ta.textLength;
            var start = obj_ta.selectionStart;
            var end = obj_ta.selectionEnd;
			var sct = obj_ta.scrollTop;
            var head = obj_ta.value.substring(0,start);
            var rng = obj_ta.value.substring(start, end);
            var tail = obj_ta.value.substring(end, length);
            if( start != end ){
                if (ibClsTag != "" && length > 0)
                    ibTag += rng + ibClsTag;
                else if (isSingle)
                    isClose = true;
                rng = ibTag;
                obj_ta.value = head + rng + tail;
                start = start + rng.length;
            }
            else{
                if(isSingle)
                    isClose = true;
                obj_ta.value = head + ibTag + tail;
                start = start + ibTag.length;
            }
            obj_ta.selectionStart = start;
            obj_ta.selectionEnd = start;
			obj_ta.scrollTop = sct;
        }
        else {
            if(isSingle)
                isClose = true;
            obj_ta.value += ibTag;
        }
    }
    obj_ta.focus();
    return isClose;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function getObj(name)
{
  if (document.getElementById)
  {
    if(document.getElementById(name))
      return document.getElementById(name);
    else
      return false;
  }
  else if (document.all)
  {
	if (document.all[name])
      return document.all[name];
    else
      return false;
  }
  else if (document.layers)
  {
    if (document.layers[name])
      return document.layers[name];
    else
      return false;
  }
}

function ColumnClose(currMenu) {
	Mclose = 'menucloseds';
	Mcontent= 'menucontents';
	if (currMenu == 'menudx') {
			Mclose = 'menuclosedr';
			Mcontent = 'menucontentr';
	}

  holder = getObj(currMenu)
  if( holder ){

    if (typeof(window.opera) == 'undefined'
        && typeof(holder.getAttribute) != 'undefined') {
        if (holder.getAttribute("className")) {
            holder.setAttribute("className", Mclose);
        } else {
            holder.setAttribute("class", Mclose);
        }
    }
    else {
        holder.setAttribute("class", Mclose);
    }

    obj = getObj(Mcontent);
    if(obj) obj.style.display = 'none';

    obj = getObj(Mclose);
    if(obj) obj.style.display = '';
  }
}
function ColumnOpen(currMenu) {
  	Mclose = 'menucloseds';
	Mcontent= 'menucontents';
	if (currMenu == 'menudx') {
			Mclose = 'menuclosedr';
			Mcontent = 'menucontentr';
	}
  holder = getObj(currMenu)
  if( holder ){


    if (typeof(window.opera) == 'undefined'
        && typeof(holder.getAttribute) != 'undefined') {
        if (holder.getAttribute("className")) {
            holder.setAttribute("className", currMenu);
        } else {
            holder.setAttribute("class", currMenu);
        }
    }
    else {
        holder.setAttribute("class", currMenu);
    }


    obj = getObj(Mcontent);
    if(obj) obj.style.display = '';

    obj = getObj(Mclose);
    if(obj) obj.style.display = 'none';
  }
}


function MemoPos(name, value) {
   var expire=new Date();
   expire=new Date(expire.getTime()+7776000000);
   document.cookie=  name + "=" +value + "; expires="+expire+"; path=/";

}

function GetPos() {
	var resultsx = getCookie('MKmenusx');
	var resultdx = getCookie('MKmenudx');
	//document.write(result);
	if (resultsx == 1)
	ColumnClose('menusx');
	if (resultdx == 1)
	ColumnClose('menudx');


}

// Meo: added in C 0.1.b
// General utility Functions called
var MkUtilsLib = {

	getPageScroll: function()
	{
		var yScroll;
		if(self.pageYOffset)
		{
			yScroll = self.pageYOffset;
		}
		else if(document.documentElement && document.documentElement.scrollTop) // Explorer 6
		{
			yScroll = document.documentElement.scrollTop;
		}
		else if(document.body) // all other Explorers
		{
			yScroll = document.body.scrollTop;
		}
		arrayPageScroll = new Array('',yScroll);
		return arrayPageScroll;
	},

	getPageSize: function()
	{
		var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
	}

}

// Ajax Spinner loading indicator
var objMkspinner = false;
function mkportal_Spinner_Show() {
	if(!objMkspinner) {
		var image = MKAJAX_IMAGES_PATH + "loadspin.gif";;
		var height = 180;
		var width = 180;
		objMkspinner = document.createElement("div");
		objMkspinner.style.position = "absolute";
		objMkspinner.style.zIndex = 1000;
		objMkspinner.style.textAlign = "center";
		objMkspinner.style.verticalAlign = "middle";
		objMkspinner.innerHTML = "<div style=\"text-align: center; border:2px solid #698490; padding: 6px; background: #FFF;\"><br /><img src=\"" + image + "\" border=\"\"><br /><br /><b>... Loading... </b><br /></div>";
		objMkspinner.style.width = width + "px";
		objMkspinner.style.height = height + "px";
		objMkspinner.style.display = 'none';
		objMkspinner.id = "mkspinner";
		var owner = document.getElementsByTagName("body").item(0);
		owner.insertBefore(objMkspinner, owner.firstChild);
	}
	var arrayPageSize = MkUtilsLib.getPageSize();
	var arrayPageScroll = MkUtilsLib.getPageScroll();
	var top = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - 180) / 2);
	var left = ((arrayPageSize[0] - 20 - 180) / 2);
	objMkspinner.style.top = top + "px";
	objMkspinner.style.left = left + "px";
	objMkspinner.style.display = 'block';
}

function mkportal_Spinner_Hide() {
 	document.getElementById('mkspinner').style.display = 'none';
}

// Ajax Core Engine
function MKP_ajax(url, options) {	

	var mka_postData = options.postBody || '';
	var mka_method = options.method || 'post';
	var mka_Complete = options.onComplete || null;
	var mka_update = options.update || null;
	var mka_sendReq = Mka_getXmlHttpRequestObject();

	function Mka_returnOut() {

		if (mka_sendReq.readyState == 4 && mka_sendReq.status == 200) {
			if (mka_Complete) 
				setTimeout(function(){mka_Complete(mka_sendReq);}, 10);
			if (mka_update)
				setTimeout(function(){mka_update.innerHTML = mka_sendReq.responseText;}, 10);
			mka_sendReq.onreadystatechange = function(){};
		}

	}

	function Mka_start(url){

		mka_sendReq.open(mka_method, url, true);
		mka_sendReq.onreadystatechange = Mka_returnOut;
		if (mka_method == 'post') {
			mka_sendReq.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
			if (mka_sendReq.overrideMimeType) mka_sendReq.setRequestHeader('Connection', 'close');
		}
		mka_sendReq.send(mka_postData);

	}
	

	function Mka_getXmlHttpRequestObject() {
		if(window.XMLHttpRequest) {	return new XMLHttpRequest(); }
		else if(window.ActiveXObject) {
			try { req = new ActiveXObject('Msxml2.XMLHTTP.4.0'); } catch(e) { try {	req = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {req = false; }} return req; }
		else {	return false; }
	}
	
	Mka_start(url);
};


//** Kimi added for Dynamic Web News v1.0
//** Tab Content script v2.0- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)

////NO NEED TO EDIT BELOW////////////////////////

function ddtabcontent(tabinterfaceid){
	this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
	this.enabletabpersistence=true
	this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
	this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
	this.subcontentids=[] //Array to store ids of the sub contents ("rel" attr values)
	this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
	this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}

ddtabcontent.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

ddtabcontent.setCookie=function(name, value){
	document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
}

ddtabcontent.prototype={

	expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
		this.cancelautorun() //stop auto cycling of tabs (if running)
		var tabref=""
		try{
			if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=document.getElementById(tabid_or_position)
			else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=this.tabs[tabid_or_position]
		}
		catch(err){alert("Invalid Tab ID or position entered!")}
		if (tabref!="") //if a valid tab is found based on function parameter
			this.expandtab(tabref) //expand this tab
	},

	cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
		if (dir=="next"){
			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
		}
		else if (dir=="prev"){
			var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1
		}
		if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function
			this.cancelautorun() //stop auto cycling of tabs (if running)
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
	},

	setpersist:function(bool){ //PUBLIC function to toggle persistence feature
			this.enabletabpersistence=bool
	},

	setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
		this.selectedClassTarget=objstr || "link"
	},

	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
	},

	urlparamselect:function(tabinterfaceid){
		var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL
		return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
	},

	expandtab:function(tabref){
		var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand
		//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through
		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
		this.expandsubcontent(subcontentid)
		this.expandrevcontent(associatedrevids)
		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""
		}
		if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
			ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)
		this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
	},

	expandsubcontent:function(subcontentid){
		for (var i=0; i<this.subcontentids.length; i++){
			var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)
			subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value
		}
	},

	expandrevcontent:function(associatedrevids){
		var allrevids=this.revcontentids
		for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
			//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
		}
	},

	setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
		for (var i=0; i<this.hottabspositions.length; i++){
			if (tabposition==this.hottabspositions[i]){
				this.currentTabIndex=i
				break
			}
		}
	},

	autorun:function(){ //function to auto cycle through and select tabs based on a set interval
		this.cycleit('next', true)
	},

	cancelautorun:function(){
		if (typeof this.autoruntimer!="undefined")
			clearInterval(this.autoruntimer)
	},

	init:function(automodeperiod){
		var persistedtab=ddtabcontent.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)
		var selectedtab=-1 //Currently selected tab index (-1 meaning none)
		var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index
		this.automodeperiod=automodeperiod || 0
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i //remember position of tab relative to its peers
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this
				this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
				this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)
				this.tabs[i].onclick=function(){
					tabinstance.expandtab(this)
					tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
					return false
				}
				if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
				}
				if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
					selectedtab=i //Selected tab index, if found
				}
			}
		} //END for loop
		if (selectedtab!=-1) //if a valid default selected tab index is found
			this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
		else //if no valid default selected index found
			this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
		}
	} //END int() function

} //END Prototype assignment
//** END Kimi added for Dynamic Web News v1.0