ContactForm = {
baseURL: undefined,
notifyUser:function( wasSuc ){
if( wasSuc == false ){
document.getElementById( 'notify_user' ).style.color = "#ff0000";
document.getElementById( 'notify_user' ).innerHTML = "Error sending message!";
}
else{
document.getElementById( 'notify_user' ).style.color = "#0000ff";
document.getElementById( 'contact_form_form' ).style.display = "none";
document.getElementById( 'notify_user' ).innerHTML = "Message was sent, thank you!
Click here to close this window."
}
document.getElementById( 'notify_user' ).style.display = "block";
},
renderForm:function(){
if( window.XMLHttpRequest ){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", ContactForm.baseURL + "/calls/mail/form",false);
xmlhttp.send(null);
document.getElementById( 'contact_form' ).innerHTML=xmlhttp.responseText;
},
createForm:function(){
// pull floating form
if( window.XMLHttpRequest ){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", ContactForm.baseURL + "/calls/mail/floating",false);
xmlhttp.send(null);
if( !document.getElementById('floating_form') ){
document.body.innerHTML += xmlhttp.responseText;
ContactForm.renderForm();
}
else{
document.getElementById( 'contact_form_form' ).style.display = "";
document.getElementById( 'notify_user' ).style.display = "none";
}
document.getElementById( 'floating_form' ).style.display = 'block';
document.getElementById( 'floating_form_modal' ).style.height = ContactForm.getDocHeight() + 'px';
document.getElementById( 'floating_form_modal' ).style.width = ContactForm.getDocWidth() + 'px';
document.getElementById( 'contact_form' ).style.position = 'absolute';
document.getElementById( 'contact_form' ).style.top = '50px';
document.getElementById( 'contact_form' ).style.left = String( ( document.body.offsetWidth / 2 ) - 210 ) + 'px';
window.scroll( 0, 0 );
},
getDocHeight:function() {
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
},
getDocWidth:function() {
var D = document;
return Math.max(
Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
Math.max(D.body.clientWidth, D.documentElement.clientWidth)
);
},
postToServer:function(){
// Prepare request data
var name = document.getElementById( 'marker' ).nextElementSibling;
var email = name.nextElementSibling;
var phone = email.nextElementSibling;
var message = phone.nextElementSibling;
name = name.getElementsByTagName('input')[0].value;
email = email.getElementsByTagName('input')[0].value;
phone = phone.getElementsByTagName('input')[0].value;
message = message.getElementsByTagName('textarea')[0].value;
if(ContactForm.validateInput() == true){
// Create request
var xmlhttp = new XMLHttpRequest();
if ("withCredentials" in xmlhttp) {
xmlhttp.open("POST", ContactForm.baseURL + "/calls/mail/send", true);
}
// IE support
else if (typeof XDomainRequest != "undefined") {
xmlhttp = new XDomainRequest();
xmlhttp.open("POST", ContactForm.baseURL + "/calls/mail/send");
}
else {
xmlhttp = null;
}
// Handle response from server
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
console.log(xmlhttp.responseText);
ContactForm.notifyUser(true);
}
else{
console.log(xmlhttp.responseText);
ContactForm.notifyUser(false);
}
}
// Prepare and send request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("name="+name+"&email="+email+"&phone="+phone+"&message="+message);
}
else{
document.getElementById( 'notify_user' ).style.color = "#ff0000";
document.getElementById( 'notify_user' ).innerHTML = "Please enter a valid Email Address";
document.getElementById( 'notify_user' ).style.display = "block";
}
},
validateInput:function(){
var email = document.getElementById( 'marker' ).nextElementSibling.nextElementSibling.getElementsByTagName('input')[0].value;
var regex = new RegExp('(.+)+@+(.+)+\.+(.+)');
return regex.test(email);
},
close:function(){
document.getElementById( 'floating_form' ).style.display = 'none';
}
};
ContactForm.baseURL = window.atob("aHR0cDovL2FwcC5uYXZvbHV0aW9ucy5jb20=");