function iniDis(){

	/*
	**  SEL EVENT ON CHANGE
	*/
	var eventsSelect = document.getElementById('eventsSelect');	
	//var placesSelect = document.getElementById('placesSelect');	
	eventsSelect.onchange = new Function("setForm(this)");
		
	/*
	**  DATES ON CHANGE
	*/
	var dateSels = getElementsByClass('date');	
	for(i=0; i<dateSels.length; i++){
		dateSels[i].onchange = function(){
			this.form.eventsSelect.options[0].selected="selected";
			setForm(this.form.eventsSelect);
		};	
		
	}	
	
	/*
	**  EXPAND
	*/
	var expand = getElementsByClass('expand');
	for(i=0; i<expand.length; i++){
		expand[i].onclick = new Function("expandUl(this)");		
	}
	
	/*
	**  JS   NAVIGATOR
	*/
	var jsNavigators = document.getElementById('jsNavigator').getElementsByTagName('a');
	for(i=0; i<jsNavigators.length; i++){		
		jsNavigators[i].onclick = new Function("changePage(this)");		
	}
	
	/*
	**  INFO  POPUP
	*/
	var info = getElementsByClass('pinfo');
	for(i=0; i<info.length; i++){		
		info[i].onmouseover = new Function("showPopup(this)");		
		info[i].onmouseout  = new Function("hidePopup(this)");		
	}	
	
	
	document.getElementById('info-callcenter').onmouseover = new Function("showInfo()");
	document.getElementById('info-callcenter').onmouseout = new Function("hideInfo()");
	
	/*
	**  FAKE  LINKS
	*/
//	var fake_link = getElementsByClass('fake_link');
//	for(i=0; i<fake_link.length; i++){		
//		fake_link[i].onclick = function(){location.replace(baseUrl+'/'+this.name)};				
//	}	
	
	
	
	
	
	//eventsSelect.onchange = new Function("reloadOptions(this)");
	
	//var f = eventsSelect.form;
	
	//f.onsubmit = new Function("setForm(this)"); 
	
}

function reloadOptions(eventsSelect){
	
	eventsSelect.form.action = baseUrl+"/"+eventsSelect.value;	
	//var url = baseUrl+"/ajax/getEventPlaces/"+eventsSelect.value;	
	//var loader1= new net.ContentLoader(url,parseResponse,null,"GET",'');
}

function parseResponse(){
	//alert(this.req.responseText);
	var placesSelect = document.getElementById('placesSelect');
	var xmlDoc = this.req.responseText;
	//var xmlDoc = this.req.responseXML.documentElement;
	placesSelect.innerHTML=xmlDoc;
	//alert(xmlDoc);	
	
}

function setForm(eventsSelect){

	//eventsSelect.form.action = baseUrl;
	
	if(eventsSelect.value!="0"){
		var info = eventsSelect.value.split('_');		
		
		var g_arr = info[1].substr(6,2);
		if(g_arr < 10){
			g_arr = g_arr.substr(1,1);
		}
		
		var g_par = info[2].substr(6,2);
		if(g_par < 10){
			g_par = g_par.substr(1,1);
			//alert(g_par);
		}
		
		setSelIndexByValue(document.getElementById('giornoarr'), parseInt(g_arr));
		setSelIndexByValue(document.getElementById('meseannoarr'),info[1].substr(0,6));
		// set checkout
		setSelIndexByValue(document.getElementById('giornopar'),parseInt(g_par));
		setSelIndexByValue(document.getElementById('meseannopar'),info[2].substr(0,6));
		
	}
		
}

function changePage(el){
	
	switch(el.id){
		
		case "first":
			if (current_page==1){return false;}
			var page = document.getElementById('page-'+current_page);
			var firstPage = document.getElementById('page-1');
			firstPage.style.display="block";
			page.style.display="none";
			current_page=1;

			break;	
						
		case "prev":
			if (current_page==1){return false;}
			var page = document.getElementById('page-'+current_page);
			var prevPage = document.getElementById('page-'+(current_page-1));
			prevPage.style.display="block";
			page.style.display="none";
			current_page--;

			break;
			
		case "next":
			if (current_page==num_pages){return false;}
			var page = document.getElementById('page-'+current_page);
			var nextPage = document.getElementById('page-'+(current_page+1));
			nextPage.style.display="block";
			page.style.display="none";
			current_page++;
				
			break;
		case "lastOne":
			if (current_page==num_pages){return false;}
			var page = document.getElementById('page-'+current_page);
			var nextPage = document.getElementById('page-'+num_pages);
			nextPage.style.display="block";
			page.style.display="none";
			current_page=num_pages;
			break;	
			
		break;
	}
	document.getElementById('current_page').innerHTML = current_page;
	
}

function expandUl(el){
	var list = document.getElementById(el.id.split('-')[1]).getElementsByTagName('li');
	var num_list = list.length;
	var span = el.getElementsByTagName('span')[0];
	span.className = switchClassName(span.className, 'more', 'less');
	if(num_list>city_limit){
		for(i=city_limit; i<num_list; i++){
			list[i].style.display = list[i].style.display=='block' ? 'none' : 'block' ;		
		}
	}

	el.className = switchClassName(el.className, 'expand', 'contract');
}

function switchClassName(className, class1, class2){
	var newClassName = '';
	var classes = className.split(' ');
	
	for(i=0; i<classes.length; i++){
		
		if(classes[i]==class1){
			newClassName+= class2+' ';
		}
		else if(classes[i]==class2){
			newClassName+= class1+' ';
		}
		else{
			newClassName+= classes[i]+' ';
		}
		
	}
	
	return newClassName;
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	if(classElements.length==0) return false;
	return classElements;
}

function findPos(o){
	var curleft = curtop = 0;
	if(o.offsetParent){
		while(o.offsetParent){
			curleft += o.offsetLeft;
			curtop += o.offsetTop;
			o = o.offsetParent
		}
	}	
	return [curleft,curtop]
}

function showPopup(el){	
	coors = findPos(el);
	pop = document.getElementById('popup-'+el.id.split('-')[1]);
	pop.style.top = coors[1] +5+"px";
	if(el.id.split('-')[1] == "help"){
		pop.style.left = coors[0]- 290 +"px";
	}
	else{
		pop.style.left = coors[0]+ 20 +"px";
	}
}

function hidePopup(el){	
	pop = document.getElementById('popup-'+el.id.split('-')[1]);
	pop.style.top = "-20000px";
	pop.style.left = "-20000px";
}

function showInfo(){	
	document.getElementById('popup-callcenter').style.display = 'block';
}

function hideInfo(){	
	document.getElementById('popup-callcenter').style.display = 'none';
}

function pad(n){
 if(n<10)
 	return "0"+n;
 return n;
}
function setSelIndexByValue(sel,val){
	for(i=0;i<sel.options.length;i++){
		if(sel.options[i].value==val) sel.options[i].selected="selected";
	}
}

function checkForm(f){
	
	var info = f.eventsSelect.value.split('_');
	
	var discount_url = info[0];
	var discount_checkin = parseInt(info[1]);
	var discount_checkout = parseInt(info[2]);
	
	var checkin  = parseInt(f.meseannoarr.value+pad(f.giornoarr.value));
	var checkout = parseInt(f.meseannopar.value+pad(f.giornopar.value));
	
	//alert(checkin+":::"+discount_checkin);
	//alert(checkout+":::"+discount_checkout);
	
	//(discount_url);
		
	if(discount_url!=0 && discount_checkin==checkin && discount_checkout==checkout){
		
		//var discount_url = f.eventsSelect.value.split('_')[0];		
		
		//var f_action = baseUrl+"/"+discount_url;
		var f_action = baseUrl+"/"+checkin+"/"+checkout;
		
	}
	else{
		
		//var checkin  = f.meseannoarr.value+pad(f.giornoarr.value);
		//var checkout = f.meseannopar.value+pad(f.giornopar.value);
		
		var f_action = baseUrl+"/"+checkin+"/"+checkout;
	}
	
	//alert(checkin);
	//alert(checkout);
	//alert(f_action); 
	//return false;
	f.action = f_action;
	
	//var info = eventsSelect.value.split('_');		
		//set Action
		//eventsSelect.form.action+="/"+info[0];
	
	//eventsSelect.form.action = baseUrl;
	//f.checkin.value = f.meseannoarr.value+pad(f.giornoarr.value);
	//f.checkin.value = f.meseannoarr.value+pad(f.giornoarr.value);
	//f.checkout.value = f.meseannopar.value+pad(f.giornopar.value);
	
	//alert(f.checkin.value+' '+f.checkout.value);
	//str = "";
	//var childs= f.childNodes;
	//for(i=0; i<childs.legth; i++){
		//if(typeof f[prop] == "object")
	//		str += childs[i]+": "+childs[i]+"\n";
	///} 
//	for(prop in f){
//		if(typeof f[prop] == "object" && f[prop]!="undefined")
//			str += prop+": \n";
//			for(iprop in f[prop]){
//				str += iprop+",";
//			}
//	}
//	alert(str);
	return true;
}
