/* LibSick Js 0.5 beta
 *
 * Copyright Netsick Corp 2010
 *
 * This file is part of the libsick_cms project
 * LibSick is a free software project licensed under the GPLv3
 *
 */

var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
var ie = document.all;

/* Fading, animation & more */

//element toggler + state checker (used for interface buttons)
toggle = function(target,op){
	obj=getObject(target).style;
	if (op) {
		if (op.animation) {
			if (e=op.animation.fade) {
				var fading = true;
				if (e.time) var fadingTime = e.time;
				else var fadingTime = 750;
			}
			if (e=op.animation.collapse) {
				var collapsing = true;
				if (e.time) var collapseTime = e.time;
				else var collapseTime = 500;
			}
		}
		else {
			var fading = false;
			var collapsing = false;
		}
		if (op.button) {}
		//default values
	}
	if (obj.display == "none") {
		if (fading) opacity_change(0,target);
		if (collapsing) collapse(target,collapseTime); 
		obj.display = obj.display? "":"block";
		if (fading) fade(target,0,100,fadingTime);
	}
	else {
		var h = obj.height;
		if (collapsing){
			collapse(target,collapseTime,h);
			setTimeout("obj.display = \"none\"", collapseTime);
		}
		if (fading) {
			fade(target,100,0,fadingTime);
			setTimeout("obj.display = \"none\"", fadingTime);
		}
		if (!collapsing && !fading) obj.display = "none";
	}
}
//change the opacity for different browsers 
opacity_change = function(opacity,id) { 
	var o = false; var o = getObject(id).style; 
	o.opacity = (opacity/100); 
    o.MozOpacity = (opacity/100); 
    o.KhtmlOpacity = (opacity/100); 
    o.MsFilter = '"progid:DXImageTransform.Microsoft.Alpha(Opacity='+(opacity+0)+')";';
	o.filter = "alpha(opacity="+(opacity+0)+");";
}
//fading function
fade = function(id,start,end,ms) { 
    var s = Math.round(ms/85); //speed for each frame 
    var t = 0; 
	if(start<end){for(i=start;i<=end;i++){setTimeout("opacity_change("+i+",'"+id+"')",(t*s));t++;}}
    else if(start>end){for(i=start;i>=end;i--){setTimeout("opacity_change("+i+",'"+id+"')",(t*s));t++;}} 
}

var timeouts= new Array();
//collapse function
collapse = function(id,ms,init){
	if(!init){}
	var tm = window.timeouts; var c = 0;
	while(tm.length!=0 && c<=tm.length-1){if(id==tm[c].id){clearTimeout(tm[c].act);var s_size = tm[c].size;removeItems(tm,c);}c++;}
	var o = getObject(id).style;
	a=tm.push({id:id})-1;
	if (o.height) {
		var h = parseInt(o.height+0);
		tm[a].size = h;
	}
	else {
		el.setStyle(id,{display:'block',overflow:'visible'});
		var h = offsetTot(id);
		o.height = h+'px';
		tm[a].size = h;
		o.display = 'none';
	}
	if(isset(s_size)){tm[a].size=s_size;}
	var w = parseInt(o.width+0);
	var s = Math.round(ms/85);
	var t = 0;
	if (o.display=="none"){
		el.setStyle(id,{height:'0px',overflow:'hidden'});
		collapseLoop = function(i){
			if (i<h) {
				t++;
				el.setStyle(id,{height:parseInt(o.height+0)+h/10+'px'});
				tm[a].act = setTimeout("collapseLoop("+parseInt(o.height+0)+");",(t*s)); 
			}
			else {el.setStyle(id,{overflow:'auto'});}
		}
		collapseLoop(0);
	}
	else {
		collapseLoop = function(i){
			if (i>0) {
				t++;
				if(parseInt(o.height+0) < h/10) el.setStyle(id,{height:'0px'});
				else el.setStyle(id,{height:parseInt(o.height+0)-h/10+'px'});
				tm[a].act = setTimeout("collapseLoop("+parseInt(o.height+0)+");",(t*s));
			}
			else {el.setStyle(id,{display:'none',height:tm[a].size+'px'}); clearTimeout(tm[a].act); removeItems(tm,a);}
		}
		collapseLoop(h);
	}
} 

// slider
slider = function(mainCont,elemCont,buttonCont,o){
	if (!elemCont || !mainCont) {alert('Slider v0.31\n\nA valid container element must be specified'); return false;}
	//declaring elements
	this.btnCont = buttonCont;
	this.mainCont = mainCont;
	this.elemCont = elemCont;
	this.mainObj = getObject(this.mainCont);
	this.elemObj = getObject(this.elemCont);
	this.mainWidth = getObject(this.mainCont).offsetWidth;	
	this.mainHeight = getObject(this.mainCont).offsetHeight;
	//css styles & control elements
	if (o && (e=o.gui.cnext)) this.cntNext = e; else this.cntNext = '';
	if (o && (e=o.gui.cprev)) this.cntPrev = e; else this.cntPrev = '';
	if (o && (e=o.gui.prevact)) this.prevActive = e; else this.prevActive = '';
	if (o && (e=o.gui.prevunact)) this.prevUnactive = e; else this.prevUnactive = '';
	if (o && (e=o.gui.nextact)) this.nextActive = e; else this.nextActive = '';
	if (o && (e=o.gui.nextunact)) this.nextUnactive = e; else this.nextUnactive = '';
	//options
	if (o && (e=o.gui.active)) this.activeElem = e; else this.activeElem = 0;
	if (o && (e=o.timers.speed)) this.scrollSpeed = e; else this.scrollSpeed = 30;
	if (o && (e=o.timers.scroll)) this.scrollTime = e; else this.scrollTime = 4000;
	//arrays
	this.activeLoops = new Array();
	this.slideObjs = new Array();
	this.btnObjs = new Array();
	var __this = this;
	this.slideInit = function(){
		var buttonNodes = getObject(this.btnCont).childNodes;
		for (var c=0; c <=buttonNodes.length-1; c++ ) {
			if (buttonNodes[c].tagName == "IMG" || buttonNodes[c].tagName == "A") {
				this.btnObjs.push(buttonNodes[c].id);
				getObject(buttonNodes[c].id).style.cursor = 'pointer';
			}
		}
		var contNodes = this.elemObj.childNodes;
		for (var n=0; n <=contNodes.length-1; n++ ) {
			if (contNodes[n].tagName == "DIV") {
				this.slideObjs.push(contNodes[n].id);
				contNodes[n].style.width = this.mainWidth+'px';
				contNodes[n].style.height = this.mainHeight+'px';
			}
		}
		this.elemObj.style.width = this.mainObj.offsetWidth*(this.slideObjs.length-1)+'px';
		this.jump(0);
	}
	this.next = function(loopStop){
		if (!loopStop) this.clearLoops();
		if (this.slideObjs[this.activeElem+1]) {
			this.active(this.activeElem+1);
			clearTimeout(this.activeScroll);
			this.scroll(this.mainWidth*this.activeElem);
			this.controls();
		}
	}
	this.previous = function(loopStop){
		if (!loopStop) this.clearLoops();
		if (this.slideObjs[this.activeElem-1]) {
			this.active(this.activeElem-1);
			clearTimeout(this.activeScroll);
			this.scroll(this.mainWidth*this.activeElem);
			this.controls();
		}
	}
	this.active = function(req){
		this.activeElem = req;
		for (n = 0; n<=this.btnObjs.length-1; n++) {
			var object = getObject(this.btnObjs[n]);
			if (n==req) {object.style.border = '2px solid #d4000a'; opacity_change(100,object.id);}
			else {opacity_change(50,object.id); object.style.border = '0px';}
		}
	}
	this.jump = function(target){
		clearTimeout(this.activeScroll);
		this.clearLoops();
		this.active(target);
		this.scroll(this.mainWidth*this.activeElem,5);
		this.controls();
	}
	this.scroll = function(point,speed){
		var applySpeed = false;
		if (!speed) var applySpeed = this.scrollSpeed; else var applySpeed = speed;
		if (this.mainObj.scrollLeft < point) this.mainObj.scrollLeft += this.mainWidth/10;
		else if (this.mainObj.scrollLeft > point) this.mainObj.scrollLeft -= this.mainWidth/10;
		if (this.mainObj.scrollLeft!=point) this.activeScroll = setTimeout(function (){__this.scroll(point,applySpeed);},applySpeed);
	}
	this.controls = function(){
		if (!this.slideObjs[this.activeElem-1]) getObject(this.cntPrev).src = this.prevUnactive; else getObject(this.cntPrev).src = this.prevActive;
		if (!this.slideObjs[this.activeElem+1]) getObject(this.cntNext).src = this.nextUnactive; else getObject(this.cntNext).src = this.nextActive;
	}
	this.loop = function(){
		var timer=0;
		for (i=1; i<=this.slideObjs.length-1; i++) {
			timer+=this.scrollTime;
			this.activeLoops.push(setTimeout(function(){__this.next('avoid_loop_stopping');},timer));
			if (i == this.slideObjs.length-1) this.activeLoops.push(setTimeout(function(){__this.jump(0);__this.loop();},timer+2000));
		}		
	}
	this.clearLoops = function(){
		if (this.activeLoops.length!=0) {
			for (var i = 0; i<=this.activeLoops.length-1; i++) {
				clearTimeout(this.activeLoops[i]);
			}
		}
	}
	//autoInit and loop via options object
	if (o && o.autoInit) this.slideInit();
	if (o && o.autoInit && o.loop) this.loop();
}

var nn6 = document.getElementById &&! document.all;
var dEl = document.documentElement;
var isdrag = false;
var x, y;
var dobj;

movemouse = function(e) {
	if( isdrag ) {
		//newmarginRight=document.body.clientWidth-widgets.wg_info[idarr[1]][1]-parseInt(dobj.style.width+0);
		dobj.style.left = (nn6 ? tx + e.clientX - x : tx + event.clientX - x)+'px';
		dobj.style.top = (nn6 ? ty + e.clientY - y : ty + event.clientY - y)+'px';

		
		myWidth = dEl.clientWidth?dEl.clientWidth:window.innerWidth;
		myHeight = dEl.innerHeight?dEl.innerHeight:document.body.clientHeight;
		if (myHeight<window.innerHeight || dobj.style.position=='fixed') {myHeight=dEl.clientHeight?dEl.clientHeight:window.innerHeight;}

		if (parseInt(dobj.style.left+0)<=0) dobj.style.left = 0+'px';
		if (parseInt(dobj.style.top+0)<=0) dobj.style.top = 0+'px';
		if (parseInt(dobj.style.left+0)>=(myWidth-parseInt(dobj.offsetWidth+0))) dobj.style.left = myWidth-parseInt(dobj.offsetWidth+0)+'px';
		if (parseInt(dobj.style.top+0)>=(myHeight-parseInt(dobj.offsetHeight+0))) dobj.style.top = myHeight-parseInt(dobj.offsetHeight+0)+'px';
		return false;
	}
}

//document.Form1.scrolly.value = (window.pageYOffset)?window.pageYOffset:(document.documentElement && document.documentElement.scrollTop)?document.documentElement.scrollTop:document.body.scrollTop;

lock_element = function(id){
	var moving_id = id;
}
selectmouse=function(e) {
	var fobj = nn6 ? e.target : event.srcElement;
	var topelement = nn6 ?  "HTML":"BODY";
	idarr = fobj.className.split(",");
	/*while (fobj.tagName != topelement && idarr[0] !=  "dragme" ) {
		fobj = nn6 ? fobj.parentNode : fobj.parentElement
	}*/
	if (idarr[0]== "dragme" ) {
		isdrag = true;
		dobj = document.getElementById(idarr[1]);
		widgets.wFocus(idarr[1]);
		tx = parseInt(dobj.style.left+0);
		ty = parseInt(dobj.style.top+0);
		x = nn6 ? e.clientX : event.clientX;
		y = nn6 ? e.clientY : event.clientY;
		document.onmousemove=movemouse;
		return false;
	}
}
stopdrag=function(){
	isdrag=false;
}
document.onmousedown=selectmouse;
document.onmouseup=stopdrag;


var z = 10;
//widgets
widgets = function(cont,o){
	wthemes = new Array();
	this.wg_cnt=0;
	this.wg_info=new Array();
	this.cnt = '';
	this.self = '';
	var __this = this;
	//constructor
	//cnt will be the main container
	if (!cont) {
		var tid = "widcnt_"+Math.floor(Math.random()*101);
		appendElement(document.body,"div",tid);
		this.cnt = getObject(tid);
	}
	else this.cnt=getObject(cont);
	if (o) {
		if (isset(e=o.dock)) {}
		if (isset(e=o.self)) this.self=e;
	}	
	//add a new widget
	this.wAdd = function(o){
		id="widg_"+this.wg_cnt++;
		//default value
		if (isset(e=o.position)) {wp=e; if(e=="fixed"){wdr=false; wdo=false;}}
		if (isset(e=o.coords)) {wc=e;} else wc="300x250";
		if (isset(e=o.size)) {ws=e;} else ws=false;
		if (isset(e=o.top)) {wt=e; if(wt){wdo=false;wdr=false;wp="fixed";}} else wt=false;
		if (isset(e=o.dockable)) {if(!wt && wp=="absolute"){wdo=true;} else wdo=false;} else wdo=false;
		if (isset(e=o.drag)) {wdr=e;} else wdr=true;
		if (isset(e=o.fade)) {wf=e;} else wf=false;
		if (isset(e=o.center)) {wcn=e;} else wcn=false;
		if (isset(e=o.title)) {wtt=e;} else wtt="New Widget";
		if (isset(e=o.theme)) {wtm=e;} else wtm="default";
		if (isset(e=o.closer)) {wtcl=e;} else wtcl=true; //da fare
		if (isset(e=o.url)) {wurl=e;} else wurl=false;

		if (ws) var wsr = ws.split("x");
		wcr = wc.split("x");
		ptop = wcr[1];
		pleft = wcr[0];
		wthemes['default']="<div id=\"<\{id\}>\" onclick=\""+this.self+".wFocus('<\{id\}>');\" style=\"font: 12px Verdana; background-color: #efefef; border: 2px dotted gray; top: "+ptop+"px; left: "+pleft+"px; position: "+wp+";<\{Size\}>\"><p style=\"margin: 0px; background-color: gray; color: #ffffff; font-weight: bold;\"<\{Dragging\}>><a href=\"#close\" style=\"float: right;\" onclick=\""+this.self+".wRemove('<\{id\}>');\"><img src=\"../system/gui/cancel.png\"/></a><\{wtt\}></p><div id=\""+id+"_cnt\" style=\"margin: 0px;\"><\{MainContent\}></div></div>";
		wthemes['dark']="<div id=\"<\{id\}>\" onclick=\""+this.self+".wFocus('<\{id\}>');\" style=\"background-color: black; color: #ffffff; border: 2px solid gray; top: "+ptop+"px; left: "+pleft+"px; position: "+wp+";<\{Size\}>\"><p<\{Dragging\}>><a href=\"#close\" style=\"float: right;\" onclick=\""+this.self+".wRemove('<\{id\}>');\">X</a><\{wtt\}></p></div>";
		
		wtm0=wthemes[wtm];
		wtm=wtm0.replace(new RegExp("<{id}>","gi"),id);
		if (wtt) {wtm=wtm.replace("<{wtt}>",wtt);} else wtm=wtm.replace(new RegExp("<{wtt}>","gi"),"");
		if (wsr) wtm=wtm.replace(new RegExp("<{Size}>","gi")," width: "+wsr[0]+"px; height: "+wsr[1]+"px;");
		else wtm=wtm.replace(new RegExp("<{Size}>","gi"),"");
		if (wdr) wtm=wtm.replace(new RegExp("<{Dragging}>","gi")," class=\"dragme,"+id+"\" style=\"cursor: move;\"");
		else wtm=wtm.replace(new RegExp("<{Dragging}>","gi"),"");
		
		if (wurl) {
			wtm=wtm.replace(new RegExp("<{MainContent}>","gi"),ajax(wurl,id+'_cnt'));
		}
		else wtm=wtm.replace(new RegExp("<{MainContent}>","gi"),"");
		if (wt) on_top({fade:true});
		this.cnt.innerHTML+=wtm;
		if (wcn) {
			cn=center(el.get(id).offsetWidth,el.get(id).offsetHeight);
			//alert(cn.x+'-'+cn.y)
			getObject(id).style.top = cn.y+"px";
			getObject(id).style.left = cn.x+"px";
		}
		this.wg_info[id+""]=[id+"",""+parseInt(wcr[0])];
		this.wFocus(id);
	}
	this.wRemove = function(id){
		o=getObject(id);
		if (e=getObject('on_top')) {
			fade('on_top',70,0,200);
			setTimeout("e.style.display='none'",200);
		}
		o.innerHTML = '';
		o.style.display = 'none';
		this.cnt.removeChild(o);
		this.wg_info[id].splice(0,2);
	}
	this.wDock = function(){}
	this.wUndock = function(){}
	this.wFocus = function (id){
		if(!id){ return false;}
		for(var wid in this.wg_info){
			if(id==wid){
				aobj=getObject(id);
				opacity_change(100,id);
				aobj.style.zIndex = z++;
			}
			else {
				//alert(this.wg_info[wid]+'---rotfl')
				var cid=this.wg_info[wid];
				if (cid[0]) opacity_change(50,cid[0]);
				else {}
			}
		}
	}
	this.dAdd = function(){}
	this.dRemove = function(){}
	this.dUpdate = function(){}

	this.wTemplate = function(){}
	this.dTemplate = function(){}
}

/* Various utilities */

on_top = function(o){
	if (el.get('on_top')) {
		if(o.fade) fade('on_top',0,70,200);
		el.setStyle('on_top',{zIndex:z++,display:'block'});
	}
	else{
		var ch = dEl.clientHeight?dEl.clientHeight:document.body.clientHeight;
		var cw = dEl.clientWidth?dEl.clientWidth:document.body.clientWidth;
		var sh = dEl.scrollHeight?dEl.scrollHeight:document.body.scrollHeight;
		var sw = dEl.scrollWidth?dEl.scrollWidth:document.body.scrollWidth;
		var wh = window.innerHeight?window.innerHeight:document.body.offsetHeight;
		
		el.add(document.body,'div','on_top');
		el.setStyle('on_top',{position:'fixed',top:'0px',left:'0px',background:'#111',zIndex:z++,height:Math.max(wh,ch)+'px',width:Math.max(sw,cw)+'px'});
		if(o.fade) fade('on_top',0,70,200);
		else opacity_change(70,'on_top');		
		//alert('wh:'+wh+'sh:'+sh+'ch:'+ch+'\n'+obj.style.height+'-'+obj.style.width)
    }
}

center = function(offx,offy){
	return mleft = {x:(document.body.clientWidth/2)-(offx/2),y:((ie?document.documentElement.clientHeight:window.innerHeight)/2)-(offy/2)}
}

//center = function(){}
//focus = function(){}

offsetTot = function(element){
	var active = getObject(element);
	if(document.defaultView){
		topMargin = parseInt(document.defaultView.getComputedStyle(document.getElementById(element), '').getPropertyValue('margin-top')+0);
		bottomMargin = parseInt(document.defaultView.getComputedStyle(document.getElementById(element), '').getPropertyValue('margin-bottom')+0);
	}
	else {
		topMargin = parseInt(active.style.marginTop+0);
		bottomMargin = parseInt(active.style.marginBottom+0);
	}
	var totHeight = active.offsetHeight+topMargin+bottomMargin+0;
	return totHeight;
}

mousetrap = function(e) {
	if(e==document.onmousemove){
		if (ie) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX + document.body.scrollLeft
			tempY = event.clientY + document.body.scrollTop
		}
		else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX
			tempY = e.pageY
		}
		// catch possible negative values in NS4
		if (tempX & 0){tempX = 0}
		if (tempY & 0){tempY = 0}
	}
	else {
		if (ie) { // grab the x-y pos.s if browser is IE
			x = event.clientX + document.body.scrollLeft
			y = event.clientY + document.body.scrollTop
		}
		else {
			x=getObject(e).offsetLeft;
			y=getObject(e).offsetTop;
		}
		return {x:x,y:y};
	}
	// show the position values in the form named Show
	// in the text fields named MouseX and MouseY
	//getObject('mousex').innerHTML = tempX
	//getObject('mousey').innerHTML = tempY
	//return retObj = {x:tempX,y:tempY}
	//alert(retObj.x+'-'+retObj.y)
	return true;
}
//document.onmousemove = mousetrap;

function isset(o){
  return(typeof(o)!='undefined');
}

/* Array Functions */

arrayUnique = function(id) {
	tmp = new Array(0);
	for (i=0; i<id.length; i++) {
		if (!contains(tmp,id[i])) {
			tmp.length += 1;
			tmp[tmp.length-1]=id[i];
		}
	}
	return tmp;
}
inArray = function(id,str) {
	for(i=0;i<=id.length-1;i++){if(id[i]==str) var found=true;}
	if (found) return true;
}
arrayRemove = function(id,str) {
	for(i=0;i<=id.length-1;i++){if(id[i]==str) id.splice(i,1);}
	return id;
}
removeItems = function(id,pos) {
	for(i=0;i<=id.length-1;i++){if(i==pos) id.splice(i,1);}
}

//mail syntax checker
mailsyntax = function(str){
	var rgx=RegExp("^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$");
	if(rgx.test(str)) return true; else return false;
}

//include function
include = function(path) {
    document.write('\n<'+'script type="text/javascript" src="'+path+'"></'+'script'+'>');
}
//getting object type
getObject = function(id){
	if (document.getElementById) var o=document.getElementById(id);
	else if (document.all) var o=document.all[id];
	else if (document.layers) var o=document.layers[id];
	return o;
}
//node appending
appendElement = function(node,tag,id,htm) {
    var ne = document.createElement(tag);
    if (id) ne.id = id;
    if (htm) ne.innerHTML = htm;
	node.appendChild(ne);
}
//is numeric function
IsNumeric = function(sText) {
	var ValidChars = "0123456789,.";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) IsNumber = false;
	}
	return IsNumber;
}
//chr function
chr = function(ascii) {
  return String.fromCharCode(ascii);
}

//non-empty POST check
noempty = function(obj){
  if (obj==null) return false;
  else return true;
}

/* Elements */
var el = {
	get : function(id){
		if (document.getElementById)  return document.getElementById(id);
		else if (document.all) return document.all[id];
		else if (document.layers) return document.layers[id];
	},
	add : function(n,t,i,o) {
		var ne = document.createElement(t);
		if (i) {
			if (ie) var ne = document.createElement('<'+t+' name="'+i+'">');
			else ne.setAttribute('name', i);
			ne.id = i;
		}
		if (o) ne.innerHTML = o;
		n.appendChild(ne);
	},
	remove : function(n,i){
		if(n==document.body){}else{n=this.get(n);}
		for(var c=0;c<n.childNodes.length;c++){if(n.childNodes[c].id==i){n.removeChild(n.childNodes[c]);}}
	},
	ihtml : function (i,o){
		this.get(i).innerHTML = o;
		var R=/<script\b[\s\S]*?>([\s\S]*?)<\/script>?/ig;
		var match;
		while (match=R.exec(this.get(i).innerHTML)) {eval(match[1]);}
	},
	empty : function(i){this.ihtml(i,'');},
	getStyle : function(i,o){return this.get(i).style[o];},
	setStyle : function(i,o){
		set = function(i,o,t){
			for(var c in o){
				if (typeof(eval('t.'+c))=="function") eval('t.'+c+'(i,o[c])');
				else eval('t.get(i).style.'+c+'=\''+o[c]+'\'');
			}
		}
		var m=i.split(',');
		if (m.length==0) set(i,o,this);
		else for(var mc=0; mc<=m.length-1; mc++) set(m[mc],o,this);
	},
	setProps : function(i,o){
		for(var c in o){
			if (typeof(eval('this.'+c))=="function") eval('this.'+c+'(i,o[c])');
			else eval('this.get(i).'+c+'=function(){'+o[c]+'}');
		}
	},
	exists : function(o){
		return(el.get(o));
	},
	click : function(i,o){this.get(i).onclick=function(){eval(o)};},
	mOver : function(i,o){this.get(i).onmouseover=function(){eval(o)};},
	mOut : function(i,o){this.get(i).onmouseout=function(){eval(o)};}
}

/* Strings */
var str = {}
/* Arrays */
var arr = {
	inArray : function(){},
	unique : function(){},
	remove : function(){},
	removeByStr : function(){}
}
/* */
var chk = {
	isEmpty : function(o){return(o==false);},
	mail : function(o){return(RegExp("^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$").test(o)==true);}
}
/* GMAPS */

gmap = function(loc,target,icon){
	if (GBrowserIsCompatible()) {
		var map = new GMap2(getobjecttype(target));
		var geocoder = new GClientGeocoder();
		map.setUIToDefault();
		//map.addControl(new GSmallMapControl());
		geocoder.getLatLng(loc, function(point) {
			if (!point) {
				alert(loc + " not found");
			}
			else {
				map.setCenter(point, 16);
				// Create our "tiny" marker icon
				var customIcon = []
				customIcon[0] = new GIcon();
				customIcon[0].image = "dot.png";
				customIcon[0].iconSize = new GSize(20, 20);
				customIcon[0].iconAnchor = new GPoint(10, 10);
				customIcon[0].infoWindowAnchor = new GPoint(10, 10);

				customIcon[1] = new GIcon();
				customIcon[1].image = "dot2.png";
				customIcon[1].iconSize = new GSize(20, 20);
				customIcon[1].iconAnchor = new GPoint(10, 10);
				customIcon[1].infoWindowAnchor = new GPoint(10, 10);
				
				if (!icon) var selIcon=customIcon[0];
				else var selIcon=customIcon[icon];
				var marker = new GMarker(point,selIcon);
				map.addOverlay(marker);
				gmap_counter++;
				var myHtml = "<p style=\"font: 10px Verdana; overflow: auto; height: 75px;\" id=\"gmap_cont"+gmap_counter+"\"><a href=\"#load_me\" onclick=\"ajax('load.html','gmap_cont"+gmap_counter+"');\">yepp</a><br /><b>Localit&agrave; cercata:</b> <br />"+loc+"</p>";
				marker.openInfoWindowHtml(myHtml);
				GEvent.addListener(marker,"click", function() {marker.openInfoWindowHtml(myHtml);});
				return marker;
			}
		});
		//var customUI = map.getDefaultUI();
		//customUI.controls.maptypecontrol = false;
		//map.setUI(customUI);
	}
}

/* AJAX */

//Xml Request
GetXmlHttp = function(){
	var xmlHttp=null;
	// Firefox, Opera 8.0+, Safari
	try { xmlHttp=new XMLHttpRequest(); }
	catch (e) {
		function GetXmlHttpObject(){
			var xmlHttp=null;
			// Firefox, Opera 8.0+, Safari
			try { xmlHttp=new XMLHttpRequest(); }
			catch (e) {
				// Internet Explorer
				try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
				catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			}
			return xmlHttp;
		}
		// Internet Explorer
		try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	return xmlHttp;
}

var loading_items = new Array();
//Ajax Request
ajax = function(url,target,options) {
	var axo = false;
	var optLoadTarget = false;
	if (!target) alert("Ajax: request error");
	if (!options) var method = "get";
	else{
		optarr = options.split(",")
		for (var opti in optarr) {
			opt=optarr[opti].split(":")
			switch (opt[0]) {
				case "loading_target":
					var opt_load_target = true;
					var optLoadTarget = opt[1];
				break;
				case "post":
					var method = "post";
				case "form":
					var spec_form = opt[1];
				default:
					var optLoadTarget = false;
			}
		}
	}
	if (opt_load_target) {getObject(optLoadTarget).innerHTML="loading!!"; loading_items.push("item");}
	function update(){
		if (axo.readyState==4 || axo.readyState=="complete") {
			if (opt_load_target) {
				loading_items.splice(0,1);
				if (loading_items.length == 0) getObject(optLoadTarget).innerHTML="";
			}
			getObject(target).innerHTML=axo.responseText;
			var R=/<script\b[\s\S]*?>([\s\S]*?)<\/script>?/ig; var match;
			while(match=R.exec(axo.responseText)){eval(match[1]);}
		}
    }
    //avoid IE caching problem
    var randz=Math.floor(Math.random()*101);
    var axo=GetXmlHttp();
	var question = '';
    if(url.search(/\?/i) != -1);
    else question='?';
    url=""+url+question+"&rand="+randz
    url=encodeURI(url)
    //GET method headers
    if(method=="get"){
		axo.open("GET",url,true)
		axo.setRequestHeader("Content-type", "text/html; charset=UTF-8")
		axo.onreadystatechange=update
		axo.send(null)
    }
    //POST method headers along with params
    else if(method=="post"){
		var params= "";
		if (spec_form && spec_form != "") {var form = document.forms[spec_form];}
		else var form = document.forms[0];
		var elementNum = form.elements.length;
		for(var i = 0; i < elementNum; i++){
			if(form.elements[i].type=='checkbox' && form.elements[i].checked==true){
				elem = form.elements[i].value;
				elem = encodeURIComponent(elem);
				if (i < elementNum-1) params += form.elements[i].name+"="+elem+"&";
				else params += form.elements[i].name+"="+elem;
			}
			else if(form.elements[i].type!='checkbox'){
				elem = form.elements[i].value;
				//elem = asciiReplace(elem);
				elem = encodeURIComponent(elem);
				if (i < elementNum-1) params += form.elements[i].name+"="+elem+"&";
				else params += form.elements[i].name+"="+elem;
			}
		}
		axo.open("POST", url, true);
		axo.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
		axo.setRequestHeader("Content-length", params.length);
		axo.setRequestHeader("Connection", "close");
		axo.onreadystatechange=update;
		axo.send(params);      
	}
}





watch_timeouts = function(){
	tm = window.timeouts;
	var cnt='';
	for (var i=0; i<=tm.length-1;i++){
		cnt += tm[i].id+'--'+tm[i].size+'\n';
	}
	alert(cnt);
	/*var act = {id:"hi",od:"god!"}
	act.lol = "odd!";
	act.od="hire!";
	alert(act.od)*/
}

//window.onscroll = function (){getObject('an_status').innerHTML = document.body.offsetHeight}

/* INCLUDING FILES */
//swfObject
include('swfobject.js');
include('flowplayer.js');
