/**
 *Trigger the new Code Igniter methodology for the assessments
 */
var newassessment=true;
/**
 * The Flash Player embedded component does not go away with the modal popup.
 * Logic here will hide the component.  It is only created once on the page, 
 * so after creation the first time it is hidden and show only.
 */
var currentPlayer = null;

/**
 * This is the modal popup (aka lightbox) for the learning center.
 * It is a YUI Panel set to modal:true for the effect.
 * The YUI Panel is only created once, and the videoId is passed to this
 * function for the video/assets to load.
 */
var persAssessmentPanel = null;


function displayPersPanel(e,params){
    if ((screen.width>=1024) && (screen.height>=768)){
        if (persAssessmentPanel == null){
            persAssessmentPanel = new YAHOO.widget.Panel("persAssessmentPanel",
            {
                width: "950px",
                height: "570px",
                close: true,
                draggable: false,
                zindex:999,
				fixedcenter: true,
                modal: true,
                visible: false,
				iframe: true,
                effect:{
                    effect:YAHOO.widget.ContainerEffect.FADE,
                    duration: .3
                }
            }
            );
        }

        persAssessmentPanel.setBody('<div class="persassessmentlightboxbody"><a class="pt_closeButton" href="#" onclick="persAssessmentPanel.hide();return true;"></a><center><img src="/img/ajaxloading_transparent.gif"/></center></div>');
        persAssessmentPanel.render(document.body);
		persAssessmentPanel.center();
		//hide .bd
		
        persAssessmentPanel.beforeHideEvent.subscribe(function() {
            if (persAssessmentPanel!=null){
                persAssessmentPanel.setBody(''); //remove player completely to stop it from playing
            }
            window.location.href = "/student-profile";
        });
        persAssessmentPanel.show();
        // Define the callback object for Connection Manager that will set the body of our content area when the content has loaded
        var callback = {
            success : function(o) {
                //todo call ajax page to get count, then resize height and call another ajax page
                //to load the content, assuring we are 1 or 2 or 3 tasks tall.
                if (o.responseText.indexOf('Login To Your Account') != -1){
                    alert('Timeout has occured, click OK to login.');
                    self.location.href="/wclogin";
                }
                persAssessmentPanel.setBody('<div>' + o.responseText + "</div>" );
            },
            failure : function(o) {
                persAssessmentPanel.setBody(o.responseText);
            }
        };
    
        var conn;
        if (params.type == 'test'){
            conn = YAHOO.util.Connect.asyncRequest("GET", "/aboutyou/persassessment/showAssessment/"+params.id+ "/" + new Date().getTime()+"/"+newassessment, callback);
        }
        else{
            conn = YAHOO.util.Connect.asyncRequest("GET", "/aboutyou/persassessment/showReport/"+params.id+ "/" + new Date().getTime()+"/"+newassessment, callback);
        }

    }
    else {
        alert("Screen resolution must be set higher than 1024 x 768 to take the personality assessment");

    }
	
}

var planningAssessmentLightbox = null;

function showPlanningAssessment(){
	if (planningAssessmentLightbox == null){
		planningAssessmentLightbox = new YAHOO.widget.Panel("planningAssessmentLightbox",{
            width: "950px",
            height: "570px",
            fixedcenter: true,
            close: true,
            draggable: false,
            zindex:999,
            modal: true,
            visible: false,
			iframe: false,
            effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration: 1}
        });
		planningAssessmentLightbox.setBody('<br/><br/><br/><br/><img src="/img/ajaxloading.gif" /> Loading...');
		planningAssessmentLightbox.render(document.body);		
		planningAssessmentLightbox.beforeHideEvent.subscribe(function() {
            if (planningAssessmentLightbox!=null){
            	planningAssessmentLightbox.setBody(''); //remove player completely to stop it from playing
            }
            //window.location.href = "/student-profile";
        });
	}
	
    // removing the old listeners, running the destroyer rules, and setting the loading message
    YAHOO.plugin.Dispatcher.process ( planningAssessmentLightbox.body, "Loading, please wait..." );
    // displaying the panel
    planningAssessmentLightbox.show();
    /* loading the content */
    YAHOO.plugin.Dispatcher.fetch ( planningAssessmentLightbox.body, '/aboutyou/planningassessment/intro' );

    return false;
}


function displayPersPanelNoLink(e,params){
    if (persAssessmentPanel == null){
        persAssessmentPanel = new YAHOO.widget.Panel("persAssessmentPanel",
        {
            width: "950px",
            height: "570px",
            fixedcenter: true,
            close: true,
            draggable: false,
            zindex:999,
            modal: true,
            visible: false,
            effect:{
                effect:YAHOO.widget.ContainerEffect.FADE,
                duration: 1
            }
        }
        );
    }

    persAssessmentPanel.setBody('<div class="persassessmentlightboxbody"><a class="pt_closeButton" href="#" onclick="persAssessmentPanel.hide();return true;"></a><br><br><br><br><br><img src="/img/ajaxloading.gif"/><br/><br/>Loading...</div>');
    persAssessmentPanel.render(document.body);
    persAssessmentPanel.beforeHideEvent.subscribe(function() {
        if (persAssessmentPanel!=null){
            persAssessmentPanel.setBody(''); //remove player completely to stop it from playing
        }
        // window.location.href = "/student-profile";

    });
    persAssessmentPanel.show();
    // Define the callback object for Connection Manager that will set the body of our content area when the content has loaded
    var callback = {
        success : function(o) {
            //todo call ajax page to get count, then resize height and call another ajax page
            //to load the content, assuring we are 1 or 2 or 3 tasks tall.
            if (o.responseText.indexOf('Login To Your Account') != -1){
                alert('Timeout has occured, click OK to login.');
                self.location.href="/wclogin";
            }       
            var cleanedResponseText = o.responseText;
            cleanedResponseText = cleanedResponseText.replace('<div class="pt_wc_divider_small" style="width:800px;"></div>', '');
            cleanedResponseText = cleanedResponseText.replace('<div class="liquidbtn" style="float:right; margin-top:15px;margin-right:130px;">', '');
            cleanedResponseText = cleanedResponseText.replace('Go to Next Assessment', '');
            cleanedResponseText = cleanedResponseText.replace('</div> <!--<div class="" style="float:right; margin-top:15px;margin-right:130px;"><a href="#" alt="button" onClick="GetAssessment()"><img border="0" src="/img/pt/wc_button_next_ass.png" width="159" height="25" alt="" /></a></div>--> <!--<div class="liquidbtn" style="float:right; margin-top:15px;margin-right:130px;"><a href="#">Go to Personality Report</a><span></span></div>-->', '');
            persAssessmentPanel.setBody(cleanedResponseText);
        },
        failure : function(o) {
            persAssessmentPanel.setBody(o.responseText);
        }
    };	
    
    var conn;
    if (params.type == 'test'){
        conn = YAHOO.util.Connect.asyncRequest("GET", "/aboutyou/persassessment/showAssessment/"+params.id+ "/" + new Date().getTime(), callback);
    }
    else{
        conn = YAHOO.util.Connect.asyncRequest("GET", "/aboutyou/persassessment/showReport/"+params.id+ "/" + new Date().getTime(), callback);
    }
	
}

function displayPersAssessment(e, vidId){


    if (persAssessmentPanel == null){
        persAssessmentPanel = new YAHOO.widget.Panel("persAssessmentPanel",
        {
            y: 150,
            x: 50,
            width: "930px",
            height: "550px",
            fixedcenter: true,
            close: true,
            draggable: false,
            zindex:999,
            modal: true,
            visible: false,
			iframe: false,
            effect:{
                effect:YAHOO.widget.ContainerEffect.FADE,
                duration: 1
            }
        }
        );
    }
    persAssessmentPanel.setBody('<div class="persassessmentlightboxbody"><div id="lrnctr"><br><br><br><br><br><img src="/img/ajaxloading.gif"/><br/><br/>Loading...</div></div>');
    persAssessmentPanel.render(document.body);
    persAssessmentPanel.beforeHideEvent.subscribe(toggleHidePlayer);
    persAssessmentPanel.show();
    // Define the callback object for Connection Manager that will set the body of our content area when the content has loaded
    var callback = {
        success : function(o) {
            if (isSessionValid(o.responseText)){
                persAssessmentPanel.setBody(o.responseText);
            }else{
                self.location.href="/wclogin";
            }
    	
        },
        failure : function(o) {
            persAssessmentPanel.setBody(o.responseText);
        }
    };
    
    // Connect to our data source and load the data
    var conn = YAHOO.util.Connect.asyncRequest("GET", "/aboutyou/persassessment/showAssessment/"+vidId, callback);
    
}
function displayPersReport(vidId){
    // Define the callback object for Connection Manager that will set the body of our content area when the content has loaded
    var callback = {
        success : function(o) {
            if (isSessionValid(o.responseText)){
                persAssessmentPanel.setBody(o.responseText);
            }else{
                self.location.href="/wclogin";
            }
    	
        },
        failure : function(o) {
            persAssessmentPanel.setBody(o.responseText);
        }
    };
    
    // Connect to our data source and load the data
    var conn = YAHOO.util.Connect.asyncRequest("GET", "/aboutyou/persassessment/showReport/"+vidId, callback);
   
}
/** These are the YUI Events that will trigger when the divs are clicked for the play buttons on the videos **/ 
function AssessmentOptions(x,y){
    this.id=x;
    this.type=y;
}

function CompleteQuiz(uid, module) {
    displayPersPanel('none',new AssessmentOptions(module,'rep'));
    return true;
}
function GetAssessment(module){
    displayPersPanel('none',new AssessmentOptions(module,'test'));
}
function quickClose(uid, module) {
    persAssessmentPanel.hide();
    return true;
}	
function QuizError(uid, module, error_id, error_text) {
    alert("Error for uid="+uid+" moduleid="+module+" QUIZ ERROR id="+error_id+" message="+error_text);//+" : "+error_txt);
}	
function GoToFullReport(){
    window.location.href='/aboutyou/persassessment/showFullReport/';
    return true;
}

