/* ------------------------------------------------------------------------------------------ */
/* Pre-load Key images */

img1 = new Image(694,20);
img1.src = "../../bundlebuilder/img/keys/stage1.gif";
img2 = new Image(694,20);
img2.src = "../../bundlebuilder/img/keys/stage2.gif";
img3 = new Image(694,20);
img3.src = "../../bundlebuilder/img/keys/stage3.gif";
img4 = new Image(694,20);
img4.src = "../../bundlebuilder/img/keys/stage4.gif";
img5 = new Image(694,20);
img5.src = "../../bundlebuilder/img/keys/stage5.gif";
img6 = new Image(694,20);
img6.src = "../../bundlebuilder/img/keys/stage6.gif";
img7 = new Image(694,20);
img7.src = "../../bundlebuilder/img/keys/stage7.gif";
img8 = new Image(694,20);
img8.src = "../../bundlebuilder/img/keys/stage8.gif";
img9 = new Image(694,20);
img9.src = "../../bundlebuilder/img/keys/stage9.gif";

/* ------------------------------------------------------------------------------------------ */
/* Function to load the Bundle Builder apps via AJAX */
function loadBBApps(app) {

	var attr = 'selected_app=' + app;
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Hide moreinfo box if it's showing
	hideTutInfo('all');
	
	// Show loading icon
	document.getElementById('loading_dial').style.display='inline';
	
	// Check for Active X
	try { 
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); // Try the first kind of active x object 
   	} catch (e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); // Try the second kind of active x object
        } catch (E) {
			xmlhttp = false;
       	}
	}
    
    // If we were able to get a working active x object, start an XMLHttpRequest
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); }
        
	var file = '/bundlebuilder/ajax/load_applications.php?'; 
	
	// Get the file
	xmlhttp.open('GET', file + attr, true);
	xmlhttp.onreadystatechange=function() {
        
		if (xmlhttp.readyState==4) { 			// Check if it is ready to recieve data
			var content = xmlhttp.responseText; // The content data which has been retrieved
			
			if (content) { 					//Make sure there is something in the content variable
			
				// Insert content into DIV
				document.getElementById('application_list').innerHTML = content;
				
				// Show loading icon
				document.getElementById('loading_dial').style.display='none';
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}

/* ------------------------------------------------------------------------------------------ */
/* Function to load the Bundle Builder Tutorials per selected app via AJAX */
function loadBBTutorials(app) {

	//alert(app);

	var attr = 'selected_app=' + app;
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Hide moreinfo box if it's showing
	hideTutInfo('all');
	
	// Show loading icon
	document.getElementById('loading_dial').style.display='inline';
	
	// Check for Active X
	try { 
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); // Try the first kind of active x object 
   	} catch (e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); // Try the second kind of active x object
        } catch (E) {
			xmlhttp = false;
       	}
	}
    
    // If we were able to get a working active x object, start an XMLHttpRequest
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); }
        
	var file = '/bundlebuilder/ajax/load_tutorials.php?'; 
	
	// Get the file
	xmlhttp.open('GET', file + attr, true);
	xmlhttp.onreadystatechange=function() {
        
		if (xmlhttp.readyState==4) { 			// Check if it is ready to recieve data
			var content = xmlhttp.responseText; // The content data which has been retrieved
			
			if (content) { 					//Make sure there is something in the content variable
			
				document.getElementById('tutorial_list').innerHTML = content;
				
				// Refresh app list
				loadBBApps(app);
				
				//alert(content);
				
				// Show loading icon
				document.getElementById('loading_dial').style.display='none';
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}

/* ------------------------------------------------------------------------------------------ */
/* Function to add/remove tutorials from the bb array via AJAX */
function bundleTotals() {

	var attr = ''; 
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Show loading icon
	document.getElementById('loading_dial').style.display='inline';
	
	// Check for Active X
	try { 
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); // Try the first kind of active x object 
   	} catch (e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); // Try the second kind of active x object
        } catch (E) {
			xmlhttp = false;
       	}
	}
    
    // If we were able to get a working active x object, start an XMLHttpRequest
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); }
        
	var file = '/bundlebuilder/ajax/bundle_total.php?'; 
	
	// Get the file
	xmlhttp.open('GET', file + attr, true);
	xmlhttp.onreadystatechange=function() {
        
		if (xmlhttp.readyState==4) { 			// Check if it is ready to recieve data
			var content = xmlhttp.responseText; // The content data which has been retrieved
			
			if (content) { 					//Make sure there is something in the content variable
			
				document.getElementById('bundle_total').innerHTML = content;
				
				// Show loading icon
				document.getElementById('loading_dial').style.display='none';
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}


/* ------------------------------------------------------------------------------------------ */
/* Function to add/remove tutorials from the bb array via AJAX */
function bundleDisplay() {

	var attr = ''; 
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Hide moreinfo box if it's showing
	hideTutInfo('all');
	
	// Show loading icon
	document.getElementById('loading_dial').style.display='inline';
	
	// Check for Active X
	try { 
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); // Try the first kind of active x object 
   	} catch (e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); // Try the second kind of active x object
        } catch (E) {
			xmlhttp = false;
       	}
	}
    
    // If we were able to get a working active x object, start an XMLHttpRequest
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); }
        
	var file = '/bundlebuilder/ajax/bundle_display.php?'; 
	
	// Get the file
	xmlhttp.open('GET', file + attr, true);
	xmlhttp.onreadystatechange=function() {
        
		if (xmlhttp.readyState==4) { 			// Check if it is ready to recieve data
			var content = xmlhttp.responseText; // The content data which has been retrieved
			
			if (content) { 					//Make sure there is something in the content variable
			
				document.getElementById('bundle_display').innerHTML = content;
				
				// Show loading icon
				document.getElementById('loading_dial').style.display='none';
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}


/* ------------------------------------------------------------------------------------------ */
/* Function to add/remove tutorials from the bb array via AJAX */
function bundleControl(action, id, type, app) {

	var attr = 'action=' + action + '&type=' + type + '&id=' + id; 
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Show loading icon
	document.getElementById('loading_dial').style.display='inline';
	
	// Check for Active X
	try { 
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); // Try the first kind of active x object 
   	} catch (e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); // Try the second kind of active x object
        } catch (E) {
			xmlhttp = false;
       	}
	}
    
    // If we were able to get a working active x object, start an XMLHttpRequest
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); }
        
	var file = '/bundlebuilder/ajax/bundle_control.php?'; 
	
	// Get the file
	xmlhttp.open('GET', file + attr, true);
	xmlhttp.onreadystatechange=function() {
        
		if (xmlhttp.readyState==4) { 			// Check if it is ready to recieve data
			var content = xmlhttp.responseText; // The content data which has been retrieved
			
			if (content) { 					//Make sure there is something in the content variable
			
				// Refresh Total
				bundleTotals();
				
				// Refresh bundle
				bundleDisplay();
				
				// Refresh tutorial display
				loadBBTutorials(app);
				
				// Show loading icon
				document.getElementById('loading_dial').style.display='none';
				
				// Hide moreinfo box if it's showing
				hideTutInfo('all');

				//alert(content);
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}

/* ------------------------------------------------------------------------------------------ */
/* Remove Tutorial */
function removeTutorial(id) {
	
	var removeTut = confirm("Remove this Tutorial-Video?")
	
	if (removeTut){
		
		
		// Remove the tutorial
		bundleControl('remove',id);
		
		// Hide moreinfo box if it's showing
		hideTutInfo('all');
	
		// Refresh the list
		bundleDisplay();
		
	}
}
	
// Call checkCords function after a 100 milliseconds
//var t = setTimeout(checkCords(PrevMouseX,PrevMouseY),5000);

/* ------------------------------------------------------------------------------------------ */
/* Function to toggle display of tutorial blurb */
function toggleBBBlurb(id, type, action, num) {

	switch (action) {
		case "show":
			showTutInfo(id, type, num);
			break;
		
		case "hide":
			hideTutInfo(num);
			break;
	}
	
}

/* ------------------------------------------------------------------------------------------ */
/* Function to add/remove tutorials from the bb array via AJAX */
function showTutInfo(id, type, num) {

	var attr = 'id=' + id + '&type=' + type; 
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Clear previous info
	document.getElementById('tut_info_' + num).innerHTML='';
	
	// Show loading icon
	//document.getElementById('loading_dial').style.display='inline';
	
	// Check for Active X
	try { 
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); // Try the first kind of active x object 
   	} catch (e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); // Try the second kind of active x object
        } catch (E) {
			xmlhttp = false;
       	}
	}
    
    // If we were able to get a working active x object, start an XMLHttpRequest
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); }
        
	var file = '/bundlebuilder/ajax/load_tutorial_info.php?'; 
	
	// Get the file
	xmlhttp.open('GET', file + attr, true);
	xmlhttp.onreadystatechange=function() {
        
		if (xmlhttp.readyState==4) { 			// Check if it is ready to recieve data
			var content = xmlhttp.responseText; // The content data which has been retrieved
			
			if (content) { 					//Make sure there is something in the content variable
			
				// Load tutorial info
				document.getElementById('tut_info_' + num).innerHTML = content;
				
				switch (num) {
					case "1":
						if (document.getElementById('tut_info_display_2').style.display=='block') {
							document.getElementById('tut_info_display_2').style.display='none';
						}
						break;
					case "2":
						if (document.getElementById('tut_info_display_1').style.display=='block') {
							document.getElementById('tut_info_display_1').style.display='none';
						}
						break;
				}
				
				// Show Tut info
				document.getElementById('tut_info_display_' + num).style.display='block';
				
				// Show loading icon
				//document.getElementById('loading_dial').style.display='none';
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}

/* ------------------------------------------------------------------------------------------ */
/* Function to add/remove tutorials from the bb array via AJAX */
function hideTutInfo(num) {

	switch (num) {
		case 'all':
			document.getElementById('tut_info_display_1').style.display='none';
			document.getElementById('tut_info_1').innerHTML='';
			document.getElementById('tut_info_display_2').style.display='none';
			document.getElementById('tut_info_2').innerHTML='';
			break;
			
		case '1':
			document.getElementById('tut_info_display_1').style.display='none';
			document.getElementById('tut_info_1').innerHTML='';
			break;
			
		case '2':
			document.getElementById('tut_info_display_2').style.display='none';
			document.getElementById('tut_info_2').innerHTML='';
			break;
	}

}

/* ------------------------------------------------------------------------------------------ */
/* Function to hide/show tutorials in the bundle */
function toggleBundleView(id) {

	if (document.getElementById('tut_list_' + id).style.display=='block') {
		document.getElementById('tut_list_' + id).style.display='none';
		document.getElementById('tut_list_txt').innerHTML = 'Show Bundle';
		document.getElementById('tut_list_icon').src='/bundlebuilder/img/icons/toggle_plus.png';
	} else {
		document.getElementById('tut_list_' + id).style.display='block';
		document.getElementById('tut_list_txt').innerHTML = 'Hide Bundle';
		document.getElementById('tut_list_icon').src='/bundlebuilder/img/icons/toggle_minus.png';
	}

}