/***********************************************
* Dynamic Ajax Content- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var undefined

var cal
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""
var page_request = false

// For search sorting
var sortkey = '';
var dir = '';
var cmd;
var oldv;
var isIE = (document.all && document.attachEvent);

function reload_hash(){
	//check location
	
	var url = window.location;
	url += "";
	var ind = url.indexOf("#");
	if(ind<0){
		window.location.reload();
	}
	
	var bstring = url.substr(ind);
	//make sure # i not a named a
	
	if(bstring == '#null' || bstring == 'null') {
		return;
	}
	
	if(bstring.indexOf("d=")<0||bstring.indexOf("u=")<0){
		//window.location.reload();
		if(bstring==''||bstring=='#'){
			
			window.location.reload();
		}
	}
	var tdiv = unescape(bstring.substr(bstring.indexOf("d=")+2,bstring.indexOf("u=")-3	));
	var url = unescape(bstring.substr(bstring.indexOf("u=")+2));
	do_ajaxpage(url, tdiv, cmd);
	
}

function do_ajaxpage(url, containerid, commands, do_not_jump){
		/* fetches url, inserts response into container element,
	//	then runs commands. */
		new Ajax.Request(url, {
		  evalScripts: true,
		  method:'get',
		  onSuccess: function(transport){
		  	$(containerid).update(transport.responseText);
		  	init_wysiwyg(containerid);
		  	afterComp(containerid, commands, do_not_jump);
		  }
		});
}

function afterComp(containerid, commands, do_not_jump){
	if(commands!=undefined){
		try{
			eval(commands)
		}catch (e){
			//do nothing
		}
	}
	if(do_not_jump!=true){
		Effect.ScrollTo(containerid, {offset:-60, duration:0.25});
	}
}

function ajaxpage(url, containerid, commands){
	cmd = commands;
	if(containerid == 'ajax-smallframe') {
		$(containerid).innerHTML = '';
		do_ajaxpage(url, containerid, commands, true);
	}else{		
		hashListener.setHash("d="+escape(containerid)+"u="+escape(url));
		//window.scrollTo(0,0);
	}
}

function loadpage(page_request, containerid, commands){
	if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
		command_load();
		var loader = document.getElementById('loader');
		if(loader != null && loader != undefined) {
			hideLoading();
		}
	}
}

function checkVariousCounts(url) {
	if (bustcachevar) //if bust caching of external page
		bustcacheparameter=(url.indexOf("?")!=-1)? "&bc="+new Date().getTime() : "?bc="+new Date().getTime()
	new Ajax.Request(url+bustcacheparameter, {
		evalJSON: true,
		method:'get',
		onComplete : function(transport){
			var obj = transport.responseJSON;
			if(obj == undefined) {
				return false;
			}
			var msg_count = document.getElementById('notify-messages');
			var msg_count2 = document.getElementById('new_messages');
			var freq_count = document.getElementById('notify-friends');
			var freq_count2 = document.getElementById('friend_requests');
			var userlink = document.getElementById('username-link');
			var total = obj.length;
							
			for(var i = 0; i < total; i++) {
				msg_count.innerHTML = '<a' + ((obj[i].messageTotal > 0) ? ' class="new"' : '') + ' href="/player_home?panel=message_inbox&js=message" title="' + obj[i].messageTotal + ' Message' + (obj[i].messageTotal != 1 ? 's' : '') + '">Inbox(' + obj[i].messageTotal + ')</a>';
				
				if(msg_count2 != null && obj[i].messageTotal > 0) {
					msg_count2.innerHTML = "("+obj[i].messageTotal+" New)";
				}else{
					if(msg_count2 != null) {
						msg_count2.innerHTML = '';
					}
				}
				
//					freq_count.innerHTML = '<a' + ((obj[i].friendTotal > 0) ? ' class="new"' : '') + ' href="/player_home?panel=friends_manage_invites&js=friend" title="' + obj[i].friendTotal + ' Friend Request' + (obj[i].friendTotal != 1 ? 's' : '') + '">' + obj[i].friendTotal + 'FR</a>';
//					
//					if(freq_count2 != null && obj[i].friendTotal > 0) {
//						freq_count2.innerHTML = "(" + obj[i].friendTotal + ")";
//					}else{
//						if(freq_count2 != null) {
//							freq_count2.innerHTML = '';
//						}
//					}
			}
		}
	});
}

function loadobjs(){
	if (!document.getElementById){
		return
	}
	for (i=0; i<arguments.length; i++){
		//alert (arguments[i]);
		var file=arguments[i]
		var fileref=""
		if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
			if (file.indexOf(".js")!=-1){ //If object is a js file
				fileref=document.createElement('script')
				fileref.setAttribute("type","text/javascript");
				fileref.setAttribute("src", file);
			}else if (file.indexOf(".css")!=-1){ //If object is a css file
				fileref=document.createElement("link")
				fileref.setAttribute("rel", "stylesheet");
				fileref.setAttribute("type", "text/css");
				fileref.setAttribute("href", file);
			}
		}
		if (fileref!=""){
			document.getElementsByTagName("head").item(0).appendChild(fileref)
			loadedobjects+=file+" " //Remember this object as being already added to page
		}
	}
	return true;
}

function posDiv() {
	positionDiv('ajax-smallframe');
}

function posDivSide() {
	positionDiv('ajax-smallframe', true);
}

function positionDiv(id) {
	var objs = document.getElementById(id);
	var obj2 = document.getElementById('fade-out');
	var obj3 = document.getElementById('video-display');
	if(obj3 != null && isIE) {
		oldv = obj3.innerHTML;
		obj3.innerHTML = '';
		obj3.style.visibility = 'hidden';
	}
	obj2.style.display = 'block';
	var width = getViewportSize("width");
	var height = getViewportSize("height");
	posleft = (width/2) - 250;
	postop = (height/2) - 250;
	if(posleft < 0) posleft = 0;
	if(postop < 0) postop = 0;
	objs.style.left = posleft + 'px';
	objs.style.top = postop + 'px';
	if(objs.style.display != 'block') {
		objs.style.display = 'block';
		hookEvent(document, 'keyup', function (e) {
	
	if(!e) {var e=window.event;}
	if(e.keyCode == 27) {
		if(objs.style.display == 'block') {
			document.getElementById('ajax-smallframe-close').onclick();
			unhookEvent(document, 'keyup');
			unhookEvent(window, 'resize');
		}
		return false;
	}
	
});
		window.onresize = posDiv;
	}
	return true;
}

function hideDiv(id) {
	var objs = document.getElementById(id);
	objs.style.display = 'none';
	var obj2 = document.getElementById('fade-out');
	obj2.style.display = 'none';
	var obj3 = document.getElementById('as_friend');
	if(obj3 != null && obj3.style) {
		obj3.style.display = 'none';
	}
	var obj4 = document.getElementById('video-display');
	if(obj4 != null && isIE) {
		obj4.innerHTML = oldv;
		obj4.style.visibility = 'visible';
	}
	window.onresize = '';
}

function hookEvent(obj, event, func) {
	if(obj != window) {
		if(obj.addEventListener) {
			obj.addEventListener(event, func, false);
			return;
		}
		if(obj.attachEvent) {
			obj.attachEvent("on" + event, func);
			return;
		}
	}
	command = "obj.on" + event + " = " + func.name;
	eval(command);
	return;
}

function unhookEvent(obj, event) {
	if(obj != window) {
		if(obj.removeEventListener) {
			obj.removeEventListener(event, function () {}, false);
			return;
		}
		if(obj.detachEvent) {
			obj.detachEvent("on" + event, function () {});
			return;
		}
	}
	command = "obj.on" + event + " = ''";
	eval(command);
	return;
}

function getRidOfLargeImage() {
	var pb = document.getElementById('page-bot');
	var wid = getViewportSize('width');
	if(wid < 1130) {
		pb.style.display = 'none';
	}
}

function rsEvent(e) {
	repopulateSelect('/blank.php?do=personalDetails_getTimezone&con=' + $('timezone-continent').getValue(), 'timezone');
}


/***********************************************
* Dynamic Ajax Post/Get Requests
***********************************************/

function doAjaxSubmit(formid, url, divid, commands){
	//will submit form and echo response to page
	var params = $(formid).serialize();
	$(divid).update("<img src='/images/working.gif' />");
	
	new Ajax.Request(url, {
		method: 'post',
		parameters: params,
		evalScripts: true,
		onSuccess: function(transport) {
			location.hash = 'null';
			$(divid).update(transport.responseText);
			init_wysiwyg(divid);
			command_load();
		}
	});
}

function doAjaxGetSubmit(formid, url, divid, commands){
	//will submit form and echo response to page
	var params = $(formid).serialize();
	$(divid).update("<img src='/images/working.gif' />");
	
	new Ajax.Request(url,
		{method: 'get',
		evalScripts: true,
		parameters: params,
		onSuccess: function(transport) {
			location.hash = 'null';
			$(divid).update(transport.responseText);
			init_wysiwyg(divid);
			command_load();
		}
	});
}

function command_load(commands) {
	if(commands!=undefined){
		var cmd = commands.split(';');
		var failed = new Array();
		for ( var i in cmd ){
			if(cmd[i].trim!=''){
				try{
					eval(cmd[i]);
				}catch (e){
					failed.push(cmd[i])
				}
			}
		}
		if(failed.length > 0) {
			createCookie('commands', failed.join(';'), 1);
		}else{
			eraseCookie('commands');
		}
	}else{
		commands = readCookie('commands');
		if(commands != null) {
			var cmd = commands.split(';');
			var failed = new Array();
			for ( var i in cmd ){
				if(cmd[i].trim!=''){
					try{
						eval(cmd[i]);
					}catch (e){
						failed.push(cmd[i])
					}
				}
			}
			if(failed.length > 0) {
				createCookie('commands', failed.join(';'), 1);
			}else{
				eraseCookie('commands');
			}
		}
	}
}

function ajaxPOST(url, postString, divResult){
	//will submit form and echo response to page
	new Ajax.Request(url, {
		parameters: postString,
		onSuccess: function(transport) {
			$(divResult).update(transport.responseText);
			try{widgInit()}
			catch(e){				
			}
		}
	});
}

function resortResults(key, module, action, dest, caller) {
	var page = location.href;
	var backuparguments = {};
	arguments['module'] = module;
	arguments['action'] = action;
	arguments['sortkey'] = key;
	if(sortkey == key) {
		if(dir == 'up') {
			arguments['sortkey'] = '';
			arguments['dir'] = '';
		}else{
			if(dir == 'down') {
				arguments['dir'] = 'up'
			}else{
				arguments['dir'] = 'down';
			}
		}
	}else{
		arguments['dir'] = 'down';
	}
	if(arguments['sortkey'] == '') {
		sortkey = '';
	}else{
		sortkey = key;
	}
	dir = arguments['dir'];
	var search_stuff = $(module + '-search-form').serialize();
	var newarguments = search_stuff.toQueryParams();
	for(value in newarguments) {
		if(newarguments[value] != '' && newarguments[value] != undefined) {
			arguments[value] = newarguments[value];
		}
	}
	for(value in arguments) {
		if(arguments[value] != '' && arguments[value] != undefined) {
			backuparguments[value] = arguments[value];
		}
	}
	var query_string = backuparguments.toQueryString();
	while(query_string.charAt(query_string.length - 1) == '&') {
		query_string = query_string.substring(0, query_string.length - 1);
	}
	//window.alert(query_string)
	ajaxpage('/blank.php' + query_string, dest);
}

function getArgsFromQueryString(query_string) {
	var args = new Object();
	var query = query_string;
	var pairs = query.split("&");
	for(var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
}

function createQueryStringFromArgs(args) {
	var qs = '?';
	for(value in args) {
		qs += value + '=' + escape(args[value]) + '&';
	}
	qs = qs.substring(0, qs.length - 1);
	return qs;
}

function addVariableIfNecessary(url, name, value) {
	if(value == '') {
		return url;
	}
	var variable = escape(name) + "=" + escape(value);
	if(url.IndexOf('?') == -1) {
		return url + '?' + variable;
	}else{
		var lastCharacter = url.substr(url.length, 1);
		while(lastCharacter == '&') {
			url = url.substr(url.length, 1);
			lastCharacter = url.substr(url.length, 1);
		}
		return url + "&" + variable;
	}
}

function getQuery(name) {
	var obj = document.getElementsByTagName('INPUT');
	var args = new Object();
	var str = '';
	var count = 0;
	for(var i = 0; i < obj.length; i++) {
		if(obj[i].getAttribute('name') == 'value[]') {
			str = "value" + count;
			args[str] = obj[i].value;
			count++;
		}
	}
	qs = createQueryStringFromArgs(args);
	qs = qs.substring(1, qs.length);
	return "&" + qs;
}

/********************************************
**
**Enter User Defined Ajax Functions Below
*********************************************/

//global functions
function checkUserName(name,tdiv){
	var postval = "uname=" + name;
	new Ajax.Request('/blank.php?module=account&action=checkUserName', {
		method: 'post',
		parameters: postval,
  		onSuccess: function(transport) {
			//document.getElementById(tdiv).innerHTML = "done";
			if(transport.responseText.blank()) {
				$(tdiv).update().hide();
				$('username').removeClassName('err');
			}else{
				$(tdiv).update(transport.responseText).show();
				$('username').addClassName('err');
			}
		}
	});
}

function checkEmail(name,tdiv,target){
	if(target == undefined) {
		target = 'regi_email';
	}
	var postval = "email=" + name;
	new Ajax.Request('/blank.php?do=account_checkEmail', {
		method: 'post',
		parameters: postval,
		onSuccess: function(transport) {//Call a function when the state changes.
			//document.getElementById(tdiv).innerHTML = "done";
			if(transport.responseText == '') {
				$(tdiv).update('').hide();
				$(target).removeClassName('err');
				$(target).errorState = false;
			}else{
				$(tdiv).update(transport.responseText).show();
				$(target).addClassName('err');
				$(target).errorState = true;
			}
		}
	});	
}

function checkGroupName(name, tdiv){
	var postval = "groupname=" + name;
	new Ajax.Request('/blank.php?do=group_checkGroupName', {
		method: 'post',
		paramters: postval,
  		onSuccess: function(transport) {
  			$(tdiv).update(transport.responseText);
		}
	});
}


function doState(country, tdiv){
	new Ajax.Request('/blank.php?module=main&action=doStateBox&country='+country, {
		onSuccess: function(transport) {
			//document.getElementById(tdiv).innerHTML = "done";
			$(tdiv).update(transport.responseText);
		}
	});
}
/*******************************
**	Profile System
**
******************************/

function editProfile(section, tdiv, editdiv){
	ajaxpage('blank.php?module=player&action='+section+'_edit', tdiv, "widgInit();");
	if(editdiv != undefined){
		document.getElementById(editdiv).innerHTML = "<a href=\"javascript:void(0)\" onclick=\"saveProfile('" + section + "', '" + tdiv + "', '" + editdiv +"')\">[Save]</a>";
	}else{
		//document.getElementById(editdiv).innerHTML = "";
	}
}



function saveProfile(section, tdiv, editdiv){
	ajaxSubmit(document.getElementById(section+'Form'),'blank.php?module=player&action='+section+'_process')
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			ajaxpage('blank.php?module=player&action='+section+'_show', tdiv);
			document.getElementById(editdiv).innerHTML = "<a href=\"javascript:void(0)\" onclick=\"editProfile('" + section + "', '" + tdiv + "', '" + editdiv +"')\">[Edit]</a>";
		}
	}
}

/*******************************
** Group Profile System
**
******************************/

function editGroupProfile(section, tdiv, groupid, editdiv){
	ajaxpage('blank.php?module=group&action='+section+'_edit&groupid='+ groupid, tdiv, "widgInit();");
	if(editdiv != undefined){
		document.getElementById(editdiv).innerHTML = "<a href=\"javascript:void(0)\" onclick=\"saveGroupProfile('" + section + "', '" + tdiv + "', '" + groupid + "', '" + editdiv +"')\">[Save]</a>";
	}else{
		//document.getElementById(editdiv).innerHTML = "";
	}
}


function saveGroupProfile(section, tdiv, groupid, editdiv){
	ajaxSubmit(document.getElementById(section+'Form'),'blank.php?module=group&action='+section+'_process&groupid='+ groupid)
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			ajaxpage('blank.php?module=group&action='+section+'_show&groupid='+groupid, tdiv);
			document.getElementById(editdiv).innerHTML = "<a href=\"javascript:void(0)\" onclick=\"editGroupProfile('" + section + "', '" + tdiv + "', '" + groupid +"', '"+ editdiv + "' )\">[Edit]</a>";
		}
	}
}

/**************************************
**	Invite System
**
***************************************/

function addInvite(email, resultDiv, emailListingDiv){
	var postval = "email=" + email;
	makePOSTRequest('blank.php?module=invite&action=addInvite', postval);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			if(http_request.responseText=='1'){
				/*document.getElementById(resultDiv).innerHTML = "Address Added";*/
				ajaxpage("blank.php?module=invite&action=getInviteEmails", emailListingDiv);
			}else{
				document.getElementById(resultDiv).innerHTML = http_request.responseText;
				return false;
			}
		}
	}	
}

function addGroupInvite(email, resultDiv, emailListingDiv){
	var postval = "email=" + email;
	makePOSTRequest('blank.php?module=group&action=addInvite', postval);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//if(http_request.responseText=='1'){
				/*document.getElementById(resultDiv).innerHTML = "Address Added";*/
				ajaxpage("blank.php?module=group&action=getInviteEmails", emailListingDiv);
			//}else{
				//document.getElementById(resultDiv).innerHTML = http_request.responseText;
			//	return false;
			//}
		}
	}	
}

/**************************************
**	Msg System
**
***************************************/

function getMsg(messagesDiv){
	makePOSTRequest('blank.php?module=message&action=hasMsg',"");
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			if(http_request.responseText=='1'){
				/*document.getElementById(resultDiv).innerHTML = "Address Added";*/
				ajaxpage("blank.php?module=message&action=getMsg", messagesDiv);
				loadobjs("js/msg.js");
			}else{
				document.getElementById(messagesDiv).innerHTML = http_request.responseText;
				return false;
			}
		}
	}	
}

function sendMsg(subject, body, toId, msgSentDiv){
	var postVal = "subject=" + subject + "&body=" + body + "&toId=" + toId ;
	makePOSTRequest('blank.php?module=message&action=sendMsg',postVal);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			if(http_request.responseText=='1'){
				document.getElementById(msgSentDiv).innerHTML = "Message Sent";
				//ajaxpage("blank.php?module=player&action=getMsg", msgSentDiv);
			}else{
				document.getElementById(msgSentDiv).innerHTML = http_request.responseText;
				return false;
			}
		}
	}	
}

function sendGroupMsg(subject, body, toId, msgSentDiv){
	var postVal = "subject=" + subject + "&body=" + body + "&toId=" + toId ;
	makePOSTRequest('blank.php?module=group&action=sendMsg',postVal);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//if(http_request.responseText=='1'){
				document.getElementById(msgSentDiv).innerHTML = "Message Sent";
				//ajaxpage("blank.php?module=player&action=getMsg", msgSentDiv);
			//}else{
				//document.getElementById(msgSentDiv).innerHTML = http_request.responseText;
			//	return false;
			//}
		}
	}	
}

function readMsg(msgid, msgBodyDiv, unreadMsgDiv){
	var postVal = "msgid=" + msgid  ;
	makePOSTRequest('blank.php?module=message&action=readMsg',postVal);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			if(http_request.responseText!=''){
				document.getElementById(msgBodyDiv).innerHTML = http_request.responseText;
				ajaxpage("blank.php?module=message&action=unreadMsg", unreadMsgDiv);
			}else{
				document.getElementById(msgBodyDiv).innerHTML = http_request.responseText;
				return false;
			}
		}
	}
}

/**************************************
**	Photos System 
**
***************************************/

function showAddAlbum(addAlbumDiv){
		ajaxpage("blank.php?module=photo&action=showAddAlbum", addAlbumDiv);
}
function showAddGroupAlbum(addAlbumDiv){
		ajaxpage("blank.php?module=group&action=showAddAlbum", addAlbumDiv);
}
function addAlbum(albumName, albumDescription, albumListingDiv, action_prefix, eventid, chkBox){
	if(chkBox.checked){
		var ispublic = 1;
	}else{
		var ispublic = 0;
	}
	var postVal = "albumName=" + albumName + "&albumDescription=" + albumDescription  +'&ispublic=' + ispublic  +'&eventid=' + eventid;
	makePOSTRequest('blank.php?module=photo&action='+action_prefix+'addAlbum' , postVal);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			if(http_request.responseText!='0'){
				document.getElementById(albumListingDiv).innerHTML = http_request.responseText;
				//ajaxpage("blank.php?module=" + module + "&action=getAlbums", albumListingDiv);
			}else{
				document.getElementById(albumListingDiv).innerHTML = "0";
				return false;
			}
		}
	}
	
}
/*
function addGroupAlbum(albumName, albumDescription, albumListingDiv){
	var postVal = "albumName=" + albumName + "&albumDescription=" + albumDescription;
	makePOSTRequest('blank.php?module=group&action=addAlbum',postVal);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//if(http_request.responseText=='1'){
				//document.getElementById(friendsDiv).innerHTML = "Accepted";
				ajaxpage("blank.php?module=group&action=getAlbums", albumListingDiv);
			//}else{
			//	document.getElementById(albumListingDiv).innerHTML = "ERRORRRR";
			//	return false;
			//}
		}
	}
	
}
*/
function showAddVideo(addVideoDiv){
		ajaxpage("blank.php?module=video&action=showAddVideo", addVideoDiv);
}

function showAddGroupVideo(addVideoDiv){
		ajaxpage("blank.php?module=group&action=showAddVideo", addVideoDiv);
}

function showAddMemberVideo(addVideoDiv){
		ajaxpage("blank.php?module=group&action=showAddMemberVideo", addVideoDiv);
}
/*
function deleteGroup(groupsDiv, groupid){
		"+groupid, groupsDiv);
}
*/
function addVideo(youTubeCode, videoListingDiv, eventid, chkBox){
	if(chkBox.checked){
		var ispublic = 1;
	}else{
		var ispublic = 0;
	}
	youTubeCode = escape(youTubeCode) ;
	var postVal = "youTubeCode=" + youTubeCode + "&eventid=" + eventid  + "&ispublic=" + ispublic;
	makePOSTRequest('blank.php?module=video&action=addVideo',postVal);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			document.getElementById(videoListingDiv).innerHTML = http_request.responseText;
		}
	}
	
}

function addGroupVideo(youTubeCode, videoDescription, videoListingDiv, eventid, chkBox){
	if(chkBox.checked){
		var ispublic = 1;
	}else{
		var ispublic = 0;
	}
	youTubeCode = escape(youTubeCode) ;
	var postVal = "youTubeCode=" + youTubeCode + "&videoDescription=" + videoDescription + "&eventid=" + eventid + "&ispublic=" + ispublic;
	makePOSTRequest('blank.php?module=group&action=addVideo',postVal);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//if(http_request.responseText=='1'){
				//document.getElementById(friendsDiv).innerHTML = "Accepted";
				ajaxpage("blank.php?module=group&action=getVideos", videoListingDiv);
			//}else{
			//	document.getElementById(videoListingDiv).innerHTML = "ERRORRRR";
			//	return false;
			//}
		}
	}
	
}


function addMemberVideo(youTubeCode, videoListingDiv, eventid, chkBox){
	if(chkBox.checked){
		var ispublic = 1;
	}else{
		var ispublic = 0;
	}
	youTubeCode = escape(youTubeCode) ;
	var postVal = "youTubeCode=" + youTubeCode + "eventid=" + eventid + "&ispublic=" + ispublic;
	makePOSTRequest('blank.php?module=group&action=addMemberVideo',postVal);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//if(http_request.responseText=='1'){
				//document.getElementById(friendsDiv).innerHTML = "Accepted";
				ajaxpage("blank.php?module=group&action=getMemberVideos", videoListingDiv);
			//}else{
			//	document.getElementById(videoListingDiv).innerHTML = "ERRORRRR";
			//	return false;
			//}
		}
	}
	
}

/**
COMMENTS SECTION 
**/

function showAddComment(addCommentDiv, userid){
		 ajaxpage("blank.php?module=comments&action=showAddComment&userid="+userid, addCommentDiv);
}

function showAddGroupComment(addCommentDiv, userid){
		 ajaxpage("blank.php?module=group&action=showAddGroupComment&userid="+userid, addCommentDiv);
}

function addComment(comment, toId, commentListingDiv){
	var postVal = "comment=" + comment + "&toId=" + toId;
	makePOSTRequest('blank.php?module=comments&action=postComment',postVal);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			if(http_request.responseText=='1'){
				//document.getElementById(friendsDiv).innerHTML = "Accepted";
				ajaxpage("blank.php?module=comments&action=getComments&toId=" + toId, commentListingDiv);
			}else{
				document.getElementById(commentListingDiv).innerHTML = "ERRORRRR";
				return false;
			}
		}
	}
	
}

function addGroupComment(comment, toId, commentListingDiv){
	var postVal = "comment=" + comment + "&toId=" + toId;
	makePOSTRequest('blank.php?module=group&action=postGroupComment',postVal);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			if(http_request.responseText!='0'){ 
				//document.getElementById(friendsDiv).innerHTML = "Accepted";
				ajaxpage("blank.php?module=group&action=getGroupComments&toId=" + toId, commentListingDiv);
			}else{
				document.getElementById(commentListingDiv).innerHTML = http_request.responseText;
				return false;
			}
		}
	}
	
}

function showAddCommentPrivate(addCommentDiv, toId){
		 ajaxpage("blank.php?module=comments&action=showAddCommentPrivate&toId="+toId, addCommentDiv);
}

function addCommentPrivate(comment, toId, commentListingDiv){
	var postVal = "comment=" + comment + "&toId=" + toId;
	makePOSTRequest('blank.php?module=comments&action=postComment',postVal);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			if(http_request.responseText=='1'){
				//document.getElementById(friendsDiv).innerHTML = "Accepted";
				ajaxpage("blank.php?module=comments&action=getCommentsPrivate", commentListingDiv);
			}else{
				document.getElementById(commentListingDiv).innerHTML = "ERRORRRR";
				return false;
			}
		}
	}
	
}

/**************************************
**	 Group Search System
**
***************************************/

function showGroupSearchResult(searchResultDiv, groupname){
	/*
	var param = '';
	var elem = document.getElementById('search2').elements;
	for(var i = 0; i < elem.length; i++)
	{
		if(elem[i].type=='text'){
			param += "&" + elem[i].name + "=";
			param += elem[i].value;
		}
	} 	
	*/	
	ajaxpage("blank.php?module=group&action=doSearch&groupname="+groupname, searchResultDiv);
}

/**************************************
**	Members System
**
***************************************/

function acceptMember(userid, friendsDiv){
	var postVal = "userid=" + userid ;
	makePOSTRequest('blank.php?module=group&action=acceptMember',postVal);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//if(http_request.responseText == '1'){
				//document.getElementById(friendsDiv).innerHTML = "Accepted";
				ajaxpage("blank.php?module=group&action=members", friendsDiv);
			//}else{
				//document.getElementById(friendsDiv).innerHTML = "ERROR";
				//return false;
			//}
		}
	}	
}

function rejectMember(userid, friendsDiv){
	var postVal = "userid=" + userid ;
	makePOSTRequest('blank.php?module=group&action=rejectMember',postVal);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//if(http_request.responseText=='1'){
				//document.getElementById(friendsDiv).innerHTML = "Accepted";
				ajaxpage("blank.php?module=group&action=members", friendsDiv);
			//}else{
				//document.getElementById(friendsDiv).innerHTML = "ERROR";
				//return false;
			//}
		}
	}	
}

function kickMember(userid, friendsDiv){
	var postVal = "userid=" + userid ;
	makePOSTRequest('blank.php?module=group&action=kickMember',postVal);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//if(http_request.responseText=='1'){
				//document.getElementById(friendsDiv).innerHTML = "Accepted";
				ajaxpage("blank.php?module=group&action=members", friendsDiv);
			//}else{
				//document.getElementById(friendsDiv).innerHTML = "ERROR";
				//return false;
			//}
		}
	}	
}

function banMember(userid, friendsDiv){
	var postVal = "userid=" + userid ;
	makePOSTRequest('blank.php?module=group&action=banMember',postVal);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//if(http_request.responseText=='1'){
				//document.getElementById(friendsDiv).innerHTML = "Accepted";
				ajaxpage("blank.php?module=group&action=members", friendsDiv);
			//}else{
			//	document.getElementById(friendsDiv).innerHTML = "ERROR";
			//	return false;
			//}
		}
	}	
}

function makeAdmin(userid, friendsDiv){
	alert("makeAdmin is deprecated, use ajaxPOST(..)");
}

function removeBan(userid, friendsDiv){
	var postVal = "userid=" + userid ;
	makePOSTRequest('blank.php?module=group&action=removeBan',postVal);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//if(http_request.responseText == '1'){
				//document.getElementById(friendsDiv).innerHTML = "Accepted";
				ajaxpage("blank.php?module=group&action=members", friendsDiv);
			//}else{
			//	document.getElementById(friendsDiv).innerHTML = "ERROR";
			//	return false;
			//}
		}
	}	
}

function doAchievement(id){
	var postVal = "id=" + id ;
	makePOSTRequest('blank.php?module=player&action=getAchievementValues',postVal);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			document.getElementById('ach').innerHTML = http_request.responseText;
		}
	}	
}

function toggleImage(img){ // to invert the arrow on collapsing slideDiv
 	img1 = "images/btn-adv-search1.gif";
 	img2 = "images/btn-adv-search2.gif";
	if (document[img].src.indexOf(img1)!= -1){	
	 document[img].src = img2;
	}
	else{
		document[img].src = img1;
	}
 }
 
 
/**************************************************************************************
Functions added by Peter B. to handle the video submission
***************************************************************************************/

function ajaxPOST(url, postString, containerId, command, do_not_jump){
	/* posts url, inserts response into container element,
	then runs command */
	
	new Ajax.Request(url, {
		method:'post',
		parameters:postString,	  
		evalScripts: true,
		onComplete: function(transport){
			$('containerId').update(transport.responseText);
			init_wysiwyg(containerId);
		  	aftercomp(containerId, command, do_not_jump)
	  	}
	});
}

function doAjaxSubmitClean(formid, submitPage, containerid, commands,do_not_jump){
	
	//will submit form and echo response to page
	//ajaxSubmit($(formid),submitPage);
	var str = $(formid).serialize();
	return ajaxPOST(submitPage, str, containerid, commands, do_not_jump);
	
}


function ajaxPostCommandClean(url, postString, command){
	//will submit form and call command(responseText)
	makePOSTRequest(url, postString);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			try{ command(http_request.responseText); }
			catch(err){
			}
		}
	}
}
 
 
 