// Begin Main Talkingheadshot.com Session Javascript

if (document.layers) {navigator.family = "nn4"}
if (document.all) {navigator.family = "ie4"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {navigator.family = "gecko"}
	// Detect Browser

iframeHasNotLoaded = new Array();

function runCommand( cmnd )
{
   document.main_form.command.value = cmnd;
   document.main_form.submit();
}

function runCommandWithBlankMenu( cmnd )
{
   document.main_form.command.value = cmnd;
   if( document.main_form.doBlankMenu )
   {
      document.main_form.doBlankMenu.value = 1;
   }
   document.main_form.submit();
}

function resetCmnd()
{
	if( document.main_form.doBlankMenu )
	{
		document.main_form.doBlankMenu.value = 0;
	}
   document.main_form.command.value = '';
}

function signup( type )
{
	document.main_form.sUserType.value = type;
	document.main_form.sm_su.value = 1;
	document.main_form.command.value = 'su_vs';
	document.main_form.submit();
}

function paymentOrder( type )
{
	document.main_form.sUserType.value = type;
	document.main_form.command.value = 'sm_su,su_po';
	document.main_form.submit();
}

function openProjectNode( nodeIndex, nodeType )
{  // Open a new project node.

	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.command.value = 'p_vpn';
	
	if( nodeType == 8 )
	{	// Open media files with blank menu.

		if( document.main_form.doBlankMenu )
		{
			document.main_form.doBlankMenu.value = 1;
		}
	}
	document.main_form.submit();
}

function getBaseXMLURL()
{
	var fieldList = new Array( 'language', 'lUserIndex', 'lUserType', 'userIndex', 'userType', 'key', 'p_pnKey', 'lastDescendantHours' );
	var val;
	var valTypeof;
	var url = getSiteLocation();
	url += '?contentType=text/xml&dummyVar=' + Math.random();

	for( var i = 0; i < fieldList.length; i++ )
	{
	    url += '&' + getInputFieldURLString( fieldList[i] );
	}
	return( url );
}

function getInputFieldURLString( fieldName )
{
    var str = '';
	var val;
	var valTypeof;
   	eval( 'valTypeof = typeof document.main_form.' + fieldName + ';' );
		
	if( valTypeof != 'undefined' )
	{
		str += fieldName + '=';

		eval( 'val = document.main_form.' + fieldName + '.value;' );

		if( typeof val == 'undefined' )
		{
			val = 0;
		}
		str += val;
	}
	return( str );
}

function reserveNode( nodeType, filename, callbackFunc, callbackParam )
{   // Ask the server to create an invisible node in reserve.

	http_request = getXMLHttpRequest();

	if( http_request )
	{
		var url = getBaseXMLURL();

		url += '&command=p_crn&createNodeType=' + nodeType + '&p_filename=' + filename;
        url += '&' + getInputFieldURLString( 'pnIndex' );
        url += '&' + getInputFieldURLString( 'pnType' );

		http_request.onreadystatechange = function() { updateProjectNodeStatus( http_request, callbackFunc, callbackParam ); };

		http_request.open( 'GET', url, true );
		http_request.send( null );
	}
}

function getProjectNodeStatus( nodeIndex, nodeType, callbackFunc, callbackParam )
{
	http_request = getXMLHttpRequest();

	if( http_request )
	{
		var url = getBaseXMLURL();

		url += '&skipInitProject=1&command=p_gns&pnIndex=' + nodeIndex + '&pnType=' + nodeType;

		http_request.onreadystatechange = function() { updateProjectNodeStatus( http_request, callbackFunc, callbackParam ); };

		http_request.open( 'GET', url, true );
		http_request.send( null );
	}
}

function updateProjectNodeStatus( http_request, callbackFunc, callbackParam )
{
	var rootNode = false;
	var error = new Object();
	var projectNodeInfo = new Object();
	var updateString = '';

	error.errorCode = -1;
	error.name = '';
	error.description = '';
	projectNodeInfo.nodeIndex = 0;
	projectNodeInfo.nodeType = 0;

	if( http_request.readyState==4 || http_request.readyState=="complete" )
	{
		if( http_request.responseXML != null )
		{
			rootNode = http_request.responseXML.documentElement;
// alert( http_request.responseText );

			if( rootNode != null )
			{
				errorNode = rootNode.getElementsByTagName( 'error' )[0];

				if( errorNode != null )
				{  // Check for errors.

					error.errorCode = xml_getNodeValue( errorNode, 'errorCode' );
					error.name = xml_getNodeText( errorNode, 'name' );
					error.description = xml_getNodeText( errorNode, 'description' );

					if( error.errorCode == 0 )
					{
						projectNode = rootNode.getElementsByTagName( 'projectNode' )[0];

						if( projectNode != null )
						{  // Check for node info

							projectNodeInfo.nodeIndex = xml_getNodeValue( projectNode, 'nodeIndex' );
							projectNodeInfo.nodeType = xml_getNodeValue( projectNode, 'nodeType' );
							projectNodeInfo.status = xml_getNodeValue( projectNode, 'status' );
							projectNodeInfo.schemaType = xml_getNodeValue( projectNode, 'schemaType' );
							projectNodeInfo.projectOwnerIndex = xml_getNodeValue( projectNode, 'projectOwnerIndex' );
							projectNodeInfo.nodeOwnerIndex = xml_getNodeValue( projectNode, 'nodeOwnerIndex' );
							projectNodeInfo.parentIndex = xml_getNodeValue( projectNode, 'parentIndex' );
							projectNodeInfo.lastModification = xml_getNodeValue( projectNode, 'lastModification' );
							projectNodeInfo.lastDescendant = xml_getNodeValue( projectNode,'lastDescendant' );
							projectNodeInfo.creationDate = xml_getNodeValue( projectNode, 'creationDate' );
						}
					}
				}
			}
			callbackFunc( projectNodeInfo, error, callbackParam );
		}
	}
}

function openProjectNodeSubMenu( nodeIndex, nodeType, depth )
{  // Open a new project node.

	http_request = getXMLHttpRequest();
	menuOpenIcon = '../graphics/Folder_small_open.gif';
	menuClosedIcon = '../graphics/Folder_small_closed.gif';

	if( http_request )
	{
		if( typeof nodeSubMenuOpenMapping == 'undefined' )
		{
			nodeSubMenuOpenMapping = new Array();
		}

		if( isVisible( 'subMenu_' + nodeIndex ) )
		{
			nodeSubMenuOpenMapping[nodeIndex] = false;

			changeVisibility( 'subMenu_' + nodeIndex, false );
			changeImage( 'nodeIcon_' + nodeIndex, menuClosedIcon );
		}
		else
		{
			if( typeof nodeSubMenuOpenMapping[nodeIndex] == 'undefined' )
			{
				var url = getBaseXMLURL();

				reWriteDiv( 'subMenu_' + nodeIndex, 'subMenu_' + nodeIndex + '_frame', '...', false );
				changeCursor( 'nodeLink_' + nodeIndex, 'wait' );
				changeCursor( 'projectMenuDownTable', 'wait' );

				url += '&command=p_xnsm&depth=' + depth + '&pnIndex=' + nodeIndex + '&pnType=' + nodeType;

				http_request.onreadystatechange = function() { updateProjectNodeSubMenu(http_request); };

				http_request.open( 'GET', url, true );
				http_request.send( null );
			}
			else
			{
				nodeSubMenuOpenMapping[nodeIndex] = true;

				changeVisibility( 'subMenu_' + nodeIndex, true );
				changeImage( 'nodeIcon_' + nodeIndex, menuOpenIcon );
			}
		}
	}
	else
	{
		document.main_form.pnIndex.value = nodeIndex;
		document.main_form.pnType.value = nodeType;
		document.main_form.command.value = 'p_vpn';

		if( nodeType == 8 )
		{	// Open media files with blank menu.

			if( document.main_form.doBlankMenu )
			{
				document.main_form.doBlankMenu.value = 1;
			}
		}
		document.main_form.submit();
	}
}

function updateProjectNodeSubMenu( http_request )
{
	var rootNode = false;
	var error = new Object();
	var updateString = '';
    
	error.name = '';
	error.description = '';

	nodeIndex = 0;
	nodeType = 0;

	if( http_request.readyState==4 || http_request.readyState=="complete" )
	{
		if( http_request.responseXML != null )
		{
			rootNode = http_request.responseXML.documentElement;
//alert( http_request.responseText );
//reWriteDiv( 'nodeInfo_description', 'nodeInfo_description_frame', http_request.responseText );
			if( rootNode != null )
			{
				projectNode = rootNode.getElementsByTagName( 'projectNode' )[0];

				if( projectNode != null )
				{  // Check for node info

					if( projectNode.getElementsByTagName( 'nodeIndex' )[0].firstChild != null )
					{
						nodeIndex = projectNode.getElementsByTagName( 'nodeIndex' )[0].firstChild.nodeValue;
					}
					if( projectNode.getElementsByTagName( 'nodeType' )[0].firstChild != null )
					{
						nodeType = projectNode.getElementsByTagName( 'nodeType' )[0].firstChild.nodeValue;
					}
				}

				var status = rootNode.getElementsByTagName( 'status' )[0].firstChild.nodeValue;

				divName = 'subMenu_' + nodeIndex;

				if( status != 0 )
				{
					errorNode = rootNode.getElementsByTagName( 'error' )[0];

					if( errorNode != null )
					{  // Check for errors.

						errorNode.name = xml_getNodeText( errorNode, 'name' );
						errorNode.description = xml_getNodeText( errorNode, 'description' );
					}
					reWriteDiv( divName, divName + '_frame', error.name + '<br></br>\n' + error.description, false );
				}
				else
				{
					var nextNode = rootNode.getElementsByTagName( 'subMenu' )[0].firstChild;
					var subMenuText = xml_getNodeText( rootNode, 'subMenu' );

					changeImage( 'nodeIcon_' + nodeIndex, menuOpenIcon );

					reWriteDiv( divName, divName + '_frame', subMenuText, false );
					nodeSubMenuOpenMapping[nodeIndex] = true;

//alert( http_request.responseText );
//reWriteDiv( 'nodeInfo_description', 'nodeInfo_description_frame', http_request.responseText );
				}
				changeCursor( 'nodeLink_' + nodeIndex, 'pointer' );
				changeCursor( 'projectMenuDownTable', 'default' );
				changeVisibility( divName, true );
			}
		}
	}
}

function openProjectNodeRecent( nodeIndex, nodeType, lastDescendantHours )
{  // Open a new project node with recently posted children only.

	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.command.value = 'p_vpn';

	if( document.main_form.lastDescendantHours )
	{
		document.main_form.lastDescendantHours.value = lastDescendantHours;
	}
	document.main_form.submit();
}

function changeNodeState( nodeIndex, nodeType, newState )
{	// Changes the state of the given project node.

	document.main_form.createNodeType.value = newState;
	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.command.value = 'p_cps';
	document.main_form.submit();
}

function analyzeNode( nodeIndex, nodeType, analysisType )
{	// Analyzes the given project node.

	document.main_form.createNodeType.value = analysisType;
	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.command.value = 'p_apr';
	document.main_form.submit();
}

function createNode( nodeIndex, nodeType, createType )
{  // Create a child node of the given node.

	document.main_form.createNodeType.value = createType;
	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.command.value = 'p_vcpn';
	document.main_form.submit();
}

function deleteNode( nodeIndex, nodeType )
{  // Delete the given node.

	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.command.value = 'p_vdpn';
	document.main_form.submit();
}

function editNode( nodeIndex, nodeType )
{  // Edit the given node.

	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.command.value = 'p_vepn';
	document.main_form.submit();
}

function copyNode( nodeIndex, nodeType )
{  // Copy the given node.

	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.transferType.value = 'copy';
	document.main_form.command.value = 'p_vtrn';
	document.main_form.submit();
}

function moveNode( nodeIndex, nodeType )
{  // Move the given node.

	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.transferType.value = 'move';
	document.main_form.command.value = 'p_vtrn';
	document.main_form.submit();
}

function submitNode( nodeIndex, nodeType )
{  // Submit the given node.

	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.command.value = 'p_vspu';
	document.main_form.submit();
}

function retractNode( nodeIndex, nodeType, suIndex )
{  // Retract the given project from the given user.

	document.main_form.suInx.value = suIndex;
	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.command.value = 'p_vrpu';
	document.main_form.submit();
}

function commandNode( nodeIndex, nodeType, cmnd )
{	// Runs the given command on the given node.

	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.command.value = cmnd;
	document.main_form.submit();
}

function importNode( nodeIndex, nodeType )
{  // Import users into the given node.

	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.transferType.value = 'import';
	document.main_form.command.value = 'p_vtrn';
	document.main_form.submit();
}

function exportNode( nodeIndex, nodeType )
{  // Export users from the given node.

	document.main_form.pnIndex.value = nodeIndex;
	document.main_form.pnType.value = nodeType;
	document.main_form.holdSelected.value = 0;
	document.main_form.transferType.value = 'export';
	document.main_form.command.value = 'p_vtrn';
	document.main_form.submit();
}

function exportSelectedUsers()
{  // Export selected users from this node.

	document.main_form.transferType.value = 'export';
	document.main_form.holdSelected.value = 1;
	document.main_form.command.value = 'p_vtrn';
	document.main_form.submit();
}

function listProjects( listMethod, schemaType )
{
	document.main_form.listMethod.value = listMethod;
	document.main_form.listSchema.value = schemaType;

	document.main_form.command.value = 'p_vpl';
	document.main_form.submit();
}

function emailUser( inx, type, prefix )
{  // Emails the given user.

	document.main_form.command.value = 'p_venu';
	document.main_form.suInx.value = inx;
	document.main_form.suType.value = type;
	document.main_form.submit();
}

function openResume( inx, type, prefix )
{
	document.main_form.command.value = prefix + 'vr';
	document.main_form.resumeIndex.value = inx;
	document.main_form.submit();
}

function openCIS( inx, type, prefix )
{
	document.main_form.command.value = prefix + 'vcs';
	document.main_form.resumeIndex.value = inx;
	document.main_form.submit();
}

function openDemo( inx, type, prefix )
{
	document.main_form.command.value = prefix + 'vdm';
	document.main_form.resumeIndex.value = inx;
	document.main_form.submit();
}

function openPortfolio( inx, type, prefix )
{
	document.main_form.command.value = prefix + 'veph';
	document.main_form.resumeIndex.value = inx;
	if( document.main_form.doBlankMenu )
	{
		document.main_form.doBlankMenu.value = 1;
	}
	document.main_form.submit();
}

function openUser( inx, type, prefix )
{
	var oldUInx = document.main_form.userIndex.value;
	var oldUType = document.main_form.userType.value;

	document.main_form.command.value = 'sm_uhm';
	document.main_form.userIndex.value = inx;
	document.main_form.userType.value = type;
	document.main_form.target = '_newTHSWindow';
	document.main_form.submit();
	document.main_form.target = '';
	document.main_form.userIndex.value = oldUInx;
	document.main_form.userType.value = oldUType;
}

function manageUser( inx, type, prefix )
{
	document.main_form.command.value = 'sm_vmul,ac_vlu';
	document.main_form.resumeIndex.value = inx;
	document.main_form.submit();
}

