/***********************************************
* 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.Updater(containerid,url, {
		  evalScripts: true,
		  method:'get',
		  onComplete : function(transport){
		  	init_wysiwyg(containerid);
		  	afterComp(containerid, commands, do_not_jump);
		  }
		});
}

function ajaxPost(url, params, containerid, commands, do_not_jump){
		/* fetches url, inserts response into container element,
	//	then runs commands. */
		new Ajax.Updater(containerid,url, {
		  evalScripts: true,
		  method:'post',
		  parameters:params,
		  onComplete : function(transport){
		  	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)){
		
		
		if(commands!=undefined){
			var cmd = commands.split(';');
			var failed = new Array();
			for ( var i in cmd ){
				if(cmd[i].trim!=''){
					try{
						//alert("Firing command " + cmd[i]);
						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');
				}
			}
		}
		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;
			var msg_count = $('notify-messages');
			var msg_count2 = $('new_messages');
			obj.each(function(item) {
				if(msg_count != null) {
					var curcount = msg_count.getElementsByTagName('a')[0].innerHTML.slice("Inbox (".length, "Inbox (".length + 1);
					msg_count.update('<a' + ((item.messageTotal > 0) ? ' class="new"' : '') + ' href="/user_home?panel=message_inbox&js=message" title="' + item.messageTotal + ' Message' + (item.messageTotal != 1 ? 's' : '') + '">Inbox (' + item.messageTotal + ')</a>');
					if(item.messageTotal > curcount) {
						new Effect.Pulsate(msg_count, { pulses: 5, duration: 1.5 });
					}
				}
				if(msg_count2 != null && item.messageTotal > 0) {
					msg_count2.update("("+item.messageTotal+" New)");
				}else{
					if(msg_count2 != null) {
						msg_count2.update('');
					}
				}
		  	});
		}
	});
}

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 = $(id);
	var obj2 = $('fade-out');
	var obj3 = $('video-display');
	if(obj3 != null && Prototype.Browser.IE) {
		oldv = obj3.innerHTML;
		obj3.update('');
		obj3.setStyle({visibility: 'hidden'});
	}
	var width = document.viewport.getWidth();
	var height = document.viewport.getHeight();
	//alert("Width: " + width + ", Height: " + height);
	//alert("Ajax-smallframe - Width: " + objs.getWidth() + ", Height: " + objs.getHeight());
	posleft = (width/2) - ((objs.getWidth())/2);
	postop = (height/2) - ((objs.getHeight())/2);
	if(posleft < 0) posleft = 0;
	if(postop < 0) postop = 0;
	//alert("Nums are " + width + "/2 - " + objs.getWidth() + "/2 and " + height + "/2 - " + objs.getHeight() + "/2; Posleft is " + posleft + "; postop is " + postop);
	objs.setStyle({left: posleft + 'px', top: postop + 'px'});
	obj2.setStyle({display: 'block', width: width + 'px', height: height + 'px'});
	if(objs.getStyle('display') != 'block') {
		objs.show();
		document.observe('keyup', function (event) {
	if(event.keyCode == Event.KEY_ESC) {
		if(objs.getStyle('display') == 'block') {
			$('ajax-smallframe-close').onclick();
			document.stopObserving('keyup');
			window.onresize = '';
		}
		return false;
	}
	
});
		window.onresize = posDiv;
	}
	return true;
}

function hideDiv(id) {
	$(id).hide();
	$('fade-out').hide();
	var obj3 = $('as_friend');
	if(obj3 != null && obj3.style) {
		obj3.setStyle({display: 'none'});
	}
	var obj4 =$('video-display');
	if(obj4 != null && Prototype.Browser.IE) {
		obj4.update(oldv);
		obj4.setStyle({visibility: 'visible'});
	}
	window.onresize = '';
}

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', false);
}

function repopulateSelect(url, selectid, add_any) {
	if(add_any == undefined) {
		add_any = true;
	}
	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){
			transport.responseJSON = eval(transport.responseText);
		  	obj = $A(transport.responseJSON);
			var select = $(selectid);
			select.innerHTML=''; /* clear old options*/
			/*var children = $A(select.options)
			children.each(function(item) {
				item.remove();
				
			});*/
			if(add_any) {
				select.insert("<option label=\"Any\" value=\"-1\">Any</option>");
			}
			obj.each(function(i) {
				select.insert("<option label=\"" + i.label + "\" value=\"" + i.value + "\">" + i.label + "</option>");
		  	});
		}
	});
}


/***********************************************
* 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.Updater(divid, url, {
		method: 'post',
		parameters: params,
		evalScripts: true,
		onSuccess: function(transport) {
			location.hash = 'null';
			init_wysiwyg(divid);
			
			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 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.Updater(divid, url, {
		method: 'get',
		evalScripts: true,
		parameters: params,
		onSuccess: function(transport) {
			location.hash = 'null';
			init_wysiwyg(divid);
			
			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
	makePOSTRequest(url, postString);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			document.getElementById(divResult).innerHTML = http_request.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 = getChildInputValues(document.getElementById(module + '-search-form'));
	var newarguments = getArgsFromQueryString(search_stuff);
	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 = createQueryStringFromArgs(backuparguments);
	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;
	makePOSTRequest('/blank.php?module=account&action=checkUserName', postval);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//document.getElementById(tdiv).innerHTML = "done";
			if(http_request.responseText == '') {
				$(tdiv).clear().hide();
				$('username').removeClassName('err');
			}else{
				$(tdiv).update(http_request.responseText).show();
				$('username').addClassName('err');
			}
		}
	}	
}

function checkEmail(name,tdiv){
	var postval = "email=" + name;
	makePOSTRequest('/blank.php?do=account_checkEmail', postval);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//document.getElementById(tdiv).innerHTML = "done";
			if(http_request.responseText == '') {
				$(tdiv).clear().hide();
				$('regi_email').removeClassName('err');
			}else{
				$(tdiv).update(http_request.responseText).show();
				$('regi_email').addClassName('err');
			}
		}
	}	
}

function checkGroupName(name, tdiv){
	var postval = "groupname=" + name;
	makePOSTRequest('/blank.php?do=group_checkGroupName', postval);
  	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//document.getElementById(tdiv).innerHTML = "done";
			document.getElementById(tdiv).innerHTML = http_request.responseText;
		}
	}	
}


function doState(country, tdiv){
	makeGETRequest('/blank.php?module=main&action=doStateBox&country='+country);
	http_request.onreadystatechange = function() {//Call a function when the state changes.
		if(http_request.readyState == 4 && http_request.status == 200) {
			//document.getElementById(tdiv).innerHTML = "done";
			document.getElementById(tdiv).innerHTML = http_request.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;
	}
 }
 function getChildInputValues(obj){
	var str = "";
	var inputs = obj.getElementsByTagName("INPUT");
	var selects = obj.getElementsByTagName("SELECT");
	var textareas = obj.getElementsByTagName("TEXTAREA");
	if(inputs.length>0){
		for (var i = 0; i < inputs.length; i++){
			if (inputs[i].type == "text" || inputs[i].type == "password" || inputs[i].type == "hidden" || inputs[i].type == "datetime" || inputs[i].type == "date" || inputs[i].type == "file" ) {
				str += inputs[i].name + "=" + escape(inputs[i].value) + "&";
			}
			if (inputs[i].type == "checkbox") {
				if (inputs[i].checked) {
				str += inputs[i].name + "=" + inputs[i].value + "&";
				} else {
					str += inputs[i].name + "=&";
				}
			}
			if (inputs[i].type == "radio") {
				if (inputs[i].checked) {
					str += inputs[i].name + "=" + inputs[i].value + "&";
				}
			}
		}
	}
	
	if(selects.length>0){
		//check if mutiples can be selected
		for (var i = 0; i < selects.length; i++){
			var tempstring = "";
			if(selects[i].multiple){
				while (selects[i].selectedIndex != -1) { 
					tempstring += selects[i].value + ";";
					selects[i].options[selects[i].selectedIndex].selected = false;
				}
			}else{
				tempstring += selects[i].value + "&";
			}
			if(tempstring != ""){
				str += selects[i].name + "=" + tempstring + "&";
			}
		}
	}
	if(textareas.length>0){
		for (var i = 0; i < textareas.length; i++){
			str += textareas[i].name + "=" + escape(textareas[i].value) + "&";
		}
	}
	return str;
}
 
 /**************************************************************************************
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.Updater(containerId, url, {
		method:'post',
		parameters:postString,	  
		evalScripts: true,
		onComplete: function(transport){
			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 = getChildInputValues($(formid));
	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){
			}
		}
	}
}
 
 
