Event.observe(window,'load',function(){

var btn = $('send_btn');

Event.observe(btn, 'click', function(event){

btn.disable();

var required = $$('.inputreq');

required.each(function(thisInput){

var id = thisInput.identify();

var req = " *";

if(!$(id).next('span.req_err'))
new Insertion.After($(id),'<span class="req_err"></span>');

if($(id).present() == false){
$(id).next('span.req_err').update(req);
$A
}else{
$(id).next('span.req_err').remove();
}
});

var arr = $A($('contact').getElementsByClassName('req_err'));

if(arr == 0)
{
var sss = "/email_send.php";

new Ajax.Request(sss, 
{
method: 'post', 
parameters: $('contact').serialize(true),
onSuccess : function(resp)
{

if (resp.responseText.match("notvalid"))
{
alert('Sorry the validation code is incorrect. Please try again!');

$('valid').clear();
$('valid').focus();
}
else if (resp.responseText.match("error"))
{
if($('top_err')){
$('top_err').remove();

}else{
new Insertion.Before('contactform','<div id="top_err">Sorry an error occurred, please try again later!</div>');

}
}
else if (resp.responseText.match("success"))
{
if($('top_err')){
$('top_err').remove();

}

if($('top_msg')){
$('top_msg').remove();

}else{
new Insertion.Before('contactform','<div id="top_msg">Your email has been successfully sent. An Aushomes representative will be in contact with you within 48hrs.</div>');
}
$('contact').reset();

}
else
{
alert(resp.responseText);
}
}
});
}

btn.enable();
});

Event.observe('newVal', 'click', function(evt){

new Ajax.Request('/new_captcha.php', 
{
method: 'get', 
onSuccess : function(res)
{
$('captimg').update(res.responseText);
}
});
});

});