var oIFrame = null;
function createIFrame() 
{
    var oIFrameElement = document.createElement("iframe");
    oIFrameElement.style.display = "none";
    oIFrameElement.name = "ifr_upload";
    oIFrameElement.id = "ifr_upload";
    document.body.appendChild(oIFrameElement);
    oIFrame = frames["ifr_upload"];
}

function endUpload(result)
{
	$('upload_waiting_icon').style.display = 'none';
	$('btn_submit').disabled = false;
	if (result == -2)
	{
	    alert("Cannot recognize your photo's format");
	}
    if (result == -1)
    {
		alert("Your file exceed limit 100KB");
    }
    else if (result == 0)
    {
    	alert("Can't upload file");
    }
    else if (result>0)
    {
       filename = $('attach_file').value;
       $('upload_form').innerHTML = '<input id="file_id" name="file_id" type="hidden" value="' + result + '" />' +
                                    '<input id="file_name" name="file_name" type="hidden" value="' + filename + '" /> <i> Filename: ' + filename + '</i>';
       callAJAX("xoad_handler","refreshUploadImage",$H({file_id: result}),refreshUploadImage_callback);
    }
}

function refreshUploadImage_callback(result)
{
    $('application_photo').style.display = "";
}

function startUpload()
{
    if (!oIFrame)
    {
        createIFrame();       
    }
    $('upload_waiting_icon').style.display = '';
    $('btn_submit').disabled = true;
    var oForm = $('upload_form');
    oForm.submit();
}
