   var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('mycommentspan').innerHTML = result;
         } else {
            //alert('There was a problem with the request.');
			document.getElementById('mycommentspan').innerHTML = 'There was a problem with the request. Please contact us and report this problem!';
         }
      }
   }
   
   function get(obj) {
	   
	  var poststr;
	  if(document.getElementById("user_id").value == 0)
	  {
		 poststr = "comment_txt=" + encodeURI( document.getElementById("comment_txt").value ) +
                    "&vid=" + encodeURI( document.getElementById("vid").value ) +
					"&user_id=" + encodeURI( document.getElementById("user_id").value ) +
					"&username=" + encodeURI( document.getElementById("username").value ) +
					"&captcha=" + encodeURI( document.getElementById("captcha").value );
	  }
	  else {
		 poststr = "comment_txt=" + encodeURI( document.getElementById("comment_txt").value ) +
		 			"&user_id=" + encodeURI( document.getElementById("user_id").value ) +
                    "&vid=" + encodeURI( document.getElementById("vid").value );
	  }
	  
      makePOSTRequest(''+MELODYURL+'/comment.php', poststr);
   }

function submitonce(theform){
//if IE 4+ or NS 6+
	if(document.getElementById("user_id").value != 0)
	{
		if(document.getElementById("comment_txt").value == '' || document.getElementById("comment_txt").value == "test"){
			//alert('You need to write a comment first!');
		}
		else{
			if (document.all||document.getElementById){
				//screen thru every element in the form, and hunt down "submit" and "reset"
				for (i=0;i<theform.length;i++){
					var tempobj=theform.elements[i]
					if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
					//disable em
					tempobj.disabled=true;
				}
				//theform.style.display='none';
				$(theform).slideUp('normal');
			}
		}
	}
	else
	{
		//	guest comment
		var alert_msg = '';
		if(document.getElementById("comment_txt").value == ''){
			//alert('You need to write a comment first!');
			alert_msg = alert_msg+'You need to write a comment first!\n';
		}
		if(document.getElementById("username").value == '' || document.getElementById("captcha").value == ''){
			alert_msg = alert_msg+'Please fill in the required fields.\n';
		}
		
		if(alert_msg != '') {
			//alert(alert_msg);
		}
		else{
			if (document.all||document.getElementById){
				//screen thru every element in the form, and hunt down "submit"
				for (i=0;i<theform.length;i++){
					var tempobj=theform.elements[i]
					if(tempobj.type.toLowerCase()=="submit")
					//disable em
					tempobj.disabled=false;
				}
				//theform.style.display='none';
				$(theform).slideUp('normal');
			}
		}	
	}
	
}

function validateSearch(b_on_submit){
    if(document.forms['search'].keywords.value == '' || document.forms['search'].keywords.value == 'search'){
        alert('You did not enter a search term. Please try again.');
        if(b_on_submit == 'true')
            return false;
    }
    else{
        document.forms['search'].submit();
    }
}
function lookup(inputString) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions').hide();
	} else if(inputString.length > 2) {
		$.post(MELODYURL2+'/ajax_search.php', {queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#suggestions').show();
				$('#autoSuggestionsList').html(data);
			}
		});
	}
} // lookup
	
function catlist()
{
	$("#ul_categories li").hoverIntent(
	 function(){
			var ul_subs = $(this).find('ul');
			
			if(ul_subs.hasClass("hidden_li"))
			{	
				ul_subs.removeClass();
				ul_subs.slideDown(80);
				ul_subs.addClass('visible_li')
			}
	 }, 
	 function(){
			var ul_subs = $(this).find('ul');
			
			if(ul_subs.hasClass("visible_li"))
			{
				ul_subs.addClass("hidden_li");	
				ul_subs.slideUp(150);
				ul_subs.removeClass('visible_li');
			}
	 });

}

function fill(thisValue) {
	$('#inputString').val(thisValue);
	setTimeout("$('#suggestions').hide();", 200);
}

function ajax_request(page, extra_params, output_sel, type, show) {
	
	var ret = false;
	
	if (type.length == 0)
	{
		type = "html";	
	}

	if (output_sel.length > 0)
	{
		$(output_sel).html('<img src="'+TemplateP+'/images/ajax-loading.gif" alt="Loading" id="loading" />Loading...').fadeIn('normal');	
	}
	$.ajax({
		   type: "GET",
		   url: MELODYURL2 + "/ajax.php", 
		   //cache: false, 
		   data: "p=" + page + "&" + extra_params,
		   dataType: type,
		   success: function(data) {
						if (output_sel.length > 0)
						{
							$(output_sel).html(data);
							
							if (show == true)
							{
								$(output_sel).show();
							}
						}
						ret = true;
					}
		   });
	
	return ret;
}

function onpage_delete_comment(comment_id, video_id, selector) {

	var confirm_msg = "You are about to delete this comment. Click 'Cancel' to stop, 'OK' to delete";
	var response = false;
	
	if (confirm(confirm_msg)) 
	{
		if (selector.length > 0) 
		{
			ajax_request("comments", "do=onpage_delete_comment&cid=" + comment_id + "&vid=" + video_id, "", "", false);
			$(selector).fadeOut('normal');
		}
	}
}

function onpage_delete_favorite(video_id, selector) {

	var response = false;

		if (selector.length > 0) 
		{
			ajax_request("favorites", "do=onpage_delete_favorite&vid=" + video_id, "", "", false);
			$(selector).fadeOut("slow");
		}
}
var arPlayer = null;
var arDone = false;
function reportNotFound(uid) {
	if (uid.length > 0 && !arDone) {
		ajax_request("video", "do=report&vid=" + uid, "", "", false);
		arDone = true;
	}
}
function onStreamNotFound(clip) {
	reportNotFound(clip.name);	
}
function triggerPlayerError(obj) {
	reportNotFound(arPlayer.id);
}
function playerReady(obj) {
	arPlayer = document.getElementById(obj['id']);
	arPlayer.addModelListener("ERROR", "triggerPlayerError");
}
