$(document).ready(function()
{
	// Read out the GET parameters.
	readGetParameters();
    
    // Try to retrieve data from the form
    // By processing an ajax request.
    data = $("form").serialize();
    
    $.getJSON("http://www.7umailer.nl/Forms/retrievedata.php?jsoncallback=?", data, 
    function(data)
    {
    	//console.log(data);
    	$.each(data, function(i, n)
        {
            var input = "#" +n.name; 
            if($(input).attr('value') != 'undefined' && n.value != '')
            {
               $(input).attr('value', n.value);
            }
        });
        
        // Check callback function
        if ( typeof onFinish == 'function' ) onFinish();
    });
});


// Method to retrieve the id / secret from the query string.
function readGetParameters()
{
    // Create a global array that will hold the value of each variable,
    // keyed by the name of the variable.
    var getData = new Array();
    var frm = document.forms.change;
            
    var searchString = window.location.search;
    if (searchString) // if has a value...
    {
        // Drop the leading "?"
        searchString = searchString.substr(1);
                
        // Generate a string array of the name value pairs.
        // Each array element will have the form "foo=bar"
        var keyValuePairs = searchString.split("&");
                
        // Now, for each name-value pair, we need to extract
        // the name and value.
        for (var i = 0; i < keyValuePairs.length; i++)
        {
            // So, keyValuePairs[i] contains the current element...
            // Split it at the equals sign.
            var keyValue = keyValuePairs[i].split("=");
                    
            // Assign the pair to the GETDATA array.
            var key = keyValue[0];
            var value = keyValue[1];
            
            if(key == "id") frm.id.value = value;
            if(key == "secret") frm.secret.value = value;
        }    
    }
}

