// Script 13.3 - checkusername.js

/*	This page does all the magic for applying
 *	Ajax principles to a registration form.
 *	The users's chosen username is sent to a PHP 
 *	script which will confirm its availability.
 */

//////// VENUE OPERATIONS ////////////////////////////////////////////////////

function loadVideoEmbedCode(video_id, html_id_container) {
	//document.getElementById('status_label').innerHTML = "Saving...";
	if(video_id !="" && html_id_container != ""){
		
		// Confirm that the object is usable:
		if (ajax) { 
			
			ajax.open('POST', 'processes/load_video_embed_code.php');
			
			// Function that handles the response:
			ajax.onreadystatechange = loadVideoEmbedCode_handle_check;
			
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		
			// Send the request:
			ajax.send("video_id="+escape(video_id)+
					  "&html_id_container="+escape(html_id_container) );
			
		} else { // Can't use Ajax!
	
			//document.getElementById('status_label').innerHTML = 'Could not be saved.';
		}
		
	}else{
		alert('Please make sure all fields are filled in, then try again.');	
	}
	
} // End of check_username() function.

// Function that handles the response from the PHP script:
function loadVideoEmbedCode_handle_check() {

	// If everything's OK:
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {

		var xmlDoc = ajax.responseXML;
		//alert('Attmpting to Return CONTAINER'+xmlDoc);
		var xml_html_id_container = xmlDoc.getElementsByTagName("html_id_container")[0];
		var html_id_container = xml_html_id_container.firstChild.nodeValue;
		
		var xml_embed_code = xmlDoc.getElementsByTagName("embed_code")[0];
		var embed_code = xml_embed_code.firstChild.nodeValue;
		
		//alert(embed_code);
		
		document.getElementById(html_id_container).innerHTML = embed_code;
		//document.getElementById('newshortname').value = "";
		
	}else{
	
	}
	
} // End of handle_check() function.


function unloadVideoEmbedCode(html_id_container) {
	//document.getElementById('status_label').innerHTML = "Saving...";
	if(html_id_container != ""){
		
		document.getElementById(html_id_container).innerHTML = "";
	
	}else{
		alert('Please make sure all fields are filled in, then try again.');	
	}
	
} // End of check_username() function.


function copy_image_to_thumb(event_id, currentImg, pathToImg, maxImgWidth, maxImgHeight, idofimg, displaypathToImg) {
	//document.getElementById('status_label').innerHTML = "Saving...";
	
	if(event_id !=""){
		
		// Confirm that the object is usable:
		if (ajax) { 
			
			ajax.open('POST', 'processes/copy_image_to_thumb.php');
			
			// Function that handles the response:
			ajax.onreadystatechange = copy_image_to_thumb_handle_check;
			
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
			// Send the request:
			ajax.send("event_id="+escape(event_id)+
					  "&currentImg="+escape(currentImg)+
					  "&pathToImg="+escape(pathToImg)+
					  "&maxImgWidth="+escape(maxImgWidth)+
					  "&maxImgHeight="+escape(maxImgHeight)+
					  "&idofimg="+escape(idofimg)+
					  "&displaypathToImg="+escape(displaypathToImg));
			
			//document.getElementById('admin_'+delete_id).style.display = "none";
		} else { // Can't use Ajax!
	
			//document.getElementById('status_label').innerHTML = 'Could not be saved.';
		}
	}else{
		alert('No Image to Copy');	
	}
	
} // End of check_username() function.

// Function that handles the response from the PHP script:
function copy_image_to_thumb_handle_check() {

	// If everything's OK:
	if ( (ajax.readyState == 4) && (ajax.status == 200) ) {
		
		var xmlDoc = ajax.responseXML;
		
		var xml_resultmessage = xmlDoc.getElementsByTagName("resultmessage")[0];
		var resultmessage = xml_resultmessage.firstChild.nodeValue;
		
		var xml_idofimg = xmlDoc.getElementsByTagName("idofimg")[0];
		var idofimg = xml_idofimg.firstChild.nodeValue;
		
		var xml_displaypathToImg = xmlDoc.getElementsByTagName("displaypathToImg")[0];
		var displaypathToImg = xml_displaypathToImg.firstChild.nodeValue;
		
		//alert(resultmessage);
		document.getElementById(idofimg).src=displaypathToImg;

	}else{
	
	}
	
} // End of handle_check() function.


