/*
 * Go to another UF but don't change the accion
 */
function goToOtherUf(url){
  var formulario = document.formulario;
  formulario.method = "post";
  formulario.action = url;
  formulario.target = "_parent";
  formulario.submit();
}


var request = null;
function httpRequest(reqType,url,asynch,respHandle){
if(window.XMLHttpRequest){
	request = new XMLHttpRequest();
	if(reqType.toLowerCase() != "post") {
		initReq(reqType, url,asynch,respHandle);
	} else {
		var args = arguments[4];
		if(args != null && args.length > 0){
			initReq(reqType,url,asynch,respHandle,args);
		}
	}
} else if (window.ActiveXObject) {
	request=new ActiveXObject("Msxml2.XMLHTTP");
	if (! request){
		request=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(request){
		if(reqType.toLowerCase() != "post") {
			initReq(reqType,url,asynch,respHandle);
		} else {
			var args = arguments[4];
			if(args != null && args.length > 0){
				initReq(reqType,url,asynch,respHandle,args);
			}
		}
	} else {}
} else {}
}
function initReq(reqType,url,bool,respHandle){
try{
	request.onreadystatechange=respHandle;
	request.open(reqType,url,bool);
	if(reqType.toLowerCase() == "post") {
		request.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
		request.send(arguments[4]);
	} else {
		request.send(null);
	}
} catch (errv) {}}


function buildNib(name){
    var form = getFormulario();
    var nib = "";
    for (i = 1; i <= 4; ++i){
        var field = name + "Nib" + i;
        nib = nib + eval( "form['" + field + "']" ).value;
    }
    return nib;
}

function clearNib(name){
    var form = getFormulario();
    var nib = "";
    for (i = 1; i <= 4; ++i){
        var field = name + "Nib" + i;
        eval( "form['" + field + "']" ).value = "";
    }
}

function clearField(name){
    var form = getFormulario();
    eval( "form['" + name + "']" ).value = "";
}

function setFocus(id){
	if (id == null){
		return;
	}

	var element = document.getElementById(id);
    if (element != null) element.focus();
}

// Sets the initial focus on the header
function setInitialFocus(){
   var element = document.getElementById("home_path");  
    if (element != null) element.focus();
}




//** Calendar functions **
function openCalendar(num){
    initializeCalendar();

    var cal = eval("document.cal" + num);
    cal.popup();
}

function buildDate(name){
    var day = getObject(name + "Dia");
    var month = getObject(name + "Mes");
    var year = getObject(name + "Ano");

    if( day.value == "" && month.value == "" && year.value == ""){
        date = "";
    }
    else{
        date = day.value + "/" + month.value + "/" + year.value;
    }
    return date;
}


//* default submit button **
var button;
function KeyDownHandler() {if (event.keyCode == 13){if (button) {event.returnValue=false;event.cancel = true;button.click();}}}
function setButton(id) {button = document.getElementById(id)}

//* Image Rollover Functions **
function switchImage(imgName, imgSrc) {if (document.images) {if (imgSrc != "none"){document.images[imgName].src = imgSrc;}}}
function preloadImages(){if(document.images) {if(!document.imageArray) document.imageArray = new Array(); var i,j = document.imageArray.length, args = preloadImages.arguments; for(i=0; i<args.length; i++){if (args[i].indexOf("#")!=0){document.imageArray[j] = new Image;document.imageArray[j++].src = args[i];}}}}

//* Transaction Menu Functions **
function showMenu(option) {
	var opmenu = new Array("fav","pat","contas","trans","pag","car","cheq","cartoes","emp","dep","fundos","merc","alert","person");
	var menu; var sectn;
	menu = getObject('menu_' + option); sectn = getObject('sectn' + option);
	if(menu&&sectn) {if (sectn.className=='sctn') {hideAllOptions(opmenu);menu.style.display='block';sectn.className = 'sctnon';} else {hideAllOptions(opmenu);sectn.className = 'sctn';}}
}
function hideAllOptions(array) {
	var size = array.length; var menu; var sectn; var counter;
	for(counter=0; counter<=size; counter++){if(getObject('menu_' + array[counter])) {menu = getObject('menu_'+ array[counter]);sectn = getObject('sectn'+ array[counter]);if(menu){menu.style.display = 'none';}if(sectn){sectn.className = 'sctn';}}}
}

//* Miscellaneous Functions **
function printWindow() {if (document.all||document.getElementById) {window.print();}} //display print dialog

function messagebox(id) {
	var string;
	if (id==0) {string="Funcionalidade n⭠dispon쵥l."};
	if (id==1) {string="Funcionalidade de ordena袯 n⭠dispon쵥l."};
	alert(string)
} //to be erased
//gets refernece to an object with an id
function getObject(id) {
	if (document.all) {	if (document.all(id)) {return(document.all(id));}if (document.all('op_menu_' + id)) {return(document.all('op_menu_' + id));}}
	if (document.getElementById) {if (document.getElementById(id)) {return(document.getElementById(id));}if (document.getElementById('op_menu_' + id)) {return(document.getElementById('op_menu_' + id));}}
}
//performs de combo box selection navigation
function doSelect(id) {var combo; combo = getObject(id); var nav; nav = combo.options[combo.selectedIndex].value; if (nav) {location.href = nav;} else {messagebox(0);}}

//tests if any radio buttons are checked
function checkradio(rid){var iradio; iradio = getObject(rid); var opt; opt = -1; for (i=0; i<iradio.length; i++) {if (iradio[i].checked) {opt = i;}} if (opt == -1) {alert("Necessita seleccionar uma op袯 para efectuar uma opera袯");return false;} else return true;}

//performs de combo box selection navigation and tests if radio buttons are checked
function doSelectCheck(id,rid) {var combo; combo = getObject(id); var nav; nav = combo.options[combo.selectedIndex].value; if (nav) { if (checkradio(rid)) {location.href = nav;}} else {messagebox(0);}}

//performs swap class name
function swapClass(id,clsname){var obj; obj = getObject(id); if (obj) obj.className = clsname;}
//simulates submit - can delete after for final implementation
function doSubmit(url){if(url){document.forms[0].action=url; document.forms[0].submit();}}
//simulates submit and tests if radio buttons are checked - can delete after for final implementation
function doSubmitCheck(url,rid){if(url){if (checkradio(rid)) {document.forms[0].action=url; document.forms[0].submit();}}else {messagebox(0);}}
//displays or hides content (used for help)
function showHide(id){var obj; obj=getObject(id); if(obj) {if (obj.style.display!='block') {obj.style.display='block';} else {obj.style.display='none';}}}
// opens a default size pop-up but can recieve new window parameters
function popUpWindow(URLStr, windowSettings)
{
var popUpWin;
//0 = adicionar aos favoritos // else =  default
if (windowSettings==1){windowSettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=280,height=240,top=100,left=100,screenX=100,screenY=100'}
// consola pop ups
else if (windowSettings==2){windowSettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=665,height=625,top=100,left=100,screenX=100,screenY=100'}
else {windowSettings='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=440,height=320,top=100,left=100,screenX=100,screenY=100'}
  if(popUpWin) {if(!popUpWin.closed) popUpWin.close();}popUpWin = open(URLStr, 'popUpWin', windowSettings);
}
//function to activate and deactivate form buttons
function enableButtons(){var obj; for(i=0; i<arguments.length; i++) {obj = getObject(arguments[i]);if (obj) {obj.className='frmbtn';obj.disabled=false;}}}
function disableButtons(){var obj;	for(i=0; i<arguments.length; i++) {obj = getObject(arguments[i]);if (obj) {obj.className='frmbtn_off';obj.disabled=true;}}}

/* Initializes every JSP page out there */
function initialize()
{
	// TODO: This has to go, eventually
	//goSetHeight('ws');

	//Set initial Focus
	setInitialFocus();

	// Call the page's specific initialization function
	initializePage();
}

function initializePage()
{
	// By default this does nothing... This way we don't have to define the function in pages that don't need it.
}

function goHome(theURL)
{
	if( (theURL.indexOf("/indice/")>0) || (theURL.indexOf("/content/")>0) ) {
		
		actualURL = ""+parent.document.location;
		
	  siteParams="";
	  splitU = actualURL.split(",");
	  parametros12=splitU[2];
	  
	  splitParametros = parametros12.split("_");
	  
    i=1;
    if (actualURL.indexOf("content")>0) 
        i=2;

    while (i<splitParametros.length)
    {
    	
    		if (i == 2){
    			siteParams=siteParams+"_"+(splitParametros[i]-1);
    		}else{
        	siteParams=siteParams+"_"+splitParametros[i];
        }
        i++;
    }
		
		if (theURL.indexOf("content")>0) {
	  	return "/pagina/content/0,,625"+siteParams+",00.html";       
		} else {
	  	return "/pagina/indice/0,,625"+siteParams+",00.html";
		}
  }
  return theURL;
}


function switchPortal(url, portal){
	if( (url.indexOf("/indice/")>0) || (url.indexOf("/content/")>0) ) {          		
		var urlBefore = url.substring(0, url.indexOf("_1_")+3);
		var urlLater = url.substring(url.indexOf("_1_")+4);
		url = urlBefore+portal+urlLater;	
	}
	return url;
}