function validateEmailv2(email){
	//function got from gen_validatorv2 script; under copyright by owner
	var splitted = email.match("^(.+)@(.+)$");
  if(splitted == null) return false;
  if(splitted[1] != null ){
		var regexp_user=/^\"?[\w-_\.]*\"?$/;
    if(splitted[1].match(regexp_user) == null) return false;
	}
	if(splitted[2] != null){
		var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		if(splitted[2].match(regexp_domain) == null){
			var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
			if(splitted[2].match(regexp_ip) == null) return false;
		}// if
		return true;
	}
	return false;
}

//for removing a div
function removeElement(child) {
	var childdiv = document.getElementById(child);
	var parentdiv = childdiv.parentNode;
	parentdiv.removeChild(childdiv);
}

//reset comment form
function resetCommentForm(){
	var form = $('commentform');
	form.name.value = "";
	form.email.value = "";
	form.comment.value = "";
}

function submitCommentsForm(form,type){
	var name = form.name.value;
	var email = form.email.value;
	var comment = form.comment.value;
	var articleid = form.articleid.value;
	var url = "../supports/scripts/comments.php";
	var pars = "name="+name+"&email="+email+"&comment="+comment+"&type="+type+"&articleid="+articleid;

	var emailerror = true;

	if(validateEmailv2(email)) emailerror = false;
	
	if(emailerror){
		alert("Please enter a valid email address first.");
		form.email.focus();
		return true;
	}
	
	if(name=="" || email=="" || comment==""){
		alert("Please enter all form values.");
		return true;
	} else
		goserver(url,pars);
}



// go server go!!
function goserver(url, pars){
	new Ajax.Updater(
		'ajaxupdater',
		url,
		{ method: 'get',
		  parameters: pars,
		  evalScripts: true
		});
}

