﻿   
//--------------------------------------------------------------------------
//                      MAIN FUNCTION  
//uploadFile() gets called upon Submit button's click [Button2]                                
//--------------------------------------------------------------------------
    
function uploadFile()
{
	var frameId = "ifra";

    var action = Concepts2Go_GetCallBackUrl();
    action = action + (action.indexOf('?') == -1 ? "?" : "&") + "Concepts2Go_IOFrame=true";

    // Create a new, invisible iframe to handle the io.
    var ioframe = null;
    if (window.ActiveXObject) {
        ioframe = document.createElement("<iframe name=\"" + frameId + "\" id=\"" + frameId + "\" onload=\"Concepts2Go_HandleIOFrameResponse('" + frameId + "');\"/>");
    } else {
        ioframe = document.createElement("iframe");
        ioframe.id = frameId;
        ioframe.name = frameId;
        ioframe.onload = function (){ Concepts2Go_HandleIOFrameResponse(frameId); }
    }
    ioframe.style.visibility = "hidden";
    ioframe.style.height = "1px";
    document.body.appendChild(ioframe);

	
	var theForm = Concepts2Go_GetForm(); 
    var tempActionUri = theForm.action; 

    theForm.action = action; 
    theForm.target = frameId;
    try { 
        theForm.submit(); 
    } 
    catch (e) {
        alert('FOUT:' + e.message);
        //result = { "value": null, "error": e.message };
    }

    // Restore the form 
    theForm.target = ""; 
    theForm.action = tempActionUri;    
    
	return false;
}

//--------------------------------------------------------------------------
//                      UTILITY FUNCTION                                  
//--------------------------------------------------------------------------

function Concepts2Go_GetForm() 
{
	var form = document.getElementById("aspnetForm");
    return form;
}    

// Returns the URL for callbacks
function Concepts2Go_GetCallBackUrl() {
    var form = Concepts2Go_GetForm() ;
    var action = form.action + (form.action.indexOf('?') == -1 ? "?" : "&") + "Concepts2Go_CallBack=true";
    return action;
}

//--------------------------------------------------------------------------
//                      CALLBACK FUNCTION                                  
//--------------------------------------------------------------------------

// This function is called by the onload event of the IOFrame after the
// callback response is received. The function invokes the clientCallBack function.
function Concepts2Go_HandleIOFrameResponse(frameid) 
{
    var iframe = document.getElementById(frameid);
    if (iframe != null) {
       setTimeout("document.body.removeChild(document.getElementById(\"" + frameid + "\"))", 10);
    }
}
