function showAddToWorkout(exerciseId, userId)
{	
	var opt = {
	    // Use POST
	    method: 'get',
	    // Handle successful response
	    onSuccess: function(t) {	        
	        var responseText = t.responseText;
	        
	        var select = document.getElementById("workoutExerciseSelect_" + exerciseId);	        
	        select.options.length = 0;
	        select.options[0] = new Option('Create a New Workout','');       
	        
	        if(responseText.length > 0){
	        	
		        responseText = responseText.split(";");		      	
		      
		        for(var i = 0; i < responseText.length; i++){		        
		        	var workoutText = responseText[i].split(",");        			        
		        	select.options[i + 1] = new Option(workoutText[1],workoutText[0]);
		        }			        	
	        }else{
	        	
	        }
	        
	        
	        Effect.SlideDown('workoutExerciseBox_' + exerciseId);
	       
	    },
	    // Handle 404
	    on404: function(t) {
	        alert('Error 404: location "' + t.statusText + '" was not found.');
	    },
	    // Handle other errors
	    onFailure: function(t) {
	        alert('Error ' + t.status + ' -- ' + t.statusText);
	    }
	}
	new Ajax.Request('/lib/services/getValidWorkouts.php?exerciseId=' + exerciseId + '&userId=' + userId, opt);	
}

function getFileLengthWidth(fileName)
{
	var opt = {
	    // Use POST
	    method: 'get',
	    // Handle successful response
	    onSuccess: function(t) {			    	
				var lengthWidth = t.responseText;				
				var videoLength, videoWidth;
				var length = 500;
				var width = 500;
				
				lengthWidth = lengthWidth.split(",");						      	
				videoLength = lengthWidth[0];
				videoWidth = lengthWidth[1];
				
				if(videoLength > length){
					length = videoLength;
				}
					
				if(videoWidth > width){
					width = videoWidth;
				}				
				
				var newWindow = window.open("/ViewVideo/" + escape(fileName) + "/",null, "height=" + length + ",width=" + width + ",status=yes,toolbar=no,menubar=no,location=no");				
	    },
	    // Handle 404
	    on404: function(t) {
	      
	    },
	    // Handle other errors
	    onFailure: function(t) {
	       
	    }
	}	
	new Ajax.Request('/lib/services/getFileInfo.php?file=' + escape(fileName), opt);	
}

function submitAddToWorkout(exerciseId)
{
	var selectBox = document.getElementById("workoutExerciseSelect_" + exerciseId);	
	var statusBar = document.getElementById("statusbar_" + exerciseId);
	var statusBarImage = document.getElementById("statusbarimage_" + exerciseId);
	var statusText = document.getElementById("statustext_" + exerciseId);
	
	
	if(selectBox.value == ""){
		window.location = "/MyWorkouts/Add/?exerciseId=" + escape(exerciseId);
	}
	
	statusBar.style.display = "block";
	
var opt = {
	    // Use POST
	    method: 'get',
	    // Handle successful response
	    onSuccess: function(t) {	        	       				
  			statusBarImage.style.display = "none";             
  			statusText.innerHTML = "Added Exercise to Workout!";
	      Effect.Highlight('workoutExerciseBox_' + exerciseId);
	       
	    },
	    // Handle 404
	    on404: function(t) {
	        alert('Error 404: location "' + t.statusText + '" was not found.');
	    },
	    // Handle other errors
	    onFailure: function(t) {
	        alert('Error ' + t.status + ' -- ' + t.statusText);
	    }
	}
	
	new Ajax.Request('/lib/services/saveWorkoutExercise.php?exerciseId=' + exerciseId + '&workoutId=' + selectBox.value, opt);		
}

function openVideoPage(fileName)
{		
	getFileLengthWidth(fileName);
}

function selectNixxieSearchInput()
{
	var searchInput = $("searchTextNixxie");
	if(searchInput.value == "Search"){
		searchInput.value = "";
	}else{
		searchInput.select();
	}
}
