/* ------------------------------------------------------------------------------------------ */
/* Function to load Tutorials */
function loadTutList(filter, value) {

	var attr = 'scripts=yes&filter=' + filter + '&value=' + value;
	var xmlhttp = false; 	// Clear our fetching variable
	
	// Clear the Search field
	if (filter != 'search') {
		document.getElementById('search_field').value='';
	}
	
	// Clear tutorial display
	document.getElementById('tutorial_area').innerHTML = '';
				
	// Show loading icon
	document.getElementById('loading').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 = '../tutorial_area/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
			
				// Load the content
				document.getElementById('tutorial_area').innerHTML = content;
				
				// Show loading icon
				document.getElementById('loading').style.display='none';
				
			}
		}
	}
	
	xmlhttp.send(null) //Nullify the XMLHttpRequest
	return;
}

function submitReview(){
	 $("#submit_review_link").click();
}

function addReview(){

			$.ajax({
		   		url: "/tutorial_area/ajax/add_review.php",
		   		dataType: "xml",
		   		type: "POST",
		   		data: $("#review_form").serialize(),
		   		timeout: 10000,
		   		success: function(data){
					
					//check response
					var loginFailed = "Login Failed. Please try again";
					var error_msg = "Please complete all fields marked with a red arrow (<img src=\"../../img/icons/required.gif\" width=\"10\" height=\"10\" />) and try again.";
					var success =  "Thank you for your submission. Your review will be verified before being made public on <?php echo $domain_title;?>.<p><input type=\"button\" value=\"Close\" onClick=\"tb_remove();\" style=\"width: 80px;\" /></p>\n";
					
					var login_var;
					var error_var;
					var success_var;
					
					success_var = $(data).find("success").text();
					if(success_var == 'success'){

						$("#login_msg").html("");
						$("#login_msg").hide();
						$("#err_msg").html("");
						$("#err_msg").hide();
						
						$("#review_form").hide();
						$("#success_msg").html(success);
						$("#success_msg").show();
					}
					else{
						$("#ts_name_img").hide();
						$("#ts_email_img").hide();
						$("#ts_content_img").hide();
						$("#ts_password_img").hide();
						
						$(data).find("loginerror").each(function(){
							login_var = $(this).text();
							$("#"+login_var+"_img").show();
						});
						if(login_var == 'ts_email' || login_var == 'ts_password'){
							$("#login_msg").html(loginFailed);
							$("#login_msg").show();
						}
						else{
							$("#login_msg").html("");
							$("#login_msg").hide();
							$("#ts_email_img").hide();
							$("#ts_password_img").hide();
						}
						
						$(data).find("Error").each(function(){
							error_var = $(this).text();
							$("#"+error_var+"_img").show();
						});
						
						if(error_var == "ts_email" || error_var == "ts_name" || error_var == "ts_content"){
							$("#err_msg").html(error_msg);
							$("#err_msg").show();
						}
						else{
							$("#err_msg").html("");
							$("#err_msg").hide();
							
							
						}
					}
				},
				error: function(xhr, ajaxOptions){
							var connect_err = "An error has occured. Please try again.";
							$("#err_msg").html(connect_err);
							$("#err_msg").show();
						}
			});
			return false;
		}