var _lock;
var _timeoutId;
var _tabcache;

function tabbed_focus(prefix)
{
    this.initialtab=[1, prefix+"focus1"];
    this.previoustab="";
    this.order = new Array(prefix+'focus1',prefix+'focus2',prefix+'focus3',prefix+'focus4');
	
	this.expandcontent = function(cid, aobject)
	{
		if (document.getElementById)
		{
			this.highlighttab(aobject);
			if (this.previoustab!="") document.getElementById(this.previoustab).style.display="none";
			document.getElementById(cid).style.display="block";
			this.previoustab=cid;
		}
	}
	
	this.highlighttab = function(aobject)
	{
		if (typeof this.tabobjlinks=="undefined")
		this.collectfocustabs();
		for (i=0; i<this.tabobjlinks.length; i++)
		this.tabobjlinks[i].className="";
		aobject.className="current";
	}
	
	this.collectfocustabs = function()
	{
		this.tabobj=document.getElementById(prefix+"focustabs");
		this.tabobjlinks=this.tabobj.getElementsByTagName("A");
	}

	this.do_onload = function()
	{
		this.collectfocustabs();
		this.expandcontent(this.initialtab[1], this.tabobjlinks[this.initialtab[0]-1])
	}
}
	
	function tabbed_rotator(prefix,timeout,numtabs, starttab)
	{
		if (starttab=="") starttab = "1";
		this.initialtab=starttab;
		this.previoustab="";
		this.order = new Array(prefix+'focus1',prefix+'focus2',prefix+'focus3',prefix+'focus4',prefix+'focus5');
		this.curpos = -1;
		this.dorotate = 1;
		this.newDate = new Date();
		this.oldDate = new Date();
		this.gotContent = new Array(numtabs);
		for (var i = 0; i < numtabs; i++) this.gotContent[i] = 0;
		this.pauseimage = "";
		this.pauseimageon = "";
	
		this.expandcontent = function(cid, aobject)
		{
			this.disable_rotate();
			this.oldDate = new Date;
			if (document.getElementById)
			{
				this.highlighttab(aobject);
				if (this.previoustab!="") document.getElementById(this.previoustab).style.display="none";
				document.getElementById(cid).style.display="block";
				this.previoustab=cid;
			}
		this.curpos = 0;
		while (cid != this.order[this.curpos])
		{
			this.curpos++;
		}
	}
	
	this.changePosition = function(id,left,top,width,height)
	{
		if (left == "") left = 0;
		if (top == "") top = 0;
		document.getElementById(id).style.top = top + 'px';
		document.getElementById(id).style.left = left + 'px';
		document.getElementById(id).style.width = width + 'px';
		document.getElementById(id).style.height = height + 'px';
	}
	
	this.changeImage = function(id,image)
	{
	    document.getElementById(id).style.backgroundImage = "url("+image+")";
	}
	
	this.changeOpacity = function(id, opacity)
	{
		if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4)
		document.getElementById(id).filters.alpha.opacity = opacity;
		else if (navigator.appName.indexOf("Netscape")!=-1&&parseInt(navigator.appVersion)>=5)
		{
			opacity = opacity / 100;
			document.getElementById(id).style.MozOpacity = opacity;
		}
	}
	
	this.highlighttab = function(aobject)
	{
		if (typeof this.tabobjlinks=="undefined")
		this.collectfocustabs();
		for (i=0; i<this.tabobjlinks.length; i++)
		this.tabobjlinks[i].className="";
		aobject.className="current";
	}
	
	this.collectfocustabs = function()
	{
	    this.tabobj=document.getElementById(prefix+"focustabs");
		this.tabobjlinks=this.tabobj.getElementsByTagName("A");
	}
	
	this.contentFetched = function(c)
	{
		this.gotContent[c-1] = 1;
	}
	
	this.rotate = function()
	{
		this.newDate = new Date();
		change = this.newDate.getTime() - this.oldDate.getTime();
		if ((this.dorotate == 1) && (change >= timeout) && (this.gotContent[this.curpos] == 1))
		{
			this.oldDate = new Date();
			this.curpos++;
			if (this.curpos >= numtabs) this.curpos = 0;
			return this.curpos.toString();
		}
		else
		{
	        return "-1";
		}
	}

	this.rotateright = function()
	{
	    this.curpos++;
		if (this.curpos >= numtabs) this.curpos = 0;
		return this.curpos.toString();
	}

	this.rotateleft = function()
	{
	    this.curpos--;
		if (this.curpos <= -1) this.curpos = (numtabs-1);
		return this.curpos.toString();
	}

	this.toggle_rotate = function()
	{
		if (this.dorotate == 0)
		{
			this.oldDate = new Date;
			this.dorotate = 1;
		}
	    else if (this.dorotate == 1) this.dorotate = 0;
	    if (this.dorotate == 1)
	    {
			document.getElementById(prefix+"pausebutton").style.background = 'url('+this.pauseimage+')';
	    }
	    else
	    {
			document.getElementById(prefix+"pausebutton").style.background = 'url('+this.pauseimageon+')';
	    }
	}
	
	this.setup_pause = function (pause, pauseon)
	{
		this.pauseimage = pause;
		this.pauseimageon = pauseon;
	}
	
	this.disable_rotate = function()
	{
		this.dorotate = 0;
		document.getElementById(prefix+"pausebutton").style.background = 'url('+this.pauseimageon+')';
	}
	
	this.enable_rotate = function()
	{
		this.dorotate = 1;
		document.getElementById(prefix+"pausebutton").style.background = 'url('+this.pauseimage+')';
	}
	
	this.do_onload = function()
	{
		this.collectfocustabs();
		this.oldDate.setFullYear(2000);
		this.tabobjlinks[starttab-1].onclick();
		this.dorotate = 1;
		document.getElementById(prefix+"pausebutton").style.background = 'url('+this.pauseimage+')';
	}
}

function openWin(url, name, features)
{
    var w = window.open(url, name, features);
    w.focus();
    return w;
}

function chainEvent(theEvent, newEvent)
{
    if (typeof theEvent != 'function')
    {
        theEvent = newEvent;
    }
    else
    {
	theEvent = function()
	{
		theEvent();
		newEvent();
	}
	}
}

function rotator(obj1,obj2,obj3)
{
    this.targetImage = obj1;
    this.targetHeadline = obj2;
    this.targetBlurb = obj3;
    this.itemsImage = new Array();
    this.itemsHeadline = new Array();
    this.itemsBlurb = new Array();
    this.ptr = 0;
    this.count = 0;
    this.p = 0;
    if (typeof Array.prototype.push == "undefined")
    {
Array.prototype.push = function(str)
{
    this[this.length] = str;
}
}
this.add = function(item1,item2,item3)
{
    this.itemsImage.push(item1);
    this.itemsHeadline.push(item2);
    this.itemsBlurb.push(item3);
    this.count++;
}
this.addImage = function(item)
{
    this.itemsImage.push(item);
}
this.addHeadline = function(item)
{
    this.itemsHeadline.push(item);
}
this.addBlurb = function(item)
{
    this.itemsBlurb.push(item);
    this.count++;
}
this.setItem = function(num)
{
    this.targetImage.innerHTML = this.itemsImage[num];
    this.targetHeadline.innerHTML = this.itemsHeadline[num];
    this.targetBlurb.innerHTML = this.itemsBlurb[num];
    this.count = num;
}
this.runItems = function()
{
    if (this.p == 0)
    {
        this.setItem((++this.ptr > this.itemsHeadline.length-1) ? this.ptr = 0 : this.ptr);
    }
    else
    {
    }
}
this.pause = function()
{
    this.p = 1;
}
this.previous = function()
{
    if(this.count <= 0)
    {
        this.setItem(2);
    }
    else
    {
        this.count = this.count - 1;
        this.setItem(this.count);
    }
}
this.next = function()
{
    if(this.count >= 2)
    {
        this.setItem(0);
    }
    else
    {
        this.count = this.count + 1;
        this.setItem(this.count);
    }
}
}
function PopUp(URL, winName, width, height, toolbar)
{
    var x = window.open(URL, winName, "location=no,height="+height+",width="+width+",scrollbars=yes,toolbar="+toolbar+",menu=no,resizable=yes,status=no");
    x.focus();
}
function getCalendarDate()
{
    var months = new Array(13);
    months[0] = "January";
    months[1] = "February";
    months[2] = "March";
    months[3] = "April";
    months[4] = "May";
    months[5] = "June";
    months[6] = "July";
    months[7] = "August";
    months[8] = "September";
    months[9] = "October";
    months[10] = "November";
    months[11] = "December";
    var now = new Date();
    var monthnumber = now.getMonth();
    var monthname = months[monthnumber];
    var monthday = now.getDate();
    var year = now.getYear();
    var dateString = monthname + ' ' + monthday + ', ' + year;
    return dateString;
}

function AJAX_CallBack(r)
{
	if(r != null)
    {
        var Name = "";
        var tabId = "";
        
        var temppos = r.indexOf('<!--divname');
        var names = r.substring(temppos);
        var data = names.split('^');
        if (data.length > 1)
        {
          Name = data[1];
          tabId = data[2];
          
          document.getElementById(Name + '_focus' + tabId + '_content').innerHTML = r;
          if (document.getElementById(Name+'_script_' + tabId))
          {
              var script = document.getElementById(Name+'_script_' + tabId).innerHTML;
              eval(script);
          }
        }
        else
        {
            document.getElementById(Name + '_focus' + tabId + '_content').innerHTML = "<b>An error ocurred. Please try again... ";
        }
    }
  
}

function LoadTab(tabId, template, sid, Name, ID, URL, webmethod, contentID)
{
	if (document.getElementById(Name + '_focus' + tabId + '_content').innerHTML.indexOf("<!-- FETCHED -->") == -1)
	{
		var preview = 0;
		var location = window.location.toString();
		if (location.indexOf('preview.aspx') != -1)
		{
			preview = 1;
		}
		
		var host = window.location.toString();
		var endofhost = host.indexOf('//');
		var temphost = host.substring(endofhost+2);
		endofhost = temphost.indexOf('/');
		
		if (temphost.indexOf('cms.24') > -1)
		{	
				
			host = host.substring(0,endofhost+9); // grabs the hostname only (including http://)	
		}
		else
		{
			host = host.substring(0,endofhost+8); // grabs the hostname only (including http://)
		}	
		URL = host+URL;
		
		var param = new SOAPClientParameters();
		param.add("tabId",tabId);
		param.add("template",template);
		param.add("sid",sid);
		param.add("Name",Name);
		param.add("ID",ID);
		if (contentID != null) param.add("contentID",contentID);
		if (preview == 1) param.add("mode", "preview");
		else param.add("mode", "publish");
		SOAPClient.invoke(URL, webmethod, param, true, AJAX_CallBack);
	
	}
	
}

function PopularTab(tabId, Name, type, ID, URL, contentID)
{
	
  
	if (document.getElementById(Name + '_focus' + tabId + '_content').innerHTML.indexOf("<!-- FETCHED -->") == -1)
	{
		var preview = 0;
		var location = window.location.toString();
		if (location.indexOf('preview.aspx') != -1)
		{
			preview = 1;
		}
		
		var host = window.location.toString();
		var endofhost = host.indexOf('//');
		var temphost = host.substring(endofhost+2);
		endofhost = temphost.indexOf('/');
		if (temphost.indexOf('cms.24') > -1)
		{	
				
			host = host.substring(0,endofhost+9); // grabs the hostname only (including http://)	
		}
		else
		{
			host = host.substring(0,endofhost+8); // grabs the hostname only (including http://)
		}
		URL = host+URL;
		
		var param = new SOAPClientParameters();
		param.add("tabId",tabId);
		param.add("Name",Name);
		param.add("type", type);
		param.add("ID",ID);
		if (contentID != null) param.add("contentID",contentID);
		if (preview == 1) param.add("mode", "preview");
		else param.add("mode", "publish");
		SOAPClient.invoke(URL, "PopularTab", param, true, AJAX_CallBack);
	}
	
}

function TabNews(tabId, Name, ID, URL, contentID)
{
	if (document.getElementById(Name + '_focus' + tabId + '_content').innerHTML.indexOf("<!-- FETCHED -->") == -1)
	{
		var preview = 0;
		var location = window.location.toString();
		if (location.indexOf('preview.aspx') != -1)
		{
			preview = 1;
		}
		
		var host = window.location.toString();
		var endofhost = host.indexOf('//');
		var temphost = host.substring(endofhost+2);
		endofhost = temphost.indexOf('/');
		if (temphost.indexOf('cms.24') > -1)
		{	
				
			host = host.substring(0,endofhost+9); // grabs the hostname only (including http://)	
		}
		else
		{
			host = host.substring(0,endofhost+8); // grabs the hostname only (including http://)
		}
		URL = host+URL;
		
		var param = new SOAPClientParameters();
		param.add("tabId",tabId);
		param.add("Name",Name);
		param.add("ID",ID);
		if (contentID != null) param.add("contentID",contentID);
		if (preview == 1) param.add("mode", "preview");
		else param.add("mode", "publish");
		SOAPClient.invoke(URL, "TabNews", param, true, AJAX_CallBack);
	}
	
}


function SOAPClientParameters()
{
    var _pl = new Array();
this.add = function(name, value)
{
    _pl[name] = value;
    return this;
}
this.toXml = function()
{
    var xml = "";
    for(var p in _pl)
    xml += "<" + p + ">" + SOAPClientParameters._serialize(_pl[p]) + "</" + p + ">"; return xml;
}
}
SOAPClientParameters._serialize = function(o)
{
    var s = "";
    switch(typeof(o))
    {
        case "string":
        s += o.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
        break;
        case "number":
        case "boolean":
        s += o.toString();
        break;
        case "object":
        if(o.constructor.toString().indexOf("function Date()") > -1)
        {
            var year = o.getFullYear().toString();
            var month = (o.getMonth() + 1).toString();
            month = (month.length == 1) ? "0" + month : month;
            var date = o.getDate().toString();
            date = (date.length == 1) ? "0" + date : date;
            var hours = o.getHours().toString();
            hours = (hours.length == 1) ? "0" + hours : hours;
            var minutes = o.getMinutes().toString();
            minutes = (minutes.length == 1) ? "0" + minutes : minutes;
            var seconds = o.getSeconds().toString();
            seconds = (seconds.length == 1) ? "0" + seconds : seconds;
            var milliseconds = o.getMilliseconds().toString();
            var tzminutes = Math.abs(o.getTimezoneOffset());
            var tzhours = 0;
            while(tzminutes >= 60)
            {
                tzhours++;
                tzminutes -= 60;
            }
            tzminutes = (tzminutes.toString().length == 1) ? "0" + tzminutes.toString() : tzminutes.toString();
            tzhours = (tzhours.toString().length == 1) ? "0" + tzhours.toString() : tzhours.toString();
            var timezone = ((o.getTimezoneOffset() < 0) ? "+" : "-") + tzhours + ":" + tzminutes;
            s += year + "-" + month + "-" + date + "T" + hours + ":" + minutes + ":" + seconds + "." + milliseconds + timezone;
        }
        else if(o.constructor.toString().indexOf("function Array()") > -1)
        {
            for(var p in o)
            {
                if(!isNaN(p))
                {
                    (/function\s+(\w*)\s*\(/ig).exec(o[p].constructor.toString());
                    var type = RegExp.$1;
                    switch(type)
                    {
                        case "":
                        type = typeof(o[p]);
                        case "String":
                        type = "string";
                        break;
                        case "Number":
                        type = "int";
                        break;
                        case "Boolean":
                        type = "bool";
                        break;
                        case "Date":
                        type = "DateTime";
                        break;
                    }
                    s += "<" + type + ">" + SOAPClientParameters._serialize(o[p]) + "</" + type + ">"
                }
                else
                s += "<" + p + ">" + SOAPClientParameters._serialize(o[p]) + "</" + p + ">"
            }
        }
        else
        for(var p in o)
        s += "<" + p + ">" + SOAPClientParameters._serialize(o[p]) + "</" + p + ">"; break; default:
        throw new Error(500, "SOAPClientParameters: type '" + typeof(o) + "' is not supported");
    }
    return s;
}
function SOAPClient()
{
}
SOAPClient.invoke = function(url, method, parameters, async, callback)
{
    if(async)
    SOAPClient._loadWsdl(url, method, parameters, async, callback);
    else
    return SOAPClient._loadWsdl(url, method, parameters, async, callback);
}
SOAPClient_cacheWsdl = new Array();
SOAPClient._loadWsdl = function(url, method, parameters, async, callback)
{
    var wsdl = SOAPClient_cacheWsdl[url];
    if(wsdl + "" != "" && wsdl + "" != "undefined")
    return SOAPClient._sendSoapRequest(url, method, parameters, async, callback, wsdl);
    var xmlHttp = SOAPClient._getXmlHttp();
    xmlHttp.open("GET", url + "?wsdl", async);
    if(async)
    {
xmlHttp.onreadystatechange = function()
{
    if(xmlHttp.readyState == 4)
    SOAPClient._onLoadWsdl(url, method, parameters, async, callback, xmlHttp);
}
}
xmlHttp.send(null);
if (!async)
return SOAPClient._onLoadWsdl(url, method, parameters, async, callback, xmlHttp);
}
SOAPClient._onLoadWsdl = function(url, method, parameters, async, callback, req)
{
    var wsdl = req.responseXML;
    SOAPClient_cacheWsdl[url] = wsdl;
    return SOAPClient._sendSoapRequest(url, method, parameters, async, callback, wsdl);
}
SOAPClient._sendSoapRequest = function(url, method, parameters, async, callback, wsdl)
{
    var ns = (wsdl.documentElement.attributes["targetNamespace"] + "" == "undefined") ? wsdl.documentElement.attributes.getNamedItem("targetNamespace").nodeValue : wsdl.documentElement.attributes["targetNamespace"].value;
    var sr = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<soap:Envelope " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " + "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body>" + "<" + method + " xmlns=\"" + ns + "\">" + parameters.toXml() + "</" + method + "></soap:Body></soap:Envelope>";
    var xmlHttp = SOAPClient._getXmlHttp();
    xmlHttp.open("POST", url, async);
    var soapaction = ((ns.lastIndexOf("/") != ns.length - 1) ? ns + "/" : ns) + method;
    xmlHttp.setRequestHeader("SOAPAction", soapaction);
    xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    if(async)
    {
xmlHttp.onreadystatechange = function()
{
    if(xmlHttp.readyState == 4)
    SOAPClient._onSendSoapRequest(method, async, callback, wsdl, xmlHttp);
}
}
xmlHttp.send(sr);
if (!async)
return SOAPClient._onSendSoapRequest(method, async, callback, wsdl, xmlHttp);
}
SOAPClient._onSendSoapRequest = function(method, async, callback, wsdl, req)
{
    var o = null;
    var nd = SOAPClient._getElementsByTagName(req.responseXML, method + "Result");
    if(nd.length == 0)
    {
        if(req.responseXML.getElementsByTagName("faultcode").length > 0)
        {
            if(async || callback)
            o = new Error(500, req.responseXML.getElementsByTagName("faultstring")[0].childNodes[0].nodeValue);
            else
            throw new Error(500, req.responseXML.getElementsByTagName("faultstring")[0].childNodes[0].nodeValue);
        }
    }
    else
    o = SOAPClient._soapresult2object(nd[0], wsdl);
    if(callback)
    callback(o, req.responseXML);
    if(!async)
    return o;
}
SOAPClient._getElementsByTagName = function(document, tagName)
{
    try
    {
        return document.selectNodes(".//*[local-name()=\""+ tagName +"\"]");
    }
    catch (ex)
    {
    }
    return document.getElementsByTagName(tagName);
}
SOAPClient._soapresult2object = function(node, wsdl)
{
    return SOAPClient._node2object(node, wsdl);
}
SOAPClient._node2object = function(node, wsdl)
{
    if(node == null)
    return null;
    //alert(node.nodeType+","+node);
    if(node.nodeType == 3 || node.nodeType == 4)
    return SOAPClient._extractValue(node, wsdl);
    if (node.childNodes.length == 1 && (node.childNodes[0].nodeType == 3 || node.childNodes[0].nodeType == 4))
    return SOAPClient._node2object(node.childNodes[0], wsdl);
    var isarray = SOAPClient._getTypeFromWsdl(node.nodeName, wsdl).toLowerCase().indexOf("arrayof") != -1;
    if(!isarray)
    {
        var obj = null;
        if(node.hasChildNodes())
        var obj = '';
        for(var i = 0; i < node.childNodes.length; i++)
        {
            var p = SOAPClient._node2object(node.childNodes[i], wsdl);
            obj = obj+p;
        }
        return obj;
    }
    else
    {
        var l = new Array();
        for(var i = 0; i < node.childNodes.length; i++)
        l[l.length] = SOAPClient._node2object(node.childNodes[i], wsdl);
        return l;
    }
    return null;
}
SOAPClient._extractValue = function(node, wsdl)
{
    var value = node.nodeValue;
    switch(SOAPClient._getTypeFromWsdl(node.parentNode.nodeName, wsdl).toLowerCase())
    {
        default:
        case "s:string":
        return (value != null) ? value + "" : "";
        case "s:boolean":
        return value+"" == "true";
        case "s:int":
        case "s:long":
        return (value != null) ? parseInt(value + "", 10) : 0;
        case "s:double":
        return (value != null) ? parseFloat(value + "") : 0;
        case "s:datetime":
        if(value == null)
        return null;
        else
        {
            value = value + "";
            value = value.substring(0, value.lastIndexOf("."));
            value = value.replace(/T/gi," ");
            value = value.replace(/-/gi,"/");
            var d = new Date();
            d.setTime(Date.parse(value));
            return d;
        }
    }
}
SOAPClient._getTypeFromWsdl = function(elementname, wsdl)
{
    var ell = wsdl.getElementsByTagName("s:element");
    if(ell.length == 0)
    ell = wsdl.getElementsByTagName("element");
    for(var i = 0; i < ell.length; i++)
    {
        if(ell[i].attributes["name"] + "" == "undefined")
        {
            if(ell[i].attributes.getNamedItem("name") != null && ell[i].attributes.getNamedItem("name").nodeValue == elementname && ell[i].attributes.getNamedItem("type") != null)
            return ell[i].attributes.getNamedItem("type").nodeValue;
        }
        else
        {
            if(ell[i].attributes["name"] != null && ell[i].attributes["name"].value == elementname && ell[i].attributes["type"] != null)
            return ell[i].attributes["type"].value;
        }
    }
    return "";
}
SOAPClient._getXmlHttp = function()
{
    try
    {
        if(window.XMLHttpRequest)
        {
            var req = new XMLHttpRequest();
            if(req.readyState == null)
            {
                req.readyState = 1;
req.addEventListener("load", function()
{
    req.readyState = 4;
    if(typeof req.onreadystatechange == "function")
    req.onreadystatechange();
}
, false);
}
return req;
}
if(window.ActiveXObject)
return new ActiveXObject(SOAPClient._getXmlHttpProgID());
}
catch (ex)
{
}
throw new Error("Your browser does not support XmlHttp objects");
}
SOAPClient._getXmlHttpProgID = function()
{
    if(SOAPClient._getXmlHttpProgID.progid)
    return SOAPClient._getXmlHttpProgID.progid;
    var progids = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
    var o;
    for(var i = 0; i < progids.length; i++)
    {
        try
        {
            o = new ActiveXObject(progids[i]);
            return SOAPClient._getXmlHttpProgID.progid = progids[i];
        }
        catch (ex)
        {
        };
    }
    throw new Error("Could not find an installed XML parser");
}

