var livesiteurl = null;
function initAvatars(imageURL)
{
    livesiteurl = imageURL;
}
function updateAvatar() 
{       	
	var avatar = document.getElementById("commentavatar");
	var selectlist = document.getElementById("avatarselect");
    if(selectlist.value =='-1')
    {
        avatar.src = livesiteurl + "/noimage.png";
        return;
    }
	avatar.src = livesiteurl + "/" + selectlist.value;
}

var nameNeeded ="";
var commentNeeded ="";
var commentLength = "";
var ratingBounds = "";
var maxRating = 0;
var securityNeeded = "";
var useSecurity = false;
var anonComments = true;
function initCommentSubmit(pnameNeeded, pcommentNeeded, pcommentLength, pratingBounds, pmaxRating, psecurityNeeded, puseSecurity)
{
    nameNeeded = pnameNeeded;
    commentNeeded = pcommentNeeded;
    commentLength = pcommentLength;
    ratingBounds = pratingBounds;
    maxRating = pmaxRating;
    securityNeeded = psecurityNeeded;
    useSecurity = puseSecurity;
}

function commentSubmitButton(allowUserComments)
{

    var form = document.commentForm;
    var comment = form.comment.value;
    var userRating = parseInt(form.userRating.value, 10);
    comment = comment.replace(/^\s+/, '');
    if(allowUserComments && form.anonymousName != null)
    {
      if (form.anonymousName.value == '')
      {
        alert( nameNeeded);
        form.anonymousName.focus();
		return false;
	  }
    }
    if (comment == '')
    {
		alert(commentNeeded);
		form.comment.focus();
		return false;
	}
	if(comment.length > 500)
	{
		alert( commentLength);
		form.comment.focus();
		return false;
    }

    if(form.requireUserRating.value == 1 &&(isNaN(userRating) || userRating < 0 || userRating > maxRating))
    {
        alert( ratingBounds + maxRating );
        form.userRating.focus();
        return false;
    }
    if(useSecurity)
    {
       if (form.security_try.value=='')
       {
	      alert(securityNeeded);
	      form.security_try.focus();
	      return false;
       }
	}
    else
    {
        return true;
    }
}

