function replycomment(commentid,username){
	document.getElementById('replycommentinfo').style.display='block';
	document.getElementById('replycommentinfo').innerHTML='You are replying to a comment made by '+username;
	document.getElementById('replycomment').value=commentid;
}


function WinOpen(page,windowname,horz,vert) { OpenWin = window.open(page,windowname,'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,width=' + horz + ',height=' + vert ); }

// JavaScript Document
var ids=new Array('comment_create','comment_login');
function switchid(id){	
	hideallids();
	showdiv(id);
}

function hideallids(){
	//loop through the array and hide each element by id
	for (var i=0;i<ids.length;i++){
		hidediv(ids[i]);
	}		  
}

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function checkemail(elem){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return false;
	}else{
		return true;
	}
}
function checkfield(elem){
	if(elem.value.length == 0){
		return true;
	}
	return false;
}
function commentsformValidator(){
	// Make quick references to our fields
	for (var i=0; i < document.commentsform.havepassword.length; i++){
		if (document.commentsform.havepassword[i].checked){
			var havepassword = document.commentsform.havepassword[i].value;
		}
	}
	var username = document.getElementById('username');
	var password = document.getElementById('password');
	var newpassword = document.getElementById('newpassword');
	var email = document.getElementById('email');
	var comment = document.getElementById('comment');
	
	// Check each input
	if(havepassword == "yes"){
		if(checkfield(username) || checkfield(password)){
				alert("Please complete all fields");
				return true;
		}
		
	} else {
		if(checkfield(username) || checkfield(newpassword) || checkfield(email)){
				alert("Please complete all fields");
				return true;
		}
		if(checkemail(email)){
				alert("Please complete a valid email address");
				return true;
		}
	}
	document.commentsform.submit();
	false;
}
