﻿/*
* @projectDescription 	Natrelle interface application project file
*                       
* @author	Tom Newton  Tom.Newton@rosetta.com
* @version	0.1
*
* REQUIRES rosetta application framework
*/

/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Global Properties/Methods
========================================================================================== */
/**
 * @namespace natrelle
 */
var natrelle = natrelle || {};

natrelle.application = new ROSETTA.application(); // ROSETTA application object helper class

/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Initialize
========================================================================================== */
natrelle.application.loadLibrary("yuiloader"); // require yuiloader library

// callback to execute when all global external files/libraries are ready
natrelle.application.setOnLoadCallback(function(){
	// create global yui loader obj (REQUIRES YUILoader preloaded)
    natrelle.YUILoader = new YAHOO.util.YUILoader();
	// set  path to YUI library files
    natrelle.YUILoader.base = natrelle.application.YUIPath;
	
	//tell a friend
    if (window.location.href.indexOf("taf.aspx") >= 0){
        document.getElementById("taf").style.visibility = "hidden";
    } else {
        natrelle.ptaf = new natrelle.taf();
        natrelle.ptaf.init();
    }	
});

/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*  Tell A Friend Object/Methods
============================================ */
natrelle.taf = function() {
    this.targetDiv = "taf";
    this.panel_id = "yuidialog_tafpanel";
    this.close_id = "taf_close"; //id of elem that close/hide form
    this.submit_id = "taf_submit"; //id of elem that submit form
    this.pageContent; //place holder for xml/html form content and success content below
    this.formStyles = {
        defaultInputColor: "#3966AA",
        errorInputColor: "#FF0000",
        defaultLabelColor: "#707070",
        errorLabelColor: "#FF0000"
    }
    this.contentSuccess;
    this.targetObj;

    this.tafPanel = new YAHOO.widget.Panel(this.panel_id, {visible:true, draggable:false, close:false, modal:true, zIndex:20000, underlay:"none", iframe:true, monitorresize:true, width:"605px", height:"328px", context:[this.targetDiv,"tr","tr"],effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}, {effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.5}]});

//    YAHOO.namespace("Rosetta.Natrelle.WebParts");
//    YAHOO.Rosetta.Natrelle.WebParts.tafPanel = new YAHOO.widget.Panel(this.panel_id, { visible: false, draggable: false, close: false, modal: true, zIndex: 20000, underlay: "none", iframe: false, monitorresize: true, width: "605px", height: "328px", context: [this.targetDiv, "tr", "tl"], effect: [{ effect: YAHOO.widget.ContainerEffect.FADE, duration: 0.5 }, { effect: YAHOO.widget.ContainerEffect.SLIDE, duration: 0.5}] });
};

natrelle.taf.prototype.init = function() {
    if (document.getElementById(this.targetDiv)) {
        var obj = this;
        this.targetObj = document.getElementById(obj.targetDiv);
        alert('target div: ' + this.targetObj);
        // send the user to the static page if on the ba modeler page
        if (window.location.href.indexOf("modeler") >= 0) {
            YAHOO.util.Event.addListener(obj.targetDiv, "click", function() {
                window.location = "/utilities/taf.aspx";
            });
        } else {
            //load any required files, css for the taf in this case
            var loader = new YAHOO.util.YUILoader();
            loader.addModule({
                name: "taf_css",
                type: "css",
                fullpath: "/Style Library/en-us/Natrelle/taf.css",
                varName: "TAF_CSS"
            });
            loader.require(['taf_css']);
            loader.onSuccess = function() {
                obj.loadContent();
            };
            loader.insert();
        }
    }
};

natrelle.taf.prototype.loadContent = function() {
    //Load XML Content
    var obj = this; //internal obj re-reference
    obj.renderPanel();
};

natrelle.taf.prototype.renderPanel = function() {
    alert('Render Panel');
    var obj = this; //internal obj re-reference
    //YAHOO.Rosetta.Natrelle.WebParts.tafPanel.render();
    obj.tafPanel.render();
    //now that the form is rendered in the dom, we can intialize the form
    //and all the form listeners
    YAHOO.util.Event.addListener(obj.close_id, "click", function() {
        obj.hidePanel()
    });
    document.getElementById(obj.panel_id).className = "";
    YAHOO.util.Event.addListener(obj.targetDiv, "click", function() {
        obj.showPanel();
    });
}

natrelle.taf.prototype.showPanel = function() {
    this.tafPanel.show();
}
natrelle.taf.prototype.hidePanel = function(rr) {
    var obj = this;
    this.tafPanel.hide();
    if (rr) {
        setTimeout("natrelle.ptaf.closeEnd()", 500);
    }
}
natrelle.taf.prototype.closeEnd = function() {
    var obj = this; //internal obj re-reference
    obj.tafPanel.setBody(obj.pageContent);
    
    YAHOO.util.Event.addListener(obj.close_id, "click", function() {
        obj.hidePanel()
    });
}

// function returns no value for javascript empty href clicks
natrelle.noReturn = function() { }

