var xmlHttp;
var OutputLayer;
var IDtoShow;
var pageToShow;


function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById(OutputLayer).innerHTML=xmlHttp.responseText ;
	} 
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 

function getNews()
{
	OutputLayer = 'newsContainer';

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return
	} 
	var url="news.asp?rnd=" + Math.floor(Math.random()*10000);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function getNews2(startpage)
{
	OutputLayer = 'newsContainer';

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return
	} 
	var url="news2.asp?rnd=" + Math.floor(Math.random()*10000) + "&currentIndex="+startpage;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function getNews3(startpage)
{
	OutputLayer = 'newsContainer';

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return
	} 
	var url="news3.asp?rnd=" + Math.floor(Math.random()*10000) + "&currentIndex="+startpage;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function getCS2(startpage)
{
	OutputLayer = 'csContainer';

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return
	} 
	var url="cs2.asp?rnd=" + Math.floor(Math.random()*10000) + "&currentIndex="+startpage;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function showPositions() {
	OutputLayer = 'jobContainer';

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return
	} 
	var url="positions.asp?rnd=" + Math.floor(Math.random()*10000);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function openPosition(divID) {
	var divToOpen = document.getElementById(divID);
	
	if(divToOpen.style.display == 'block') {
		divToOpen.style.display = 'none';
	} else {
		divToOpen.style.display = 'block';
	}
}

function inviaCV(idJob) {
	OutputLayer = 'cvContainer'+idJob;

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return
	} 
	var url="formCV.asp?idJob="+idJob
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function validateForm() {
	var richiesti = new Array();
	var etichette = new Array();
	var required = 0
	var stringa = 'Attenzione, verificare i seguenti campi: \n';
	
	etichette.push('Cognome','Nome','Citta\'', 'Provincia','Via','Email','Telefono','Invia Allegato');
	richiesti.push('txtCognome', 'txtNome', 'txtCitta', 'txtProvincia', 'txtVia', 'txtEmail', 'txtTelefono', 'txtAllegato');
	for(i=0; i < richiesti.length; i++){
		if(document.getElementById(richiesti[i]).value == '') {
			required = 1;
			stringa = stringa + '\n' + etichette[i]
			//alert(richiesti[i] + ': ' + eval('document.modulo_career.'+ richiesti[i]+'.value'));
		}
	}
	if((document.getElementById('txtIndirizzoUni').selectedIndex == 0) && ((document.getElementById('txtTitoloStudio').selectedIndex > 2))) {
		stringa = stringa + '\nSelezionare l\'indirizzo universitario';
		required = 1;
	}
	if((document.getElementById('dateyear').selectedIndex == 0) || (document.getElementById('datemonth').selectedIndex == 0) || (document.getElementById('dateday').selectedIndex == 0)) {
		stringa = stringa + '\nSpecificare la data di nascita';
		required = 1;
	}
	if((document.getElementById('txtAreaInteresse1').selectedIndex == 0)) {
		stringa = stringa + '\nSpecificare un\'area di interesse';
		required = 1;
	}	
	if((document.getElementById('txtTitoloStudio').selectedIndex == 0)) {
		stringa = stringa + '\nSpecificare il titolo di studio';
		required = 1;
	}
	var indemail = document.getElementById('txtEmail').value;
	if((indemail.indexOf(".") > 2) && (indemail.indexOf("@") > 0)) {
		
	} else {
		stringa = stringa + '\nL\'indirizzo Email inserito non e\' valido';
		required = 1;
	}
	
	
	if((document.getElementById('chkPrivacy').checked == false)) {
		stringa = stringa + '\n\nPer inviare il modulo devi accettare il trattamento dei dati personali';
		required = 1;
	}
	
	
	if(required == 0) {
		document.formCV.submit();		
		return true;		
	} else {
		alert(stringa);
		return false;
	}
}

function privacy() {
	availheight = screen.availHeight;
		availwidth = screen.availWidth;
		searchWin = window.open('privacy.asp','aprifinestra','width=600,height=400,scrollbars=yes,resizable=yes,status=no,location=no,toolbar=no,menubar=no');
}

function checkStudy() {
	if((document.getElementById('txtTitoloStudio').selectedIndex > 2)) {
		document.getElementById('txtIndirizzoUni').disabled = false;
	} else {
		document.getElementById('txtIndirizzoUni').disabled = true;
	}
}