var $D = YAHOO.util.Dom;
var $E = YAHOO.util.Event;
var $A = YAHOO.util.Anim;
var $M = YAHOO.util.Motion;

YAHOO.util.AnimMgr.fps = 500;

function hideDiv(divId) {
    _$('#' + divId).hide();
}

function showDiv(divId) {
    _$('#' + divId).show();
}

function killDiv(divId) {
    hideDiv(divId);
    _$('#' + divId).setContent('');
}

function stripHTML(html) {
	var re= /<\S[^><]*>/g
	html = html.replace(re, "");
	return html;
}

function confirmCancel(question, url) {
    handleCancel = function(e) {
        this.hide();
        return false;
    }

    handleConfirm = function(e) {
        this.hide();
        location.href = url;
    }

    confirmCancelDlg = new YAHOO.widget.SimpleDialog("confirmCancelDlg", { visible:false, width: "20em", effect:[{effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.25},{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25}], fixedcenter:true, modal:true, draggable:false });

    confirmCancelDlg.setHeader("Warning!");
    confirmCancelDlg.setBody(question);
    confirmCancelDlg.cfg.setProperty("icon", YAHOO.widget.SimpleDialog.ICON_WARN);

    confirmCancelDlg.cfg.queueProperty("buttons", [
                                    { text:"OK", handler:handleConfirm, isDefault:true },
                                    { text:"Cancel", handler:handleCancel }
                                ]);

    var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn:handleCancel ,scope:confirmCancelDlg, correctScope:true} );
    confirmCancelDlg.cfg.queueProperty("keylisteners", listeners);

    confirmCancelDlg.render(document.body);
    confirmCancelDlg.show();
}

function languageDlg() {
    var handleCancel = function() {
        this.cancel();
    }
    var handleSubmit = function() {
        this.submit();
    }


    dlgDialog = new YAHOO.widget.Dialog("translate", { modal:true, visible:false, width:"200px", fixedcenter:true, constraintoviewport:true, draggable:true });

    dlgDialog.setHeader('Choose your language');

    dlgDialog.setBody('<form action="index.php?action=setLanguage" method="post">\
                       <select name="language" style="width: 190px;">\
                           <option value="en">English</option>\
                           <option value="pt">Portuguese</option>\
                           <option value="de">German</option>\
                           <option value="fr">French</option>\
                           <option value="es">Spanish</option>\
                           <option value="it">Italian</option>\
                           <option value="ja">Japanese</option>\
                       </select>\
                       </form>');

    var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn:handleCancel,scope:dlgDialog,correctScope:true} );

    dlgDialog.cfg.queueProperty("keylisteners", listeners);
    dlgDialog.cfg.queueProperty("buttons", [ { text:"Submit", handler:handleSubmit },
                                               { text:"Cancel", handler:handleCancel }
                                             ]);

    dlgDialog.render(document.body);

    dlgDialog.cfg.setProperty("postmethod", "form");
    dlgDialog.show();
}

function generateFeed() {
    var type = document.feeds.t.options[document.feeds.t.selectedIndex].value;
    var orientation = document.feeds.o.options[document.feeds.o.selectedIndex].value;
    var media = document.feeds.f.options[document.feeds.f.selectedIndex].value;

    _$('#feedLink').setContent('<a href="feeds.php?o=' + orientation + '&amp;t=' + type + '&amp;f=' + media + '">Your RSS Feed</a>: <input type="text" value="http://pornotube.com/feeds.php?o=' + orientation + '&amp;t=' + type + '&amp;f=' + media + '" style="width: 400px;" onclick="this.select()" />');
}

/* ====================================================================================== */
/* ajaxSpinner                                                                            */
/* START ================================================================================ */

YAHOO.widget.ajaxSpinner = function() {
    this.init();
};

YAHOO.widget.ajaxSpinner.prototype.init = function() {
    this.Spinner = new YAHOO.widget.Overlay("ajaxSpinner", {visible:true});
    this.Spinner.render(document.body);
    
    this.Spinner.cfg.setProperty("visible", false);
    
    this.Spinner.setBody('<p style="font-weight: bold;">Working..</p>');
    
    this.Spinner.cfg.setProperty("width", "75px");
    this.Spinner.cfg.setProperty("x", $D.getViewportWidth() - 125);
    this.Spinner.cfg.setProperty("y", 10);
    this.Spinner.cfg.setProperty("zIndex", 990);
    this.Spinner.cfg.setProperty("constraintoviewport", true);
    this.Spinner.cfg.setProperty("monitorresize", true);
    
}

YAHOO.widget.ajaxSpinner.prototype.show = function(e) {
    this.Spinner.cfg.setProperty("visible", true);
    this.Spinner.render();
}

YAHOO.widget.ajaxSpinner.prototype.hide = function() {
    this.Spinner.cfg.setProperty("visible", false);
    this.Spinner.render();
}

/* ====================================================================================== */
/* ajaxSpinner                                                                            */
/* END ================================================================================== */