// JavaScript Document
/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();






// code for mail form

/* -------------------------- */
/* LOGIN */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function sendmail() {
// Optional: Show a waiting message in the layer with ID ajax_response
document.getElementById('login_response').innerHTML = "<img src='images/loading.gif'/>"
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var name = encodeURI(document.getElementById('name').value);
var txtPhone = encodeURI(document.getElementById('txtPhone').value);
var email = encodeURI(document.getElementById('email').value);
var message = encodeURI(document.getElementById('message').value);
var security_code = encodeURI(document.getElementById('security_code').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'contact_process.php?name='+name+'&txtPhone='+txtPhone+'&email='+email+'&message='+message+'&security_code='+security_code+'&nocache = '+nocache);
http.onreadystatechange = loginReply;
http.send(null);
}
function loginReply() {
if(http.readyState == 4){ 
var response = http.responseText;
//alert (response);
if(response == 0)
{
// if login fails
document.getElementById('login_response').innerHTML = 'You have provided an invalid security code';
// else if login is ok show a message: "Welcome + the user name".
}
else
{
document.getElementById('login_response').innerHTML = 'Your claim request has been submitted';
reset();
}
}
}
