var ie = (navigator.appName.indexOf("Microsoft")!=-1);
var ns = (navigator.appName.indexOf("Netscape")!=-1);

function LimpaForm(FormName){
	var i;
	var Form = eval(FormName);
	
	for(i = 0;i < Form.length; i++)
		if( Form[i].type == "text" || Form[i].type == "textarea" || Form[i].type == "password" )
			Form[i].value = ""; 		
	
	return; 
}

function RequiredChange(a1, a2)
{
	var i, j;
	for(i = 0;i < aCampos.length;i++)
	{
		for(j = 0;j < a1.length;j++)
			if(aCampos[i][0] == a1[j])
				aCampos[i][1] = true;
			
		for(j = 0;j < a2.length;j++)
			if(aCampos[i][0] == a2[j])
				aCampos[i][1] = false;
	}
}

function ClassChange(tdreq, tdnreq)
{
	var obj1, obj2;
	
	obj1 = eval("document.getElementById('" + tdreq + "')");
	obj2 = eval("document.getElementById('" + tdnreq + "')");		
	
	obj1.style.fontWeight = 'bold';
	obj2.style.fontWeight = 'normal';
}

function getChk(wrk, frm){
	var chk="", tam;
	
	for(i=0; i< frm.length; i++)
	{
		if((frm[i].type == "checkbox") && (frm[i].name.substr(0, wrk.length) == wrk ))
		{
			if(frm[i].checked) {
				if(chk != "" )
					chk += "|";
				
				tmp = frm[i].name.substr(wrk.length, frm[i].name.length);
				if (tmp.length < 5){ 
					tam = (5-tmp.length);
					for(j=1; j<= tam;j++){ 
						tmp = "0" + tmp;
					}
				}
				chk += tmp
			}
		}
	}
	return chk;		
}

function getHidden(wrk, frm){
	var hd="", tam;
	
	for(i=0; i< frm.length; i++)
	{
		if((frm[i].type == "hidden") && (frm[i].name.substr(0, wrk.length) == wrk ))
		{
			if(frm[i].value != '') {
				if(hd != "" )
					hd += "|";
								
				tmp = frm[i].value;
				if (tmp.length < 5){ 
					tam = (5-tmp.length);
					for(j=1; j<= tam;j++){ 
						tmp = "0" + tmp;
					}
				}
				hd += tmp
			}
		}
	}
	return hd;		
}

function getTxt(wrk, frm){
	var txt="", tam;
	
	for(i=0; i< frm.length; i++)
	{
		if((frm[i].type == "text") && (frm[i].name.substr(0, wrk.length) == wrk))
		{
			if(!frm[i].disabled) {
				if(txt != "" )
					txt += "|";
				
				if(frm[i].value < 0 || frm[i].value == "" || !ValidateNumber(frm[i].value))
					return -1;
				txt += frm[i].value;
			}
		}
	}
	return txt;		
}

function getTxtStr(wrk, frm){
	var txt="", tam;
	
	for(i=0; i< frm.length; i++)
	{
		if((frm[i].type == "text") && (frm[i].name.substr(0, wrk.length) == wrk))
		{
			if(!frm[i].disabled) {
				if(txt != "" )
					txt += "|";
				
				if(frm[i].value == "")
					txt += " ";
				else
					txt += frm[i].value;	
			}
		}
	}
	return txt;		
}

function getCmb(wrk, frm){
	var cmb="", tam;
		
	for(i=0; i< frm.length; i++)
	{
		if((frm[i].type == "select-one") && (frm[i].name.substr(0, wrk.length) == wrk))
		{
			if(!frm[i].disabled) {
				if(cmb != "" )
					cmb += "|";
							
				cmb += frm[i].value;
			}
		}
	}
	return cmb;		
}

function CharCount(frm, obj, cont){

	if(obj != null){
		var objCount = eval(frm + ".c" + obj.name);
	
		if(obj.value.length <= cont){
			objCount.value = cont - obj.value.length;
		}
		else {
			obj.value = obj.value.substr(0,cont);
			objCount.value = 0;
		}
	}
}

function cleanQuote(FormName){
	var i;
	var Form = eval(FormName);
	for(i = 0;i < Form.length; i++)
	{
		if(Form[i].type == "text") 
		{	
			Form[i].value = stripQuote(Form[i].value); 
		}
	}
	return ; 
}

function stripQuote(s) {
var tmp = s;
	while (tmp.indexOf("'") > -1) tmp = tmp.replace("'", "");
	return tmp;
}

function fecharJanela(){
	if(window.parent.document.getElementById('tdframemain') != null)
		window.parent.document.getElementById("tdframemain").innerHTML = "<table width=720 align=center cellpadding=0 cellspacing=0 border=0><tr><td></td></tr></table>";  
	else
		window.close();
}

function extractWindow(url, nome){
	config = "resizable=yes,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes, titlebar=no";	
	var win = window.open(url, nome, config);	
	var altura = (document.body.scrollHeight > (screen.availHeight-100))?(screen.availHeight-100):(document.body.scrollHeight+60);
	
	win.resizeTo(840, parseInt(altura));
	win.moveTo(100,100); 
		
	if(window.parent.document.getElementById('tdframemain') != null)
		window.parent.document.getElementById('tdframemain').innerHTML = "&nbsp;";
}

function resizeframe(){
	if(window.parent.document.getElementById('tdframemain') != null){
		
		window.parent.document.getElementById('tdframemain').height = (ie)?(document.body.scrollHeight + 13):(document.body.offsetHeight + 13);
		
		/*if(ie)
			window.parent.document.getElementById('tdframemain').height = document.body.scrollHeight + 13;
		else
			window.parent.document.getElementById('tdframemain').height = document.body.offsetHeight + 13;*/
	}
}

function Localizador(pg){
	if(window.parent.document.getElementById('localizador') != null)
		window.parent.document.getElementById('localizador').innerHTML = pg;
}

