 /** 
 * All JS related to the flyouts for WiseChoice are in this file.  
 * Flyouts include: ViewCalendarEvent Popup, Add/EditCalendarEvent Popup, Help Popup, and School Matching Popup.
 *  
 *  schoolMatchingSearchPopup()
 *  showHelpPopup2()
 *  showHelpPopup1()
 *  viewCalendarEventPopup()
 *  addCalendarEventPopup()
 *  showProfilePicPopup()
*/

var schoolMatchingSearchPopupPanel; //flyout panel
var helpPopupPanel; //flyout panel
var addCalendarEventPanel; //flyout panel
var viewCalendarEventPanel; //flyout panel
var currentlySelectedEventGk; //when user clicks on add or edit flyout, this is set.
var profilePicPopupPanel; //flyout panel
var myTimer; //global timer for hoover bubbles.  Used to toggle a setTimeout call for hoverbubble descriptions


function showProfilePicPopup(){
	
	profilePicPopupPanel = new YAHOO.widget.Panel("profilePicPanelDiv",{
	    width: 403,
		height: 194,
	    fixedcenter: true,
	    close: true,
	    draggable: false,
	    underlay:"none",
	    zindex:9999,
	    modal: true,

	}
	);
	profilePicPopupPanel.render(document.body);
	
    profilePicPopupPanel.show();
	document.getElementById('profilePicPanelDiv').style.display = 'block';

}
function stripJS(element, rawJS){
	
    var children = element.childNodes;
    for (var i=0;i<children.length;i++){
        var child = children[i];
        if("SCRIPT" == child.tagName){
            rawJS += child.innerHTML;
        //alert(child.innerHTML);
        }
        if (child.childNodes.length>0){
            rawJS = stripJS(child,rawJS);
        }
    }
    return rawJS;
}

/**
 * this is the javascript for the flyout with the right side tail.  It is a fixed size flyout.
 * There is also css for the flyout, it is in YAHOO.widget.Panel.css
 * 
 * The popups all use different sets of css for the look, based on if the tail is on top, bottom, or in 
 * your case to the right.  the css is determined using the css indicator you pass into the Panel() 
 * constructor.  I named yours schoolMatchingSearch.
 * 
 * @param element - DOM HTMLElement
 * @return
 */
function showSchoolMatchingSearchPopup(element){
    var myX = YAHOO.util.Dom.getX(element);
    var myY = YAHOO.util.Dom.getY(element);
	
    schoolMatchingSearchPopupPanel = new YAHOO.widget.Panel("schoolMatchingSearchDIV",
    {
        x: myX - 222,
        y: myY - 120,
        width: "275px",
        fixedcenter: false,
        close: true,
        draggable: false,
        underlay:"none",
        zindex:999,
        modal: false,
        effect:{
            effect:YAHOO.widget.ContainerEffect.FADE,
            duration: 1
        }
    }
    );
    schoolMatchingSearchPopupPanel.render(element.parentNode);
	
    //set this to fix quirk when making display:none to display:block.
    //display:none was required to keep hidden schoolMatchingSearchTable from taking up screen
    //space when not in use.
    var daDialog = YAHOO.util.Dom.get("schoolMatchingSearchTable");
    daDialog.style.display='block';

}


function showSchoolMatchingConfirmPopup(element, schoolName){
    var myX = YAHOO.util.Dom.getX(element);
    var myY = YAHOO.util.Dom.getY(element);
	
    schoolMatchingConfirmPopupPanel = new YAHOO.widget.Panel("schoolMatchingConfirm",
    {
        //				x: myX - 222,
        //				y: myY - 120,
        width: "465px",
        fixedcenter: true,
        close: true,
        draggable: false,
        underlay:"none",
        //	        	zindex:999,
        modal: true,
        effect:{
            effect:YAHOO.widget.ContainerEffect.FADE,
            duration: 1
        }
    }
    );
    schoolMatchingConfirmPopupPanel.render(element.parentNode);
	
    //set this to fix quirk when making display:none to display:block.
    //display:none was required to keep hidden schoolMatchingConfirmTable from taking up screen
    //space when not in use.
    //	var daDialog = YAHOO.util.Dom.get("schoolMatchingSearchTable");
    //	daDialog.style.display='block';
    var uniDialog = YAHOO.util.Dom.get("university_of");
    uniDialog.innerHTML=schoolName;
}

function showCareerMatchingConfirmPopup(element, careerName) {
    var myX = YAHOO.util.Dom.getX(element);
    var myY = YAHOO.util.Dom.getY(element);
	
    careerMatchingConfirmPopupPanel = new YAHOO.widget.Panel("careerMatchingConfirm",
    {
        //				x: myX - 222,
        //				y: myY - 120,
        width: "465px",
        fixedcenter: true,
        close: true,
        draggable: false,
        underlay:"none",
        zindex:999,
        modal: true,
        effect:{
            effect:YAHOO.widget.ContainerEffect.FADE,
            duration: 1
        }
    }
    );
    careerMatchingConfirmPopupPanel.render(element.parentNode);
	
    //set this to fix quirk when making display:none to display:block.
    //display:none was required to keep hidden schoolMatchingConfirmTable from taking up screen
    //space when not in use.
    //	var daDialog = YAHOO.util.Dom.get("schoolMatchingSearchTable");
    //	daDialog.style.display='block';
    var careerDialog = YAHOO.util.Dom.get("career_of");
    careerDialog.innerHTML=careerName;
}


/**
 * Help popup shown when a user clicks on a hyperlink that shows a bubble popup.  Used in onclick calls.
 * showHelpPopup2 attempts to center the help popup based on linkWidth
 * 
 * This call uses AJAX to load the title and description for the popup.
 * 
 * The helpGk is the id of the element itself.  Use element.id to get this value.
 * 
 * @param element -  the link used to position the popup over
 * @param helpGk - the gk for the help topic in the database
 * @param linkWidth - used to help center the popup on the x axis
 * @param tailDirection - only allowable value is "DOWN", "UP", or blank.  Default it blank with causes tail "UP".
 * 						- causes the help popup to display inverted
 * @return
 */
function showHelpPopup2(element, helpGk, linkWidth, tailDirection, popupHeight){
    var myX = YAHOO.util.Dom.getX(element);
    var myY = YAHOO.util.Dom.getY(element);
    popupWidth = 200;
	
    if (tailDirection == undefined ||
        tailDirection.toUpperCase() != "DOWN" ||
        tailDirection.toUpperCase() == "UP"){
		
        tailDirection = "_TAILUP";
    }else{
        tailDirection = "";
    }
	
    var left = myX - (popupWidth/2) + 10 + (linkWidth/2);
    var top =  (tailDirection=="")? myY - popupHeight : myY + 10;
		
    helpPopupPanel = new YAHOO.widget.Panel("helpPopupPanel"+tailDirection,
    {
        x: left,
        y: top,
        width: popupWidth,
        fixedcenter: false,
        close: true,
        draggable: false,
        underlay:"none",
        zindex:999,
        modal: false,
	        	
        effect:{
            effect:YAHOO.widget.ContainerEffect.FADE,
            duration: 1
        }
    }
    );
    helpPopupPanel.setHeader("<div></div>");
    helpPopupPanel.setBody("<div style='min-height:"+(popupHeight-80)+"px'><img src='/img/ajaxloadingsmall.gif' /> Loading...</div>");
    helpPopupPanel.setFooter("<!--must include to show tail-->");
    helpPopupPanel.render(element.parentNode);
    helpPopupPanel.show();

    var callback = {
        success : function(o) {
            if (isSessionValid(o.responseText)){
                var CSVresponse = o.responseText;
                var CSVarray = CSVresponse.split("|");
                var title = CSVarray[0];
                var description = CSVarray[1];
                helpPopupPanel.setHeader("<div><br style='line-height:30px'/>&nbsp;&nbsp;"+title+"</div>");
                helpPopupPanel.setBody("<div style='padding:15px 15px;color:#526e90; text-align: left;padding-right: 5px;'>"+description+"</div>");
            }else{
                self.location.href="/wclogin";
            }
        },
        failure : function(o) {
            helpPopupPanel.setBody(o.responseText);
        }
    };
    
    var conn = YAHOO.util.Connect.asyncRequest("GET", "/tools/help/popup/" + element.id, callback);
}

/**
 * Started to work on a new helppopup
 * @param element
 * @param helpGk
 * @param linkWidth
 * @param tailDirection
 * @param popupHeight
 * @return
 */
function showHelpPopup3(element, helpGk, linkWidth, tailDirection, popupHeight){
	
    // 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)){
                var CSVresponse = o.responseText;
                var CSVarray = CSVresponse.split("|");
                var title = CSVarray[0];
                var description = CSVarray[1];
                var descHeight = ((description.length /28)*12);
                var myX = YAHOO.util.Dom.getX(element);
                var myY = YAHOO.util.Dom.getY(element);
                popupWidth = 200;
	        	
                if (tailDirection == undefined ||
                    tailDirection.toUpperCase() != "DOWN" ||
                    tailDirection.toUpperCase() == "UP"){
	        		
                    tailDirection = "_TAILUP";
                }else{
                    tailDirection = "";
                }
                tailDirection="_TAILUP";
                var left = myX - (popupWidth/2) + 10 + (linkWidth/2);
                var top =   myY+10;
                //alert("top :"+top+"  descheight :"+descHeight);
	        		
                helpPopupPanel = new YAHOO.widget.Panel("helpPopupPanel"+tailDirection,
                {
                    x: left,
                    y: top,
                    width: popupWidth,
                    fixedcenter: false,
                    close: true,
                    draggable: false,
                    underlay:"none",
                    zindex:999,
                    modal: false,
	        	        	
                    effect:{
                        effect:YAHOO.widget.ContainerEffect.FADE,
                        duration: 1
                    }
                }
                );
                helpPopupPanel.setHeader("<div><br style='line-height:30px'/>&nbsp;&nbsp;"+title+"</div>");
                helpPopupPanel.setBody("<table><tr><td><div style='padding:15px 15px;color:#526e90; font-family:Arial,Trebuchet MS; font-size: 12px; font-weight:normal; text-align: left;padding-right: 5px;'>"+description+"</div></td><td>&nbsp;&nbsp;&nbsp;</td></tr></table");
                helpPopupPanel.setFooter("<!--must include to show tail-->");
                helpPopupPanel.render(element.parentNode);
                helpPopupPanel.show();

            }else{
                self.location.href="/wclogin";
            }
        	
        },
        failure : function(o) {
            helpPopupPanel.setBody(o.responseText);
        }
    };
    
    // Connect to our data source and load the data
    var conn = YAHOO.util.Connect.asyncRequest("GET", "/tools/help/popup/" + element.id, callback);
}
function showHelpPopup4(element,helpGk, linkWidth, tailDirection, popupHeight){
    var myX = YAHOO.util.Dom.getX(element);
    var myY = YAHOO.util.Dom.getY(element);
    popupWidth = 200;
	
    if (tailDirection == undefined ||
        tailDirection.toUpperCase() != "DOWN" ||
        tailDirection.toUpperCase() == "UP"){
		
        tailDirection = "_TAILUP";
    }else{
        tailDirection = "";
    }
	
	

    // 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)){
                var CSVresponse = o.responseText;
                var CSVarray = CSVresponse.split("|");
                var title = CSVarray[0];
                var description = wordwrap(CSVarray[1],28,'<br>',true);
	        	var occur = description.match(/<br>/g);
                //number of characters in the description
                //var length = description.length;
	        	
                //number of characters per line plus an extra hundred for the header and footer
                popupHeight = (((occur.length + 1) * 16)+100);
	        	
                var left = myX - (popupWidth/2) + 10 + (linkWidth/2);
                var top =  myY - popupHeight;
	        	
                //if there is no room above a link then put the popup below.
                if (top<30){
                    tailDirection="_TAILUP";
                    var top =  myY+10;
                }
                helpPopupPanel = new YAHOO.widget.Panel("helpPopupPanel"+tailDirection,
                {
                    x: left,
                    y: top,
                    width: popupWidth,
                    textAlign: 'left',
                    fixedcenter: false,
                    close: false,
                    draggable: false,
                    underlay:"none",
                    zindex:999,
                    modal: false,
                    effect:{
                        effect:YAHOO.widget.ContainerEffect.FADE,
                        duration: 1
                    }
                }
                );
	        	
                helpPopupPanel.setHeader("<div><br style='line-height:30px'/></div>");
                helpPopupPanel.setBody("<div style='padding:15px 15px;color:#526e90; font-family:Arial,Trebuchet MS; font-size: 12px; font-weight:normal; text-align: left;'>"+description+"</div>");
                helpPopupPanel.setFooter("<!--must include to show tail-->");
                helpPopupPanel.render(document.body);
                helpPopupPanel.show();
                return false;
            }else{
                self.location.href="/wclogin";
            }
        	
        },
        failure : function(o) {
            helpPopupPanel.setBody(o.responseText);
        }
    };
    
    // Connect to our data source and load the data
    var conn = YAHOO.util.Connect.asyncRequest("GET", "/tools/help/popup/" + element.id, callback);
}

function showHelpPopup5(element, helpGk, linkWidth, tailDirection, popupHeight){
    /**
     *Passing function parameters inside a setTimeout function has to use a 'closure'.
     *example  setTimeout(function(){showHelpPopup4.....
     * Setting variables to Null is to fix a memory leak in IE.
     * Something about the IE garbage collector not working correctly.
     *
     * Also it is important to note the myTimer class variable.  This is so that
     * the element that is making the request for a help popup can cancel the request
     * with a mouseout function.  example :
     * onmouseout="clearTimeout(myTimer);" onmouseover="showHelpPopup5(this,'tuition',0,'DOWN',100);return false"
     *
     * I could've made another function to call the cleartimeout function, but what's the point.
     *
     * I could've put this setTimeout function in the page element but that would just be messy and a pain to maintain.
     */  
    YAHOO.util.Event.addListener(element, "mouseout", popupmouseout);
    myTimer = setTimeout(function(){
        showHelpPopup4(element, helpGk, linkWidth, tailDirection, popupHeight);
        element= null;
        helpGk=null;
        linkWidth=null;
        tailDirection=null;
        popupHeight=null;
    },500);

}


function popupmouseout(){
    clearTimeout(myTimer);
    if(!(undefined===helpPopupPanel)){
     helpPopupPanel.hide();
    }
}


/**
 * Help popup shown when a user clicks on a hyperlink that shows a bubble popup.  Used in onclick calls.
 * showHelpPopup1 calls showHelpPopup2, but without a linkWidth
 * 
 * This call uses AJAX to load the title and description for the popup. The helpGk is the id of the element 
 * 
 * @param element - if the id of the element is the helpGk, use this method.
 * @return
 */
function showHelpPopup1(element){
    showHelpPopup2(element, element.id);
}

/**
 * This function is for the small calendar on the dashboard.  Upon mouseover of an event in the small calendar,
 * this function produce a flyout that shows the events for that day.
 * 
 * @param elementId - the id of the HTML element representing the day of the month, used for positon of the flyout arror
 * @param ts - timestamp of the day of the month
 * @return
 */
function viewCalendarEventPopup(elementId, ts){

    if (addCalendarEventPanel!=null)addCalendarEventPanel.hide();
	
    var dailyElement = YAHOO.util.Dom.get(elementId);
    var myX = YAHOO.util.Dom.getX(elementId);
    var myY = YAHOO.util.Dom.getY(elementId);
    var myWidth = 208;
    var myHeight = 200;
    var dailyBoxWidth = 36;

    viewCalendarEventPanel = new YAHOO.widget.Panel("viewCalendarEventPanel",
    {
        x: myX - (myWidth/2) + (dailyBoxWidth/2),
        y: myY - myHeight,
        width: "208px",
        height: "200px",
        fixedcenter: false,
        close: true,
        draggable: false,
        underlay:"none",
        zindex:999,
        modal: false,
        visible: false
    }
    );
    viewCalendarEventPanel.setHeader("<div class='tl'></div><div class='tc'></div><div class='tr'></div>");
    viewCalendarEventPanel.setBody("<img src='/img/ajaxloading.gif'/><br/><br/>Loading...");
    viewCalendarEventPanel.setFooter("<!--must include to show tail-->");
    viewCalendarEventPanel.render(document.body);
    viewCalendarEventPanel.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)){
                viewCalendarEventPanel.setBody(o.responseText);
            }else{
                self.location.href="/wclogin";
            }
        	
        },
        failure : function(o) {
            viewCalendarEventPanel.setBody(o.responseText);
        }
    };
    
    // Connect to our data source and load the data
    var conn = YAHOO.util.Connect.asyncRequest("GET", "/tools/calendar/viewevent/" + ts, callback);
    
	$('.container-close').click(function(){
		viewCalendarEventPanel.hide();
	})
}
function viewCalendarCollegeVisitEventPopup(elementId){

    if (addCalendarEventPanel!=null)addCalendarEventPanel.hide();

    var dailyElement = YAHOO.util.Dom.get(elementId);
    var myX = YAHOO.util.Dom.getX(elementId);
    var myY = YAHOO.util.Dom.getY(elementId);
    var myWidth = 208;
    var myHeight = 200;
    var dailyBoxWidth = 36;

    viewCalendarEventPanel = new YAHOO.widget.Panel("viewCalendarEventPanel",
    {
        x: myX - (myWidth/2) + (dailyBoxWidth/2),
        y: myY - 125,
        width: "208px",
        height:"150px",
        fixedcenter: false,
        close: true,
        draggable: false,
        underlay:"none",
        zindex:999,
        modal: false,
        visible: false
    }
    );
    viewCalendarEventPanel.setHeader("<div class='tl'></div><div class='tc'></div><div class='tr'></div>");
    viewCalendarEventPanel.setBody("<img src='/img/ajaxloading.gif'/><br/><br/>Loading...");
    viewCalendarEventPanel.setFooter("<!--must include to show tail-->");
    viewCalendarEventPanel.render(document.body);
    viewCalendarEventPanel.show();   
    var html ='<table border="0" cellspacing="5" width="100%"><tr><td class="subheadinggrey">To view or edit details <br/>for this event go to the<br /> College Visit Planner</a></td></tr><tr><td colspan=2><div style="float:left;background:url(/img/bg3.gif) repeat-x;width:195px;"><img src="/img/spacer.gif"/><br/><br/><a href="/collegevisit/main">Go To College Visit Planner</a></div></td></tr></table>';
    viewCalendarEventPanel.setBody(html);


}

/**
 * This dialog acts as the add and edit calendar event flyout.  The eventId is passed in for edit.
 * 
 * @param elementId - the id of the HTML element representing the day of the month, used for positon of the flyout arror
 * @param myMonth - integer for the current month
 * @param myDay - integer for day of month selected
 * @param myYear - integer for the current year
 * @param eventId - if user clicked on an event on a day, this is the event id to display in the calendar flyout
 * @return
 */
function addCalendarEventPopup(elementId, myMonth,myDay,myYear, eventId){
    if (viewCalendarEventPanel!=null)viewCalendarEventPanel.hide();
    if (addCalendarEventPanel!=null)addCalendarEventPanel.hide();
	
    currentlySelectedEventGk = eventId; //used by deleteTask() function
	
    //determines the css style to use for tail.
    var tailDirection = "DOWN";
	
    var myEndMonth = myMonth;
    var myEndDay = myDay;
    var myEndYear = myYear;
    var myTime="08:00",myEndTime="08:00";
	
    var dailyElement = YAHOO.util.Dom.get(elementId);
    var myX = YAHOO.util.Dom.getX(elementId);
    var myY = YAHOO.util.Dom.getY(elementId);
    var myWidth = 327;
    var myHeight = 440;
    var dailyBoxWidth = 70;

    if (myY <450){
        tailDirection = "UP";
    }
	
    //AddEventForm submitted
    var performSubmit = function() {
        //disable buttons
        var buttons = addCalendarEventPanel.getButtons();
        for (var i=0;i<buttons.length;i++){
            buttons[i].disabled = true;
        }
        //show animated gif while submitting
        var messageElement = YAHOO.util.Dom.get("addCalendarEventPanelMessageArea");
        messageElement.innerHTML = "<img src='/img/ajaxloadingsmall.gif'/> Please wait...";
        //submit the form
        addCalendarEventPanel.submit();
    };

    //AddForEvent Submission returned successfull, event was added 
    var handleFormSubmittalSuccess = function(o) {
        var response = o.responseText;
    	
        if (response == "Success"){
            addCalendarEventPanel.hide();
            self.location.reload();
        }else{
            //error occured, re-enable buttons
            var buttons = addCalendarEventPanel.getButtons();
            for (var i=0;i<buttons.length;i++){
                buttons[i].disabled = false;
            }
            //hide animated button and show errors
            var messageElement = YAHOO.util.Dom.get("addCalendarEventPanelMessageArea");
            messageElement.innerHTML = "<span class='subheadingred'>"+response.substr(5)+"</span>";
        }
    };

    //AddForEvent Submission returned with error, event was not added 
    var handleFormSubmittalFailure = function(o) {
        alert("Submission failed: " + o.status);
    };
    
    
    addCalendarEventPanel = new YAHOO.widget.Dialog((tailDirection=="UP")?"addCalendarEventPanelDiv_TAILUP":"addCalendarEventPanelDiv",
    {
        x: myX - (myWidth/2) + (dailyBoxWidth/2),
        y: (tailDirection=="UP")? myY + dailyBoxWidth : myY - myHeight,
        width: "327px",
        height: "455px",
        fixedcenter: false,
        hideaftersubmit:false,
        close: true,
        draggable: false,
        zindex:999,
        underlay:"none",
        modal: false,
        visible: false,
        buttons : [ {
            text:"Save",
            handler:performSubmit
        } ]
	        	
    }
    );

    //add Delete button
    if (currentlySelectedEventGk != -1){
        var myButtons = [ {
            text:"Save",
            handler:performSubmit
        },{
            text:"Delete",
            handler:deleteTask
        } ];
        addCalendarEventPanel.cfg.queueProperty("buttons", myButtons);
    }
	
    //render
    addCalendarEventPanel.render(document.body);
	
    //set this to fix quirk when making display:none to display:block.
    //display:none was required to keep hidden addCalendarEventPanelTable from taking up screen
    //space when not in use.
    var daDialog = YAHOO.util.Dom.get((tailDirection=="UP")?"addCalendarEventPanelTable_TAILUP":"addCalendarEventPanelTable");
    daDialog.style.display='block';
    daDialog.style.height='340px';

    //show the add event dialog
    addCalendarEventPanel.show();

    //these are the functions to call for AJAX form submittal.
    addCalendarEventPanel.callback = {
        success: handleFormSubmittalSuccess,
        failure: handleFormSubmittalFailure
    };

	
    //HTML form input elements
    //NOTE: these are not all the same, some are inputs, some are XML text nodes, some are checkboxes
    var eventGkElement = YAHOO.util.Dom.get("event_id");
    var typeIdElement = YAHOO.util.Dom.get("type_id");
    var eventTitleElement = YAHOO.util.Dom.get("eventtitle");
    var eventDescriptionElement = YAHOO.util.Dom.get("eventdesc");
    var eventReminderNoteElement = YAHOO.util.Dom.get("remindernote");
    var eventSaveReminderElement = YAHOO.util.Dom.get("wc_event_reminder");
    var eventReminderMethodElement = YAHOO.util.Dom.get("pm_reminder_method");
    var eventReminderWaitPeriodElement = YAHOO.util.Dom.get("pm_reminder_wait_period");
    var eventAllDayElement = YAHOO.util.Dom.get("eventallday");
    var startDateMonthElement = YAHOO.util.Dom.get("event_date_month");
    var startDateDayElement = YAHOO.util.Dom.get("event_date_day");
    var startDateYearElement = YAHOO.util.Dom.get("event_date_year");
    var eventStartTimeElement = YAHOO.util.Dom.get("eventstart_time");
    var endDateMonthElement = YAHOO.util.Dom.get("end_event_date_month");
    var endDateDayElement = YAHOO.util.Dom.get("end_event_date_day");
    var endDateYearElement = YAHOO.util.Dom.get("end_event_date_year");
    var eventEndTimeElement = YAHOO.util.Dom.get("eventend_time");
    var deleteTail = YAHOO.util.Dom.get("deletetail");
	
    //Reset values for Add Event.  If this is Edit Event, they will be set below.
    var titleEl = YAHOO.util.Dom.get("title");
    if (tailDirection == "UP")
        titleEl.innerHTML = "<br style='line-height:35px;'/>&nbsp;&nbsp;Add an Event";
    else
        titleEl.innerHTML = "&nbsp;&nbsp;Add an Event";
	
    eventTitleElement.value = "Event Title";
    eventDescriptionElement.value = "Event Description";
    eventAllDayElement.checked = 0;
    eventSaveReminderElement.checked = 0;
    eventReminderNoteElement.value = "Event Location";
	
    //Reset messageArea
    var messageElement = YAHOO.util.Dom.get("addCalendarEventPanelMessageArea");
    messageElement.innerHTML = "";
	
    if (eventId!=-1){
        //EDIT event logic
        //
        //set title and eventGk for event bring edtied
        var titleEl = YAHOO.util.Dom.get("title");
        if (tailDirection == "UP")
            titleEl.innerHTML = "<br style='line-height:35px;'/>&nbsp;&nbsp;Edit an Event";
        else
            titleEl.innerHTML = "&nbsp;&nbsp;Edit an Event";
		
        //set hidden value for event id for form submission; so we know what event to update
        eventGkElement.value = eventId;
		
        //the delete button needs to exist for EDIT event, show tail
        deleteTail.style.visibility="visible";
		
        // Callback methods for the AJAX call to load the edit data
        var getEventDataCSVCallback = {
            success : function(o) {
                if (isSessionValid(o.responseText)){
                    var CSVresponse = o.responseText;
                    var CSVarray = CSVresponse.split("|");
                    eventTitleElement.value = CSVarray[0];
                    eventDescriptionElement.value = CSVarray[1];
                    //alert(CSVarray[1]);
                    setComboValue(startDateMonthElement,CSVarray[2]);
                    setComboValue(startDateDayElement,CSVarray[3]);
                    setComboValue(startDateYearElement,CSVarray[4]);
                    setComboValue(eventStartTimeElement,CSVarray[5]);
                    setComboValue(endDateMonthElement,CSVarray[6]);
                    setComboValue(endDateDayElement,CSVarray[7]);
                    setComboValue(endDateYearElement,CSVarray[8]);
                    setComboValue(eventEndTimeElement,CSVarray[9]);
                    eventAllDayElement.checked = (CSVarray[10] == "Y")?1:0;
                    eventSaveReminderElement.checked = (CSVarray[11] == "Y")?1:0;
                    eventReminderNoteElement.value = CSVarray[12];
                    setComboValue(eventReminderWaitPeriodElement,CSVarray[13]);
                    setComboValue(eventReminderMethodElement,CSVarray[14]);
                    eventGkElement.value = currentlySelectedEventGk;
                    if (CSVarray.length >= 16){
                        if(typeIdElement!= null){
                        typeIdElement.value = CSVarray[15];
                        }
                    }
		        	
                }else{
                    self.location.href="/wclogin";
                }
	    		
            },
            failure : function(o) {
                alert('failure in getEventDataCSVCallback');
            }
        };
	    
	    
        //make AJAX call to get event information and populate the flyout.
        var conn = YAHOO.util.Connect.asyncRequest("GET", "/tools/calendar/getEventDataCSV/" + eventId, getEventDataCSVCallback);

    }else{
        //ADD event logic
        //
        //add the date for the day selected in the calendar.
        setComboValue(startDateMonthElement,myMonth);
        setComboValue(startDateDayElement,myDay);
        setComboValue(startDateYearElement,myYear);
        setComboValue(eventStartTimeElement,myTime);
        setComboValue(endDateMonthElement,myEndMonth);
        setComboValue(endDateDayElement,myEndDay);
        setComboValue(endDateYearElement,myEndYear);
        setComboValue(eventEndTimeElement,myEndTime);
        //the delete button does not exist for ADD event, remove tail
        deleteTail.style.visibility="hidden";
    }
}


/**
 * Used by Add/Edit Calendar Event Popup
 * @param theCombo
 * @param theValueToSet
 * @return
 */
function setComboValue(theCombo, theValueToSet){
    for (var i=0 ; i < theCombo.length; i++){
		
        if (theCombo.options[i].value==theValueToSet){
            theCombo.selectedIndex = i;
            return true;
        }
    }
}

function saveAsDialogOnKeyPress(e){
    var key;
    if(window.event){
        key = window.event.keyCode;     //IE
    }else{
        key = e.which;     //firefox
    }
    if(key == 13){
        return false; //disable the enter button
    }else{
        return true;
    }
}

function saveResume(activityResumeGk, userGk) {
    var saveasmessagediv = YAHOO.util.Dom.get("saveAsMessageDIV");
       
    var callback = {
        success : function(o) {       
            if (isSessionValid(o.responseText)){
                if (o.responseText.indexOf("SUCCESS")>-1){
                    //activityResumeSaveAsDialog.hide();
                    saveasmessagediv.innerHTML = "Saved";
					
                    //reload page showing new name
                    var splits = o.responseText.split("|");
                    self.location.href="/student-profile/build-activity-resume/editResume/"+ splits[1];
                }else if (o.responseText.indexOf("DUPLICATE")>-1){
                    saveasmessagediv.innerHTML = "Name already in use";
                    return false;
                }
            }else{
                self.location.href="/wclogin";
            }
        	
        },
        failure : function(o) {
            alert('unable to save résumé at this time');
        }
    };

    //show AJAX swirly while saving
    saveasmessagediv.innerHTML = "<img src='/img/ajaxloadingsmall.gif' /> Saving...";
	
    YAHOO.util.Connect.setForm('saveasform', false);
    var conn = YAHOO.util.Connect.asyncRequest("POST", "/student-profile/build-activity-resume/saveActivityResume/"+activityResumeGk+"/-1/"+userGk+"/", callback);
}
///////////////////////////////////////////////////////////////
/** 
 * TO be used for Popups related to table labels.  
 *  showHelpPopup2()
 *  showHelpPopup1()
*/
//var helpPopupPanel; //flyout panel
/**
 * Help popup shown when a user clicks on a hyperlink that shows a bubble popup.  Used in onclick calls.
 * showHelpPopup2 attempts to center the help popup based on linkWidth
 * 
 * This call uses AJAX to load the title and description for the popup.
 * 
 * The helpGk is the id of the element itself.  Use element.id to get this value.
 * 
 * @param element -  the link used to position the popup over
 * @param helpGk - the gk for the help topic in the database
 * @param linkWidth - used to help center the popup on the x axis
 * @param tailDirection - only allowable value is "DOWN", "UP", or blank.  Default it blank with causes tail "UP".
 * 						- causes the help popup to display inverted
 * @return
*/

function ptShowHelpPopup(element, helpGk, linkWidth, tailDirection, popupHeight){
    var myX = YAHOO.util.Dom.getX(element);
    var myY = YAHOO.util.Dom.getY(element);
    var popupWidth = 300;
    //	var popupHeight = 265;
	
    if (tailDirection == undefined ||
        tailDirection.toUpperCase() != "DOWN" ||
        tailDirection.toUpperCase() == "UP"){
		
        tailDirection = "_TAILUP";
    }else{
        tailDirection = "";
    }
	
    helpPopupPanel = new YAHOO.widget.Panel("helpPopupPanel_label"+tailDirection,
    {
        x: myX - (popupWidth/3) + 10 + (linkWidth/2),
        y: myY + 10,
        y: (tailDirection=="")? myY - popupHeight : myY - popupHeight,
        width: popupWidth,
        fixedcenter: false,
        close: true,
        draggable: false,
        underlay:"none",
        zindex:999,
        modal: false,
	        	
        effect:{
            effect:YAHOO.widget.ContainerEffect.FADE,
            duration: 1
        }
    }
    );
    helpPopupPanel.setHeader("<div></div>");
    helpPopupPanel.setBody("<div><img src='/img/ajaxloadingsmall.gif' /> Loading...</div>");
    helpPopupPanel.setFooter("<!--must include to show tail-->");

    helpPopupPanel.render(element.parentNode);
    helpPopupPanel.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)){
                var CSVresponse = o.responseText;
                var CSVarray = CSVresponse.split("|");
                var title = CSVarray[0];
                var description = CSVarray[1];
                helpPopupPanel.setHeader("<div><br style='line-height:30px'/>&nbsp;&nbsp;"+title+"</div>");
        	    
                //	description = 'Do you expect this amount to change significantly in the year you start college?';
                helpPopupPanel.setBody("<div class='tablediv' style='padding-left:15px;color:#526E90 !important; text-align: left;padding-right: 5px;'><table><tr><td style='color:#526E90 !important;'><b>"+description+"</b></td><td>&nbsp;&nbsp;</td></tr></table></div>");
            }else{
                self.location.href="/wclogin";
            }
        	
        },
        failure : function(o) {
            helpPopupPanel.setBody(o.responseText);
        }
    };
    
    // Connect to our data source and load the data
    //    var conn = YAHOO.util.Connect.asyncRequest("GET", "/tools/help/popup/" + element.id, callback);
    
    var conn = YAHOO.util.Connect.asyncRequest("GET", "/tools/help/popup/" + helpGk, callback);
    return;
}
 
///////////////////////////////////////////
function pt_helpPopupPanelHide(e) {
    helpPopupPanel.hide();
    return;
}
///////////////////////////////////////////////////////////////

function wordwrap (str, int_width, str_break, cut) {
    // Wraps buffer to selected number of characters using string break char
    //
    // version: 1004.2314
    // discuss at: http://phpjs.org/functions/wordwrap    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Nick Callen
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Sakimori    // +   bugfixed by: Michael Grier
    // *     example 1: wordwrap('Kevin van Zonneveld', 6, '|', true);
    // *     returns 1: 'Kevin |van |Zonnev|eld'
    // *     example 2: wordwrap('The quick brown fox jumped over the lazy dog.', 20, '\n');
    // *     returns 2: 'The quick brown fox \njumped over the lazy\n dog.'    // *     example 3: wordwrap('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.');
    // *     returns 3: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod \ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim \nveniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea \ncommodo consequat.'
    // PHP Defaults
    var m = ((arguments.length >= 2) ? arguments[1] : 75   );
    var b = ((arguments.length >= 3) ? arguments[2] : "\n" );    var c = ((arguments.length >= 4) ? arguments[3] : false);

    var i, j, l, s, r;

    str += '';
    if (m < 1) {
        return str;
    }
     for (i = -1, l = (r = str.split(/\r\n|\n|\r/)).length; ++i < l; r[i] += s) {
        for (s = r[i], r[i] = ""; s.length > m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : "")){
            j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s.slice(m).match(/^\S*/)).input.length;
        }
    }
    return r.join("\n");
}
