function HttpRequest(name,callback,waitCallback) 
{
    // branch for native XMLHttpRequest object
	this.name = name ;
	this.callback = callback;
	this.xmlhttp = null;
	this.waiter = waitCallback;

	if (window.XMLHttpRequest) 
	{
        this.xmlhttp = new XMLHttpRequest();
    }
	else if (window.ActiveXObject) 
	{
        this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
	return this;
}


HttpRequest.prototype.parseForm = function(form) { with (this)
{
 // Parses a form DOM reference to an escaped string suitable for GET/POSTing.

 var str = '', gE = 'getElementsByTagName', inputs = [
  (form[gE] ? form[gE]('input') : form.all ? form.all.tags('input') : []),
  (form[gE] ? form[gE]('select') : form.all ? form.all.tags('select') : []),
  (form[gE] ? form[gE]('textarea') : form.all ? form.all.tags('textarea') : [])
 ];

 // Loop through each list of tags, constructing our string.
 for (var i = 0; i < inputs.length; i++)
  for (j = 0; j < inputs[i].length; j++)
   if (inputs[i][j])
   {
    var plus = '++'.substring(0,1); 
    str += escape(inputs[i][j].getAttribute('name')).replace(plus, '%2B') +
     '=' + escape(inputs[i][j].value).replace(plus, '%2B') + '&';
   }

  return str.substring(0, str.length - 1);
}};

HttpRequest.prototype.xmlhttpSend = function(uri, formStr, text) { with (this)
{
 //  XMLHttpRequest is used  to asynchronously open a URI, and optionally POST a provided
 // form string if any (otherwise, performs a GET).

 xmlhttp.open(formStr? 'POST' : 'GET', uri, true);

 if (formStr )
	 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	 
 xmlhttp.onreadystatechange = function() {
  if (xmlhttp.readyState == 4)
  {
  	
   var doc;
   if(text)
   	doc = xmlhttp.responseText;
   else
   	doc= xmlhttp.responseXML;
   if (callback) callback(doc);
  }
   else
	if(waiter) waiter();
 };
 xmlhttp.send(formStr);
 return true;
}};

function EmailValidation(str)
{
	var regx = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	
	var email = regx.exec(str);
	if(email)
	{
		return true;
	}
	else return false;
}

function SendMail(requesturl,responseHandler,from,fromname,subject,message,waithandler)
{
	
    try{
	var validator = new HttpRequest('username',responseHandler,waithandler);
	if( validator == null)
	    alert("could not create http request object");
	var data = "from="+from+"&fromname="+fromname+"&subject="+subject+"&body="+message;
	return validator.xmlhttpSend(requesturl,data,true);
	}
	catch(e){
	alert(e);}
	return false;
}
// <!CDATA[
function ResponseHandler(doc)
{
    document.getElementById('msg').innerHTML = doc;
    
    document.getElementById('button').disabled = "false";
}

function WaitHandler()
{
    document.getElementById('button').disabled = "true";
    document.getElementById('msg').innerHTML = "Sending...";
}
