//2ndhub javascript functions 
//copyright MM 2010

var c=0;
var t;
var timer_is_on=0;

var ftc=0;
var ft;
var flash_title_on = 0;

var doc_title = document.title;
var flash_title = "";

var windowstatus = 1;

var userAgent = navigator.userAgent.toLowerCase();
var pattern = /msie/;
var pattern6 = /msie 6.0/;
var pattern7 = /msie 7.0/;
var firefoxpattern = /firefox/;

if(pattern.test(userAgent)){
	document.onfocusout = function(){ setwindowstatus("blurry"); }
	document.onfocusin = function(){ setwindowstatus("focus"); }	
}else{
	window.onblur = function(){ setwindowstatus("blurry"); }
	window.onfocus = function(){ setwindowstatus("focus"); }
}

function setwindowstatus(word){
	if(word == "blurry"){
		windowstatus = 0;
	}else if(word == "focus"){
		windowstatus = 1;
		//flashTitle();
	}
}

function flashCount(){
	ftc=ftc+1;
	
	if(ftc%2 == 0){
		document.title = doc_title;
		dur = 500;
	}else{
		document.title = flash_title;
		dur = 1500; //1500 = 1.5 secs
	}
	
	ft=setTimeout("flashCount()",dur);
}

function updateAlerts(returnedtext){
	//alert(returnedtext);
	if(returnedtext == "logout"){
		window.location.reload();
	}else{
		
		var parser;
		var xmlDoc;

		if (window.DOMParser){
	  	parser=new DOMParser();
	  	xmlDoc=parser.parseFromString(returnedtext,"text/xml");
	  }else{ // Internet Explorer
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(returnedtext);
	  }
	  
	  var tab = xmlDoc.getElementsByTagName("alerts");
	  var mail_count = tab[0].attributes.getNamedItem("mail_count").nodeValue;
	  var chat_count = tab[0].attributes.getNamedItem("chat_count").nodeValue;
		
		var alertsinfo = tab[0].firstChild.nodeValue;
		document.getElementById('mailinfo').innerHTML = alertsinfo;
		
		if(mail_count > 0 || chat_count > 0){
			//start flashing the top
			clearTimeout(ft);				
			if(mail_count > 0) flash_title = "New Mail!"; //document.getElementById("mailsound").Play();
			if(chat_count > 0) flash_title = "New Chat!"; 
			if(chat_count > 0 && windowstatus == 0 && (!newchatwin || (newchatwin && newchatwin.closed)) ) document.getElementById("chatsound").Play();
			if(chat_count > 0 && mail_count > 0) flash_title = "New Chat & New Mail!";
		  flash_title_on=1;
		  flashCount();
		}else if(mail_count == 0 && chat_count == 0){
			//stop flashing the top
			clearTimeout(ft);
			flash_title_on = 0;
		}
	}
}

function statusAlertsUpdate(){
	if(document.getElementById('mailinfo')){
		var params = "alerts=check&page="+jpage+"&sp="+jsubpage;
		makeHttpRequest("jscript/AjxStatusMail.php", updateAlerts, 'POST', params);
	}
}

function timedCount(){

if(c > 0){ statusAlertsUpdate(); }

c=c+1;
	
	if(c > 420){ //420 x 30000 = 3.5 hours
		stopCount();
	}else{
		t=setTimeout("timedCount()",30000); //60000 = 1 min - 30000 = 30 seconds
	}
}

function doTimer(){
	if(!timer_is_on){
  	timer_is_on=1;
  	timedCount();
  }
}

function stopCount(){
	clearTimeout(t);
	timer_is_on=0;
}

function formSubmit(form,source){		
	form.whichsource.value=source;
	form.submit(); //turned this off due to double submit - test in other browsers
}

function sortSubmit(form,sort,source){
	form.sb.value=sort;
	form.whichsource.value=source;
	form.submit();		
}

function sortSubmit2(form,sort,source){
	//alert(source);
	form.whichsource.value=source;
	form.submit();		
}
	
function formAlert(message){  
  alert(message);
}	
	
function formSubmitId(form,source,id,aname){			

	var tess = source + id;		
	if(source == 'delete'){
		pass=confirm('Are you sure you want to delete '+aname+'?'+' This cannot be undone!');		
		source = '';
		if (pass == true){		
			source = 'delete';
		}
	}
	//alert(form);
	form.whichsource.value=source;
	form.whichid.value=id;
	form.whichname.value=aname;
	form.submit();
}

function formSubmitIdOrd(form,source,id,order_id){			
	
	form.whichsource.value=source;
	form.whichid.value=id;
	form.order.value=order_id;
}

function formSubmitReply(form,source,id){
	form.whichsource.value=source;
	form.whichid.value=id;
	form.submit();
}

//showimage is a simple function that switches the main image with the clicked thumb image :)
function showimage(source){
	document.main.src = source;
}

function showGroupForm(){
	if(document.getElementById('newgroupbutton'))document.getElementById('newgroupbutton').style.display = 'none';
	if(document.getElementById('newgroupform'))document.getElementById('newgroupform').style.display = 'block';
}

function showPollResults(returnedtext){
	document.getElementById('pollresults').innerHTML = returnedtext;
	document.getElementById('pollresults').style.display = 'block';
	document.getElementById('polloptions').style.display = 'none';
	document.getElementById('pollstate').innerHTML = "<div class='lgrey' style='width: 100%; float: left; text-align: left; '>Thank you for voting.</div>";
}

function submitPoll(){
	var vote = document.getElementById('pollradioselect').value;
	var poll = document.getElementById('poll').value;
	var params = "poll="+poll+"&vote="+vote;
	makeHttpRequest("jscript/poll.php", showPollResults, 'POST', params);
}

function enablePoll(choice){
	document.getElementById('pollradioselect').value = choice;
	var pollb = "<a href='javascript:void(0);' ><img border='0' src='"+langdir+'submitg.gif'+"' name='submitpoll' onclick='submitPoll()' />";
	if(document.getElementById('pollsubmit'))document.getElementById('pollsubmit').innerHTML = pollb;
}

function showHidePoll(){

	var shpr = document.getElementById('pollresultsswitch');
	shpr.innerHTML = '';

	with (document.getElementById('pollresults').style){ 
		showswitch = display!='none' ? 0 : 1;
		display = display!='none' ? 'none' : 'block';
		shpr.innerHTML = display!='none' ? 'hide results' : 'show results';
  }
  
  with (document.getElementById('polloptions').style){
   	display = display!='none' ? 'none' : 'block';
  }
  
  with (document.getElementById('pollsubmit').style){ 
   	display = display!='none' ? 'none' : 'block';
  }
}

function showHide2(id){

  with (document.getElementById(id).style)
    { showswitch = display!='none' ? 0 : 1 }
  with (document.getElementById(id).style)
    { 
      if(showswitch == 0){display = 'block'}else{
      display = display!='none' ? 'none' : 'block'}
    }

  if((id == 'part1')&& (showswitch == 1)){

    document.getElementById('part2').style.display = 'none';
    document.getElementById('myslbut').className = 'profmenu'; 
    document.getElementById('myrlbut').className = 'profmenu2';
    document.getElementById('myslbut2').className = 'profmenu';
    document.getElementById('myrlbut2').className = 'profmenu2';
    document.getElementById('onpart').value = '1';
  }
  
  if((id == 'part2')&& (showswitch == 1)){
    document.getElementById('part1').style.display = 'none';
    document.getElementById('myslbut').className = 'profmenu2';
    document.getElementById('myrlbut').className = 'profmenu';
    document.getElementById('myslbut2').className = 'profmenu2';
    document.getElementById('myrlbut2').className = 'profmenu';
    document.getElementById('onpart').value = '2';
  }
}

function showHide4(id){

  with (document.getElementById(id).style)
    { showswitch = display!='none' ? 0 : 1 }
  with (document.getElementById(id).style)
    { 
      if(showswitch == 0){display = 'block'}else{
      display = display!='none' ? 'none' : 'block'}
    }

  if((id == 'reply1')&& (showswitch == 1)){
    
    document.getElementById('reply2').style.display = 'none';
    document.getElementById('replybut1').className = 'profmenu';
    document.getElementById('replybut2').className = 'profmenu2';
    //document.getElementById('onpart').value = '1';

  }
  
  if((id == 'reply2')&& (showswitch == 1)){

    document.getElementById('reply1').style.display = 'none';
    document.getElementById('replybut1').className = 'profmenu2';
    document.getElementById('replybut2').className = 'profmenu';
    //document.getElementById('onpart').value = '2';
  }
}

function showFull(id){
	document.getElementById("edit"+id).innerHTML = document.getElementById("full"+id).innerHTML;
}

function showHideCom(id){

	with (document.getElementById("replysection"+id).style) { display = display!='none' ? 'block' : 'block' }

	if(document.getElementById("replyfield"+id)){
		
		if(document.getElementById("replyfield"+id).style.display == 'none'){
			document.getElementById("replyfield"+id).style.display = 'block';
		}else{
			//document.getElementById("replyfield"+id).style.display = 'none';
		}
		//if(document.getElementById("replyfield"+id).value == '') { document.getElementById("replyfield"+id).style.display = 'none' }
	}
	
	if(document.getElementById("addcomtext"+id)){
		with (document.getElementById("addcomtext"+id).style) { display = display!='none' ? 'none' : 'block' }
	}
	
	document.getElementById("addcomment"+id).focus();
}

function showHideAllCom(id){
	with(document.getElementById(id).style) { display = display!='none' ? 'none' : 'block' }
}

function showHideMes(id){

var srcimg = 'img' + id;

	with(document.getElementById(id).style){ picswitch = display!='none' ? 0 : 1 }
	with (document.getElementById(id).style){ display = display!='none' ? 'none' : 'block' }

	if(( picswitch == 0)){
		document.getElementById(srcimg).src = dir + 'show1.gif';
	  if(id == 'qbrowse'){document.getElementById('columntitlebrowse').className = 'browsemargin10';}
	}else if (( picswitch == 1)){
		document.getElementById(srcimg).src = dir + 'hide1.gif';
	  if(id == 'qbrowse'){document.getElementById('columntitlebrowse').className = 'browsemargin' ;}
	}
		
}

function showHideIt(id){

	var srcimg = 'img' + id;
	
	with(document.getElementById(id).style){ picswitch = display!='none' ? 0 : 1 }
	with(document.getElementById(id).style){ display = display!='none' ? 'none' : 'block' }

	if(picswitch == 0){
		document.getElementById(srcimg).src = langdir + 'show.gif';
	  if(id == 'qbrowse'){document.getElementById('columntitlebrowse').className = 'browsemargin10';}
	}else if( picswitch == 1){
		document.getElementById(srcimg).src = langdir + 'hide.gif';
	  if(id == 'qbrowse'){document.getElementById('columntitlebrowse').className = 'browsemargin' ;}
	}
}

function showHideBrowse(id){
	if(id == 'basicbrowse'){
		document.getElementById(id).style.display = 'block';
		document.getElementById('advbrowse').style.display = 'none';
		document.search.browsesearch.value = 'basicbrowse';
		document.browse.browsesearch.value = 'basicbrowse';
	}else if( id == 'advbrowse'){
		document.getElementById(id).style.display = 'block';
		document.getElementById('basicbrowse').style.display = 'none';
		document.search.browsesearch.value = 'advbrowse';
		document.browse.browsesearch.value = 'advbrowse';
	}
}

function showHideEdit(id){
	
	with(document.getElementById(id).style){ picswitch = display!='none' ? 0 : 1 }
	with(document.getElementById(id).style){ display = display!='none' ? 'none' : 'block' }
	//document.getElementById('advoptions').style.display = 'none';
	
	if(picswitch == 0){
		document.getElementById('edit').src = langdir+'editplus.gif';
		document.getElementById('dispeditsearch').value='0';
	}else if(picswitch == 1){
		document.getElementById('edit').src = langdir+'editminus.gif';
		document.getElementById('dispeditsearch').value='1';
	}
	
}

function showHideFlag(id){
	
	with(document.getElementById(id).style){ picswitch = display!='none' ? 0 : 1 }
	with(document.getElementById(id).style){ display = display!='none' ? 'none' : 'block' }
	
	if(picswitch == 0){
		document.getElementById('flag').src = langdir+'flag_open.gif';
	}else if(picswitch == 1){
		document.getElementById('flag').src = langdir+'flag_close.gif';
	}
}

//this function is used in advanced search and checks for check boxes if they are checked
//if none are checked, then it hides the nice to have, must have
function ShowPriority(thisform,thisname, id){

	var myArray = thisform.elements[thisname];

	var show = 0;
	
	for(var i = 0; i < myArray.length; i++) {
		if(myArray[i].checked == true){
			show = 1;
		}
	}
	if(thisname == "seekrl[]" && thisform.elements['priority_basicrl'][0].checked){
		show = 0;
	}

	if(show == 1){
		document.getElementById(id).style.display = 'block';
	}else{
		document.getElementById(id).style.display = 'none';
	}

}

//this function shows the priority radio buttons for basic rl info advanced search form
function basicRL(vari){
	if(vari == 2){
		document.getElementById('priority_genderrl').style.display = 'block';
		document.getElementById('priority_agerl').style.display = 'block';
		document.getElementById('priority_seekrl').style.display = 'block';
	}else if(vari == 1){
		document.getElementById('priority_genderrl').style.display = 'none';
		document.getElementById('priority_agerl').style.display = 'none';
		document.getElementById('priority_seekrl').style.display = 'none';
	}
}

//advanced search delete
function enableDelete(thisname, thisvalue){
	
	var delbutton;
	
	//savedsearches
	if(thisvalue > 1){
		delbutton = "<a href='javascript:showDialog();' ><img class='qbrowse' src='"+dir+"del_x.gif' name='delete' border='0' alt='delete' title='delete saved search' /></a>";
		document.getElementById('delsearch').innerHTML = delbutton;	
		//document.getElementById('delsearch').disabled = false;
	}else{
		delbutton = "<img class='qbrowse' src='"+dir+"del_x_gry.gif' name='delete' border='0'/>";
		document.getElementById('delsearch').innerHTML = delbutton;
	}
}

function showAlertsResults(returnedtext){
	
	//alert(returnedtext);
	if(document.getElementById('alert1')){var dispstate1 = document.getElementById('alert1').style.display;}
	if(document.getElementById('alert2')){var dispstate2 = document.getElementById('alert2').style.display;}
	
	document.getElementById('alerts').innerHTML = returnedtext;
	//if show
	if(dispstate1 && dispstate1 == 'block'){
		if(document.getElementById('imgalert1'))document.getElementById('imgalert1').src = dir + 'hide1.gif';
		if(document.getElementById('alert1'))document.getElementById('alert1').style.display = dispstate1;
	}
	
	if(dispstate2 && dispstate2 == 'block'){
		if(document.getElementById('imgalert2'))document.getElementById('imgalert2').src = dir + 'hide1.gif';
		if(document.getElementById('alert2'))document.getElementById('alert2').style.display = dispstate2;
	}
}

function showGroupResults(returnedtext){
	//alert(returnedtext);	
	document.getElementById('groupslist').innerHTML = returnedtext;
}

function closeDialog(){		
 		var w = document.getElementById("overlay");
 		w.style.display="none";
 		w.style.visibility="hidden";
 		w.style.zIndex="-1"; 		 		
 		var x = document.getElementById("dialogtop_content");
 		var y = document.getElementById("dialogtext");
 		x.removeChild(x.childNodes[1]);
 		y.removeChild(y.childNodes[0]);
 			if(document.getElementById('sortmenu')){
	 			document.getElementById('sortmenu').style.display = "block";
	 		}
 	}
 	
function confirmDialog(form,conftype,numb){		
 		var w = document.getElementById("overlay");
 		w.style.display="none";
 		w.style.visibility="hidden";
 		w.style.zIndex="-1"; 		 		
 		var x = document.getElementById("dialogtop_content");
 		var y = document.getElementById("dialogtext");
 		x.removeChild(x.childNodes[1]);
 		//y.removeChild(y.childNodes[0]);
			if(conftype == 1 && conftype == 2){
				document.getElementById('sortmenu').style.display = "block";
			}		
		if(conftype == 1){
			form.whichsource.value='delete';
			form.submit();
		}else if(conftype == 2){
			if(form == "signup"){window.location = "http://www.2ndhub.com/?page=register";}
			if(form == "login"){window.location = "http://www.2ndhub.com/?page=login";}
			if(form == "profile"){window.location = "http://www.2ndhub.com/?page=my_profile";}
		}else if(conftype == 4){
			form.whichsource.value='block';
			form.submit();
		}else if(conftype == 6){
			form.whichsource.value='unblock';
			form.submit();
		}else if(conftype == 7){
			form.whichsource.value='addfav';
			form.submit();
		}else if(conftype == 8){
			form.whichsource.value='remfav';
			form.submit();
		}else if(conftype == 9){
			form.whichsource.value='addfriend';
			form.submit();
		}else if(conftype == 10){
			form.whichsource.value='removefriend';
			form.submit();
		}else if(conftype == 11){
			form.whichid.value=numb;
			form.whichsource.value='removepost';
			form.submit();
		}else if(conftype == 12){
			AlertsSections(conftype, numb);
			//form.whichsource.value='denyfriend';
		}else if(conftype == 13){
			AlertsSections(conftype, numb);
			//form.whichsource.value='denybusmem';
		}else if(conftype == 14){
			doNewsComments(conftype, numb);
		}else if(conftype == 15){
			form.whichid.value=numb;
			form.whichsource.value='removegroup';
			form.submit();
		}else if(conftype == 16){
			form.whichid.value=numb;
			form.whichsource.value='removemems';
			form.submit();
		}else if(conftype == 17){
			form.whichid.value=numb;
			form.whichsource.value='leavegroup';
			form.submit();
		}else if(conftype == 18){
			form.whichid.value=numb;
			form.whichsource.value='removeservers';
			form.submit();
		}else if(conftype == 19){
			groupSections(conftype, numb);
			//form.whichsource.value='leavegroup';
		}else if(conftype == 20){
			form.whichsource.value='removesubcribers';
			form.submit();
		}else if(conftype == 21){
			form.whichid.value=numb;
			form.whichsource.value='removeprofile';
			form.submit();
		}else if(conftype == 22){
			form.whichid.value=numb;
			form.whichsource.value='removenotices';
			form.submit();
		}
}
 	
function showDialog(delname,diagtype,specificid){
	
	var w = document.getElementById("overlay");	
	var x = document.getElementById("dialogtop_content");
	var y = document.getElementById("dialogtext");
	var z = document.getElementById("dialogbuttons");
	var xz = document.getElementById("dialogbuttons");

	if(pattern6.test(userAgent) && !pattern7.test(userAgent)){
		//alert("IE 6!");
		var bwidth = document.documentElement.clientWidth;		
		w.style.position="absolute";
		w.style.width = bwidth + "px";
		w.style.backgroundImage="url(../"+dir+"spacer.gif)";
		
		if(document.getElementById('sortmenu')){
		 document.getElementById('sortmenu').style.display = "none";
		}
	}

	dialogTitle = document.createTextNode(dtitle[0]);
	//take array of dialog values rendered in html and replace based on diagtype value
	var dialogBody2 = dialogbody[diagtype].replace(new RegExp("\\[name\]","gm"),delname);
	//basic button config - specificid not always used
	//6-13 & 4 (but has id=edit on cancel button
	var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"yes.gif' alt='yes' border='0' onclick='confirmDialog(flagblock,"+diagtype+","+specificid+");return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"cancelr.gif' alt='cancel' id='cancel' border='0' onclick='closeDialog();' /></a>";
	
	//change the title of the dialog if one is present
	if(dtitle[diagtype]){dialogTitle = document.createTextNode(dtitle[diagtype]);}
	
	if(diagtype == 1){	
		var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"ok.gif' alt='ok' border='0' onclick='confirmDialog(search,"+diagtype+");return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"cancelr.gif' alt='cancel' id='edit' border='0' onclick='closeDialog();' /></a>";
	}else if(diagtype == 2){
		var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"signup.gif' alt='login' border='0' onclick='confirmDialog(\"signup\","+diagtype+");return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"loging.gif' alt='login' border='0' onclick='confirmDialog(\"login\",2);return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"closer.gif' alt='close' border='0' onclick='closeDialog();' /></a>";
	}else if(diagtype == 3){
		var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"continueg.gif' alt='continue' border='0' onclick='confirmDialog(\"profile\","+diagtype+");return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"closer.gif' alt='close' border='0' onclick='closeDialog();' /></a>";
	}else if(diagtype == 5 || diagtype == 25 || diagtype == 26){
		var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"ok.gif' alt='ok' border='0' onclick='closeDialog();' /></a>&nbsp;";
	}
	
	//You can currently specify multple features and options, and you can also save multple searches and return to them later.
	x.appendChild(dialogTitle);
	y.innerHTML = dialogBody2;
	xz.innerHTML = buttons; 
	w.style.zIndex="1000";
	w.style.display="block";
	w.style.visibility="visible";
}

function hideNotice(){
	if(document.getElementById("success")){ document.getElementById("success").style.display = 'none';}
}

function showNewComment(returnedtext){
	//alert(returnedtext);
	var parentid = document.getElementsByName('whichid')[0].value;
	
	//insertcomdiv$parent_id
 t = document.createElement("div");
 t.innerHTML = returnedtext;
 document.getElementById('insertcomdiv'+parentid).appendChild(t);
 
 //if(document.getElementById('addcomtextA'+parentid))document.getElementById('addcomtextA'+parentid).style.display = 'block';
 if(document.getElementById('addcomtext'+parentid))document.getElementById('addcomtext'+parentid).style.display = 'block';
 document.getElementById('replyfield'+parentid).style.display = 'none';
 document.getElementById('addcomment'+parentid).value = '';
 
 //addcomtext61 show
 //replyfield61 hide
 
 //w.appendChild(t);
 //document.getElementById('insertcomdiv'+61).innerHTML = returnedtext;
 //scrollTo(0,0);
 //window.location.hash = "#expandcomments";
}

function showMoreComments(returnedtext){
	//alert(returnedtext);
 document.getElementById('expandcomments').innerHTML = returnedtext;
 scrollTo(0,0);
 //window.location.hash = "#expandcomments";
}

function showMoreCom(num){
	var params = "";
	makeHttpRequest("jscript/AjxNewsComments.php", showMoreComments, 'POST', params);
}

function AlertsSections(conftype, numb){
	var params = "type="+conftype+"&numb="+numb;
	makeHttpRequest("jscript/AjxAlertsSections.php", showAlertsResults, 'POST', params);
}

function groupSections(conftype, numb){
	var sect = document.getElementById("whichsection").value;
	var prof = document.getElementById("whichprof").value;
	var params = "type="+conftype+"&numb="+numb+"&section="+sect+"&prof="+prof;
	makeHttpRequest("jscript/AjxAlertsSections.php", showGroupResults, 'POST', params);
}

function doAddComment(conftype, numb){
	
	document.getElementsByName('whichid')[0].value = numb;
	var reply = document.getElementById('addcomment'+numb).value;
	reply = encodeURIComponent(reply);
	var color = document.getElementById('postcolor'+numb).value;
	var express = document.getElementById('postexpress'+numb).value;
	
	var subscribe = 0;
	if(document.getElementById('subscribe_thread'+numb)) { subscribe = document.getElementById('subscribe_thread'+numb).checked; }

	var params = "whichsource="+conftype+"&whichid="+numb+"&reply_comment"+numb+"="+reply+"&postcolor"+numb+"="+color+"&postexpress"+numb+"="+express+"&subscribe_thread"+numb+"="+subscribe;
	//alert(params);
	makeHttpRequest("jscript/AjxNewsComments.php", showNewComment, 'POST', params);
}

function showDelComment(returnedtext){
	//alert(returnedtext);
	var commentid = document.getElementsByName('whichid')[0].value;
 	document.getElementById('commentwrapper'+commentid).innerHTML = returnedtext;
}

function doNewsComments(conftype, numb){
	document.getElementsByName('whichid')[0].value = numb;
	var params = "whichsource="+conftype+"&whichid="+numb;
	makeHttpRequest("jscript/AjxNewsComments.php", showDelComment, 'POST', params);
}

function cancelEditPost(post_id){
	var x = document.getElementById("edit"+post_id);
	var y = document.getElementById("editform"+post_id);
	x.style.display = 'block';
	y.style.display = 'none';
}

function showEditComment(returnedtext){
	//alert(returnedtext);
	var post_id = document.getElementsByName('whichid')[0].value;
	
	var x = document.getElementById("edit"+post_id);
	var y = document.getElementById("editform"+post_id);
	x.style.display = 'none';
	y.innerHTML = returnedtext;
	y.style.display = 'block';
	var scrheight = document.getElementById("editpost"+post_id).scrollHeight;
	
	//var pattern6 = /msie 6.0/;
	//var pattern7 = /msie 7.0/;
	
	if(pattern6.test(userAgent) && !pattern7.test(userAgent) && scrheight > 22){
		scrheight = scrheight + 26;
	}else{
		scrheight = scrheight + 12;
	}
	
	document.getElementById("editpost"+post_id).style.height = scrheight+'px';
	document.getElementById("editpost"+post_id).focus();
	
	if(pattern6.test(userAgent) && !pattern7.test(userAgent) && scrheight > 22){
		var FieldRange = document.getElementById("editpost"+post_id).createTextRange();
		FieldRange.moveStart('character',document.getElementById("editpost"+post_id).value.length );
		FieldRange.collapse();
		FieldRange.select();
	}
	
}

function editPost(conftype, post_id){
	document.getElementsByName('whichid')[0].value = post_id;
	var params = "whichsource="+conftype+"&whichid="+post_id;
	makeHttpRequest("jscript/AjxNewsComments.php", showEditComment, 'POST', params);
}

function addRemVideo(myval, parent_id){

	var vidchanged = 0;
	var postvideoid = "postvideo";
	var postvideo_icon_id = "postvideo_icon";
	var videofieldid = "videolinkfield";

	if(parent_id > 0){
		postvideoid = "postvideo"+parent_id;
		postvideo_icon_id = "postvideo_icon"+parent_id;
		videofieldid = "videolinkfield"+parent_id;
	}
	//on mouse down
	if(myval == 2 && vidchanged == 0 && document.getElementById(videofieldid).value == initvid){
		document.getElementById(videofieldid).value = "";
		document.getElementById(videofieldid).focus();
		vidchanged = 1;
	}

	if(myval == 3){
		document.getElementById(postvideoid).style.display = 'block';
		document.getElementById(postvideo_icon_id).style.display = 'none';
	}
	
	if(myval == 4){
		document.getElementById(postvideoid).style.display = 'none';
		document.getElementById(postvideo_icon_id).style.display = 'block';
		document.getElementById(videofieldid).value = initvid;
	}
}

function expandInput(id, myval, parent_id){
	
	var changed = 0;
	var origstring = initmess; //"What's happening?";
	var currentval = '';
	var useid = "postbutton";
	var postsubjectid = "newsubject";
	var postoptionsid = "postoptions";
	var postvideoid = "postvideo";
	var postvideo_icon_id = "postvideo_icon";
	var videofieldid = "videolinkfield";
	var postsubscribe = "postsubscribe";
	var postitgif = langdir+'postit.gif';
	var postitgifdis = langdir+'postit_disabled.gif';
	
	if(id == "addcomment"+parent_id){
		origstring = "Add a comment!";
		useid = "replybutton"+parent_id;
		postoptionsid = "postoptions"+parent_id;
		postvideoid = "postvideo"+parent_id;
		postvideo_icon_id = "postvideo_icon"+parent_id;
		videofieldid = "videolinkfield"+parent_id;
		postsubscribe = "postsubscribe"+parent_id;
		postitgif = langdir+'postcomment.gif';
		postitgifdis = langdir+'postcomment_disabled.gif';
	}

	if(id == "editpost"+parent_id){
		origstring = "Edit your post";
		useid = "editpostbutton"+parent_id;
		postoptionsid = "postoptions"+parent_id;
		postvideoid = "postvideo"+parent_id;
		postvideo_icon_id = "postvideo_icon"+parent_id;
		videofieldid = "videolinkfield"+parent_id;
		postsubscribe = "postsubscribe"+parent_id;
		postitgif = langdir+'postit.gif';
		postitgifdis = langdir+'postit_disabled.gif';
	}
	
	if(id == 'newsubject'){
		origstring = initsubj;
	}
	
	if(id == 'editsubject'+parent_id){
		origstring = initsubj;
		postsubjectid = "editsubject"+parent_id;
		useid = "editpostbutton"+parent_id;
	}
	
	document.getElementById(id).style.height = "14px";
	document.getElementById(id).scrollHeight;
	var scrheight = document.getElementById(id).scrollHeight;
	scrheight = scrheight + 12;
	
	//on key up
	if(myval == 0 && document.getElementById(id).value != origstring && document.getElementById(id).value != ''){
		if(parent_id > 0 && id == "addcomment"+parent_id){ document.getElementById("replydiv"+parent_id).style.display = 'block'; }
		if(id != "editpost"+parent_id && id != postsubjectid ){document.getElementById(postoptionsid).style.display = 'block';}
		if(id=='newcomment' && section == 1){document.getElementById(postsubjectid).style.display = 'block';}
		document.getElementById(useid).disabled = false;
		document.getElementById(useid).src = postitgif;
		if((id=='newcomment' || id == "editpost"+parent_id ) && document.getElementById(postvideoid).style.display == 'none' ){document.getElementById(postvideo_icon_id).style.display = 'block';}
		if(document.getElementById(postsubscribe))document.getElementById(postsubscribe).style.display = 'block';
		//document.getElementById(postoptionsid).disabled = false;
	}

	//on mouse down
	if(myval == 1 && changed == 0 && document.getElementById(id).value == origstring){
		if(parent_id > 0){document.getElementById("replydiv"+parent_id).style.display = 'block';}
		document.getElementById(id).value = "";
		document.getElementById(id).focus();
		if(id=='newcomment' && section == 1){document.getElementById(postsubjectid).style.display = 'block';}
		changed = 1;
	}	
	//alert(scrheight);
	document.getElementById(id).style.height = scrheight+'px';
	
	//on blur lost focus
	if(myval == 2 && document.getElementById(id).value == ''){
		if(parent_id > 0){ document.getElementById("replydiv"+parent_id).style.display = 'none';}
		if(parent_id > 0 && document.getElementById("replyfield"+parent_id) ){ document.getElementById("replyfield"+parent_id).style.display = 'none';}
		//if(parent_id > 0 && document.getElementById("replysection"+parent_id) ){ document.getElementById("replysection"+parent_id).style.display = 'none';}
		if(parent_id > 0 && document.getElementById("addcomtext"+parent_id) ){ document.getElementById("addcomtext"+parent_id).style.display = 'block';}
		//if(id=='newsubject'){document.getElementById(postsubjectid).style.display = 'none';}
		if(id != postsubjectid){document.getElementById(postoptionsid).style.display = 'none';}
		if(id != postsubjectid){document.getElementById(postvideo_icon_id).style.display = 'none';}
		if(id != postsubjectid){document.getElementById(postvideoid).style.display = 'none';}
		document.getElementById(useid).disabled = true;
		//document.getElementById(postoptionsid).disabled = true;
		if(parent_id == 0)document.getElementById(id).value = origstring;
		document.getElementById(id).style.height = '14px';
		document.getElementById(useid).src = postitgifdis;
		changed = 0;
		if(document.getElementById(videofieldid).value == ''){document.getElementById(videofieldid).value = initvid;}
		if(document.getElementById(postsubscribe))document.getElementById(postsubscribe).style.display = 'none';
	}

}

function rollover(id, command){
	if(command == 1){
		document.getElementById(id).src = dir + 'del_x.gif';
	}else{
		document.getElementById(id).src = dir + 'del_x_gry.gif';
	}
}

//this function limits the #characters on a text input field
//id = id of text field, totchars = max # chars, writefield - div to update with #chars left
function remainChars(id,totchars, writefield){
	var len = document.getElementById(id).value.length;
	if(len > totchars){
		document.getElementById(id).value = document.getElementById(id).value.substring(0,totchars);
		var len = document.getElementById(id).value.length;	
	}
	var numleft = totchars - len;
	if (numleft == 0){
		document.getElementById(writefield).style.display = 'block';
		document.getElementById(writefield).innerHTML = "You've reached " + totchars + " characters!";
	}else{
		document.getElementById(writefield).innerHTML = "";
	}
}

function dupSearchField(searchfield){
	//alert(searchfield);
	document.getElementById('searchfield1').value = searchfield;
	document.getElementById('searchfield2').value = searchfield;
}

//this function shows/hides the remember me login feature
function showRemem(thisform, thisname){
var hiddenname = thisform.usernameh.value;
var hiddenpass = thisform.userpassh.value;
var field = 'password';
//var hiddenname = document.logform.usernameh.value;
//var hiddenname = document.getElementById('usernameh').value;
	if(hiddenname != '' && hiddenpass != ''){ 
		if(thisform.username.value != hiddenname || thisform.passw.value != hiddenpass){
			document.getElementById('remembox').style.display = 'block';
		}else if(thisform.username.value == hiddenname && thisform.passw.value == hiddenpass){
			document.getElementById('remembox').style.display = 'none';
		}
	}
}

var newwindow;
function popup(url){ 
	newwindow=window.open(url,'name',"height=630,width=390,top=200,left=260,scrollbars=yes");
	if (window.focus) {newwindow.focus()}
}

var newchatwin = false;
function popChat(url){
	if(newchatwin == false || newchatwin.closed){
		newchatwin=window.open(url,'chat',"height=380,width=620,top=200,left=260,scrollbars=no,resizable=yes");
		if(!firefoxpattern.test(userAgent)){ newchatwin.blur(); } 
		if (window.focus) {newchatwin.focus();}
	}else{
		if(!firefoxpattern.test(userAgent)){ newchatwin.blur(); } //newchatwin.blur();
		if (window.focus) {newchatwin.focus();}
	}
}

function closeChat(){
	if(newchatwin)newchatwin.close();
}

function PopWindow(mypage, myname, w, h, scroll) {
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
		win = window.open(mypage, myname, winprops)
		if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

//-----------------------
//new showHid function that sets and reads help info cookie
function showHide(id){
	var srcimg = 'img' + id;
	
	var chelp1 = 0; //default - this variable will be set into cookie
	var chelp2 = 0;
	var chelp3 = 0;
	var chelp4 = 0;
	var chelp5 = 0;
	var chelp6 = 0;
	var chelp7 = 0;

	var showhelpgif = langdir+'showhelp.gif';
	
	var hidehelpgif = langdir+'hidehelp.gif';
	
	var allcookies = document.cookie;

 var cookies = allcookies.replace(/ /g, '').split(';');
  for(var i = 0; i < cookies.length; i++) {
    // Does this cookie string begin with the name we want?
    //alert(cookies[i]);
    if (cookies[i].substring(0, cookie_prefix+"help".length+1) == (cookie_prefix+"help" + "=")) {        
        var cookie = cookies[i];
        break;
    }
  }
  if(cookie == null){
  }else{
    var cookval = decodeURIComponent(cookie.substring(cookie_prefix+"help=".length));
    var helpvalues = cookval.split('|');
    chelp1 = helpvalues[0];
    chelp2 = helpvalues[1];
    chelp3 = helpvalues[2];
    chelp4 = helpvalues[3];
    chelp5 = helpvalues[4];
    chelp6 = helpvalues[5];
    chelp7 = helpvalues[6];
  }

	with(document.getElementById(id).style){ picswitch = display!='none' ? 0 : 1 }
	with(document.getElementById(id).style){ display = display!='none' ? 'none' : 'block' }
	if(( picswitch == 0) && (id == 'help1')){
		//alert (id);
		document.getElementById(srcimg).src = showhelpgif;
		chelp1 = 0;
	}else if(( picswitch == 1) && (id == 'help1')){
		document.getElementById(srcimg).src = hidehelpgif;
		chelp1 = 1;
	}
	
	if(( picswitch == 0) && (id == 'help2')){
		//alert (id);
		document.getElementById(srcimg).src = showhelpgif;	
		chelp2 = 0;
	}else if (( picswitch == 1) && (id == 'help2')){
		document.getElementById(srcimg).src = hidehelpgif;
		chelp2 = 1;
	}
	
	if(( picswitch == 0) && (id == 'help3')){
		//alert (id);
		document.getElementById(srcimg).src = showhelpgif;
		chelp3 = 0;
	}else if (( picswitch == 1) && (id == 'help3')){
		document.getElementById(srcimg).src = hidehelpgif;
		chelp3 = 1;
	}
	
	if(( picswitch == 0) && (id == 'help4')){
		//alert (id);
		document.getElementById(srcimg).src = showhelpgif;
		chelp4 = 0;
	}else if (( picswitch == 1) && (id == 'help4')){
		document.getElementById(srcimg).src = hidehelpgif;
		chelp4 = 1;
	}
	
	if (( picswitch == 0) && (id == 'help5')){
		//alert (id);
		document.getElementById(srcimg).src = showhelpgif;
		chelp5 = 0;
	}else if (( picswitch == 1) && (id == 'help5')){
		document.getElementById(srcimg).src = hidehelpgif;
		chelp5 = 1;
	}
	
	if (( picswitch == 0) && (id == 'help6')){
		//alert (id);
		document.getElementById(srcimg).src = showhelpgif;
		chelp6 = 0;
	}else if (( picswitch == 1) && (id == 'help6')){
		document.getElementById(srcimg).src = hidehelpgif;
		chelp6 = 1;
	}
	
	if (( picswitch == 0) && (id == 'help7')){
		//alert (id);
		document.getElementById(srcimg).src = showhelpgif;
		chelp7 = 0;
	}else if (( picswitch == 1) && (id == 'help7')){
		document.getElementById(srcimg).src = hidehelpgif;
		chelp7 = 1;
	}
		
	//write the cookie because this function was called and something changed
  days = 365; // -ve for deleting it.
  var date = new Date();
  date.setTime(date.getTime ()+(days*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();
	//alert(chelp1);
	document.cookie = cookie_prefix+"help=" + chelp1 + "|" + chelp2 + "|" + chelp3 + "|" + chelp4 + "|" + chelp5 + "|" + chelp6 + "|" + chelp7 + expires + "; path=/";
		
}

//---------------------------
//new setHelp function that sets basic help(in page) & cookie info for default help settings
function setHelp(helpswitch){
  var allcookies = document.cookie;
  //0 is hidden 
  var help1 = 0;
  var help2 = 0;
  var help3 = 0;
  var help4 = 0;
  var help5 = 0;
  var help6 = 0;
  var help7 = 0;

	var showhelpgif = langdir+'showhelp.gif';

	var hidehelpgif = langdir+'hidehelp.gif';

  var cookies = allcookies.replace(/ /g, '').split(';');
  for(var i = 0; i < cookies.length; i++) {
    // Does this cookie string begin with the name we want?
    //alert(cookies[i]);
    if (cookies[i].substring(0, cookie_prefix+"help".length+1) == (cookie_prefix+"help" + "=")) {        
        var cookie = cookies[i];
        break;
    }
  }
  if(cookie == null){
    //couldn't find the cookie - do this
    days = 365; // -ve for deleting it.
    var date = new Date();
    date.setTime(date.getTime ()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
       
    var setval = encodeURIComponent("0|0|0|0|0|1|1");
    //cookie doesn't exist yet, so let's set it /*"; max-age=" + (60*60*24*365) +*/
    document.cookie = cookie_prefix+"help=" + setval + expires + "; path=/";
  }else{
    var cookval = decodeURIComponent(cookie.substring(cookie_prefix+"help=".length));
    var helpvalues = cookval.split('|');
    help1 = helpvalues[0];
    help2 = helpvalues[1];
    help3 = helpvalues[2];
    help4 = helpvalues[3];
    help5 = helpvalues[4];
    help6 = helpvalues[5];
    help7 = helpvalues[6];
  }
    
  //ok we either read the cookie values or we wrote them
  if(helpswitch == 1){
    if(help1 == 1){
      //alert("help1");
      document.getElementById("help1").style.display = 'block';
      document.getElementById("imghelp1").src = hidehelpgif;
    }else{
      document.getElementById("help1").style.display = 'none';
      document.getElementById("imghelp1").src = showhelpgif;
    }
    if(help2 == 1){
      //alert("help2");
      document.getElementById("help2").style.display = 'block';
      document.getElementById("imghelp2").src = hidehelpgif;
    }else{
      //document.getElementById("help2").style.display = 'none';
      //document.getElementById("imghelp2").src = showhelpgif;
    }
  }else if(helpswitch == 2){
    if(help4 == 1){
      //alert("help4");
      document.getElementById("help4").style.display = 'block';
      document.getElementById("imghelp4").src = hidehelpgif;
    }else{
      document.getElementById("help4").style.display = 'none';
      document.getElementById("imghelp4").src = showhelpgif;
    }
      if(help5 == 1){
      //alert("help4");
      document.getElementById("help5").style.display = 'block';
      document.getElementById("imghelp5").src = hidehelpgif;
    }else{
      document.getElementById("help5").style.display = 'none';
      document.getElementById("imghelp5").src = showhelpgif;
    }
  }else if(helpswitch == 3){
  	
  	if(help3 == 1){
      //alert("help3");
      document.getElementById("help3").style.display = 'block';
      document.getElementById("imghelp3").src = hidehelpgif;
    }else{
      document.getElementById("help3").style.display = 'none';
      document.getElementById("imghelp3").src = showhelpgif;
    }
  
  }else if(helpswitch == 4 && document.getElementById("help6")){
  	
	  	if(help6 == 1){
	      document.getElementById("help6").style.display = 'block';
	      document.getElementById("imghelp6").src = hidehelpgif;
	    }else{
	      document.getElementById("help6").style.display = 'none';
	      document.getElementById("imghelp6").src = showhelpgif;
	    }    
	    if(help7 == 1){
	      document.getElementById("help7").style.display = 'block';
	      document.getElementById("imghelp7").src = hidehelpgif;
	    }else{
	      document.getElementById("help7").style.display = 'none';
	      document.getElementById("imghelp7").src = showhelpgif;
	    }
  }

}

function makeHttpRequest( to_url, callback_function, methtype, params, return_xml  ){
 
 var http_request, response, i;

 var activex_ids = ['MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];

 if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+...
   http_request = new XMLHttpRequest();
   if (http_request.overrideMimeType) {
   		http_request.overrideMimeType('text/html');
  		//http_request.overrideMimeType('text/xml');
   }
 } else if (window.ActiveXObject) { // IE6 and older
   for (i = 0; i < activex_ids.length; i++) {
     try {
       http_request = new ActiveXObject(activex_ids[i]);
     } catch (e) {}
   }
 }

 if (!http_request) {
   //write custom function to prompt user with this
   //alert('Unfortunately your browser doesn’t support this feature.');
   return false;
 }

 http_request.onreadystatechange = function() {
   if (http_request.readyState !== 4) {
       // not ready yet
       return;
   }
   if (http_request.status !== 200) {
     // ready, but not OK
     //write custom pop up for this error
     //alert('There was a problem with the request.(Code: ' + http_request.status + ')');
     return;
   }
   if (return_xml) {
     response = http_request.responseXML;
   } else {
     response = http_request.responseText;
   }
   // invoke the callback
   callback_function(response);
 };
	//'GET'
 	http_request.open(methtype, to_url, true);
 
 	if(methtype == 'POST'){
 		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		//http_request.setRequestHeader("Content-length", params.length);
		//http_request.setRequestHeader("Connection", "close");
 		http_request.send(params);
	}else{
 		http_request.send(null);
	}
}