var xmlHttp // ------------------------------------------------------------------- // Central AJAX Call // ------------------------------------------------------------------- function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { //Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } // ------------------------------------------------------------------- // General Utilities // ------------------------------------------------------------------- // General trim of all white space in string function trim_all(s) { var i; var returnString = ""; // Search through string's characters one by one. // If character is not a whitespace, append to returnString. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (c != " ") returnString += c; } return returnString; } // Specific trim of only whitespace (or specified char) at the end or beginning of a string. // Parameters: // str: string to trim (required). // chars: character to trim from string (optional. defaults to white space char). function trim(str, chars) { return ltrim(rtrim(str, chars), chars); } // Left trim only. function ltrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); } // Right trim only. function rtrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); } function hov(loc,cls) { if(loc.className) loc.className=cls; } function isInt(x) { var y=parseInt(x); if (isNaN(y)) return false; return x==y && x.toString()==y.toString(); } function doClick(buttonName,e) { //the purpose of this function is to allow the enter key to //point to the correct button to click. var key; if (window.event) { key = window.event.keyCode; //IE } else { key = e.which; //firefox } if (key == 13) { //Get the button the user wants to have clicked var btn = document.getElementById(buttonName); if (btn != null) { //If we find the button click it btn.click(); //e.keyCode = 0 key = ""; } } } function textCounter(field, countfield) { countfield.value = field.value.length; } /*function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit) // if too long...trim it! field.value = field.value.substring(0, maxlimit); // otherwise, update 'characters left' counter else countfield.value = maxlimit - field.value.length; } */ function convertPagerListForPost(textData) { var result = ""; // Convert multi-line pager text to be ':' separated list var lines = textData.split('\n'); for (var i = 0;i < lines.length;i++) { if (i > 0) { result += ":"; } result += lines[i]; } return encodeURI(result); } function submitRequest() { clearFeedback(); xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } if (checkform()) { var passwd = trim(document.getElementById("passwd").value); var pagerText = document.getElementById("pagers").value; var pagers = convertPagerListForPost(pagerText); var msgText = document.getElementById("idmsg").value; var replyEmail = trim(document.getElementById("email_reply").value); var url = "http://www.xms.com.au/cgi-bin/xmhsweb_sms"; var params = "passwd=" + encodeURI(passwd) + "&pagers=" + pagers + "&msgText=" + encodeURI(msgText); "&email_reply=" + encodeURI(replyEmail); if (replyEmail.length > 0) { params = params + "&email_reply=" + encodeURI(replyEmail); } xmlHttp.open("POST", url, true); //Send the proper header information along with the request xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.onreadystatechange=handleRequestReply; xmlHttp.send(params); } } function handleRequestReply() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { // Parse reply text and determine whether message entry was successful var reply = xmlHttp.responseText; var success = (reply.indexOf("Message succesfully sent") > 1); // Notify user of success/fail var feedback = document.getElementById("messageFeedback"); if (success) { feedback.innerHTML = "" + reply + ""; } else { feedback.innerHTML = "" + reply + ""; } } } function checkform() { var feedback = document.getElementById("messageFeedback"); // Ensure that it is possible to provide feedback if (feedback == null) { alert("Error! Feedback element missing!"); return false; } // Ensure password has been specified. var txt = document.getElementById("passwd"); if (txt != null) { if (txt.value == null || txt.value == "") { feedback.innerHTML = "" + "You must enter your xms gateway password." + ""; return false; } } // Ensure pager has been specified. txt = document.getElementById("pagers"); if (txt != null) { if (txt.value == null || txt.value == "") { feedback.innerHTML = "" + "You must enter at least one pager/mobile number." + ""; return false; } } // Ensure message has been specifed. txt = document.getElementById("idmsg"); if (txt != null) { if (txt.value == null || txt.value == "") { feedback.innerHTML = "" + "You must enter a message." + ""; return false; } } // Look for optional email address, and if present, ensure it's valid. txt = document.getElementById("email_reply"); if (txt != null) { var emailTxt = trim(txt.value); if (emailTxt != null && emailTxt != "") { if (echeck(emailTxt) == false) { feedback.innerHTML = "" + "The reply email is optional. But if entered, it must be a valid email address." + ""; return false; } } } return true; } function echeck(str) { var at="@" var dot="." var lat=str.indexOf(at) var lstr=str.length var ldot=str.indexOf(dot) if (str.indexOf(at)==-1){ //alert("Invalid E-mail ID") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) { //alert("Invalid E-mail ID") return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) { //alert("Invalid E-mail ID") return false } if (str.indexOf(at,(lat+1))!=-1) { //alert("Invalid E-mail ID") return false } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) { //alert("Invalid E-mail ID") return false } if (str.indexOf(dot,(lat+2))==-1) { //alert("Invalid E-mail ID") return false } if (str.indexOf(" ")!=-1) { //alert("Invalid E-mail ID") return false } return true } function clearFeedback() { var feedback = document.getElementById("messageFeedback"); // Ensure that it is possible to provide feedback if (feedback != null) { feedback.innerHTML = ""; } }