var ajax = getServer();

function getServer() {
	if ( window.XMLHttpRequest ) {
		return new XMLHttpRequest();
	} else if ( window.ActiveXObject ) {
		return new window.ActiveXObject( "Microsoft.XMLHTTP" );
	}
}

function getFile( str_url ) {
	document.getElementById( "carregando" ).innerHTML = "Carregando...";
	document.getElementById( "conteudo" ).innerHTML = "";
	ajax.open( "GET", str_url, true );
	ajax.onreadystatechange = function() {
		if ( ajax.readyState == 4 ) {
			document.getElementById( "carregando" ).innerHTML = "";
			document.getElementById( "conteudo" ).innerHTML = ajax.responseText;
		}
	}

	ajax.send( null );
}

function makePOSTRequest( str_form_id, str_url ) {
	var obj_form = document.getElementById( str_form_id );
	var str_parameters = '';
	var str_separator  = '';
	for ( var int_count = 0; int_count < obj_form.elements.length; int_count++ ) {
		str_parameters += str_separator + obj_form.elements[int_count].name + '=' + escape( encodeURI( obj_form.elements[int_count].value ) );
		str_separator = '&'; 
	}
	
	ajax.open( "POST", str_url, true );
	ajax.onreadystatechange = function() {
		if ( ajax.readyState == 4 ) {
			document.getElementById( "carregando" ).innerHTML = "";
			document.getElementById( "conteudo" ).innerHTML = ajax.responseText;
		}
	}
	ajax.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
	ajax.setRequestHeader( "Content-length", str_parameters.length );
	ajax.setRequestHeader( "Connection", "close" );
	ajax.send( str_parameters );
}

function makePOSTRequest2( str_form_id, str_url, str_destination ) {
	document.getElementById( str_destination ).innerHTML = "Consultando...";
	var obj_form = document.getElementById( str_form_id );
	var str_parameters = '';
	var str_separator  = '';
	for ( var int_count = 0; int_count < obj_form.elements.length; int_count++ ) {
		str_parameters += str_separator + obj_form.elements[int_count].name + '=' + escape( encodeURI( obj_form.elements[int_count].value ) );
		str_separator = '&'; 
	}
	
	ajax.open( "POST", str_url, true );
	ajax.onreadystatechange = function() {
		if ( ajax.readyState == 4 ) {
			document.getElementById( str_destination ).innerHTML = ajax.responseText;
		}
	}
	ajax.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
	ajax.setRequestHeader( "Content-length", str_parameters.length );
	ajax.setRequestHeader( "Connection", "close" );
	ajax.send( str_parameters );
}

function jumpToField( obj_field, str_id_jump ) {
	if ( obj_field ) {
		var obj_jump = document.getElementById( str_id_jump );

		if ( obj_jump ) {
			if ( obj_field.tagName.toLowerCase() == 'input' ) {
				if ( obj_field.maxLength == obj_field.value.length ) {
					obj_jump.focus();
					return true;
				}
			} else if ( obj_field.tagName.toLowerCase() == 'select' ) {
				obj_jump.focus();
				return true;
			}
		}
	}

	return false;
}


function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
	var b_version = navigator.appVersion;

	if ( b_version.indexOf( 'MSIE 6' ) > -1 || b_version.indexOf( 'MSIE 5' ) > -1 ) {
		for(var i=0; i<document.images.length; i++)
		{
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText
				var imgAttribs = img.attributes;
				for (var j=0; j<imgAttribs.length; j++)
				{
					var imgAttrib = imgAttribs[j];
					if (imgAttrib.nodeName == "align")
					{
						if (imgAttrib.nodeValue == "left") imgStyle = "float:left;" + imgStyle
						if (imgAttrib.nodeValue == "right") imgStyle = "float:right;" + imgStyle
						break
					}
				}

				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				strNewHTML += "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}
}