HTML_HOME = '';
var DHTML = (document.getElementById || document.all || document.layers);

		function getObj(name)
		{
		    this.obj   = null;
		    this.style = null;
  			if (document.getElementById)
  			{
  				this.obj = document.getElementById(name);
				if (this.obj != null)
					this.style = document.getElementById(name).style;
  			}
  			else if (document.all)
  			{
				this.obj = document.all[name];
				if (this.obj != null)
					this.style = document.all[name].style;
  			}
  			else if (document.layers)
  			{
   				this.obj = document.layers[name];
				if (this.obj != null)
   					this.style = document.layers[name];
  			}
  			
		}

		function hideDiv($targetDiv)
		{
			if (!DHTML) return;
			var x = new getObj($targetDiv);
			if (x.obj != null) 	x.style.display = 'none';
		}
		function showDiv($targetDiv)
		{
			if (!DHTML) return;
			var x = new getObj($targetDiv);
  			if (x.obj != null) 	x.style.display = 'inline';
		}
		function toggleDiv($targetDiv)
		{
			if (!DHTML) return;
			var x = new getObj($targetDiv);
  			if (x.obj != null)
			{	
				if (x.style.display == 'none')
				{	x.style.display = 'inline';	}
				else if (x.style.display == 'inline')
				{	x.style.display = 'none';	}
				else if (x.style.display == 'block')
				{	x.style.display = 'none';	}
			}	 	
		}
		function setFocus($target)
		{
			if (!DHTML) return;
			var x = new getObj($target);
  			if (x.obj != null) 	x.obj.focus();
		}

		function enableField($target)
		{
//alert('in enableField, target='+$target);		  
			if (!DHTML) return;
			var x = new getObj($target);
  			if (x.obj != null) 	x.obj.disabled = false;
		}
		function disableField($target)
		{
//alert('in disableField, target='+$target);		  
			if (!DHTML) return;
			var x = new getObj($target);
  			if (x.obj != null) 	x.obj.disabled = true;
		}

		function setHTML($target,$sHTML)
		{
			if (!DHTML) return;
			var x = new getObj($target);
  			if (x.obj != null) 	x.obj.innerHTML = $sHTML;
		}

// 2/17/2007 UNTESTED!!!
		function setStyle($target,$sProperty,$sStyle)
		{
			if (!DHTML) return;
			var x = new getObj($target);
  			if (x.obj != null) 
			{
//				if ($sProperty == 'background-color') 	x.style.background-color = $sStyle;
				x.style.$sProperty = $sStyle;
			}  
		}

	function popitup(url,name,height,width) 
	{
		newwindow=window.open(url,name,'height='+height+',width='+width);
		if (window.focus) { newwindow.focus(); }
		return false;
	}

	function util_addEvent(obj, evType, fn)
	{ 
		if (obj.addEventListener)
		{ 
		   obj.addEventListener(evType, fn, false); 
		   return true; 
		} 
		else if (obj.attachEvent)
		{ 
		   var r = obj.attachEvent("on"+evType, fn); 
		   return r; 
		} 
		else 
		{ 
		   return false; 
		} 
	}


// ------------------------------------------------------
//      local actions here
// ------------------------------------------------------
// these may be called by the server code (video.server.php)
		function setSessionInfo($isLoggedIn,$username,$item_id)
		{
			isLoggedIn = $isLoggedIn;		  
			username   = $username;		  
			item_id    = $item_id;		  
		}
		function setUserLoggedIn($isLoggedIn)
		{
			isLoggedIn = $isLoggedIn;		  
		}
		function setUserName($username)
		{
			username = $username;		  
		}
		function setItemId($item_id)
		{
			item_id = $item_id;		  
		}
		function getItemId()
		{
			return item_id;		  
		}

		function enableIdentifySelf()
		{
		  setUserLoggedIn(false);
		  hideDiv('loginFormWrapper');
		  hideDiv('signupFormWrapper');
	  	  hideDiv('leaveComment');  
	  	  hideDiv('commentStatusDiv');  

		  showDiv('navRegLog');
		  showDiv('identifySelf');
		}

		function cancelSignupForm()
		{
/*		  signupForm.reset();   */  /* netscape chokes on this */
		  xajax.$('signupButton').disabled=false;
		  xajax.$('signupButton').value="Sign Up!";
		  hideDiv('signupFormWrapper');
		  hideDiv('globalContainer');
		  showDiv('navRegLog');
		  showDiv('identifySelf');		
		}

		function cancelLoginForm()
		{
/*		  loginForm.reset();   */  /* netscape chokes on this */
		  xajax.$('loginButton').disabled=false;
		  xajax.$('loginButton').value="Log In!";
		  hideDiv('loginFormWrapper');
		  hideDiv('globalContainer');
		  showDiv('navRegLog');
		  showDiv('identifySelf');		
		}

		function enableCommentForm()
		{
		  if (isLoggedIn)
		  {
		    hideDiv('loginFormWrapper');
		    hideDiv('signupFormWrapper');
		    hideDiv('leaveComment');
		    showDiv('commentFormDiv');
		    setFocus('cname');
		  }
		}
		function cancelCommentForm()
		{
/*		  commentForm.reset();  */  /* netscape chokes on this */
		  xajax.$('commentButton').disabled=false;
		  xajax.$('commentButton').value="Add Comment";
		  hideDiv('commentFormDiv');
		  hideDiv('leaveComment');
		  hideDiv('memberStatusDiv');
		}

		function enableMemberLinks()
		{
		  setUserLoggedIn(true);
		  hideDiv('navRegLog');
		  hideDiv('identifySelf');
		  hideDiv('loginFormWrapper');
		  hideDiv('signupFormWrapper');
		  hideDiv('globalContainer');

		  showDiv('hdrGreeting');		
		  showDiv('navGreeting');		
		  showDiv('navMemMsg');		
		  showDiv('hdrMemMsg');		
		  showDiv('memberStatusDiv');		
	  	  showDiv('leaveComment');  
		}

                function refreshPage()
                {
	  	  // refresh page if needed
	  	  if (pageIsMemberOnly)
	  	  {
	  	        location.href = location.href;
	  	  }
                }

		function enableMemberComment()
		{
		  setUserLoggedIn(true);

		  hideDiv('navRegLog');
	  	  hideDiv('identifySelf');  
		  hideDiv('loginFormWrapper');
		  hideDiv('signupFormWrapper');
	  	  hideDiv('leaveComment');  
		  hideDiv('commentStatusDiv');		

//  memberStatusDiv was set by the register/login code
//  commentStatusDiv will be set, if needed, by the process comment code

		  showDiv('memberCommentDiv');
		  setFocus('memberComment');
		}

		function disableMemberComment()
		{
		  setUserLoggedIn(false);

		  hideDiv('loginFormWrapper');
		  hideDiv('signupFormWrapper');
		  hideDiv('leaveComment');		
		  hideDiv('memberCommentDiv');		
		  hideDiv('commentStatusDiv');		
		  hideDiv('hdrMemMsg');     /* Jul 15, 2007 */		

		  /* showDiv('navMemMsg');   */  /* Jul 4, 2007 */		
		  showDiv('memberStatusDiv');		
		  showDiv('navRegLog');
		  showDiv('identifySelf');
		}

		function cancelMemberCommentForm()
		{
		/*  memberCommentForm.reset(); */  /* netscape chokes on this */
		  xajax.$('memberComment').value="";
		  xajax.$('memberCommentButton').disabled=false;
		  xajax.$('memberCommentButton').value="Add Comment";
		  hideDiv('memberCommentDiv');
		  
		  showDiv('navMemMsg');		
		  showDiv('memberStatusDiv');		
		  showDiv('leaveComment');		
		}

		function enableGroupMessage()
		{
	  	  hideDiv('leaveMessage');  

		  showDiv('groupMessageDiv');
		  setFocus('groupMessage');
		}

		function disableGroupMessage()
		{
		  hideDiv('leaveMessage');		
		  hideDiv('groupMessageDiv');		
		}

		function cancelGroupMessageForm()
		{
		/*  memberMessageForm.reset(); */  /* netscape chokes on this */
		  xajax.$('groupMessage').value="";
		  xajax.$('groupMessageButton').disabled=false;
		  xajax.$('groupMessageButton').value="Add Message";
		  hideDiv('groupMessageDiv');
		  
		  showDiv('leaveMessage');		
		}

		function needsSignupOrLoginHelp()
		{
        	location.href = HTML_HOME+'/SignUp.php?from='+location.href;
		}

		function wantsToComment()
		{
		  if (isLoggedIn)
		  {
		    hideDiv('navMemMsg');		
			hideDiv('memberStatusDiv');		     
			enableMemberComment('leaveComment','memberCommentDiv');
		  }
		  else
		  {
			response = confirm('You need to login or sign up for a free account in order to comment.\nSigning up is quick and easy: we only ask for username, password, and email address (for security).\nWould you like to login or sign up now?');
			if (response)
			{
              location.href = HTML_HOME+'/SignUp.php?from='+location.href;
            }
		  }
		}
        function addToPlaylist($item_id,$shortTitle,$targetDiv)
        {
// alert("item="+$item_id+", shortTitle="+$shortTitle+", target="+$targetDiv);
		  if (isLoggedIn)
		  {
			showPlaylistForm($item_id,$shortTitle,$targetDiv);
		  }
		  else
		  {
			response = confirm('You need to login or sign up for a free account in order to add to a playlist.\nSigning up is quick and easy: we only ask for username, password, and email address (for security).\nWould you like to login or sign up now?');
			if (response)
			{
                     location.href = HTML_HOME + '/SignUp.php?from=' + location.href;
                  }
		  }
        }

		function launchPlaylist(listid)
		{
			location.href = HTML_HOME + "/videoserver/playlist.php&id=" + listid;

		    return false;
		}

		function enableShare()
		{
		  /* show the form, as "popup"? */
		  showDiv('shareFormWrapper');
		  setFocus('friend');
		}
		function cancelShareForm()
		{
/*		  shareForm.reset();  */  /* netscape chokes on this */
		  xajax.$('shareButton').disabled=false;
		  xajax.$('shareButton').value="Send Email";
		  hideDiv('shareFormWrapper');
		}

		function cancelGlobalContainer()
		{
		  hideDiv('globalContainer');
		}

// ------------------------------------------------------
//    calls to server here
// ------------------------------------------------------
		function getSessionInfo()
		{
			xajax_getSessionInfo();   
			return false;
		}
		function setUserVideoInfo($item_id,$currTitleName,$currTitleLength,$currTitleShortDesc,$currTitleTags)
		{ // "'"
			xajax_setUserVideoInfo(''+$item_id+'',''+$currTitleName+'',''+$currTitleLength+'',''+$currTitleShortDesc+'',''+$currTitleTags+'');  
			return false;
		}
		function submitRating($item_id,$val,$targetDiv)
		{
			xajax_setRating($item_id,$val,$targetDiv);
			return false;
		}
		function showRating($item_id,$targetDiv)
		{
			xajax_getRating($item_id,$targetDiv);  // e.g. ;nameA1056 
			return false;
		}
		function getViewed($item_id,$targetDiv)
		{
			xajax_getViewed($item_id,$targetDiv);   
			return false;
		}
		function incrementViewed($item_id,$targetDiv)
		{
			xajax_incrementViewed($item_id,$targetDiv);  
			return false;
		}
		function showComments($item_id,$preCommentDiv,$commentDiv,$comm_page)
		{
			xajax_getComments($item_id,$preCommentDiv,$commentDiv,$comm_page);  // e.g. lnameA1056 
			return false;
		}
		function showCommentsCount($item_id,$commentsCount)
		{
			xajax_getCommentsCount($item_id,$commentsCount);   
			return false;
		}
		function showSentCount($item_id,$target)
		{
			xajax_getSentCount($item_id,$target);   
			return false;
		}
		
		function submitComment()
		{
			xajax.$('commentButton').disabled=true;
			xajax.$('commentButton').value="please wait...";
			xajax_processCommentForm(xajax.getFormValues("commentForm"));
			return false;
		}
		function submitMemberComment()
		{
			xajax.$('memberCommentButton').disabled=true;
			xajax.$('memberCommentButton').value="please wait...";
			xajax_processCommentForm(xajax.getFormValues("memberCommentForm"));
			return false;
		}
		function reportComment($comment_id)
		{
			xajax_reportComment($comment_id);
			return false;
		}
		function showMessages($item_id,$messageDiv,$msg_page)
		{
			xajax_getMessages($item_id,$messageDiv,$msg_page);  // e.g. PL*xXXXA1056 
			return false;
		}
		function submitGroupMessage()
		{
			xajax.$('groupMessageButton').disabled=true;
			xajax.$('groupMessageButton').value="please wait...";
			xajax_processMessageForm(xajax.getFormValues("groupMessageForm"));
			return false;
		}
		function deleteMessage($message_id)
		{
			xajax_deleteMessage($message_id);
			return false;
		}

		function showSignup($containerDiv,$msgDiv)
		{
			xajax_showSignupForm($containerDiv,$msgDiv);
			return false;
		}
		function submitSignup()
		{
			xajax.$('signupButton').disabled=true;
			xajax.$('signupButton').value="please wait...";
			xajax_processSignupForm(xajax.getFormValues("signupForm"));
			
			return false;
		}
		function showLogin($containerDiv,$msgDiv)
		{
			xajax_showLoginForm($containerDiv,$msgDiv);
			return false;
		}
		function sendUserInfo()    // forgot userid or password
		{
			xajax.$('sendInfoButton').disabled=true;
			xajax.$('sendInfoButton').value="please wait...";
			xajax_sendUserInfo(xajax.getFormValues("forgotInfoForm"));

		    return false;
		}
		function submitLogin()
		{
			xajax.$('loginButton').disabled=true;
			xajax.$('loginButton').value="please wait...";
			xajax_processLoginForm(xajax.getFormValues("loginForm"));

		    return false;
		}
		function submitLoginFromHeader()
		{
			xajax.$('loginButton2').disabled=true;
			xajax.$('loginButton2').value="please wait...";
			xajax_processLoginForm(xajax.getFormValues("hdrLoginForm"));

		    return false;
		}

		function doLogout()
		{
		var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
			xajax_doLogout(sPage);
			return false;
		}
		function submitChgPswd()
		{
			xajax.$('chgpswdButton').disabled=true;
			xajax.$('chgpswdButton').value="please wait...";
			xajax_processchgpswdForm(xajax.getFormValues("chgpswdForm"));

		    return false;
		}
		function submitDropout()
		{
			xajax.$('dropoutButton').disabled=true;
			xajax.$('dropoutButton').value="please wait...";
			xajax_processdropoutForm(xajax.getFormValues("dropoutForm"));

		    return false;
		}
		function showPlaylistForm($item_id,$shortTitle,$targetDiv)
		{
//alert("item="+$item_id+", shortTitle="+$shortTitle+", target="+$targetDiv);
		    
			xajax_showPlaylistForm($item_id,$shortTitle,$targetDiv);

		    return false;
		}
		function processPlaylistForm()
		{
			xajax.$('addButton').disabled=true;
			xajax.$('addButton').value="please wait...";
			xajax_processPlaylistForm(xajax.getFormValues("playlistForm"));

		    return false;
		}

		function getPlaylistsForUser($targetDiv,$user)
		{
			xajax_getPlaylistsForUser($targetDiv,$user);

		    return false;
		}
		function showPLNameChangeForm($id,$plname,$targetDiv,$msgDiv)
{
			xajax_showPLNameChangeForm($id,$plname,$targetDiv,$msgDiv);

		    return false;
}
		function processPLNameChangeForm()
{
			xajax.$('chgButton').disabled=true;
			xajax.$('chgButton').value="please wait...";
			xajax_processPLNameChangeForm(xajax.getFormValues("PLNameChangeForm"));

		    return false;
}
		function setPLPrivacy($plid,$private,$targetDiv,$msgDiv)
{
			xajax_setPLPrivacy($plid,$private,$targetDiv,$msgDiv);
}		

		function showPLSharingForm($plid,$targetDiv)
{
			xajax_showPLSharingForm($plid,$targetDiv);
		    return false;
}
		function processPLSharingForm()
{
			xajax.$('saveButton').disabled=true;
			xajax.$('saveButton').value="please wait...";
			xajax_processPLSharingForm(xajax.getFormValues("PLSharingForm"));
		    return false;
}

		function deletePlaylist($id,$plname,$targetDiv)
{
			xajax_deletePlaylist($id,$plname,$targetDiv);
}		

		function deleteFromPlaylist($plid,$item_id,$targetDiv)
{
			xajax_deleteFromPlaylist($plid,$item_id,$targetDiv);
}		
		
		function submitShare()
		{
			xajax.$('shareButton').disabled=true;
			xajax.$('shareButton').value="please wait...";
			xajax_processShareForm(xajax.getFormValues("shareForm"));
			return false;
		}
		
		function showPagedVideoList($channel, $vidtype, $numPerPage, $target, $topLink, $bottomLink, $pageno)
		{
                        xajax_showPagedVideoList($channel, $vidtype, $numPerPage, $target, $topLink, $bottomLink, $pageno);
		}
