// Check / Uncheck (object: checkbox)
// flag = this.checked, obj = reference to the checkboxs to be selected
function changeSelection(flag, obj){
	size = 0;
	for(i=0; i<obj.length; size++){
		if(size==1){
			break;
		}
	}
	
	if(size>0){
		for(i=0; i<obj.length; i++){
			obj[i].checked = flag;
		}
	}else{
		obj.checked = flag;
	}
}

// Check / Uncheck (object: combobox)
// flag = this.checked, obj = reference to the combobox to be selected
function changeSelectionComboBox(flag, obj){
	for(i=0; i<obj.length; i++){
		obj[i].selected = flag;
	}
}


// this function allow to check or decheck the objSelectAll if necessary
// objSelectAll = the checkbox representing the select/deselect All
// objCheckbox = the list of checkbox to control
function checkSelection(objSelectAll, objCheckbox){

	if(objCheckbox.length>1){
		
		for(i=0; i<objCheckbox.length; i++){
			if(objCheckbox[i].checked==false){
				objSelectAll.checked = false;
				return;
			}
		}

		objSelectAll.checked = true;
		
	}else{
		objSelectAll.checked = objCheckbox.checked;
	}
}

function checkSelectionComboBox(objSelectAll, objComboBox){

	if(objComboBox.length>=1){
		for(i=0; i<objComboBox.length; i++){
			if(objComboBox[i].selected==false){
				objSelectAll.checked = false;
				return;
			}
		}

		objSelectAll.checked = true;
		
	}else{
		objSelectAll.checked = objComboBox.selected;
	}
}

// Change Language in the authentication procedure
function setLanguage(language, contextPath){
	mainUrl = self.location.pathname;
	if(mainUrl==contextPath || mainUrl==contextPath+"/" || mainUrl.indexOf("index.jsp")>=0){
		mainUrl = contextPath+"/control/welcome";
	}
	self.location.href=mainUrl+"?mainLanguage="+language+"&r="+Math.random();
}

function scrollLayer(layerName, pixerScrollTop){
	var cross_scroller, ns_scroller;

	if (document.all || document.getElementById){
		if(document.getElementById(layerName)){
			cross_scroller = document.getElementById(layerName);
			cross_scroller.scrollTop=cross_scroller.scrollTop+pixerScrollTop;
		}
	}
	else if (document.layers){
		ns_scroller = eval('document.layers.'+layerName);
		if(ns_scroller){
			ns_scroller.scrollTop=ns_scroller.scrollTop+pixerScrollTop;
		}
	}
}

function removeScroll(layerName){
	var cross_scroller, ns_scroller;

	if (document.all || document.getElementById){
		if(document.getElementById(layerName)){
			cross_scroller = document.getElementById(layerName);
			cross_scroller.style.height = 'auto';
		}
	}
	else if (document.layers){
		ns_scroller = eval('document.layers.'+layerName);
		if(ns_scroller){
			ns_scroller.style.height = 'auto';
		}
	}
}

function setWindowTitle(title){
	top.document.title = title;
}

function clickButtonOnEnter(e, inputId, buttonId)	{
	var inputElement= document.getElementById(inputId);
	var buttonElement= document.getElementById(buttonId);
	if( !e ) {
	    if( window.event ) {         //Internet Explorer
	      e = window.event;
	    } else {                   //total failure, we have no way of referencing the event
	      return;
	    }
    }
    if( typeof( e.keyCode ) == 'number'  ) {        //DOM
    	e = e.keyCode;
    } else if( typeof( e.which ) == 'number' ) {      //NS 4 compatible
    	e = e.which;
    } else if( typeof( e.charCode ) == 'number'  ) {       //also NS 6+, Mozilla 0.9+
    	e = e.charCode;
    } else {               //total failure, we have no way of obtaining the key code
    return;
    }
    if(e == 13) {   //pressed the ENTER key
    	buttonElement.click();
    }
}

