﻿YAHOO.namespace("nbcore");
YAHOO.namespace("netboat.calendar");
YAHOO.namespace("netboat.uploadDialogs");
YAHOO.namespace("netboat.action");
var tmpBoxOffsetHeight;
var uploadImageDialog;

//------------------------------------------------------------------------------------
function getAbsTop(el) { return (el.offsetParent) ? el.offsetTop + getAbsTop(el.offsetParent) : el.offsetTop; }
function getAbsLeft(el) { return (el.offsetParent) ? el.offsetLeft + getAbsLeft(el.offsetParent) : el.offsetLeft; }
function $() { var elements = new Array(); for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == 'string') element = document.getElementById(element); if (arguments.length == 1) return element; elements.push(element); } return elements; }
function $t(tagname, parent) { return (parent) ? parent.getElementsByTagName(tagname) : document.getElementsByTagName(tagname) }
/* (un)register function for document onclick event*/
function docOnClick(func) { if (func) { document.onclick = func } else { document.onclick = function() { return; } } }
function stripTags(text) { return text.replace(/<\/?[^>]+>/gi, ''); }


YAHOO.util.Event.onContentReady("nb-main-navigation", function () {
     var oMenuBar = new YAHOO.widget.MenuBar("nb-main-navigation", { 
          autosubmenudisplay: true, 
          hidedelay: 750, 
          lazyload: true });
     oMenuBar.render();
 });            
                




YAHOO.nbcore.SelectPortalLanguage = function(e) {
    var t = (e ? YAHOO.util.Event.getTarget(e) : null);
    location.href = "/?lang=" + t.value;
}


YAHOO.util.Event.onDOMReady(function() { YAHOO.util.Event.addListener('nb-choosePortalLang', 'change', YAHOO.nbcore.SelectPortalLanguage); });




//-------------------------------------------------------------------------------------------
function validateTerm() {
    if (!Validation.isValidDate($(fieldPrefix + "AdTerm").value)) {
        alert( Messages.error_date_format);
    }
}

function setTermTime(duration) {
    var txtDate1 = $(fieldPrefix + "AdTerm");
    var now = new Date();
    txtDate1.value = now.add("mo", duration).toShortFormat();
}

YAHOO.netboat.calendar.init = function() {

    YAHOO.netboat.calendar.cal1 = new YAHOO.widget.Calendar("cal1", "calUntilContainer",
      { title:  Messages.misc_choose_expiration_date,
          close: true,
          draggable: true,
          mindate: new Date,
          maxdate: (new Date()).add("mo", 6)
      });

    YAHOO.netboat.calendar.cal1.render();
    YAHOO.netboat.calendar.cal1.hide();
    YAHOO.netboat.calendar.cal1.selectEvent.subscribe(function(type, args, obj) {
        var dates = args[0];
        var date = dates[0];
        var year = date[0];
        var month = (date[1] < 10) ? "0" + date[1] : date[1];
        var day = (date[2] < 10) ? "0" + date[2] : date[2];


        var txtDate1 = document.getElementById(fieldPrefix + "AdTerm");
        txtDate1.value = day + "." + month + "." + year;
        YAHOO.netboat.calendar.cal1.hide();
    }
	   );


    $('calUntilContainer').style.left = (getAbsLeft($(fieldPrefix + 'ShowCalUntil')) + 20) + "px";
    $('calUntilContainer').style.top = (getAbsTop($(fieldPrefix + 'ShowCalUntil')) - 100) + "px";

}
//-------------------------------------------------------------------------------------------

YAHOO.netboat.initUploadDialogs = function() {

    uploadImageDialog = new YAHOO.widget.Dialog("uploadImageDialog", {
        width: "320px",
        fixedcenter: true,
        constraintoviewport: true,
        underlay: "shadow",
        close: true,
        visible: false,
        draggable: true,
        buttons: [{ text: "Cancel", handler: function() { this.hide(); }, isDefault: true}]

    });

}


//-------------------------------------------------------------------------------------------

YAHOO.netboat.initVideoUploadDialogs = function() {

    rmVideoDialog = new YAHOO.widget.Dialog("dialogContainer", {
        width: "320px",
        underlay: "shadow",
        close: true,
        visible: false,
        draggable: true,
        buttons: [{ text: "Yes", handler: handleVideoDeletion, isDefault: true },
                  { text: "No", handler: handleVideoCancel}]

    });

    rmImageDialog.setHeader(Messages.misc_confirmation);
    rmImageDialog.setBody(Messages.misc_confirmation_delete_video);
    $('dialogContainer').style.position = "absolute";


    uploadVideoDialog = new YAHOO.widget.Dialog("uploadVideoDialog", {
        width: "320px",
        fixedcenter: true,
        constraintoviewport: true,
        underlay: "shadow",
        close: true,
        visible: false,
        draggable: true,
        buttons: [{ text: "Cancel", handler: handleCancel, isDefault: true}]

    });

}


//-------------------------------------------------------------------------------------------





//-------------------------------------------------------------------------------------------

/*
* Fade out the layer with the specified id
* This method calls it self until the layer has full transparency
* To use the effect, call function blindUp(id,orgHeight)!
*/
function fadeOut(layerId, opac) {

    if (!opac) opac = 100;

    var lay = document.getElementById(layerId);
    if (lay == null) return;
    if (opac > 0) {
        opac = opac - 10;
        if (tmpBoxOffsetHeight)
            lay.style.height = ((tmpBoxOffsetHeight / 100) * opac) + "px";

        setFadeOpacity(layerId, opac);
        setTimeout('fadeOut("' + layerId + '","' + opac + '")', 50);
    } else {
    lay.style.display = "none";
    Element.remove(layerId);
    }
}


/*
* set value of transparancy for the given element
*/
function setFadeOpacity(id, opac) {
    var lay = document.getElementById(id);
    try {
        if (Browser.IE && !Browser.IE7) {
            lay.filters.alpha = "opacity = " + opac;
        } else {
            lay.style.MozOpacity = opac / 100;
            lay.style.opacity = opac / 100;
        }
    } catch (e) {
        EException.handle(e);
        return true;
    }
    return false;
}
