/*
JAvaScript Toolkit (http://www.jastegg.it)
Version:		0.3 alpha
Author: 		Diego La Monica (http://diegolamonica.info)
Works With:		Internet Explorer 6 & 7, Firefox 2.0+, Safari 3.0.2 beta for Windows, Opera 9.21
*/
JASTEggIt={_internal:{idCount:0},_el:function(el){if(typeof(el)!='object')return JASTEggIt._id(el);else return el;},_id:function(id){return document.getElementById(id);},_get:function(cascade,from,p){if(!this.Array.is(cascade))cascade=cascade.split('>');if(from==null)from=0;if(p==null)p=document;if(from==cascade.length)return p;var attrs={};var item=cascade[from];if(item.substring(0,1)=='#')attrs={id:item.substring(1,item.length)};else if(item.substring(0,1)=='.')attrs={className:item.substring(1,item.length)};else attrs={name:item};var ret=this.DOM.find(p,attrs);for(var i=0;i<ret.length;i++){var k=i;ret[k]=this._get(cascade,from+1,ret[k]);};for(var i=0;i<ret.length;i++){var k=i;if(ret[k]=='')ret[k]=null;if(this.Array.is(ret[k])){this.Array.merge(ret,ret[k]);ret[k]=null;};};ret=this.Array.purge(ret);return ret;},_name:function(name,parent){if(parent==null)parent=document;return parent.getElementsByTagName(name);},_works:function(){alert('JAST framewor is working fine!');},_ready:false,_interval:setInterval(' JASTEggIt.startup(); JASTEggIt._startingUp=false;',100),_startup:function(){for(keyVar in this)if(typeof(this[keyVar])=='object'&&this[keyVar].startup!=null)this[keyVar].startup();},eggs:function(){var eggs=Array();for(egg in this)if(typeof egg==='object'&&egg.info!=null)eggs[eggs.length]=egg.info;return eggs;},generateUniqueId:function(prefix){var d=new Date();var id=prefix+'-';var summa=d.getDay();summa+=d.getMonth();summa+=d.getYear();summa+=d.getHours();summa+=d.getMinutes();summa+=d.getSeconds();summa+=d.getMilliseconds();id+=summa;id+='-'+this._internal.idCount++;return id;},mergeOptions:function(src,full){if(src==null)src=full;for(o in full)if(src[o]==null)src[o]=full[o];return src;},startup:function(){if(navigator.userAgent.substring(0,5)=='Opera'&&(document.readyState=='complete')){this._startup();clearInterval(this._interval);this._interval=0;this._ready=true;}else{var tag=this._name('html');if(tag==null)return false;if(!tag[0].innerHTML.match(/<\/body>/i))return false;clearInterval(this._interval);this._interval=0;this._startup();this._ready=true;return(tag!=null);};},extend:function(key,object){this[key]=object;this[key].name=key;if(this._ready&&(this[key].startup!=null)){this[key].startup();};},event:function(item,event,fn){var f=null;var obj=(typeof(item)=='object'?item:this._id(item));if(typeof(fn)==='function'){f=fn;}else{f=function(event){eval(fn);};functionString=fn.replace(/this\./g,'_id(\''+item+'\').');}if(document.addEventListener){obj.addEventListener(event,f,false);}else if(document.attachEvent){obj.attachEvent('on'+event,f);}else{obj.setAttribute('on'+event,f);};},Accessibility:{clickEvent:function(id,fn){JASTEggIt.event(id,'click',fn);JASTEggIt.event(id,'keypress',function(event){var keynum=JASTEggIt.kbd.getKeyPressed(event);if(keynum==32||(keynum==13&&window.event)){fn();return false;}});}},Array:{is:function(a){return(a)&&(!a.length!=null)&&(typeof a==='object')&&(typeof a.length==='number');},toString:function(a){var buffer='';for(var i=0;i<a.length;i++){if(buffer!='')buffer+=',';if(this.is(a[i])){buffer+=this.toString(a[i]);}else if(typeof a[i]==='object'){buffer+=(typeof a[i]);}else{buffer+=a[i];};};buffer='['+buffer+']';return buffer;},merge:function(a1,a2){if(a2==null)return a1;for(var i=0;i<a2.length;i++)a1[a1.length]=a2[i];return a1;},purge:function(a){var ret=Array();for(var i=0;i<a.length;i++){var k=i;if(a[k]!=null)ret[ret.length]=a[k];};return ret;}},strings:{trim:function(s){while(s.substr(0,1)==' ')s=s.substr(1,s.length);while(s.substr(s.length-1,1)==' ')s=s.substring(0,s.length -1);return s;},split:function(stringa,separatore){var newArray=stringa.split(separatore);return this.removeLastChar(newArray,separatore);},removeLastChar:function(textArray,lastChar){for(var i=0;i<textArray.length;i++){var l=textArray[i].length;if(textArray[i].substr(l-1,1)==lastChar)textArray[i]=textArray[i].substr(0,l -1);};return textArray;}},DOM:{createContainer:function(el,tagName){var e=document.createElement(tagName);e.id=JASTEggIt.generateUniqueId(tagName);var p=el.parentNode;p.appendChild(e);e.appendChild(el);return e;},createOnDocument:function(tagName){var e=document.createElement(tagName);var body=JASTEggIt._name('BODY')[0];body.appendChild(e);e.id=JASTEggIt.generateUniqueId(tagName);return e;},position:function(el){var sl=0,st=0;var is_div=/^div$/i.test(el.tagName);if(is_div&&el.scrollLeft)sl=el.scrollLeft;if(is_div&&el.scrollTop)st=el.scrollTop;var r={x:el.offsetLeft-sl,y:el.offsetTop-st};if(el.offsetParent){var tmp=this.position(el.offsetParent);r.x+=tmp.x;r.y+=tmp.y;};return r;},style:function(el,at){var e=JASTEggIt._el(el);var st=null;if(window.getComputedStyle)st=window.getComputedStyle(e,null);else if(e.currentStyle)st=e.currentStyle;if(st==null)return null;if(at==null)return st;at=at.split(' ');var ret=new Object();for(var i=0;i<at.length;i++)ret[at[i]]=st[at[i]];return ret;},setStyle:function(el,rules){var e=JASTEggIt._el(el);for(rule in rules)e.style[rule]=rules[rule];},realSize:function(el){el=JASTEggIt._el(el);var att=this.style(el,'width height paddingTop paddingBottom paddingLeft paddingRight marginTop marginBottom');var buffer="";for(prop in att){att[prop]=parseInt(att[prop]);if(isNaN(att[prop]))att[prop]=0;buffer+=prop+" = "+att[prop]+'\n';};var width=(att.width==0?el.offsetWidth-(att.paddingLeft+att.paddingRight):att.width);var height=(att.height==0?el.offsetHeight-(att.paddingTop+att.paddingBottom):att.height);return{width:width,height:height};},locate:function(el,x,y,w,h,p){el=JASTEggIt._el(el);if(p==null)p='absolute';el.style.position=p;el.style.width=w+'px';el.style.height=h+'px';el.style.left=x+'px';el.style.top=y+'px';},nodeMatch:function(e,attrs){for(a in attrs)if(attrs[a]!=e[a])return false;return true;},find:function(p,match){var ret=Array();for(var i=0;i<p.childNodes.length;i++){var node=p.childNodes[i];if(this.nodeMatch(node,match))ret[ret.length]=node;ret=JASTEggIt.Array.merge(ret,this.find(node,match));};return ret;}},Listener:{_listener:[],_interval:null,_inside:false,_watch:function(){if(this._inside)return false;this._inside=true;for(i=0;i<this._listener.length;i++){var itm=this._listener[i];var obj=JASTEggIt._id(itm.id);if(obj!=null&&itm.execute!=null){var attributes=itm.attribute.split('|');for(j=0;j<attributes.length;j++){var k=j;if(obj[attributes[k]]!=itm.lastValue[k]){itm.execute(itm);itm.lastValue[k]=obj[attributes[k]];};};};};this._inside=false;},clear:function(){if(this._interval==null)clearInterval(this._interval);_listener=[];},watch:function(id,attribute,fn){this._listener[this._listener.length]={id:id,attribute:attribute,lastValue:[],execute:fn};if(this._interval==null)this._interval=setInterval('JASTEggIt.Listener._watch()',10);}},kbd:{getKeyPressed:function(event){var keynum=0;if(window.event)keynum=window.event.keyCode;else if(event.which)keynum=event.which;return keynum;}},xhttp:{options:{userName:null,password:null,asyncMode:true},_xssInstances:0,_xhrInstances:0,_loaderId:'',_createXhr:function(){var obj=null;if(typeof(XMLHttpRequest)==="function"||typeof(XMLHttpRequest)==="object"){obj=new XMLHttpRequest();}else if(window.ActiveXObject){obj=this._createXhrFromActiveX();};return obj;},_createXhrFromActiveX:function(){var aVersions=["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];for(var i=0;i<aVersions.length;i++){try{var oXmlHttp=new ActiveXObject(aVersions[i]);return oXmlHttp;}catch(e){};};return null;},_createQueryString:function(parameters){var params='';if(typeof(parameters)=='object'){for(keys in parameters){if(params!='')params+='&';params+=escape(keys)+'='+escape(parameters[keys]);};}else{params=parameters;};return params;},sendRequest:function(method,url,parameters,retFunction){var w=JASTEggIt;var _xhr=this._createXhr();if(_xhr==null)return false;this._xhrInstances+=1;if(this._xhrInstances>0&&this._loaderId!='')w._id(this._loaderId).style.display='';var params=this._createQueryString(parameters);_xhr.onreadystatechange=function(){if(_xhr.readyState==4){var output_buffer=_xhr.responseText;output_buffer=output_buffer;if(retFunction!=null){if(typeof retFunction==='function'){retFunction(output_buffer);}else{retFunction=retFunction.replace('%%BUFFER%%','output_buffer');eval(retFunction);}};_xhr=null;var x=w.xhttp;var ldr=x._loaderId;x._xhrInstances-=1;if(x._xhrInstances==0&&ldr!='')w._id(ldr).style.display='none';return true;};};if(method=="POST"){_xhr.open("POST",url,true);_xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');_xhr.send(params);}else{if(params!='')url+=(url.indexOf('?')!=-1?'&':'?')+params;_xhr.open("GET",url,this.options.userName);_xhr.setRequestHeader("connection","close");_xhr.send(null);};return true;},xsRequest:function(url,parameters,retFunction){var w=JASTEggIt;var h=w._name('head').item(0);if(this._xssInstances!=0){var old=w._id('xsrequest-script');if(old)head.removeChild(old);this._xssInstances=0;};var s=document.createElement('SCRIPT');var params=this._createQueryString(parameters);url+=(url.indexOf('?')!=-1?'&':'?')+params;s.type='text/javascript';this._xssInstances+=1;s.id='xsrequest-script';s.defer=true;s.src=url;s.returnTo=retFunction;h.appendChild(s);},xsResponse:function(data){var w=JASTEggIt;var old=w._id('xsrequest-script');this._xssInstances=0;old.returnTo(data);if(old){var h=w._name('head').item(0);h.removeChild(old);};}}};var _=JASTEggIt;