//libreria di utility laboratoriaweb 2.0
//variabili globali che mi servono per gestire la transizione delle immagini nel dettaglio news
var agNewsImage = new Array();
var iImageVisualized;
//calcola l'altezza e la larghezza dell'area effettiva dello schermo

function fnGetHeight() {
	iScreenHeight = window.screen.height;
 	return iScreenHeight;
}

function fnGetWidth() {
	iScreenWidth = window.screen.width;
	return iScreenWidth;
}

/*riduce del 20% l'altezza dello schermo*/
function fnAdaptToHeightResolution(){
	iScreenHeight =  fnGetHeight();
	iAdaptQuote = iScreenHeight*0.20;
	return iScreenHeight-iAdaptQuote;

}

/*riduce del 15% la larghezza dello schermo*/

function fnAdaptToWidthResolution(){
	iScreenWidth =  fnGetWidth();
	iAdaptQuote = iScreenWidth*0.15;
	return iScreenWidth-iAdaptQuote;

}

//centra rispetto allo schermo l'elemento passato come argomento

function fnAdaptToScreen(sElement){
	oElementToAdapt=document.getElementById(sElement);
	iScrenHalfHeight=parseInt(fnAdaptToHeightResolution()/2);
	/*
	iScrenHalfWidth=parseInt(fnAdaptToWidthResolution()/2);
	*/
	iScrenHalfWidth=parseInt(fnGetWidth()/2);
	iElementHeight=oElementToAdapt.clientHeight;
    iElementWidth=oElementToAdapt.clientWidth;
	if(parseInt(iElementWidth/2)<iScrenHalfWidth){
 		oElementToAdapt.style.left=iScrenHalfWidth+"px";
	    oElementToAdapt.style.marginLeft="-"+parseInt(iElementWidth/2)+"px";
	}
	if(parseInt(iElementHeight/2)<iScrenHalfHeight){
		oElementToAdapt.style.top=iScrenHalfHeight+"px";
		oElementToAdapt.style.marginTop="-"+parseInt(iElementHeight/2)+"px";

	}
}

/*colora thumbnails change*/

function fnSetColor(oItem){
	sColor = oItem.style.color;
	oItem.style.color = "#FCA83A";
}

function fnUnsetColor(oItem){
	oItem.style.color = sColor;
}


/*gestione onMouseOver dei link del menù*/

function fnChangeImg(oItem){
//alert(oItem.src);
}

function fnResetImg(){

}

/*gestore box update file e pdf*/

function fnAddUpdloadBox(oItem){
 	//estraggo il numero del box
	var sPattern = /[a-zA-Z]*[_][a-zA-Z]*[_]/;
	var iNumItem = oItem.id.split(sPattern);
	var iNewItem = ++iNumItem[1];
    //generazione nuovo child input
	var oNewNode = document.createElement("input");
	oNewNode.setAttribute("type","file");
	sNewNodeName = "image_"+iNewItem;
    oNewNode.setAttribute("name",sNewNodeName);
    oNewNode.setAttribute("size","40");
    //prelievo del div parent e collegamento nuovo figlio
    var oParent = document.getElementById('ins_news');
    oParent.appendChild(oNewNode);
	document.getElementById('ins_news').numImg.value = iNewItem;
    //fnAddTextChild("Immagine"+iNewItem,oNewNode);
}

/*created 02/05/2010*/
/*
*fnCheckCriteria controlla la coerenza del parametro di ricerca, serve ad evitare di appesantire le ricerche se il criterio è troppo corto e da troppi risultati da visualizzare
*@sCriteria: string that build the like parameter in query
*@bCheck: boolean that say the parameter is correct or not
*/

function fnCheckSendResearch(oForm){
	 if(oForm.criterio.value == "inserisci criterio" || oForm.criterio.value == " " || oForm.criterio.value.length<3){
			fnOpenServicesBox('error','Criterio di ricerca non impostato correttamente');
	 }
	else
		oForm.submit();
	return false;
}

/*fnChange... servono semplicemente ad azzerare i valori iniziali dei campi input e cambiare il colore del font*/
function fnChangeLoginInput(sDivForm){
	var oForm = document.getElementById(sDivForm);
	oForm.user.value="";
	oForm.user.style.color="#000";
	oForm.user.onclick="";
	oForm.passw.value="";
	oForm.passw.type="password";
	oForm.passw.style.color="#000";
	oForm.passw.onclick="";
}

function fnChangeContattiInput(sDivForm,e){
	var oForm = document.getElementById(sDivForm);
	if(e.type == 'click'){
		oForm.testo.value="";
		oForm.testo.style.color="#000";
		oForm.testo.onclick="";
	}
	if(e.type == 'change'){
		oForm.oggetto.onclick="";
		oForm.oggetto.style.color="#000";
	}	
}

/*fnCheckValidMail controlla che formalmente l'indirizzo mail sia corretto*/
/*
*sMailAddress stringa indirizzo
*return: boolean
*/
function fnCheckValidMail(sMailAddress){
	var sPattern = new RegExp("^[a-zA-Z0-9_.-]+@[a-zA-Z]+\.[a-zA-Z]{2,4}$");
        var risultato = sPattern.exec(sMailAddress);
	return risultato;
}




/*calcolo la la posizione dell'elemento da la chiamo*/
/*
*oElement: oggetto
*return: oggetto con le proprietà x e y
*/

function getPosition( oElement )
{
	//oggetto di nome pos con due proprietà x e y
	var pos = {};
	pos.y = 0;
	pos.x = 0;
	while( oElement != null ) {
		pos.y += oElement.offsetTop ?  oElement.offsetTop : 0;
		pos.x += oElement.offsetLeft ?  oElement.offsetLeft : 0;
		oElement = oElement.offsetParent;
	}
	return pos;
}

/*
* fnAdjustImage calcola le dimensioni dell'immagine di cui viene passato l'id e la ridimensiona distinguendo tra verticali e orizzontali, la visualizza dopo averla ridimensionata
*sDivImage: string id dell'immagine
*return null
*/
function fnAdjustImage(sDivImage){
	if(document.getElementById(sDivImage)){
		var oImage=document.getElementById(sDivImage);
		var iHeight = oImage.height;
		var iWidth = oImage.width;
		if(iHeight>iWidth){
			oImage.style.height = "186px";
			oImage.style.width = "150px";
		}
		if(iHeight<iWidth){
			oImage.style.height = "150px";
			oImage.style.width = "186px";
		}
		oImage.style.display = "inline";
	}
}

/*funzione che esegue l'inner html nell'elemento di cui gli viene passato l'id, il contenuto è il secondo parametro*/
function fnOpenAll(sDivContainer,sContent){
	document.getElementById(sDivContainer).innerHTML = sContent;
}

