





/*NOT USED ANYMORE -- LOOK IN /scripts/global/tv/js (sucka!)*/
























/* jQuery function that returns false */
jQuery.fn.extend({
  returnFalse: function() {
    return false;
  }
});

/*
  Extends the Element native object to include some nifty shortcut methods.
*/
Element.implement({
	isVisible: function() {
		return this.getStyle('display') != 'none';
	},
	toggle: function() {
		this[this.isVisible() ? 'hide' : 'show']();
        return false;
	},
  toggleFade: function(mSecs) {
      this[this.isVisible() ? 'fadeOut' : 'fadeIn'](typeof mSecs == 'number' ? mSecs : null);
      return false;
  },
	hide: function() {
		var d;
		try {
			//IE fails here if the element is not in the dom
			d = this.getStyle('display');
		} catch(e){}
		this.store('originalDisplay', d||'block');
		this.setStyle('display','none');
		return false;
	},
	show: function(display) {
		original = this.retrieve('originalDisplay')?this.retrieve('originalDisplay'):this.get('originalDisplay');
		this.setStyle('display',(display || original || 'block'));
		return false;
	},
    fadeIn: function(mSecs) {
        this.setStyle('opacity',0);
        this.setStyle('display','block');
        this.set('tween', {duration:(typeof mSecs == 'number' ? mSecs : 200)});
        this.tween('opacity',1);
        return false;
    },
    fadeOut: function(mSecs) {
        var fade = (typeof mSecs == 'number' ? mSecs : 100);
        this.set('tween', {duration:(typeof mSecs == 'number' ? mSecs : 100)});
        this.tween('opacity',0);
        this.setStyle.delay(fade, this,['display','none']);
        return false;
    },
    swapClass: function(remove, add) {
        return this.removeClass(remove).addClass(add);
    },
    toggleClass: function (class1, class2) {
        this.setAttribute('class', (this.getAttribute('class') == class1 ? class2 : class1));
        return false;
    }
});


/******************************************************************
 function ajaxReplace
     Ajax function to replace an element's innerHTML with the
     result of a url.

 Requires
     theElement - the element whose innerHTML gets replaced
     theQuery    - the url (incl querystring)

 Optional
     loginInstr - text to explain why the user has to log in
        (if omitted, then user not required to log in)
     busyIcon - element to show while waiting

 Returns
     false, always.
********************************************************************/
function ajaxReplace(theElement, theQuery, loginInstr, busyIcon){
    if((typeof loginInstr != "string") || loginCheck(loginInstr)) {
        if (typeof busyIcon != "undefined"){
            busy_icon.show();
        }
        var myRequest = new Request(
            {
                method: 'get',
                url: theQuery,
                onComplete: function(html){
                    theElement.innerHTML = html;
                    if (typeof busyIcon != "undefined"){
                        busy_icon.hide();
                    }
                }
            }
        );
        myRequest.send();
    }
    return false;
}



/**
* niftyPanel - creates a modal panel with whatever ID you provide.
* Bases it on $('nifty_panel') element (which must be present in your markup somewhere).
* Usage:   myPanel = new niftyPanel('my_ID');
*
* Methods
*   close() - close the panel
*
*   displayResults(theForm, loginText) - display the results of a form in the panel.
*     If loginText included, then will require login before submitting.
*     Usage:  onsubmit="return ($defined(myPanel) && myPanel.displayResults(this, 'You must log in to record to TiVo'))"
*
*   displayHREF(theHREF, loginText) - same as above but takes an href rather than a form.
*     Usage: onclick="return ($defined(myPanel) && displayHREF(this.href, 'Please log in first'))"
*
* ...the "$defined" keeps it from executing before panel is finished loading.
*
* NOTES
*   Uses CSS class NIFTY_PANEL
*
*   For best results, split your content into classes .content and .wait_state --
*   then niftyPanel will display .wait_state while waiting for an ajax interaction to
*   complete
*
*   You can overwrite whenDone with a function you want it to run when complete.
*
**/
var globalModalPanel;
function niftyPanel(elemID){
    this.id = elemID;

    this.whenDone = function(){}; //feel free to override

    //display the panel
    this.show = function(){
        //delete if already exists
        if ($(this.id)) {
            var el = $(this.id);
            el = el.parentNode.removeChild(el);
            delete el;
        }

        //create the node and append to body
        this.domElem  = $('nifty_panel').cloneNode(true);
        this.domElem.setAttribute('id',this.id);
        document.body.appendChild(this.domElem);
        this.domElem.style.display='block';

        this.contentArea = this.domElem.getElement('.content_area');

        //give it a global handle while it's up
        globalModalPanel = this;
    };

    //Make sure panel is up and then display waitstate content if any
    this.waitState = function(){
        if (globalModalPanel == this) {
            if (this.contentArea.getElement('.wait_state') && this.contentArea.getElement('.content')){
                this.contentArea.getElement('.content').setStyle('display','none');
                this.contentArea.getElement('.wait_state').setStyle('display','block');
            }
        } else {
            this.show();
        }
    };

    //hide it
    this.close = function(){
        this.domElem.setStyle('display','none');
        globalModalPanel = null;
    };

    //submit a form and display its results in panel
    this.displayResults = function(theForm, loginText){
        if((typeof loginText != 'string') || loginCheck(loginText)) {
            this.waitState();
            var submitTheForm = new Request({
                url: theForm.action,
                method: 'get',
                onSuccess:   function(html){
                    globalModalPanel.contentArea.innerHTML = html;
                    globalModalPanel.contentArea.getElement('.wait_state') && globalModalPanel.contentArea.getElement('.wait_state').setStyle('display','none');
                    globalModalPanel.contentArea.getElement('.content') && globalModalPanel.contentArea.getElement('.content').setStyle('display','block');
                    globalModalPanel.whenDone();
                }
            });


            //get the form inputs
            var paramString = '';
            for (i=0; i<theForm.elements.length; i++) {
                if ((theForm.elements[i].type != 'radio' && theForm.elements[i].type != 'checkbox') || theForm.elements[i].checked){
                    paramString += theForm.elements[i].name + '=' + theForm.elements[i].value +'&';
                }
            }
            submitTheForm.send(paramString);
        }
        return false;
    };

    //submit a url and display the result in panel
    this.displayHREF = function(theHREF, loginText){
        if((typeof loginText != 'string') || loginCheck(loginText)) {
            this.waitState();
            var displayTheHREF = new Request({
                url: theHREF,
                method: 'get',
                onSuccess:   function(html){
                    globalModalPanel.contentArea.innerHTML = html;
                    globalModalPanel.contentArea.getElement('.wait_state') && globalModalPanel.contentArea.getElement('.wait_state').setStyle('display','none');
                    globalModalPanel.contentArea.getElement('.content') && globalModalPanel.contentArea.getElement('.content').setStyle('display','block');
                    globalModalPanel.whenDone();
                }
            });
            displayTheHREF.send();
        }
        return false;
    }



}

