function SendToPhoneClient(a,b){this.url=a;this.responseHandler=b;this.elements={};for(var c in SendToPhoneClient.ElementId){a=document.getElementById(SendToPhoneClient.ElementId[c]);if(!a)throw new Error("Document must contain an element with id "+SendToPhoneClient.ElementId[c]);this.elements[SendToPhoneClient.ElementId[c]]=a}this.get()}SendToPhoneClient.ElementId={CLIENT:"stp-client",LANGUAGE:"stp-hl",LOCALE:"stp-gl",LANDING:"stp-landing"};
SendToPhoneClient.prototype.makeServiceHandler=function(a){var b=this;a.onreadystatechange=function(){if(a.readyState==4){b.debug(a.responseText);var c=eval("("+a.responseText+")");if(c.success)b.responseHandler.onSuccess();else if(c.errorGeneral)b.responseHandler.onError(SendToPhoneClient.ErrorType.GENERAL,c.errorGeneralId,c.errorGeneral);else if(c.errorMobileUserId)b.responseHandler.onError(SendToPhoneClient.ErrorType.MOBILE_USER_ID,c.errorMobileUserIdId,c.errorMobileUserId);else if(c.errorTextToSend)b.responseHandler.onError(SendToPhoneClient.ErrorType.TEXT_TO_SEND,
c.errorTextToSendId,c.errorTextToSend);else c.errorCarrier?b.responseHandler.onError(SendToPhoneClient.ErrorType.CARRIER,c.errorCarrierId,c.errorCarrier):b.responseHandler.onLanding(b.createCaptcha(c),c.carrier,c.mobileUserId)}};return true};
SendToPhoneClient.prototype.get=function(){var a=this.createRequest();this.makeServiceHandler(a);var b=this.url;b+="?client="+escape(this.elements[SendToPhoneClient.ElementId.CLIENT].value);b+="&hl="+escape(this.elements[SendToPhoneClient.ElementId.LANGUAGE].value);b+="&gl="+escape(this.elements[SendToPhoneClient.ElementId.LOCALE].value);a.open("GET",b,true);a.send(null)};
SendToPhoneClient.prototype.post=function(){var a=this.createRequest();this.makeServiceHandler(a);var b=this.getParameterString();a.open("POST",this.url,true);a.setRequestHeader("Content-type","application/x-www-form-urlencoded");a.setRequestHeader("Content-length",b.length);a.setRequestHeader("Connection","close");a.send(b);this.responseHandler.onSubmit();return false};
SendToPhoneClient.prototype.getParameterString=function(){var a=this.elements[SendToPhoneClient.ElementId.LANDING],b=a.getElementsByTagName("input"),c=[],d=0;for(d=0;d<b.length;++d)c.push(b[d].name+"="+window.encodeURIComponent(b[d].value));a=a.getElementsByTagName("select");for(d=0;d<a.length;++d)a[d].options.length>0&&c.push(a[d].name+"="+window.encodeURIComponent(a[d].options[a[d].selectedIndex].value));return c.join("&")};
SendToPhoneClient.prototype.createRequest=function(){try{if(typeof ActiveXObject!="undefined")return new ActiveXObject("Microsoft.XMLHTTP");else if(window.XMLHttpRequest)return new XMLHttpRequest}catch(a){}return null};SendToPhoneClient.prototype.createCaptcha=function(a){if(!a.urlCaptcha)return null;var b={};b.url=a.urlCaptcha;b.width=a.captchaWidth;b.height=a.captchaHeight;b.error=a.errorCaptcha;b.encryptedAnswer=a.encrypted_captcha_answer;return b};
SendToPhoneClient.ErrorType={CARRIER:"stp-error-carrier",GENERAL:"stp-error-general",MOBILE_USER_ID:"stp-error-mobile-user-id",TEXT_TO_SEND:"stp-error-text-to-send"};SendToPhoneClient.prototype.debug=function(a){var b=document.getElementById("stp-json");if(b)b.innerHTML=a};
function DefaultSTPResponseHandler(){this.elements={};for(var a in DefaultSTPResponseHandler.ElementIds){var b=document.getElementById(DefaultSTPResponseHandler.ElementIds[a]);if(!b)throw new Error("Document must contain an element with id "+DefaultSTPResponseHandler.ElementIds[a]);this.elements[DefaultSTPResponseHandler.ElementIds[a]]=b}}
DefaultSTPResponseHandler.ElementIds={CAPTCHA:"stp-captcha",CAPTCHA_ANSWER:"stp-encrypted-captcha-answer",CAPTCHA_ERROR:"stp-captcha-error",CAPTCHA_IMAGE:"stp-captcha-image",CARRIER:"stp-carrier",CARRIER_ERROR:SendToPhoneClient.ErrorType.CARRIER,CARRIERS:"stp-carriers",LANDING:"stp-landing",NUMBER:"stp-number",SUCCESS:"stp-success",GENERAL_ERROR:SendToPhoneClient.ErrorType.GENERAL,MOBILE_USER_ID_ERROR:SendToPhoneClient.ErrorType.MOBILE_USER_ID,TEXT_TO_SEND_ERROR:SendToPhoneClient.ErrorType.TEXT_TO_SEND};
DefaultSTPResponseHandler.prototype.onSuccess=function(){hide(this.elements[DefaultSTPResponseHandler.ElementIds.LANDING]);setDisplayStyle(this.elements[DefaultSTPResponseHandler.ElementIds.SUCCESS],"")};DefaultSTPResponseHandler.prototype.onError=function(a,b,c){if(a=document.getElementById(a)){a.innerHTML=c;a.style.display=""}};
DefaultSTPResponseHandler.prototype.onLanding=function(a,b,c){setDisplayStyle(this.elements[DefaultSTPResponseHandler.ElementIds.LANDING],"");hide(this.elements[DefaultSTPResponseHandler.ElementIds.SUCCESS]);if(a){setDisplayStyle(this.elements[DefaultSTPResponseHandler.ElementIds.CAPTCHA],"");this.elements[DefaultSTPResponseHandler.ElementIds.CAPTCHA_IMAGE].src=a.url;this.elements[DefaultSTPResponseHandler.ElementIds.CAPTCHA_ANSWER].value=a.encryptedAnswer;if(a.error){var d=this.elements[DefaultSTPResponseHandler.ElementIds.CAPTCHA_ERROR];
d.innerHTML=a.error;setDisplayStyle(d,"")}}else hide(this.elements[DefaultSTPResponseHandler.ElementIds.CAPTCHA]);if(b){a=this.elements[DefaultSTPResponseHandler.ElementIds.CARRIERS];for(var e in b){d=document.createElement("option");d.text=b[e].name;d.value=b[e].value;try{a.add(d,null)}catch(f){a.add(d)}}setDisplayStyle(this.elements[DefaultSTPResponseHandler.ElementIds.CARRIER],"")}if(c)this.elements[DefaultSTPResponseHandler.ElementIds.NUMBER].value=c};
DefaultSTPResponseHandler.prototype.onSubmit=function(){for(var a in SendToPhoneClient.ErrorType)hide(document.getElementById(SendToPhoneClient.ErrorType[a]));hide(this.elements[DefaultSTPResponseHandler.ElementIds.CAPTCHA_ERROR])};function setDisplayStyle(a,b){if(a)a.style.display=b}function hide(a){setDisplayStyle(a,"none")}window.SendToPhoneClient=SendToPhoneClient;window.DefaultSTPResponseHandler=DefaultSTPResponseHandler;var JSCompiler_inline_pSendToPhoneClient_33=SendToPhoneClient.prototype;
JSCompiler_inline_pSendToPhoneClient_33.post=JSCompiler_inline_pSendToPhoneClient_33.post;
