function doOrder (i)
{
	XSLSort = document.XSLDocument.documentElement.selectNodes("//xsl:sort");
 
	if (XSLSort[0].attributes(0).text == i.toString())
	{
		if ( XSLSort[0].attributes(1).text == "ascending")
		{
			XSLSort[0].attributes(1).text = "descending";
		}
		else
		{
			XSLSort[0].attributes(1).text = "ascending";
		}
	}
	else
	{
		XSLSort[0].attributes(1).text = "ascending";
	}

	XSLSort[0].attributes(0).text = i.toString();

	document.body.innerHTML =  document.XMLDocument.transformNode(document.XSLDocument);
}

function openFlag (o)
{
	j = document.getElementById('h').getElementsByTagName("div");

	for (var i = 0; i < j.length; i++)
	{
		if (document.getElementById('c'+j[i].id)) document.getElementById('c'+j[i].id).style.display = 'none';

		j[i].style.top = '0px';
		j[i].style.left = '0px';
		j[i].style.zIndex = '1';
		j[i].style.height = '18px';

		if (o == j[i].id)
		{
			if (document.getElementById('c'+j[i].id)) document.getElementById('c'+j[i].id).style.display = 'inline';

			j[i].style.top = '1px';
			j[i].style.zIndex = '2';
			j[i].style.height = '28px';
		}

		if (j[i].id >= o) j[i].style.left = '-1px';
	}
}

function openMenu (o)
{
	j = document.getElementById('menu').getElementsByTagName("div");

	for (var i = 0; i < j.length; i++)
	{
		if (document.getElementById('c'+j[i].id)) document.getElementById('c'+j[i].id).style.display = 'none';
	}

	document.getElementById('c'+o).style.display = 'block';
}

function selectRecord (o)
{
	if (o.style.backgroundColor == '#f8f6ec') o.style.backgroundColor = '#ffffff';
	else
	{
		o.style.backgroundColor = '#f8f6ec';
	}
}

function today (i)
{
	y = new Date();

	m = y.getMonth() + 1;

	i.value = y.getFullYear() + '-' + m + '-' + y.getDate();
}

function showCalendar (id, y, m)
{
	w = 0;
	d = 1;

	var cal;

	cal = '<table border="1" bordercolor="#e6e6dd" cellpadding="4" cellspacing="0" style="font-size:9px;border-collapse:collapse;cursor:pointer;">';
	cal += '<tr align="center" style="font-size:9px">';
	cal += '<td width="20">D</td>';
	cal += '<td width="20">S</td>';
	cal += '<td width="20">T</td>';
	cal += '<td width="20">Q</td>';
	cal += '<td width="20">Q</td>';
	cal += '<td width="20">S</td>';
	cal += '<td width="20">S</td>';
	cal += '</tr>';

	for (i=0; i<6; i++)
	{
		cal += '<tr align="center">';

		for (j=0; j<7; j++)
		{
			x = new Date (y, m-1, w+1);

			if ((d > x.getUTCDay()) && (m-1 == x.getMonth()))
			{
				w++;

				cal += '<td bgcolor="#ffffff" onclick="" class="">'+w+'</td>';
			}
			else
			{
				cal += '<td bgcolor="#ffffff" onclick="" class=""></td>';
			}

			d++;
		}

		cal += '</tr>';
	}

	cal += '</table>';

	document.getElementById(id).innerHTML =  cal;
}

function formatar (src, mask) 
{
	// Tirando caracteres especiais da formatacao

	var char = src.value.substring(src.value.length-1, src.value.length);

	if ((char == ".") || (char == ",") || (char == "/") || (char == "-")) src.value = src.value.substring(0, src.value.length-1);


	// Fazendo a formatacao

	var max = mask.length + 1;

	var i = src.value.length;

	if (max > i)
	{
		var saida = mask.substring(0,1);

		var texto = mask.substring(i)

		if (texto.substring(0,1) != saida) 
		{
			src.value += texto.substring(0,1);
		}
	}
	else
	{
		src.value = src.value.substring(0, max-1);
	}
}

function VerificaCPF (i)
{
	i = i.replace(".", "");
	i = i.replace(".", "");
	i = i.replace(".", "");
	i = i.replace("-", "");

	if (vercpf(i)) return true;
	else 
	{
		alert('CPF inválido, preencha um CPF correto e tente novamente.');

		return false;
	}
}

function vercpf (cpf) 
{if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
return false;
add = 0;
for (i=0; i < 9; i ++)
add += parseInt(cpf.charAt(i)) * (10 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(9)))
return false;
add = 0;
for (i = 0; i < 10; i ++)
add += parseInt(cpf.charAt(i)) * (11 - i);
rev = 11 - (add % 11);
if (rev == 10 || rev == 11)
rev = 0;
if (rev != parseInt(cpf.charAt(10)))
return false;
return true;}