//Browser Support Code
function addFavs(){

	var ajaxRequestFav; // The variable that makes Ajax possible!

	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequestFav = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequestFav = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequestFav = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}

	var content_id = document.getElementById('contentid').value;
	var queryString = "?contentid=" + content_id;
	ajaxRequestFav.open("GET", "tmpDo-addfave.php" + queryString, true);
	ajaxRequestFav.send(null); 
	//alert(queryString);

	document.forms['addToFavs'].elements['fav'].style.visibility = 'hidden';
	//document.forms['addToFavs'].elements['added'].style.display = 'inline';
	alert("This has now been added to your favourites!");
}



function ajaxFunctionReport(){


	var ajaxRequest; // The variable that makes Ajax possible!
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}


	var recipient = "paul.evans@themusicpage.com";
	var check = 0;
	//Check the email address
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(recipient)){
		check = 1;
	} else {
		alert("Invalid E-mail Address! Please re-enter.")
		check = 0;
	}
	if (check == 1) {
		var message = document.getElementById('reportComment').value;
		var content_id = document.getElementById('content_id').value;
		var person_id = document.getElementById('person_id').value;
		var username = document.getElementById('username').value;
		var queryString = "?message=" + message + "&content_id=" + content_id + "&recipient=" + recipient + "&person_id=" + person_id + "&username=" + username;
		ajaxRequest.open("GET", "do-reportContent.php" + queryString, true);
		ajaxRequest.send(null); 
		//alert("do-reportContent.php" + queryString);

		document.getElementById('report').style.display = 'none';
		//document.getElementById('shareResult').style.display = 'inline';
		var ajaxDisplay = document.getElementById('reportResult');
		ajaxDisplay.innerHTML='<div align="center"><img src="images/ok.gif"><h4>Message Sent!</h4></div>';
		setTimeout('document.getElementById(\'reportResult\').innerHTML=\'\'', 5000);
	}
}


//Browser Support Code
function ajaxFunctionShare(type){


	var ajaxRequest; // The variable that makes Ajax possible!
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}


	var recipient = document.getElementById('recipient').value;
	var check = 0;
	//Check the email address
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(recipient)){
		check = 1;
	} else {
		alert("Invalid E-mail Address! Please re-enter.")
		check = 0;
	}
	if (check == 1) {
		var message = document.getElementById('message').value;
		var content_id = document.getElementById('content_id').value;
		var queryString = "?message=" + message + "&content_id=" + content_id + "&recipient=" + recipient + "&type=" + type;
		ajaxRequest.open("GET", "do-shareContent.php" + queryString, true);
		ajaxRequest.send(null); 

		document.getElementById('share').style.display = 'none';
		document.getElementById('shareResult').style.display = 'inline';
		var ajaxDisplay = document.getElementById('shareResult');
		ajaxDisplay.innerHTML='<div align="center"><img src="images/ok.gif"><h4>Message Sent!</h4></div>';
		setTimeout('document.getElementById(\'shareResult\').innerHTML=\'\'', 5000);
	}
}




//Browser Support Code
function ajaxFunctionTellFriend(type){

	var ajaxRequest; // The variable that makes Ajax possible!
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}


	var recipient = document.getElementById('recipient').value;
	var check = 0;
	//Check the email address
	if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(recipient)) && (document.getElementById('from').value != "")) {
		check = 1;
	} else {
		alert("Please make sure all fields are complete and the email address is valid.")
		check = 0;	
	}

	if (check == 1) {
		var message = document.getElementById('message').value;
		var from = document.getElementById('from').value;
		var queryString = "?message=" + message + "&from=" + from + "&recipient=" + recipient;
		ajaxRequest.open("GET", "do-tellFriend.php" + queryString, true);
		ajaxRequest.send(null); 

		document.getElementById('share').style.display = 'none';
		document.getElementById('shareResult').style.display = 'inline';
		var ajaxDisplay = document.getElementById('shareResult');
		ajaxDisplay.innerHTML='<div align="center"><img src="images/ok.gif"><h4>Message Sent!</h4></div>';
		setTimeout('document.getElementById(\'shareResult\').innerHTML=\'\'', 5000);
	}
}



//comment
//Browser Support Code
function ajaxFunction(){
	var ajaxRequest; // The variable that makes Ajax possible!
		try{
			// Opera 8.0+, Firefox, Safari
			ajaxRequest = new XMLHttpRequest();
		} catch (e){
			// Internet Explorer Browsers
			try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		try{
			if(ajaxRequest.readyState == 4){
				//document.myForm.time.value = ajaxRequest.responseText;
				//document.getElementById("allComments").innerHTML=ajaxRequest.responseText;
				var ajaxDisplay = document.getElementById('allComments');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
			//ajaxDisplay.innerHTML = "RESPONSE";
			} else {
				var ajaxDisplay = document.getElementById('allComments');
				ajaxDisplay.innerHTML='<div align="center">Please Wait... <img src="images/working.gif"></div>';
			}
		} catch(e) {
		//alert(e);
		}
	}
	
	/*
	var comment = document.getElementById('comment').value;
	comment = comment.replace(/\n/g, "<br />");
	var content_id = document.getElementById('content_id').value;
	var heading = document.getElementById('heading').value;
	var queryString = "?comment=" + comment + "&content_id=" + content_id + "&heading=" + heading;
	ajaxRequest.open("GET", "addComment.php" + queryString, true);
	ajaxRequest.send(null); 
	//alert(queryString);
	*/
	
	var comment = document.getElementById('comment').value;
	var content_id = document.getElementById('content_id').value;
	var heading = document.getElementById('heading').value;
	
	var url = "addComment.php";
	var params = "comment=" + comment + "&content_id=" + content_id + "&heading=" + heading;
	ajaxRequest.open("POST", url, true);
	
	//Send the proper header information along with the request
	ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//ajaxRequest.setRequestHeader("Content-length", params.length);
	//ajaxRequest.setRequestHeader("Connection", "close");
	
	ajaxRequest.send(params);
 
	
	//document.getElementById('postComment').style.display = 'none';

}
