 function showDoc(){
	if($('#decision').css("display")=='none') { 
		$('#decision').css("display","block");
	}else{
		$('#decision').css("display","none");
	}
}

function showUserInfo(no,username,boxid) {
	if($("#user_info_"+boxid).css("display")=="none") {
		  $('.user_info_box').hide("200");
			$("#user_info_"+boxid).show("200");
	}else{
		$("#user_info_"+boxid).hide("200");
	}
 return false;
}

function follow(no) {
	$.post("/case", { 'procType':'follow', 'id': no}, function(xml) {
		if($("error",xml).text()==0){
			$("#li-follow-"+no).html('<a href="javascript:void(0);" class="pre" onClick="javascript:unfollow(\''+no+'\');" title="unfollow"><span id="follow-'+no+'" class="following">Following</span></a>'); 
		}
 });
 return false;
}

function unfollow(no) {
	$.post("/case", { 'procType':'unfollow', 'id': no}, function(xml) {
		if($("error",xml).text()==0){
			$("#li-follow-"+no).html('<a href="javascript:void(0);" class="pre" onClick="javascript:follow(\''+no+'\');"><span id="follow-'+no+'" class="follow">Follow case</span></a>'); 
		}
 });
 return false;
}

function submitGuestCommentbk() {
	var error='';
	if($('#author_email').val()=='') error +='- Email is empty\n';
	var regex = /^ *[A-Za-z0-9_\-\.]+\@[A-Za-z0-9_\-]+(\.[A-Za-z0-9_\-]+)+ *$/;

	if (!regex.test($('#author_email').val())) { 
		 error += "email address is invalid\n";
	}
		
	if($('#comment').val()=='') error +='- Comment is empty\n';
	if(error!='') {
		alert(error);
	}else{
		$('#procType').val('submitComment');
		$("form").submit();
	}
}

function submitComment() {
	$('#procType').val('submitComment');
	$("form").submit();
}

function submitCommentary() {
	$('#procType').val('submitCommentary');
	$("form").submit();
}

function forgotPass() {
	var email = $('#author_email').val();
	$('#forgot_pass').html('<img src="/images/working.gif" />');
	$.post("/case", { 'procType':'subForgot', 'author_email': email}, function(xml) {
		if($("error",xml).text()==0){
			$('#forgot_pass').html('<span class="proc_ok">New password sent</span>');
		}else{
			$('#forgot_pass').html('<span class="error">SYSTEM ERROR</span>');
		}
 });
 return false;
}

$(document).ready(function() {
	
	$('#authoremailLoading').hide();
	$('#author_email').blur(function(){
		var author_email = $('#author_email').val().replace(/ /g,'');
		
		if(author_email.length==0) {
			$('#msgforauthor').html('Please enter email address').css("display","inline").addClass('error');
			$('#author_email').val('');
    	return false;
		}
		
		var regex = /^ *[A-Za-z0-9_\-\.]+\@[A-Za-z0-9_\-]+(\.[A-Za-z0-9_\-]+)+ *$/;
		if (!regex.test(author_email)) { 
			$('#msgforauthor').html('Please enter valid email address').css("display","inline").addClass('error');
			$('#author_email').focus();
    	return false;
		}else{
			$('#msgforauthor').html('')
		}
		
		$('#author_email').val(author_email);

    	return false;
	});

});

function addTags(no) {
	var v = $('#newtags').val();
	$.post("/case", { 'procType':'add_tags', 'lid': no, 'tags': v}, function(xml,no) {
		if($("error",xml).text()) {
		}
    $("#my_tag_cloud ul").empty();
		if($("tag",xml).text()) {
			$(xml).find("tag").each(function() {
				var $tg = $(this); 
				var tagid = $tg.find('tagid').text();	
				var tagslug = $tg.find('slug').text();	
				var tagname = $tg.find('tagname').text();
				 $('#my_tag_cloud ul').append('<li id="tag'+tagid+'" class="s3"><span class="removetagattach" onClick="javascript:removeTag(\''+tagid+'\',\''+no+'\');"></span><a href="/udrptalk/tag/'+tagslug+'">'+tagname+'</a></li>');				 
		 });
		}
	});	
	$('#newtags').val('');
	return false;
	setTimeout('addTags()', 4000);
}

function removeTag(id,no) {
	$.post("/case", { 'procType':'remove_tag', 'tagid': id, 'lid': no}, function(xml) {
		if($("error",xml).text()==0) {
    	$("#tag"+id).remove();
		}
	});		
}

function removeExTag(link_id,tagid,tagname,slug) {
	$.post("/case", { 'procType':'remove_tag', 'tagid': tagid, 'lid': link_id}, function(xml) {
		if($("error",xml).text()==0) {
    	$("#button_add_"+tagid).html('<input type="button" name="tag" value="Add '+tagname+' Tag" onClick="javascript:addExTag(\''+link_id+'\',\''+tagid+'\',\''+tagname+'\',\''+slug+'\')"  />');
				$('#button_add_'+tagid).removeClass("tagged");
		}
	});		
}

function addExTag(link_id,tagid,tagname,slug) {
	$.post("/case", { 'procType':'link_tag', 'lid': link_id, 'tagid': tagid}, function(xml) {
		if($("error",xml).text()==0) {
				$('#button_add_'+tagid).html('<span class="tag">'+tagname+'</span> <span class="tagremove" onClick="javascript:removeExTag(\''+link_id+'\',\''+tagid+'\',\''+tagname+'\',\''+slug+'\');">Remove</span>');
				$('#button_add_'+tagid).addClass("tagged");
		}
	});	
	return false;
	setTimeout('addTags()', 4000);
}

tinyMCE.init({
    mode: "exact",
    elements : "elm1",
    theme : "advanced",
    theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,blockquote,justifyleft,justifycenter,justifyright, justifyfull,|,outdent,indent,|,bullist,numlist,sub,sup,undo,redo,link,unlink,code",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    plugins : 'inlinepopups',
    setup : function(ed) {
        // Add a custom button
        ed.addButton('mybutton', {
            title : 'My button',
            image : 'img/example.gif',
            onclick : function() {
				// Add you own code to execute something on click
				ed.focus();
                ed.selection.setContent('<strong>Hello world!</strong>');
            }
        });
    }
});
