/* submit comments form */
function submitComment(){
	var newCommentName = _("newCommentName");
	var newCommentMessage = _("newCommentMessage");
	var newCommentAntiSpamCode = _("newCommentAntiSpamCode");
	var newCommentAntiSpamCodeVerification = _("newCommentAntiSpamCodeVerification");
	var newCommentSubmit = _("newCommentSubmit");
	var newCommentRememberName = _("newCommentRememberName");
	
	/* check if name is given */
	if(!newCommentName || newCommentName.value.length==0){
		newCommentName.focus();
		changeClass(newCommentName,"Comment_Form Comment_FormError");
		return false;
	}
	
	/* check if message is given */
	if(!newCommentMessage || newCommentMessage.value.length==0){
		newCommentMessage.focus();
		changeClass(newCommentMessage,"Comment_Form Comment_FormError");
		return false;
	}
	
	
	/* check if anti spam code matches */
	if(!newCommentAntiSpamCode || !newCommentAntiSpamCodeVerification || newCommentAntiSpamCode.value!=newCommentAntiSpamCodeVerification.value){
		newCommentAntiSpamCode.focus();
		changeClass(newCommentAntiSpamCode,"Comment_Form Comment_FormError");
		return false;
	}
	
	/* check if slider is on the right */
	if(_("newCommentSlider").value!=1){
		_("slider").style.borderColor = "#888";
		return false;
	}
	
	/* disable submit button and change text */
	newCommentSubmit.innerHTML += "ting...";
	newCommentSubmit.disabled = true;
	
	/* remember name or not */
	if(newCommentRememberName.src.indexOf("unchecked")==-1){
		setCookie("CommentName",newCommentName.value,365,null,null,null);
	}else{
		deleteCookie("CommentName");
	}
	
	return true;
}

/* hide comments with slider */
function hideComments(){	
	/* hide link "Hide comments" and show link "Show comments */
	hide(_("Comments_Hide"));
	show(_("Comments_Show"));
	
	/* slide out */
	new Fx.Slide("Comments").slideOut();
	
	/* set cookie to hide comments */
	setCookie("HideComments","yes",365,null,null,null);
	
	/* hide pictures inside comments-container because ie-bug */
	var images = _("Comments").getElementsByTagName("img");
	
	for(var i=images.length-1;i>-1;i--){
		hide(images[i]);
	}
}

/* show comments with slider */
function showComments(){
	/* show link "Hide comments" and show link "Show comments */
	hide(_("Comments_Show"));
	show(_("Comments_Hide"));
	
	/* show pictures inside comments-container because ie-bug */
	var images = _("Comments").getElementsByTagName("img");
	
	for(var i=images.length-1;i>-1;i--){
		show(images[i]);
	}
	
	/* slide in */
	show(_("Comments"));
	new Fx.Slide("Comments").slideIn();
	
	/* delete cookie to hide comments */
	deleteCookie("HideComments");
}

/* text counter */
function textCounter(field,counter,maxlimit,linecounter) {
	var fieldWidth = parseInt(field.offsetWidth);
	var charcnt = field.value.length; 
	
	/* trim the extra text */
	if(charcnt > maxlimit){
		field.value = field.value.substring(0,maxlimit);
	}else{
	/* progress bar percentage */
		var percentage = parseInt(100-((maxlimit-charcnt)*100)/maxlimit);
		_(counter).style.width = parseInt((fieldWidth*percentage)/100)+"px";
		_(counter).innerHTML = percentage+"%";

		if(percentage==100){
			_(counter).style.backgroundColor = "rgb(229,135,18)";
			_(counter).style.display = "block";
		}else{
			_(counter).style.backgroundColor = "rgb(121,148,112)";

			if(percentage==0){
				_(counter).style.display = "none";
			}else{
				_(counter).style.display = "block";
			}
		}
	}
}

/* remember name (change hidden input and image) */
function toggleRememberName(img){
	if(img.src.indexOf("unchecked")!=-1){
		img.src = "../../img/layout/checked.gif";
	}else{
		img.src = "../../img/layout/unchecked.gif";
	}
}