///////////////////////////////////////////////////////////
//// JUMP MENU ////////////////////////////////////////////
///////////////////////////////////////////////////////////
function jumpMenu(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
///////////////////////////////////////////////////////////
// POP-UP /////////////////////////////////////////////////
///////////////////////////////////////////////////////////
function popup(page,name,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=1,resizable=no';
	window.open(page,name,settings);
}
///////////////////////////////////////////////////////////
// MOSTRA-ESCONDE /////////////////////////////////////////
///////////////////////////////////////////////////////////
function toggleLayer(layer){
	if(document.getElementById(layer).style.display == "none"){
		document.getElementById(layer).style.display = "";
	}else{
		document.getElementById(layer).style.display = "none";
	}
}
function showLayer(layer){
	if(document.getElementById(layer).style.display == "none"){
		document.getElementById(layer).style.display = "";
	}
}
function hideLayer(layer){
	if(document.getElementById(layer).style.display == ""){
		document.getElementById(layer).style.display = "none";
	}
}
///////////////////////////////////////////////////////////
// SWAP-IMAGES ////////////////////////////////////////////
///////////////////////////////////////////////////////////
function swapImage(control,image){
	document.getElementById(control.id).src = image;
}

///////////////////////////////////////////////////////////
// TEXT LIMIT /////////////////////////////////////////////
///////////////////////////////////////////////////////////

function textLimit(field, maxlen, LimitController) {
	// verifica
	if(field.value.length > maxlen + 1){
		alert('Limite de caracteres ultrapassado!');
	}
	if(field.value.length > maxlen){
		field.value = field.value.substring(0, maxlen);
	}
	// imprime limite
	LimitControllerHtml = field.value.length+" / "+maxlen;
	document.getElementById(LimitController).innerHTML = LimitControllerHtml;

}

///////////////////////////////////////////////////////////
// FORMATA DATA ///////////////////////////////////////////
///////////////////////////////////////////////////////////
function FormataData(campo, event){
	var posNumeros = "01346789";
	var posEspacos = "25";
	var strNumeros = '0123456789';

	if ((event.keyCode == 8) || (event.keyCode == 46))
		return false;

	for (i = 0; i < campo.value.length; i++)
		if ((posNumeros.indexOf(i) != -1) && (strNumeros.indexOf(campo.value.substr(i, 1)) == -1)) {
			campo.value = campo.value.substr(0, i);
			return false;
		} else if ((posEspacos.indexOf(i) != -1) && (campo.value.substr(i, 1) != '/')) {
			campo.value = campo.value.substr(0, i);
			return false;
	}

	if (campo.value.length > 10)
		campo.value = campo.value.substr(0, 10);

	if ((campo.value.length == 2) || (campo.value.length == 5))
		campo.value = campo.value + "/";
}
///////////////////////////////////////////////////////////
// FORMATA CEP ////////////////////////////////////////////
///////////////////////////////////////////////////////////
function mask(obj, mascara) {
	var campo = obj.value.length;
	var saida = mascara.substring(0,1);
	var texto = mascara.substring(campo);
	if(texto.substring(0,1) != saida) {
		obj.value += texto.substring(0,1);
	}
}

///////////////////////////////////////////////////////////
// LINK ID ////////////////////////////////////////////////
///////////////////////////////////////////////////////////
function getLinkID() {
	var loc = location.hash;
	loc = loc.replace ("#", "");
	//alert("LinkID: "+loc);
	if (loc) {
		return loc;
	} else {
		return "";
	}
}
function setLinkID(strID) {
	window.location.hash = strID;
}
///////////////////////////////////////////////////////////
