function externalLinks() {
	if (!document.getElementsByTagName) 
		return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}

function controlla(idform,aC,aV){
	var i;
	var status = true;
	
	for(i in aC){
		var c = document.getElementsByName(aC[i]);
		c = c[0];
		
		if(typeof(c)=="undefined")
			continue;
		
		switch(c.type){
			case 'text':
			case 'textarea':
			case 'select-one':
			case 'button':
			case 'hidden':
				if(c.value == aV[i]){
					c.style.borderColor = "#FF0000";
					c.style.backgroundColor = "#FFFFCC";
					status = false;
				}else{
					c.style.borderColor = "#5D657C";
					c.style.backgroundColor = "#FFFFFF";
				}
			break;
			case 'select-multiple':
				if(c.selectedIndex == -1){
					c.style.borderColor = "#FF0000";
					c.style.backgroundColor = "#FFFFCC";
					status = false;
				}else{
					c.style.borderColor = "#5D657C";
					c.style.backgroundColor = "#FFFFFF";
				}
			break;
			default:
				alert(c.type);
			break;
		}
	}
	return status;
}

function getCal(ctl,m,y){
	
	if(typeof(m) == "undefined")
		m = 0;
	if(typeof(y) == "undefined")
		y = 0;
		
	//window.open('calendar.php?ctl='+ctl+(m?"&m="+m:"")+(y?"&y="+y:""),'Calendario','width=320,height=220,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
	window.open('index_pop.php?op=calendar&ctl='+ctl+(m?"&m="+m:"")+(y?"&y="+y:""),'Calendario','width=320,height=250,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
}

function getPers(ctl,one,sbm){
	
	if(typeof(one) == "undefined")
		one = 0;
	if(typeof(sbm) == "undefined")
		sbm = 1;
	
	window.open('index_pop.php?op=pers&ctl='+ctl+"&one="+one+"&sbm="+sbm,'People','width=520,height=400,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no');	
}

function getPerg(ctl,one,sbm){
	
	if(typeof(one) == "undefined")
		one = 0;
	if(typeof(sbm) == "undefined")
		sbm = 1;
	
	window.open('index_pop.php?op=perg&ctl='+ctl+"&one="+one+"&sbm="+sbm,'People','width=520,height=400,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no');	
}

function getProd(ctl,sbm){
	
	if(typeof(sbm) == "undefined")
		sbm = 0;
	
	window.open('index_pop.php?op=prod&ctl='+ctl+"&sbm="+sbm,'Produzioni','width=600,height=250,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no');	
}

function getEpi(ctl,sbm){
	
	if(typeof(sbm) == "undefined")
		sbm = 0;
	
	window.open('index_pop.php?op=epi&ctl='+ctl+"&sbm="+sbm,'Episodi','width=600,height=250,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no');	
}

function box(id,val){
				
	/*
	<div class="popupbox" id="div<?=$g['id_guida']?>">ciao</div>
							<a href="javascript:void(0);" id="infobutt<?=$g['id_guida']?>" onmouseover="box(<?=$g['id_guida']?>,1);" onmouseout="box(<?=$g['id_guida']?>,0);"><img src="img/info.png" alt="" /></a>
	
	*/
				
				
	var b = document.getElementById('div'+id);
	var i = document.getElementById('infobutt'+id);
	
	var curleft = curtop = 0;
	if (i.offsetParent) {
		curleft = i.offsetLeft
		curtop = i.offsetTop
		while (i = i.offsetParent) {
			curleft += i.offsetLeft
			curtop += i.offsetTop
		}
	}
	
	if(val){
		/*if(typeof(navigator.product)=='undefined'){
			b.style.top = '0px';
			b.style.left = '0px';
		}else{
			
			b.style.top = (curtop)+'px';
			b.style.left = (curleft-470)+'px';
		}
		*/
		b.style.display = 'block';
	}else{
		b.style.display = 'none';
	}
}

function ac(n){
	var o = document.getElementById(n);
	o.style.display = o.style.display=='block'?'none':'block';
}

function selMY(cb){
	var m = document.getElementById('hM');
	var y = document.getElementById('hY');
	var my = cb.value.match(/(\d+)/g);
	
	m.value = my[0];
	y.value = my[1];
	
	cb.form.submit();
}

window.onload = externalLinks;