﻿// File JScript


function GeneralHttpError(sender, args){
    //Imposta il timer per nascondere il messaggio di errore del login se è visibile
    setTimeout("CloseErrorLogin()", 4000);

    if (args.get_error() != undefined){
       var errorMessage;
       if (args.get_response().get_statusCode() == '500'){
           errorMessage = "Si sono verificati degli errori di comunicazione con il server, si consiglia di ricaricare la pagina!";
       }else{
           errorMessage = args.get_error().message;
       }
       args.set_errorHandled(true);
       alert(errorMessage);
   }

}


    function ChangeDivDisplay(divId){

        var element = document.getElementById(divId);
        if (element == null){
            alert(templateStrings.GetUnableFindDivElement());
            return false;
        }
        element.style.display = (element.style.display == "none") ? "" : "none";
        
    }

    function AddEventOnObject(element, onEvent, eventCode){

        if (element == null){
            alert("Impossibile aggiundere un evento ad un oggetto vuoto!");
            return false;
        }
        if (onEvent == null || eventCode == null){
            alert("Specificare l'evento e/o il codice da associare!");
            return false;
        }    
        
        if (element.addEventListener){
            onEvent = onEvent.substring(2); //toglie il prefisso 'on'    
            element.addEventListener(onEvent, eventCode, false);
        }else if (element.attachEvent)
            element.attachEvent(onEvent, eventCode);

        return true;

    }   


    function IsAttributeNull(attribute){

        return (attribute == null || attribute.value == "null");

    }

    function SetLocation(newUrl){
        document.location = newUrl;
    }
    function ChangeLanguage(newLanguage){
        
        var thisLocation = document.location.toString();
        
        //se c'è già il parametro lng viene eliminato
        thisLocation = thisLocation.replace(/(lng=)(it|en)[&|#]/g, "");
        thisLocation = thisLocation.replace(/(lng=)(it|en)$/g, "");
        
        if (thisLocation.indexOf("?") == -1)
            thisLocation += "?";
        
        thisLocation += (thisLocation.match(/(&|\?)$/g)) ? "lng=" : "&lng=";
        thisLocation += newLanguage;
                
        SetLocation(thisLocation);
        
    }

    function NewSampleSearch(){
        var description = document.getElementById('description_search');
        if (description == null){
            alert("Occorre specificare una chiave di ricerca!");
            return false;
        }
        var keySearch = encodeURIComponent(description.value);
        StartWait();
        SetLocation("search.aspx?description=" + keySearch);
    }


		function showDivCats(divId, pA) {
			ChangeDivDisplay(divId);
			
			if(pA.innerHTML == "+") 
				pA.innerHTML = "-";
			else if(pA.innerHTML == "-") 
				pA.innerHTML = "+";
			
		}
