function displayBlock(div) {
	document.getElementById(div).style.display = "block";
}

function displayN(div) {
	var divs = displayN.arguments;
	for (var i=0; i<displayN.arguments.length; i++){
		document.getElementById(divs[i]).style.display = "none";	
	}
}

function displayBlock2(div, div2) {
	document.getElementById(div).style.display = "block";
	document.getElementById(div2).style.display = "block";
}
function displayN2(div, div2) {
	document.getElementById(div).style.display = "none";
	document.getElementById(div2).style.display = "none";
}
function muestraOculta3(div1, div2, div3) {
	var o1 = document.getElementById(div1);
	var o2 = document.getElementById(div2);
	var o3 = document.getElementById(div3);
	if (o1 != null) {
		if (o1.style.display == 'none') {
			o1.style.display = 'block';
			o2.style.display = 'block';
			o3.style.display = 'none';
		} else {
			o1.style.display = 'none';
			o2.style.display = 'none';
			o3.style.display = 'block';
		}
	}
}

function muestraOculta2(div1, div2) {
	var o1 = document.getElementById(div1);
	var o2 = document.getElementById(div2);
	if (o1.style.display == 'none') {
		o1.style.display = '';
		o2.style.display = 'none';
	} else {
		o1.style.display = 'none';
		o2.style.display = '';
	}
}
function goToURL() { //v3.0
	var i, args = goToURL.arguments;
	document.returnValue = false;
	for (i = 0; i < (args.length - 1); i += 2)
		eval(args[i] + ".location='" + args[i + 1] + "'");
}
function MM_openBrWindow(theURL, winName, features) { //v2.0
	window.open(theURL, winName, features);
}

function changeStyle(id) {
	var e = document.getElementsByTagName('label');
	for (i = 0; i < e.length; i++) {
		e[i].className = 'off';
	}
	document.getElementById(id).className = 'selected';
}

/*function changeSelectionStyle(id) {
	
	var inputId = id.substr(0,id.length-2);
	alert(id);
	alert(inputId);
	var child = document.getElementById('selectedAuthorities-' + id + '_' + i);
	if(document.getElementById(inputId).checked){document.getElementById(id).className = 'yes';}
	alert(document.getElementById(inputId).checked);
	
	if($(id).checked && $(id).className = ''){$(id).className = 'yes';}
	if(!$(id).checked){$(id).className = '';}
	
	if(document.getElementById(id).className != 'yes'){
		document.getElementById(id).className = 'yes';
		
	}
	else{document.getElementById(id).className = '';}
}*/


function selectUnselectChildren(id) {
	var checked = document.getElementById(id).checked;
	var i = 0;
	while (true) {
		var child = document.getElementById('selectedAuthorities-' + id + '_' + i);
		if (child != null) {
			if (checked) {
				if (!child.checked) {
					child.click();
				}
			} else {
				if (child.checked) {
					child.click();
				}
			}
			i++;
		} else {
			return;
		}
	}
}

function checkAllFathers() {
	var i = 0;
	while (true) {
		var father = document.getElementById(i);
		if (father != null) {
			checkChildren(father);
			i++;
		} else {
			break;
		}
	}
}

function checkChildren(father) {
	var i = 0;

	while (true) {
		var child = document.getElementById('selectedAuthorities-' + father.id + '_' + i);
		if (child != null) {
			if (child.checked) {
				child.click();
				child.click();
				document.getElementById(child.id + 'li').className = 'yes';
			}
			i++;
		} else {
			break;
		}
	}
}

function checkFatherSelection(id) {
	var fatherIdStartIndex = id.indexOf('-') + 1;
	var fatherIdEndIndex = id.indexOf('_');
	var fatherId = id.substring(fatherIdStartIndex, fatherIdEndIndex);
	
	var father = document.getElementById(fatherId);
	checkFather(father);
}

function checkFather(father) {
	var allChecked = true;
	var i = 0;

	while (true) {
		var child = document.getElementById('selectedAuthorities-' + father.id + '_' + i);
		if (child != null) {
			if (!child.checked) {
				allChecked = false;
				break;
			}
			i++;
		} else {
			break;
		}
	}
	
	father.checked = allChecked;
}

function muestraOculta(div1) {
	var o1 = document.getElementById(div1);
	if (o1 != null) {
		if (o1.style.display == 'none') {
			o1.style.display = 'block';
		} else {
			o1.style.display = 'none';
		}
	}
}

function showSelect() {
	var e = document.getElementsByTagName('select');
	for (i = 0; i < e.length; i++) {
		e[i].style.visibility = 'visible';
	}
}
function hideSelect(selectID) {
	var e = document.getElementsByTagName('select');
	for (i = 0; i < e.length; i++) {
		e[i].style.visibility = 'hidden';
	}
	//en caso de que el div pop-up contenga un select.
	if (document.getElementById(selectID) != null){
		document.getElementById(selectID).style.visibility = 'visible';
	}
}

//-----------------Nueva Funcion para desplegar el div transparente al alto del contenido -----------------//
function modifDiv() {
	var obj = document.getElementById('transparentDiv').style;
	if (obj.display == 'none')
		showSelect();
	else
		obj.height = document.getElementById('divMain').offsetHeight + 10 + 'px';
}
function displayTransparentDiv(transparentDivId, loadingDivId) {
	var transparentDiv = document.getElementById(transparentDivId);
	transparentDiv.style.display = "block";
	modifDiv();
	
	if (loadingDivId) {
		var loadingDiv = document.getElementById(loadingDivId);
		var verticalScroll = self.pageYOffset ? self.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body ? document.body.scrollTop : null;
		loadingDiv.style.top = 200 + verticalScroll + "px";		
		loadingDiv.style.display = "block";
	}
}
function displayActionPopupDiv(actionPopupDivId) {
	var actionPopupDiv = document.getElementById(actionPopupDivId);
	centerElement(actionPopupDiv);
	actionPopupDiv.style.display = "block";	
}
function displayLoadingPopupDiv(actionPopupDivId, loadingPopupDivId) {
	var loadingPopup =  document.getElementById(loadingPopupDivId);
	var actionPopup = document.getElementById(actionPopupDivId);
	
	var height = (actionPopup.getHeight() - 4).toString();
	var width = (actionPopup.getWidth() - 7).toString();
	var marginLeft = (-(width / 2) + 2).toString();
	
	loadingPopup.style.height = height + 'px';
	loadingPopup.style.width = width + 'px';
	loadingPopup.style.marginLeft = marginLeft + 'px';
	loadingPopup.style.display = 'block';	
}
//-----------------Nueva Funcion para ubicar al div del popup al top de donde se cliquea -----------------//
function displayPop(div, div2) {
	displayTransparentDiv(div2);
	displayActionPopupDiv(div);
}
//--------------------------//
function displayblockp(name) {
	var e = document.getElementsByName(name);
	for (i = 0; i < e.length; i++) {
		e[i].style.display = 'block';
	}
}
function hideblockp(name) {
	var e = document.getElementsByName(name);
	for (i = 0; i < e.length; i++) {
		e[i].style.display = 'none';
	}
}
//---------------Para mostrar u ocultar los errores de los formularios----------//
function tooltip(id, help, error) {
	var e = document.getElementsByTagName('samp');
	var f = document.getElementsByTagName('code');
	for (i = 0; i < e.length; i++) {
		e[i].style.display = "none";
	}
	for (j = 0; j < f.length; j++) {
		f[j].style.display = "none";
	}
	if (document.getElementById(id).className == 'errorlabel') {
		document.getElementById(error).style.display = "inline";
	} else {//en caso de que el id que estemos validando no tenga samp la siguiente linea lo condiciona.
		if (document.getElementById(help) != null) {
			document.getElementById(help).style.display = "block";
		}
	}
}

//------- Funcion para mostrar/ocultar los filtros ----------------//
function collapseExpandFilters(elem, div) {
	if (elem.className == "") {
		elem.className="off";
		document.getElementById(div).style.display = "none";
	} else {
		elem.className="";
		document.getElementById(div).style.display = "block";
	}
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof (window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function centerElement(element) {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentElement = element;
			var contentHeight = contentElement.offsetHeight;
			contentElement.style.position = 'absolute';
			if (windowHeight - contentHeight > 0) {
				contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
			}
		}
	}
}

function muestra(div1, div2){
        var o1 = document.getElementById(div1);
        var o2 = document.getElementById(div2);
        if (o1.style.display == 'none'){
	          o1.style.display = '';
              o2.className='arrow on';
	    } else {
              o1.style.display = 'none';
              o2.className = 'arrow off';
        }
}

function closeOrRedirect(url){
    if (window.opener == null){
        window.location=url;
    }
    else {
        window.close();
    }
}
