IOL.API={url:"/api.iol.php",format:"json",check_auth:false,version:"1.0"};IOL.API.request=function(h,e,f,j,d,k){if(typeof e!="object"){e={}}e.method=h;e._ts=new Date().getTime();var c=(j)?false:true;k=k||1;if(e.arrback||e.objback){j=1;c=0}if(!f){f=window}var a=this.url+"/"+h+"/"+this.format;var g=_post_params(e);console.log("API Call "+h+",async: "+c+", tries: "+k+", params : "+g+", url :"+a);var i;if(c){var b={method:"post",asynchronous:true,encoding:"UTF-8",requestHeaders:{"X-API-Version":this.version},postBody:g,onSuccess:function(m){if(window.window_is_unloaded){try{i.abort()}catch(n){}return}if(m.responseText.empty()&&k<3){i.abort();IOL.API.request(h,e,f,j,d,k+1)}else{IOL.API.response(h,e,f,m.responseXML,m.responseText)}},onFailure:function(){if(window.window_is_unloaded){try{i.abort()}catch(m){}return}if(k<3){IOL.API.request(h,e,f,j,d,k+1)}else{IOL.API.response(h,e,f,"","")}}};if(d){setTimeout(function(){i=new Ajax.Request(a,b)},d)}else{i=new Ajax.Request(a,b)}}else{i=new Ajax.Request(a,{method:"post",asynchronous:false,encoding:"UTF-8",postBody:g,requestHeaders:{"X-API-Version":this.version}});var l=i.transport;return this.response(h,e,f,l.responseXML,l.responseText)}};IOL.API.response=function(e,b,d,c,a){if(this.format=="xml"){return IOL.API.responseXML(e,b,d,c,a)}else{if(this.format=="json"){return IOL.API.responseJSON(e,b,d,a)}}};IOL.API.responseJSON=function(g,b,f,a){var j;try{j=(a||"").evalJSON()}catch(e){console.log("API invalid JSON response : "+a);j={}}if(typeof(j)=="object"&&j.status!=undefined){var i=(j.status>0)?true:false}else{j={error:{id:900}};var i=false}var h;if(b.callback){h=b.callback+"_onApi"}else{h=g.str_replace(".","_")+"_onApi"}if(this.check_auth&&(j.user_id!=glob_user_id)&&!j.error){j.error={id:105}}if(j.error&&j.error.id==105){if(confirm(_MSG.api_err_105)){var c=document.URL;document.location=c+((c.indexOf("?")>=0)?"&":"?")+"login[method]=login&login[errid]=8"}return}if(b.arrback){return[i,j,a,b]}if(b.objback){return{success:i,rsp:j,txt:a,params:b}}if(b.noback){return}console.info("API Callback "+h+", success : "+i);
if(f[h]){f[h](i,j,a,b)}else{console.warn("API can't find callback function : "+h)}};IOL.API.responseXML=function(f,b,e,c,a){if(!c){var g=(a.indexOf('status="1"')>-1)?true:false}else{var g=(c.documentElement&&c.documentElement.getAttribute("status")=="1")?true:false}if(b.arrback){return new Array(g,rsp,a,b)}var d;if(b.callback){d=b.callback+"_onApi"}else{d=f.str_replace(".","_")+"_onApi"}if(e[d]){e[d](g,c,a,b)}else{IOL.debug("API can't find callback function : "+d)}};function escape_utf8(e){if(e=="0"){return 0}if(e==""||e==null||!e){return""}e=e.toString();var g,d;var a="";var b=0;while(b<e.length){g=e.charCodeAt(b++);if(g>=56320&&g<57344){continue}if(g>=55296&&g<56320){if(b>=e.length){continue}d=e.charCodeAt(b++);if(d<56320||g>=56832){continue}g=((g-55296)<<10)+(d-56320)+65536}if(g<128){a+=String.fromCharCode(g)}else{if(g<2048){a+=String.fromCharCode(192+(g>>6),128+(g&63))}else{if(g<65536){a+=String.fromCharCode(224+(g>>12),128+(g>>6&63),128+(g&63))}else{a+=String.fromCharCode(240+(g>>18),128+(g>>12&63),128+(g>>6&63),128+(g&63))}}}}var f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";e=a;a="";for(var b=0;b<e.length;b++){if(f.indexOf(e.charAt(b))==-1){a+="%"+to_hex(e.charCodeAt(b))}else{a+=e.charAt(b)}}return a}function to_hex(b){var a="0123456789ABCDEF";return a.charAt(b>>4)+a.charAt(b&15)}function _post_params(e,d){var c="";if(e instanceof Array){for(var b=0;b<e.length;b++){var a=e[b];if(typeof a=="object"||typeof a=="array"){c+="&"+_post_params(a,d?d+"["+b+"]":b)}else{if(d){c+="&"+d+"["+b+"]="+escape_utf8(a)}else{c+="&"+b+"="+escape_utf8(a)}}}}else{if(e instanceof Object){for(var b in e){if(b=="method"||b=="callback"||b=="arrback"||b=="objback"||b=="noback"||b.indexOf("_")==0){continue}var a=e[b];if(typeof a=="object"||typeof a=="array"){c+="&"+_post_params(a,d?d+"["+b+"]":b)}else{if(d){c+="&"+d+"["+b+"]="+escape_utf8(a)}else{c+="&"+b+"="+escape_utf8(a)}}}}}return c.substr(1,c.length)}IOL.API.query=function(f,e,c,i,j){e=(typeof e=="object")?e:{};i=(typeof i=="object")?i:{};if(c=="return"){i.sync=true
}var d=(i.sync)?false:true;j=j||1;if(!i.no_at){e._at=Math.round(new Date().getTime()/1000)}if(!window.glob_api_key){IOL.debug("err","API Key is missing");return}if(window.glob_api_key){e.api_key=window.glob_api_key}if(window.glob_api_hash){e.auth_token=window.glob_api_hash}var a="/api/"+f+"/json";if(window.glob_api_secret){var h=[],l="";for(var b in e){h.push(b)}h.sort();h.each(function(m){l+=m+e[m]});l+=f+window.glob_api_secret;e.api_sig=get_md5(l);console.log(l);console.log(e.api_sig)}IOL.debug("info","API Call url :"+a+", async="+d+", tries="+j+", params=...");IOL.debug(1,e);var g;if(d){var b={method:"post",asynchronous:true,encoding:"UTF-8",requestHeaders:{"X-API-Version":this.version},parameters:e,onSuccess:function(m){if(window.window_is_unloaded){try{g.abort()}catch(n){}return}if(m.responseText.empty()&&j<3){g.abort();IOL.API.query(f,e,c,i,j+1)}else{IOL.API.replyJSON(f,e,c,i,m)}},onFailure:function(){if(window.window_is_unloaded){try{g.abort()}catch(m){}return}if(j<3){g.abort();IOL.API.query(f,e,c,i,j+1)}else{IOL.API.replyJSON(f,e,c,i,null)}}};if(i.delay){setTimeout(function(){g=new Ajax.Request(a,b)},i.delay)}else{g=new Ajax.Request(a,b)}}else{g=new Ajax.Request(a,{method:"post",asynchronous:false,encoding:"UTF-8",parameters:e,requestHeaders:{"X-API-Version":this.version}});var k=g.transport;return IOL.API.replyJSON(f,e,c,i,k)}};IOL.API.replyJSON=function(f,h,d,c,a){var b;if(a&&a.responseText){b=a.responseText.evalJSON(true)}else{IOL.debug("err","API response is NULL");b={}}var g=(b.api&&b.api.status=="ok")?true:false;if(g){IOL.debug("info","API call is sucessfull")}else{IOL.debug("warn","API call failed: "+api.code+" "+api.message)}c.method=f;if(d=="return"){return{success:g,rsp:b,params:h,options:c}}else{d=d||window;var e=(c.callback)?c.callback+"_onApi":f.str_replace(".","_")+"_onApi";if(d[e]){d[e](g,b,h,c)}else{IOL.debug("err","API could not find callback="+e)}}};function get_md5(n){var l=n.length*8;var q=Array();var t=(1<<8)-1;for(var h=0;h<l;h+=8){q[h>>5]|=(n.charCodeAt(h/8)&t)<<(h%32)}q[l>>5]|=128<<((l)%32);
q[(((l+64)>>>9)<<4)+14]=l;var r=1732584193;var p=-271733879;var o=-1732584194;var m=271733878;for(var h=0;h<q.length;h+=16){var k=r;var j=p;var g=o;var e=m;r=md5_ff(r,p,o,m,q[h+0],7,-680876936);m=md5_ff(m,r,p,o,q[h+1],12,-389564586);o=md5_ff(o,m,r,p,q[h+2],17,606105819);p=md5_ff(p,o,m,r,q[h+3],22,-1044525330);r=md5_ff(r,p,o,m,q[h+4],7,-176418897);m=md5_ff(m,r,p,o,q[h+5],12,1200080426);o=md5_ff(o,m,r,p,q[h+6],17,-1473231341);p=md5_ff(p,o,m,r,q[h+7],22,-45705983);r=md5_ff(r,p,o,m,q[h+8],7,1770035416);m=md5_ff(m,r,p,o,q[h+9],12,-1958414417);o=md5_ff(o,m,r,p,q[h+10],17,-42063);p=md5_ff(p,o,m,r,q[h+11],22,-1990404162);r=md5_ff(r,p,o,m,q[h+12],7,1804603682);m=md5_ff(m,r,p,o,q[h+13],12,-40341101);o=md5_ff(o,m,r,p,q[h+14],17,-1502002290);p=md5_ff(p,o,m,r,q[h+15],22,1236535329);r=md5_gg(r,p,o,m,q[h+1],5,-165796510);m=md5_gg(m,r,p,o,q[h+6],9,-1069501632);o=md5_gg(o,m,r,p,q[h+11],14,643717713);p=md5_gg(p,o,m,r,q[h+0],20,-373897302);r=md5_gg(r,p,o,m,q[h+5],5,-701558691);m=md5_gg(m,r,p,o,q[h+10],9,38016083);o=md5_gg(o,m,r,p,q[h+15],14,-660478335);p=md5_gg(p,o,m,r,q[h+4],20,-405537848);r=md5_gg(r,p,o,m,q[h+9],5,568446438);m=md5_gg(m,r,p,o,q[h+14],9,-1019803690);o=md5_gg(o,m,r,p,q[h+3],14,-187363961);p=md5_gg(p,o,m,r,q[h+8],20,1163531501);r=md5_gg(r,p,o,m,q[h+13],5,-1444681467);m=md5_gg(m,r,p,o,q[h+2],9,-51403784);o=md5_gg(o,m,r,p,q[h+7],14,1735328473);p=md5_gg(p,o,m,r,q[h+12],20,-1926607734);r=md5_hh(r,p,o,m,q[h+5],4,-378558);m=md5_hh(m,r,p,o,q[h+8],11,-2022574463);o=md5_hh(o,m,r,p,q[h+11],16,1839030562);p=md5_hh(p,o,m,r,q[h+14],23,-35309556);r=md5_hh(r,p,o,m,q[h+1],4,-1530992060);m=md5_hh(m,r,p,o,q[h+4],11,1272893353);o=md5_hh(o,m,r,p,q[h+7],16,-155497632);p=md5_hh(p,o,m,r,q[h+10],23,-1094730640);r=md5_hh(r,p,o,m,q[h+13],4,681279174);m=md5_hh(m,r,p,o,q[h+0],11,-358537222);o=md5_hh(o,m,r,p,q[h+3],16,-722521979);p=md5_hh(p,o,m,r,q[h+6],23,76029189);r=md5_hh(r,p,o,m,q[h+9],4,-640364487);m=md5_hh(m,r,p,o,q[h+12],11,-421815835);o=md5_hh(o,m,r,p,q[h+15],16,530742520);p=md5_hh(p,o,m,r,q[h+2],23,-995338651);r=md5_ii(r,p,o,m,q[h+0],6,-198630844);
m=md5_ii(m,r,p,o,q[h+7],10,1126891415);o=md5_ii(o,m,r,p,q[h+14],15,-1416354905);p=md5_ii(p,o,m,r,q[h+5],21,-57434055);r=md5_ii(r,p,o,m,q[h+12],6,1700485571);m=md5_ii(m,r,p,o,q[h+3],10,-1894986606);o=md5_ii(o,m,r,p,q[h+10],15,-1051523);p=md5_ii(p,o,m,r,q[h+1],21,-2054922799);r=md5_ii(r,p,o,m,q[h+8],6,1873313359);m=md5_ii(m,r,p,o,q[h+15],10,-30611744);o=md5_ii(o,m,r,p,q[h+6],15,-1560198380);p=md5_ii(p,o,m,r,q[h+13],21,1309151649);r=md5_ii(r,p,o,m,q[h+4],6,-145523070);m=md5_ii(m,r,p,o,q[h+11],10,-1120210379);o=md5_ii(o,m,r,p,q[h+2],15,718787259);p=md5_ii(p,o,m,r,q[h+9],21,-343485551);r=md5_add(r,k);p=md5_add(p,j);o=md5_add(o,g);m=md5_add(m,e)}var s=Array(r,p,o,m);var f="0123456789abcdef";n="";for(var h=0;h<s.length*4;h++){n+=f.charAt((s[h>>2]>>((h%4)*8+4))&15)+f.charAt((s[h>>2]>>((h%4)*8))&15)}return n}function md5_cmn(h,e,d,c,g,f){return md5_add(md5_rol(md5_add(md5_add(e,h),md5_add(c,f)),g),d)}function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)}function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)}function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)}function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)}function md5_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}function md5_rol(a,b){return(a<<b)|(a>>>(32-b))};