function openCalendar(strUrl){
        tb_show(null,'#TB_inline?height=20&width=250&inlineId=loader_div',null);
        $('#msgCalendarContent').html("<iframe id='iframecalendar' class='msgCalendarTable' src='"+strUrl+"' scrolling='no' frameborder='0'></iframe>");
}
function showCalendar (){
    $('#msgCalendar').show();
	tb_remove();
}
function hideCalendar () {
	$('#msgCalendar').hide();
	tb_remove(); 
}

/**
 * Sets a COOKIE value
 * @param   string  The name of the COOKIE
 * @param   string  The value for the COOKIE
 * @param   date    The date at which the COOKIE expires, or leave blank to use the current session's enddate
 * @param   string  The path for which the COOKIE is valid, or leave blank to use the current document's path
 * @param   string  The domain for which the COOKIE is valid, or leave blank to use the current document's domain
 * @param   boolean Whether or not the COOKIE should use secure transmission
 * @return  void
 */
function setCookie(strName, strValue, datExpires, strPath, strDomain, blnSecure){
    strPath = '/';
    document.cookie = strName + "=" + escape(strValue) +
                      ((datExpires) ? "; expires=" + datExpires.toGMTString() : "") +
                      ((strPath)    ? "; path=" + strPath : "") +
                      ((strDomain)  ? "; domain=" + strDomain : "") +
                      ((blnSecure)  ? "; secure" : "");
}

/**
 * Returns the string value of a COOKIE, or null if it was not set
 * @param   string  The name of the COOKIE
 * @return  string  The value of the COOKIE
 */
function getCookie(strName){
    var objCookie = document.cookie;
    if (!objCookie) return;
    var strPrefix = strName + "=";
    var intStart  = objCookie.indexOf("; " + strPrefix);
    if (intStart == -1){
        intStart = objCookie.indexOf(strPrefix)
        if (intStart != 0) return null;
    } else {
        intStart += 2;
    }

    var intEnd = objCookie.indexOf(";", intStart);
    if (intEnd == -1) intEnd = objCookie.length;
    return unescape(objCookie.substring(intStart + strPrefix.length, intEnd));
}

/**
 * Deletes a COOKIE
 * @param   string  The name of the cookie
 */
function deleteCookie(strName, strPath, strDomain){
    if (getCookie(strName)){
        document.cookie = strName + "=" +
                          ((strPath) ? "; path=" + strPath : "") +
                          ((strDomain) ? "; domain=" + strDomain : "") +
                          "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function fancy_alert(text, timeout, height)
{
    if(!timeout) {
        timeout = 5000;
    }
    if(!height) {
        height = 30;
    }

    $("#fancy_alert div").html(text);
    tb_show(null,"#TB_inline?height="+height+"&width=450&inlineId=fancy_alert",null, true);
    setTimeout("tb_remove();", timeout);

    // When the thickbox closes set the focus on the first input field (if there is one)
    $("#TB_overlay").unload(function(e){
          $('input:visible:enabled:first').focus();
    });
}

/**
 * Converts a XHtml url to javascript
 * @param   string  The url to convert
 * @return  string  The converted url
 */
function urlToJs(strUrl){
    return strUrl.replace('&amp;', '&');
}

wbds_counttags=0;
wbds_serverup=true;
wbds_firstdone=false;
wbds_waitserver=4000;
wbds_pageid=-1;

function wbds_testserver() {
	if (wbds_waitserver>0 && !wbds_firstdone) {
		wbds_waitserver-=200;
		setTimeout('wbds_testserver()',200);
	} else if (!wbds_firstdone) {
		wbds_serverup=false;
		if (document.all) {
			var ua=navigator.userAgent;
			if (parseFloat(ua.slice(ua.indexOf('MSIE')+5))>=5) document.scripts['wbds_tag0'].src='//';
		}
	}
}

function wbds_writeTag(wbds_size, wbds_position) {
	var rnd=Math.round(Math.random()*100000000);
	if (wbds_pageid<0) wbds_pageid=Math.round(Math.random()*100000000);
	if (wbds_serverup) {
		document.write('<scr'+'ipt language="javascript" id="wbds_tag'+wbds_counttags+'" src="');
		document.write(wbds_target+'/ADSIZE='+wbds_size+'/AAMSZ='+wbds_size+'/POSITION='+wbds_position+'/PAGEID='+wbds_pageid+'/ACC_RANDOM='+rnd+'"></scr'+'ipt>');
		if (wbds_counttags++==0) setTimeout('wbds_testserver()',200);
	}
}


var ajaxIframeObject;
function ajaxRequest(strUrl){

    // Pass the request to the server
    if (!document.createElement) {return true};

    // If the document supports dynamic creation of elements, create the iframe object
    if (!ajaxIframeObject && document.createElement) {
        try {
            var tempIFrame=document.createElement('iframe');
            tempIFrame.setAttribute('id','ajaxFrame');
            tempIFrame.style.border = '0px';
            tempIFrame.style.width  = '800px';
            tempIFrame.style.height = '400px';
            ajaxIframeObject = document.body.appendChild(tempIFrame);

            if (document.frames) {
                // this is for IE5 Mac, because it will only
                // allow access to the document object
                // of the IFrame if we access it through
                // the document.frames array
                ajaxIframeObject = document.frames['ajaxFrame'];
            }
        } catch(exception) {
            // This is for IE5 PC, which does not allow dynamic creation
            // and manipulation of an iframe object. Instead, we'll fake
            // it up by creating our own objects.
            iframeHTML='\<iframe id="ajaxFrame" style="';
            iframeHTML+='border:0px;';
            iframeHTML+='width: 0px;';
            iframeHTML+='height: 0px;';
            iframeHTML+='"><\/iframe>';
            document.body.innerHTML+=iframeHTML;
            ajaxIframeObject = new Object();
            ajaxIframeObject.document = new Object();
            ajaxIframeObject.document.location = new Object();
            ajaxIframeObject.document.location.iframe = document.getElementById('ajaxFrame');
            ajaxIframeObject.document.location.replace = function(location) {
                this.iframe.src = location;
            }
        }
    }

    if (navigator.userAgent.indexOf('Gecko') !=-1 && !ajaxIframeObject.contentDocument) {
        // we have to give NS6 a fraction of a second
        // to recognize the new IFrame
        setTimeout('ajaxRequest(\''+strUrl+'\')',10);
        return false;
    }

    if (ajaxIframeObject.contentDocument) {
        // For NS6
        IFrameDoc = ajaxIframeObject.contentDocument;
    } else if (ajaxIframeObject.contentWindow) {
        // For IE5.5 and IE6
        IFrameDoc = ajaxIframeObject.contentWindow.document;
    } else if (ajaxIframeObject.document) {
        // For IE5
        IFrameDoc = ajaxIframeObject.document;
    } else {
        return true;
    }

	if (IFrameDoc.location.replace) {
	    IFrameDoc.location.href = strUrl;
		// IFrameDoc.location.replace(strUrl);
	}
    else {
		IFrameDoc.location.href = strUrl;
	}
}

/**
 * Resizes the browser window to fit to contents
 */
function autoFitWindow(){

    if (self.scrollWidth){
    	intWidth = self.scrollWidth;
    	intHeight = self.scrollHeight;
    }else if (document.documentElement && document.documentElement.scrollWidth){
    	intWidth = document.documentElement.scrollWidth;
    	intHeight = document.documentElement.scrollHeight;
    }else if (document.body){
    	intWidth = document.body.scrollWidth;
    	intHeight = document.body.scrollHeight;
    }

    if (window.offsetHeight){
        intWidth  += window.offsetWidth  - window.clientWidth;
        intHeight += window.offsetHeight - window.clientHeight;
    } else if (window.document && window.document.offsetHeight){
        intWidth  += window.document.offsetWidth  - window.document.clientWidth;
        intHeight += window.document.offsetHeight - window.document.clientHeight;
    } else if (window.document.documentElement && window.document.documentElement.offsetHeight){
        intWidth  += window.document.documentElement.offsetWidth  - window.document.documentElement.clientWidth;
        intHeight += window.document.documentElement.offsetHeight - window.document.documentElement.clientHeight;
    }
    window.resizeTo(intWidth + 6, intHeight + 106);

}

/**
 * Global variables
 */
var TB_Ajax_IFrame_Count  = 0;
var TB_Ajax_Request_Stack = new Array();

/**
 * TB_Ajax_Request
 * ---------------
 * Class to make ajax requests
 */
function TB_Ajax_Request(){

    // Properties
    this.intRequestId    = TB_Ajax_Request_Stack.length;
    this.objRequest      = false;
    this.objIFrame       = false;
    this.blnIFrame       = false;
    this.blnLoaded       = false;
    this.objCallback     = false;
    this.arrCallbackArgs = new Array();
    this.strData         = "";

    // Methods
    this.get          = TB_Ajax_Request_Get;
    this.create       = TB_Ajax_Request_Create;
    this.useIFrame    = TB_Ajax_Request_UseIFrame;
    this.checkState   = TB_Ajax_Request_CheckState;
    this.setCallback  = TB_Ajax_Request_SetCallback;
    this.doCallback   = TB_Ajax_Request_DoCallback;
    this.IFrameLoaded = TB_Ajax_Request_IFrameLoaded;

    // Code
    TB_Ajax_Request_Stack[this.intRequestId] = this;
}

function TB_Ajax_Request_UseIFrame(){
    this.blnIFrame = true;
}

function TB_Ajax_Request_SetCallback(strFunction){
    this.objCallback = strFunction;

    for(var i=1;i<arguments.length;i++){
        this.arrCallbackArgs[this.arrCallbackArgs.length] = arguments[i];
    }
}

function TB_Ajax_Request_DoCallback(){
    strCallback = "this.objCallback(this.strData";
    for(var i=0;i<this.arrCallbackArgs.length;i++){
        strCallback += ",this.arrCallbackArgs[" + i + "]";
    }
    strCallback += ")";
    eval(strCallback);
}

function TB_Ajax_Request_IFrameLoaded(){
    this.blnLoaded = true;
    if (this.objIFrame.document) this.strData = this.objIFrame.document.getElementsByTagName("body")[0].innerHTML;
    else strData = this.objIFrame.contentDocument.getElementsByTagName("body")[0].innerHTML;
    this.doCallback();
}

function TB_Ajax_Request_CheckState(){
    if (this.objRequest.readyState != 4) return;
    this.blnLoaded = true;

    this.strData = this.objRequest.responseText;
    delete this.objRequest;
    this.doCallback();
}

function TB_Ajax_Request_Get(strUrl){
    strUrl += (strUrl.indexOf('?') != -1 ? '&' : '?') + 'TB_AJAX_REQUEST_ID=' + this.intRequestId;


    // Use an IFrame?
    if (this.blnIFrame == true){
        strUrl += '&TB_AJAX_REQUEST_IFRAME=1';
        if (this.objIFrame.document)
            this.objIFrame.document.location.href = strUrl;
        else this.objIFrame.src = strUrl;
    }

    // Or XMLHttp object?
    else {
        this.objRequest.onreadystatechange = new Function("TB_Ajax_Request_Stack[" + this.intRequestId + "].checkState();");
        this.objRequest.open('GET', strUrl);
        // .substr(0, strUrl.indexOf('?')), true);
		this.objRequest.send(strUrl.substr(strUrl.indexOf('?')+1));
    }
}


function TB_Ajax_Request_Create(){

    // Use true AJAX?
    if (this.blnIFrame == false){

        // Create the XMLHttpRequest object
        try{
            this.objRequest = new XMLHttpRequest();
        }

        // In IE this will result in an error because it uses an ActiveX component instead
        catch(e){

            // So try to create the ActiveX object
            try{
                this.objRequest = new ActiveXObject("Msxml2.XMLHTTP");
            }

            // In IE 5.5 this also fails, because another ActiveX component is used
            catch(e){

                // So create the older ActiveX object
                try{
                    this.objRequest = new ActiveXObject("Microsoft.XMLHTTP");
                }

                // If this also failed, try to use an IFrame instead
                catch(e) {
                    this.useIFrame();
                    this.create();
                }
            }
        }
    }

    // Or fake it using an IFrame?
    else {

        // We'll need to dynamically create an iframe
        if (!document.createElement) return false;

        try {

            // Try to create the IFrame dynamically
            this.objIFrame = document.createElement('iframe');
            this.objIFrame.setAttribute('id', 'TB_AJAX_IFRAME_OBJECT_' + TB_Ajax_IFrame_Count);
            this.objIFrame.style.border = '0px';
            this.objIFrame.style.height = '0px';
            this.objIFrame.style.width  = '0px';

            this.objIFrame = document.body.appendChild(this.objIFrame);
            if (document.frames) this.objIFrame = document.frames['TB_AJAX_IFRAME_OBJECT_' + TB_Ajax_IFrame_Count];

            var i = 0;
            while(i<1000) i++;
            TB_Ajax_IFrame_Count++;
        }

        // This will fail on IE5
        catch (e) {

            document.body.innerHTML += '\<iframe id="TB_AJAX_IFRAME_OBJECT_'
                                     + TB_Ajax_IFrame_Count
                                     + '" style="border:0px;width:0px;height:0px;"><\/iframe>';

            this.objIFrame                           = new Object();
            this.objIFrame.document                  = new Object();
            this.objIFrame.document.location         = new Object();
            this.objIFrame.document.location.replace = function(location) {this.iframe.src = location;}

            if (document.getElementById){
                this.objIFrame.document.location.iframe = document.getElementById('TB_AJAX_IFRAME_OBJECT_' + TB_Ajax_IFrame_Count);
            } else if (document.all){
                this.objIFrame.document.location.iframe = document.all['TB_AJAX_IFRAME_OBJECT_' + TB_Ajax_IFrame_Count];
            } else if (document.layers){
                this.objIFrame.document.location.iframe = document.layers['TB_AJAX_IFRAME_OBJECT_' + TB_Ajax_IFrame_Count];
            }

            TB_Ajax_IFrame_Count++;
        }

    }
}


if (!document.all) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;

var intMouseX = 0;
var intMouseY = 0;

function getMouseXY(e) {
    if (document.all) { // grab the x-y pos.s if browser is IE
        intMouseX = event.clientX + document.documentElement.scrollLeft;
        intMouseY = event.clientY + document.documentElement.scrollTop;
    } else {  // grab the x-y pos.s if browser is NS
        intMouseX = e.pageX + window.pageXOffset;
        intMouseY = e.pageY + window.pageYOffset;
    }
    if (intMouseX < 0){intMouseX = 0;}
    if (intMouseY < 0){intMouseY = 0;}
}

function ajaxLoadIFrame(strUrl, strCallback){
    var objAjax = new TB_Ajax_Request();
    objAjax.useIFrame();
    objAjax.create();
    if (strCallback) objAjax.setCallback(strCallback);
    objAjax.get(strUrl);
}

function ajaxLoadRequest(strUrl, strCallback){
    var objAjax = new TB_Ajax_Request();
    objAjax.create();
    if (strCallback) objAjax.setCallback(strCallback);
    objAjax.get(strUrl);
}