var uploadstarted = 0;

function upload_progressbar_aborted()
{
    // happen when file exceeds the maximum allowed size (through progress bar)
    document.location.href = upload_current_page+"?err=1&s="+sid;
}

function cancelupload()
{
    if (confirm("Are you sure you want to cancel this upload?"))
        document.location.href = upload_current_page+"?err=2&s="+sid;
}

function openterms()
{
    window.open('/popup_terms.html');
    return false;
}

function update_progress_src()
{
    document.getElementById('frm_progressbar').src = progress_url;
}

function uploadformsubmit()
{
    if (!formcheck())
        return false;

    var ua = navigator.userAgent.toLowerCase();
    divCont1 = document.getElementById("divContent1");
    divCont2 = document.getElementById("divContent2");
    if (divCont1 && divCont2)
    {
        if (ua.indexOf( "safari" ) == -1)
            divCont1.style.display = 'none';
        else
            divCont1.className = 'hide_el';
    	divCont2.style.display = 'block';
	}
    setTimeout("update_progress_src()", 500);

	divBtn = document.getElementById("btnupload");
    divBtn.value = "Uploading, Please Wait...";
	divBtn.disabled = true;

	document.onclick = click_while_upload;

    divMys = document.getElementById("mysendspace_bar");
    if (divMys)
        divMys.style.display = 'none';
    
    return true;
}

function click_while_upload(e)
{
    if (!e)
        var e = window.event;

    if (e.which)
        rightclick = (e.which == 3);
    else if (e.button)
        rightclick = (e.button == 2);
    else
        rightclick = false;

    if (e.target)
        targ = e.target;
    else if (e.srcElement)
        targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
	  targ = targ.parentNode;

    if (!rightclick && targ.id != 'cancel_button' && (targ.tagName == 'A' || targ.tagName == 'INPUT'))
        return confirm('Leaving this page will terminate the upload. Are you sure you want to continue?')
    else
        return true;
}
