﻿/**
*
*  uno.web.js 
*  by Hideki Yamamoto eu-gsm[+393453332248]
*  Version 0.9.0.0
*  This file is part of the uno js project.
*
*  ©Hideki Yamamoto all rights reserved.
*
*  Licence       : Http://about:blank
*  Documentation : Http://about:blank
*  History       : Http://about:blank
*
**/
if(!uno){alert('uno.web.js requires uno.js');};
if(!uno.xml){alert('uno.web.js requires uno.xml.js');};
if(!uno.window){alert('uno.web.js requires uno.dhtml.js');};
Namespace.register("uno.web");
/////////////////////////////////////////////////////////////////////////////////
////////////////////////   C L I E N T   U I   A P I   //////////////////////////
/////////////////////////////////////////////////////////////////////////////////
////////////// CLIENT URL DETECTION /////////////////////////////////////////////
uno.web.site=function(){var site=uno.cookie.read('unosite');if(!site){site=uno.web.domain();return uno.cookie.read('unosite');}return site;};
uno.web.domain=function(){
    var dom=uno.cookie.read('unodomain');
    if(!dom){var ddd=document.domain;
        ddd=uno.replaceall(ddd,'cesvinonew','cesvi');
        ddd=uno.replaceall(ddd,'cesvinew','cesvi');
        if(ddd.indexOf('madeincesvi.org')>-1){setTimeout('location.href=\'http://madein.cesvi.org\'',100);return 'abort';}
        if(ddd.indexOf('madeincesvi.it')>-1){setTimeout('location.href=\'http://madein.cesvi.org\'',100);return 'abort';}
        ddd=uno.replaceall(ddd,'www.madeincesvi.org','madein.cesvi.org');
        ddd=uno.replaceall(ddd,'madeincesvi.org','madein.cesvi.org');
        ddd=uno.replaceall(ddd,'www.madeincesvi.it','madein.cesvi.org');
        ddd=uno.replaceall(ddd,'madeincesvi.it','madein.cesvi.org');
        ddd=uno.replaceall(ddd,'donazionx','donazioni');
        var ddx=new Array;ddx=ddd.split(".");
        if(ddx.length<=2){dom=ddd+'/';
            uno.cookie.create('unosite','www/');}
        else{ddd='';dom=ddx[ddx.length-2]+'.'+ddx[ddx.length-1]+'/';
            for(var i=ddx.length-3;i>=0;i--){ddd=ddd+ddx[i]+"/";}
            uno.cookie.write('unosite',ddd);}
        uno.cookie.write('unodomain',dom);}
    return dom;};
uno.web._url_base=function(){return uno.web.domain()+uno.web.site();};
uno.web.url_page=function(name){var d=uno.web.domain();if(d=='abort'){return d;}return uno.web._url_base()+'page/'+name+'.xml';};
uno.web.url_ctr=function(name){return uno.web._url_base()+'ctr/'+name+'.xml';};
uno.web.url_ctc=function(name){return uno.web._url_base()+'ctc/'+name+'.xml';};
uno.web.url_data=function(name){return uno.web._url_base()+'data/'+name+'.xml';};
uno.web.url_css=function(name){return uno.web._url_base()+'css/'+name+'.css';};
uno.web.url_script=function(name){return uno.web._url_base()+'script/'+name+'.js';};
uno.web.gotopage=function(name){location.href='?name='+name;};
////////////// COM UTILITY //////////////////////////////////////////////////////
uno.web.sayok=function(url){uno.xml.asyncload(url,false,uno.web._sayok,uno.web._sayko);};
uno.web.sayokpost=function(url,formid){uno.xml.asyncloadpost(url,false,uno.xml._okprocess, uno.xml._okprocess, formid);};
uno.web.sayokframe=function(url,formid){uno.xml.asyncloadframe(url,false,uno.xml._okprocess, uno.xml._okprocess, formid);};
uno.web.renderpage=function(name){var d=uno.web.url_page(name);if(d!='abort'){uno.xml.renderpage(uno.web.url_page(name));}};
uno.web.rendercontent=function(elm,content){uno.xml.rendercontent(elm,uno.web.url_ctc(content));};
uno.web.rendercontrol=function(elm,control,dataurl,form){uno.xml.rendercontrol(elm,uno.web.url_ctr(control),dataurl,form);};
uno.web.rendercontrolpost=function(elm,control,dataurl,form){uno.xml.rendercontrolpost(elm,uno.web.url_ctr(control),dataurl,form);};
uno.web.rendercontrolframe=function(elm,control,dataurl,form){uno.xml.rendercontrolframe(elm,uno.web.url_ctr(control),dataurl,form);};
/////////////////////////////////////////////////////////////////////////////////////
Namespace.register('uno.crossdomain');
uno.crossdomain.environment=false;
/////////////////////////////////////////////////////////////////////////////////////
uno.web.cmdurl=function(){if(uno.crossdomain.environment){return uno.web._crossdomcmdurl;}else{return uno.web._normcmdurl;}};
uno.web._normcmdurl = '?a=';
uno.web._crossdomcmdurl = 'jdefault.aspx?a=';
uno.web._url=function(cmd){return uno.web._cmdurl() + cmd;};
uno.web._urlx=function(cmd,nams,vars){var url='';var i=0;for(i=0;i<nams.length;i++){if(!uno.isnullorempty(vars[i])){url+='&'+nams[i]+'='+encodeURIComponent(vars[i]);}}return uno.web._cmdurl()+cmd+url;};
uno.web.editmode=function(){var x=uno.cookie.read('unoeditmode');if(x){return parseInt(x);}return 0;};
uno.web._editor_show=function(type,ntturl,_originaltarget,_dataurl){
    var title='';
    try{title=ntturl.substring(0,ntturl.lastIndexOf('.xml'));
        title=title.substring(ntturl.lastIndexOf('/')+1,title.length);
        title=title+' - uno web editor';
    }catch(ex){title='uno web editor'};
    if(!document.getElementById('uno-web-editor')){uno.insert(document.body,'div',['id','uno-web-editor','style','display:none']);}
    if(type=='ctc'){
        uno.xml.rendercontrol('newindow',uno._resctr+type+'_editor.xml',ntturl);
    }else if(type=='ctr'){
        var elm=uno.insert(document.body,'div',['id',uno.getuqid('xwin'),'style','display:block;']);
        var elmxml='<data><wid>'+elm.id+'</wid><originaltarget>'+_originaltarget+'</originaltarget><templateurl><![CDATA['+ntturl+']]></templateurl><dataurl><![CDATA['+_dataurl+']]></dataurl></data>';
        uno.xml._rendercontrol(elm,uno.xml.preloaded('ctr_editor'),uno.xml.parse(elmxml));
        uno.window.show(elm.id,['minimizeto','tray','title',title,'refreshjs','uno.xml.rendercontrol(\''+elm.id+'\',\''+ntturl+'\',\''+_dataurl+'\');']);
    }};
uno.web.editor_test=function(){uno.fancybox.hide();};
uno.web.editor_save=function(type,name){uno.fancybox.hide();};
uno._resctr='http://www.openuno.org/jdefault.aspx?a=5&rtype=ctr&name=';
//setTimeout('uno.xml.preload(\'ctr_editor\',uno._resctr+\'ctr_editor.xml\')',1000);
_u4=function(){var p=uno.querystring('page');if(uno.isnullorempty(p)){p='home';}uno.web.renderpage(p);};
uno.addevent(document,'load',_u4);
