/* Preload some images */

img0 = new Image();
img0.src = "/ned-web/img/icons/expand_off.gif";
img1 = new Image();
img1.src = "/ned-web/img/icons/expand_on.gif";
img2 = new Image();
img2.src = "/ned-web/img/icons/play_off.gif";
img3 = new Image();
img3.src = "/ned-web/img/icons/play_on.gif";
img4 = new Image();
img4.src = "/ned-web/img/icons/not_logged.gif";

/* ---- Function to toggle display of iFrame ------------------------------------------------------- */
function togglePlayer(toggle_state) {

	switch (toggle_state) {
		case '2':
			document.getElementById('iframe_area').style.display='block';
			document.getElementById('player_area').style.display='none';
			break;
			
		case '1':
			document.getElementById('iframe_area').style.display='none';
			document.getElementById('player_area').style.display='block';
			break;
			
	}
}

/* ---- Function to make the window full-screen ------------------------------------------------------- */
function full_screen(){
	window.moveTo(0,0)
	window.resizeTo(screen.width,screen.height-30)
}

/* ----- Show Video Preview Player ----------------------------------------------------------------- */
function loadNEDwebNav(nedweb_sec, safetitle, chap, sec, vid) {

	togglePlayer('1'); // Make sure to show player
	
	//qtInit();
	
	var attr = '?nedweb_sec=' + nedweb_sec + '&safetitle=' + safetitle + '&chap=' + chap + '&sec=' + sec + '&vid=' + vid;
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Show loading dial
	if (document.getElementById('loading_dial')) {
		document.getElementById('loading_dial').style.visibility='visible';
	}
	
	// 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 = '../../' + nedweb_sec + '/ajax/load_nav.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('nav_nedweb_area').innerHTML = content;
				
				// Show loading dial
				document.getElementById('loading_dial').style.visibility='hidden';
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}

/* ----- Show Video Preview Player ----------------------------------------------------------------- */
function loadNedWebNav(safetitle, chap, sec, vid) {

	togglePlayer('1'); // Make sure to show player
	
	//qtInit();
	
	var attr = '?safetitle=' + safetitle + '&chap=' + chap + '&sec=' + sec + '&vid=' + vid;
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Show loading dial
	document.getElementById('loading_dial').style.visibility='visible';
	
	// 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 = '../../ned-web/ajax/load_nav.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('nav_nedweb_area').innerHTML = content;
				
				// Show loading dial
				document.getElementById('loading_dial').style.visibility='hidden';
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}


/* ----- Display video files ------------------------------------------------------------------------------------- */
function showVideo(nedweb_sec, safetitle, tut_id, chap, sec, vid, vid_title) {

	togglePlayer('1'); // Make sure to show player
	
	// Display video title
	if (document.getElementById('vid_name_' + vid)) {
		var vid_title = document.getElementById('vid_name_' + vid).value;
	} else {
		var vid_title = 'Autoplay';
	}

	//alert("Tut ID: " + tut_id + "/ Chap: " + chap + "/ Sec: " + sec + "/ Vid: " + vid + "/ Title: " + vid_title);

	var attr = '?id=' + tut_id + '&chap=' + chap + '&sec=' + sec + '&vid=' + vid + '&vid_title=' + vid_title;
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Show loading dial
	if (document.getElementById('loading_dial')) {
		document.getElementById('loading_dial').style.visibility='visible';
	}
	
	// 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 = '../../' + nedweb_sec + '/ajax/video_player.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
				
				// Reload video list
				loadNEDwebNav(nedweb_sec, safetitle, chap, sec, vid);
				
				// Hide scrollbars
				document.getElementById('player_area').innerHTML = '';
				document.getElementById('player_area').style.overflow='';
				
				// Load player
				document.getElementById('player_area').innerHTML = content;
				
				// Show Video title
				document.getElementById('video_title').innerHTML = vid_title;
				
				// Show loading dial
				if (document.getElementById('loading_dial')) {
					document.getElementById('loading_dial').style.visibility='hidden';
				}
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}


/* ----- Display video files ------------------------------------------------------------------------------------- */
function showVid(safetitle, tut_id, chap, sec, vid, vid_title) {

	togglePlayer('1'); // Make sure to show player
	
	// Display video title
	if (document.getElementById('vid_name_' + vid)) {
		var vid_title = document.getElementById('vid_name_' + vid).value;
	}

	//alert("Tut ID: " + tut_id + "/ Chap: " + chap + "/ Sec: " + sec + "/ Vid: " + vid + "/ Title: " + vid_title);

	var attr = '?id=' + tut_id + '&chap=' + chap + '&sec=' + sec + '&vid=' + vid + '&vid_title=' + vid_title;
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Show loading dial
	document.getElementById('loading_dial').style.visibility='visible';
	
	// 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 = '../../ned-web/ajax/video_player.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
				
				// Reload video list
				loadNedWebNav(safetitle, chap, sec, vid);
				
				// Hide scrollbars
				document.getElementById('player_area').innerHTML = '';
				document.getElementById('player_area').style.overflow='';
				
				// Load player
				document.getElementById('player_area').innerHTML = content;
				
				// Show Video title
				document.getElementById('video_title').innerHTML = vid_title;
				
				// Show loading dial
				document.getElementById('loading_dial').style.visibility='hidden';
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}

/* ----- Show Tutorials and Last Played ----------------------------------------------------------------- */
function loadTutorials(nedweb_sec, site, sid) {

	togglePlayer('1'); // Make sure to show player
	
	//qtInit();
	
	var attr = '?site=' + site + '&sid=' + sid;
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Show loading dial
	if (document.getElementById('loading_dial')) {
		document.getElementById('loading_dial').style.visibility='visible';
	}
	
	// Clear video title area
	document.getElementById('video_title').innerHTML = 'Tutorials';
	
	// 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 = '../../' + nedweb_sec + '/ajax/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('player_area').innerHTML = content;
				document.getElementById('player_area').style.overflow='auto';
				
				// Show loading dial
				if (document.getElementById('loading_dial')) {
					document.getElementById('loading_dial').style.visibility='hidden';
				}
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}

/* ----- Show Tutorials by App Type ----------------------------------------------------------------- */
function loadTutorialsByApp(nedweb_sec, app, app_name) {
	
	togglePlayer('1'); // Make sure to show player
	
	//qtInit();
	
	var attr = '?app=' + app;
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Show loading dial
	if (document.getElementById('loading_dial')) {
		document.getElementById('loading_dial').style.visibility='visible';
	}
	
	// Clear video title area
	document.getElementById('video_title').innerHTML = 'Tutorials for ' + app_name;
	
	// 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 = '../../' + nedweb_sec + '/ajax/tutorials_by_app.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('appArea').innerHTML = content;
				document.getElementById('appArea').style.overflow='auto';
				
				// Show loading dial
				if (document.getElementById('loading_dial')) {
					document.getElementById('loading_dial').style.visibility='hidden';
				}
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}

/* ----- Show Recently Played ----------------------------------------------------------------- */
function loadRecentlyPlayed(nedweb_sec) {
	
	togglePlayer('1'); // Make sure to show player
	
	//qtInit();
	
	var attr = '?nedweb_sec=' + nedweb_sec;
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Show loading dial
	if (document.getElementById('loading_dial')) {
		document.getElementById('loading_dial').style.visibility='visible';
	}
	
	// Clear video title area
	document.getElementById('video_title').innerHTML = 'Recently Played Tutorial-Videos';
	
	// 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 = '../../' + nedweb_sec + '/ajax/recently_played.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('appArea').innerHTML = content;
				document.getElementById('appArea').style.overflow='auto';
				
				// Show loading dial
				if (document.getElementById('loading_dial')) {
					document.getElementById('loading_dial').style.visibility='hidden';
				}
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}


/* ----- Show Forums ----------------------------------------------------------------- */
function loadForums(site_url) {

	togglePlayer('2'); // Make sure to hide player
	
	document.getElementById('video_title').innerHTML = "Forums";
	document.getElementById('iframe_area').src=site_url + '/forum-nedweb/';

}

/* ----- Show Support ----------------------------------------------------------------- */
function loadSupport(site_url) {

	togglePlayer('2'); // Make sure to hide player
	
	document.getElementById('video_title').innerHTML = "Support";
	document.getElementById('iframe_area').src=site_url + '/support/index_nedweb.php';

}


/* ----- Display plan info area -------------------------------------------------------------------------------- */
function showPlanMatrix(nedweb_sec, aspect) {

	togglePlayer('1'); // Make sure to show player
	
	// Display video title
	var vid_title = 'Subscription Required';

	var attr = '?aspect=' + aspect;
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Show loading dial
	document.getElementById('loading_dial').style.visibility='visible';
	
	// 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 = '../../' + nedweb_sec + '/ajax/plans.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
				
				// Reload video list
				//loadNedWebNav(safetitle, chap, sec, vid);
				
				// Hide scrollbars
				document.getElementById('player_area').innerHTML = '';
				document.getElementById('player_area').style.overflow='';
				
				// Load player
				document.getElementById('player_area').innerHTML = content;
				
				// Show Video title
				document.getElementById('video_title').innerHTML = vid_title;
				
				// Show loading dial
				document.getElementById('loading_dial').style.visibility='hidden';
				
				tb_init('a.thickbox, area.thickbox, input.thickbox');
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
	
}

/* ----- Display preview info area -------------------------------------------------------------------------------- */
function showPreviewInfo(safetitle, tut_id, chap, sec, vid, vid_title) {

	togglePlayer('1'); // Make sure to show player
	
	// Display video title
	var vid_title = 'Subscription Required';

	//alert("Tut ID: " + tut_id + "/ Chap: " + chap + "/ Sec: " + sec + "/ Vid: " + vid + "/ Title: " + vid_title);

	var attr = '';
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Show loading dial
	document.getElementById('loading_dial').style.visibility='visible';
	
	// 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 = '../../ned-web/ajax/default_player.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
				
				// Reload video list
				//loadNedWebNav(safetitle, chap, sec, vid);
				
				// Hide scrollbars
				document.getElementById('player_area').innerHTML = '';
				document.getElementById('player_area').style.overflow='';
				
				// Load player
				document.getElementById('player_area').innerHTML = content;
				
				// Show Video title
				document.getElementById('video_title').innerHTML = vid_title;
				
				// Show loading dial
				document.getElementById('loading_dial').style.visibility='hidden';
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
	
}

