
function changesrc(cosa){  
	// cookies
	if (getCookie("IDb")&&getCookie("IDp")) {
		//alert(getCookie("IDb"));
		//alert(getCookie("IDp"));
		if (document.all) {
			document.all[cosa].src="http://booking.terravision.eu/boxbanner.asp";
		} else {
			document.getElementById(cosa).src="http://booking.terravision.eu/boxbanner.asp";
		}
	
	}	
	// querystring
	else if ((window.location.href.indexOf('?'))!=-1) {    
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		var hash;
		var z = 0;

		//prendiamo in considerazione solo i parametri passati sull'URL con nome IDb e IDp che siano valorizzati
		for(var i = 0; i < hashes.length; i++){
			
			hash = hashes[i].split('=');
		
			z++;

			if (z==1) {
				if (hash[0]=='IDb') {
					if (hash[1]=='') {
						return false;
					}    
				} else {
					return false;
				}
			} else if (z==2) {
				if (hash[0]=='IDp') {
					if (hash[1]=='') {
						return false;
					}
				} else {
					return false;
				}
			}
		}

		if (document.all) {
			document.all[cosa].src="http://booking.terravision.eu/boxbanner.asp?"+window.location.href.slice(window.location.href.indexOf('?') + 1);
		} else {
			document.getElementById(cosa).src="http://booking.terravision.eu/boxbanner.asp?"+window.location.href.slice(window.location.href.indexOf('?') + 1);
		}
	}
}

function getCookie(name){
	var cookies = document.cookie;
	/*alert("i cookies: " + cookies);
	alert("cookies.length: " + cookies.length);
	alert("cookies.indexOf(name): " + cookies.indexOf(name));*/
	if (cookies.indexOf(name) != -1){
		var startpos = cookies.indexOf(name)+name.length+1;
		//alert("startpos: " + startpos);
		var endpos = cookies.indexOf(";",startpos);//-1
		//alert("endpos: " + endpos);
		if (endpos == -1) endpos = cookies.length;
		/*alert("cookies.length-bis: " + cookies.length);
		alert("endpos-bis: " + endpos);*/
		return unescape(cookies.substring(startpos,endpos));
		//alert("valore: " + cookies.substring(startpos,endpos));
	}else{
		return false;
	}
}
