function sendTheComment(){
	//Avoid never-ending loop
	if($('.sendthecomment').attr('resetSwitch')){
		$('.sendthecomment').removeAttr('resetSwitch');
		return false;
	}
	if($('#name').val().length == 0){
		alert("Do you have a name?");
		//focus on the input element
		$('#name').focus();
		//reset the button
		$('.sendthecomment').attr('resetSwitch','reset').click();
		return false;
	}else if($('#message').val().length == 0){
		alert("You aren't going to write a comment?");
		//focus on the input element
		$('#message').focus();
		//reset the button
		$('.sendthecomment').attr('resetSwitch','reset').click();
		return false;
	}
		
	get_tuturl = window.location.url;
	get_tutid2 = $("#tutid").val();
	get_name = $("#name").val();
	get_url = $("#url").val();
	get_email = $("#email").val();
	get_message = $("#message").val();
	$.ajax({
		url: 'include/comments/submit.php',
		type : "POST",
		data: ({
			ajax_submit:"true",
			tuturl: get_tuturl,
			tutid2:get_tutid2, 
			name:get_name, 
			url:get_url, 
			email:get_email, 
			message:get_message
		}),
		success: function(msg){
			$('.commentstatus').css({opacity:0}).html('Your comment was posted successfully!').animate({opacity:1},"slow").delay(2000).animate({opacity:0},"slow");
			articleId = $('#commentsHere').attr('articleId');
			$.ajax({
				url: 'getthecomment',
				type : "POST",
				data: ({
					ajax_fetch:"true",
					id:articleId 
				}),
				success: function(msg){
					$('#commentsHere').html(msg);
				}
			});
			$("#name").val('');
			$("#url").val('');
			$("#email").val('');
			$("#message").val('');
			$('.sendthecomment').attr('resetSwitch','reset').click();
		}
	});
}



//-->


/*itoggle*/

/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);



/**
 * @author Thomas Bensmann
 * v. 0.76
 */
(function($) {
  $.fn.iToggler = function(options) {
	
	defaults = {
			state: "unchecked", // checked or unchecked by default? options: checked || unchecked
			type: "yesno",		// yesno || onoff || open || agree || save || show 
			tint: "blue",		// blue || green || purple
			disabled: "enabled"	// enabled || disabled
	}
		
	var settings = $.extend(defaults, options);
	
	return this.each(function (i) {
		
		var opts = settings;
		//isset(color)
		if(!$(this).attr("togglecolor")){$(this).attr({togglecolor: opts.tint});}
		//isset(type)
		if(!$(this).attr("toggletype")){$(this).attr({toggletype: opts.type});}
				
		this.style.backgroundImage = 
			'url(http://gfx.thomas-online.no/thomas-online.no/itoggle/toggle-' + $(this).attr("togglecolor")  + '-' + $(this).attr("toggletype")  + '.png)';	   
		
		
		//Checking or unchecking the Toggle
		switch($(this).attr("checked")){
			case "checked":
				$(this).css("backgroundPosition", "0px 0px")
				break;
			case "unchecked":
				$(this).css("backgroundPosition", "-54px 0px")
				break;
			default:
				if(opts.state=="checked")
					$(this).css("backgroundPosition", "0px 0px").attr("checked", "checked");
				else
					$(this).css("backgroundPosition", "-54px 0px").attr("checked", "unchecked");
		}
		
		
		//Disabling or enabling the Toggle
		switch($(this).attr("toggledisabled")){
			case "disabled":
				$(this).fadeTo(300, 0.33);
				break;
			case "enabled":
				$(this).fadeTo(300, 1);
				break;
			default:
				if(opts.disabled == "disabled")
					fadeValue = 0.33;
				else
					fadeValue = 1;
				$(this).attr("toggledisabled", opts.disabled).fadeTo(300, fadeValue);
		}
		
		//So we don't duplicate the onclick
		$(this).unbind('click',onClick);
		
		//Preserving objects event
		if(this.onclick){
			oldclick = this.onclick;
			this.onclick = "";
			$(this).bind('click',oldclick);
		}
		//Adding our toggle event
		$(this).bind('click',onClick);
		
	});
	
	function onClick(){
		if($(this).attr("toggledisabled")=="disabled")
			return false;
		switch($(this).attr("checked")){
			case "checked":
				$(this).stop().animate({"backgroundPosition":"(-54px 0)"}, 150 ).attr("checked", "unchecked");
				break;
			case "unchecked":
				$(this).stop().animate({"backgroundPosition":"(0px 0)"}, 150 ).attr("checked", "checked");
				break;
		}
	}
	
  }
})(jQuery);


