/******************************************************************************
 *
 * Copyright (c) Enigma Interactive 2003
 * 7-15 pink lane / newcastle / ne1 5dw / england
 * t: +44 (0)191 261 2991 www.enigma-interactive.co.uk f: +44 (0)191 261 2378
 *
 * Filename: 	current_project.js
 * Description:	A set of utility javascript functions
 *
 *
 * History
 * ver	date		who			comment
 * ----------------------------------------------------------------------------
 * 1 	27-Apr-2004	Chris Gair	Created
 *****************************************************************************/
 
 /*******************************************************************************
 * Description:	Gets the selected project id in the list and then changes the 
 *				forms action to load the project, then submits the form
 * Parameters:	none
 *
 * History
 * ver	date		who					comment
 *------------------------------------------------------------------------------
 * 1	27-Apr-2004	Chris Gair			Created
 ******************************************************************************/
function load_project()
{
	projid = document.project.project_list.value;
	document.project.action = "current_project.cfm?projid=" + projid;
	document.project.load.value = "1";
	document.project.submit();
}

 /*******************************************************************************
 * Description:	Gets the selected project id in the list and then changes the 
 *				forms action to sort the project, then submits the form
 * Parameters:	none
 *
 * History
 * ver	date		who					comment
 *------------------------------------------------------------------------------
 * 1	27-Apr-2004	Chris Gair			Created
 ******************************************************************************/	
function order_list(ordering, isGuest)
{	
	projid = document.project.project_list.value;
	if(isGuest)
		window.location.href = "current_project.cfm?sort=" + ordering;
	else
		window.location.href = "current_project.cfm?projid=" + projid + "&sort=" + ordering;
}

 /*******************************************************************************
 * Description:	Saves the current project
 *				
 * Parameters:	none
 *
 * History
 * ver	date		who					comment
 *------------------------------------------------------------------------------
 * 1	30-Apr-2004	Chris Gair			Created
 ******************************************************************************/	
function save_project()
{	
	projid = document.project.project_list.value;
	sortorder = document.project.sort_list.value;
	document.project.save.value = "1";
	document.project.action = "current_project.cfm?projid=" + projid + "&sort=" + sortorder;
	document.project.submit();
}

/*******************************************************************************
 * Description:	
 * Parameters:	none
 *
 * History
 * ver	date		who					comment
 *------------------------------------------------------------------------------
 * 1	16-Jun-2004	Chris Gair			Created
 ******************************************************************************/
function gotoProject()
{
	var projectid;
	projectid = document.goto_project.project_list.value;
	document.goto_project.action = "current_project.cfm?projid=" + projectid;
	document.goto_project.submit();
}

function handleVersion(p_objectId,trackId)
{
	var objElement;
	
	objElement = document.getElementById(p_objectId);

	strCurrentClass = objElement.className;
	
	if (strCurrentClass.indexOf("hidden") != -1 ) 
	{
		//remove
		document.checkVersion.command.value = 'remove';
	}
	else if ( strCurrentClass.indexOf("visible") != -1 ) 
	{
		//add
		document.checkVersion.command.value = 'add';
	}
		document.checkVersion.id.value = trackId;
	
	objFormField = xGetElementById( "open_" +  trackId);
	if( objFormField ) {
		objFormField.value = "" + trackId;
	}

	document.checkVersion.submit();
}

/*******************************************************************************
 * Description:	Submits a passed form
 * Parameters: formName - the name of the form you wish to submit
 *									
 *
 * History
 * ver	date		who					comment
 *------------------------------------------------------------------------------
 * 1.0	07-Dec-2004	Sam Jenkins			Created
 ******************************************************************************/
 function submitForm(p_formName)
 {
	eval("document." + p_formName + ".submit()");
 }
 
 /**
  * called when the user clicks the "Download All" button
  */
function downloadAll( p_intProjectId, p_strSessionId ) {
	
	strOpenTracks = "";
	objOpenTracks = document.project.opentracks;
	
	// create a comma seperated list of all the tracks that are
	// currently displying their alternate verions
	for( i=0 ; i<objOpenTracks.length ; i++ ) {
	
		if( objOpenTracks[i].value != "" ) {
			
			if( strOpenTracks == "" ) {
				strOpenTracks = objOpenTracks[i].value;
			}
			else {
				strOpenTracks = strOpenTracks + "," + objOpenTracks[i].value;
			}
		}
	}
	
	location.href = "/pages/download/copyright.cfm?sid="+p_strSessionId+"&projectId="+p_intProjectId+"&opentracks="+strOpenTracks;
	
} // end of function downloadAll




function setProjectTitle(title, shortTitle)

{
	xInnerHtml('pb_title', unescape(title));
	xInnerHtml('tabbar_current_project', unescape(shortTitle));
}

function url_folder(id)
{
	document.location.href="/pages/my_play/project_list.cfm?folderaction=select&foldertype=project&folderid=" + id;
}
