/******************************************************************
*	file		:		clientscript/ajax.js
*
*	Methods for creating ajax-requests
*	mainly uses ajax.php for getting data
*
******************************************************************/

/***
* Fetches file given as argument
* and returns it's output
*/
function do_ajax(containerObject, urlstring)
{
	var AJAX;
	if( window.XMLHttpRequest )
	{
		AJAX = new XMLHttpRequest();
	}
	else
	{
		AJAX = new ActiveXObject("Microsoft.XMLHTTP");
	}
   
   if( AJAX )
   {
		AJAX.open('get', urlstring, false);
		AJAX.send(null);
		containerObject.innerHTML = AJAX.responseText;
		
		var scripts = containerObject.getElementsByTagName('script');
		for(var i=0;i<scripts.length;i++)
		{
			eval(scripts[i].innerHTML);
		}
	}
	else
	{
		return false;
	}
}

/* video functions */
function submit_video_comment(profileid, messagebox)
{
	var containerObj = _('videocomments'+profileid);
	var message = escape( _(messagebox).value );
	do_ajax( containerObj, 'ajax.php?action=video_submit_comment&profileid='+profileid+'&message='+message );
	containerObj.style.height = '';
	_(messagebox).value = '';
}

function delete_video_comment(profileid, commentid)
{
	var containerObj = _('videocomments'+profileid);
	do_ajax( containerObj, 'ajax.php?action=video_delete_comment&profileid='+profileid+'&commentid='+commentid );
	containerObj.style.height = '';
	return false;
}

function video_goto_page(profileid, page)
{
	var containerObj = _('videocomments'+profileid);
	do_ajax( containerObj, 'ajax.php?action=video_fetch_comments&profileid='+profileid+'&page='+page );
	containerObj.style.height = '';
	return false;
}

/*
function video_vote_comment(videoid, commentid, page, vote)
{
	var containerObj = _('videocomments'+videoid);
	do_ajax( containerObj, 'ajax.php?action=video_vote_comment&profileid='+videoid+'&commentid='+commentid+'&page='+page+'&vote='+vote );
	return false;
}
*/

/* Locations and groups for registering */
/*
function update_videos( container, selectname, channelid)
{
	var containerObj = _(container);
	do_ajax( containerObj, 'ajax.php?action=fetch_videos&channelid='+channelid+'&selectname='+selectname);	
}
*/

/* Edit users profile */
/*
function edit_profile( userid )
{
	var containerObj = _('userprofile');
	do_ajax( containerObj, 'ajax.php?action=edit_profile&userid='+userid);
	return false;
}
*/

/* Submit user profile */
/*
function submit_profile( userid, profilebox )
{
	var containerObj = _('userprofile');
	var profile = escape( _(profilebox).value );
	do_ajax( containerObj, 'ajax.php?action=submit_profile&userid='+userid+'&profile='+profile);
	return false;
}
*/

/* Vote on video */
/*
function video_vote( userid )
{
	var containerObj = _('video_score');
	var vote = _('vote_value').value;
	do_ajax( containerObj, 'ajax.php?action=video_vote&userid='+userid+'&vote='+vote);
	return false;
}
*/


