
	var URL_RELATIVE = "/";

	function addOption(object,text,value,selected) {
		var defaultSelected = false;
		var optionName = new Option(text, value, defaultSelected, selected)

		object.options[object.length] = optionName;
	}
	
	function ajaxNoAction(){
	}

	function changeComboBoxValue(formulario, arrDdoFlh, cboDdoPai, cboDdoFlh, txtDdoPai){
		varDdoPai = cboDdoPai.options[cboDdoPai.selectedIndex].value;

		if(varDdoPai==""){
			cboDdoFlh.length=0;
			return 0;
		}

		for(k=0;k<arrDdoFlh.length;k++){
			if(arrDdoFlh[k][0]==varDdoPai){
				numDdoPai = k;
				tamanho = arrDdoFlh[k][1].length + 1;
				break;
			}
		}	

		cboDdoFlh.length = tamanho;

		numDdoFlh = 0;
		selectedItem = false;

		for (contador=1;contador<tamanho;contador++) {
			cboDdoFlh.options[contador]=new Option(arrDdoFlh[numDdoPai][1][numDdoFlh][1], arrDdoFlh[numDdoPai][1][numDdoFlh][0]);

			if(parseInt(arrDdoFlh[numDdoPai][1][numDdoFlh][0])==parseInt(txtDdoPai.value)){
				cboDdoFlh.options[contador].selected=true;
				selectedItem = true;
			}
			else{
				if(!selectedItem)
					cboDdoFlh.selectedIndex=0;
			}

			numDdoFlh++;
		}
	}

	function charToHex(i) {
		if (i == 0) {
			hexChar = '0' }
		else { if (i == 1) {
			hexChar = '1'}
		else { if (i == 2) {
			hexChar = '2'}
		else { if (i == 3) {
			hexChar = '3' }
		else { if (i == 4) {
			hexChar = '4'}
		else { if (i == 5) {
			hexChar = '5' }
		else { if (i == 6) {
			hexChar = '6'}
		else { if (i == 7) {
			hexChar = '7' }
		else { if (i == 8) {
			hexChar = '8'}
		else { if (i == 9) {
			hexChar = '9'}
		else { if (i ==10) {
			hexChar = 'a'}
		else { if (i ==11) {
			hexChar = 'b'}
		else { if (i ==12) {
			hexChar = 'c'}
		else { if (i ==13) {
			hexChar = 'd'}
		else { if (i ==14) {
			hexChar = 'e'}
		else { if (i ==15) {
			hexChar = 'f'}
		} } } } } } } } } } } } } } }
		return hexChar;
	}
	
	function confirmDeleteTableRecord(formulario, varPmsPqsCdg){
		if(parseInt(document.forms[formulario].txtCpoPkyItmChk.value) > 0){
			varConf = window.confirm('Confirma a exclusão?');
	
			if(varConf==true){
				document.forms[formulario].action = "Global.asp?txtOprTblBdd=delete&txtPmsPqsCdg=" + varPmsPqsCdg;
				document.forms[formulario].submit();
			}
		}
		else
			window.alert("Você não selecionou nenhum item!");
	}

	/* Codigo comum em todas as paginas que utilizam a funcao printGridMasterDetail */
	function countElement(formulario, booleano){
		if(booleano)
			document.forms[formulario].txtCpoPkyItmChk.value++;
		else
			document.forms[formulario].txtCpoPkyItmChk.value--;
	}

	function deleteFile(fileFolder, fileBox, fileBoxAux, fileLabel, openerWindow){
		if(fileBox.type=="select")
		{
			if(fileBox.selectedIndex > 0){
				if(window.confirm("ATENÇÃO: Você excluirá o arquivo '" + fileBox[fileBox.selectedIndex].text + "'! Para EXCLUIR, clique OK."))
					window.open(URL_RELATIVE + "/HTMLEditor/ImageFile/FileDelete.aspx?fileFolder=" + fileFolder + "&fileName=" + fileBox[fileBox.selectedIndex].value + "&fileBox=" + fileBox.name, "", "width=20,height=20");
			}else{
				window.alert("Escolha um arquivo antes de excluir!");
			}
		}
		else
		{
			if(window.confirm("ATENÇÃO: Você excluirá o arquivo '" + fileBox.value + "'! Para EXCLUIR, clique OK."))
				window.open(URL_RELATIVE + "/HTMLEditor/ImageFile/FileDelete.aspx?fileFolder=" + fileFolder + "&fileName=" + fileBox.value + "&fileBox=" + fileBox.name + "&fileBoxAux=" + fileBoxAux + "&fileLabel=" + fileLabel + "&openerWindow=" + openerWindow, "", "width=20,height=20");
		}
	}

	function deleteOption(object,index) {
		object.options[index] = null;
	}
	
    function getScrollXY() {
        var scrOfX = 0, scrOfY = 0;

        if( typeof( window.pageYOffset ) == 'number' ) {
            //Netscape compliant
            scrOfY = window.pageYOffset;
            scrOfX = window.pageXOffset;
        } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
            //DOM compliant
            scrOfY = document.body.scrollTop;
            scrOfX = document.body.scrollLeft;
        } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
            //IE6 standards compliant mode
            scrOfY = document.documentElement.scrollTop;
            scrOfX = document.documentElement.scrollLeft;
        }
        return [ scrOfX, scrOfY ];
    }

	function hexQuotient(i) {
		return Math.floor(eval(i +'/ 16'));
	}
	
	/* Codigo comum a todas as paginas de cadastro */
	function insertNewTableRecord(formulario, varPmsPqsCdg){
		document.forms[formulario].action="ViewFrame.asp?txtOprTblBdd=view&txtPmsPqsCdg=" + varPmsPqsCdg;
		document.forms[formulario].method="post";
		document.forms[formulario].target="_parent";
		document.forms[formulario].txtOprTblBdd.value="view";
		document.forms[formulario].txtCpoPky.value="";
		document.forms[formulario].submit();
	}

	function jumpToAnchor( anchor ) {
		if(anchor=="")
			return false;

		// make the location a string
		URLString = document.location+"";
		
		/* make sure there is not already an anchor, if there is strip it out
		and reformat the URL */
		if ( URLString.indexOf( "#" ) < 0 ) {
			document.location = document.URL + "#" + anchor;
		}
		else {
			URLString = URLString.substring( 0, URLString.indexOf( "#" ) );
			document.location = URLString + "#" + anchor;
		}
	}

	var objXMLDoc;
		
	function loadXML(url, sendHow, sendThis, doThis) {
		objXMLDoc = null;
		
		if (typeof window.ActiveXObject != 'undefined' ) {
			objXMLDoc = new ActiveXObject("Microsoft.XMLHTTP");
			objXMLDoc.onreadystatechange = function(){if ( objXMLDoc.readyState != 4 ) return ; doThis();};
		}
		else {
			objXMLDoc = new XMLHttpRequest();
			objXMLDoc.onload = function(){if ( objXMLDoc.readyState != 4 ) return ; doThis();};
		}

		objXMLDoc.open( sendHow, url, true );

		if(sendHow=='POST'){
			objXMLDoc.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
		}

		objXMLDoc.send( sendThis );
	}
		
	function modifyTableRecord(formulario, varPmsPqsCdg, varTblBdd, varCpsPky, varCpoPky, varCpoPqsVlr, varCpoPqsDsc){
		document.forms[formulario].action="ViewFrame.asp?txtOprTblBdd=view&txtPmsPqsCdg=" + varPmsPqsCdg + "&txtTblBdd=" + varTblBdd + "&txtCpsPky=" + varCpsPky + "&txtCpoPky=" + varCpoPky + "&txtCpoPqsVlr=" + varCpoPqsVlr + "&cboCpoPqsDsc=" + varCpoPqsDsc;
		document.forms[formulario].target="_parent";
		document.forms[formulario].submit();
	}

	function newOption(inText,inValue){
		// Create element in this frame's tree
		var myOpt = new Option(inText,inValue,false,false)

		// return reference
		return myOpt
	}

	function SetupUserControl(varContainer, varUserControl)
	{
		var numInnerWidth = 0, numInnerHeight = 0;

		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			numInnerWidth = window.innerWidth;
			numInnerHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			numInnerWidth = document.documentElement.clientWidth;
			numInnerHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			numInnerWidth = document.body.clientWidth;
			numInnerHeight = document.body.clientHeight;
		}

		try 
		{ 
			document.getElementById(varContainer).style.width = numInnerWidth + 'px';
			document.getElementById(varContainer).style.height = numInnerHeight + 'px';

			if(document.all)
			{
				document.getElementById(varUserControl).className = 'cssModalPopupIE';
			}
			else
			{
				document.getElementById(varUserControl).className='cssModalPopupMozilla';
			} 
		} 
		catch(e)
		{
		}
	}
	
	function saveAllRecords(formulario, CpoPkyQtd, varPmsPqsCdg){
		numCpoPkyItm= 1;
		numCpoPkyItmMax = parseInt(document.forms[formulario].txtCpoPkyItmTtl.value)*5;

		while(numCpoPkyItm< numCpoPkyItmMax){
			varErro=false;
		
			if(!varErro && removeBlankSpace(document.forms[formulario].elements[numCpoPkyItm].value)==0){
				varErro=true;
				window.alert("Preencha o campo 'Descripción'!");	
				document.forms[formulario].elements[numCpoPkyItm].focus();
			}
			
			if(!varErro){
				numCpoPkyItm= numCpoPkyItm+ 4;
			}
			else{
				numCpoPkyItm= numCpoPkyItmMax;
			}
		}

		if(!varErro){
			document.forms[formulario].action="Global.asp?txtOprTblBdd=update_all&txtCpoPkyQtd=" + CpoPkyQtd + "&txtPmsPqsCdg=" + varPmsPqsCdg;
			document.forms[formulario].submit();
		}
	}

	function showDialog(url, rE_02, width, rEO7l){
		//var rES7O = document.body.style.cursor;
	
		//document.body.style.cursor = "wait";
	
		var rET90 = window.open(url, rE_02, "status=no, center=yes, help=no, minimize=no, maximize=no, scroll=no, border=thin, statusbar=no, Width=" + width + "px, Height=" + rEO7l + "px");
		
		//document.body.style.cursor = rES7O;
		
		//return rET90;
	}

	function showToolTip(strTitle, strText){
		// ddrivetip('TEXT TO DISPLAY', 'OPTIONAL BACKGROUND COLOR', OPTIONAL TIP WIDTH)
		ddrivetip("<iframe src='ToolTip.asp?ToolTipTitle=" + strTitle + "&ToolTipText=" + strText + "' scrolling=No frameborder=0 class=cssToolTipBox></iframe>", '', 200);
	}

	function sortOptions(what) {
		var copyOption = new Array();

		for (var i=1;i<what.options.length;i++)
			copyOption[i-1] = new Array(what[i].text.toLowerCase(), what[i].text, what[i].value, (what.selectedIndex==i));
		
		copyOption.sort();

		for (var i=what.options.length-1;i>0;i--)
			deleteOption(what,i);
		
		for (var i=0;i<copyOption.length;i++)
			addOption(what,copyOption[i][1],copyOption[i][2],copyOption[i][3]);
	}

	function toHex(i) {
		runningTotal = ''
		quotient = hexQuotient(i);
		remainder = eval(i + '-(' + quotient + '* 16)')
		runningTotal = charToHex(remainder) + runningTotal;
		while( quotient >= 16) {
			savedQuotient = hexQuotient(quotient);
			remainder = eval(quotient + '-(' + savedQuotient + '* 16)');
			runningTotal = charToHex(remainder) + runningTotal;
			quotient = savedQuotient;
		} 
		return charToHex(quotient) + runningTotal ;
	}

	function unsetChildGroup(blnCtdPsaGpoCck, numCtdPsaGpoCdg){
		if(blnCtdPsaGpoCck)
		{
			blnFoundFirst = false;

			for(i=0;i < document.forms[0].elements.length;i++)
			{
				if(document.forms[0].elements[i].id.indexOf("chkUserGroupParent" + numCtdPsaGpoCdg + "Child")!= -1)
				{	
					blnFoundFirst = true;
					document.forms[0].elements[i].checked=false; 
				}
				else if(blnFoundFirst)
						break;
			}
		}
	}

	function unsetParentGroup(blnCtdPsaGpoCck, numCtdPsaGpoCdg){
		if(blnCtdPsaGpoCck)
		{
			var objParent = document.getElementById('chkUserGroupParent' + numCtdPsaGpoCdg);
			
			if(objParent!=null)
				objParent.checked = false;
		}
	}

	function uploadFile(saveIn, fileBox, fileBoxAux, fileLabel, openerWindow){
		var rET90 = showDialog(URL_RELATIVE + "/HTMLEditor/ImageFile/FileUpload.aspx?saveIn=" + saveIn + "&fileBox=" + fileBox + "&fileBoxAux=" + fileBoxAux + "&fileLabel=" + fileLabel + "&openerWindow=" + openerWindow, null, 674, 310);
	}

	function ScrollAjaxWait() {
	    try {
	        var arrScroll = new Array(2);
	        arrScroll = getScrollXY();
	        document.getElementById('myDialog').style.top = arrScroll[1] + "px";
	    }
	    catch(e) {
	    }
	}

    function SetFieldFocus(strFieldName)
    {
        try
        {
           //setTimeout("document.getElementById('" + strFieldName + "').select(); document.getElementById('" + strFieldName + "').focus();", 0);
           setTimeout("document.getElementById('" + strFieldName + "').focus();", 1);
        }
        catch(e)
        {
        }
    }
