/*
function include(url)

{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e);
}
 
include("ajax.js")
include("AjaxUtility.js")
*/



// cerca un elemento nell'array
function include(arr, obj) {
  for(var i=0; i<arr.length; i++) {
    if (arr[i] == obj) return true;
  }
}


// funzione per l'apertura di un popup generico
function openPopup (strURL,w,h,target) {
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	
	if (!target) target = "_blank";
    
    window.open(strURL,target,"width=" + w + ", height=" + h + ", left=" + l + ", top=" + t +", resizable=Yes, scrollbars=Yes");
    }
    
    
// funzione per l'apertura di un popup generico
function openPopupFix (strURL,w,h,target) {
	var l = Math.floor((screen.width-w)/2);
	var t = Math.floor((screen.height-h)/2);
	
	if (!target) target = "_blank";
    
    window.open(strURL,target,"width=" + w + ", height=" + h + ", left=" + l + ", top=" + t +", resizable=No, scrollbars=No");
    }

// Funzione che genera un alert al load della pagina. Vengono gestite comunque eventuali altre funzioni inserite nel load
function alertOnLoad(txt){

	addEvent(window, 'load', new Function('setTimeout(function(){alert(\'' + txt + '\')},1)'));

}

// Crossbrowser event attach and remove
function addEvent(obj, type, fn){
	if (obj.attachEvent) {
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} else
		obj.addEventListener( type, fn, false );
}

// assegna il contenuto al controllo
function SetContent(objControl, value) {

    if ((value==null) || (value=='undefined')) { 
        value='';
    }

    if (typeof objControl.textContent != 'undefined') {
            objControl.textContent = value;
    }else {
            objControl.innerText = value;
    } 
}

// restituisce il contenuto del controllo
function GetContent(objControl) {
    
    if (typeof objControl.textContent != 'undefined') {
        return objControl.textContent;
    }else {
        return objControl.innerText;
    } 
}

// true se value è nullo
function IsNull(value){
    if ((value==null) || (value=='undefined')) {
        return true;
    }else{
        return false;
    }
}

function OpenSearchItinerari() {
    
    var key = document.getElementById("cerca").value;
    
    window.location.href = "T35_RisultatiItinerari.aspx?key=" + key;

}


function OpenSearchComm() {
    
    var key = document.getElementById("communitykey").value;
    
    window.location.href = "T37_RisultatiCommunity.aspx?key=" + key;

}



/**********************************************************************************************/
/* Funzioni pagina registrazione                                                              */

// gestisce visibilità dei div
function showhideDiv(divID){
    
    if(document.getElementById("hidShowDiv").value.indexOf('[' + divID + ']') != -1){
        // il div è presente (= è visibile), lo rimuoviamo
        document.getElementById(divID).style.display='none'
        show1 = false
        document.getElementById("hidShowDiv").value = document.getElementById("hidShowDiv").value.replace('[' + divID + ']','');
    }else{
        // il div NON è presente (= è nascosto), lo aggiungiamo
        document.getElementById(divID).style.display='block'
        show1 = true
        document.getElementById("hidShowDiv").value += '[' + divID + ']';
    }
}

// gestisce la memorizzazione dei checkbox selezionati
function AddRemoveValueCheck(chk,hiddenTxt) {
    if (chk.checked) {
        document.getElementById(hiddenTxt).value += '[' + chk.value + ']';
    }else{
        document.getElementById(hiddenTxt).value = document.getElementById(hiddenTxt).value.replace('[' + chk.value + ']','');
    }
}

// riempie le liste di chechbox con i valori memorizzati nelle textbox hidden
function FillCBL(hiddenTxt,itemName){
    if (document.getElementById(hiddenTxt).value == '') {return}

    // recupero i mesi inseriti
    var OldValues = document.getElementById(hiddenTxt).value.replace(/\[/g,'').split(']');
    
    
    for (i=0;i<OldValues.length;i++){
        if (OldValues[i]=='') {break;}
        document.getElementById(itemName + OldValues[i]).checked = true;
        }
    
}

// ripristina la visibilità dai controlli precedentemente visualizzati
function ShowAll(){
    var ShowDiv = document.getElementById("hidShowDiv").value
    
    if (ShowDiv != ''){
        var OldValues= ShowDiv.replace(/\[/g,'').split(']');
        for (i=0;i<OldValues.length;i++){
            if (OldValues[i]=='') {break;}
            document.getElementById(OldValues[i]).style.display='block'
        }
    }
}

function FillData(){
    document.getElementById("txtUserName").value = 'nachille';
    document.getElementById("txtEmail").value = 'nicola.achille@ramcube.it';
    document.getElementById("txtNome").value = 'Nicola';
    document.getElementById("txtCognome").value = 'Achille';
    document.getElementById("txtIndirizzo").value = 'via Saragat 2';
    document.getElementById("txtCap").value = '20051';
    CaricaCitta_ddl_reg('20051');
    document.getElementById("txtTelefono").value = '0299483232';
    document.getElementById("txtMobile").value = '3398656904';
    document.getElementById("txtTelefono").value = '0299483232';
    document.getElementById("txtDataNascita").value = '19/02/1981';
    document.getElementById("txtPassword").value = 'xxx';
    document.getElementById("txtPassword2").value = 'xxx';
    document.getElementById("chkCatalogo").checked = true;
    document.getElementById("chkTermini").checked = true;
}


function Logout(txt){
    alert(txt);
    window.location.href = "Default.aspx"
    
}




/*****************************************************************************************************/
/*   Upload da Personale.aspx                                                                        */

function ConfirmUpload(item)
{

    var strMsg;
    var btnName;
    if (item == 'foto') {
        strMsg = "Certifico di avere i diritti di distribuzione di questa foto \n\r e che essa non viola le condizioni d`uso ";
        btnName = "btnUpFoto";
    }else{
        strMsg = "Certifico di avere i diritti di distribuzione di questo racconto \n\r e che esso non viola le condizioni d`uso ";
        btnName = "btnUpRacconto";
    }
    // conferma
    
    if(confirm(strMsg)){
        var g = document.getElementById(btnName); //prendo il button del form padre
        if (g!=null) g.click();
    } 
   
}



function HideClessidra(){
    document.getElementById('divWait').style.display = 'none';
}


/*
	Note: the unload event is called when the page reload too.
		So, we have to check if the user has clicked the X, checking
		the mouse position at the event object.
*/
function hideClessidraIfXClicked(){	
    
	try {
		if(window.event) 
			if (window.event.clientY<0 && window.event.clientY>-20 && window.event.clientX>(window.document.body.clientWidth-20)) {
				parent.opener.document.getElementById('divWait').style.display = 'none';
			}
	} catch(e){
	}

}



function UnicaRisposta(obj,totRisp,namePart){	
 
    var cont = '';
    var objName = '';
    
    for(var i=0; i<totRisp; i++) {
        if (i<10) {cont = '0' + i}
        objName = namePart + '_ctl' + cont + '_radRisposta';
        
        // decheck
        document.getElementById(objName).checked = false;
    }
    
    // decheck per il radio corrente
    obj.checked = true;

}


function ManageIdRElimina(obj, IdER){	
 
    var cont = '';
    var objName = '';
    
    var hidIRispostaElimina = document.getElementById("hidIRispostaElimina").value;
    
    if (!obj.checked) {
        document.getElementById("hidIRispostaElimina").value = hidIRispostaElimina + '|' + IdER + '|';
    }
    
    if (obj.checked) {
        document.getElementById("hidIRispostaElimina").value = hidIRispostaElimina.replace('|' + IdER + '|', '');
    }

}


function txtKeyPress(myfield, e, loginButtonId) {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;

    if (keycode == 13) {
        var LoginButton = document.getElementById(loginButtonId);
        if (LoginButton == undefined)
            return true;
        else {
            LoginButton.click();
            return false;
        }
    } else return true;
}
