var wrike=new Object();
wrike.sendReview={
review:{},
constructor:function()
{

},
init:function()
{
	this.nameInput=dojo.byId("name");
	this.emailInput=dojo.byId("email");
	this.descInput=dojo.byId("desc");
    if (this.descInput)
	    this.descInput.value = "";
	this.url=dojo.byId("topic");
	this.submit=dojo.byId("submitBtn");
	this.emailErr=dojo.byId("emailErr");
	this.nameErr=dojo.byId("nameErr");
	this.descErr=dojo.byId("descErr");
	this.okdiv=dojo.byId("msg");
	this.yes=dojo.byId("subjectyes");
	this.no=dojo.byId("subjectno");
	this.allform=dojo.byId("contactus");
    if (this.descInput)
	    dojo.connect(this.submit,"onclick",this,"onSubmit");
},
onSubmit:function()
{
	if(!this.validate())
		return;
	this.review.topic=this.url.value;
	this.review.help=this.yes.checked==true?"yes":"no";
	this.review.desc=this.descInput.value;
	this.review.email=this.emailInput.value;
	this.review.name=this.nameInput.value;
	dojo.xhrPost({url:"/ajaxsendreview",content:{review: dojo.toJson(this.review)},handleAs:"text",timeout:30000}).addBoth(dojo.hitch(this,function(response,ioArgs){
			this.okdiv.innerHTML=response;
			this.allform.style.display="none";
		}));
},
validate:function()
{
if(this.testEmpty(this.emailInput.value))
{
	this.emailErr.innerHTML=wrikeI18n["Please enter a valid email address"];
	this.emailErr.style.display="";
}
else
{
	this.emailErr.style.display="none";
if(!this.testEmail(this.emailInput.value))
	{
		this.emailErr.innerHTML=wrikeI18n["Please enter a valid email address"];
		this.emailErr.style.display="";
	}
	else
		this.emailErr.style.display="none";
}
if(this.testEmpty(this.nameInput.value))
{
	this.nameErr.innerHTML=wrikeI18n["Please enter your name"];
	this.nameErr.style.display="";
}
else
	this.nameErr.style.display="none";
if(this.testEmpty(this.descInput.value))
{
	this.descErr.innerHTML=wrikeI18n["Please enter your message"];
	this.descErr.style.display="";
}
else
	this.descErr.style.display="none";
return !this.testEmpty(this.emailInput.value)&&this.testEmail(this.emailInput.value)&&!this.testEmpty(this.nameInput.value)&&!this.testEmpty(this.descInput.value);
},
testEmail:function(s)
{
	re = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;
	return re.test(s);
},
testEmpty:function(s)
{
	if(s==null||s.length==0)
		return true;
	return false;
}

};
dojo.addOnLoad(function()
{
	wrike.sendReview.init();


});