function deletethread(thread_id) {
	if(confirm('Are you sure you want to delete?')) {
		document.getElementById('delete_thread_id').value = thread_id;
		document.showthread.submit();
	} else {
		return false;
	}
}

function replythread(thread_id) {        
	document.getElementById('reply_thread_id').value = thread_id;
	document.showthread.action = 'post_edit.php';
	document.showthread.submit();
	return false;
}

function replypost(post_id) {
	document.getElementById('reply_post_id').value = post_id;
	document.showthread.action = 'post_edit.php';
	document.showthread.submit();
	return false;
}

function editthread(thread_id) {
	document.getElementById('thread_id').value = thread_id;
	document.showthread.action = 'thread_edit.php';
	document.showthread.submit();
	return false;
}
    
    function editpost(post_id)
    {        
        document.getElementById('reply_post_id').value=post_id;                 
        document.getElementById('act').value='edit';  
        document.showthread.action='post_edit.php';               
        document.showthread.submit();        
        return false;
    }
    
    function deletepost(post_id){        
        if(confirm('Are you sure you want to delete?')){
            document.getElementById('delete_post_id').value=post_id;                 
            document.showthread.submit();
        }
        else
        {
            return false;
        }
    }
    
    function createthread(forum_id, frompage)
    {   
        if (frompage=='1'){
		document.showforum.action=__FORUM_URL__+'/thread_edit.php?f='+forum_id;
            document.showforum.submit();
        }
        else{
            document.showthread.action='thread_edit.php?f='+forum_id;               
            document.showthread.submit();   
        }  
        return false;  
    }
    
    function reportabusethread(thread_id){        
        if(confirm('Are you sure you want to report this as abuse?')){
            document.getElementById('abuse_thread_id').value=thread_id;                 
            document.showthread.submit();
        }
        else
        {
            return false;
        }
    }
    
    function reportabusepost(post_id){        
        if(confirm('Are you sure you want to report this as abuse?')){
            document.getElementById('abuse_post_id').value=post_id;                 
            document.showthread.submit();
        }
        else
        {
            return false;
        }
    }
    
    function clearbestanswerpost(post_id){  
        if (confirm('Are you sure to clear this as best answer?')){
            document.getElementById('clear_best_post_id').value=post_id;
            document.showthread.submit();
        }
        else
        {    
            return false;
        }
    }
    
    function bestanswerpost(post_id){  
        if (confirm('Are you sure to set this as best answer?')){
            document.getElementById('best_post_id').value=post_id;
            document.showthread.submit();
        }
        else
        {    
            return false;
        }
    }
    
    
    function set_ids(id,name){
		$('#set_user_name').val(name);
		$('#set_user_id').val(id);
	}
	
	
	function hidequote()
	{
		$('#content_ifr').contents().find('#tiny_quote').remove();
	}
	
	function showquote(){
	   getnew =  tinyMCE.getInstanceById('content').getContent();
	   document.getElementById('divnew').innerHTML = getnew;
	   getold="<div id='tiny_quote'>"+document.getElementById('divreply').innerHTML+'</div><p>&nbsp;</p>';
	   tinyMCE.getInstanceById('content').setContent(getold + getnew);
	}
	
	function enableinvitee(){
		 document.getElementById('divinvitee').style.visibility='visible';	
		 	document.getElementById('divinvitee').style.height='130px';	
	}
	
	function disableinvitee(){
		document.getElementById('divinvitee').style.visibility='hidden';
		document.getElementById('divinvitee').style.height='0px';
    }
    
    function validatethread(minchars, maxchars){
    	clear_options();
        tinymcetext=tinyMCE.getInstanceById('content').getContent();
        tinytextlength = tinymcetext.length;
        title = document.getElementById('title').value;
        strRE = /^[\s ]*$/gi; 
        
        if (document.getElementById('forum_id').selectedIndex == 0)
        {
            alert('Please select a Forum');
            document.getElementById('forum_id').focus();
            return false;
        }
        else if (title=='' || strRE.test(title)){
            alert('Please enter thread title');
            document.getElementById('title').focus();
            return false;
        }   
        else if (tinyMCE.getInstanceById('content').getContent()==''){
            alert('Please enter thread description');
            return false;
        }
        else if (tinytextlength < minchars){
            alert('Thread description must be a minimum of ' + minchars + ' characters');
            return false;
        }
        else if (tinytextlength > maxchars){
            alert('Thread description must be a less than ' + maxchars + ' characters');
            return false;
        }       
    }
    
    function validatepost(minchars, maxchars){
    	
    	document.getElementById('post_form').target='';
    	document.getElementById('post_form').action='';
    	document.getElementById('post_preview').value='0';
    	
        tinymcetext=tinyMCE.getInstanceById('content').getContent();
        tinytextlength = tinymcetext.length;
        title = document.getElementById('post_title').value;
        strRE = /^[\s ]*$/gi; 
        
        if (title=='' || strRE.test(title)){
            alert('Please enter post title');
            document.getElementById('post_title').focus();
            return false;
        }   
        else if (tinyMCE.getInstanceById('content').getContent()==''){
            alert('Please enter post description');
            return false;
        }
        else if (tinytextlength > maxchars){
            alert('Post description must be a less than ' + maxchars + ' characters');
            return false;
        }
        else if (tinytextlength < minchars){
            alert('Post description must be a minimum of ' + minchars + ' characters');
            return false;
        }   
    }
	
	
	function moveposts()
    { 
        postids=getpostcookie();        
        document.getElementById('movepostids').value = postids;
        if (postids == null){
            alert('Select at least one item');
            return;
        }
        else
        {
            document.showthread.action='movepost.php';      
            document.showthread.submit();
            return false;
        }       
    }
    
    
    function validatemoveposts(){
        if (movepost.move_post_type[0].checked == true){
               
            if ((eval(document.getElementById('forumurl').value.length)=='') && (document.getElementById('forum_selector').selectedIndex == 0)){
                alert('Please enter Forum URL or select a Forum');
                return false;
            }
            else if (eval(document.getElementById('threadtitle').value.length)==''){
                alert('Please enter Thread Title');
                return false;
            }
            else if (tinyMCE.getInstanceById('content').getContent() ==''){
                alert('Please enter Thread Description');
                return false;
            }
            else{
                return true;
            }
        }
        else {
            if (eval(document.getElementById('threadurl').value.length)==''){
                alert('Please enter Thread URL');
                return false;
            }
            else{
                return true;
            }
        }
    }
    
    
    function validatemergethreads(){
        if (eval(document.getElementById('threadurl').value.length)=='') {
            alert('Please enter Thread URL');
            return false;
        }
        else{
            return true;
        }
        
    }
    
    function validatemovethreads(){
       if ((eval(document.getElementById('forumurl').value.length)=='') && (document.getElementById('forum_selector').selectedIndex == 0)){
            alert('Please enter Forum URL or select a Forum');
            return false;
        }
        else{
            return true;
        }
    }
    
    
    function getCookieVal (offset) { 
        var endstr = document.cookie.indexOf (';', offset); 
        if (endstr == -1) 
            endstr = document.cookie.length; 
        return unescape(document.cookie.substring(offset, endstr));
    }


    function update_forum_permissions(){
    	clear_options();
        forumid=document.getElementById('forum_id').value;
        document.newthread.action='thread_edit.php?f='+forumid;      
        document.newthread.submit();
    }
    
    function setthreadcookie(ischecked, cookievalue){
        threadid = getthreadcookie();          
        if (ischecked){             
            if (threadid != null){                
                document.cookie = 'mthreadid='+escape(cookievalue)+','+threadid+';path=/;';                
            }
            else{
                document.cookie = 'mthreadid='+escape(cookievalue)+',;path=/';
            }            
        }
        else {
            if (threadid != null){
                document.cookie = 'mthreadid='+ threadid.replace(cookievalue+',','')+';path=/';
            }
        }            
        threadid = getthreadcookie();    
        document.getElementById('movethreadids').value = threadid;
    }
    
    
    function setpostcookie(ischecked, cookievalue){
        postid = getpostcookie();          
        var postidstr = '';
        if (ischecked){             
            if (postid != null){                
               postidstr  = 'mpostid='+escape(cookievalue)+','+postid;                
            }
            else{
                postidstr = 'mpostid='+escape(cookievalue)+',';
            }            
        }
        else {
            if (postid != null){
                postidstr = 'mpostid='+ postid.replace(cookievalue+',','');
            }
        }            
	if (postidstr != '') {
		document.cookie = postidstr.replace(/,$/,'');
	}
        postid = getpostcookie();    
        document.getElementById('movepostids').value = postid;
    }
        
    function getpostcookie(){
        var arg = 'mpostid='; 
        var alen = arg.length; 
        var clen = document.cookie.length; 
        var i = 0; 
        while (i < clen) { 
        var j = i + alen; 
        if (document.cookie.substring(i, j) == arg) 
            return getCookieVal (j); 
        i = document.cookie.indexOf(' ', i) + 1; 
        if (i == 0) break; 
        } 
        return null;
    }
    
    function getthreadcookie(){
        var arg = 'mthreadid='; 
        var alen = arg.length; 
        var clen = document.cookie.length; 
        var i = 0; 
        while (i < clen) { 
        var j = i + alen; 
        if (document.cookie.substring(i, j) == arg) 
            return getCookieVal (j); 
        i = document.cookie.indexOf(' ', i) + 1; 
        if (i == 0) break; 
        } 
        return null;
    }
   

    function deletepostcookie() { 
        var exp = new Date(); 
        exp.setTime (exp.getTime() - 1); 
        var cval = getpostcookie(); 
        document.cookie = 'mpostid=' + cval + '; expires=' + exp.toGMTString();
    }

    function deletethreadcookie() { 
        var exp = new Date(); 
        exp.setTime (exp.getTime() - 1); 
        var cval = getthreadcookie(); 
        document.cookie = 'mthreadid=' + cval + ';path=/;expires=' + exp.toGMTString();
    }
    
    function remove_tag(id){    
	    $('#'+id).remove();
	    $('#link_'+id).remove();	
	    get_tags()  
    }
    
    var nt_id = 100;
    function add_tag(){
        nt_id += 1;
        var tag_title = document.getElementById('add_new_tag').value;
        document.getElementById('add_new_tag').value='';        
	    var html = '';
   	    html += "<span id='new_tag_"+nt_id+"' class='tag_class'>"+tag_title+"</a></span>";
        html +="<span id='link_new_tag_"+nt_id+"'><a href=javascript:remove_tag('new_tag_"+nt_id+"') >[X]</a></span>&nbsp;";
   	    $('#tag_list').append(html);   
   	    get_tags();    
    }
    
    function get_tags(){   
        var html = '';
        $('.tag_class').each(function(){    
	     html += $(this).html() + ',';         
        });  
        $('#hdn_tags').val(html);
}

function removetag(id){    
	$('#'+id).remove();
	$('#rm_'+id).remove();
	gettags();
}
var nt_id = 0;
function addtag(tag_text_id){
        nt_id += 1;
        var tag_title = $('#'+tag_text_id).val();        
	if(!check_tag(tag_title)){
		var html = '';
        	html += "<span id='new_tag_"+nt_id+"' class='tagclass'>"+tag_title+"</a></span>";
	        html +="<span id='rm_new_tag_"+nt_id+"'><a href=javascript:removetag('new_tag_"+nt_id+"') >[X]</a></span>&nbsp;";
        	$('#tag_list').append(html);
	        $('#'+tag_text_id).val(''); 
		gettags();
	}
	else{
		alert('Tag already Exists');
	}
}
    

