
if(typeof jajah=="undefined")var jajah=new Object();if(typeof jajah.events=="undefined")jajah.events=new Object();jajah.events.Dispatcher=function(){}
jajah.events.Dispatcher.prototype={init:function(o){o.addEventListener=this.addEventListener;o.removeEventListener=this.removeEventListener;o.dispatchEvent=this.dispatchEvent;},addEventListener:function(type,listner){type="_jj_"+type;if(typeof this[type]=="undefined")
{this[type]=new Array();}
JajahDispatcher.removeEventListener(this[type],listner);this[type].push(listner);},removeEventListener:function(type,listener){if(typeof type=="string")type=this["_jj_"+type];if(type!=undefined)
{var l=type.length;var i;for(i=0;i<l;i++)
{var o=type[i];if(o.constructor==listener.constructor){if(o.toString()==listener.toString()){type.splice(i,1);return;}}}}},dispatchEvent:function(evt){var type=this["_jj_"+evt];if(typeof type!="undefined"){var l=type.length;var i;for(var i=0;i<l;i++){type[i].call();}}}}
var JajahDispatcher=new jajah.events.Dispatcher();
if(typeof jajah=="undefined")var jajah=new Object();if(typeof jajah.buttons=="undefined")jajah.buttons=new Object();jajah.buttons.Events=function(){JajahDispatcher.init(this);this._path="http://www.jajah.com/buttons/api/call.ashx?type=script&m=";this._loading=false;this._lng="en";this.init();}
jajah.buttons.Events.prototype={init:function(){this.$d=document;this.$head=this.$d.getElementsByTagName('head')[0];this.scpt();this.res=null;this.regevt();},regevt:function(){var This=this;this.addEventListener("oncall",function(){This.oncall();});this.addEventListener("onstatus",function(){This.onstatus();});},scpt:function(){if(typeof this._scpt!="undefined")this.$head.removeChild(this._scpt);this._scpt=this.$d.createElement('script');this._scpt.type='text/javascript';this._scpt.defer=true;this.$head.appendChild(this._scpt)},load:function(s){if(this._loading)return;this.scpt();this._loading=true;this._scpt.src=this._path+s+"&lng="+this._lng+"&r="+$rnd();},call:function(sn,caller){this.stopstatus();this._sn=sn;this._caller=caller;var s="call&sn="+sn+"&num="+caller;this.load(s);},oncall:function(){this._cid=this.res.cid;this._guid=this.res.guid;if(this.res.er.sc){this.autostatus(3000);}else{this._lastError=this.res.er.ms;this.dispatchEvent("onerror");}},msg:function(msg){var s="msg&sn="+this._sn+"&num="+this._caller+"&guid="+this._guid+"&msg="+msg;this.load(s);},status:function(){var s="status&cid="+this._cid;this.load(s);},onstatus:function(){var s=this.res.stt.cd;if(s=="2"){this.autostatus(5000);}else if(s!="0"&&s!="1"&&s!="2"){this.stopstatus();}},autostatus:function(n){this.stopstatus();var This=this;this._inter=setInterval(function(){This.status();},n);},stopstatus:function(){clearInterval(this._inter);},el:function(id){return"string"==typeof(id)?this.$d.getElementById(id):id;}}
function $rnd(){return new Date().getTime();}
var JajahCallManager=new jajah.buttons.Events();
jajah.buttons.UI=function(){this._txt={yrnum:"Your number",nacur:"Currently not available",cntry:"Country",areanum:"Area and number"};this._callImg="http://www.jajah.com/images/buttons/jajah_free_call_button.gif";this._clickHtml='<a href="javascript;" onclick="JajahCallUI.draw(this, \'{sn}\');return false;"><img src="{image}" border="0"/></a>';this._inptHtml='<div style="position:relative;">+<input type="text" id="jajahCode" maxlength="5" value="{code}" style="width:35px;"/>-<input type="text" id="jajahNum" maxlength="15" value="{num}" style="width:90px;"/>&nbsp;<a href="#" onclick="JajahCallUI.call(this);return false;"><img src="http://www.jajah.com/images/buttons/call.gif" style="border:none;position:absolute;top:0px;"/></a></div><div class="enter" style="padding-left: 8px; font-size: 10px;">'+this._txt.cntry+' - '+this._txt.areanum+'</div>';this._loadHtml='<img style="padding-left:80px;" src="http://www.jajah.com/images/animations/loading.gif" style=""/></div>';this._callingHtml='<img src="http://www.jajah.com/images/buttons/green.gif"/>&nbsp;<img src="http://www.jajah.com/images/animations/connect_call2.gif"/>';this._naHtml='<img src="http://www.jajah.com/images/buttons/red.gif"/>';this._actHtml='<img src="http://www.jajah.com/images/buttons/green.gif"/>&nbsp;<img src="http://www.jajah.com/images/animations/active_call2.gif"  />&nbsp;<img src="http://www.jajah.com/images/buttons/green.gif"/>';this._autoParse=true;this.init();}
jajah.buttons.UI.prototype={init:function(){this.$d=document;this._code="1";this._caller=this.getCaller();this._mgr=JajahCallManager;this.regevt();},regevt:function(){var This=this;if(this._autoParse){var f=function(){This.parse();};if(this.$d.addEventListener){this.$d.addEventListener("DOMContentLoaded",f,false);}else{window.attachEvent("onload",f)}}
this._mgr.addEventListener("oncall",function(ui){This.oncall();});this._mgr.addEventListener("onstatus",function(ui){This.onstatus();});},parse:function(){
var a=this.getElementsByClassName("JajahButton","div",document);for(var i=0;i<a.length;i++){var sn=a[i].innerHTML.split("=")[1];this.parseit(a[i],sn);}
},parseit:function(e,sn){e.innerHTML=this._clickHtml.replace("{image}",this._callImg);e.style.display="";e.sn=sn;},draw:function(o,sn){this._mgr.stopstatus();this._lststt=-1;if(typeof this._curr!="undefined")this.showHtml("reset");this._curr=o.parentNode;if(typeof sn!="undefined"&&sn!="{sn}"){o.parentNode.sn=sn;}
this.showHtml("input")},drawInpt:function(){clearTimeout(this._timeout);var a=this._caller.split("-");var code=a.length>0&&a[0].length>=1&&a[0].length<=5?a[0]:this._code;var num=a.length>1&&a[0].length<=15?a[1]:this._txt.yrnum;this._curr.innerHTML=this._inptHtml.replace("{code}",code).replace("{num}",num);},call:function(o){var p=o.parentNode.parentNode;this._caller=this._mgr.el("jajahCode").value+"-"+this._mgr.el("jajahNum").value;this.saveCaller();this.showHtml("load");JajahCallManager.call(p.sn,this._caller);},oncall:function(){var r=this._mgr.res;if(r.er.sc){this.showHtml("calling");}else{this.showHtml("notavail");this.showLater("reset",5000);}},onstatus:function(){var r=this._mgr.res;var s=r.stt.cd;var bts=r.stt.bts;if(s=="1"||s=="2"){if(this._lststt!=s){this.showHtml("active");;}}else if(s!="0"&&s!="1"&&s!="2"){if(s!=3||bts=="2"||bts=="3"){this.showHtml("notavail");this.showLater("reset",5000);}else{this.showHtml("reset");}}
this._lststt=s;},showLater:function(html,n){clearTimeout(this._timeout);var This=this;this._timeout=setTimeout(function(){This.showHtml(html);},n,"reset");},showHtml:function(s){var c=this._curr;if(c.htmtp==s)return;switch(s){case"load":c.innerHTML=this._loadHtml;break;case"active":c.innerHTML=this._actHtml;break;case"calling":c.innerHTML=this._callingHtml;break;case"notavail":c.innerHTML=this._naHtml+"&nbsp;"+this._txt.nacur;break;case"reset":this.parseit(c,c.sn);break;case"input":this.drawInpt();break;}
c.htmtp=s;},saveCaller:function(){var date=new Date();date.setTime(date.getTime()+31104000000);var expires="; expires="+date.toGMTString();document.cookie="jajahcaller="+this._caller+expires+"; path=/";},getCaller:function(){var c=document.cookie;var name="jajahcaller=";var n1=c.indexOf(name)
if(n1>-1){n1+=name.length;var n2=c.indexOf(";",n1);if(n2<0)n2=n1+20;return c.substring(n1,n2);}
return"";},getElementsByClassName:function(className,tag,elm){var testClass=new RegExp("(^|\\\\s)"+className+"(\\\\s|$)");var tag=tag||"*";var elm=elm||document;var elements=(tag=="*"&&elm.all)?elm.all:elm.getElementsByTagName(tag);var returnElements=[];var current;var length=elements.length;for(var i=0;i<length;i++){current=elements[i];if(testClass.test(current.className)){returnElements.push(current);}}
return returnElements;}}
var JajahCallUI=new jajah.buttons.UI();