function CreateSelectOption(sWindowName, sFormName, sValue, sText, sClass) {
	var NewOption = eval(sWindowName).document.createElement('option');
	
	NewOption.value = sValue;
	NewOption.text = sText;
	NewOption.defaultSelected = false;
	NewOption.selected = true;
	NewOption.className = sClass;
	
	eval(sWindowName).eval(sFormName).add(NewOption);
}

function Popup(File, WinName, WinWidth, WinHeight) {
	window.open(File, WinName, 'width=' + WinWidth + ',height=' + WinHeight + ',menubar=no,resizable=no,toolbar=no,status=no,scrollbars=no');
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function ExpandCollapseCustom(ObjMenu, ObjImage) {
	if (ObjMenu.style.display == "none") {
       ObjMenu.style.display = "";
	   ObjImage.src = "/Imagens/icon_minus.gif"
	}
	else {
		ObjMenu.style.display = "none";
	   ObjImage.src = "/Imagens/icon_plus.gif"
	}
	
}

function ExpandCollapse(Obj) {
	if (Obj.style.display == "none") {
       Obj.style.display = "";
	}
	else {
		Obj.style.display = "none";
	}
}

function ChangeSRC(Obj, Image) {
	Obj.src = Image;
}


//==============================================================================
//== Função AJAX
//== Autor: Tiago Carvalho | Criação: 10/2007
//==============================================================================
var NomeCampo //variável global que recebe o nome do campo que receberá os dados

function handleHttpResponse()
{
	if (http.readyState == 4) 
	{
		document.getElementById(NomeCampo).options.length = 0;
		results = http.responseText.split(";");
		for( i = 0; i < results.length-1; i++ )
		{
			string = results[i].split( "|" );
			document.getElementById(NomeCampo).options[i] = new Option( string[0] , string[1] );
		}
	}
}

function getHTTPObject() 
{
	var xmlhttp;
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') 
	{
		try 
		{
			xmlhttp = new XMLHttpRequest();
		} 
		catch (e) 
		{
			xmlhttp = false;
		}
	}
	return xmlhttp;
}

var http = getHTTPObject();

//==============================================================================
//== Função Carrega um combo com os fornecedores via Ajax
//== Autor: Julio Rovesta | Criação: 03/2009
//==============================================================================
function carregaFornecedores()
{	
	NomeCampo = 'Fornecedor';	
	if (document.getElementById(NomeCampo).options.length < 3)
	{				
		document.getElementById(NomeCampo).options[0] = new Option( "Aguarde, Carregando..." , "");
		document.getElementById(NomeCampo).options[0].selected = true;
		http.open("GET", "/Modulos/Geral/GetFornecedoresAjax.asp", true);	
		http.onreadystatechange = handleHttpResponse;
		http.send(null);
	}
}
