var winPopup;
window.onfocus = ClosePopup;

// for printer friendly and email this page
var newWindow;
// debugger;

var _util = new function() {

      var m = document.location.pathname.match(/(.*\/Events)\/(\([0-9a-zA-Z]*\))*/i)
    var m1 = (m && m[1] != null ? m[1] : "");
    var m2 = (m && m[2] != null ? m[2] : "");

    if (m2 > "")
        m2 = "/" + m2;
    this.appRoot = m1 + m2;
}

function utility_GetAppRoot()
{
	return _util.appRoot;
}

function ValidateNumber(aFld)
{
	var s = aFld.value;	
	if (!validateNumeric(s) && s.length > 0)
	{		
		alert("Please enter a number");
		return false;
	}	
	return true;
}

function  validateNumeric( strValue ) {
/******************************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
******************************************************************************/
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 
 // ^[-+]?\d+(\.\d+)?
  //check for numeric characters 
  return objRegExp.test(strValue);
}

// for popup calendar
function GetDate(CtrlName) 
 {
  winPopup = window.open('/Events/Popup/Calendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName, 'winPopup', 'width=300,height=300,top=300,left=500,toolbars=no,scrollbars=no,status=no,resizable=no');
 }
 function GetDropDownDate(CtrlName) {
     var mmddyyyyClientId = CtrlName.split('-');
     var CtrlNValue = document.getElementById(mmddyyyyClientId[0]).value + "/" +  document.getElementById(mmddyyyyClientId[1]).value + "/" + document.getElementById(mmddyyyyClientId[2]).value;
     winPopup = window.open('/Events/Popup/Calendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName + '&CtrlValue=' + CtrlNValue, 'winPopup', 'width=300,height=250,top=300,left=500,toolbars=no,scrollbars=no,status=no,resizable=no');
 }
 //popup airports
 function GetAirport(Ctrl_APName, Ctrl_APCode)
 {
  winPopup = window.open('/Events/Popup/Airports.aspx?FormName=' + document.forms[0].name + '&CtrAPName=' + Ctrl_APName + '&CtrAPCode=' + Ctrl_APCode ,  'winPopup', 'width=750,height=800,top=300,left=500,toolbars=no,scrollbars=yes,status=no,resizable=no');
 }
 
// for popup email this page
function PopupEmailThisPage(PageID)
 {
  winPopup = window.open('/Events/Popup/EmailPage.aspx?page=' + PageID, "winPopup", "width=650,height=400,top=300,left=500,toolbars=no,scrollbars=no,status=no,resizable=no");
 } 

function CheckWindow()
{
	if (winPopup != null)
	{
		winPopup.close()
	}
}

function ClosePopup()
{
	 try
	  {
	    if (winPopup && typeof(winPopup.closed) != "'unknown'" && !winPopup.closed)
	    {
		  winPopup.close();
	    }
	    if (newWindow && typeof(newWindow.closed) != "'unknown'" && !newWindow.closed)
	    {
		  newWindow.close();
	    }
	  }
	 catch(e)
	  {
	  }
	
}

// ============================= < CSS Class helper functions ===============================
	// generic functions for changing style rules ***************************************
	function GetStyleSheetClass(cssClassName)
	{
		var ds = document.styleSheets;
		
		for(i = 0; ds.length > i; i++)
		{
			dsi = ds[i];
			if (dsi.rules != undefined)
			    dsir = dsi.rules; //IE

			else {
			    dsir = dsi.cssRules; //Mozilla, Firefox
			    if (dsir == null)
			        return;
			}

			for(j = 0; dsir.length > j; j++) {
			    if (dsir[j].selectorText == undefined)
			        return;
				var selectorText = dsir[j].selectorText.toLowerCase();
				//document.writeln(selectorText + "\\");
				if(selectorText.toLowerCase() == cssClassName.toLowerCase())
				{
					//for (si = 0;si < dsir[j].style.length; si++) {document.writeln(dsir[j].style[si] + "<br/>");}
					return dsir[j];
				}
			}
		}
		return null;
	}
	
	function ChangeStyleSheetRule(cssClassName,theRule,changeTo)
	{
		var cssClass = GetStyleSheetClass(cssClassName);
		
		alert(cssClass);
		
		if (cssClass!= null)
		{
			cssClass.style[theRule] = changeTo;
		}
	}
	
	function GetStyleSheetRuleValue(cssClassName,theRule)
	{
		var cssClass = GetStyleSheetClass(cssClassName);
		if (cssClass!= null)
		{
			return cssClass.style[theRule] ;
		}
		return "";
	}
	
	function CopyStyleSheetRule (fromClass, toClass, theRule)
	{
		var fromValue = GetStyleSheetRuleValue(fromClass, theRule);
		if (fromValue > "")
		{
			ChangeStyleSheetRule(toClass, theRule, fromValue);
		}
		
	}
	
	// specific function for changing style rules for html button ***************************************
	function ChangeHtmlButtonColorTheme(cssClassName,theRule,changeTo)
	{
		var cssTabBgrd1, ButtonReg;
		cssTabBgrd1 = GetStyleSheetClass("TD.TabBgrd1");
		ButtonReg = GetStyleSheetClass("SPAN.ButtonReg");

		if (cssTabBgrd1 == undefined || cssTabBgrd1 == null || ButtonReg == null) 
			return;
		ButtonReg.style["color"] = cssTabBgrd1.style["color"];
		ButtonReg.style["backgroundColor"] = cssTabBgrd1.style["backgroundColor"];
		
	}
	// use generic functions to copy TabBgrd1 color theme to Calendar Header class
	function ChangeCalendarHeaderColorTheme(cssClassName,theRule,changeTo)
	{	
		var cssTabBgrd1, CalendarHeader;		
		cssTabBgrd1 = GetStyleSheetClass("TD.TabBgrd1");
		CalendarHeader = GetStyleSheetClass("Table.CalendarHeader");
		
		if (cssTabBgrd1 == null || CalendarHeader == null) 
			return;
		CalendarHeader.style["color"] = cssTabBgrd1.style["color"];
		CalendarHeader.style["backgroundColor"] = cssTabBgrd1.style["backgroundColor"];			
	}
	
	// use generic functions to copy TabBgrd1 color theme to Calendar Next Prev text class
	function ChangeCalendarNextPrevStyle(cssClassName,theRule,changeTo)
	{	
		var cssTabBgrd1, CalendarNextPrevStyle;		
		cssTabBgrd1 = GetStyleSheetClass("TD.TabBgrd1");
		CalendarNextPrevStyle = GetStyleSheetClass("Font.CalendarNextPrevStyle");
		
		if (cssTabBgrd1 == null || CalendarNextPrevStyle == null) 
			return;
		CalendarNextPrevStyle.style["color"] = cssTabBgrd1.style["color"];
//		CalendarNextPrevStyle.style["backgroundColor"] = cssTabBgrd1.style["backgroundColor"];			
	}
	
	// use specific function to copy TabBgrd1 color theme to HTML button
	ChangeHtmlButtonColorTheme();	
	// use specific function to copy TabBgrd1 color theme to calendar header
	ChangeCalendarHeaderColorTheme();
	// use specific function to copy TabBgrd1 color theme to calendar next prev style
	ChangeCalendarNextPrevStyle();

// ============================= CSS Class helper functions > ===============================


// function to populate day drop down based on the selected month and year when using drop down lists for month, day, year
	function FillDayLookup(ddlMonth, ddlDay, ddlYear)
	{
		var SelectedMonthDays;
		var SelectedMonth = parseInt(ddlMonth.value, 10);
		if (SelectedMonth == 0)
		{return;}
		var SelectedYear = parseInt(ddlYear.value, 10);

		switch (SelectedMonth)
		{
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				SelectedMonthDays = 31;
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				SelectedMonthDays = 30;
				break;
			case 2:
				if (SelectedYear == 0)
				{SelectedMonthDays = 28;}
				else if (SelectedYear % 4 == 0)
				{SelectedMonthDays = 29;}
				else
				{SelectedMonthDays = 28;}
				break;
			default:
				SelectedMonthDays = 0;
				break;
		}

		if (SelectedMonthDays == 0)
		{return;}
		
		var CurrentMonthDays = ddlDay.options.length;
		
		if ((CurrentMonthDays) == SelectedMonthDays)
		{
			return;
		}
		else if (CurrentMonthDays <= SelectedMonthDays)
		{
			for (i=CurrentMonthDays+1; i<=SelectedMonthDays; i++)
			{
				var oDayOption = document.createElement("OPTION");
				oDayOption.value = i;
				oDayOption.text = i;
				ddlDay.options.add(oDayOption);
			}
		}
		else if (CurrentMonthDays > SelectedMonthDays)
		{
			for (i=CurrentMonthDays; i>=SelectedMonthDays; i--)
			{
				ddlDay.options.remove(i);
			}
		}
	}
// function to populate day drop down based on the selected month and year when using drop down lists for month, day, year

function Cvent_findElement(n, doc) {
  var p,i,x;  
	if(!doc) 
		doc=document; 
	/*
	if((p=n.indexOf("?"))>0 && parent.frames.length) 
	{
		doc=parent.frames[n.substring(p+1)].document; 
		n=n.substring(0,p);
	}
	*/
	if(!(x=doc[n]) && doc.all) 
		x=doc.all[n]; 
	for (i=0;!x&&i<doc.forms.length;i++) 
	{
		x=doc.forms[i][n];
	}
	for(i=0; !x && doc.layers && i<doc.layers.length; i++)
	{
		x=Cvent_findElement(n,doc.layers[i].document);
	}
	if(!x && doc.getElementById) 
		x=doc.getElementById(n); 
	return x;
}



function ToggleDisplay(objName, sDisplay)
{
	if (!Cvent_findElement)
	{
		alert("include utility.js");
	}
	if (!sDisplay)
	{
		sDisplay = "";
	}
	var obj = Cvent_findElement(objName);
	
	if(obj != null)
	{
		if (obj.style.display == "none")
		{
			obj.style.display = sDisplay;
		}
		else
		{
			obj.style.display = "none";
		}
	}
}

//this function is used to set the 
//default focus on a page to the very first control visible and active
//this function is used to set the 
//default focus on a page to the very first control visible and active
function SetDefaultFocus()
{		
    try
    {
        // for each form
        for (f=0; f < document.forms.length; f++)
        {
        // for each element in each form
            for(i=0; i < document.forms[f].length; i++)
            {
              // if it's not a hidden element and it's not disabled
              if (document.forms[f][i].type != "hidden" && document.forms[f][i].disabled != true)
              {       
                    document.forms[f][i].focus();
                    return;
              }      
            }//eof sub-for    
        }//eof main for
    }
    catch(e)
    {
        
    }
}

function SetFocus(focusElement) {    
    j$("[name ='" + focusElement + "']").focus()
}

function DisableEnterKey(e) {

    var key;

    if (!e) {
        e = window.event;
    }

    if (e.keyCode) {
        key = e.keyCode;
    }
    else {
        key = e.which;
    }

    return (key != 13);
}

function trim(value) {
    var temp = value;
    var obj = /^([\s|\n|\r]*)([\W\w]*)([\s|\n|\r]*$)/mg;
    if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
    var obj = /  /g;
    while (temp.match(obj)) { temp = temp.replace(obj, ""); }
    return temp;
}
// Sortable table jquery plugin [used on guet side attendee, staff pages]

if (window.jQuery) {
    (function(j$) {
        jQuery.fn.makeSortable = function() {
            this.each(function(i_table, v_table) {
                var tbl = j$(this).addClass("jquery-tablesort");
                if (tbl.get()[0].tagName.toUpperCase() == "TABLE") {
                    j$("th > *:first-child", tbl).each(function(i_col, v_col) {
                        var th = j$(this);
                        th.click(function() {
                            if (!j$(this).hasClass('isNotSortable')) {
                                var not = tbl.find("td table *");
                                tbl.find("tbody").not(not).each(function(i_tbody, v_tbody) {
                                    var rows = j$(v_tbody).find("tr").not(not);
                                    var bak = [], sort_as = null;
                                    rows.each(function(i_row, v_row) {
                                        var td = bak[i_row] = j$(this).find("td").not(not).eq(i_col).text() + "";
                                        var type =
                                      (!isNaN(Date.parse(td)) ? "date"
                                        : (!isNaN(new Number(td)) ? "number"
                                          : (!isNaN(new Number(td.replace(/^\j$/, ""))) ? "currency"
                                            : "string")));
                                        sort_as = (!!sort_as && sort_as != type ? "string" : type);
                                    });
                                    rows = rows.sort(function(a, b) {
                                        var va = j$(a).find("td").not(not).eq(i_col).text();
                                        var vb = j$(b).find("td").not(not).eq(i_col).text();
                                        if (sort_as == "date") {
                                            va = Date.parse(va);
                                            vb = Date.parse(vb);
                                            return (va < vb ? -1 : (va == vb ? 0 : 1));
                                        } else if (sort_as == "currency") {
                                            return (va.replace(/^\j$/, "") - vb.replace(/^\j$/, ""));
                                        } else if (sort_as == "number") {
                                            return (va - vb);
                                        } else if (sort_as == "string") {
                                            va = va.toString().toLowerCase();
                                            vb = vb.toString().toLowerCase();
                                            return (va < vb ? -1 : (va == vb ? 0 : 1));
                                        } else {
                                            return 0;
                                        }
                                    });
                                    var isAscendingMode = th.hasClass("sort-asc");
                                    j$(".sort-asc", tbl).not(not).removeClass("sort-asc");
                                    j$(".sort-desc", tbl).not(not).removeClass("sort-desc");
                                    var fnCheck = (function() {
                                        var areAllRowsEmpty = true;
                                        for (var i = 0; i < rows.size(); i++) {
                                            if (rows.eq(i).find("td").not(not).eq(i_col).text() != bak[i])
                                                return { retValue: false, isEmpty: areAllRowsEmpty };
                                            if (trim(bak[i]) != "") {
                                                areAllRowsEmpty = false;
                                            }
                                        }
                                        return { retValue: true, isEmpty: areAllRowsEmpty };
                                    })();

                                    if (fnCheck.retValue) {
                                        if (fnCheck.isEmpty) {
                                            if (isAscendingMode)
                                                th.removeClass("sort-asc").addClass("sort-desc");
                                            else
                                                th.removeClass("sort-desc").addClass("sort-asc");
                                        } else {
                                            rows = j$(rows.get().reverse());
                                            th.removeClass("sort-asc").addClass("sort-desc");
                                        }


                                    } else {
                                        th.removeClass("sort-desc").addClass("sort-asc");
                                    }
                                    j$(v_tbody).append(rows);
                                });
                                tbl.trigger('sort');
                            }
                        });
                    });
                    tbl.trigger('sort');
                }
            });
            return this;
        }
    })(jQuery);
}

function ShowModalPopup(triggerControId, pageUrl, width, height, bUsePartialIdMatch) {
  
    if (height == null)
        height = "300px";
    if (width == null)
        width = "270px";

    var dialogHtml = '<div id="dialog" style="height:' + height + ';width:' + width + ';overflow:auto;">' +
                            '<iframe id="frame" class="frame"  runat="server" height="95%" width="90%"  frameborder="0" />' +
                         '</div>';  //create content for dialog div
    j$('#dialogContentHolder').html(dialogHtml);      //set content to contentHolderDiv
    //Added onComplete on Colorbox Plugin to fix prod issue #31877
    if (bUsePartialIdMatch) {
        j$("[id $='" + triggerControId + "']").colorbox({ inline: true, href: j$("#dialog"), onComplete: function() { j$('#cboxTitle').css('display', 'none'); } }, setFrame(pageUrl));    //create dialog by setting the frames src    
    }
    else {
        j$('#' + triggerControId).colorbox({ inline: true, href: j$("#dialog"), onComplete: function() { j$('#cboxTitle').css('display', 'none'); } }, setFrame(pageUrl));     //create dialog by setting the frames src
    }

}
//function desinged for summary and payment page
function CallPopupConfirm(btnId, hdnConID) {
    if (hdnConID != null) {
        var hdnCon = document.getElementById(hdnConID);
        if (hdnCon != null)
            hdnCon.value = "1";
    }
    j$.fn.colorbox.close();
    j$('#' + btnId).click();
}
//function desinged for summary and payment page
function CallPopupCancel(btnId1) {
    if (btnId1 != null) {
        document.getElementById(btnId1).removeAttribute("onclick");
    }
    j$.fn.colorbox.close();
    clickedCount = 0; //reset clicked count when press cancel
    j$('.overlay').remove();
    j$('div.register-btn-bottom').removeClass('finish-registration');
    return false;
}

function ShowSFModalPopup(triggerControId, width, height, markup) {
   
    if (height == null)
        height = "300px";
    if (width == null)
        width = "400px";    
    var dialogHtml = '<div id="dialog" style="height:' + height + ';width:' + width + ';overflow:auto;" class="frame">' + markup +
                         '</div>';  //create content for dialog div
    
    j$('#dialogContentHolder').html(dialogHtml);      //set content to contentHolderDiv

    j$('#dummyDialogBtn').colorbox({ inline: true, href: j$("#dialog"), escKey: false, overlayClose: false });     //create dialog by setting the frames
}

function ShowApplyDiscountModalPopup(triggerControId, width, height, markup) {
   
    if (height == null)
        height = "300px";
    if (width == null)
        width = "400px";    
    var dialogHtml = '<div id="dialog" style="height:' + height + ';width:' + width + ';overflow:auto;" class="frame">' + markup +
                         '</div>';  //create content for dialog div
    
    j$('#dialogContentHolder').html(dialogHtml);      //set content to contentHolderDiv

    j$('#dummyDialogBtnForDiscount').colorbox({ inline: true, href: j$("#dialog"), escKey: false, overlayClose: false });     //create dialog by setting the frames
}

function CallApplyDiscountPopupSave(sDscntCode, bIsBulkReg, sRegCartStub, nRegCartStatusId, hdnAttendeeListID) {
    if (hdnAttendeeListID != null) {
        var hdnAttendeeList = document.getElementById(hdnAttendeeListID);
        if (hdnAttendeeList != null) {
            j$('table#tblRCA input[type=checkbox]:checked').each(function (i) {
                hdnAttendeeList.value = hdnAttendeeList.value + this.value + ",";
            });
        }
    }
    PageMethods.ApplyDiscountCodeFromPopup(sDscntCode, bIsBulkReg, sRegCartStub, nRegCartStatusId, hdnAttendeeList.value, hdnAttendeeListID, OnApplyDiscountSuccess, null);
    return false;
}

function OnApplyDiscountSuccess(result) {
    if (result != "") {
        var array = result.split(";");
        var div = document.getElementById('divError');
        var p = document.getElementById('pError');
        div.style.display = '';
        p.innerHTML = array[0];

        var hdnAttendeeList = document.getElementById(array[1]);
        hdnAttendeeList.value = "";
    }
    else {
        j$.fn.colorbox.close();
        document.aspnetForm.submit();
    }

}

function CallApplyDiscountPopupCancel(btnId1) {
    j$.fn.colorbox.close();
    return false;
}

function OpenSingleChoicePopup(pageURL) {
    winPopup = window.open(pageURL + '&FormName=' + document.forms[0].name, "window1", "width=500px,height=520px,top=300,left=500,toolbars=no,scrollbars=no,status=no,resizable=no");
}

function setFrame(pageUrl) {
    j$('.frame').attr('src', pageUrl)
}

function ShowSingleChoicePopUp(triggerControId, pageUrl, width, height) {
    j$('#' + triggerControId).colorbox({ iframe: true, href: pageUrl, innerWidth: width, innerHeight: height });

}


var MRSessionTimeoutID;

//Session Timout due to Inactivity Methods
var MRSessionTimeoutValue = 59;  // 59
var MRSessionTimeoutOffset = 19; //40
function StartSessionTimer(sSmmFromStub) {
    // disable the timer if document is in the frame
    if (window.top.location != document.location) {
        return;
    }
    set_cookie("MRTimeout", (new Date()).toUTCString(), null);
    MRSessionTimeoutID = window.setTimeout("SessionTimeoutPopup('" + sSmmFromStub + "')", 60000 * (MRSessionTimeoutValue - MRSessionTimeoutOffset));

}

function set_cookie(name, value, expirationDate) {
    document.cookie = name + "=" + value + ";path=/;" + (expirationDate == null ? "" : "expires=" + expirationDate.toUTCString());
}

function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        // if cookie exists
        if (offset != -1) {
            offset += search.length
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset);
            // set index of end of cookie value
            if (end == -1) end = document.cookie.length;
            returnvalue = unescape(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;

}

function SessionTimeoutPopup(sSmmFromStub) {
    // check if there are activities from other broswer instances/tabs

    var latm = get_cookie("MRlatm");
    if (latm.length > 0) {
        var dLmt = new Date(latm);
        var dNow = new Date((new Date()).toUTCString());
        var cTimer = new Date(get_cookie("MRTimeout"));
        if (((dNow.getTime() - dLmt.getTime()) < (60000 * (MRSessionTimeoutValue - MRSessionTimeoutOffset)))
                &&
            ((dNow.getTime() - cTimer.getTime()) < (60000 * (MRSessionTimeoutValue - MRSessionTimeoutOffset)))) {
            return;
        }

    }
    var getPageSize = function() {
        var xScroll, yScroll;
        if (window.innerHeight && window.scrollMaxY) {
            xScroll = window.innerWidth + window.scrollMaxX;
            yScroll = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }

        var windowWidth, windowHeight;

        if (self.innerHeight) {	// all except Explorer
            if (document.documentElement.clientWidth) {
                windowWidth = document.documentElement.clientWidth;
            } else {
                windowWidth = self.innerWidth;
            }
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowWidth = document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }

        // for small pages with total height less then height of the viewport
        if (yScroll < windowHeight) {
            pageHeight = windowHeight;
        } else {
            pageHeight = yScroll;
        }

        // for small pages with total width less then width of the viewport
        if (xScroll < windowWidth) {
            pageWidth = xScroll;
        } else {
            pageWidth = windowWidth;
        }
        //////////   Added width limit as stupid IE looses opacity when you increase the width of the box beyound certain limit.
        if (Prototype.Browser.IE && xScroll > 1500)
            xScroll = 1500;

        return [xScroll, pageHeight];
        //return [pageWidth, pageHeight];
    };

    //Parent div(transparent) to make the backgroud grayed out
    window.focus();
    var divTag = document.getElementById("divSession");
    var divParent = document.getElementById("divParent")

    if (divParent == null) {
        divParent = document.createElement("div");
        divParent.id = "divParent";
        divParent.className = "transparentDiv";
        divTag = document.createElement("div");
        divTag.id = "divSession";
        divTag.setAttribute("align", "center");
        divTag.className = "dynamicDiv";
        divTag.innerHTML = "<table cellspacing='0' cellpadding='0' style='width:100%;border-style:none;'>"
                        + "<tr height='20%'><td style='border:1px solid black; padding-left:10px;text-align:center'><img src='/a/images/cvent_logo.gif' /></td></tr>"
                        + "<tr height='20%'><td align='center' class='FormSubSecHeadCenter' style='font-size:16px;border-left: 1px solid black;border-right: 1px solid black;color:#303030;'><br/>This session is about to expire.<br/></td></tr>"
                        + "<tr height='60%'><td class='FormLabelNoTextAlignWidth' align='center' style='font-size:14px;;border-left: 1px solid black;border-right: 1px solid black; border-bottom:1px solid black;color:#303030;' >Click <b>Continue</b> to continue with this session and complete the form.<br/>Click <b>Close</b> to end this session and exit this form.<br/><br/></br><br/><br/><input type='image' id='btn_Continue' OnClick='ContinueSession(\"" + sSmmFromStub + "\")' src='/a/images/button_continue.gif' />&nbsp;&nbsp;&nbsp;<input  type='image' id='btn_logout' OnClick='LogoutSession(\"" + sSmmFromStub + "\")' src='/a/images/button_close.gif'/><br/><br/></td></tr>"
                        + "</table>";
        document.body.appendChild(divParent);
        var pageSize = getPageSize();
        divParent.style.width = pageSize[0];
        divParent.style.height = pageSize[1];
        document.body.appendChild(divTag);
    }
    else {
        divParent.style.display = "block";
        divTag.style.display = "block";
    }
    
    //Setting the width and height of the div.
    if (typeof(document.viewport) != "undefined") {
        var arrayPageScroll = document.viewport.getScrollOffsets();
        var divTop = 100; var divLeft = 300;
        $(divTag).setStyle(
        {
            top: (arrayPageScroll.top + divTop) + 'px',
            left: (arrayPageScroll.left + divLeft) + 'px'
        }
     );
    }
   
    // start second timer for automatically close window 1 min later
    window.setTimeout('if (document.getElementById("divSession").style.display != "none") RedirectToLogin(\"' + sSmmFromStub + '\");', 60000);
}

function ContinueSession(sSmmFromStub) {
    new Ajax.Request(utility_GetAppRoot() + "/images/pix.aspx?img=0",
                    {
                        //postBody: '',
                        method: 'get',
                        //contentType: "application/json",
                        onSuccess: onSuccessRecieve.bindAsEventListener(this, sSmmFromStub),
                        onFailure: function(res) { RedirectToLogin(sSmmFromStub) }
                    });
    document.getElementById("divSession").style.display = "none";
    document.getElementById("divParent").style.display = "none";
}

function onSuccessRecieve(req, sSmmFromStub) {
    if (req.status == 200) {
        StartSessionTimer(sSmmFromStub);
    }
    else {
        RedirectToLogin(sSmmFromStub);
    }
}

function RedirectToLogin(sSmmFromStub) {
    new Ajax.Request(utility_GetAppRoot() + "/images/pix.aspx",
            {
                postBody: '',
                method: 'post',
                //contentType: "text/html",
                onSuccess: function(transport) { document.location = utility_GetAppRoot() + "/SMMForm/MeetingRequest/Logout.aspx?smm_form_stub=" + sSmmFromStub; },
                onFailure: function(transport) { document.location = utility_GetAppRoot() + "/SMMForm/MeetingRequest/Logout.aspx?smm_form_stub=" + sSmmFromStub; }
            });
          
      }

function LogoutSession(sSmmFromStub) {
  if (document.getElementById("divSession").style.display == "none") {
      return;
  }

  var sUrl = utility_GetAppRoot() + "/SMMForm/MeetingRequest/Logout.aspx?smm_form_stub=" + sSmmFromStub;
  window.location = sUrl;
}


