String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
var lastScroll = 0;
var xMargin = 50;
var yMargin = 50;
var activeID;
var activeWindow;
var windowList = new Array();
var layerStart = 10;
var divCount = 0;
var delimiter = "–";
var is_ie;
var cookieCount = 0;
if(document.cookie){
    cookieCount = document.cookie.split(';').length;
}
if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
    is_ie = true;
}else{
    is_ie = false;
}

mouseX = 0;
mouseY = 0;
function scaleMouse(e){
    if(!is_ie){
        mouseX = e.pageX
        mouseY = e.pageY
    }
    updateSize();
    return(false);
}

function center(divID) {
    if(is_ie){
        eval(divID).style.left = (document.body.offsetWidth - parseInt(eval(divID).style.width))/2;
        eval(divID).style.top = 50;
    }else{
        document.getElementById(divID).style.left = (window.innerWidth - document.getElementById(divID).style.width.replace("px",""))/2;
        document.getElementById(divID).style.top = 50;
    }
}

function show(divID){
    document.getElementById(divID).style.visibility = 'visible';
}

function hide(divID){
    document.getElementById(divID).style.visibility = 'hidden';
}

function toggle(divID){
    if(document.getElementById(divID).style.visibility == 'hidden'){
        show(divID);
    }else{
        hide(divID);
    }
}

function set(obj,value){
    obj.value = value;
}

function moveFront(divID){
    if(windowList[windowList.length] != divID){
        var tempList = new Array();
        for(var i=0; i<windowList.length; i++){
            if(windowList[i] != divID){
                tempList[tempList.length] = windowList[i];
            }
        }
        tempList[tempList.length] = divID;
        windowList = tempList;
        for(var i=0; i<windowList.length; i++){
            if(is_ie){
                eval(windowList[i]+"_window").style.zIndex = layerStart + i;
            }else{
                document.getElementById(windowList[i]+"_window").style.zIndex = layerStart + i;
            }
        }
        //window.status = "New Order: "+windowList;
    }
}

function updateSize(){
    if(activeID != null){
        if(is_ie){
            var newWidth = (event.clientX + document.body.scrollLeft)-eval(activeWindow).style.left.replace("px","");
            var newHeight = (event.clientY + document.body.scrollTop)-eval(activeWindow).style.top.replace("px","");

            if(document.getElementById(activeID+"_iframe") != null){
                newWidth = newWidth + 4;
                newHeight = newHeight - 35;
                if(newWidth > 0){
                    document.getElementById(activeID+"_table").width = newWidth;
                }
                if(newHeight > 0){
                    document.getElementById(activeID+"_iframe").height = newHeight;
                }
            }else if(document.getElementById(activeID+"_content") != null){
                newWidth = newWidth + 4;
                newHeight = newHeight - 35;
                if(newWidth > 0){
                    document.getElementById(activeID+"_table").width = newWidth;
                }
                if(newHeight > 0){
                    document.getElementById(activeID+"_content").style.height = newHeight;
                }
            }
        }else{
            var newWidth = mouseX-document.getElementById(activeWindow).style.left.replace("px","");
            var newHeight = mouseY-document.getElementById(activeWindow).style.top.replace("px","");

            if(document.getElementById(activeID+"_iframe") != null){
                newWidth = newWidth + 4;
                newHeight = newHeight - 35;
                if(newWidth > 0){
                    document.getElementById(activeID+"_table").width = newWidth;
                }
                if(newHeight > 0){
                    document.getElementById(activeID+"_iframe").height = (newHeight - 35);
                }
            }else if(document.getElementById(activeID+"_content") != null){
                newWidth = newWidth + 4;
                newHeight = newHeight - 54;
                if(newWidth > 0){
                    document.getElementById(activeID+"_table").width = newWidth;
                    if(window.navigator.userAgent.toLowerCase().indexOf("firefox") < 0){
                        document.getElementById(activeID+"_content").style.width = (newWidth - 22);
                    }
                }
                if(newHeight > 0){
                    document.getElementById(activeID+"_content").style.height = newHeight;
                }
            }
        }
    }
}
function deselect(){
    if (document.selection){
        document.selection.empty();
    }else if (window.getSelection){
        window.getSelection().removeAllRanges();
    }
}
function selectElement(id){
    if(document.selection){
        var range = document.body.createTextRange();
        range.moveToElementText(document.all[id]);
        range.select();
    }else if(window.getSelection()){
        var range = document.createRange();
        range.selectNodeContents(document.getElementById(id));
        var selection = window.getSelection();
        selection.removeAllRanges();
        selection.addRange(range);
    }
}
function disableSelection(e){
    return false;
}

function enableSelection(){
    return true;
}

function doAction(action){
    if(action == "enable"){
        if(is_ie){
            document.onselectstart = null;
        }else{
            document.onmousedown = null;
        }
    }else if(action == "disable"){
        if(is_ie){
            document.onselectstart = new Function ("return false");
        }else{
            document.onmousedown = disableSelection;
        }
    }
}

function startScale(divID){
    deselect();
    moveFront(divID);
    activeID = divID;
    activeWindow = divID+"_window";
    if(document.getElementById(activeID+"_iframe") != null){
        document.getElementById(activeID+"_iframe").style.visibility = 'hidden';
    }
    document.onmousemove = scaleMouse;
    document.onmouseup = stopMove;
}

function stopMove(){
    document.onmousemove = null;
    if(is_ie){
        if(document.getElementById(activeID+"_iframe") != null){
            document.getElementById(activeID+"_iframe").style.visibility = '';
        }
    }else{
        if(document.getElementById(activeID+"_iframe") != null){
            document.getElementById(activeID+"_iframe").style.visibility = '';
        }
    }
    document.onmouseup = null;
}

function toggleWindow(divID){
    var button = divID+"_toggle";
    if(is_ie){
        if(eval(divID).style.height == ''){
            eval(divID).style.height = '1px';
            eval(divID+"_content").style.visibility = 'hidden';
            eval(button).innerHTML = "+<br/>";
        }else{
            eval(divID).style.height = '';
            eval(divID+"_content").style.visibility = 'visible';
            eval(button).innerHTML = "-<br/>";
        }
    }else{
        if(document.getElementById(divID).style.height == ''){
            document.getElementById(divID).style.height = '0px';
            document.getElementById(divID+"_content").style.visibility = 'hidden';
            document.getElementById(button).innerHTML = "+<br/>";
        }else{
            document.getElementById(divID).style.height = '';
            document.getElementById(divID+"_content").style.visibility = 'visible';
            document.getElementById(button).innerHTML = "-<br/>";
        }
    }
}

function toggleOpen(divID){
    var xOffset = 0;
    var yOffset = 0;

    var xNew = 0;
    var yNew = 0;

    if (document.body.scrollTop != undefined){
        var ieBox = document.compatMode != "CSS1Compat";
        var cont = ieBox ? document.body : document.documentElement;
        xOffset = cont.scrollLeft;
        yOffset = cont.scrollTop;
    }else{
        xOffset = window.pageXOffset;
        yOffset = window.pageYOffset;
    }

    if((lastScroll != (xOffset + yOffset)) || (xOffset > 0 || yOffset > 0)){
        xNew = xOffset + xMargin;
        yNew = yOffset + yMargin;
        if(is_ie){
            eval(divID+"_window").style.left = xNew;
            eval(divID+"_window").style.top = yNew;
        }else{
            document.getElementById(divID+"_window").style.left = xNew;
            document.getElementById(divID+"_window").style.top = yNew;
        }
        lastScroll = (xOffset + yOffset);
    }

    var button = divID+"_toggle";
    if(is_ie){
        eval(divID).style.height = '';
        eval(divID+"_content").style.visibility = 'visible';
        eval(button).innerHTML = "-<br/>";
    }else{
        document.getElementById(divID).style.height = '';
        document.getElementById(divID+"_content").style.visibility = 'visible';
        document.getElementById(button).innerHTML = "-<br/>";
    }
}

function closeWindow(divID){
    if(is_ie){
        eval(divID+"_window").style.visibility = "hidden";
        eval(divID+"_content").style.visibility = "hidden";
    }else{
        document.getElementById(divID+"_window").style.visibility = "hidden";
        document.getElementById(divID+"_content").style.visibility = "hidden";
    }
}

function createID(value){
    value = value.toLowerCase();
    var idName = "";
    validChars = "abcdefghijklmnopqrstuvwxyz0123456789";
    for(var i=0; i<value.length; i++){
        if(validChars.indexOf(value.charAt(i)) > -1){
            idName += value.charAt(i);
        }else{
            idName += "_";
        }
    }
    return(idName);
}

// WINDOW DRAG CLASS (dom-drag.js)
var Drag = {

	obj : null,

	init : function(id, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o = document.getElementById(id+'_handle');
		oRoot = document.getElementById(id+'_window');
		
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;
		
		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
		
		
	},

	start : function(e)
	{
		doAction("disable");
		
		var o = Drag.obj = this;
		moveFront(o.id.split('_')[0]);
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		doAction("enable");
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

// EX: javascript: openWindow('Google',null,'http://www.google.com/',600,400);
function openWindow(title,content,url,width,height,xPos,yPos,divID){
    // CREATES DYNAMIC ID FROM TITLE
    
    if(divID == null){
        divID = createID(title);
    }

    // DETERMINES IF WINDOW EXISTS
    found = false;
    if(document.getElementById(divID) != null){
        found = true;
    }

    // CREATES WINDOW (if not found)
    if(!found){
        var xPos = (xPos == null) ? xMargin : xPos;
        var yPos = (yPos == null) ? yMargin : yPos;
        var width = (width == null) ? '300' : width;
        var height = (height == null) ? '' : height;
        var title = (title == null) ? 'Window' : title;
        var content = (content == null) ? '' : content;
        var url = (url == null) ? '' : url;

        var titleBar = '#FFAF00';
        var titleColor = '#FFFFFF';
        var template = (is_ie) ? 'template2' : 'template1';
        if(template == 'template2' && is_ie){
            width = width + 12;
        }
        var windowState = 'open';
        if(url != ""){
            content = "<div id='"+divID+"_content' name='"+divID+"_content'><iframe src='"+url+"' style='background:#FFFFFF;width:100%;' align='center' id='"+divID+"_iframe' name='"+divID+"_iframe' height='"+height+"' align='center' frameborder='0' scrolling='auto'></iframe></div>";
        }else{
            if(height != ""){
                content = "<div id='"+divID+"_content' name='"+divID+"_content' style='padding:10px;height:"+height+";overflow:auto;' onclick=\"javascript: moveFront('"+divID+"');\">"+content+"</div>";
            }else{
                content = "<div id='"+divID+"_content' name='"+divID+"_content' style='padding:10px;' onclick=\"javascript: moveFront('"+divID+"');\">"+content+"</div>";
            }
        }

        // CREATES WINDOW
        var dynWin = document.getElementById(template).value;
        dynWin = dynWin.replace(/d0/g,divID);
        dynWin = dynWin.replace(/XPOS/g,xPos);
        dynWin = dynWin.replace(/YPOS/g,yPos);
        dynWin = dynWin.replace(/WIDTH/g,width);
        dynWin = dynWin.replace(/TITLEBAR/g,titleBar);
        dynWin = dynWin.replace(/TITLECOLOR/g,titleColor);
        dynWin = dynWin.replace(/TITLE/g,title);
        dynWin = dynWin.replace(/CONTENT/g,content);

        if(is_ie){
            eval("windowContainer").innerHTML = eval("windowContainer").innerHTML+dynWin;
        }else{
            document.getElementById("windowContainer").innerHTML = document.getElementById("windowContainer").innerHTML+dynWin;
        }
        windowList[windowList.length] = divID;
        //window.status = windowList;
    }
    if(is_ie){
        eval(divID+"_window").style.visibility = "visible";
        eval(divID+"_content").style.visibility = "visible";
    }else{
        document.getElementById(divID+"_window").style.visibility = "visible";
        document.getElementById(divID+"_content").style.visibility = "visible";
    }
    toggleOpen(divID);
    moveFront(divID);
}

function showIndividual(head,url){
    divID = "individual";
    openWindow(head,null,url,770,570,null,null,divID);
    toggleOpen(divID);

    // SETS UP SHARED POPUP
    if(is_ie){
        eval(divID+"h").innerHTML = head;
        eval(divID+"_iframe").location.href = url;
    }else{
       document.getElementById(divID+"h").innerHTML = head;
       document.getElementById(divID+"_iframe").src = url;
    }
}
function showCommunity(head,url){
    //openWindow(head,null,url,550,400,null,null,null);
    divID = "community";
    openWindow(head,null,url,550,400,null,null,divID);
    toggleOpen(divID);

    // SETS UP SHARED POPUP
    if(is_ie){
        eval(divID+"h").innerHTML = head;
        eval(divID+"_iframe").location.href = url;
    }else{
       document.getElementById(divID+"h").innerHTML = head;
       document.getElementById(divID+"_iframe").src = url;
    }    
}
function showService(head,url){
    //openWindow(head,null,url,550,400,null,null,null);
    divID = "service";
    openWindow(head,null,url,550,400,null,null,divID);
    toggleOpen(divID);

    // SETS UP SHARED POPUP
    if(is_ie){
        eval(divID+"h").innerHTML = head;
        eval(divID+"_iframe").location.href = url;
    }else{
       document.getElementById(divID+"h").innerHTML = head;
       document.getElementById(divID+"_iframe").src = url;
    }      
}
function popWindow(url){
	url = url.replace("&#58;",":");
	void window.open(url);
}