var processing = 0;
var onLoginVoteId = null;
var voteInterval = 0;
addEvent(window, 'load', start);
var ids=new Array('Netscape','Web','All','Netscape-bottom','Web-bottom','All-bottom');
var checkMailID, checkMailCount = 0;
var checkMailInterval = 60; // seconds
var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;
var numb = '00.5123456789';
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

function isValid(parm,val) {
if (parm == "") return true;
for (i=0; i<parm.length; i++) {
if (val.indexOf(parm.charAt(i),0) == -1) return false;
}
return true;
}

function isNum(parm) {return isValid(parm,numb);}

function switchSearchType(id,formval){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		resetClass(ids[i],'');
	}
	resetClass(id,'on');
	resetClass(id+'-bottom','on');
	setFormValue('showval',formval);
	setFormValue('showval-bottom',formval);
}

function setFormValue(id,formval) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).value = formval;
		//alert(id+action);
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.value = formval;
		}
		else { // IE 4
			document.all.id.value = formval;
		}
	}
}


function resetClass(id,action) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).className = action;
		//alert(id+action);
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.className = action;
		}
		else { // IE 4
			document.all.id.className = action;
		}
	}
}

function showhide(id,action) {
	//safe function to show an element with a specified id

	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = action;
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = action;
		}
		else { // IE 4
			document.all.id.style.display = action;
		}
	}
}


function start(){
	//DWO.regurg();
	//Tag forms with events
	var forms = document.getElementsByTagName('form');
	var monitorTyping = [];
	for(var i = 0; i < forms.length; i++){
		var form = forms[i];
		//Check for special interest commands
		for(var j = 0; j < form.length; j++){
			var elem = form.elements[j];
			if(elem.name == "monitor"){
				monitorTyping = elem.value.split(",");
				break;
			}
		}
		//Add Events
		for(var j = 0; j < form.length; j++){
			var elem = form.elements[j];

			for(var k = 0; k < monitorTyping.length; k++){
				if(monitorTyping[k] == elem.name){
					if(elem.type == 'text' || elem.type == 'textarea'){
						addEvent(elem, 'keypress', onFinishTyping);
					} else {
						//addEvent(elem, 'change', onFinishTyping);
					}
				}
			}
			//alert(form.elements[j].name);
		}
	}

	// add the mail checks
	checkMailID = setInterval('checkMail();',checkMailInterval * 1000);
}

function submitVote(storyId, from_comment_dialog){
	//document.getElementById('voteStatus'+storyId).innerHTML = 'Voting...';
	voteCount = parseInt(document.getElementById('voteCount'+storyId).innerHTML,10);
	var countarr = document.getElementsByName('voteCount'+storyId);
	for (i=0; i<countarr.length; i++) {
	    countarr[i].innerHTML = voteCount + 1;
	}
	var statusarr = document.getElementsByName('voteStatus'+storyId);
	for (k=0; k<statusarr.length; k++) {
	    statusarr[k].innerHTML = '<img src="'+ihost+'/media/iconVoteSwitch.gif" width="10" height="10" border="0" /> Voted';
	}
	var badgearr = document.getElementsByName('voteBadge'+storyId);
	for (j=0; j<badgearr.length; j++) {
	    badgearr[j].className="voted";
	    badgearr[j].href="#";
	    badgearr[j].onclick="";
	    if (document.getElementById("nswidget") != null) {
	        badgearr[j].innerHTML = "Voted";
	    }
	}

	//Hide the "Don't forget to Vote" text if present... (on story permlink)
	var commentVoteDialogContainer = document.getElementById('commentVoteDialogContainer');
	if (commentVoteDialogContainer) {
		commentVoteDialogContainer.innerHTML = '';
	}
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=SubmitVote&voteDivId="+storyId+"&storyId="+storyId, respVote);
}

function respVote(resp) {
	if(resp) {
		//If no login is available ask to login
		if(!resp.loggedIn){
			onLoginVoteId = resp.storyId;
                        var docHeight=document.body.scrollTop;
			if (document.getElementById("nswidget") != null) {
				parent.location.href=secureHost+"/signin/?y="+docHeight+"&loginaction=vote&id="+resp.storyId+"&backurl="+escape(document.referrer);
			} else if (document.getElementById("storyFramePage") != null) { 
				parent.location.href=secureHost+"/signin/?y="+docHeight+"&loginaction=vote&id="+resp.storyId+"&backurl="+escape(parent.location.href);
			} else {
				document.location.href=secureHost+"/signin/?y="+docHeight+"&loginaction=vote&id="+resp.storyId+"&backurl="+escape(document.location.href);
			}
			return;
		}
		return;
	}
}

function switchUserinfo(size){
        processing=0;
        //ajaxObj.method="POST";
        //ajaxObj.format="JSON";
        //ajaxObj.call("action=GetUserInfo&userinfoType="+size, respSwitchUserInfo);
}

function respSwitchUserInfo(resp){
        if (resp) {
            if (resp.success) {
                document.getElementById('userinfo').innerHTML=resp.content;
            }
        }
}

function remFriend(memberId,friendId,friendAlias,cacheKey){
        processing=0;
        //ajaxObj.method="POST";
        //ajaxObj.format="JSON";
        //ajaxObj.call("action=RemoveFriend&memberid="+memberId+"&friendid="+friendId+"&friendalias="+friendAlias+"&cacheKey="+cacheKey, removeFriendResponse);
}

function removeFriendResponse(resp) {
        if (resp) {
            if (resp.success) {
               document.getElementById('friendAvatar'+resp.friendid).style.display='none';
               document.getElementById('friendAvatar'+resp.friendid).innerHTML="";
               document.getElementById('removeFriend').innerHTML=resp.friendalias+" is no longer one of your friends.";
            }
        }
}

function remUnclaimedFriend(memberId,friendId,friendAlias,cacheKey){
        processing=0;
        //ajaxObj.method="POST";
        //ajaxObj.format="JSON";
        //ajaxObj.call("action=RemoveUnclaimedFriend&memberid="+memberId+"&friendid="+friendId+"&friendalias="+friendAlias+"&cacheKey="+cacheKey, remUnclaimedFriendResponse);
}

function remUnclaimedFriendResponse(resp) {
	if (resp) {
		if (resp.success) {
			document.getElementById('friendAvatar'+resp.friendid).style.display='none';
			document.getElementById('friendAvatar'+resp.friendid).innerHTML="";
		}
	}
}

function addFriendToProfile(memberId,friendId,friendAlias,querylim,cacheKey){
	processing=0;
	//ajaxObj.method="POST";
	//ajaxObj.format="JSON";
	//ajaxObj.call("action=AddFriend&memberid="+memberId+"&friendid="+friendId+"&friendalias="+friendAlias+"&limit="+querylim+"&cacheKey="+cacheKey, addFriendResponse);
}

function addFriendResponse (resp) {
	if (resp) {
		if (resp.success) {
			var fof=document.getElementById("memberfof");
			var pfvote=document.getElementById("memberpfvote");
			var pfcrating=document.getElementById("memberpfcrating");
			var ucf=document.getElementById("memberucf");
			var foffon=document.getElementById("friendsOfflineOnlineDiv");
			if (fof != null) { fof.innerHTML=resp.memberfof; }
			if (pfvote != null) { pfvote.innerHTML=resp.memberpfvote; }
			if (pfcrating != null)  { pfcrating.innerHTML=resp.memberpfcrating; }
			if (ucf != null) { ucf.innerHTML=resp.memberucf; }
			if (foffon != null) { foffon.innerHTML=resp.friendsoffon; }
			document.getElementById("friendAdded").innerHTML=resp.friendalias+" has been added as your friend.";
		}
	}
}

function removeMsg(msgId,divid,lim,page,msgtype,folder){
	if (!folder) folder = '';
       processing=0;
       //ajaxObj.method="POST";
       //ajaxObj.format="JSON";
       //ajaxObj.call("action=RemoveMessage&messageid="+msgId+"&divid="+divid+"&lim="+lim+"&page="+page+"&msgtype="+msgtype+"&folder="+folder, removeMsgResponse);
}

function removeMsgResponse(resp) {
	if (resp) {
		if (resp.success) { 
			document.getElementById(resp.divid).innerHTML=resp.contents;
			
			if (document.getElementById('newMessageCount') && resp.newMessageCount >= 0){
				document.getElementById('newMessageCount').innerHTML = resp.newMessageCount;
				if (resp.newMessageCount == 1){
					document.getElementById('newMessageCountPlural').style.display = 'none';
				}
				else {
					document.getElementById('newMessageCountPlural').style.display = '';
				}
			}

			if (resp.totalcount <= resp.Limit * (resp.page-1) && resp.page > 1) {
				// all messages from this page are removed, back up
				document.location.href = resp.navurlprefix + (resp.page-1)
			} else {
				// update the navigation bar
				document.getElementById('pageNavTop').innerHTML = resp.navBar;
				document.getElementById('pageNavBottom').innerHTML = resp.navBar;
			}
		}
	}
}

function getCommentForm(divid, storyId, parentCommentId, title) {
	processing=0;
	//ajaxObj.method="POST";
	//ajaxObj.format="JSON";
	//ajaxObj.call("action=GetContent&template=AddComment&divid="+divid+"&storyId="+storyId+"&parentCommentId="+parentCommentId+"&title="+title, getContent_callback);
}

function getContent_callback(resp) {
	if (resp) { if (resp.success) { 
		element = document.getElementById(resp.divid);
		element.innerHTML = resp.content;
	} }
}

function getTopStories(divid, divother, limit) {
	processing=0;
	//ajaxObj.method="POST";
	//ajaxObj.format="JSON";
	//ajaxObj.call("action=TopStories&divid="+divid+"&divother="+divother+"&limit="+limit, getTopStoriesResponse);
}

function buildStoryHtml(story) {
	date = story.createdOn;
	url = '/story/' + date.substring(0,4) + '/' + date.substring(5, 7) + '/' + date.substring(8,10) + '/' + story.slug;
	link = '<p><a href="#" onclick="windowNavigate(window.opener, \''+url+'\');return false;">' + story.title + '</a></p>';
	return link;
}

function getTopStoriesResponse(resp) {
	if (resp) { if (resp.success) {
		topstory = buildStoryHtml(resp.content[0]);
		otherstories = '';
		for (i=1; i<resp.content.length; i++) {
			otherstories += buildStoryHtml(resp.content[i]);
		}

		divid = document.getElementById(resp.divid);
		divother = document.getElementById(resp.divother);
		divid.innerHTML = topstory;
		divother.innerHTML = otherstories;
	} }
}

function getMsgForm(alias,memberId,rootMessageId,parentMessageId,divid,folder,page) {
	if (!folder) folder = '';
       processing=0;
       //ajaxObj.method="POST";
       //ajaxObj.format="JSON";
       //ajaxObj.call("action=GetMsgForm&alias="+alias+"&memberid="+memberId+"&rootmessageid="+rootMessageId+"&parentmessageid="+parentMessageId+"&divid="+divid+"&folder="+folder+"&page="+page, getMsgFormResponse);
}

function getMsgFormResponse(resp) {
	if(resp){
  	if(resp.success) {
  		document.getElementById(resp.divid).innerHTML=resp.content;
		}
	}
}

function hideFrameNav(memberId,url) {
        processing=0;
        //ajaxObj.method="POST";
        //ajaxObj.format="JSON";
        //ajaxObj.call("action=HideFrameNav&memberid="+memberId+"&url="+url, hideFrameNavResponse);
}

function hideFrameNavResponse(resp) {
        var status=document.getElementById('hideFrameStatus');
        if (resp) {
            status.innerHTML=resp.htmlStatus;
            if (resp.success) {
	        parent.location.href=resp.url;
                return;
            } 
        }
        status.innerHTML='<em class="error">Error hiding frame</em>'; 
}

function submitSignin(formId) {
	//var qs = ajaxObj.getForm(formId);
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=Signin"+qs, respSignin);
}

var loginCallback = null;
function respSignin(resp) {
	var formStatus = document.getElementById('signinAjaxFormStatus');
	if(resp){
		formStatus.innerHTML = resp.message;
		if(resp.success){
			destroyPop('signinAjaxPopup');
                        var miniMemberBar = document.getElementById('miniMemberBar');
                        var miniMember = document.getElementById('miniMember');
                        if(miniMemberBar != null) {
                            pushHTML('miniMemberBar', 'framesignedin');
                        }else if (miniMember != null) {
                            pushHTML('miniMember', 'profilesignedin');
                        } else {
			    pushHTML('member','signedin');
                        }
			if(onLoginVoteId){
				submitVote(onLoginVoteId);
			}
			if(loginCallback){
				loginCallback();
			}
			retrieveVoteCounts();
			//window.location.reload();
		}
		return;
	}
	formStatus.innerHTML = 'Error Logging In';
}

function submitResetPassword(formId) {
        //var qs = ajaxObj.getForm(formId);
        //ajaxObj.method = "POST";
        //ajaxObj.format = "JSON";
        //ajaxObj.call("action=ResetPassword"+qs, respResetPassword);
}

function respResetPassword(resp){
        var formStatus = document.getElementById('forgotPasswordAjaxFormStatus');
        if(resp){
               formStatus.innerHTML = resp.message;
               if(resp.success){
                     destroyPop('forgotPasswordAjaxPopup');
                     pushHTML('member', 'passwordreset');
               }
               return;
        }
        formStatus.innerHTML = 'Error Resetting Password';
}

function refreshDlContent(divid) {
        var qs="divid="+divid;
        //ajaxObj.method="POST";
        //ajaxObj.format="JSON";
        //ajaxObj.call("action=RefreshDl&"+qs,refreshDlContentResp);
}

function refreshDlContentResp(resp) {
        if (resp.content) {
        	document.getElementById(resp.divid).innerHTML=resp.content;
        }
}

function checkSubmitUrl(url){
	document.getElementById('urlCheckStatus').innerHTML = 'Validating URL';
	processing = 0;
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=CheckSubmitUrl&url="+encodeURIComponent(url), submitUrlResponse);
}

function submitUrlResponse(resp){
	var status = document.getElementById('urlCheckStatus');
	
	if(resp){
		status.innerHTML = resp.htmlStatus;
	}
	else {
		status.innerHTML = '<span style="color:red;">URL Check Failed</span>';
	}
	
	return;
}

function checkSubmitText(text){
	processing = 0;
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=CheckSubmitText&text="+encodeURIComponent(text),submitTextResponse);
}

function submitTextResponse(resp){
	if(resp){
		var status = document.getElementById('textCheckStatus');
		status.innerHTML = resp.htmlStatus;
	}
	
	return;
}

function checkSubmitTitle(title){
	document.getElementById('titleCheckStatus').innerHTML = 'Validating Title';
	processing = 0;
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=CheckSubmitTitle&title="+encodeURIComponent(title), submitTitleResponse);
}

function submitTitleResponse(resp){
	var status = document.getElementById('titleCheckStatus');

	if(resp){
		status.innerHTML = resp.htmlStatus;
	}
	else {
		status.innerHTML = '<span style="color:red;">Title Check Failed</span>';
	}

	return;
}

function checkSubmitChannel(){
	var channel = document.getElementById('storyChannel').value
 //	document.getElementById('channelCheckStatus').innerHTML = 'Validating Channel '  + channel;
	processing = 0;
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=CheckSubmitChannel&channel="+channel, submitChannelResponse);
}

function submitChannelResponse(resp){
	var status = document.getElementById('channelCheckStatus');
	if(resp){
		status.innerHTML = resp.htmlStatus;
	}
	return;
}

function trackOutbound(storyId){
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=OutboundStory&storyId="+storyId, trackOutboundResponse);
	return true;
}

function trackOutboundResponse(resp){
	return true;
}

//For tracker
var timeUntilUpdate=0;
var trackCheckInt=0;
function updateTrackerEvents(numevents,eventtype,divname,directory,trspeed,pagenum,trackchannel){
     timeUntilUpdate=timeUntilUpdate - trackCheckInt;
     if (timeUntilUpdate <=0) {
         timeUntilUpdate=trspeed;
         //ajaxObj.method = "POST";
         //ajaxObj.format = "JSON";
         //ajaxObj.call("action=UpdateTrackerList&numevents="+numevents+"&divid="+divname+"&directory="+directory+"&eventtype="+eventtype+"&page="+pagenum+"&trackchannel='"+trackchannel+"'", updateTrackerEventResponse);
     }
     var seconds = eval (timeUntilUpdate / 1000);
     if (seconds < 10) {
         seconds = "0" + seconds;
     } else {
         seconds = "" + seconds;
     }
     document.getElementById('secondsUntilNextUpdate').innerHTML=seconds;
     if (tprunning) {
         setTimeout("updateTrackerEvents("+numevents+", "+eventtype+", '"+divname+"', '"+directory+"', "+trspeed+", "+pagenum+", '"+trackchannel+"')", trackCheckInt);
     }
}

function updateTrackerEventResponse(resp){
     for(i=0; i<resp.limit; i++) {
        var eventcontent=document.getElementById(resp.divid+'Content'+i);
        if (eventcontent != null) {
           if (i==0) {
              eventcontent.setAttribute('class', 'track trackOn');
           } else {
              eventcontent.setAttribute('class', 'track');
           }
           eventcontent.innerHTML=eval('resp.eventcontent'+i);
        }
    }
}

function updateMiniTrackerEvent(divname,directory,mtrpos,mtrspeed,mtrnum){
    var nextpos=mtrpos + 1;
    if(mtrpos >= 30 || mtrcache == null || eval('mtrcache.eventcontent'+nextpos) == null){
      mtrpos=0;
      //ajaxObj.method="POST";
      //ajaxObj.format="JSON";
      //ajaxObj.call("action=UpdateTrackerList&numevents=30&divid="+divname+"&directory="+directory+"&eventtype=0", updateMiniTrackerEventResponse);
    } else {
      mtrpos = nextpos;
      var fillPos=0;
      for (i=0; i < mtrnum; i++) {
      	var eventcontent = document.getElementById(divname+'Content'+i);
	if (eval('mtrcache.eventcontent'+(mtrpos + i)) != null) {
		eventcontent.innerHTML=eval('mtrcache.eventcontent'+(mtrpos + i));
	} else {
		fillPos = fillPos + 1;
		eventcontent.innerHTML=eval('mtrcache.eventcontent'+(fillPos));
	}
      }
    }

    setTimeout("updateMiniTrackerEvent('tphp', 'tracker', "+mtrpos+", "+mtrspeed+", "+mtrnum+")", mtrspeed);
}

function updateMiniTrackerEventResponse(resp){
    resp.divid="tphp";
    mtrcache=resp;
    var eventcontent=document.getElementById(resp.divid+'Content0');
    if (resp.eventcontent0 != null) {
    	eventcontent.innerHTML=eval('resp.eventcontent0');
    }
    var eventcontent1=document.getElementById(resp.divid+'Content1');
    if (resp.eventcontent1 != null) {
        eventcontent1.innerHTML=eval('resp.eventcontent1');
    }
}

//For comment
function submitCommentRating(bit,commentId){
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=RateComment&rating="+bit+"&commentId="+commentId, submitCommentRatingResponse);
}

function submitCommentRatingResponse(resp){
	if(resp){
		if(!resp.loggedIn){
                        var docHeight=document.body.scrollTop;
                        document.location.href=secureHost+"/signin/?y="+docHeight+"&loginaction=commentrating&rating="+resp.rating+"&id="+resp.commentId+"&backurl="+escape(document.location.href);
			return;
		}

			var status = document.getElementById('commentStatus'+resp.commentId);
		if(resp.success){
	        if (resp.rating >= 1) {
	           var respText='You gave this comment a positive vote.';
	        } else {
	           var respText='You gave this comment a negative vote.';
				status.innerHTML = respText;
	           document.getElementById('comment-body'+resp.commentId).style.display = 'none';
	        }
			document.getElementById('commentRating'+resp.commentId).innerHTML = resp.modifiedRating;
                        document.getElementById('rateSpan'+resp.commentId).innerHTML=respText;
                        document.getElementById('rateSpan'+resp.commentId).className="rated";
			return;
		}
		status.innerHTML = 'Error rating comment';
	}
}

function blockMessages(memberId,divid,lim,page){
        processing=0;
	//ajaxObj.method="POST";
	//ajaxObj.format="JSON";
	//ajaxObj.call("action=BlockMessages&memberId="+memberId+"&divid="+divid+"&lim="+lim+"&page="+page,blockMessageResponse);
}

function blockMessageResponse(resp){
	if (resp) {
		if (resp.success) { 
			document.getElementById(resp.divid).innerHTML=resp.contents;
			
			if (document.getElementById('newMessageCount') && resp.newMessageCount >= 0){
				document.getElementById('newMessageCount').innerHTML = resp.newMessageCount;
				if (resp.newMessageCount == 1){
					document.getElementById('newMessageCountPlural').style.display = 'none';
				}
				else {
					document.getElementById('newMessageCountPlural').style.display = '';
				}
			}

			if (resp.totalcount <= resp.Limit * (resp.page-1) && resp.page > 1) {
				// all messages from this page are removed, back up
				document.location.href = resp.navurlprefix + (resp.page-1)
			} else {
				// update the navigation bar
				document.getElementById('pageNavTop').innerHTML = resp.navBar;
				document.getElementById('pageNavBottom').innerHTML = resp.navBar;
			}
		}
	}

}

function blockCommenter(commentId){
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=BlockComment&commentId="+commentId, blockCommenterResponse);
}

function blockCommenterResponse(resp){
	var status = document.getElementById('commentStatus'+resp.commentId);
	if(resp){
		status.innerHTML = resp.htmlResponse;
		if(!resp.loggedIn){
                        var docHeight=document.body.scrollTop;
                        document.location.href=secureHost+"/signin/?y="+docHeight+"&loginaction=blockcomment&id="+resp.commentId+"&backurl="+escape(document.location.href);
			return;
		}
		
		return;
	}
	status.innerHTML = 'Error rating comment';
}

function editComment(commentId) {
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=EditComment&commentId="+commentId, editCommentResponse);
}

function editCommentResponse(resp){
	if (resp) {
		if (resp.success){
			document.getElementById('comment'+resp.commentId).innerHTML = resp.contents;
			document.getElementById('editSpan'+resp.commentId).innerHTML = ' ';
		}
		else {
			document.getElementById('editSpan'+resp.commentId).innerHTML = '<em>'+resp.error+'</em>';
		}
	}
}

function addStar(commentId){
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=ChangeStars&commentId="+commentId+"&change=up", starResponse);
}

function subStar(commentId){
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=ChangeStars&commentId="+commentId+"&change=dn", starResponse);
}

function starResponse(resp){
	if(resp){
		document.getElementById('commentStars'+resp.commentId+'Status').innerHTML = resp.htmlResponse;
		var stars = document.getElementById('commentStars'+resp.commentId);
		if(resp.stars){
			stars.innerHTML = resp.stars;
		}
	}
}

function commentValidate(commentform){
	//var qs = ajaxObj.getForm(commentform);
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=ValidateComment"+qs, commentValidateResponse);
	document.getElementById('postId').value = document.getElementById('storyId').value;
}

function commentValidateResponse(resp){
	if (resp) {
		if (resp.valid) {
			//Check for the vote...
			var storyId = document.getElementById('storyId').value;
			if (document.getElementById('commentVoteCheckbox') != undefined) {
				var commentVoteCheckbox = document.getElementById('commentVoteCheckbox').checked;
				if (commentVoteCheckbox == 1) {
					submitVote(storyId);
				}
			}
			document.getElementById(resp.formName).submit();
		} else {
			document.getElementById('inlineCommentTextStatus'+resp.parentCommentId).innerHTML = resp.statusText;
		}
	}
}

function sendMessage(divid,alias,statid){
	pushHTML(divid,'sendmessageform','alias='+alias+'&divid='+divid+'&statid='+statid);
}

function sendMessageSubmit(){
	//var qs = ajaxObj.getForm('sendMessageForm');
	//ajaxObj.method="POST";
	//ajaxObj.format="JSON";
	//ajaxObj.call("action=SendMsg"+qs, sendMessageResponse);
}

function sendMessageResponse(resp){
	if (resp){
		var e = document.getElementById(resp.divid);
		e.innerHTML='';
		if (resp.divid != resp.statid) e.style.display='none';
		var r = document.getElementById(resp.statid);
		r.innerHTML=resp.message;
		r.className="status";
		r.onClick="";
	}
}

function showMessageThread(rootMessageId, myId, lim, page) {
	//ajaxObj.method="POST";
	//ajaxObj.format="JSON";
	//ajaxObj.call("action=ShowMessageThread&rootMessageId="+rootMessageId+"&myId="+myId+"&lim="+lim+"&page="+page, showMessageThreadResponse);
}

function showMessageThreadResponse(resp) {
	if (resp) {
		if (resp.success) {
			threadDiv = document.getElementById('thread'+resp.rootMessageId);
			threadDiv.style.border = '2px #7fbdc2 solid';
			threadDiv.innerHTML = resp.content;
		}
	}
}

//For comment
function reportComment(commentId){
	pushHTML('postCommDisplay'+commentId,'reportcommentpop','commentId='+commentId);
}

function reportCommentSubmit(){
	//var qs = ajaxObj.getForm('reportCommentPop');
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=ReportComment"+qs, reportCommResponse);
}

function reportCommResponse(resp){
	if(resp){
		if(resp.success){
			var e = document.getElementById('postCommDisplay'+resp.commentId);
			e.innerHTML = '';
			e.style.display = 'none';
			var r = document.getElementById('commentStatus'+resp.commentId);
			r.innerHTML=resp.htmlStatus;
			r.className="status";
		}
	}
}

//For story
function reportStory(storyId){
	pushHTML('postDisplay'+storyId,'reportstorypop','storyId='+storyId);
	//getFormHTML('reportAjaxPop','reportstorypop','storyId='+storyId);
}
function closeDupe(storyId){
	pushHTML('postDisplay'+storyId,'closedupepop','storyId='+storyId);
}
function killSpam(storyId){
	pushHTML('postDisplay'+storyId,'killspampop','storyId='+storyId);
}
function redirectStory(storyId){
	pushHTML('postDisplay'+storyId,'redirectstorypop','storyId='+storyId);
}

function reportStorySubmit(){
	//var qs = ajaxObj.getForm('reportStoryPop');
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=ReportStory"+qs, reportResponse);
}

function reportResponse(resp){
	if(resp){
		if(resp.success){
			var e = document.getElementById('postDisplay'+resp.storyId);
			e.innerHTML = '';
			e.style.display = 'none';
			var r = document.getElementById('reportStoryButtons');
			r.innerHTML = resp.htmlStatus;
			r.className = "status";
		}
	}
}

function closeDupeSubmit(){
	//var qs = ajaxObj.getForm('closeDupePop');
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=CloseDupe"+qs, closeDupeResponse);
}

function closeDupeResponse(resp){
	if(resp){
		if(resp.success){
			var e = document.getElementById('postDisplay'+resp.storyId);
			e.innerHTML = '';
			e.style.display = 'none';
			var r = document.getElementById('reportStoryButtons');
			r.innerHTML = resp.htmlStatus;
			r.className = "status";
		}
	}
}

function killSpamSubmit(){
	//var qs = ajaxObj.getForm('killSpamPop');
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=KillSpam"+qs, killSpamResponse);
}

function killSpamResponse(resp){
	if(resp){
		if(resp.success){
			var e = document.getElementById('postDisplay'+resp.storyId);
			e.innerHTML = '';
			e.style.display = 'none';
			var r = document.getElementById('reportStoryButtons');
			r.innerHTML = resp.htmlStatus;
			r.className = "status";
		}
	}
}

function redirectStorySubmit(){
	//var qs = ajaxObj.getForm('redirectStoryPop');
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=RedirectStory"+qs, redirectStoryResponse);
}

function redirectStoryResponse(resp){
	if(resp){
		if(resp.success){
			document.location.href = document.location.href;
		}
		else {
			var r = document.getElementById('reportStoryButtons');
			r.innerHTML = resp.htmlStatus;
			r.className = "error";
		}
	}
}

//For registration only
function checkItem(itemid,itemclass){
	document.getElementById(itemid+'Status').innerHTML = 'Validating Alias';
	var itemValue = document.getElementById(itemid).value;
	processing = 0;
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action="+itemclass+"&item="+itemValue+"&itemid="+itemid, checkItemResponse);
}

function checkItemResponse(resp){
	var status = document.getElementById(resp.itemid+'Status');
	if(resp){
		status.innerHTML = resp.htmlStatus;
		if(resp.exists){
			//button.disabled = true;
		} else {
			//button.disabled = false;
		}
		return;
	}
	status.innerHTML = '<span style="color:red;">Alias Check Failed</span>';
}



//Voting Magic
function retrieveVoteCounts(){
	var votes = scrapeStories();
	
	if(votes.length == 0){
		clearInterval(voteInterval);
		return;
	}

	var qs = votes.join(",");
	
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=GetVoteStats&indexes="+qs, applyVoteCounts);

}

function applyVoteCounts(resp){
	if(resp){
		for(i in resp){
			var info = resp[i];
			var countarr = document.getElementsByName('voteCount'+info.storyId);
			//var count = document.getElementById('voteCount'+info.storyId);
			for (i=0; i<countarr.length; i++) {
			    countarr[i].innerHTML=info.votes;
			}

			//if(count){
			//	count.innerHTML = info.votes;
			//}

			//If memberId isn't null then change to voted.
			if(info.memberId){
			        var statusarr = document.getElementsByName('voteStatus'+info.storyId);
				for (j=0; j<statusarr.length; j++) {
				    if (statusarr[i]) {
					statusarr[i].innerHTML = '<img src="'+ihost+'/media/iconVoteSwitch.gif" width="10" height="10" border="0" /> Voted';
			            }
				}
				var badgearr = document.getElementsByName('voteBadge'+info.storyId);
				for (k=0; k < badgearr.length; k++) {
				     if (badgearr[k]) {
				         badgearr[k].className='voted';
			             }
				}
				//var status = document.getElementById('voteStatus'+info.storyId);
				//var voteBadge = document.getElementById('voteBadge'+info.storyId);
				//if(status){
			//		status.innerHTML = '<img src="/media/iconVoteSwitch.gif" width="10" height="10" border="0" /> Voted';
			//	}
			//	if(voteBadge){
			//		voteBadge.className = 'voted';
			//	}
			}
		}
	}
}


function scrapeStories(){
	var elems = document.getElementsByTagName('span');
	var votes = new Array();
	
	for(var i = 0; i < elems.length; i++){
		if(elems[i].id){
			var idStr = elems[i].id;
			if(idStr.substr(0,9) == 'voteCount'){
				votes.push(idStr.substr(9));
			}
		}
	}
	return votes;
}


function previewSubmit(){
	//var qs = ajaxObj.getForm('submitStory');
	//ajaxObj.method = "POST";
	//ajaxObj.format = "JSON";
	//ajaxObj.call("action=PreviewSubmit"+qs, previewResponse);
	return false;
}

function previewResponse(resp){
	document.getElementById('submissionPreview').innerHTML = resp.preview;
	document.getElementById('storySubmitButtonTop').disabled=false;
        window.location.href="#preview";
}


//Multi use functions
//Hack to use the same AJAX class for pulling templates
var pushDivId = '';
function pushHTML(divId,template){

	if(arguments[2]){
		template += "&" + arguments[2];
	}

	pushDivId = divId;
	//ajaxObj.method = "POST";
	//ajaxObj.format = "TEXT";
	//ajaxObj.call("action=PullTemplate&templateName="+template, pushHTMLResponse);	
}

function pushHTMLResponse(resp){
	if(resp){
		var e = document.getElementById(pushDivId);
		e.innerHTML = resp;
		e.style.display = 'block';
	}
}

function getFormHTML(popName,templateName){
	var popDiv = createPop(popName,'');
	
	if(arguments[2]){
		templateName += "&" + arguments[2];
	}

	//ajaxObj.method = "POST";
	//ajaxObj.format = "TEXT";
	//ajaxObj.call("action=PullTemplate&templateName="+templateName, getFormHTMLResponse);
}

function getFormHTMLResponse(resp){
	if(resp){
		document.getElementById('displayNode').innerHTML = resp;
		return;
	}
}

var processingIndex = [];
function onFinishTyping(e){
	var obj;
	if(e.keyCode && e.keyCode == 9) return;
	if(e.originalTarget){
		obj = e.originalTarget;
	} else {
		obj = e.srcElement;
	}
	
	if(!processingIndex[obj.id]){
		processingIndex[obj.id] = setInterval("finishTyping('"+obj.id+"')",500);
		return;
	}

	clearInterval(processingIndex[obj.id]);
	processingIndex[obj.id] = setInterval("finishTyping('"+obj.id+"')",500);
}

function finishTyping(objid){
	clearInterval(processingIndex[objid]);
	eval(finishTypingArr[objid]);
}

var finishTypingArr = [];
function finishTypingCallback(obj,callback){
	finishTypingArr[obj.id,callback];
}

function charCountdown(objId,displayId,limit){
	var tb = document.getElementById(objId);
	var hb = document.getElementById(displayId);

//	if(tb.value.length > limit){
//		tb.value = tb.value.substr(0,limit);
//	}

	if (tb.value.length > limit){
		hb.innerHTML = (tb.value.length-limit) + ' character';
		if (tb.value.length-limit != 1) hb.innerHTML += 's';
		hb.innerHTML += ' over comment length limit.';
	}
	else {
		hb.innerHTML = limit-tb.value.length+' character';
		if (tb.value.length != (limit - 1)) hb.innerHTML += 's';
		hb.innerHTML += ' left.';
	}
	return tb.value.length <= limit;
}

function createPop(name,className){
	//var popDiv = document.createElement('div');
	//Hackey Shortcut
	lightBox();
	var popDiv = document.getElementById('displayNode');

	m = measure(popDiv);

	popDiv.style.top = ((m.scrollY+(m.height/2))-(m.eHeight/2))+"px";
	popDiv.style.left = ((m.scrollX+(m.width/2))-(m.eWidth/2))+"px";

	popDiv.style.visibility = "visible";
	popDiv.innerHTML = 'Please Wait...';
	//popDiv.style.classname = className;
	return popDiv;
}

function lightBox(){
	var lightBox = document.getElementById("lightBox");
	lightBox.style.display = "block";
	lightBox.style.position = "absolute";

	//IE Needs this
	lightBox.style.left = 0;
	lightBox.style.right = 0;

	m = measure();

	lightBox.style.height = m.contentHeight+"px";
	lightBox.style.width = m.contentWidth+"px";

	lightBox.style.backgroundColor = "black";
	lightBox.style.zIndex = 5;
	lightBox.onclick = function(){
		destroyPop('');
	}

	//new Function('this.style.display = "none"');
	
	if(document.all){
		lightBox.style.filter = "alpha(opacity=70)";
	} else {
		lightBox.style.opacity = 0.7;
	}
	
	//Turn off elemebts that punch through the div.
	var objTags = document.getElementsByTagName('object');
	for(var i = 0; i < objTags.length; i++){
		var tag = objTags[i];
		tag.style.display = 'none';
	}
	
	return;
}

function destroyPop(popName){
	//Actually remove this
	var lightBox = document.getElementById("lightBox");
	lightBox.style.display = "none";
	var popDiv = document.getElementById('displayNode');
	popDiv.style.visibility = "hidden";
	popDiv.style.innerHTML = "";

	//Turn on elemebts that punch through the div.
	var objTags = document.getElementsByTagName('object');
	for(var i = 0; i < objTags.length; i++){
		var tag = objTags[i];
		tag.style.display = 'block';
	}
}

/*
var DWO = {
	Write:document.write,
	CurrentStackItem:"unset",
	Capture:function(str){
		if(!DWO.DisplayStack[DWO.CurrentStackItem]){
			DWO.DisplayStack[DWO.CurrentStackItem] = [];
		}
		DWO.DisplayStack[DWO.CurrentStackItem].push(str);
		//document.writeln(str);
	},
	delayedWrite:function(func,stack){
		DWO.CurrentStackItem = stack;
		eval(func);
	},
	DisplayStack:[],
	ScriptRegex:new RegExp("<script.*?src=[\"|'](.*)?[\"|']","im"),
	regurg:function(){
		for(i in DWO.DisplayStack){
			var str = DWO.DisplayStack[i].join("");
			DWO.DisplayStack[i] = [];
			if(DWO.ScriptRegex.exec(str)){
				DWO.stripNestedScripts(str);
				return DWO.regurg();
			}

			//DWO.insertScriptBlock(i,newJs);
			//document.getElementById(i).innerHTML = str;
			//document.writeln(str);
		}
		//alert(DWO.DisplayStack.length);
	},
	stripNestedScripts:function(str){
		var srcMatch = DWO.ScriptRegex.exec(str);
		if(srcMatch){
			req.open("GET", "/util/geturl.php?url="+srcMatch[1], false);
			req.send(null);
			return DWO.stripNestedScripts(req.responseText);
		}
		DWO.insertScriptBlock(i,str);
		return str;
	},
	insertScriptBlock:function(elemId,newJs){
		var html_div = document.getElementById(elemId);
		var js = document.createElement('script');
		for(x in js){
			//document.writeln(x+"<br>");
		}
		js.setAttribute('language', 'javascript');
		js.setAttribute('type', 'text/javascript');
		js.textContent = newJs;
		html_div.appendChild(js);
	}
}

if (window.XMLHttpRequest) {
	req = new XMLHttpRequest();
} else if(window.ActiveXObject){
	req = new ActiveXObject("Microsoft.XMLHTTP");
}

document.write = DWO.Capture;
*/

function measure(elem){
	var m = new Array();
	//IE stats
	if(document.all){
		m.contentHeight = document.body.clientHeight;
		m.contentWidth = document.body.clientWidth;
		m.height = document.documentElement.offsetHeight;
		m.width = document.documentElement.offsetWidth;
		m.scrollX = document.documentElement.scrollLeft;
		m.scrollY = document.documentElement.scrollTop;
		if(elem){
			m.eContentHeight = elem.clientHeight;
			m.eContentWidth = elem.clientWidth;
			m.eHeight = elem.offsetHeight;
			m.eWidth = elem.offsetWidth;
			m.eScrollX = elem.scrollLeft;
			m.eScrollY = elem.scrollTop;
		}

	} else {	
		//Moz
		m.contentHeight = document.body.offsetHeight;
		m.contentWidth = document.body.offsetWidth;
		m.height = window.innerHeight;
		m.width = window.innerWidth;
		m.scrollX = window.pageXOffset;
		m.scrollY = window.pageYOffset;
		if(elem){
			m.eContentHeight = elem.offsetHeight;
			m.eContentWidth = elem.offsetWidth;
			m.eHeight = elem.offsetHeight;
			m.eWidth = elem.offsetWidth;
			m.eScrollX = elem.pageXOffset;
			m.eScrollY = elem.pageYOffset;
		}
	}
	return m;
}

function addEvent(obj, eventType,fn, useCapture)
{
	if (obj.addEventListener) {
		obj.addEventListener(eventType, fn, useCapture);
		return true;
	} else {
		if (obj.attachEvent) {
			var r = obj.attachEvent("on"+eventType, fn);
			return r;
		}
	}
}

var dlindex=0;
var dlrunning=true;
var dlrotationcount=0;

function changeDlTab(index){
    dlrunning=false;
    dlindex=index;
    return switchTab('dlTabs', dlindex, 'dl', 'dlContentWrapper');
}

function changeAdTab(index){
    dlrunning=false;
    dlindex=index;
    return switchTab('dlTabs', dlindex, 'dl', 'dlContentWrapper');
}

function changeRevTab(index){
    dlrunning=false;
    dlindex=index;
    return switchTab('dlTabs', dlindex, 'dl-rev', 'dlContentWrapper');
}
function changeCitTab(index){
    dlrunning=false;
    dlindex=index;
    return switchTab('dlTabs', dlindex, 'dl-cit', 'dlContentWrapper');
}


function rotateContent() {
    if(dlrunning) {
       if (dlindex > dlnumtabs) {
          dlindex = 0;
          if (dlrotate==0) {
             dlrotationcount=dlrotationcount + 1;
             if (dlrotationcount >= dlnumrotations) {
                refreshDlContent('dlAll');
                dlrotationcount=0;
                var keepgoing=true;
                var newdlnumtabs=0;
                while (keepgoing) {
                    if (document.getElementById('dlPrevImg'+newdlnumtabs) == null) {
			newdlnumtabs = newdlnumtabs - 1;
			keepgoing=false;
		    } else { newdlnumtabs = newdlnumtabs + 1; }
                }
                dlnumtabs=newdlnumtabs; 
             }
          }
       }
       switchTab('dlTabs', dlindex, 'dl', 'dlContentWrapper');
       dlindex++;
       setTimeout("rotateContent()", dlspeed);
    }
    return false;
}

function incrementContent(){
		if (dlrunning) {
			// If it's running, then dlindex is set to the next tab
			dlindex--;
		}
		
    dlrunning=false;
    dlindex=dlindex + 1;
    if (dlindex > dlnumtabs) { dlindex = 0; }
    for (i=0; i<=dlnumtabs; i++)
    {
       document.getElementById('dlPrevImg'+i).setAttribute('src', ihost+'/media/iconDlPrev.gif');
       document.getElementById('dlPauseImg'+i).setAttribute('src', ihost+'/media/iconDlPause.gif');
       document.getElementById('dlPlayImg'+i).setAttribute('src', ihost+'/media/iconDlPlay.gif');
       document.getElementById('dlNextImg'+i).setAttribute('src', ihost+'/media/iconDlNextOn.gif');
    }
    switchTab('dlTabs', dlindex, 'dl', 'dlContentWrapper');
    return false;
}

function decrementContent(){
		if (dlrunning) {
			// If it's running, then dlindex is set to the next tab
			dlindex--;
		}

    dlrunning=false;
    dlindex=dlindex - 1;
    if (dlindex < 0) { dlindex = dlnumtabs; }
    for (i=0; i<=dlnumtabs; i++)
    {
       document.getElementById('dlPrevImg'+i).setAttribute('src', ihost+'/media/iconDlPrevOn.gif');
       document.getElementById('dlPauseImg'+i).setAttribute('src', ihost+'/media/iconDlPause.gif');
       document.getElementById('dlPlayImg'+i).setAttribute('src', ihost+'/media/iconDlPlay.gif');
       document.getElementById('dlNextImg'+i).setAttribute('src', ihost+'/media/iconDlNext.gif');
    }
    switchTab('dlTabs', dlindex, 'dl', 'dlContentWrapper');
    return false;
}

function stopRotateContent(){
    dlrunning=false;
    for (i=0; i<=dlnumtabs; i++)
    {
       document.getElementById('dlPrevImg'+i).setAttribute('src', ihost+'/media/iconDlPrev.gif');
       document.getElementById('dlPauseImg'+i).setAttribute('src', ihost+'/media/iconDlPauseOn.gif');
       document.getElementById('dlPlayImg'+i).setAttribute('src', ihost+'/media/iconDlPlay.gif');
       document.getElementById('dlNextImg'+i).setAttribute('src', ihost+'/media/iconDlNext.gif');
    }
    return false;
}

function startRotateContent(){
    dlrunning=true;
    for (i=0; i<=dlnumtabs; i++)
    {
       document.getElementById('dlPrevImg'+i).setAttribute('src', ihost+'/media/iconDlPrev.gif');
       document.getElementById('dlPauseImg'+i).setAttribute('src', ihost+'/media/iconDlPause.gif');
       document.getElementById('dlPlayImg'+i).setAttribute('src', ihost+'/media/iconDlPlayOn.gif');
       document.getElementById('dlNextImg'+i).setAttribute('src', ihost+'/media/iconDlNext.gif');
    }
    rotateContent();
}

function stopTrackerContent(){
    tprunning=false;
    document.getElementById('trPlayImg').setAttribute('src', ihost+'/media/iconDlPlay.gif');
    document.getElementById('trPauseImg').setAttribute('src', ihost+'/media/iconDlPauseOn.gif');
    return false;
}

function startTrackerPageContent(){
    tprunning=true;
    document.getElementById('trPlayImg').setAttribute('src', ihost+'/media/iconDlPlayOn.gif');
    document.getElementById('trPauseImg').setAttribute('src', ihost+'/media/iconDlPause.gif');
    timeUntilUpdate=trspeed;
    trackCheckInt=1000;
    setTimeout("updateTrackerEvents("+numevents+", "+eventtype+", 'tp', 'trackerpage', "+trspeed+","+trackerpagenum+", '"+trackerchannel+"')", trackCheckInt);
    return false;
}

function startMiniTrackerContent(){
    setTimeout("updateMiniTrackerEvent('tphp', 'tracker', "+mtrpos+", "+mtrspeed+", "+mtrnum+")", mtrspeed);
    return false;
}


function switchTab(tabMenu,activeTab,contentWrap,contentClass) {
	/*
	ARGS
	----
	tabMenu = the UL with the tabs
	activeTab = the tab/content you're switching to
	contentWrap = the element around the content of the box
	contentClass = the className for the divs (they have to be divs) you're switching to/from
	*/
	var menu = document.getElementById(tabMenu);
	var menuTabs = menu.getElementsByTagName("li");
	var contentWrap = document.getElementById(contentWrap);
	var contentAreas = contentWrap.getElementsByTagName("div");

	for(var i=0; i<menuTabs.length; i++) {
		menuTabs[i].className = "";
		if(menuTabs[i].id.indexOf(activeTab)>-1) {
			menuTabs[i].className = "on";
		}
	}
	for(j=0;j<contentAreas.length;j++) {
		if(contentAreas[j].className.indexOf(contentClass)>-1 ) {
			contentAreas[j].className = contentClass + " off";
			if(contentAreas[j].id.indexOf(activeTab)>-1) {
				contentAreas[j].className = contentClass;
			}
		}
	}

	return false;
}

var currentframepos=0;
function switchFrameStory(pos) {
     //alert('calling switchFrameStory('+pos+')');
     currentframepos=pos;
     for(var i=0; i<numRecs; i++) {
        var framediv=document.getElementById('frameElem'+i);
        if(i==pos){
            framediv.className="frameContent on";
        }else{
            framediv.className="frameContent";
        }
     }
     document.getElementById('back').setAttribute("href", storyUrlArr[pos]);
     document.getElementById('close').setAttribute("href", urlArr[pos]);
     parent._right.location=urlArr[pos];

     return false;
}

function createCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name){
	createCookie(name,"",-1);
}

function selectAvatar(avatarNum){
	for(var i=2; i <= 6; i++) {
		if (avatarNum == i) {
			document.getElementById( 'defaultAvatar'+i).style.border='2px #007c85 solid';
		} else {
			document.getElementById('defaultAvatar'+i).style.border='';
		}
	}
}	

function checkMail(){
	processing=0;
/*	var mailChecker = ajaxObj;
	mailChecker.method="POST";
	mailChecker.format="JSON";
	mailChecker.call("action=CheckMail&interval="+checkMailInterval,checkMailResponse);*/
}

function checkMailResponse(resp){
	if (resp.success){
		if (resp.messages > 0){
			document.getElementById('member-notify').style.display = '';
			if (document.getElementById('messageCenterLink')){
				document.getElementById('messageCenterLink').innerHTML = getMessageCenterLink(resp.totalNewMessages, resp.alias);
			}
		}
	}
}

function getMessageCenterLink(newMessageCount, alias){
	var link = '<a href="/member/'+alias+'/messages/" title="';

	if (newMessageCount == 0){
		link += 'Message Center">Message Center';
	}
	else {
		link += 'New Messages"><strong>'+newMessageCount+'</strong> new message';

		if (newMessageCount > 1){
			link += 's';
		}
	}

	link += '</a>';

	return link;
}

function closeMsgAlert(disableAlerts){
	document.getElementById('member-notify').style.display = 'none';
	processing=0;
	//ajaxObj.method="POST";
	//ajaxObj.format="JSON";
	//ajaxObj.call("action=CloseMsgAlert&disable="+disableAlerts,closeMsgAlertResponse);
}

function closeMsgAlertResponse(resp){
}

function playInlineVideo(videoId, divId){
	processing=0;
	//ajaxObj.method="POST";
	//ajaxObj.format="JSON";
	//ajaxObj.call("action=PlayInlineVideo&videoId=" + videoId + "&divId="+divId, playInlineVideoResponse);
}

function playInlineVideoResponse(resp){
	if (resp.success){
		document.getElementById(resp.divId).innerHTML = resp.contents;
		document.getElementById(resp.divId).style.display = '';
	}
}

function getVideoEmbedCode(guid, size){
	document.getElementById('embedCode'+guid).innerHTML = 'Loading embed code...';
	document.getElementById('embedCode'+guid).style.display = '';
	processing=0;
	//ajaxObj.method="POST";
	//ajaxObj.format="JSON";
	//ajaxObj.call("action=GetVideoEmbedCode&guid=" + guid + "&size="+size, getVideoEmbedCodeResponse);
}

function getVideoEmbedCodeResponse(resp){
	if (resp){
		// Firefox is smart and knows that a textarea can display < characters.
		// IE, on the other hand, is dumb.
		resp.embedCode = resp.embedCode.replace(/</g,'&lt;');
		document.getElementById('embedCode'+resp.guid).innerHTML = resp.embedCode;
		document.getElementById('embedCode'+resp.guid).style.display = '';
	}
}

function showUploadProgress() {
	var vidUpload = document.getElementById('storyVideo');

	if (vidUpload) {
		if (vidUpload.value != ''){
			document.getElementById('submitButtons').style.display = 'none';
			document.getElementById('progressBar').style.display = '';
			// For IE - All animations are stopped when a form is submitted, so
			// so we reset the img after the submit.
			document.getElementById('progressBarAnimation').src = ihost + "/media/progressBar.gif";
		}
	}
}

function findPosition(obj) {
	var posLeft = posTop = 0;

	if (obj.offsetParent) {
		posLeft = obj.offsetLeft;
		posRight = obj.offsetRight;
		obj = obj.offsetParent;
		while (obj != null) {
			posLeft += obj.offsetLeft;
			posTop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}

	return [posLeft, posTop];
}

function matchMember(partial) {
       processing=0;
       //ajaxObj.method="POST";
       //ajaxObj.format="JSON";
       //ajaxObj.call("action=MatchMember&partial="+partial, matchMemberResponse);
}

function matchMemberResponse(resp) {
	if(resp){
		if(resp.success) {
			var matchDiv = document.getElementById("matchDiv");
			var matchList = document.getElementById("matches");
			var sendToAlias = document.getElementById("sendToAlias");
			var page = document.getElementById("page");
			var matches = resp.content;
			var pos = findPosition(sendToAlias);
			var posPage = findPosition(page);
			if (matches.length > 0) {
				//alert(pos[0] + ' ' + posPage[0]);
				var offsetLeft = pos[0] - posPage[0] - 10;
				matchDiv.style.left = offsetLeft + "px";
				matchDiv.style.top = "3em";
				matchDiv.style.display = "block";
				matchList.options.length = 0; //reset the states dropdown
				matchList.size = matches.length > 20 ? 20 : matches.length;

				for (var i = 0; i < matches.length; i++) {
					var option = new Option()
					option.text = matches[i]['alias'];
					option.value = matches[i]['alias'];
					matchList.options[matchList.options.length] =new Option(matches[i]['alias']);
				}
			} else {
				matchDiv.style.display = "none";
			}
		}
	}
}

function MatchSelected(obj) {
	var matchDiv = document.getElementById("matchDiv");
	var sendToAlias = document.getElementById("sendToAlias");
	var matches = document.getElementById("matches");
	sendToAlias.value = matches.options[matches.selectedIndex].text;
	matchDiv.style.display = "none";
	sendToAlias.focus();
}

function openChatWindow() {
	chat = window.open('/chat', 'netscapechat', 'width=800,height=600');
	chat.focus();
}

function windowNavigate(win, url) {
	win.location = url;
	win.focus();
}

ai_ie=document.all;
function ai_ge(x) { return (document.getElementById(x)); }

//function below injects content element into target element - used in non-ie browsers
function ai_ad(pid, aid) {
	var par=ai_ge(pid);
	var adpt=ai_ge(aid);
	par.appendChild(adpt);
		adpt.style.position='inherit';
}

//function to determine x-coordinate of target element
function ai_posX(obj) {
	var left=0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			left+=obj.offsetLeft;
			obj=obj.offsetParent;
		}
	} else if (obj.x) { left+=obj.x }
	return left;
}

//function to determine y-coordinate of target element
function ai_posY (obj) {
	var top=0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			top+=obj.offsetTop;
			obj=obj.offsetParent;
		}
	} else if (obj.x) { top+=obj.y }
	return top;
}

//function to assign coordinates to content element
function ai_pos(targ,hid) {
	var targA=ai_ge(targ);
	var hidB=ai_ge(hid);
	hidB.style.display='block';
	hidB.style.top=ai_posY(targA)+'px';
	hidB.style.left=ai_posX(targA)+'px';
}

var ai_posArr=new Array();
//function to reposition absolutely positioned elements
function ai_poo() {
	if (ai_ie) {
		for (var i=0; i<ai_posArr.length;i++) {
			ai_pos(ai_posArr[i].targ,ai_posArr[i].hid);
		}
	}
}

//function to apply either DOM Injection (non-IE) or reposition (IE)
function ai_inj(targ,tad){
	if (!ai_ie) {
		ai_ad(targ,tad);
	} else {
		ai_pos(targ,tad);
		ai_posArr.push({targ:targ,hid:tad});
	}
}

function showComment(commentId) {
	element = document.getElementById('comment-body' + commentId);
	element.style.display = "block";
}

function hideComment(commentId) {
	element = document.getElementById('comment-body' + commentId);
	element.style.display = "none";
}
function openEditPhotoWindow()
{
	if(document.all||document.layers) window.open('/members/edit_photo.asp', 'homewin', 'width=480,height=380,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/members/edit_photo.asp','homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=480,height=380');
}
function openLocVidHelpWindow()
{
	if(document.all||document.layers) window.open('/reviews/loc_vid_help.asp', 'homewin', 'width=640,height=480,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/reviews/loc_vid_help.asp','homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=640,height=480');
}
function loadAddGal(vnuid,vnuname,vnucity)
{
	if(document.all||document.layers) window.open('/reviews/add_gal_pic.asp?vnuid=' + vnuid + '&vnuname=' + vnuname + '&vnucity=' + vnucity, 'homewin', 'width=640,height=480,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/reviews/add_gal_pic.asp?vnuid=' + vnuid + '&vnuname=' + vnuname + '&vnucity=' + vnucity,'homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=640,height=480');
}
function send_message(member)
{
	if(document.all||document.layers) window.open('/members/send_message.asp?user=' + member, 'homewin', 'width=450,height=400,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/members/send_message.asp?user=' + member ,'homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=450,height=400');
}
function post_guestbook(member)
{
	if(document.all||document.layers) window.open('/members/post_guestbook.asp?user=' + member, 'homewin', 'width=400,height=350,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/members/post_guestbook.asp?user=' + member ,'homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=400,height=350');
}
function edit_guestbook(member,message)
{
	if(document.all||document.layers) window.open('/members/post_guestbook.asp?user=' + member + '&msg=' + message, 'homewin', 'width=400,height=350,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/members/post_guestbook.asp?user=' + member + '&msg=' + message ,'homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=400,height=350');
}

function openPhoto(member,photo)
{
	if(document.all||document.layers) window.open('/members/view_photo.asp?name=' + member + '&photo=' + photo, 'homewin', 'width=500,height=480,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/members/view_photo.asp?name=' + member + '&photo=' + photo,'homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=500,height=480');
}
function openPhotoWindow(member,photo)
{
	if(document.all||document.layers) window.open('/members/view_photo.asp?name=' + member + '&photo=' + photo, 'homewin', 'width=500,height=460,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/members/view_photo.asp?name=' + member + '&photo=' + photo,'homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=500,height=460');
}

function checkRegistrationFields()
{

	missinginfo = "";

	var emailFilter=/^.+@.+\..{2,3}$/;
    var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/

    if (document.general_support.email.value.match(illegalChars)) {
    	missinginfo += "\n     -  Invalid Email Address";
    }
    if (!(emailFilter.test(document.general_support.email.value))) {
    	missinginfo += "\n     -  Invalid Email Address";
    }

	if (document.general_support.username.value == "") {
	missinginfo += "\n     -  Missing Username";
	}
	if (document.general_support.pwd.value == "") {
	missinginfo += "\n     -  Missing Password";
	}
	if (document.general_support.cpwd.value == "") {
	missinginfo += "\n     -  Missing Password Confirm";
	}
	if (document.general_support.pwd.value != document.general_support.cpwd.value) {
	missinginfo += "\n     -  Passwords don't match";
	}
	if (document.general_support.firstname.value == "") {
	missinginfo += "\n     -  Missing First Name";
	}
	if (document.general_support.sex.value == "") {
	missinginfo += "\n     -  Missing Sex";
	}
	if ( (document.general_support.sex.value != "M") && (document.general_support.sex.value != "m") && (document.general_support.sex.value != "F") && (document.general_support.sex.value != "f") ){
	missinginfo += "\n     -  Incorrect Sex (M or F only)";
	}
	if (document.general_support.city.value == "") {
	missinginfo += "\n     -  Missing City";
	}
	if (document.general_support.email.value == "") {
	missinginfo += "\n     -  Missing Email";
	}
    if ( ( (document.general_support.born.value < 1900 ) ||
    (document.general_support.born.value > 2000) ) && document.general_support.born.value != "") {
    missinginfo += "\n     -  Dodgy year of birth";
    }
    if (document.general_support.valcode.value.toUpperCase() != document.general_support.vc.value.toUpperCase()) {
	missinginfo += "\n     -  Incorrect validation code";
	}

	if (missinginfo != "") {
	missinginfo ="_____________________________\n" +
	"Sorry, please correct the following:\n" +
	missinginfo + "\n_____________________________" +
	"\nPlease re-enter and submit again!";
	alert(missinginfo);
	return false;
	}
	else return true;
}

function checkVenueFields()
{

	missinginfo = "";

	var emailFilter=/^.+@.+\..{2,3}$/;
    var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
    var illegalAddrChars= /[\<\>\;\:\\\/\"\[\]]/;
    var PhoneExp  = /^\+/;

    if (document.general_support.addr1.value.match(illegalAddrChars)) {
    	missinginfo += "\n     -  Invalid Address Line 1";
    }
	if (document.general_support.vnu.value == "") {
	missinginfo += "\n     -  Missing Venue Name";
	}
	if (document.general_support.addr1.value == "") {
	missinginfo += "\n     -  Missing Address Line 1";
	}
	if (document.general_support.city.value == "") {
	missinginfo += "\n     -  Missing City";
	}
	if ((document.general_support.country.value == "GBR") && (document.general_support.postalcode.value == "")) {
	missinginfo += "\n     -  For UK addresses, please enter the Post Code";
	}
	if ( (!(PhoneExp.test(document.general_support.tel1.value))) && (document.general_support.tel1.value != "") ) {
	missinginfo += "\n     -  Invalid telephone. must start with +country code";
	}

	if (missinginfo != "") {
	missinginfo ="_____________________________\n" +
	"Sorry, please correct the following:\n" +
	missinginfo + "\n_____________________________" +
	"\nPlease re-enter and submit again!";
	alert(missinginfo);
	return false;
	}
	else return true;
}

function checkReviewFields()
{
	missinginfo = "";

	var emailFilter=/^.+@.+\..{2,3}$/;
    var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/

	if (document.general_support.review.value == "") {
	missinginfo += "\n     -  Missing review text";
	}
	if (document.general_support.rating_overall.value == "") {
	missinginfo += "\n     -  Missing overall rating";
	}
    if ( ( (document.general_support.rating_service.value < 0 ) ||
    (document.general_support.rating_service.value > 5) ) && document.general_support.rating_service.value != "") {
    missinginfo += "\n     -  Dodgy service rating";
    }
    if ( ( (document.general_support.rating_food.value < 0 ) ||
    (document.general_support.rating_food.value > 5) ) && document.general_support.rating_food.value != "") {
    missinginfo += "\n     -  Dodgy food rating";
    }
    if ( ( (document.general_support.rating_atmosphere.value < 0 ) ||
    (document.general_support.rating_atmosphere.value > 5) ) && document.general_support.rating_atmosphere.value != "") {
    missinginfo += "\n     -  Dodgy atmosphere rating";
    }
    if ( ( (document.general_support.rating_wyd.value < 0 ) ||
    (document.general_support.rating_wyd.value > 5) ) && document.general_support.rating_wyd.value != "") {
    missinginfo += "\n     -  Dodgy WYD rating";
    }
    if ( ( (document.general_support.rating_overall.value < 0 ) ||
    (document.general_support.rating_overall.value > 5) ) && document.general_support.rating_overall.value != "") {
    missinginfo += "\n     -  Dodgy overall rating";
    }

    if (!isNum(document.general_support.rating_overall.value)) {
	missinginfo += "\n     -  Overall rating must be a number";
	}

    if ( (!isNum(document.general_support.rating_service.value)) && document.general_support.rating_service.value != "") {
	missinginfo += "\n     -  Service rating must be a number";
	}

    if ( (!isNum(document.general_support.rating_food.value)) && document.general_support.rating_food.value != "") {
	missinginfo += "\n     -  Food rating must be a number";
	}

    if ( (!isNum(document.general_support.rating_atmosphere.value)) && document.general_support.rating_atmosphere.value != "") {
	missinginfo += "\n     -  Atmosphere rating must be a number";
	}

    if ( (!isNum(document.general_support.rating_wyd.value)) && document.general_support.rating_wyd.value != "") {
	missinginfo += "\n     -  WYD rating must be a number";
	}

	if (missinginfo != "") {
	missinginfo ="_____________________________\n" +
	"Sorry, please correct the following:\n" +
	missinginfo + "\n_____________________________" +
	"\nPlease re-enter and submit again!";
	alert(missinginfo);
	return false;
	}
	else return true;
}


function checkLocVidFields()
{

	missinginfo = "";

    var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/

    if (document.loc_video.video_url.value.match(illegalChars)) {
    	missinginfo += "\n     -  Invalid characters in video ID";
    }

	if (document.loc_video.video_url.value == "") {
	missinginfo += "\n     -  Missing Video ID";
	}
	if (Left(document.loc_video.video_url.value,4) == "http") {
	missinginfo += "\n     -  Video ID only, not the URL";
	}

	if (missinginfo != "") {
	missinginfo ="_____________________________\n" +
	"Sorry, please correct the following:\n" +
	missinginfo + "\n_____________________________" +
	"\nPlease re-enter and submit again!";
	alert(missinginfo);
	return false;
	}
	else return true;
}
function checkNewsFields()
{
	missinginfo = "";
	if (document.post_news.body.value == "") {
	missinginfo += "\n     -  the details";
	}

	if (missinginfo != "") {
	missinginfo ="_____________________________\n" +
	"Sorry, please fill in:\n" +
	missinginfo + "\n_____________________________" +
	"\nPlease re-enter and submit again!";
	alert(missinginfo);
	return false;
	}
	else return true;
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function Mid(str, start, len)
{
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}
function Len(str)
{
    return String(str).length;
}

function InStr(strSearch, charSearchFor)
{
            for (i=0; i < strSearch.length; i++)
            {
                  if (charSearchFor == Mid(strSearch, i, 1))
                  {
                        return i;
                  }
            }
            return -1;
}

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 5
    StopTheClock()
    StartTheTimer()
}
function InitializeNewsMainTimer()
{
    // Set the length of the timer, in seconds
    secs = 5
    StopTheClock()
    StartTheNewsMainTimer()
}
function InitializeChatTimer()
{
    // Set the length of the timer, in seconds
    secs = 5
    StopTheClock()
    StartTheChatMainTimer()
}
function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer()
{
    if (secs==0)
    {
        StopTheClock()
        loadNewsTracker(document.f_nname.nname.value)
        InitializeTimer()
    }
    else
    {
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}
function StartTheNewsMainTimer()
{
    if (secs==0)
    {
        StopTheClock()
        loadNews()
        InitializeNewsMainTimer()
    }
    else
    {
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheNewsMainTimer()", delay)
    }
}
function StartTheChatMainTimer()
{
    if (secs==0)
    {
        StopTheClock()
        if (myChatRoom != '')
        {
            loadChats();
        }
        InitializeChatTimer()
    }
    else
    {
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheChatMainTimer()", delay)
    }
}

function OnChangedUsername()
{
    if(document.general_support.username.value == "") {
        document.general_support.btnCheckAvailability.disabled = true;
    }
    else
    {
        document.general_support.btnCheckAvailability.disabled = false;
    }
}

function OnCheckAvailability()
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "check_username.asp", true);
    oRequest.onreadystatechange = UpdateCheckAvailability;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("strCmd=availability&strUsername=" + document.general_support.username.value);
}

function UpdateCheckAvailability()
{
    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            document.getElementById("Available").innerHTML = oRequest.responseText;
        }
        else
        {
            document.getElementById("Available").innerHTML = "Asychronous Error";
        }
    }
}
function loadGal()
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "load_gal_strip.asp", true);
    oRequest.onreadystatechange = UpdateGalStrip;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("strCmd=load&iVnuID=" + document.gal_strip.vnu.value);
}

function UpdateGalStrip()
{
    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            document.getElementById("vnu_gal_strip").innerHTML = oRequest.responseText;
        }
        else
        {
            document.getElementById("vnu_gal_strip").innerHTML = "No pictures found";
        }
    }
}
function loadGalMain(picID)
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "load_gal_main.asp?picID=" + picID, true);
    oRequest.onreadystatechange = UpdateGalDetail;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("strCmd=load&iVnuID=" + document.gal_detail.vnu.value);
}

function UpdateGalDetail()
{
    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            document.getElementById("vnu_gal_detail").innerHTML = oRequest.responseText;
        }
        else
        {
            document.getElementById("vnu_gal_detail").innerHTML = "Asychronous Error";
        }
    }
}
function loadNews()
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "load_news_main.asp", true);
    oRequest.onreadystatechange = UpdateNewsMain;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("strCity=" + encodeURI(document.filter_strip.cit.value) + "&c=" + document.filter_check.c.checked + "&g=" + document.filter_check.g.checked + "&s=" + document.filter_check.s.checked + "&j=" + document.filter_check.j.checked + "&n=" + document.filter_check.n.checked + "&o=" + document.filter_check.o.checked + "&r=" + document.filter_check.r.checked + "&t=" + document.filter_check.t.checked + "&a=" + document.filter_check.a.checked);
}
function UpdateNewsMain()
{
    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            document.getElementById("news_detail").innerHTML = oRequest.responseText;
        }
        else
        {
            document.getElementById("news_detail").innerHTML = "Nothing found";
        }
    }
}

function postNews()
{
    document.post_news.btnPostNews.disabled = true;

    var dtls;

    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "post_news_main.asp", true);
    oRequest.onreadystatechange = PostNewsMain;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    dtls = document.post_news.details.value;
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');
    oRequest.send("strCmd=load&city=" + encodeURI(document.post_news.city.value) + "&cat=" + document.post_news.cat.value + "&details=" + encodeURI(dtls) + "&url=" + encodeURI(document.post_news.url.value) + "&img_1=" + encodeURI(document.post_news.img_1.value) + "&headline=" + encodeURI(document.post_news.headline.value) + "&vnu_name=" + encodeURI(document.post_news.vnu_name.value));
}
function PostNewsMain()
{
    if(oRequest.readyState == 4)
    {
        document.post_news.btnPostNews.disabled = false;

        if(oRequest.status == 200)
        {
            document.getElementById("pst_news").innerHTML = oRequest.responseText;
            loadNews();
        }
        else
        {
            document.getElementById("pst_news").innerHTML = "Error posting!";
        }
    }
}
function loadNewsTracker(act)
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "/common/blocks/tracker.asp", true);
    oRequest.onreadystatechange = UpdateNewsTracker;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("strCmd=load&city=" + encodeURI(document.f_cname.cname.value) + "&action=" + act);
}
function UpdateNewsTracker()
{
    var ntxt;

    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            try
            {
                document.getElementById("four").innerHTML = oRequest.responseText;
            }
            catch(ex)
            {
                ntxt = oRequest.responseText;
                var t = document.createElement('div');
                t.innerHTML = ntxt;
                document.getElementById("four").innerHTML = "";
                document.getElementById("four").appendChild(t);
/*                document.getElementById("four").innerHTML = "No news or gossip" + ntxt;*/
            }
        }
        else
        {
            document.getElementById("four").innerHTML = "No news or gossip!";
        }
    }
}
function loadNewsDetail()
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "load_news_detail.asp", true);
    oRequest.onreadystatechange = UpdateNewsDetail;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("id=" + document.nws_full_detail.news_id.value);
}
function UpdateNewsDetail()
{
    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            document.getElementById("news_full_detail").innerHTML = oRequest.responseText;
            loadNewsComments();
        }
        else
        {
            document.getElementById("news_full_detail").innerHTML = "Nothing found";
        }
    }
}

function loadNewsComments()
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "load_news_comments.asp", true);
    oRequest.onreadystatechange = UpdateNewsComments;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("id=" + document.nws_comments_detail.news_id.value);
}
function UpdateNewsComments()
{
    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            document.getElementById("news_full_comments").innerHTML = oRequest.responseText;
        }
        else
        {
            document.getElementById("news_full_comments").innerHTML = "No comments on this article yet.  Why not be the first to add one?";
        }
    }
}
function postNewsComment()
{
    document.post_news_comment.btnPostNewsComment.disabled = true;

    var dtls;

    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "post_news_comment.asp", true);
    oRequest.onreadystatechange = PostNewsCommentMain;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    dtls = document.post_news_comment.comment.value;
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');
    oRequest.send("strCmd=load&comment=" + encodeURI(document.post_news_comment.comment.value) + "&news_id=" + document.post_news_comment.news_id.value);
}
function PostNewsCommentMain()
{
    if(oRequest.readyState == 4)
    {
        document.post_news_comment.btnPostNewsComment.disabled = false;

        if(oRequest.status == 200)
        {
            document.getElementById("pst_news_comment").innerHTML = oRequest.responseText;
            loadNewsDetail();
        }
        else
        {
            document.getElementById("pst_news_comment").innerHTML = "Error posting!";
        }
    }
}

function loadMbrTracker()
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "/common/blocks/mbr_tracker.asp", true);
    oRequest.onreadystatechange = UpdateMbrTracker;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("strCmd=load&action=" + encodeURI(document.f_cname.cname.value));
}

function UpdateMbrTracker()
{
    var ntxt;

    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            try
            {
                document.getElementById("mbrtracker").innerHTML = oRequest.responseText;
            }
            catch(ex)
            {
                ntxt = oRequest.responseText;
                var t = document.createElement('div');
                t.innerHTML = ntxt;
                document.getElementById("mbrtracker").innerHTML = "";
                document.getElementById("mbrtracker").appendChild(t);
/*                document.getElementById("four").innerHTML = "No news or gossip" + ntxt;*/
            }
        }
        else
        {
            document.getElementById("mbrtracker").innerHTML = "No activity to report!";
        }
    }
}

function loadCityVenues(city)
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "load_venue_list.asp", true);
    oRequest.onreadystatechange = UpdateCityVenues;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("Strcity=" + encodeURI(city) + "&filter=" + document.cit.filter.value);
}
function UpdateCityVenues()
{
    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            document.getElementById("mn2Inner-venue").innerHTML = oRequest.responseText;
        }
        else
        {
            document.getElementById("mn2Inner-venue").innerHTML = "No venues found. Try looking at the city homepage for more info.";
        }
    }
}
function loadChatRoom(chatroom,filter)
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "load_chatroom.asp", true);
    oRequest.onreadystatechange = UpdateChatRoom;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("StrChatRoom=" + encodeURI(chatroom) + "&filter=" + filter);
}
function UpdateChatRoom()
{
    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            document.getElementById("mn2Inner-venue").innerHTML = oRequest.responseText;
        }
        else
        {
            document.getElementById("mn2Inner-venue").innerHTML = "Nobodies here!. Try looking at a different chatroom.";
        }
    }
}
function loadChats()
{
    if(window.XMLHttpRequest)
    {
        oRequest2 = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest2.open("POST", "load_chats.asp", true);
    oRequest2.onreadystatechange = UpdateChats;

    oRequest2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest2.send("filter=all");
}
function UpdateChats()
{
    var lat;
    var lng;
    var ctext;

    if(oRequest2.readyState == 4)
    {
        if(oRequest2.status == 200)
        {
            if (oRequest2.responseText != '')
            {
                lat=Mid(oRequest2.responseText,InStr(oRequest2.responseText,"{") + 1,9);
                lng=Mid(oRequest2.responseText,InStr(oRequest2.responseText,"}") + 1,9);
                ctext=Mid(oRequest2.responseText,InStr(oRequest2.responseText,"|")+1,InStr(oRequest2.responseText,"}")-InStr(oRequest2.responseText,"{")-11);

                if (ctext!="nnnn") {
                    document.getElementById("ch_his").innerHTML= document.getElementById("ch_his").innerHTML + "<br>" + ctext + "<hr>";
                    postChatLocation(lat,lng,ctext,99);
                }
                else
                {
                    hideInfoWindow();
                }
            }
        }
        else
        {
            alert('Issue getting chat');
        }
    }
}
function postChat()
{
    document.post_chat.btnPostChat.disabled = true;

    var dtls;

    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "post_chat.asp", true);
    oRequest.onreadystatechange = PostChatMain;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    dtls = document.post_chat.chatbox.value;
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');
    dtls = dtls.replace('&','and');

    oRequest.send("strCmd=load&details=" + encodeURI(dtls));
}
function PostChatMain()
{
    if(oRequest.readyState == 4)
    {
        document.post_chat.btnPostChat.disabled = false;

        if(oRequest.status == 200)
        {
            document.post_chat.chatbox.value="";
            document.getElementById("pst_chat").innerHTML = "Ready ..";
        }
        else
        {
            document.getElementById("pst_chat").innerHTML = "Error posting!";
        }
    }
}
function postMstatus()
{
    var dtls;

    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "post_mstatus.asp", true);
    oRequest.onreadystatechange = PostMstatusMain;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    dtls = document.mstat_strip.mstat_stat.value;
    dtls = dtls.replace('\r\n','<br/>');
    dtls = dtls.replace('\n','<br/>');
    dtls = dtls.replace('&','and');

    oRequest.send("strCmd=load&status=" + encodeURI(dtls));
}
function PostMstatusMain()
{
    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            document.getElementById("mstat_main").innerHTML = oRequest.responseText;
            loadMbrTracker();
        }
        else
        {
            document.getElementById("mstat_main").innerHTML = "Status unknown..";
        }
    }
}
function mbr_trackset(action) {

    document.getElementById("mbrtracker").innerHTML = "<img src=/pictures/animloading.gif border=0>";

    document.f_cname.cname.value=action;
    loadMbrTracker();
}

function nws_trackset(act) {

    document.getElementById("four").innerHTML = "<img src=/pictures/animloading.gif border=0>";

    document.f_nname.nname.value=act;
    loadNewsTracker(act);
}

function dis_viewset(act) {

    document.getElementById("DisBody").innerHTML = "<img src=/pictures/animloading.gif border=0>";

    document.f_dname.dname.value=act;
    loadDisView(act);
}
function loadDisView(act,tid)
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "/common/blocks/updatediscussion.asp", true);
    oRequest.onreadystatechange = UpdateDisView;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("strCmd=load&related=" + encodeURI(document.f_cname.cname.value) + "&action=" + act + "&tid=" + tid);
}
function UpdateDisView()
{
    var ntxt;

    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            try
            {
                document.getElementById("DisBody").innerHTML = oRequest.responseText;
            }
            catch(ex)
            {
                ntxt = oRequest.responseText;
                var t = document.createElement('div');
                t.innerHTML = ntxt;
                document.getElementById("DisBody").innerHTML = "";
                document.getElementById("DisBody").appendChild(t);
/*                document.getElementById("four").innerHTML = "No news or gossip" + ntxt;*/
            }
        }
        else
        {
            document.getElementById("DisBody").innerHTML = "Nothing to show";
        }
    }
}
function postTopic()
{
    document.add_topic.btnPostTopic.disabled = true;

    var dtls;
    var pars;

    dtls = document.add_topic.topicmessage.value;

    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "post_discussion_main.asp", true);
    oRequest.onreadystatechange = PostTopicMain;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//    pars="strCmd=load&title=" + encodeURI(document.add_topic.topictitle.value) + "&message=" + encodeURI(dtls) + "&related=" + encodeURI(document.add_topic.related.value);
//    alert(pars);
    oRequest.send("strCmd=load&title=" + encodeURI(document.add_topic.topictitle.value) + "&message=" + encodeURI(dtls) + "&related=" + encodeURI(document.add_topic.related.value));

}
function PostTopicMain()
{
    if(oRequest.readyState == 4)
    {
        document.add_topic.btnPostTopic.disabled = false;

        if(oRequest.status == 200)
        {
//            document.getElementById("add_topic").innerHTML = oRequest.responseText;

            loadDisView('dt',0);
        }
        else
        {
            document.getElementById("add_topic").innerHTML = "Error posting!";
        }
    }
}
function postReply()
{
    document.add_reply.btnPostReply.disabled = true;

    var dtls;
    var pars;

    dtls = document.add_reply.replymessage.value;

    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "post_reply_main.asp", true);
    oRequest.onreadystatechange = PostReplyMain;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//    pars="strCmd=load&title=" + encodeURI(document.add_topic.topictitle.value) + "&message=" + encodeURI(dtls) + "&related=" + encodeURI(document.add_topic.related.value);
//    alert(pars);
    oRequest.send("strCmd=load&title=" + encodeURI(document.add_reply.replytitle.value) + "&tid=" + encodeURI(document.add_reply.topicID.value) + "&message=" + encodeURI(dtls) + "&related=" + encodeURI(document.add_reply.related.value));

}
function PostReplyMain()
{
    if(oRequest.readyState == 4)
    {
        document.add_reply.btnPostReply.disabled = false;

        if(oRequest.status == 200)
        {
//            document.getElementById("add_topic").innerHTML = oRequest.responseText;

            loadDisView('dm',document.add_reply.topicID.value);
        }
        else
        {
            document.getElementById("add_reply").innerHTML = "Error posting!";
        }
    }
}
