﻿// JScript File
$(function() {
    //scrollpane parts
    var pppGrid = $('.ppp-grid, .ppp-body');
    var pppGridContent = $('.ppp-grid-content');
    var scrollPane = $('.ppp-grid-pane');
    var hdrPane = $('.ppp-grid-hdr-pane');
    var sideLPane = $('.ppp-grid-side-left');
    var scrollContentX = $('.ppp-grid-scroll-x');
    var scrollContentY = $('.ppp-grid-scroll-y');
    var $window = $(window);
    var gridPanex = $('.ppp-grid-pane-x');
    var gridPaney = $('.ppp-grid-pane-y');
    var $wrapper = $('#wrapper');

    //build slider
    var scrollbarx = $(".ppp-scroll-bar-x").slider({
        value: 0,
        slide: function(e, ui) {
            if (scrollContentX.width() > scrollPane.width()) { scrollContentX.css('margin-left', Math.round(ui.value / 100 * (scrollPane.width() - scrollContentX.width())) + 'px'); }
            else { scrollContentX.css('margin-left', 0); }
            sizeScrollbar();
        }
    });
    var scrollbary = $(".ppp-scroll-bar-y").slider({
        orientation: "vertical",
        min: -100,
        max: 0,
        slide: function(e, ui) {
            if (scrollContentY.height() > scrollPane.height()) { scrollContentY.css('margin-top', Math.round(ui.value * -1 / 100 * (scrollPane.height() - scrollContentY.height())) + 'px'); }
            else { scrollContentY.css('margin-top', 0); }
            sizeScrollbar();
        }
    });

    //append icon to horizontal handle
    var handleHelperX = scrollbarx.find('.ui-slider-handle')
            .mousedown(function() {
                scrollbarx.width(handleHelperX.width());
            })
            .mouseup(function() {
                scrollbarx.width('100%');
            })
            .append('<span class="ui-icon ui-icon-grip-dotted-vertical"></span>')
            .wrap('<div class="ui-handle-helper-parent"></div>').parent();

    //append icon to vertical handle
    var handleHelperY = scrollbary.find('.ui-slider-handle')
	        .mousedown(function() {
	            scrollbary.height(handleHelperY.height());
	        })
	        .mouseup(function() {
	            scrollbary.height('100%');
	        })
	        .append('<span class="ui-icon ui-icon-grip-dotted-horizontal"></span>')
	        .wrap('<div class="ui-handle-helper-parent"></div>').parent();

    //change overflow to hidden now that slider handles the scrolling
    scrollPane.css('overflow', 'hidden');

    //size scrollbar and handle proportionally to scroll distance
    function sizeScrollbar() {
        var bottomMargin = scrollbary.slider('value');
        bottomMargin *= -1;

        if (bottomMargin == 0) bottomMargin = 1;
        bottomMargin = 1 - (bottomMargin * .01);
        scrollbary.find('.ui-slider-handle').css({
            height: 75,
            'margin-bottom': -75 * bottomMargin
        });

        var leftMargin = scrollbarx.slider('value');

        if (leftMargin == 0) leftMargin = 1;
        leftMargin = (leftMargin * .01);
        scrollbarx.find('.ui-slider-handle').css({
            width: 75,
            'margin-left': -75 * leftMargin
        });
        if (scrollContentX.width() <= scrollPane.width())
            scrollbarx.parent().hide();
        scrollbary.height(scrollPane.height());
        scrollbarx.width(scrollPane.width());
    }

    setTimeout(sizeScrollbar, 10); //safari wants a timeout

    function resizeFullView() {
        var addedWidth = $window.width() - pppGrid.outerWidth() - 25;
        var addedHeight = $window.height() - pppGrid.outerHeight() - 25;
        pppGrid.css({
            height: pppGrid.height() + addedHeight,
            width: pppGrid.width() + addedWidth,
            left: 12,
            position: 'absolute',
            top: 0
        });
        scrollPane.css({
            width: scrollPane.width() + addedWidth,
            height: scrollPane.height() + addedHeight
        })
        pppGrid.trigger('resize');
        $(this).html('Reduce');
    }

    $('.ppp-grid-fullview').toggle(function() {
        isFullView = true;
        resizeFullView.call(this);
    }, function() {
        isFullView = false;
        $(this).html('Expand');
        pppGrid.css({
            width: 600,
            height: 670,
            left: 'auto',
            top: 'auto',
            position: 'relative'
        });
        scrollPane.css({
            width: 'auto',
            height: 600
        });
        pppGrid.trigger('resize');
    });

    (function() {
        $window.resize(function() {
            var wrapperHeight = $wrapper.height();
            var windowHeight = $window.height();
            var pppGridHeight = pppGrid.height();
            var height;

            height = windowHeight - wrapperHeight;
            if (pppGridHeight > 200 || height > 0) {
                pppGrid.height(pppGridHeight + height);
                //scrollPane.height(scrollPane.height() + height);

                // same as pppGrid.trigger('resize');
                // but runs faster for some reason
                gridPaney.height(pppGrid.height() - 70);
                gridPanex.width(pppGrid.width() - 200);
                sizeScrollbar();
            }
        });
        $window.resize();
    } ());

});


function MtgPPP() {
    this.PPPSessionKey = "";
    this.MeetingID = 0;
}
MtgPPP.prototype.isEmail = function(str) 
{
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) 
  {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > str.indexOf("@")+1) && (str.indexOf("@") > 1);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}
MtgPPP.prototype.ValidateEmail = function(obj) 
{
	if (obj.value.length ==0) 
	{
		alert ("Please enter a valid email address.");
		obj.focus();
		return false;
	}
	
	if (!this.isEmail(obj.value))
	{
		alert ("Please check your email address,\n it is not a valid email address format.");
		obj.focus();
		return false;
	}
	
	return true;
}
MtgPPP.prototype.EventDetail = function(EventID) 
{
  txtWin = window.open("eventviewer.asp?ID="+ EventID,'PPPDetail',"width=700,scrollbars");
  txtWin.focus();
}
MtgPPP.prototype.SubEventList = function(EventID) 
{
  txtWin = window.open("subeventlist.asp?ID="+ EventID,'SubEventList',"width=700,scrollbars");
  txtWin.focus();
}
MtgPPP.prototype.PrintPP = function(PPPSessionKey) 
{
  txtWin = window.open("printPP.asp?PPPSK="+ this.PPPSessionKey,'PrintPP',"width=700,scrollbars");
  txtWin.focus();
}
MtgPPP.prototype.EmailPP = function(PPPSessionKey) 
{
  txtWin = window.open("emailPP.asp?PPPSK="+ this.PPPSessionKey,'EmailPP',"width=550,height=350,scrollbars");
  txtWin.focus();
}
MtgPPP.prototype.PPHelp = function() 
{
  txtWin = window.open("help.asp",'PPPHelp',"width=700,scrollbars");
  txtWin.focus();
}
MtgPPP.prototype.ToggleImg = function(myid)
{
	var imgRef = MM_findObj(myid)
	if (imgRef);	// see if image exists
	{
		if(imgRef.src.indexOf("Open")>=0)
		{
			imgRef.src='/Images/Mtg/FolderClose.gif';
			var newval = 0;
		}
		else
		{
		imgRef.src='/Images/Mtg/FolderOpen.gif';
		var newval = 1;
		}
	}
}
MtgPPP.prototype.ShowPPUpdate = function(msg)
{
    var objS = document.getElementById('PPUpdateDiv');
    var coord = this.findPos(obj);
    var objP = this;
    var action;

    objS.innerHTML = msg;

    ctlS.style.margin='5px';
    ctlS.onmouseout = function(){objP.PPUpdate(eventID,action);objP.HidePPUpdate();};
    objS.appendChild(ctlS);
    
    objS.style.left=(coord[0])+'px';
    objS.style.top=coord[1]+'px';
    objS.style.display='block';
}
MtgPPP.prototype.HidePPUpdate = function()
{
    var objS = document.getElementById('PPUpdateDiv');

    objS.style.display='none';
}
MtgPPP.prototype.findPos = function(obj) 
{
	var curleft = curtop = 0;
	var b = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while ((obj = obj.offsetParent) && b<3) {
			b +=1;
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}
MtgPPP.prototype.ReadUpdateMessage = function(xmlMsg)
{
    var events = xmlMsg.getElementsByTagName('events').item(0);
    
    var eventid=0;
    var selected="";
    var objI;
    var node;
    var objP = this;
    var action;

        
    for (var i = 0; i < events.childNodes.length; i++)
    {
        node = events.childNodes.item(i);
        eventid=node.getAttribute('id');
        selected = node.getAttribute('selected');
        
        if(eventid!=null)
        {   
            objI=document.getElementById('PPImg_'+eventid);
            if(objI!=null)
            {
                if(selected!=null && selected=='D') 
                {
                    objI.src='/images/mtg/PPDelIcon.gif';
                    objI.title='Delete from schedule';
                    action='del';
                }
                else
                {
                    objI.src='/images/mtg/PPAddIcon.gif';
                    objI.title='Add to schedule';
                    action='add';
                }
                objI.style.display='block';
            }
        }
    }
}

MtgPPP.prototype.getXMLHttpRequest = function()
{  
    var xmlHttp;
    try { xmlHttp=new XMLHttpRequest(); }
    catch (e)
    {     
        try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e)
        {
            try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (e)
            { xmlHttp=false; }
        }
    }
    return xmlHttp;
}

MtgPPP.prototype.RequestData = function(postdata, callback)
{
    var xmlHttp = this.getXMLHttpRequest();
    
    xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4){callback(xmlHttp);}}
    xmlHttp.open("POST","/meetings/meeting9/PPP/PPPCB.asp",true);
	xmlHttp.setRequestHeader('User-Agent','XMLHTTP/1.0');
	xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader('Content-length',postdata.length);
    xmlHttp.send(postdata);
}

MtgPPP.prototype.PPUpdate = function(eventID, action)
{
    var obj=this;
    if(eventID!=null&&eventID>0)
    {
        this.RequestData('PPPSessionKey=' + this.PPPSessionKey + '&meetingid=' + this.MeetingID + '&pgs=PP&action=' + action + '&eventid='+eventID, function (xmlHttp){obj.ReadUpdateMessage(xmlHttp.responseXML);});
    }
}
MtgPPP.prototype.PPUpdate2 = function(obj)
{
    var id = obj.id.slice(6);
    var action;
    if(obj.title.toLowerCase().match('delete')==null) action='add'; 
    else action='del';

    this.PPUpdate(id, action);
}
MtgPPP.prototype.PPActivate = function()
{
    var obj=this;
    if(this.PPPSessionKey!="")
        this.RequestData('PPPSessionKey=' + this.PPPSessionKey + '&meetingid=' + this.MeetingID + '&pgs=PP&action=list',  function(xmlHttp){obj.ReadUpdateMessage(xmlHttp.responseXML);});
}

