/******************************************************************
*	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;
	}
	else
	{
		return false;
	}
}

/* video functions */
function submit_video_comment(profileid, mode, messagebox)
{
	var containerObj = _('videocomments'+profileid);
	var message = escape( _(messagebox).value );
	var modetype = mode;
	do_ajax( containerObj, 'ajax.php?action=video_submit_comment&profileid='+profileid+'&mode='+modetype+'&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, mode)
{
	var containerObj = _('videocomments'+profileid);
	do_ajax( containerObj, 'ajax.php?action=video_fetch_comments&profileid='+profileid+'&page='+page+'&mode='+mode );
	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_locations( container, selectname, groupid, include_all )
{
	var containerObj = _(container);
	do_ajax( containerObj, 'ajax.php?action=fetch_locations&groupid='+groupid+'&selectname='+selectname+'&include_all='+include_all);	
}

/* 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;
}


