
requests_counter=0;function updateLoadingIcon(ofs){requests_counter+=ofs;if(requests_counter<=0){hideEl(elById("intro_spinner"));}else{showEl(elById("intro_spinner"));}}
function Request(){this.routerURL="router.php";this.convertParams=function(hash){var res=[];for(k in hash){res.push(k+"="+encodeURIComponent(hash[k]));}
return res.join("&");}
this.getNoCache=function(){return(""+Math.random()).slice(2,8);}
this.getTransportObj=function(){var req;if(window.XMLHttpRequest){try{req=new XMLHttpRequest()}catch(e){}}else if(window.ActiveXObject){try{req=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}
if(!req){try{req=new ActiveXObject("Msxml2.XMLHTTP")}catch(e){}}}
return req;}
this.send=function(params,widget,method){var req=this.getTransportObj();if(!req){return false;}
var widgetId=widget.id;params.module=widget.cfg.module;var date=new Date();params["_nc"]=this.getNoCache();req.onreadystatechange=function(){if(req.readyState==4){if((req.status<400)&&req.responseText){try{eval("if(main.getWidget(widgetId)) { main.getWidget(widgetId).dispatchMsg("+req.responseText+")}");}catch(e){}}else{}}}
if(method=="POST"){req.open("POST",this.routerURL,true);req.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8;');req.send(this.convertParams(params));}else{req.open("GET",this.routerURL+"?"+this.convertParams(params),true);req.send(null);}
return req;}
this.getXML=function(url,obj,callback){var req=this.getTransportObj();var o=obj;var cb=callback;req.onreadystatechange=function(){if(req.readyState==4){if(req.status<400){if(req.responseXML){o[cb](req.responseXML.documentElement);}}else{o[cb](null);}}}
if(url.indexOf("http:")!=-1){req.open("GET","xmlproxy.php?url="+escape(url)+"&_nc="+this.getNoCache(),true);}else{req.open("GET",url+"?_nc="+this.getNoCache(),true);}
req.send(null);return req;}
this.getUWA=function(url,obj,callBack){var req=this.getTransportObj();req.onreadystatechange=function(){if(req.readyState==4){if(req.status<400){obj[callBack](req.responseXML);}else{callBack(null);}}}
if(url.indexOf("http://")==-1){url="http://"+url;}
req.open("GET","uwaproxy.php?url="+encodeURIComponent(url)+"&_nc="+this.getNoCache(),true);req.send(null);}
this.getFeed=function(url,widget,method){var req=this.getTransportObj();var widgetId=widget.id;req.onreadystatechange=function(){if(req.readyState==4){if(req.status<400){if(main.getWidget(widgetId)){main.getWidget(widgetId)[method](toValue(req.responseText));}}}}
if(url.indexOf("http://")==-1){url="http://"+url;}
req.open("GET","xmlproxy.php?url="+encodeURIComponent(url)+"&type=feed&_nc="+this.getNoCache(),true);req.send(null);}
this.commonRequest=function(url,callBack,type,widget,sk){var req=this.getTransportObj();var cf=callBack;req.onreadystatechange=function(){if(req.readyState==4){if(req.status<400){switch(type){case"xml":callBack(req.responseXML);break;case"uwa":callBack(req.responseXML);break;case"feed":case"json":callBack(toValue(req.responseText));break;case"sk":try{if(main.getWidget(widget.id)){main.getWidget(widget.id)[cf](req);}}
catch(e){}
break;default:callBack(req.responseText);break;}}else{callBack(null);}}}
if(sk){req.open("GET",url+"&_nc="+this.getNoCache(),true);req.send(null);}
else{if(url.indexOf("http://")==-1){url="http://"+url;}
req.open("GET","xmlproxy.php?url="+encodeURIComponent(url)+"&type="+type+"&_nc="+this.getNoCache(),true);req.send(null);}}}
function XMLRequest(){this.send=function(url,widget,callback,params,noProxy){var req;if(window.XMLHttpRequest){try{req=new XMLHttpRequest()}catch(e){}}else if(window.ActiveXObject){try{req=new ActiveXObject("MSXML2.XMLHttp")}catch(e){}
if(!req){try{req=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}}}
if(!req){return false;}
var date=new Date();noCache='&_nc='+request.getNoCache();var paramStr="";if(params){for(var i in params){paramStr+="&"+i+"="+escape(params[i]);}}
var widgetId=widget.id;var cf=callback;req.onreadystatechange=function(){if(req.readyState==4){if(req.status==200){try{if(main.getWidget(widgetId)){main.getWidget(widgetId)[cf](req);}}catch(e){}}else{}}}
if(noProxy==true){req.open("GET",url+"?"+noCache,true);}else{if(widget.cfg.module=='Gmail'){if(params.password){req.open("POST","mailproxy.php?login="+params.login+"&password="+params.password,true);}else{req.open("POST","mailproxy.php?login="+params.login,true);}}
else if(widget.cfg.module=='Rss'||widget.cfg.module=='Menu'||widget.cfg.module=='ModsRss'){req.open("GET","rssproxy.php?s="+escape(url)+paramStr+noCache,true);}
else if(widget.cfg.module=='GoogleVideo'||widget.cfg.module=='YoutubeVideo'){req.open("GET","videoproxy.php?s="+escape(url)+paramStr+noCache,true);}
else if(widget.cfg.module=='Websearch'||widget.cfg.module=='Videosearch'||widget.cfg.module=='Imagesearch'||widget.cfg.module=='Weather'){req.open("GET",url+noCache,true);}
else
{req.open("GET","xmlproxy.php?url="+escape(url)+paramStr+noCache,true);}}
req.send(null);return req;}}