
/*******************************************  SECURITY  ***************************************************************/
document.oncontextmenu = contextMenu; //uncomment this for  silent right click disable....
function contextMenu()
{
    return false;
}

var F5 = 116;
if (typeof window.event != 'undefined')
	document.onkeydown = function()
	{
		if (event.keyCode == F5) {
			if(parent.refreshPressed != 'undefined') {
				parent.refreshPressed = 'yes';
			}
		}
	}
else
	document.onkeypress = function(e)
	{
		if (e.keyCode == F5) {
			if(refreshPressed != 'undefined') {
				parent.refreshPressed = 'yes';
			}
		}
	}

// *************************************************** VALIDATION  ****************************************************//


function ie_mozilla (user_agent) // function that checks if clients browser is ie or mozilla  
{
  var ie = user_agent.match(/msie/);
  
  var mozilla = user_agent.match(/mozilla/);

  if(ie != null){
     return 'ie';
  }
  else if(mozilla != null){
     return 'mozilla';
  }
  else
  {
     return 'other';
  }
  
} // end function ie_mozilla

function moz_browser_name (user_agent)
{
 var name = 'Mozilla';
 
 var namesArr = new Array(/firefox\/\d+.\d+/, /safari/, /netscape\/\d+.\d+/, /opera/);
 
 var b_name = '';
 
 for(var count =0; count<namesArr.length; count++)
 { //alert(namesArr[count]);
   //b_name = user_agent.match(namesArr[count]);
   b_name = user_agent.match(namesArr[count]);
   //alert(b_name);
   if(b_name!=null)return b_name;
 }
 return b_name='';
}

function base_os_check(user_agent)
{
 //alert(user_agent);
 var os_type = new Array('win','mac','linux','freebsd');
 //var os_type = new Array('mac','linux');
 var user_os_type = '';
 
 //alert(user_os_type);
 
 for(var count = 0; count<os_type.length;count++)
 {
  user_os_type = user_agent.match(os_type[count]);
  if(user_os_type != null)
  {
   break;
  }
 }// end for 
 
 return user_os_type;
} // end function base_os_check(user_agent)

function failedBrowserCheck() {

	var browserType = "";
	var browserCheckFail = false;
	var temp_agt = navigator.userAgent.toLowerCase();

	if(ie_mozilla(temp_agt) == 'mozilla') {
		browserType = moz_browser_name(temp_agt).toString();
	} else {
		browserType = "ie";
	}

	//alert("browserType="+browserType);

	var osType = base_os_check(temp_agt);

	//alert("osType="+osType);

	if(osType == 'win') {
		if(browserType.indexOf('firefox') == -1 && browserType.indexOf('ie') == -1) {
			alert("Please use an IE or Firefox browser.");
			browserCheckFail = true;
		}
	} else if(browserType.indexOf('firefox') == -1) {
		alert("Please use a Firefox browser.");
		browserCheckFail = true;
	}
	
	return browserCheckFail;
	//window.location = 'blank.html';
}

function failedCookieCheck() {

	var cookieCheckFail = false;

	document.cookie="testcookie";
	var cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false;
	
	if(!cookieEnabled) {
		alert("Your browser does not allow cookies. Please enable them to view the presentation");
		cookieCheckFail = true;
		parent.window.location = '/nocookies.html';
	}

	return cookieCheckFail;
}
// *********************************************** For Post functions. ***********************************************************//

function doViewerTokenFormPost(formAction,formTarget) {
	//alert("doTokenFormPost("+formAction+", "+formTarget+")");
	var oldTarget = document.viewerTokenForm.target;
	var oldAction = document.viewerTokenForm.action;
	if(formTarget!='')document.viewerTokenForm.target = formTarget;
	if(formAction!='')document.viewerTokenForm.action = formAction;
	document.viewerTokenForm.submit();
	document.viewerTokenForm.target = oldTarget;
	document.viewerTokenForm.action = oldAction;
}

function addViewerToken(tname,tvalue) {
	var tokenForm = document.getElementById("viewerTokenForm");
	//alert("tokenForm="+tokenForm);
	if(tokenForm != null) {
		//alert(typeof tokenForm[tname]);
		if ((typeof tokenForm[tname])=="undefined") {
			var txtInp = document.createElement('input');   
			txtInp.setAttribute('type', 'hidden');
			txtInp.setAttribute('name',tname);
			txtInp.setAttribute('id',tname);
			txtInp.setAttribute('value',tvalue);
			tokenForm.appendChild(txtInp);
		} else {
			tokenForm[tname].value=tvalue;
		}
	} else {
		alert("form doesn't exist.  tName="+tname+ "  tValue="+tvalue);
	}         
}

function doPlayerTokenFormPost(formAction,formTarget) {
	//alert("doTokenFormPost("+formAction+", "+formTarget+")");
	var oldTarget = document.playerTokenForm.target;
	var oldAction = document.playerTokenForm.action;
	if(formTarget!='')document.playerTokenForm.target = formTarget;
	if(formAction!='')document.playerTokenForm.action = formAction;
	document.playerTokenForm.submit();
	document.playerTokenForm.target = oldTarget;
	document.playerTokenForm.action = oldAction;
}

function addPlayerToken(tname,tvalue) {
	var tokenForm = document.getElementById("playerTokenForm");
	//alert("tokenForm="+tokenForm);
	if(tokenForm != null) {
		//alert(typeof tokenForm[tname]);
		if ((typeof tokenForm[tname])=="undefined") {
			var txtInp = document.createElement('input');   
			txtInp.setAttribute('type', 'hidden');
			txtInp.setAttribute('name',tname);
			txtInp.setAttribute('id',tname);
			txtInp.setAttribute('value',tvalue);
			tokenForm.appendChild(txtInp);
		} else {
			tokenForm[tname].value=tvalue;
		}
	} else {
		alert("form doesn't exist.  tName="+tname+ "  tValue="+tvalue);
	}         
}
// ************************************************  POSITIONING/FORMATTING FOR UI  *********************************************//


/**
 * Returns style object for object whose ID is passed as argument
 */ 
function getStyleObject( objectId )
{
    if( document.getElementById && document.getElementById( objectId ) ) {
        return document.getElementById( objectId ).style;
    } else if ( document.all && document.all( objectId ) ) {
        return document.all( objectId ).style;
    } else {
        return false;
    }
}


function setFrameHeight() {
	var thisFrameHeight = 0;

	var thisFrameName = window.frameElement.name;
	var thisFrame = parent.document.getElementById(thisFrameName);
	var thisFrameContentLength = 0;
	var thisFrameHeight = thisFrame.offsetHeight;

	//var reglogFrame = top.document.getElementById("reglogin_frame");
	//var navFrame = top.document.getElementById("nav");
	var reglogFrame = getOuterLevelElement('reglogin_frame');
	var navFrame = getOuterLevelElement('nav');

	if (thisFrame.contentDocument && thisFrame.contentDocument.documentElement.offsetHeight) { //Firefox
		thisFrameContentLength = thisFrame.contentDocument.documentElement.offsetHeight+3; 
	} else if (thisFrame.Document && thisFrame.Document.body.scrollHeight) { // IE
		thisFrameContentLength = thisFrame.Document.body.scrollHeight;
	} else if (thisFrame.Document && thisFrame.Document.documentElement.scrollHeight) { // IE
		thisFrameContentLength = thisFrame.Document.documentElement.scrollHeight;
	}

	if(thisFrameName == 'main' && getOuterLevelVariable('mainFrameHeight') != 'undefined') {
		if(reglogFrame != null && reglogFrame != 'undefined' && reglogFrame != 'null') { // Type 3 or 4 (set both main and reglogin frames)
			thisFrame.style.height = Math.max(getOuterLevelVariable('regloginFrameHeight'), getOuterLevelVariable('regloginFrameContentLength'), getOuterLevelVariable('mainFrameHeight'), thisFrameContentLength);
			reglogFrame.style.height = Math.max(getOuterLevelVariable('regloginFrameHeight'), getOuterLevelVariable('regloginFrameContentLength'), getOuterLevelVariable('mainFrameHeight'), thisFrameContentLength);
		} else { // Type 1 or 2 (set main frame only)
			if(getOuterLevelVariable('mainType') == "1" && navFrame != null) {  // Type 1 sets both main and nav frames)
				thisFrame.style.height = Math.max(getOuterLevelVariable('navFrameHeight'), getOuterLevelVariable('navFrameContentLength'), getOuterLevelVariable('mainFrameHeight'), thisFrameContentLength);
				navFrame.style.height = Math.max(getOuterLevelVariable('navFrameHeight'), getOuterLevelVariable('navFrameContentLength'), getOuterLevelVariable('mainFrameHeight'), thisFrameContentLength);
			} else {
				thisFrame.style.height = Math.max(getOuterLevelVariable('mainFrameHeight'), thisFrameContentLength);
			}
		}
		
	} else if(thisFrameName == 'reglogin' && getOuterLevelVariable('regloginFrameHeight') != 'undefined') {
		thisFrame.style.height = Math.max(getOuterLevelVariable('regloginFrameHeight'), thisFrameContentLength);
	} else if(thisFrameName == 'nav' && getOuterLevelVariable('navFrameHeight') != 'undefined') {
		thisFrame.style.height = Math.max(getOuterLevelVariable('navFrameHeight'),thisFrameContentLength);
	} else if(thisFrameName == 'header' && getOuterLevelVariable('headerFrameHeight') != 'undefined') {
		thisFrame.style.height = Math.max(getOuterLevelVariable('headerFrameHeight'), thisFrameContentLength);
	} else {
		thisFrame.style.height = Math.max(thisFrameHeight, thisFrameContentLength);
	}

}

function redirectToTopFrame(frameAction) {
	
	if(document.getElementById("index_mainDiv") != null) {
		self.location=frameAction;
	} else if(parent.document.getElementById("index_mainDiv") != null) {
		parent.location=frameAction;
	} else if(parent.parent.document.getElementById("index_mainDiv") != null) {
		parent.parent.location=frameAction;
	} else if(parent.parent.parent.document.getElementById("index_mainDiv") != null) {
		parent.parent.parent.location=frameAction;
	} else {
		top.location=frameAction;
	}
}


function getOuterLevelElement(elementName) {
	//alert("inside tplibrary  getOuterLevelFrame("+elementName+")");

	// sets the target of the form to be one of the frames directly below the talkpoint outer window
	if(document.getElementById("index_mainDiv") != null) {
		return document.getElementById(elementName);
	} else if(parent.document.getElementById("index_mainDiv") != null) {
		return parent.document.getElementById(elementName);
	} else if(parent.parent.document.getElementById("index_mainDiv") != null) {
		return parent.parent.document.getElementById(elementName);
	} else if(parent.parent.parent.document.getElementById("index_mainDiv") != null) {
		return parent.parent.parent.document.getElementById(elementName);
	} else if(top.document.getElementById(elementName) != null){
		return top.document.getElementById(elementName);
	} else {
		return null;
	}
}

function getOuterLevelVariable(variableName) {
	//alert("inside tplibrary  getOuterLevelFrame("+elementName+")");
	
	var rtnValue = "";

	if(document.getElementById("index_mainDiv") != null) {
		rtnValue = variableName;
		return eval(rtnValue);
	} else if(parent.document.getElementById("index_mainDiv") != null) {
		rtnValue = 'parent.'+variableName;
		return eval(rtnValue);
	} else if(parent.parent.document.getElementById("index_mainDiv") != null) {
		rtnValue = 'parent.parent'+variableName;
		return eval(rtnValue);
	} else if(parent.parent.parent.document.getElementById("index_mainDiv") != null) {
		rtnValue = 'parent.parent.parent'+variableName;
		return eval(rtnValue);
	} else {
		return top.variableName;
	}
}


// *********************************************  DATA STORAGE / MANIPULATION  ***********************************************//


function Cookie(document, name, hours, path, domain, secure)
{
    this.$document = document;
    this.$name = name;
    if (hours)
        this.$expiration = new Date((new Date()).getTime() + hours * 60*30);
        //this.$expiration = new Date((new Date()).getTime() + hours * 3600000);
    else
        this.$expiration = null;
    if (path) this.$path = path; else this.$path=null;
    if (domain) this.$domain = domain; else this.$domain=null;
    if (secure) this.$secure = secure; else this.$secure=null;
}

function _Cookie_store()
{
    var cookieval = "";
    for (var prop in this){
        if ((prop.charAt(0) == '$') || ((typeof this[prop])== 'function'))
            continue;
        if (cookieval != "") cookieval += '&';
        cookieval += prop + ':' + escape(this[prop]);
    }
    
    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
      cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure=' + this.$secure;

    this.$document.cookie = cookie;
}

		
function getCookie( name ) 
{
    var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ){
        return null;
    }
	
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ';', len );
    if ( end == -1 ) end = document.cookie.length;
    return unescape( document.cookie.substring( len, end ) );
}


/**
 * Typical usage: setCookie( "producer.setDelay.<%=sEventID%>", 28000, 1, "", "", "" )
 *
 * Setting the path to "" will set it to the document path
 *
 * The length of time for the cookies defaults to days, so if you want shorter than a day
 * send in .5 for 12 hours or .25 for 6 hours, etc...
 * 
 */
 
function setCookie( name, value, expires, path, domain, secure ) {
    var today = new Date();
	
    today.setTime( today.getTime() );
    if ( expires ) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
	
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name+'='+escape( value ) +
        ( ( expires ) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
        ( ( path ) ? ';path=' + path : '' ) +
        ( ( domain ) ? ';domain=' + domain : '' ) +
        ( ( secure ) ? ';secure' : '' );
}

function deleteCookie( name, path, domain ) {
    if ( getCookie( name ) ) document.cookie = name + '=' +
            ( ( path ) ? ';path=' + path : '') +
            ( ( domain ) ? ';domain=' + domain : '' ) +
            ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}	
		
		
/* DONT USE THIS, USE SET COOKIE ABOVE
 * Function to add a cookie
 * @param name name of cookie to add
 * @param val id of cookie
 */
 
function addCookieShort(name,val) 
{
	var vs = new Cookie(document, name, (60*60*12));
	vs.id = val;
	vs.store();
}	


/*
 * @return XMLHttpRequest which provides scripted client functionality 
 * for transferring data between a client and a server
 * (AJAX uses this)
 */
 
function getXmlHttpObject() 
{
    var xmlHttp;
    
	try{// Firefox, Opera 8.0+, Safari
	  	xmlHttp=new XMLHttpRequest();
	}
	catch (e){// Internet Explorer
	  	try{
	    	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  	catch (e){
	    	try{
	      		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	      	}
	    	catch (e){
	      		alert("Your browser does not support AJAX!");
	      		return false;
	      	}
	    }
	}
	
    return xmlHttp;
}

//***************************************************  SESSION TRACKING   ******************************************************//

// current logout functions
function doTPLogout(eid, uid, email, ssid, text) {
	//alert("create logout url");

   var lourl = 'logout_user.jsp?eventid='+eid+'&userid='+uid+'&email='+escape(email)+'&sessionstart='+ssid;

   //document.getElementById('help').innerHTML = lourl;
   //alert("logouturl="+lourl);
   newajaxlogout(lourl);
  
}

function newajaxlogout(url)
{ 
	try { 
      var requester = new XMLHttpRequest(); 
	  requester.open("GET",url);
      requester.send(null);
      //alert("Thank You");
   } catch (error) { 
      try {	 
         var requester = new ActiveXObject("Microsoft.XMLHTTP"); 
		  requester.open("GET",url);
	   	  requester.send(null);
   		  //alert("Thank You");
      } catch (error) { 
	  	 window.open(url,'LOG_OUT','height=120,width=330,screenX=100,screenY=100,left=100,top=100');
         //return; 
      } 
   }
}


