
function copy_to_clipboard(object) {
/*$(object).text();
   CopiedTxt = document.selection.createRange();
   CopiedTxt.execCommand("Copy");*/
}

function make_featured_courses_sortable() {
    $("#featured_classes_ul").sortable({
        revert: false,
        update: function(event, ui) {
            save_featured_classes_order();
        }
    }).floating = true;
}

function save_featured_classes_order() {
    $.post(window.COURSE_SAVE_FEATURED_CLASSES_ORDER, {
        ids: get_ids_from_sortable_list('featured_classes_ul')
    }, function(){
        });
}

function delete_course(id, calendar_page) {
    if (confirm("Are you sure that you want to permanently delete the class?")) {
        $.post(window.COURSE_DELETE, {
            id: id
        }, function(){
            refresh_featured_courses();
            refresh_calendar(calendar_page);
        });
    }
}

function feature_course(id, calendar_page) {
    $.post(window.COURSE_FEATURE, {
        id: id
    }, function(retrieved_data){
        if (retrieved_data != 'success') { if (window.debug) alert (retrieved_data); }
        else {
            refresh_featured_courses(calendar_page);
            refresh_calendar(calendar_page);
        }
    });
}

function unfeature_course(id, calendar_page) {
    $.post(window.COURSE_UNFEATURE, {
        id: id
    }, function(retrieved_data){
        if (retrieved_data != 'success') { if (window.debug) alert (retrieved_data); }
        else {
            refresh_featured_courses(calendar_page);
            refresh_calendar(calendar_page);
        }
    });
}

function load_info_modal(id) {
    hide_video();
    createPopUp('modal_contact_form_hidden_div', 617, 500);
    $.post(window.COURSE_INFO_URL, {
        id: id
    }, function(retrieved_data){
        $("#NSPopUP").html(retrieved_data).height("auto");
    });
}

/*function load_foxycart_cart() {
    var info_modal_form = document.getElementById('info_modal_form');
    var foxycart_hidden_form = document.getElementById('foxycart_hidden_form');
    foxycart_hidden_form.name.value = info_modal_form.name.value;
    foxycart_hidden_form.price.value = info_modal_form.price.value;
    foxycart_hidden_form.date.value = info_modal_form.date.value;
    foxycart_hidden_form.time.value = info_modal_form.time.value;
    unload_modal_contact_form();
    foxycart_hidden_form.submit();
}*/

function get_ids_from_sortable_list(sortable_list) {
    var items = $("#" + sortable_list + " li");
    var ids = '';
    var temp_array = {};

    for(var x = 0; x < items.length ; x++) {
        temp_array = items[x].id.split("_");
        ids += temp_array[temp_array.length-1];
        if (x < items.length -1) ids += ',';
    }
    //alert(ids);
    return ids;
}

function refresh_featured_courses(calendar_page) {
    var count = 0;
    var glob_retrieved_data;
    var container = 'featured_classes_div';
    $("#" + container).fadeOut(300, function (){
        count++;
        if (count == 2) {
            $("#" + container).html(glob_retrieved_data);
            $("#" + container).fadeIn(300);
        }
    });
    $.post(window.COURSE_GET_FEATURED_COURSES, {
        page: calendar_page
    }, function(retrieved_data){
        if(retrieved_data.length > 0) {
            glob_retrieved_data = retrieved_data;
            count++;
            if (count == 2) {
                $("#" + container).html(retrieved_data);
                $("#" + container).fadeIn(300);
            }
        }
    });
}

function refresh_calendar(page) {
    var count = 0;
    var glob_retrieved_data;
    var container = 'calendar_inner_content_div';
    $("#" + container).fadeOut(300, function (){
        count++;
        if (count == 2) {
            $("#" + container).html(glob_retrieved_data);
            $("#" + container).fadeIn(300);
        }
    });
    $.post(window.COURSE_GET_CALENDAR, {
        page: page
    }, function(retrieved_data){
        if(retrieved_data.length > 0) {
            glob_retrieved_data = retrieved_data;
            count++;
            if (count == 2) {
                $("#" + container).html(retrieved_data);
                $("#" + container).fadeIn(300);
            }
        }
    });
}

function refresh_incoming_classes_form (class_selected) {
    var count = 0;
    var glob_retrieved_data;
    $("#dynamic_content_div").fadeOut(300, function (){
        count++;
        if (count == 2) {
            $("#dynamic_content_div").html(glob_retrieved_data);
            $("#dynamic_content_div").fadeIn(300);
        }
    });
    $.post(window.dev + "/code/php/run_function.php", {
        function_to_call: "get_selected_class",
        class_selected: class_selected
    }, function(retrieved_data){
        if(retrieved_data.length > 0) {
            glob_retrieved_data = retrieved_data;
            count++;
            if (count == 2) {
                $("#dynamic_content_div").html(retrieved_data);
                $("#dynamic_content_div").fadeIn(300);
            }
        }
    });
}

function refresh_buzz_form (buzz_selected) {
    var count = 0;
    var glob_retrieved_data;
    $("#dynamic_content_div").fadeOut(300, function (){
        count++;
        if (count == 2) {
            $("#dynamic_content_div").html(glob_retrieved_data);
            $("#dynamic_content_div").fadeIn(300);
        }
    });
    $.post(window.dev + "/code/php/run_function.php", {
        function_to_call: "get_selected_buzz",
        buzz_selected: buzz_selected
    }, function(retrieved_data){
        if(retrieved_data.length > 0) {
            glob_retrieved_data = retrieved_data;
            count++;
            if (count == 2) {
                $("#dynamic_content_div").html(retrieved_data);
                $("#dynamic_content_div").fadeIn(300);
            }
        }
    });
}

function save_buzz (buzz_selected) {
    var buzz_form = document.getElementById('upload_form');
    $.post(window.dev + "/code/php/run_function.php", {
        function_to_call: "set_selected_buzz",
        buzz_selected: buzz_selected,
        date: buzz_form.date.value,
        title: buzz_form.title.value,
        link: buzz_form.link.value,
        author: buzz_form.author.value
    }, function(retrieved_data){
        if (retrieved_data == "success") alert ("Buzz succesfully updated!");
        else if (window.debug) alert (retrieved_data);
    });
}

function upload_media_file() {
    /* Configure form before submitting it */
    var upload_background_form = document.getElementById("upload_background_form");
    upload_background_form.id.value = document.getElementById("class_select").value;

    /* Submit form */
    upload_background_form.submit();
}

function createCookie(name,value,days) {
    var expires;
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        expires = "; expires="+date.toGMTString();
    }
    else expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function send_mailing_list_email() {
    if (checkfields('mailing_list_contact_form')) {
        var mailing_list_contact_form = document.getElementById('mailing_list_contact_form');
        $.post(window.dev + "/code/php/send_email.php", {
            email: mailing_list_contact_form.email.value
        }, function(){});
        alert ("Your form has been submitted. Thank you for contacting us");
        mailing_list_contact_form.reset();
        mailing_list_contact_form.email.style.color = "#B3B3B3";
        window.email_cleaned = 0;
    } else {
        alert ("Please complete with a valid e-mail");
    }
}

function home_thumb_selected (new_image) {
    var big_image = document.getElementById("home_big_image");
    big_image.src = window.dev + "/media/images/home/" + new_image + ".jpg";
}

function preload_home_thumb_images() {
    image_obj2 = new Image();
    image_obj3 = new Image();
    image_obj4 = new Image();
    image_obj5 = new Image();
    image_obj6 = new Image();
    image_obj7 = new Image();
    image_obj8 = new Image();
    image_obj9 = new Image();
    image_obj10 = new Image();
    image_obj11 = new Image();
    image_obj2.src = window.dev + "/media/images/home/2.jpg";
    image_obj3.src = window.dev + "/media/images/home/3.jpg";
    image_obj4.src = window.dev + "/media/images/home/4.jpg";
    image_obj5.src = window.dev + "/media/images/home/5.jpg";
    image_obj6.src = window.dev + "/media/images/home/6.jpg";
    image_obj7.src = window.dev + "/media/images/home/7.jpg";
    image_obj8.src = window.dev + "/media/images/home/8.jpg";
    image_obj9.src = window.dev + "/media/images/home/9.jpg";
    image_obj10.src = window.dev + "/media/images/home/10.jpg";
    image_obj11.src = window.dev + "/media/images/backgrounds/home_link_selector.gif";
}


