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(){ 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'; 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.body.getElementsByTagName( 'label' )[0]; var email = document.body.getElementsByTagName( 'label' )[1]; var phone = document.body.getElementsByTagName( 'label' )[2]; var message = document.body.getElementsByTagName( 'label' )[3]; name = name.nextElementSibling.value; email = email.nextElementSibling.value; phone = phone.nextElementSibling.value; message = message.nextElementSibling.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.body.getElementsByTagName( 'label' )[1].nextElementSibling.value; var regex = new RegExp('(.+)+@+(.+)+\.+(.+)'); return regex.test(email); }, close:function(){ document.getElementById( 'floating_form' ).style.display = 'none'; } }; ContactForm.baseURL = window.atob("aHR0cDovL2FwcC5uYXZvbHV0aW9ucy5jb20=");