﻿/* http://stackoverflow.com/questions/3861729/copy-clone-dropdown-list-with-selected-option-in-jquery  */
$(document).ready(function() {

    var oldForm = $('#embeddedform');
    var oldSubmit = oldForm.find('input[type=submit], #embeddedSubmit');
    
    oldSubmit.click(function() {



        var oldForm = $('#embeddedform');

        var newForm = $('<form>', {
            action: oldForm.attr('action'),
            method: oldForm.attr('method'),
			target: oldForm.attr('target'),
            id: 'activeForm'
        }).css({
            display: 'none'
        });
		
        newForm.append(oldForm.children().clone(true));
		
		var $originalSelects = oldForm.find('select');
		newForm.find('select').each(function(index, item) {
			$(item).val($originalSelects.eq(index).val() );
		});
		
				
		newForm.appendTo('body');
		newForm.submit();
        
        return false;
    });
});

