(function () { /*Use Object Detection to detect IE6*/var m = document.uniqueID /*IE*/ && document.compatMode /*>=IE6*/ && !window.XMLHttpRequest /*<=IE6*/ && document.execCommand; try { if (!!m) { m("BackgroundImageCache", false, true) /* = IE6 only */ } } catch (oh) { }; })();

if (typeof (WC) == "undefined") WC = {}; // define public Namespace

window.$ = function (sId) { return document.getElementById(sId) };

function getTr(el) {
    while (el && el.tagName != 'TR') {
        el = el.parentNode;
    }
    return el;
};

function getParentByTagName(o, sTagName) {
    while (o && o.tagName != sTagName) {
        o = o.parentNode;
    }
    return o;
};

function getPosTopLeft(o) {
    var p = new Object();
    p.top = 0;
    p.left = 0;
    while (o != null) {
        p.top += o.offsetTop;
        p.left += o.offsetLeft;
        o = o.offsetParent;
        //TEST This out
        //if(o && ( o.style.position == 'relative'|| o.style.position=='absolute') )   break;

    }
    return p;
};

function addEvent(obj, sEvent, oFn, bUseCapture) {

    if (window.attachEvent != null) return obj.attachEvent('on' + sEvent, oFn);
    else if (window.addEventListener) {

        obj.addEventListener(sEvent, oFn, bUseCapture || false);
        return true;
    }
    else obj['on' + sEvent] = oFn;
};

function removeEvent(o, sEvent, oFn, bUseCapture) {

    if (document.detachEvent) {
        //window.status=o + oFn;
        o.detachEvent('on' + sEvent, oFn);
        return;
    }
    else {
        if (document.removeEventListener) {
            bUseCapture = bUseCapture ? bUseCapture : false;
            o.removeEventListener(sEvent, oFn, bUseCapture);
            return true;
        }
        else o['on' + sEvent] = null;
    }
};

function onSelectStart() {
    if (window.event.srcElement.tagName == "INPUT")
        return;
    window.event.cancelBubble = true;
    window.event.returnValue = false;
    return false;
};


function getDocClientAndOffsetHeight() {
    var oBody = document.getElementsByTagName('BODY')[0];
    //if Internet Explorer
    if (document.all) {
        // IE in strict mode  
        if (document.documentElement.clientHeight > 0 && oBody.currentStyle) {
            this.clientHeight = document.documentElement.clientHeight;
            this.offsetHeight = document.body.offsetHeight;
            this.offsetHeight = document.body.scrollHeight;
            var m = {};
            m.top = oBody.currentStyle['marginTop'];
            m.bottom = oBody.currentStyle['marginBottom'];
            this.offsetHeight += (parseInt(m.top) + parseInt(m.bottom));
        }
        else {
            this.clientHeight = document.body.clientHeight;
            this.offsetHeight = document.body.scrollHeight;
        }
    }
    else {
        // Gecko
        this.clientHeight = self.innerHeight;
        this.offsetHeight = document.body.offsetHeight;

        var m = {};
        if (document.defaultView) {
            m.top = document.defaultView.getComputedStyle(oBody, '').getPropertyValue('margin-top');
            m.bottom = document.defaultView.getComputedStyle(oBody, '').getPropertyValue('margin-bottom');
            this.offsetHeight += (parseInt(m.top) + parseInt(m.bottom)); //20px offset for scroll bars          
        }
    }
    return this;
};



function fade(el, state) {
    if (el) {

        fade.el = el;
        el.style.position = 'relative';

        if (state.toLowerCase() == 'on') {
            fade.opacity = 0;
            fade.target = 100;
            fade.increment = 2;
        }
        else {
            fade.opacity = 90;
            fade.target = 0;
            fade.increment = -1;
        }

    }

    if ((fade.opacity <= 80 && fade.target == 100) || (fade.opacity >= 80 && fade.target == 0)) {
        fade.opacity += fade.increment;
        fade.el.style.filter = 'alpha(opacity=' + fade.opacity + ')';
        fade.el.style['opacity'] = fade.opacity / 100;
        var wait = (fade.target == 0 ? -1 * (79 - fade.opacity) : 82 - fade.opacity);
        //        window.status = fade.el.style.filter  + '  ' + fade.target + ' ' + _i++ + '  wait:' + wait;
        setTimeout("fade()", wait);
    }
    else {
        if (fade.target == 0) {
            fade.el.style.display = 'none';
            fade.el.style.opacity = '';
        }
        else {
            fade.el.style.filter = 'alpha(opacity=' + 100 + ')';
            fade.el.style.opacity = '';
            //alert("Opacity Finished");
        }

    }

};

String.prototype._format = function (args) {
    var s = this.toString();
    if (typeof (args) == 'object') {
        s = s.replace(/{/g, '\'+args[\'');
        return eval('\'' + s.replace(/}/g, '\']+ \'') + '\'');
    }
    s = s.replace(/{/g, '\'+arguments[');
    return eval('\'' + s.replace(/}/g, ']+ \'') + '\'');
};


function PleaseWait(icon, mesg) {
    var elLoad = document.createElement('div');
    if (!icon) icon = 'spinner.gif';
    if (!mesg) mesg = 'Please Wait...';
    with (elLoad.style) {
        visibility = 'hidden';
        position = 'absolute';
        border = '1px solid #eee';
        padding = '5px 10px 5px 10px';
        zIndex = 1000;
        backgroundColor = '#eee';
    }
    elLoad.innerHTML = '<img border="0" src="' + icon + '">&nbsp;' + mesg + '</span>';
    document.body.appendChild(elLoad);
    PleaseWait.id = elLoad;
};

PleaseWait.show = function (viewPort) {
    var t, l;
    var elView = document.getElementById(viewPort);
    var elLoad = PleaseWait.id;

    if (true || !elView) {
        t = ((document.body.clientHeight - elLoad.offsetHeight) / 2);
        l = ((document.body.clientWidth - elLoad.offsetWidth) / 2);
    }
    else {
        t = parseInt(elView.style.top) + ((elView.offsetHeight - elLoad.offsetHeight) / 2);
        l = parseInt(elView.style.left) + ((elView.offsetWidth - elLoad.offsetWidth) / 2);

        if ((t <= 0) || (l <= 0)) {
            l = parseInt(elView.style.left);
            t = parseInt(elView.style.top);
        }

    }


    elLoad.style.visibility = 'visible';
    elLoad.style.left = l.toString() + "px";
    elLoad.style.top = t.toString() + "px";


};

PleaseWait.hide = function () {
    PleaseWait.id.style.visibility = 'hidden';
};

function tabInit(tabsID, tabName) {
    try {

        var tabs = $(tabsID).getElementsByTagName("A");

        if ((!tabName) || (tabName.length == 0))
            tabName = tabs[0].hash.substring(1);


        for (var i = 0; i < tabs.length; i++) {
            if (tabs[i].hash == "#" + tabName) {
                var current = new Object();
                current.tab = tabs[i].parentNode;
                current.tabPanel = $(tabName);
                current.tab.className += " selected";
                if (current.tabPanel.className.indexOf('tabPanelSelected') == -1) current.tabPanel.className += " tabPanelSelected";
                if (!tabOnClick.prev) tabOnClick.prev = new Object();
                tabOnClick.prev[tabsID] = current;
            } else {
                var tabPanel = $(tabs[i].hash.substring(1));
                if (tabPanel && tabPanel.className.indexOf('tabPanelHidden') == -1) tabPanel.className += " tabPanelHidden";
            }
        }
    } catch (e) {
        alert("Error initializing Tabs\n" + e.message);
    }
};

function tabClick(sId, hash) {
    var tabs = $(sId).getElementsByTagName("A");
    for (var i = 0; i < tabs.length; i++) {
        if (tabs[i].hash == "#" + hash) {
            //synthetic click function
            elementClick(tabs[i]);
            return;
        };
    }


};

function elementClick(el) {
    if (document.createEvent) {
        //FF support
        e = document.createEvent("MouseEvents");
        e.initEvent("click", true, false);
        // The "click" argument is one that's significant to the "MouseEvents" set mentioned earlier -- again, consult that reference. The two Boolean values // refer to whether the event bubbles up through the DOM and whether the event may be canceled with the preventDefault() method.
        el.dispatchEvent(e);
    } else el.click();
};

function tabOnClick(sId, e, hash) {
    var o = (window.event ? window.event.srcElement : e.target);

    if (o.tagName != "A") return;

    if (tabOnClick.prev && tabOnClick.prev[sId]) {
        tabOnClick.prev[sId].tab.className = tabOnClick.prev[sId].tab.className.replace("selected", "");
        if (tabOnClick.prev[sId].tabPanel)
            tabOnClick.prev[sId].tabPanel.className = tabOnClick.prev[sId].tabPanel.className.replace("tabPanelSelected", "tabPanelHidden");
    }
    current = new Object();
    current.tab = o;
    if (o.tagName.indexOf("A") != -1) {
        current.tabPanel = $(o.hash.substring(1));
        current.tab = o.parentNode;
    }
    current.tab.className += ' selected';
    if (current.tabPanel)
        current.tabPanel.className = current.tabPanel.className.replace("tabPanelHidden", "tabPanelSelected");

    tabOnClick.prev[sId] = current;
    //cancel the click event in IE and Firefox
    e.returnValue = false;
    if (e.stopPropagation) { e.preventDefault(); e.stopPropagation(); }

};

function getSelectedTab(sId) {
    var tabs = $(sId).getElementsByTagName("A");
    for (var i = 0; i < tabs.length; i++) {
        if (tabs[i].parentNode.className.indexOf("selected") != -1) {
            return tabs[i].hash.substring(1);
        };
    }
    return tabs[0].hash.substring(1); ;
}


function FieldFocus() {
    var focusSet = false;
    var oListOfInputs = document.getElementsByTagName('INPUT');

    for (var i in oListOfInputs) {
        if (oListOfInputs[i].tagName == "INPUT" && oListOfInputs[i].type != "hidden" && oListOfInputs[i].type != "button" && oListOfInputs[i].type != "submit" && oListOfInputs[i].type != "reset" && oListOfInputs[i].type != "checkbox") {
            oListOfInputs[i].onfocus = FieldFocus.focus;
            if (!focusSet && !oListOfInputs[i].disabled) {
                try {
                    oListOfInputs[i].focus();
                    focusSet = true;
                } catch (err) { }
            }
        }
    }

    oListOfInputs = document.getElementsByTagName('SELECT');
    for (var i in oListOfInputs) if (oListOfInputs[i].tagName == 'SELECT') oListOfInputs[i].onfocus = FieldFocus.focus;

    oListOfInputs = document.getElementsByTagName('TEXTAREA');
    for (var i in oListOfInputs) if (oListOfInputs[i].tagName == 'TEXTAREA') oListOfInputs[i].onfocus = FieldFocus.focus;


};

FieldFocus.focus = function (e) {
    var elInput = (e ? e.target : window.event.srcElement);

    if (FieldFocus._elPrevFocus) FieldFocus._elPrevFocus.className = FieldFocus._elPrevFocus.className.replace('focus', '');

    elInput.className += ' focus';
    FieldFocus._elPrevFocus = elInput;
    if (typeof (originalValues) != 'undefined' && !originalValues[elInput.name]) {
        originalValues[elInput.name] = new Object();
        originalValues[elInput.name].value = elInput.value;
    }

    return true;
};

function getModifiedElementsOriginalValues(formName) {
    var f = document.forms[formName];
    var url = '';
    for (var i = 0; i < f.length; i++) {
        if (f.elements[i].type != 'button' && f.elements[i].type != 'submit') {
            if (originalValues[f.elements[i].name] && (originalValues[f.elements[i].name].value != f.elements[i].value))
                url += '&' + f.elements[i].name + '=' + escape(originalValues[f.elements[i].name].value);
        }
    }
    return url;
};

function interogateObj(o, all) {
    var s = '';
    all = all || ''; //set default to false if not defined

    for (a in o) {
        if (o[a] > '' || all == 'ALL')
            s += "\n" + a + ' = ' + o[a];
    }
    return s;
};


function showHelp(url) {
    var width = 800;
    var height = 600;
    var top = (screen.height - height) / 2;
    var left = (screen.width - width) / 2;

    var features = "top={0},left={1},width={2},height={3},menu=0,toolbar=0,status=0,resizable=1";
    features = features._format([top, left, width, height]);

    hrefToOpen = url;
    w = window.open(hrefToOpen, "help", features, true);
    if (!w.opener) w.opener = self;
    w.focus();
    return false;
};

function getRadioButtonSelectedValue(sForm, sRadio) {
    var rb = document.forms[sForm][sRadio];
    for (var i = 0; i < rb.length; i++) {
        if (rb[i].checked) return rb[i].value;
    }
    return null;
};

function openWindow(url, w, h, target) {
    target = target || "win";
    var width = w || 800;
    var height = h || 600;

    var top = (screen.height - height) / 2;
    var left = (screen.width - width) / 2;
    hrefToOpen = url;
    var features = "top={0},left={1},width={2},height={3},menu=0,status=0,location=0,resizable=1";
    features = features._format([top, left, width, height]);
    var w = window.open("PleaseWait.htm", target, features, true);

    if (!w.opener) w.opener = self;
    w.focus();
    return false;
};

var ELEMENT_NODE = 1;
function _nextSibling(o) {
    do {
        o = o.nextSibling;
    } while (o && o.nodeType != ELEMENT_NODE)
    return o;
}

function _previousSibling(o) {
    do {
        o = o.previousSibling;
    } while (o && o.nodeType != ELEMENT_NODE)
    return o;
}

function _lastChild(o) {
    o = o.lastChild;
    while (o && o.nodeType != ELEMENT_NODE) {
        o = o.previousSibling;
    }


    return o;
}

function _firstChild(o) {
    o = o.firstChild;
    while (o && o.nodeType != ELEMENT_NODE) {
        o = o.nextSibling;
    }
    return o;
}

function _getChildNodes(o) {
    var childNodes = o.childNodes;

    if (document.all) return childNodes;

    // filter FF Nodes for spaces/text
    // nodeType 1 = element  
    var children = new Array();
    for (var i = 0; i < childNodes.length; i++) {
        if (childNodes[i].nodeType == ELEMENT_NODE) children.push(childNodes[i]);
    }
    return children;
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
    	((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return (setStr);
}


/* simple tab control */
function showMe(oThis, tab) {
    if (showMe.currentTab == tab || document.getElementById(tab) == null) return false;

    var tabsID = tab.split(".")[1];
    var tabContainerParent = "tabContainer." + tabsID;
    var tabTabParent = "tabs." + tabsID;

    if (showMe.currentTabObject == null) {
        var tabs = document.getElementById(tabTabParent).getElementsByTagName("A");
        for (var i = 0; i < tabs.length; i++) {
            if (tabs[i].className == "tabSelected") showMe.currentTabObject = tabs[i];
        }

    }

    if (showMe.currentTabObject)
        showMe.currentTabObject.className = "";

    var divs = document.getElementById(tabContainerParent).getElementsByTagName("div");

    for (var i = 0; i < divs.length; i++) {
        if (divs[i].className == "tabSectionSelected")
            divs[i].className = "tabSection";
    }

    document.getElementById(tab).className = "tabSectionSelected";
    oThis.className = "tabSelected";
    showMe.currentTab = tab;
    showMe.currentTabObject = oThis;
    return false;
}

function showMeDelayed(el, tab) {
    var delay = 200 //300 miliiseconds
    showMeNot.timeoutID = setTimeout(function () { showMe(el, tab); }, delay);
    return false;
}

function showMeNot() {
    if (showMeNot.timeoutID) {
        clearTimeout(showMeNot.timeoutID);
        showMeNot.timeoutID = null;
    }
    return false;
}


function animateTabControlPauseToggle(widgetID, trueOrFalse) {

    if (animateTabControl.instance)

        animateTabControl.instance[widgetID].pause = trueOrFalse;

    return false;
}

function animateTabControl(widgetID, delay) {

    if (typeof animateTabControl.instance != Object) {
        animateTabControl.instance = Object;
    }

    if (!animateTabControl.instance[widgetID]) {

        var tabControl = 'tabs.' + widgetID;
        var links = $(tabControl).getElementsByTagName('a');

        animateTabControl.instance[widgetID] = { 'links': links, 'delay': delay, 'nextLink': 0, 'pause': false };
    }

    if (!animateTabControl.instance[widgetID].pause) {
        nextLink = animateTabControl.instance[widgetID].nextLink++;


        if (nextLink > (animateTabControl.instance[widgetID].links.length - 1)) {
            nextLink = 0;
            animateTabControl.instance[widgetID].nextLink = 1;
        }

        var delay = animateTabControl.instance[widgetID].delay;

        var oLink = animateTabControl.instance[widgetID].links[nextLink];
        var tab = 'tab.' + widgetID + '.' + nextLink.toString();

        showMe(oLink, tab);
        fade($(tab), 'on');
    }

    setTimeout(function () { animateTabControl(widgetID); }, delay);
}
function editSection(e, uri) {
    //cancel the click event in IE and Firefox
    if (e.stopPropagation) { e.preventDefault(); e.stopPropagation(); }
    else
        e.cancelBubble = true;

    openAdminWindow(uri, 1000, 800, "CMS");
    return false;
}


function openAdminWindow(url, w, h, target) {
    target = target || "win";
    var width = w || 800;
    var height = h || 600;

    var top = (screen.height - height) / 2;
    var left = (screen.width - width) / 2;
    hrefToOpen = url;
    var features = "top={0},left={1},width={2},height={3},menu=0,status=0,location=0,resizable=1,scrollbars=1";
    features = features._format([top, left, width, height]);

    var w = window.open(url, target, features, true);

    if (!w.opener) w.opener = self;
    w.focus();
    return false;
};

function saveStat(el) {
    alert("You are going to an external site " + el.href + " be carefull.\nNOTE:We record this stat so we can keep track of trafic we are sending clients.");
}



function printWindow(el) {
    var sectionToPrint = "<div style='margin-top:20px'>" + $(el).innerHTML + "</div>";
    var logo = "<img src=\"" + $('Logo').src + "\" style=\"border:none\"  alt=\"\" />";

    var w = window.open("", "printWindow", "width=800,height=600,status=yes,toolbar=yes,scrollbars=yes,menubar=yes", false);
    w.document.open();

    w.document.write("<html><head>");
    w.document.write("<title>" + document.title + "</title>");
    w.document.write("<style>body {margin:10px;} body,label,p,td {font-family:Arial} a {display:none}  p {margin:2px 0} div img{display:none} .Scroll {overflow:visible;height:auto!important}</style></head><body>");
    w.document.write(logo);
    w.document.write(sectionToPrint);
    w.document.write("</body></html>");
    w.document.close();
}

function displayInFrameModal(url, w, h) {


    displayInFrameSetup(url, w, h);
    setModalState(true);
    window.open(url, "PopupIframe", "", true);

    return false;
}

function displayInFrame(url, w, h) {
    displayInFrameSetup(url, w, h);
    if (url > "") {
        window.open(url, "PopupIframe", "", true);
    }
    return false;
}

function getScrollXY() {
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == 'number') {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    var o = new Object()
    o.scrollX = scrOfX;
    o.scrollY = scrOfY;

    return o;
}

function displayInFrameSetup(url, w, h) {
    url = url + ((url.indexOf('?') == -1 ? '?' : '&') + 'ts=' + (new Date()).getTime());
    var el = $("PopupContainer");
    el.style.display = "block";
    el.style.width = w || "600px";
    el.style.height = h || "500px";
    el.style.zIndex = 801;

    var width = el.offsetWidth;
    var height = el.offsetHeight;
    // alert( width  + "Screen Width: " + screen.width);      
    var top = (screen.height - height - 100) / 2;
    var left = (screen.width - width) / 2;

    left = parseInt((document.body.clientWidth - width) / 2);
    //alert(document.body.clientWidth + " -- " + screen.width + " " + width);

    el.style.top = (top + document.body.scrollTop) + "px";
    el.style.top = getScrollXY().scrollY + 100 + "px";

    el.style.left = left + "px";
    //var code = "$('PopupContainer').style.top ='" + el.style.top + "'";
    //el.style.top = "-10000px";
    //create iframe if necessary
    createPopupIframe();
}

refreshPage = false;
function closeInFrame() {

    $('PopupContainer').style.display = 'none';

    var el = $("PopupContents");
    el.innerHTML = "";
    el.style.height = "0px";
    el.style.display = "none";
    //if model frame then delete frame history 
    if (getModalState()) {
        setModalState(false);
        deleteIframeHistory("PopupIframe");
    }
    else {
        window.open('about:blank', "PopupIframe", "", true);
    }
    if (refreshPage)
        refresh();

    return false;
}

function showInFrame() {

    $('PopupContainer').style.display = 'block';
    setModalState(true, 100);

    return false;
}

function deleteIframeHistory(id) {
    var iframe = $(id);
    if (iframe)
        iframe.parentNode.removeChild(iframe);
    return false;
}

function createPopupIframe() {
    var name = 'PopupIframe';
    if (!$(name)) {

        var p = $('PopupIframeParent');
        var el = document.createElement('iframe');
        el.id = name;
        el.name = name;
        el.frameBorder = '0';
        // el.scrolling='no';
        el.width = '100%';
        el.height = '100%';
        p.appendChild(el);
        // IMPORTANT: This is a BUG FIX for Internet Explorer 7 
        if (self.frames[name].name != name) self.frames[name].name = name;

    }
    $('PopupIframeParent').style.display = "block";
}

function refresh() {

    var sURL = unescape(window.location.pathname);
    window.location.href = sURL;
}


function displayPopUpModal(contentEl, w, h) {


    var el = $("PopupContainer");
    el.style.display = "block";
    el.style.width = w || "600px";
    el.style.height = h || "500px";
    el.style.zIndex = 801;

    var width = el.offsetWidth;
    var height = el.offsetHeight;
    var top = (screen.height - height - 100) / 2;
    var left = (screen.width - width) / 2;

    left = parseInt((document.body.clientWidth - width) / 2);

    el.style.top = (top + document.body.scrollTop) + "px";
    el.style.left = left + "px";
    h = el.style.height;
    $('PopupIframeParent').style.display = "none";
    el = $("PopupContents");
    el.style.display = "block";
    el.innerHTML = $(contentEl).innerHTML;

    el.style.height = h;
    el.style.overflow = "auto";

    //alert(el.innerHTML);

    setModalState(true);


    return false;
}


// If Internet Explorer then defince W3C XMLHttpRequest function 
if (!window.XMLHttpRequest)
    window.XMLHttpRequest = function () {
        var progIDs = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];
        for (var i = 0; i < progIDs.length; i++) {
            try {
                var xmlHttp = new ActiveXObject(progIDs[i]);
                return xmlHttp;
            } catch (e) { }
        }

        return null;
    }





/*===============================================================================*/
function hideShim(o) {

    var oShim = $(o.id + '.Shim');
    if (oShim) oShim.style.display = 'none';
};

function setModalState(state, zIndex) {

    var oShim = $('ModalShim');

    if (!oShim) {
        oShim = document.createElement('DIV');
        oShim.id = 'ModalShim';

        with (oShim.style) {
            zIndex = zIndex || 700;
            width = '100%';
            height = '500%';
            position = 'absolute';
            top = 0;
            left = 0;
            //backgroundColor = "Transparent";
            // backgroundColor = '#333333';
            //filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=40)';
            //opacity = .8;

        }
        oShim.style['-moz-opacity'] = .1;
        document.body.appendChild(oShim);

    }

    oShim.style.display = (state ? 'block' : 'none');
};

function getModalState() {
    var oShim = $('ModalShim');
    return (oShim && oShim.style.display != 'none');
};

/* Horizontal scroller */

function scrollMe(id, direction) {
    hideSomeThing();
    var el = document.getElementById(id);
    var newScrollLeft = 0;
    var scrollChunk = scrollMe.scrollChunks || 10;
    var scrollDelay = scrollMe.scrollDelayMillisecond || 20;

    var keepScrolling = true;

    if (direction == 'right')
        newScrollLeft = el.scrollLeft + scrollChunk;
    else
        newScrollLeft = el.scrollLeft - scrollChunk;


    if (newScrollLeft > (el.scrollWidth - el.offsetWidth)) {
        newScrollLeft = el.scrollWidth - el.offsetWidth;
        keepScrolling = false;
    }
    else if (newScrollLeft <= 0) {
        newScrollLeft = 0;
        keepScrolling = false;
    }

    el.scrollLeft = newScrollLeft;
    if (keepScrolling)
        scrollMe.timeout = setTimeout('scrollMe("' + id + '","' + direction + '")', scrollDelay);

    return false;

}


function stopScrolling() {
    if (scrollMe.timeout)
        clearTimeout(scrollMe.timeout);
    showSomething();
    return false;
}
function showSomething() {
    return;

}
function hideSomeThing() {
    return;

}
scrollMe.scrollChunks = 10;
scrollMe.scrollDelayMillisecond = 20;

if (!document.all) {
    HTMLElement.prototype.__defineGetter__("innerText", function () {
        var r = this.ownerDocument.createRange();
        r.selectNodeContents(this);
        return r.toString();
    });

};


/*Track Anchor Link Clicks 
START: to be cleaned up 
*/

/* getClickedObject - returns an object that caught whatever event is in process
*     note that this could be onload, onmouseover, etc.
* var eventObject = getClickedObject(this);
* then you can do eventObject.whatever and go about your business.
*/
function getClickedObject(obj) {
    var clickedElement = null;
    if (typeof obj != undefined && obj.tagName) {
        //this IS defined, so the browser is following the standards
        return obj;
    } else {
        //this isn't defined, which means IE is in play
        try {
            //get the element from the window event instead
            return window.event.srcElement;
        } catch (e) {
        }
    }
}

function rootPath() {
    return document.location.protocol + "//" + document.location.host;
}

function tc() {
    //fix  for ie not passing tis correctly
    var el = getClickedObject(this);
    var pos = getPosTopLeft(el);

    // alert("Top:" + pos.top + " Left:" + pos.left + " root path:" + rootPath);
    var rootPath = setLinkTrackingOn.rootPath;

    var imagePath = rootPath + "Utils/TrackMe.ashx?AnchorHref={0}&AnchorID={1}&AnchorText={2}&SourcePageX={3}&SourcePageY={4}";
    imagePath = imagePath._format([el.getAttribute("href") || "", el.getAttribute("id") || "", el.innerText, pos.left, pos.top]) + "&NoCache=" + (new Date());
    imagePath = encodeURI(imagePath);
    var img = new Image();
    //$("debug").innerHTML = imagePath;
    //alert(imagePath);
    img.src = imagePath;
    return true;
}

function showAllLinks() {

    //var links = $("ContentBody").getElementsByTagName("a");
    var links = document.getElementsByTagName("a");
    var s = "";
    for (i = 0; i < links.length; i++) {
        if (links[i].getAttribute("href").indexOf("http:") != -3) {
            s += ("<br>" + links[i].getAttribute("href"));
            links[i].onclick = tc;
        }
    }
    //$("debug").innerHTML = s;
}

function setLinkTrackingOn() {
    //var links = $("ContentBody").getElementsByTagName("a");
    var links = document.getElementsByTagName("a");

    for (i = 0; i < links.length; i++) {
        addEvent(links[i], "click", tc);
        //s  links[i].onclick=tc;
    }
}

/*Track Anchor Link Clicks 
END to be cleaned up 
*/
/*Insert Poll */
function insertPoll(args) {
    args.height = args.height || 250;
    args.width = args.width || 190;
    var pollFrame = '<iframe id="__' + args.pollID + '" style="width:' + args.width + 'px;height:' + args.height + 'px" src="/CMS/Poll/Poll.aspx?ID=' + args.pollID + '" frameborder="0" scrolling="no"></iframe>';
    document.write(pollFrame);
}


/* Comments Management  BEGIN*/
function saveComment(formEl) {
    var validForm = formField.submit(formEl);
    if (validForm) {
        formEl.action = rootPath() + "/CMS/Comments/SaveComment.aspx";
        displayInFrame('', '300px', '100px');
        return true;
    }
    return false;
}

formField = {};
formField.init = function (el) {
    el = document.getElementById(el);
    var inputs = el.getElementsByTagName('input');
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].type.indexOf('text') != -1 && inputs[i].title > "")
            inputs[i].value = inputs[i].title;
    }
    inputs = el.getElementsByTagName('textarea');
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].type.indexOf('text') != -1 && inputs[i].title > "")
            inputs[i].value = inputs[i].title;
    }
}

formField.focus = function (el) {
    if (el.value == el.title)
        el.value = '';
    el.style.color = "#333333";
}

formField.blur = function (el) {
    if (!el.value > "") {
        el.value = el.title;
    }
}

formField.submit = function (f) {
    var errMsg = "";

    var inputs = f.getElementsByTagName('input');
    var input = null;
    var reEmail = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;

    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].type.indexOf('text') != -1 && inputs[i].title.indexOf('required') > 0)
            if (inputs[i].value == inputs[i].title || trim(inputs[i].value).length == 0 || (inputs[i].name.indexOf('email') != -1 && !reEmail.test(inputs[i].value))) {
                errMsg += " * " + inputs[i].title + "\n";
                if (input == null)
                    input = inputs[i];
            }
    }

    inputs = f.getElementsByTagName('textarea');
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].type.indexOf('textarea') != -1 && inputs[i].title.indexOf('required') > 0)

            if (inputs[i].value == inputs[i].title || trim(inputs[i].value).length == 0)
                errMsg += " * " + inputs[i].title + "\n";
        if (input == null)
            input = inputs[i];
    }

    if (errMsg.length > 0) {
        errMsg = "Please enter required information:\n" + errMsg;
        alert(errMsg);
        input.focus();
        return false;
    } else
        return true;
}

function trim(str)
{ return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1'); }

function rate(el, rating, commentID) {

    var confirmMesg = "Please Confirm\n I want to give this comment a thumbs " + (rating > 0 ? "up" : "down") + ".";
    if ( confirm(confirmMesg)) {
        var countEl = el.nextSibling;
        saveRating(commentID, rating, countEl);
    }
    return false;
}

function replyTo(commentID) {
    document.getElementById("commentsForm")["commentParentID"].value = commentID;
    document.getElementById('commentContainer').scrollIntoView(true);
    return true;
}

function rootPath() {
    return document.location.protocol + "//" + document.location.host;
}

function saveRating(commentID, rating, countEl) {

    if (saveRating.http) return false;
    saveRating.http = new XMLHttpRequest();
    //make a connection to the server ... specifying that you intend to make a GET request 
    //to the server. Specifiy the page name and the URL parameters to send
    saveRating.http.open('get', rootPath() + '/CMS/Comments/SaveCommentRating.ashx?commentID=' + commentID + '&ratingUpOrDown=' + rating);
    //  + '&ts=' + (new Date()).getTime());
    //assign a handler for the response
    saveRating.http.onreadystatechange = function () {
        if (saveRating.http.readyState == 4) {
            if (saveRating.http.responseText.indexOf('ERROR') != -1)
                alert("Error:\nRating not updated.");
            else
{
 //alert(saveRating.http.responseText);
               countEl.nodeValue = saveRating.http.responseText;
}
            saveRating.http = null;
        }
    }
    //actually send the request to the server
    saveRating.http.send(null);
}
/* Comments Management  END*/
     