function fileQueued(fileObj) {
	try {
		this.addFileParam(fileObj.id, "file_id", fileObj.id);
		/*
		var progress = new FileProgress(fileObj, this.getSetting("upload_target"));
		progress.SetStatus("Uploading...");
		progress.ToggleCancel(true, this);
		*/

	} catch (ex) { this.debugMessage(ex); }

}

function fileProgress(fileObj, bytesLoaded) {
	try {
		var percent = Math.ceil((bytesLoaded / fileObj.size) * 100)

		var progress = new FileProgress(fileObj,  this.getSetting("upload_target"));
		progress.SetProgress(percent);
		if (percent === 100) {
			progress.SetStatus("Criando thumbnail...");
			progress.ToggleCancel(false, this);
		} else {
			progress.SetStatus("Subindo arquivo... "+ percent +"%");
			progress.ToggleCancel(true, this);
		}
	} catch (ex) { this.debugMessage(ex); }
}

function fileComplete(fileObj, server_data) {
	try {
		var progress = new FileProgress(fileObj,  this.getSetting("upload_target"));
		progress.SetComplete();
		progress.SetStatus("Imagem enviada.");
		progress.ToggleCancel(false);
		document.getElementById("hdfConvidadoFoto").value = server_data;
	} catch (ex) { this.debugMessage(ex); }
}


function fileCancelled(fileObj) {
	try {
		var progress = new FileProgress(fileObj,  this.getSetting("upload_target"));
		progress.SetCancelled();
		progress.SetStatus("Cancelado");
		progress.ToggleCancel(false);
	}
	catch (ex) { this.debugMessage(ex); }
}

function queueComplete() {
	try {
        var progress = new FileProgress({ name: "Concluido." },  this.getSetting("upload_target"));
        progress.SetComplete();
        progress.SetStatus("Todas as imagens foram processadas.");
        progress.ToggleCancel(false);
    } catch (ex) { this.debugMessage(ex); }
}

function uploadError(error_code, fileObj, message) {
	try {
		var error_name = "";
		switch(error_code) {
			case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE:
				error_name = "Arquivo vazio";
			break;
			case SWFUpload.ERROR_CODE_UPLOAD_LIMIT_EXCEEDED:
				alert("Timeout");
				return
			break;
			case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED:
				alert("Você excedeu o limite de arquivos para upload");
				return
			break;
			case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT:
				error_name = "Arquivo excedeu o limite";
			break;
			case SWFUpload.ERROR_CODE_HTTP_ERROR:
				error_name = "Erro de http";
			break;
			case SWFUpload.ERROR_CODE_MISSING_UPLOAD_TARGET:
				error_name = "UploadTarget está vazio";
			break;
			case SWFUpload.ERROR_CODE_UPLOAD_FAILED:
				error_name = "Falha ao enviar arquivo";
			break;
			case SWFUpload.ERROR_CODE_IO_ERROR:
				error_name = "Falha de IO";
			break;
			//case SWFUpload.ERROR_CODE_SECURITY_ERROR:
			//	error_name = "Erro de segurança";
			//break;
			default:
				alert("Erro");
			break;
		}

        var progress = new FileProgress(fileObj,  this.getSetting("upload_target"));
		progress.SetStatus(error_name);
		progress.ToggleCancel(false);
		

	} catch (ex) { this.debugMessage(ex); }

}


/* ******************************************
 *	FileProgress Object
 *	Control object for displaying file info
 * ****************************************** */

function FileProgress(fileObj, target_id) {
	this.file_progress_id = "divFileProgress";

	this.fileProgressWrapper = document.getElementById(this.file_progress_id);
	if (!this.fileProgressWrapper) {
		
		this.fileProgressWrapper = document.createElement("div");
		this.fileProgressWrapper.className = "progressWrapper";
		this.fileProgressWrapper.id = this.file_progress_id;

		this.fileProgressElement = document.createElement("div");
		this.fileProgressElement.className = "progressContainer";

		var progressCancel = document.createElement("a");
		progressCancel.className = "progressCancel";
		progressCancel.href = "#";
		progressCancel.style.visibility = "hidden";
		progressCancel.appendChild(document.createTextNode(" "));

		var progressText = document.createElement("div");
		progressText.className = "progressName";
		progressText.appendChild(document.createTextNode(fileObj.name));

		var progressBar = document.createElement("div");
		progressBar.className = "progressBarInProgress";

		var progressStatus = document.createElement("div");
		progressStatus.className = "progressBarStatus";
		progressStatus.innerHTML = "&nbsp;";

		this.fileProgressElement.appendChild(progressCancel);
		this.fileProgressElement.appendChild(progressText);
		this.fileProgressElement.appendChild(progressStatus);
		this.fileProgressElement.appendChild(progressBar);

		this.fileProgressWrapper.appendChild(this.fileProgressElement);

		document.getElementById(target_id).appendChild(this.fileProgressWrapper);
		
		this.fileProgressWrapper.display = "block";

	} else {
		this.fileProgressElement = this.fileProgressWrapper.firstChild;
		this.fileProgressElement.childNodes[1].firstChild.nodeValue = fileObj.name;
	}

	this.height = this.fileProgressWrapper.offsetHeight;

}
FileProgress.prototype.SetProgress = function(percentage) {
	this.fileProgressElement.className = "progressContainer green";
	this.fileProgressElement.childNodes[3].className = "progressBarInProgress";
	this.fileProgressElement.childNodes[3].style.width = percentage + "%";
}
FileProgress.prototype.SetComplete = function() {
	this.fileProgressElement.className = "progressContainer blue";
	this.fileProgressElement.childNodes[3].className = "progressBarComplete";
	this.fileProgressElement.childNodes[3].style.width = "";

}
FileProgress.prototype.SetError = function() {
	this.fileProgressElement.className = "progressContainer red";
	this.fileProgressElement.childNodes[3].className = "progressBarError";
	this.fileProgressElement.childNodes[3].style.width = "";

}
FileProgress.prototype.SetCancelled = function() {
	this.fileProgressElement.className = "progressContainer";
	this.fileProgressElement.childNodes[3].className = "progressBarError";
	this.fileProgressElement.childNodes[3].style.width = "";

}
FileProgress.prototype.SetStatus = function(status) {
	this.fileProgressElement.childNodes[2].innerHTML = status;
}

FileProgress.prototype.ToggleCancel = function(show, upload_obj) {
	this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden";
	if (upload_obj) {
		var file_id = this.file_progress_id;
		this.fileProgressElement.childNodes[0].onclick = function() { upload_obj.cancelUpload(file_id); return false; };
	}
}

function textCounter(field, countfield, maxlimit) {

            if( field.value.length > maxlimit )

                        field.value = field.value.substring(0, maxlimit);

            else if( countfield != '' )

                        countfield.value = maxlimit - field.value.length;

}

//################################################################################//

//  Function:       Mascara()																		                    //                                                                                                                 //
//  Criador:			 Rafael Une.																						//
//  Description:              Cria uma mascara no campo informado de acordo com				//
//									o tipo do campo.											                        //

//################################################################################//
function Mascara(tipo, campo, teclaPress) {
	if (window.event)
	{
		var tecla = teclaPress.keyCode;
	} else {
		tecla = teclaPress.which;
	}
 
	var s = new String(campo.value);
	// Remove todos os caracteres à seguir: ( ) / - . e espaço, para tratar a string denovo.
	s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
 
	tam = s.length + 1;
 
	if ( tecla != 9 && tecla != 8 ) {
		switch (tipo)
		{
		case 'CPF' :
			if (tam > 3 && tam < 7)
				campo.value = s.substr(0,3) + '.' + s.substr(3, tam);
			if (tam >= 7 && tam < 10)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,tam-6);
			if (tam >= 10 && tam < 12)
				campo.value = s.substr(0,3) + '.' + s.substr(3,3) + '.' + s.substr(6,3) + '-' + s.substr(9,tam-9);
		break;
 
		case 'CNPJ' :
 
			if (tam > 2 && tam < 6)
				campo.value = s.substr(0,2) + '.' + s.substr(2, tam);
			if (tam >= 6 && tam < 9)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,tam-5);
			if (tam >= 9 && tam < 13)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,tam-8);
			if (tam >= 13 && tam < 15)
				campo.value = s.substr(0,2) + '.' + s.substr(2,3) + '.' + s.substr(5,3) + '/' + s.substr(8,4)+ '-' + s.substr(12,tam-12);
		break;
 
		case 'TEL' :
			if (tam > 2 && tam < 4)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,tam);
			if (tam >= 7 && tam < 11)
				campo.value = '(' + s.substr(0,2) + ') ' + s.substr(2,4) + '-' + s.substr(6,tam-6);
		break;
 
		case 'DATA' :
			if (tam > 2 && tam < 4)
				campo.value = s.substr(0,2) + '/' + s.substr(2, tam);
			if (tam > 4 && tam < 11)
				campo.value = s.substr(0,2) + '/' + s.substr(2,2) + '/' + s.substr(4,tam-4);
		break;
		}
	}
}

//################################################################################//

//  Function:       StartCaract()                                                                                     //                                                                                                                 //
//  Criador:			 Rafael Une.																						//
//  Description:              Coloca a quantidade de caracteres restantes de acordo				//
//									com a quantidade de caracteres que já existe.                        //

//################################################################################//
function StartCaract(qtd)
{
	start = document.getElementById('crt_rest').value;
	start = start - qtd;
	document.getElementById('crt_rest').value = start;
}

function Inscricao(L_ROOT)
{
    var w = window.open(L_ROOT + 'default.aspx','Ver','left=20,top=20,width=600,height=500,location=0,resizable=yes,scrollbars=yes');
}

//################################################################################//

//  Function:       LimitaCaracter()                                                                                     //                                                                                                                 //
//  Criador:			 Clayton Caliari.																						//
//  Description:              Limita a quantidade de caracter de um campo texto,				//
//									trecho de código retirado do eicv3.                        //

//################################################################################//
function LimitaCaracter(oCampo, oContador, inteLimiteMaximo)
{
    if (oCampo.value.length > inteLimiteMaximo)
        oCampo.value = oCampo.value.substring(0, inteLimiteMaximo);
    else if (oContador != '')
        document.getElementById(oContador).value = inteLimiteMaximo - oCampo.value.length;
    
    return true;
}