var xmlHttp


function getCheckedValue() {
	var radioObj=document.f_comment.mood;
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


 function checkEmail(email) {
      if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)){
        return (true)
      }
     
      return (false)
    }

function valideaza(){
	
	var errormsg="<p><span class='red'><b>You must complete";
	if(document.f_comment.name.value==""){
		errormsg+=" your name!";
	}
	else{
		if (!checkEmail(document.f_comment.email)){
		errormsg+=" your email corectly!";
		}
		else{
			if(document.f_comment.comment.value==""){
		errormsg+=" your comment!";
	}
			
		}
		
	}
	
	if(errormsg=="<p><span class='red'><b>You must complete"){
		return true;
	}
	else{
		errormsg+="</b></span></p>";
		document.getElementById("form_error").innerHTML=errormsg;
		return false;
	}
}

function addcomment(id)
{

if(valideaza()){

xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
} 
var url="http://www.famouswhy.com/download/doAddComment.php"
url=url+"?sid="+Math.random()

var parameters="name="+escape(document.f_comment.name.value)+"&email="+escape(document.f_comment.email.value)+"&comment="+escape(document.f_comment.comment.value)+"&id="+id+"&mood="+getCheckedValue();


xmlHttp.onreadystatechange=stateChangedC
xmlHttp.open("POST",url,true)
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xmlHttp.setRequestHeader("Content-length", parameters.length)
xmlHttp.setRequestHeader("Connection", "close")
xmlHttp.send(parameters)
}
} 

function stateChangedC() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("form_comment").innerHTML=xmlHttp.responseText 
//alert('hgfhgf');
} 
} 

