/* QA.PHP */
function checkKeycode(e) {
	var askform = document.getElementById('askform');
	var keycode;
	if (window.event) 
		keycode = window.event.keyCode;
	else if (e) 
		keycode = e.which;
	if(keycode == 13){
		//document.askform.action = 'ask.php?t=z';
		document.askform.submit();
	}
	else{
		keychar = String.fromCharCode(keycode);
		return keychar;
	}
}
function check_submit(elementid,msg) {
	var textarea = document.getElementById(elementid);
	if(!textarea.value || textarea.value == '<br>') { 
		alert(msg); 
		textarea.focus(); 
		return false; 
	}
	else
		return true;
}
function toggleCommentModerator(divid) {
	div = document.getElementById(divid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'commentvisible' ? 'commenthidden' : 'commentvisible';
		if (curclass == 'commentvisible') {
			var els = getElementsByClassName('commentvisible');
			if (els) {
				for (el in els) {
					el = els[el];
					el.className = 'commenthidden';
				}
			}
		}
		div.className = curclass;
	}
}
function addEvent( obj, type, fn ) {
    if ( obj.attachEvent ) {
      obj['e'+type+fn] = fn;
      obj[type+fn] = function(){obj['e'+type+fn](window.event);}
      obj.attachEvent('on'+type, obj[type+fn]);
    } else {
      obj.addEventListener(type, fn, false);
    }
}

function getElementsByClassName(classname) {
	if (document.getElementsByTagName) {
		var els = document.getElementsByTagName("*");
		var c = new RegExp('/b^|' + classname + '|$/b');
		finale = new Array();
		var n=0;
		for (var i=0; i < els.length; i++) {
			if (els[i].className) {
				if(c.test(els[i].className)) {
					finale[n] = els[i];
					n++;
				}
			}
		}
		return finale;
	}
	return false;
}

function poprequest(url){
	var newwindow;
	newwindow=window.open(url,'name','height=500,width=300,left=40,top=40,toolbar=no,menubar=no,directories=no,location=no,scrollbars=yes,status=no,resizable=yes,fullscreen=no');

	if (window.focus) {
		newwindow.focus()
	}
}

function getXmlHttpRequestObject() {
  var xmlHttp;
  // this should work for all browsers except IE6 and older
  try {
    // try to create XMLHttpRequest object
    xmlHttp = new XMLHttpRequest();
  }
  catch(e) {
    // assume IE7 or older
    var XmlHttpVersions = new Array(
			"MSXML2.XMLHTTP.7.0",
			"MSXML2.XMLHTTP.6.0",
			"MSXML2.XMLHTTP.5.0",
			"MSXML2.XMLHTTP.4.0",
			"MSXML2.XMLHTTP.3.0",
			"MSXML2.XMLHTTP",
			"Microsoft.XMLHTTP");
    // try every prog id until one works
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
      try { 
        // try to create XMLHttpRequest object
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

var xmlhttp = getXmlHttpRequestObject();

function load(id,url,post) {
	msgdiv = document.getElementById(id);
	if (msgdiv) {
		msgdiv.innerHTML = 'Loading...';
	}

	var method = post ? 'POST':'GET';
	xmlhttp.open(method, url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			//getChatRequest();

			// deal with response
			var statustxt = '';
			if(xmlhttp.status == 200) {
				statustxt = xmlhttp.responseText;
			} else if(xmlhttp.status ==500) {
				//statustxt = 'Error ';
			} else {
				//statustxt = 'Unknown Response Code '+xmlhttp.status;
			}
			if (msgdiv) {
				msgdiv.innerHTML = statustxt;
					if (match = /<script[^>]*>(.*)<\/script>/gi.exec(statustxt)) {
					//alert(match[1]);
					eval(match[1]);
				}
			}
		}
	}
	if (post) {
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.send(post);
	} else {
		xmlhttp.send(null);
	}
}

function load_textarea(id,url,post) {
	msgdiv = document.getElementById(id);
	if (msgdiv) {
		//msgdiv.innerHTML = 'Loading...';
	}
	if (document.all) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		xmlhttp = new XMLHttpRequest();
	}

	xmlhttps.push(xmlhttp);
	var method = post ? 'POST':'GET';
	xmlhttp.open(method, url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			// deal with response
			var statustxt = '';
			if(xmlhttp.status == 200) {
				statustxt = xmlhttp.responseText;
			} else if(xmlhttp.status ==500) {
				//statustxt = 'Error ';
			} else {
				//statustxt = 'Unknown Response Code '+xmlhttp.status;
			}
			if (msgdiv) {
				msgdiv.value = statustxt;
				//window.scrollTo(0,0);
				if (match = /<script[^>]*>(.*)<\/script>/gi.exec(statustxt)) {
					//alert(match[1]);
					eval(match[1]);
				}
				//alert(url);
			}
		}
	}
	if (post) {
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.send(post);
	} else {
		xmlhttp.send(null)
	}
}

function winClose() {
	if (self.opener) {
		self.opener.window.focus();
	}
	window.close();
}

function moveOn() {
	if (self.opener) {
		self.setTimeout('winClose()', 5000)  
	}
}

function loginregistersubmit(form,str) {
	if (str == 'login')	{
		form.action = '/login.php';
	} 
	else{	
		form.action = '/register.php';
	}
	form.submit()
}

function toggleAnswer(atag,divid,textid,msg1,msg2) {
	div = document.getElementById(divid);
	texta = document.getElementById(textid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'answervisible' ? 'answerhidden' : 'answervisible';
		if (curclass == 'answervisible') {
			var els = getElementsByClassName('answervisible');
			if (els) {
				for (el in els) {
					el = els[el];
					el.className = 'answerhidden';
				}
			}
			div.className = curclass;
			texta.focus();
			
			oTop = div.offsetTop;
			bSize = getBrowserSize();
			sPos = getScrollXY();
			oPos = oTop - sPos.y;
			//alert('oTop = ' + oTop);
			//alert('sPos = ' + sPos.y);
			//alert('bSize = ' + bSize.y);
			if(bSize.y - oPos < 266){
				window.scrollTo(0,oTop - 200);
			}
		}
		else {
			texta.value='';
			div.className = curclass;
		}
	}
}

function toggleQuestionEditor(divid,textid) {
	div = document.getElementById(divid);
	texta = document.getElementById(textid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'editqvisible' ? 'editqhidden' : 'editqvisible';
		if (curclass == 'editqvisible') {
			div.className = curclass;
			texta.focus();
			/*
			bSize = getBrowserSize();
			leftwidth = (bSize.x - 771)/2;
			oLeft = div.offsetLeft;

			if(leftwidth > 0){
				setStyleByClass('div','editqvisible', 'left', leftwidth)
			}
			*/
		}
		else {
			div.className = curclass;
		}
	}
}

function toggleQuestionEditor2(divid,textid) {
	div = document.getElementById(divid);
	texta = document.getElementById(textid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'editq2visible' ? 'editq2hidden' : 'editq2visible';
		if (curclass == 'editq2visible') {
			div.className = curclass;
			texta.focus();
		}
		else {
			div.className = curclass;
		}
	}
}

function toggleAnswerEditor(atag,divid,textid,msg1,msg2) {
	if (atag) {
		atxt = atag.innerHTML;
		atag.innerHTML = atxt == msg1 ? msg2 : msg1;
	}
	div = document.getElementById(divid);
	texta = document.getElementById(textid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'editavisible' ? 'editahidden' : 'editavisible';
		if (curclass == 'editavisible') {
			div.className = curclass;
			texta.focus();
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleCommentEditor(divid,textid) {
	div = document.getElementById(divid);
	texta = document.getElementById(textid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'editcvisible' ? 'editchidden' : 'editcvisible';
		if (curclass == 'editcvisible') {
			div.className = curclass;
			texta.focus();
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleSubjectEditor(divid,textid) {
	div = document.getElementById(divid);
	texta = document.getElementById(textid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'editqvisible' ? 'editqhidden' : 'editqvisible';
		if (curclass == 'editqvisible') {
			div.className = curclass;
			texta.focus();
		}
		else {
			div.className = curclass;
		}
	}
}

function toggleResponseEditor(divid,textid) {
	div = document.getElementById(divid);
	texta = document.getElementById(textid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'editqvisible' ? 'editqhidden' : 'editqvisible';
		if (curclass == 'editqvisible') {
			div.className = curclass;
			texta.focus();
		} 
		else {
			div.className = curclass;
		}
	}
}
/*
function toggleGroupTitleEditor(divid,textid) {
	div = document.getElementById(divid);
	texta = document.getElementById(textid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'editgroupvisible' ? 'editgrouphidden' : 'editgroupvisible';
		if (curclass == 'editgroupvisible') {
			div.className = curclass;
			texta.focus();
		}
		else {
			div.className = curclass;
		}
	}
}
*/

function toggleRichTextEditor(divid,richtexteditordiv,script,width,height,resource_type,resource_id,page,uploaderdiv,editing_text) {
	var xmlhttp = getXmlHttpRequestObject();
	var div = document.getElementById(divid);
	var richtexteditordiv = document.getElementById(richtexteditordiv);
	//alert(escape(editing_text));

	if (div) {
		curclass = div.className;
		curclass = curclass == 'editvisible' ? 'edithidden' : 'editvisible';
		if (curclass == 'editvisible' && richtexteditordiv) {
			if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
				xmlhttp.open('GET','/res/richtexteditor_ajax.php?script=' + script + '&width=' + width + '&height=' + height + '&resource_type=' + resource_type + '&resource_id=' + resource_id + '&page=' + page + '&uploaderdiv=' + uploaderdiv + '&editing_text=' + escape(editing_text), true);
				//alert(page);
				
				richtexteditordiv.innerHTML = '<span style=\"color:#ffffff\">Loading...</span>';

				xmlhttp.onreadystatechange = function(){
					if (xmlhttp.readyState == 4) {
						if (xmlhttp.status==200){
							richtexteditordiv.innerHTML = xmlhttp.responseText;
							//alert(richtexteditordiv.innerHTML);
						}
						else {
							alert("Problem retrieving data:" + xmlhttp.statusText)
						}
					}
				}
				xmlhttp.send(null);
			}
		} 
		div.className = curclass;
	}
}

/*
function toggleRichTextEditorFF(divid,editdiv) {
	var div = document.getElementById(divid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'editvisible' ? 'editffhidden' : 'editvisible';
		if (curclass == 'editvisible') {
			enableDesignMode(editdiv,divid);
		}
		div.className = curclass;
	}
}
*/

function toggleRichTextEditorFF(divid) {
	var div = document.getElementById(divid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'editvisible' ? 'edithidden' : 'editvisible';
		div.className = curclass;
	}
}

function toggleSectionEditor(divid,textid) {
	div = document.getElementById(divid);
	texta = document.getElementById(textid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'editsectionvisible' ? 'editsectionhidden' : 'editsectionvisible';
		if (curclass == 'editsectionvisible') {
			div.className = curclass;
			texta.focus();
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleSearchIntLink(divid,query,ignore,listid,contentid) {
	var xmlhttp = getXmlHttpRequestObject();
	var div = document.getElementById(divid);

	if (div) {
		curclass = div.className;
		curclass = curclass == 'searchlinkvisible' ? 'searchlinkhidden' : 'searchlinkvisible';
		if (curclass == 'searchlinkvisible') {
			div.className = curclass;
			if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
				xmlhttp.open('GET','/modules/listsearchqs.php?query=' + query + '&ignore=' + ignore,true);
				
				var related = document.getElementById(listid);
				related.innerHTML = '<span style=\"color:#ffffff\">Loading...</span>';

				xmlhttp.onreadystatechange = function(){
					if (xmlhttp.readyState == 4) {
						if (xmlhttp.status==200){
							related.innerHTML = '';
							var str = xmlhttp.responseText.split("&iexcl;");
							//alert(str);
							for(i=0; i < str.length - 1; i++) {
								var substr = str[i].split("&plusmn;");
								var relatedqs = '<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin-bottom: 10px;\">';
								relatedqs += '<tr><td width=\"130\" style="color:#ffffff">';
								relatedqs += '<input type=\"radio\" id=\"radioq'+contentid+'\" name=\"radioq'+contentid+'\" value=\"'+ substr[0]+'\">&nbsp;'+ substr[0]+'</td>';
								relatedqs += '<td><textarea id=\"text'+substr[0]+'\" name=\"text'+substr[0]+'\" style=\"width:220px;height:35px;\">'+substr[1]+'</textarea></td>';
								relatedqs += '</tr>';
								relatedqs += '</table>';
								related.innerHTML += relatedqs;
							}
							//alert(related.innerHTML);
						}
						else {
							alert("Problem retrieving XML data:" + xmlhttp.statusText)
						}
					}
				}
				xmlhttp.send(null);
			}
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleIntLink(divid) {
	div = document.getElementById(divid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'intlinkvisible' ? 'intlinkhidden' : 'intlinkvisible';
		if (curclass == 'intlinkvisible') {
			div.className = curclass;
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleIntLink2(divid) {
	div = document.getElementById(divid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'intlink2visible' ? 'intlink2hidden' : 'intlink2visible';
		if (curclass == 'intlink2visible') {
			div.className = curclass;
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleExtLink(divid,textid) {
	var div = document.getElementById(divid);
	var texta = document.getElementById(textid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'extlinkvisible' ? 'extlinkhidden' : 'extlinkvisible';
		if (curclass == 'extlinkvisible') {
			div.className = curclass;
			texta.focus();
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleExtLink2(divid,textid) {
	var div = document.getElementById(divid);
	var texta = document.getElementById(textid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'extlink2visible' ? 'extlink2hidden' : 'extlink2visible';
		if (curclass == 'extlink2visible') {
			div.className = curclass;
			texta.focus();
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleVideoLink(divid) {
	var div = document.getElementById(divid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'extlinkvisible' ? 'extlinkhidden' : 'extlinkvisible';
		if (curclass == 'extlinkvisible') {
			div.className = curclass;
		} 
		else {
			div.className = curclass;
		}
	}
}

function showOverlay(){
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);

	var objOverlay = document.getElementById('overlay');

	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';
}

function hideOverlay(){
	var objOverlay = document.getElementById('overlay');
	objOverlay.style.display = 'none';
}
function toggleAvatarUploader(uploaderdivid,iframedivid,newuploader) {
	var udiv = document.getElementById(uploaderdivid);
	var idiv = document.getElementById(iframedivid);
	
	if (udiv) {
		ucurclass = udiv.className;
		ucurclass = ucurclass == 'qa_imageuploadervisible' ? 'qa_imageuploaderhidden' : 'qa_imageuploadervisible';
		udiv.className = ucurclass;

		if (idiv) {
			var iframewidth = 640;
			var iframeheight = 480;		

			icurclass = idiv.className;
			icurclass = icurclass == 'qa_loadervisible' ? 'qa_loaderhidden' : 'qa_loadervisible';
			idiv.className = icurclass;
		}
	}
}

/*
function toggleImageUploader(uploaderdivid,iframedivid,newuploader) {
	var udiv = document.getElementById(uploaderdivid);
	var idiv = document.getElementById(iframedivid);
	var arrayBrowserSize = getBrowserSize();
	var arrayPageScroll = getPageScroll();

	if (udiv) {
		var uploaderBgheight = 140;		
		var uploaderBgwidth = 400;

		ucurclass = udiv.className;
		ucurclass = ucurclass == 'imageuploadervisible' ? 'imageuploaderhidden' : 'imageuploadervisible';
		//alert(ucurclass);
		if (ucurclass == 'imageuploadervisible') {
			udiv.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - uploaderBgheight) / 2) + 'px');
			udiv.style.left = (((arrayBrowserSize.x - uploaderBgwidth) / 2) + 'px');
			alert(udiv.style.top);
			alert(udiv.style.left);
			udiv.style.display = 'block';
		}
		udiv.className = ucurclass;

		if (idiv) {
			var iframeheight = 620;		
			var iframewidth = 800;

			icurclass = idiv.className;
			icurclass = icurclass == 'loadervisible' ? 'loaderhidden' : 'loadervisible';
			if (icurclass == 'loadervisible') {
				idiv.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 10 - iframeheight) / 2) + 'px');
				idiv.style.left = (((arrayPageSize[0] - 10 - iframewidth) / 2) + 'px');
				idiv.style.display = 'block';
				idiv.className = icurclass;
			}
			else{
				idiv.className = icurclass;
				if(udiv){
					//hideOverlay();
					ucurclass = 'imageuploadervisible';
					udiv.className = ucurclass;
				}
			}
		}
	}
}
*/
function toggleImageUploader(uploaderdivid,iframedivid) {
	var udiv = document.getElementById(uploaderdivid);
	var idiv = document.getElementById(iframedivid);

	if (udiv) {
		ucurclass = udiv.className;
		ucurclass = ucurclass == 'imageuploadervisible' ? 'imageuploaderhidden' : 'imageuploadervisible';
		if (ucurclass == 'imageuploadervisible') {
			oTop = udiv.offsetTop;
			bSize = getBrowserSize();
			sPos = getScrollXY();
			oPos = oTop - sPos.y;
			//alert('oTop = ' + oTop);
			//alert('sPos = ' + sPos.y);
			//alert('bSize = ' + bSize.y);
			if(bSize.y - oPos < 300){
				window.scrollTo(0,oTop - 300);
			}
		}

		udiv.className = ucurclass;

		if (idiv) {
			icurclass = idiv.className;
			icurclass = icurclass == 'loadervisible' ? 'loaderhidden' : 'loadervisible';
			idiv.className = icurclass;
		}
	}
}

function toggleQAImageUploader(uploaderdivid,iframedivid,newuploader) {
	var udiv = document.getElementById(uploaderdivid);
	var idiv = document.getElementById(iframedivid);
	//console.log(uploaderdivid);
	//console.log(udiv.className);

	if (udiv) {
		ucurclass = udiv.className;
		ucurclass = ucurclass == 'qa_imageuploadervisible' ? 'qa_imageuploaderhidden' : 'qa_imageuploadervisible';
		udiv.className = ucurclass;

		if (idiv) {
			var iframewidth = 640;
			var iframeheight = 480;		

			icurclass = idiv.className;
			icurclass = icurclass == 'qa_loadervisible' ? 'qa_loaderhidden' : 'qa_loadervisible';
			idiv.className = icurclass;
		}
	}
}

function toggleQAImageUploader2(uploaderdivid,iframedivid,newuploader) {
	var udiv = document.getElementById(uploaderdivid);
	var idiv = document.getElementById(iframedivid);

	if (udiv) {
		ucurclass = udiv.className;
		ucurclass = ucurclass == 'qa_imageuploadervisible2' ? 'qa_imageuploaderhidden2' : 'qa_imageuploadervisible2';
		udiv.className = ucurclass;

		if (idiv) {
			icurclass = idiv.className;
			icurclass = icurclass == 'qa_loadervisible' ? 'qa_loaderhidden' : 'qa_loadervisible';
			idiv.className = icurclass;
		}
	}
}

function toggleFileUploader(divid) {
	div = document.getElementById(divid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'imageuploadervisible' ? 'imageuploaderhidden' : 'imageuploadervisible';
		if (curclass == 'imageuploadervisible') {
			div.className = curclass;
		}
		else {
			div.className = curclass;
		}
	}
}

function toggleSearch(divid) {
	div = document.getElementById(divid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'intlinkvisible' ? 'intlinkhidden' : 'intlinkvisible';
		if (curclass == 'intlinkvisible') {
			div.className = curclass;
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleSearchQuestions(divid,query,ignore,listid,contentid) {
	var xmlhttp = getXmlHttpRequestObject();
	var div = document.getElementById(divid);
	url = '/modules/listsearchquestions.php?query=' + query + '&ignore=' + ignore;
	if (div) {
		curclass = div.className;
		curclass = curclass == 'searchlinkvisible' ? 'searchlinkhidden' : 'searchlinkvisible';
		if (curclass == 'searchlinkvisible') {
			div.className = curclass;
			if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
				xmlhttp.open('GET','/modules/listsearchquestions.php?query=' + query + '&ignore=' + ignore,true);
				
				var related = document.getElementById(listid);
				related.innerHTML = '<span style=\"color:#ffffff\">Loading...</span>';

				xmlhttp.onreadystatechange = function(){
					if (xmlhttp.readyState == 4) {
						if (xmlhttp.status==200){
							related.innerHTML = xmlhttp.responseText;
						}
						else {
							alert("Problem retrieving XML data:" + xmlhttp.statusText)
						}
					}
				}
				xmlhttp.send(null);
			}
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleSearchDebatesOrGroups(divid,type,query,listid) {
	var xmlhttp = getXmlHttpRequestObject();
	var div = document.getElementById(divid);

	if (div) {
		curclass = div.className;
		curclass = curclass == 'searchlinkvisible' ? 'searchlinkhidden' : 'searchlinkvisible';
		if (curclass == 'searchlinkvisible') {
			div.className = curclass;
			if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
				xmlhttp.open('GET','/modules/listsearchdebatesorgroups.php?type=' + type + '&query=' + query,true);
				
				var listd = document.getElementById(listid);
				listd.innerHTML = '<span style=\"color:#ffffff\">Loading...</span>';

				xmlhttp.onreadystatechange = function(){
					if (xmlhttp.readyState == 4) {
						if (xmlhttp.status==200){
							listd.innerHTML = xmlhttp.responseText;
						}
						else {
							alert("Problem retrieving XML data:" + xmlhttp.statusText)
						}
					}
				}
				xmlhttp.send(null);
			}
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleAjaxAllGroups(listid,display_by,page) {
	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
		xmlhttp.open('GET','/modules/listallgroups.php?display_by=' + display_by + '&page=' + page,true);
		
		var listd = document.getElementById(listid);

		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status==200){
					listd.innerHTML = xmlhttp.responseText;
				}
				else {
					alert("Problem retrieving XML data:" + xmlhttp.statusText)
				}
			}
		}
		xmlhttp.send(null);
	}
}

function toggleAjaxAllThreads(listid,grouppage,page) {
	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
		xmlhttp.open('GET','/modules/listgroupthreads.php?grouppage=' + grouppage + '&p=' + page,true);
		
		var listd = document.getElementById(listid);

		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status==200){
					listd.innerHTML = xmlhttp.responseText;
				}
				else {
					alert("Problem retrieving XML data:" + xmlhttp.statusText)
				}
			}
		}
		xmlhttp.send(null);
	}
}

function toggleAjaxNewDebates(listid,page) {
	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
		xmlhttp.open('GET','/modules/listnewdebates.php?page=' + page,true);
		
		var listd = document.getElementById(listid);

		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status==200){
					listd.innerHTML = xmlhttp.responseText;
				}
				else {
					alert("Problem retrieving XML data:" + xmlhttp.statusText)
				}
			}
		}
		xmlhttp.send(null);
	}
}

function toggleAjaxSearchedDebates(listid,zone_id,page) {
	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
		xmlhttp.open('GET','/modules/listsearcheddebates.php?page=' + page + '&zone_id=' + zone_id,true);
		
		var listd = document.getElementById(listid);

		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status==200){
					listd.innerHTML = xmlhttp.responseText;
				}
				else {
					alert("Problem retrieving XML data:" + xmlhttp.statusText)
				}
			}
		}
		xmlhttp.send(null);
	}
}

function toggleAjaxSearchedGroups(listid,zone_id,page) {
	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
		xmlhttp.open('GET','/modules/listsearchedgroups.php?page=' + page + '&zone_id=' + zone_id,true);
		
		var listd = document.getElementById(listid);

		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status==200){
					listd.innerHTML = xmlhttp.responseText;
				}
				else {
					alert("Problem retrieving XML data:" + xmlhttp.statusText)
				}
			}
		}
		xmlhttp.send(null);
	}
}

function toggleAjaxAllDebates(listid,display_by,page) {
	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
		xmlhttp.open('GET','/modules/listalldebates.php?display_by=' + display_by + '&page=' + page,true);
		
		var listd = document.getElementById(listid);

		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status==200){
					listd.innerHTML = xmlhttp.responseText;
				}
				else {
					alert("Problem retrieving XML data:" + xmlhttp.statusText)
				}
			}
		}
		xmlhttp.send(null);
	}
}

function makeItMyFavourite(div_id,type,resource,action) {
	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
		xmlhttp.open('GET','/modules/listmyfavdebatesorgroups.php?type=' + type + '&resource=' + resource + '&action=' + action,true);
		
		var div_id = document.getElementById(div_id);
		//listd.innerHTML = 'Loading...';

		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status==200){
					div_id.innerHTML = xmlhttp.responseText;
				}
				else {
					alert("Problem retrieving XML data:" + xmlhttp.statusText)
				}
			}
		}
		xmlhttp.send(null);
	}
}

function makeItRelatedGroup(div_id,grouppage,resource,action) {
	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
		xmlhttp.open('GET','/modules/listrelatedgroups.php?grouppage=' + grouppage + '&resource=' + resource + '&action=' + action,true);
		
		var div_id = document.getElementById(div_id);
		//listd.innerHTML = 'Loading...';

		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status==200){
					div_id.innerHTML = xmlhttp.responseText;
				}
				else {
					alert("Problem retrieving XML data:" + xmlhttp.statusText)
				}
			}
		}
		xmlhttp.send(null);
	}
}

function selectText(textid) {
	var ie = (document.all) ? true : false;
	var texta = document.getElementById(textid);

	if (!texta) return false;
	txtstr = new String(texta.value);

	if(ie){
		if(document.selection){ 
			var range = document.selection.createRange(); 
			var stored_range = range.duplicate(); 
			stored_range.moveToElementText( texta ); 
			stored_range.setEndPoint( 'EndToEnd', range ); 
			texta.selectionStart = stored_range.text.length - range.text.length; 
			texta.selectionEnd = texta.selectionStart + range.text.length; 
		}
		else{
			return;
		}
	}
	else{
		if (!(txtstr && texta.selectionEnd)) {
			return;
		}
	}

	txtstr = txtstr.substring(texta.selectionStart,texta.selectionEnd);

	return txtstr;
}

function getBrowserSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
  } 
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return {x:myWidth, y:myHeight};
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } 
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return {x:scrOfX, y:scrOfY};
}

function setStyleByClass(t,c,p,v){
	var ie = (document.all) ? true : false;
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

function getPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function toggleExtLinkForComment(divid) {
	var div = document.getElementById(divid);
	if (div) {
		curclass = div.className;
		curclass = curclass == 'commentextlinkvisible' ? 'extlinkhidden' : 'commentextlinkvisible';
		if (curclass == 'commentextlinkvisible') {
			div.className = curclass;
		} 
		else {
			div.className = curclass;
		}
	}
}

function toggleShare(iframedivid,resource_type,resource_id) {
	arrayPageScroll = getPageScroll();
	arrayPageSize = getPageSize();
	var idiv = document.getElementById(iframedivid);

	if (idiv) {
		var iframeheight = 490;		
		var iframewidth = 500;
	
		icurclass = idiv.className;
		icurclass = icurclass == 'sharevisible' ? 'sharehidden' : 'sharevisible';
	
		if (icurclass == 'sharevisible') {
			//showOverlayShare();
			idiv.src = '/share_it1.php?resource_id='+resource_id+'&resource_type='+resource_type;
			//alert(arrayPageScroll[1]+', '+arrayPageSize[1]+', '+arrayPageSize[2])
			idiv.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 200 - iframeheight) / 2) + 'px');
			idiv.style.left = (((arrayPageSize[0] - 200 - iframewidth) / 2) + 'px');
			idiv.style.display = 'block';
			idiv.className = icurclass;
			//alert(arrayPageSize[0]+' : '+arrayPageSize[1]+' : '+arrayPageSize[2]+' : '+arrayPageSize[3]);
		}
		else{
			//hideOverlayShare();
			idiv.className = icurclass;
		}
	}
}

function loading() {
	arrayPageScroll = getPageScroll();
	arrayPageSize = getPageSize();

	if ($('img.loading_img').is(':hidden')) {
		var divheight = 22;		
		var divwidth = 126;
	
		//alert(arrayPageScroll[1]+', '+arrayPageSize[1]+', '+arrayPageSize[2])
		div_top = (arrayPageScroll[1] + ((arrayPageSize[3] - 300 - divheight) / 2) + 'px');
		$('img.loading_img').css('top',div_top);
		div_left = (((arrayPageSize[0] - 200 - divwidth) / 2) + 'px');
		$('img.loading_img').css('left',div_left);
		$('img.loading_img').css('display','block');
		$('img.loading_img').show();
		
		//alert(arrayPageSize[0]+' : '+arrayPageSize[1]+' : '+arrayPageSize[2]+' : '+arrayPageSize[3]);
	}
	else{
		//hideOverlayShare();
		$('img.loading_img').hide();
	}
}
function cat_pop_up(data) {
	arrayPageScroll = getPageScroll();
	arrayPageSize = getPageSize();

	if ($('div.cat_pop_up').is(':hidden')) {
		var divheight = 300;		
		var divwidth = 850;
	
		$('div.cat_pop_up .content').html(data);
		//alert(arrayPageScroll[1]+', '+arrayPageSize[1]+', '+arrayPageSize[2])
		div_top = (arrayPageScroll[1] + ((arrayPageSize[3] - 300 - divheight) / 2) + 'px');
		$('div.cat_pop_up').css('top',div_top);
		div_left = (((arrayPageSize[0] - 225 - divwidth) / 2) + 'px');
		$('div.cat_pop_up').css('left',div_left);
		$('div.cat_pop_up').css('display','block');
		$('img.loading_img').hide();
		$('div.cat_pop_up').fadeIn(1000);
		
		//alert(arrayPageSize[0]+' : '+arrayPageSize[1]+' : '+arrayPageSize[2]+' : '+arrayPageSize[3]);
	}
	else{
		//hideOverlayShare();
		$('div.cat_pop_up').fadeOut(1000);
	}
}
function list_pop_up(data) {
	arrayPageScroll = getPageScroll();
	arrayPageSize = getPageSize();

	if ($('div.list_pop_up').is(':hidden')) {
		var divheight = 300;		
		var divwidth = 500;
	
		$('div.list_pop_up').html(data);
		//alert(arrayPageScroll[1]+', '+arrayPageSize[1]+', '+arrayPageSize[2])
		div_top = (arrayPageScroll[1] + ((arrayPageSize[3] - 300 - divheight) / 2) + 'px');
		$('div.list_pop_up').css('top',div_top);
		div_left = (((arrayPageSize[0] - 500 - divwidth) / 2) + 'px');
		$('div.list_pop_up').css('left',div_left);
		$('div.list_pop_up').css('display','block');
		$('img.loading_img').hide();
		$('div.list_pop_up').fadeIn(1000);
		
		//alert(arrayPageSize[0]+' : '+arrayPageSize[1]+' : '+arrayPageSize[2]+' : '+arrayPageSize[3]);
	}
	else{
		//hideOverlayShare();
		$('div.list_pop_up').fadeOut(1000);
	}
}
function error_pop_up(data) {
	arrayPageScroll = getPageScroll();
	arrayPageSize = getPageSize();

	if ($('div#error_pop_up').is(':hidden')) {
		var divheight = 200;		
		var divwidth = 350;
		if(data) {
			$('div.cat_pop_up .content').html(data);
		}
		//alert(arrayPageScroll[1]+', '+arrayPageSize[1]+', '+arrayPageSize[2])
		div_top = (arrayPageScroll[1] + ((arrayPageSize[3] - 300 - divheight) / 2) + 'px');
		$('div#error_pop_up').css('top',div_top);
		div_left = (((arrayPageSize[0] - 225 - divwidth) / 2) + 'px');
		$('div#error_pop_up').css('left',div_left);
		$('div#error_pop_up').css('display','block');
		$('img.loading_img').hide();
		$('div#error_pop_up').fadeIn(1000);
		
		//alert(arrayPageSize[0]+' : '+arrayPageSize[1]+' : '+arrayPageSize[2]+' : '+arrayPageSize[3]);
	}
	else{
		//hideOverlayShare();
		$('div.pop_up').fadeOut(1000);
	}
}
function pop_up(data,head_title) {
	arrayPageScroll = getPageScroll();
	arrayPageSize = getPageSize();

	if ($('div.pop_up').is(':hidden')) {
		var divheight = 200;		
		var divwidth = 350;
	
		$('td.pop_up_content').html(data);
		if(head_title)
			$('div#pop_up div.head').html(head_title);
		//alert(arrayPageScroll[1]+', '+arrayPageSize[1]+', '+arrayPageSize[2])
		div_top = (arrayPageScroll[1] + ((arrayPageSize[3] - 300 - divheight) / 2) + 'px');
		$('div.pop_up').css('top',div_top);
		div_left = (((arrayPageSize[0] - 200 - divwidth) / 2) + 'px');
		$('div.pop_up').css('left',div_left);
		$('div.pop_up').css('display','block');
		$('img.loading_img').hide();
		$('div.pop_up').fadeIn(1000);
		
		//alert(arrayPageSize[0]+' : '+arrayPageSize[1]+' : '+arrayPageSize[2]+' : '+arrayPageSize[3]);
	}
	else{
		//hideOverlayShare();
		$('div.pop_up').fadeOut(1000);
	}
}
/*
function toggleShare(resource_type,resource_id) {
	$(document).ready(function(){
		if($('#share_it').is(':hidden')){
			$('#share_it .content').load('/share_it.php?resource_type='+resource_type+'&resource_id='+resource_id)
			$('#share_it').fadeIn();
		}else{
			$('#share_it').fadeOut();
		}
	});
}*/

function setAdCode(divid, adcode) {
	var divid = document.getElementById(divid);
	divid.innerHTML = adcode;

	return true;
}
function toggleAjaxMyShouts(username,listid,page) {
	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
		xmlhttp.open('GET','/modules/listmyshouts.php?username=' + username + '&page=' + page,true);
		
		var listd = document.getElementById(listid);
		//listd.innerHTML = 'Loading...';

		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status==200){
					listd.innerHTML = xmlhttp.responseText;
				}
				else {
					alert("Problem retrieving XML data:" + xmlhttp.statusText)
				}
			}
		}
		xmlhttp.send(null);
	}
}

function actionOnQuestion(div_id,type,resource_id,action,page) {
	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
		alert(div_id + ' ' +type + ' ' + resource_id + ' ' + action + ' ' + page);
		xmlhttp.open('GET','/modules/'+type+'.php?resource_id=' + resource_id + '&action=' + action + 'page' + page,true);
		
		var div_id = document.getElementById(div_id);
		//listd.innerHTML = 'Loading...';

		xmlhttp.onreadystatechange = function(){
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status==200){
					div_id.innerHTML = xmlhttp.responseText;
				}
				else {
					alert("Problem retrieving XML data:" + xmlhttp.statusText)
				}
			}
		}
		xmlhttp.send(null);
	}
}

function changeTo(resource,tadivid,divid,aid,regex,misspell,suggested) {
	//alert(txtid);
	var text = document.getElementById(tadivid).innerHTML;
	var textarea = $('textarea#'+resource).attr('value');//alert(text);
	if(misspell!=suggested){
		if (text.match(regex)) {
			document.getElementById(tadivid).innerHTML = text.replace(regex,suggested);
			document.getElementById(resource).value = textarea.replace(regex,suggested);

			$('#'+aid).attr("class","suggested");
		}
	}
	else{
		if (text.match(regex)) {
			document.getElementById(tadivid).innerHTML = text.replace(regex,suggested);
			document.getElementById(resource).value = textarea.replace(regex,suggested);

			$('#'+aid).attr("class","");
		}
	}
} 

function spellSuggestion(resource,tadivid,divid,aid,misspell) {
	var div = document.getElementById(divid);
	var changed_spell = document.getElementById(aid).innerHTML;

	if (div) {
		curclass = div.className;
		curclass = curclass == 'spellsuggestion_visible' ? 'spellsuggestion_hidden' : 'spellsuggestion_visible';
		if (curclass == 'spellsuggestion_visible') {
			div.className = curclass;
			div.innerHTML = '<span style=\"color:#blue\">Loading...</span>';
			$('#'+divid).load('/modules/listspellingsuggestions.php', {resource:resource,tadivid:tadivid,divid:divid,aid:aid,misspell:misspell,changed_spell:changed_spell});
		} 
		else {
			div.className = curclass;
		}
	}
}

/*
function spellSuggestion(resource,tadivid,divid,aid,misspell) {
	var xmlhttp = getXmlHttpRequestObject();
	var div = document.getElementById(divid);
	var changed_spell = document.getElementById(aid).innerHTML;
	//alert(changed_spell);

	if (div) {
		curclass = div.className;
		curclass = curclass == 'spellsuggestion_visible' ? 'spellsuggestion_hidden' : 'spellsuggestion_visible';
		//curclass = 'spellsuggestion_visible';
		if (curclass == 'spellsuggestion_visible') {
			div.className = curclass;
			if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
				xmlhttp.open('GET','/modules/listspellingsuggestions.php?resource='+resource+'&tadivid=' + tadivid + '&divid=' + divid + '&aid=' + aid + '&misspell=' + misspell + '&changed_spell=' + changed_spell,true);
				div.innerHTML = '<span style=\"color:#blue\">Loading...</span>';
				xmlhttp.onreadystatechange = function(){
					if (xmlhttp.readyState == 4) {
						if (xmlhttp.status==200){
							div.innerHTML = xmlhttp.responseText;
						}
						else {
							alert("Problem retrieving XML data:" + xmlhttp.statusText)
						}
					}
				}
				xmlhttp.send(null);
			}
		} 
		else {
			div.className = curclass;
		}
	}
}
*/

function changeTo_RTE(resource,tadivid,divid,aid,regex,misspell,suggested,rteid) {
	//alert(rteid);
	var text = document.getElementById(tadivid).innerHTML;
	if(document.all) {
		var textarea = $('div#'+rteid).html();
	}
	else{
		var textarea = $('iframe#'+rteid).contents().find('body').html();
	}

	if(misspell!=suggested){
		if (text.match(regex)) {
			document.getElementById(tadivid).innerHTML = text.replace(regex,suggested);
			if(document.all) {
				document.getElementById(rteid).innerHTML = textarea.replace(regex,suggested);
			}
			else{
				document.getElementById(rteid).contentWindow.document.body.innerHTML = textarea.replace(regex,suggested);
			}
			$('#'+aid).attr("class","suggested");
		}
	}
	else{
		if (text.match(regex)) {
			document.getElementById(tadivid).innerHTML = text.replace(regex,suggested);
			if(document.all) {
				document.getElementById(rteid).innerHTML = textarea.replace(regex,suggested);
			}
			else{
				document.getElementById(rteid).contentWindow.document.body.innerHTML = textarea.replace(regex,suggested);
			}
			$('#'+aid).attr("class","");
		}
	}
} 

///*
function spellSuggestion_RTE(resource,tadivid,divid,aid,misspell,rteid) {
	var div = document.getElementById(divid);
	var changed_spell = document.getElementById(aid).innerHTML;

	if (div) {
		curclass = div.className;
		curclass = curclass == 'spellsuggestion_visible' ? 'spellsuggestion_hidden' : 'spellsuggestion_visible';
		if (curclass == 'spellsuggestion_visible') {
			div.className = curclass;
			div.innerHTML = '<span style=\"color:#blue\">Loading...</span>';
			$('#'+divid).load('/modules/listspellingsuggestions_rte.php', {resource:resource,tadivid:tadivid,divid:divid,aid:aid,misspell:misspell,changed_spell:changed_spell,rteid:rteid});
		} 
		else {
			div.className = curclass;
		}
	}
}
//*/
/*
function spellSuggestion_RTE(resource,tadivid,divid,aid,misspell,rteid) {
	//alert(rteid);
	var xmlhttp = getXmlHttpRequestObject();
	var div = document.getElementById(divid);
	var changed_spell = document.getElementById(aid).innerHTML;
	//alert(changed_spell);

	if (div) {
		curclass = div.className;
		curclass = curclass == 'spellsuggestion_visible' ? 'spellsuggestion_hidden' : 'spellsuggestion_visible';
		//curclass = 'spellsuggestion_visible';
		if (curclass == 'spellsuggestion_visible') {
			div.className = curclass;
			if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
				xmlhttp.open('GET','/modules/listspellingsuggestions_rte.php?resource='+resource+'&tadivid=' + tadivid + '&divid=' + divid + '&aid=' + aid + '&misspell=' + misspell + '&changed_spell=' + changed_spell + '&rteid=' + rteid,true);
				div.innerHTML = '<span style=\"color:#blue\">Loading...</span>';
				xmlhttp.onreadystatechange = function(){
					if (xmlhttp.readyState == 4) {
						if (xmlhttp.status==200){
							div.innerHTML = xmlhttp.responseText;
						}
						else {
							alert("Problem retrieving XML data:" + xmlhttp.statusText)
						}
					}
				}
				xmlhttp.send(null);
			}
		} 
		else {
			div.className = curclass;
		}
	}
}
*/

function hideSpellingSuggestions(divid) {
	var div = document.getElementById(divid);
	if (div) {
		div.className = 'spellsuggestion_hidden';
	}
}

function hideAllSpellingSuggestions(tadivid) {
	var text = document.getElementById(tadivid).innerHTML;
	var regex = /spellsuggestion_visible/g;
	if (text.match(/spellsuggestion_visible/g)) {
		document.getElementById(tadivid).innerHTML = text.replace(regex,"spellsuggestion_hidden ");
	}
}

function character_count(textarea,displayobj,max_count) {
	var textarea_value = textarea.value;
	var max_count = max_count ? max_count : 500;
	var character_count = (max_count - textarea_value.length);
	var character_or_characters = "";
	if(character_count == 1)
		character_or_characters = "character";
	else
		character_or_characters = "characters";
	
	if(character_count < 0)
		character_count = 0;
		
	if(textarea.value.length > max_count)
		textarea.value = textarea.value.substring(0, max_count);

	displayobj.innerHTML = character_count + character_or_characters + ' left';
}

var badRatingReq = getXmlHttpRequestObject();
function toggleResourceUser(divid,remote_user,resource_user,datefrom,dateto,goodorbad,action) {
	div = document.getElementById(divid);
	if (div) {
		div.className = div.className == 'resource_users_visible' ? 'resource_users_hidden' : 'resource_users_visible';
		if(action) div.className = 'resource_users_visible';
		if (div.className == 'resource_users_visible') {
			if (badRatingReq.readyState == 4 || badRatingReq.readyState == 0) {
				badRatingReq.open('GET','/modules/listbadratingsgroupbyuser.php?_inline=1&remote_user='+remote_user+'&resource_user='+resource_user+'&datefrom='+datefrom+'&dateto='+dateto+'&goodorbad='+goodorbad+'&action='+action,true);
				badRatingReq.onreadystatechange = function(){
					if (badRatingReq.readyState == 4){
						div.innerHTML = '';
						if (badRatingReq.status==200){
							div.innerHTML = badRatingReq.responseText;
						}
						else {
							alert("Problem retrieving XML data:" + badRatingReq.statusText)
						}
					}
				}
				badRatingReq.send(null);
			}
		} 
	}
}
