if (typeof (WPLY_host)=="undefined") WPLY_host = "";
var WPLY= {extend : function(){
	var io = function(o)
	{
		for(var m in o){this[m] = o[m];} 
	};
	return function(sb, sp, overrides)
			{
				if(typeof sp == 'object')
				{
					overrides = sp;
					sp = sb;
					sb = function(){sp.apply(this, arguments);};
				}
				var F = function(){}, sbp, spp = sp.prototype;
				F.prototype = spp;
				sbp = sb.prototype = new F();
				sbp.constructor=sb;
				sb.superclass=spp;
				if(spp.constructor == Object.prototype.constructor)	{spp.constructor=sp;}
				sb.override = function(o) {WPLY.override(sb, o);};
				sbp.override = io;
				WPLY.override(sb, overrides);
				return sb;
			};
}(),

override : function(origclass, overrides)
			{
				if(overrides)
					{
						var p = origclass.prototype;
						for(var method in overrides){p[method] = overrides[method];}
					}
			}
,progID:0			
}
var WOOPLY = WPLY;
WPLY.PCall = "/source/Call.php";

WPLY.apply=function(C,D,B){if(B){WPLY.apply(C,B)}if(C&&D&&typeof D=="object"){for(var A in D){C[A]=D[A]}}return C};WPLY.Data={};WPLY.Form={};WPLY.creationDate = new Date();WPLY.JLoaded = {};WPLY.Data.Collection=function(){this.items=[];this.map={};this.keys=[];this.length=0;};
WPLY.isArray=function(o) {if (o.constructor.toString().indexOf("Array") == -1) return false; else return true;}
WPLY.webopenpreloading=function (s) {if (s==1) document.getElementById("art_loading").style.display="block";else document.getElementById("art_loading").style.display="none";}
WPLY.OpenDir=function(F,I,P){window.open("/source/Admin/ReadDirFile.php?Field="+F+"&ImgPrw="+I+"&Path="+P,"READPATH",'width=900,height=600,left=10,top=10,scrollbars=yes,resizable=yes');}
WPLY.jscssadded="";
WPLY.loadjscss = function(filename, filetype,fcallback){if (WPLY.jscssadded.indexOf("["+filename+"]")==-1){if (filetype=="js"){var fileref=document.createElement('script');fileref.onload=fcallback;fileref.setAttribute("type","text/javascript");fileref.setAttribute("src", filename);} else if (filetype=="css"){var fileref=document.createElement("link");fileref.onload=fcallback;fileref.setAttribute("rel", "stylesheet");fileref.setAttribute("type", "text/css");fileref.setAttribute("href", filename);}if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref);WPLY.jscssadded+="["+filename+"]";}}	
WPLY.JSON=function () {this.decode=function(json){return eval("(" + json + ')');}};
WPLY.DataAjax = function() {
	var to=this;
	   this.LoadPage = function (url, param)
	   {
		  parameters=param;
		if(typeof param == 'object')
			{
				var i=0;
				var s="";
				for(var a in param){s="&";parameters+=s+a+"="+param[a];}
				}
      	to.http_request = false;
      	if (window.XMLHttpRequest) 
			{ // Mozilla, Safari,...
			 to.http_request = new XMLHttpRequest();
			 
			 if (to.http_request.overrideMimeType) 
			 	{
            		to.http_request.overrideMimeType('text/html');
         		}
      		} 
			else if (window.ActiveXObject) 
					{ // IE
         				try {
            				to.http_request = new ActiveXObject("Msxml2.XMLHTTP");
         					} catch (e) 
								{
            						try {
               							to.http_request = new ActiveXObject("Microsoft.XMLHTTP");
            							} 
									catch (e) {}
         						}
      				}
		  if (!to.http_request) 
		  {
			 alert('Cannot create XMLHTTP instance');
			 return false;
		  }
			  
      to.http_request.onreadystatechange = to.callbackFirst;
      to.http_request.open('POST', url, true);
	  to.http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");	
      to.http_request.setRequestHeader("Content-length", parameters.length);
      to.http_request.setRequestHeader("Connection", "close");
      to.http_request.send(parameters);
	  
	  
   } // End Load Data Ajax


        this.LoadData = function(wm,wa,addParam) {
			  var poststr = "";
			  var url = WPLY.buildCallUrl("WJSR",wm,wa,"");
			  
			  
			  if (typeof(addParam)=="object")  
			  	{
					if (addParam.addParam!="") poststr+="&"+Param.addParam;
					url = addParam.Url;
				}
				else
				{	
				  if (addParam!="") addParam="&"+addParam;
				  poststr+=addParam;
				}
			  
			  to.LoadPage(url, poststr);
   } //End PostForm


        this.PostForm = function(obj,addParam) {
			  var poststr = "";
			  poststr=WPLY.GetFormData(obj);
			  if (addParam!="") addParam="&FLE=GAR&"+addParam;
			  poststr+=addParam;
			  
			  	
			  to.LoadPage(WPLY_host+'/source/Call.php', poststr);
   } //End PostForm
	this.PostFormLoadJS = function(obj,addParam) {
			  var poststr = "";
			  poststr=WPLY.GetFormData(obj);
			  if (addParam!="") addParam="&FLE=GAR&"+addParam;
			  poststr+=addParam;
			  WPLY.loadjscss(WPLY_host+'/source/Call.php?'+poststr,'js',this.callback);
   } //End PostForm JS
   this.callbackFirst=function(res){};
   this.callback=function(res){};
   
   this.callbackFirst = function (res)
   {
	   
	     if (to.http_request.readyState == 4) {
         if (to.http_request.status == 200) {
			 
            result = to.http_request.responseText;
			
			to.callback(result);
				

         } else {/*Error Request*/}
      }
	   }

}

WPLY.GetFormData=function(f){
  var s = "";
  var n = f.elements.length;
  var t = "";
  
 
 
   for(var i = 0; i < n; i++){
	  TagType=f.elements[i].type;
      if (TagType == "checkbox") {
	   if (f.elements[i].checked) t = f.elements[i].name + "= 1" ;
	   	else t = f.elements[i].name + "= 0";
               
	}
	else
	   if (TagType == "radio") {
               if (f.elements[i].checked) {
                  t = f.elements[i].name + "=" + f.elements[i].value ;
               }
            }
		else t = f.elements[i].name+"="+encodeURIComponent(f.elements[i].value);		
    if(i < n-1){
      s += t + "&";
    }else{
      s += t;
    }  
  }
	
  return s;
}

WPLY.hasClass=function(e,c) {
	return e.className.match(new RegExp('(\\s|^)'+c+'(\\s|$)'));
}
 
WPLY.addClass=function(e,c) {
	if (!WPLY.hasClass(e,c)) e.className += " "+c;
}
 
WPLY.removeClass=function(e,c) {
	if (WPLY.hasClass(e,c)) {
    	var reg = new RegExp('(\\s|^)'+c+'(\\s|$)');
		e.className=e.className.replace(reg,' ');
	}
}
 
WPLY.getNewDomId=function() {WPLY.progID+=1; return "wid"+WPLY.progID;} 
WPLY.getDomEvent=function(e) {var a=window.event || e;if (!a.target)  a.target=a.srcElement;return  a.target;} 
WPLY.getAbsXY =function (e) {var r = {x:e.offsetLeft, y:e.offsetTop};if (e.offsetParent) {var t=WPLY.getAbsXY(e.offsetParent);r.x+=t.x;r.y+=t.y;} return r;};
WPLY.Data.JsonReader = function(a,b)
{
	this.prop=a;
	this.fields=b;
}

WPLY.Data.Store=function (a)
{
	var t=this;
	this.data=new WPLY.Data.Collection();
	this.reader = a.reader;
	this.nrec=0;
	this.onLoaded=function(){};

	if (typeof(a.data)!="undefined")
		{
			dst = a.data;
			dft = a.fields;
			t.data.items=[];
			t.data.length=dst.length;
			t.nrec=dst.length;
			for (i=0;i<dst.length;i++)
				{
					
					Data = {};
					for (j=0;j<dft.length;j++)
						{
							eval("Data."+dft[j]+"='"+dst[i][j]+"'");
						}
						t.data.items.push(Data);
					
				}
				
			}
	
	this.load=function(p)
		{
		var c = new WPLY.DataAjax();
		c.callback = function (res) 
		{

			var r=WPLY.JSON.decode(res);
			var totrec=eval("r."+t.reader.prop.total);						
			t.data.length=totrec;
			t.nrec=totrec;
			var Data = eval("r."+t.reader.prop.root);
			var i=0;
			t.data.items=[];			
			for (i=0;i<totrec;i++)
				{
					t.data.items.push(Data[i]);
				}
			if (typeof(p.callback)!="undefined") p.callback();
			t.onLoaded();
		
		}
		if (typeof(p.param)=="undefined") p.param={};
		//alert(p.param.length);
		c.LoadPage(a.conn, p.param);
		}
}



WPLY.createDom = function(o, pN){
        var e;
		e = document.createElement(o.tag||'div');
		var useSet = !!e.setAttribute; 
		for(var a in o){e[a] = o[a];}
		
		if(o.html) e.innerHTML = o.html;
        
        if(pN) pN.appendChild(e);
        return e;
    };
WPLY.createHTML = function(p){
	
		var SingleTags = new Array("br","frame","hr","img","input","link","meta","range","spacer","wbr","area","param","col");
	
        if(typeof p == 'string'){
            return p;
        }
        var b = "";
        if (WPLY.isArray(p)) {
            for (var i = 0, l = p.length; i < l; i++) {
                b += createHtml(p[i]);
            }
            return b;
        }
        if(!p.tag){
            p.tag = "div";
        }
        b += "<" + p.tag;
        for(var attr in p){
            if(attr == "tag" || attr == "cn" || attr == "html" || typeof p[attr] == "function") continue;
            if(attr == "style"){
                var s = p["style"];
                if(typeof s == "function"){
                    s = s.call();
                }
                if(typeof s == "string"){
                    b += ' style="' + s + '"';
                }else if(typeof s == "object"){
                    b += ' style="';
                    for(var key in s){
                        if(typeof s[key] != "function"){
                            b += key + ":" + s[key] + ";";
                        }
                    }
                    b += '"';
                }
            }else{
                if(attr == "cls"){
                    b += ' class="' + p["cls"] + '"';
                }else if(attr == "htmlFor"){
                    b += ' for="' + p["htmlFor"] + '"';
                }else{
                    b += " " + attr + '="' + p[attr] + '"';
                }
            }
        }
        if(SingleTags.indexOf(p.tag)>0){
            b += "/>";
        }else{
            b += ">";
            var cn = p.cn;
            if(cn){
                b += createHtml(cn);
            } else if(p.html){
                b += p.html;
            }
            b += "</" + p.tag + ">";
        }
        return b;
    
    
};




WPLY.Component = function(config){
	var t = this;
	this.startConfig = config;
	t.html="";
	t.NodeAppend="";
	t.listener = []
	this.Value = "";
	this.TextValue = "";
	t.type = "";
    
	this.getValue = function () {return t.Value;}
	
	this.addListener = function (p){
		t.listener.push({id:p.id,t:p.t,f:p.f,c:p.c});
		}
	this.render=function(idr) {
		document.getElementById(idr).appendChild(t.NodeAppend);
		var e=t.listener;
		for (var i = 0, l = e.length; i < l; i++) {
                document.getElementById(e[i].id).addEventListener(e[i].t,e[i].f,e[i].c);
            }
		
		}
    this.init();
};
WPLY.Form.TextField=WPLY.extend(WPLY.Component,
	{
		init : function (){
			var idi=WPLY.getNewDomId();
			var inp = WPLY.createDom({tag:"input",type:"text",className:"x-form-text x-form-field",id:idi});
			this.NodeAppend = inp;
			this.type = "TextField";

		}
	}	
);




WPLY.Form.ComboBox=WPLY.extend(WPLY.Form.TextField,
									{
										init : function (){
														
														WPLY.Form.ComboBox.superclass.init.call(this);
														var idi=WPLY.getNewDomId();
														var idt=WPLY.getNewDomId();
														var idl=WPLY.getNewDomId();
														var idli=WPLY.getNewDomId();
														var idc;
														var t=this;
														
														this.type = "ComboBox";
														
														this.setValue = function (a) 
															{
																
																var s = t.startConfig.store;
																var vField = t.startConfig.vField;
																var dField = t.startConfig.dField;
																for (var i=0;i<s.nrec;i++)
																	{
																		var itm = s.data.items[i];
																		var code=itm[vField];
																		var name=itm[dField];
																		
																		if (code==a)
																			{
																				t.Value = code;
																				t.TextValue = name;
																				cmbhid.value=code;
																				cmbtxt.value=name;
																				}
																	}
																}
														
														this.onSelect = function() {}
														this.on = function (p) {if (p.t=="select") t.onSelect=p.f;}
														
														if (typeof(this.startConfig.store)!="undefined") 
															{this.store=this.startConfig.store;this.store.onLoaded=function(){DataLoaded();}   }
														else this.store="";
														if (typeof(this.startConfig.id)!="undefined") idc=this.startConfig.id; else idc=WPLY.getNewDomId();
														
														
														var cmb = WPLY.createDom({className:"x-form-field-wrap x-trigger-wrap-focus",id:WPLY.getNewDomId(),id:idc});
														var cmbhid = WPLY.createDom({tag:"input",type:"hidden",className:"x-form-field-wrap"},cmb);
														var cmbtxt = WPLY.createDom({tag:"input",type:"text",className:"x-form-text x-form-field",id:idi},cmb);
														var cmbtr = WPLY.createDom({tag:"img",src:"/source/images/s.gif",className:"x-form-trigger",id:idt},cmb);
														
														var lst = WPLY.createDom({className:"x-combo-list x-combo-list-small w-hidden",id:idl});
														
														var lstin = WPLY.createDom({className:"x-combo-list-inner",id:idli},lst);
														document.body.appendChild(lst); 
														lstin.style.height = "100px";
														lstin.style.maxHeight = "100px";
														lstin.style.width = "150px";

														this.NodeAppend = cmb;

														this.addListener({id:idt,t:"mouseover",f:function() {WPLY.addClass(cmbtr,"x-form-trigger-over");},c:false});
														this.addListener({id:idt,t:"mouseout",f:function() {WPLY.removeClass(cmbtr,"x-form-trigger-over");},c:false});
														var elomov = function(e) {b=WPLY.getDomEvent(e);WPLY.addClass(b,"x-combo-selected");}
														var elomot = function(e) {b=WPLY.getDomEvent(e);WPLY.removeClass(b,"x-combo-selected");}
														var elomcl = function(e) {b=WPLY.getDomEvent(e);lst.style.display="none"; t.onSelect(b.getAttribute("cmbcode"));cmbhid.value=b.getAttribute("cmbcode");cmbtxt.value=b.innerHTML; t.Value=b.getAttribute("cmbcode"); t.TextValue=b.innerHTML; }

														var DataLoaded = function ()
															{
																var s = t.startConfig.store;
																var vField = t.startConfig.vField;
																var dField = t.startConfig.dField;
																var el;
																lstin.innerHTML="";
																for (var i=0;i<s.nrec;i++)
																	{
																		var itm = s.data.items[i];
																		var code=itm[vField];
																		var name=itm[dField];
																		el = WPLY.createDom({className:"x-combo-list-item",html:name},lstin);
																		el.setAttribute("cmbcode",code);
																		 el.addEventListener("mouseover",elomov,false);
																		 el.addEventListener("mouseout",elomot,false);
																		 el.addEventListener("mousedown",elomcl,true);
																		
																		 
																		
																	}
																}
														var clickontrigger = function(e) {
																				
																				
																			 if (lst.style.display=="block") 
																			 	lst.style.display="none"; 
																			else {
																					cmbtxt.focus();
																					cmbtxt.addEventListener("blur",function(){lst.style.display="none";},true);
																					var poscmb=WPLY.getAbsXY(cmbtxt);
																					lst.style.position="absolute";
																					lst.style.left=poscmb.x+"px";
																					lst.style.top=(poscmb.y+cmbtr.offsetHeight)+"px";
																					lst.style.display="block";
																					DataLoaded();
																					
																					
																		 		}
																			}
														this.addListener({id:idt,t:"click",f:clickontrigger,c:false});
														
														if (typeof(this.startConfig.store)!="undefined") 
															{if (this.startConfig.store.nrec>0) DataLoaded(); }
							
														
															}
									}
);

WPLY.LoadArrayJsCss = function(ArrMod,Loadfunc)
	{

		var Rec = ArrMod.pop();
		var FileName="";
		var LoadFile = 1;
		var JLN ="";
		if (!(Rec == undefined)) 
			{ 
				JLN=Rec.file.replace(/\//g,"_");
				JLN=JLN.replace(/\./g,"_");	
				JLN=JLN.replace(/\-/g,"_");	
				JLN=JLN.replace(/\?/g,"_");	
				JLN=JLN.replace(/\=/g,"_");	
				JLN=JLN.replace(/\&/g,"_");	
				
				if ((typeof(Rec.type)=="undefined") || (Rec.type=="") || (Rec.form=="")) FileName=Rec.file;
					else 
						{
							if (Rec.type=="css") FileName="/source/addon/"+Rec.form+"/"+Rec.type+"/"+Rec.file+".css";
								else FileName="/source/addon/"+Rec.form+"/"+Rec.type+"/"+Rec.file+".js?";
						}
				
				
				if (LoadFile==1)
					{
					posExt=FileName.search(/.css/i);
					FileType="";
					if (posExt>0) FileType="css";
					
					if ((Rec.type=="css") || (FileType=="css")) 
										{
											WPLY.loadjscss(FileName,"css",function(){});
											if (Rec.func!="") Rec.func();
											WPLY.LoadArrayJsCss(ArrMod,Loadfunc);

										}
						else WPLY.loadjscss(FileName,"js",function(){
									
										if (Rec.func!="") Rec.func();
										WPLY.LoadArrayJsCss(ArrMod,Loadfunc);
										
										});
					}
					
				else 
					{
						
						if (Rec.func!="") Rec.func();
						WPLY.LoadArrayJsCss(ArrMod,Loadfunc);
					}
			}
		else
			if ((Loadfunc!="") && (Loadfunc!=undefined)) Loadfunc();
				
	
		}
WPLY.BuildFilter = function(filter,Pos,Type,Value,Field,Comparison)
	{
		
	if (!filter) filter=[];
	if (Pos=="") Pos=filter.length;
	filter[Pos]=[];
	filter[Pos]["data"]=[];
	filter[Pos]["data"]["type"]=Type;
	filter[Pos]["data"]["value"]=Value;
	if (!(Comparison)) filter[Pos]["data"]["comparison"]="lk"; else filter[Pos]["data"]["comparison"]=Comparison;
	filter[Pos]["field"]=Field;
	return filter;
	
	}
	
WPLY.ElaboraFilter = function(filterManage,nameFilter)
	{
		nameFilter = nameFilter || "Filtro";
		if (nameFilter == "undefined") nameFilter="Filtro";
		RqstParam={};
		for (var i=0;i<filterManage.length;i++)
					{
						RqstParam[nameFilter+"["+i+"][data][type]"]=filterManage[i]["data"]["type"];
						RqstParam[nameFilter+"["+i+"][data][value]"]=filterManage[i]["data"]["value"];
						RqstParam[nameFilter+"["+i+"][data][comparison]"]=filterManage[i]["data"]["comparison"];
						RqstParam[nameFilter+"["+i+"][field]"]=filterManage[i]["field"];
						}
		return RqstParam
	}		
	
WPLY.scroll = {items:[],itemstot:0,pause:0};	
WPLY.scroll.start = function ()
		{
		var n="";
		for (i=0;i<WPLY.scroll.itemstot;i++)
			{
				n = WPLY.scroll.items[i].box;
				//alert(n.style.left);
				if ((-1)*parseInt(n.style.left)>parseInt(n.offsetWidth))
					{
					n.style.left = parseInt(WPLY.scroll.items[i].oW);
					}
					else
						{
						if (WPLY.scroll.pause==0) n.style.left = parseInt(n.style.left) - WPLY.scroll.items[i].speed;
						}
			
				}
		}
	


WPLY.scroll.newitem = function (Setting)
{
	var idbox = Setting.idbox;
	var BoxCnt = document.getElementById(idbox);
	
	
	
	var Box = '<div style="position:absolute;left:0px;top:0px;  " id="'+idbox+'_in" onmouseover="WPLY.scroll.pause=1" onmouseout="WPLY.scroll.pause=0">'+document.getElementById(idbox).innerHTML+'</div>';
	document.getElementById(idbox).innerHTML = Box;
	var n = document.getElementById(idbox+'_in');
	
	WPLY.scroll.items[WPLY.scroll.itemstot]={box:n,pause:0,oW:BoxCnt.offsetWidth,speed:Setting.speed};
	n.style.width = n.offsetWidth;
	
	WPLY.scroll.itemstot+=1;
	if (WPLY.scroll.itemstot==1) setInterval("WPLY.scroll.start()",30);
}	
	
WPLY.MenuStart={}

WPLY.GetDateExtended = function () {
	
data = new Date();
ora =data.getHours();
minuti=data.getMinutes();
secondi=data.getSeconds();
giorno = data.getDay();
mese = data.getMonth();
date= data.getDate();
year= data.getYear();
if(minuti< 10)minuti="0"+minuti;
if(secondi< 10)secondi="0"+secondi;
if(year<1900)year=year+1900;
if(ora<10)ora="0"+ora;
if(giorno == 0) giorno = " Domenica ";
if(giorno == 1) giorno = " Lunedì ";
if(giorno == 2) giorno = " Martedì ";
if(giorno == 3) giorno = " Mercoledì ";
if(giorno == 4) giorno = " Giovedì ";
if(giorno == 5) giorno = " Venerdì ";
if(giorno == 6) giorno = " Sabato ";
if(mese == 0) mese = "Gennaio ";
if(mese ==1) mese = "Febbraio ";
if(mese ==2) mese = "Marzo ";
if(mese ==3) mese = "Aprile ";
if(mese ==4) mese = "Maggio ";
if(mese ==5) mese = "Giugno ";
if(mese ==6) mese = "Luglio ";
if(mese ==7) mese = "Agosto ";
if(mese ==8) mese = "Settembre ";
if(mese ==9) mese = "Ottobre ";
if(mese ==10) mese = "Novembre ";
if(mese ==11) mese = "Dicembre";
return giorno+" "+date+" "+mese+" "+year;
//+" - ora "+ora+":"+minuti+":"+secondi;
	}

WPLY.img_dimension = function (ori_w, ori_h, maxw, maxh) {
	var newsize={};
	if(ori_w >= ori_h) {
		var alt_new = maxw * ori_h / ori_w;
		newsize.width = maxw;
		newsize.height = alt_new;

	}
	else if(ori_h > ori_w) {
		var largh_new = ori_w * maxh / ori_h;
		newsize.width = largh_new;
		newsize.height = maxh;
	}
return newsize;
}

WPLY.date_countdown = function () {
	var TO = this;
	this.dateFuture = new Date(2012,12,21,21,12,21);
	this.set_date = function (y,m,d,h,j,s) {TO.dateFuture = new Date(y,m,d,h,j,s);}
	this.width='600px';
	this.height='10px';
	this.bgcolor='none';
	if (document.all||document.getElementById) document.write('<span id="wply-countdown" style="width:'+TO.width+'; height:'+TO.height+'; background-color:'+TO.bgcolor+'"></span>')
	
	this.countdown = function ()
		{
			var dateNow = new Date();									
			var amount = TO.dateFuture.getTime() - dateNow.getTime();		
			delete dateNow;
			if(amount < 0){document.getElementById('wply-countdown').innerHTML="Now!";}
			else{
				days=0;hours=0;mins=0;secs=0;out="";
				amount = Math.floor(amount/1000);
				days=Math.floor(amount/86400);
				amount=amount%86400;
				hours=Math.floor(amount/3600);
				amount=amount%3600;
				mins=Math.floor(amount/60);
				amount=amount%60;
				secs=Math.floor(amount);
				if(days != 0){out += days +" "+((days!=1)?"giorni":"giorno")+", ";}
				if(days != 0 || hours != 0){out += hours +" "+((hours!=1)?"ore":"ora")+", ";}
				if(days != 0 || hours != 0 || mins != 0){out += mins +" "+((mins!=1)?"minuti":"minuto")+", ";}
				out += secs +" secondi";
				document.getElementById('wply-countdown').innerHTML=out;
			}
		}
						
}

WPLY.buildCallUrl = function(wcall,wm,wa,param)
{
	if (typeof(param)!="undefined" && (param != "")) param = "&"+param;
	return WPLY.PCall + "?WCALL="+wcall+"&WM="+wm+"&WA="+wa+param;
}
