var errors, edtFileName, hddnField, hddnImgField, hddnFileType, hddnMulti;	
var module = baseRootURL + "upload/";

/*
Dropzone.options.sableDropzone = 
{ 
	url: module+'upload_val.php',
	paramName: "edtFileName",
	previewsContainer: ".dropzone-previews",
	uploadMultiple: true,
	parallelUploads: 5,
	maxFiles: 20,
	accept:	function (file, done)
			{
				doUpload();
				done();
			}
 };
*/

function doUpload()
{
	document.getElementById('uploadProgress').src = module+'uploading.gif';
	document.getElementById('frmUpload').submit();
	if (document.getElementById('bar_blank')!==null){startUpload();} //monitors the upload progress making use of Ajax Calls back to the same page...
}
	
function uploadFile()
{
	errors = false; //initialise
	var hddnField = 	document.getElementById('hddnField').value;
	var hddnImgField =  document.getElementById('hddnImgField').value;
	var hddnFileType = 	document.getElementById('hddnFileType').value;
	var hddnMulti = 	document.getElementById('hddnMulti').value;
    if (!errors)
	{		
		var data = {};
		data.dummy = ""; //we seem to get errors from the first value, so always add a dummy value first.
		data.edtFileName = edtFileName;
		data.hddnField = hddnField;
		data.hddnImgField = hddnImgField;
		data.hddnFileType = hddnFileType;
		data.hddnMulti = hddnMulti;
		callModule("upload/upload_val.php", data);		
	}
} /* registerQuote() */

//**** UPLOAD PROGRESS *****//
function toggleBarVisibility()
{
    var e = document.getElementById("bar_blank");
    e.style.display = (e.style.display == "block") ? "none" : "block";
}

function createRequestObject()
{
    var http;
    if (navigator.appName == "Microsoft Internet Explorer") http = new ActiveXObject("Microsoft.XMLHTTP"); else http = new XMLHttpRequest();
    return http;
}

function sendRequest() 
{
    var http = createRequestObject();
    http.open("GET", module+"progress.php");
    http.onreadystatechange = function () { handleResponse(http); };
    http.send(null);
}

function handleResponse(http) 
{
    var response;
    if (http.readyState == 4) 
	{
        response = http.responseText;
        document.getElementById("bar_color").style.width = response + "%";
        document.getElementById("status").innerHTML = response + "%";

        if (response < 100) 
		{
            setTimeout("sendRequest()", 1000);
        }
        else 
		{
            toggleBarVisibility();
            document.getElementById("status").innerHTML = "Done.";
        }
    }
}

function startUpload() 
{
    toggleBarVisibility();
    setTimeout("sendRequest()", 1000);
}

////(function (){document.getElementById("frmUpload").onsubmit = startUpload;})();