$(function(){
    /*$('#timezone').selectbox();
    $('#country').selectbox();
    $('#chinese').selectbox();
    $('#usr_timezone').selectbox();
    $('#state').selectbox();
    $('#usr_county').selectbox();*/

    $('.more').live("click",function(){
        var ID = $(this).attr("id");
        if(ID){
            $("#more"+ID).html('<img src="components/media/site/moreajax.gif" />');
            $.ajax({
                type: "POST",
                url: "content/ajax_more.php",
                data: "lastmsg="+ ID,
                cache: false,
                success: function(html){
                    $("ol#updates").append(html);
                    $("#more"+ID).remove();
                }
            });
        }
        else{
            $(".morebox").html('The End');
        }
        return false;
    });
    // delete message
    //    $('.message_actions .delete').live ('click', function (e) {
    //		e.preventDefault ();
    //
    //		$(this).parents ('tr').fadeOut ('medium', function () { $(this).remove (); });
    //	});
    // paginate messages
    $('#browser_data').dataTable( {
        "iDisplayLength": 6,
        "bLengthChange": false,
        "bFilter": false,
        "aoColumnDefs": [
        {
            "bSearchable": false,
            "bVisible": true,
            "aTargets": [ 3 ]
        },
{
            "bVisible": false,
            "aTargets": [ 3 ]
        }
        ]
    } );
    /*

    $('#calendar').fullCalendar({
        theme: true,
        editable: true,
        events: "incs/json-events.php",
        eventDrop: function(event, delta) {
            alert(event.title + ' was moved ' + delta + ' days\n' +
                '(should probably update your database)');
        },
        eventMouseover: function(calEvent, jsEvent, view) {

            $('.calendar_tooltip').remove();
            $('<div class="calendar_tooltip" style="position:absolute;left:'+(jsEvent.pageX-10)+'px;top:'+(jsEvent.pageY)+'px;z-index:20">'+calEvent.data+'</div>')
            .appendTo('body')
            .show();
            $('.calendar_tooltip').mouseover(function(){
                $(this).show();
            });
            $('.calendar_tooltip').mouseout(function(){
                $(this).hide();
            });
        },

        loading: function(bool) {
            if (bool) $('#loading').show();
            else $('#loading').hide();
        }

    });*/
    $('#fullcalendar').fullCalendar({
        theme: true,
        editable: true,
        events: "incs/json-events.php",
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        eventDrop: function(event, delta) {
            alert(event.title + ' was moved ' + delta + ' days\n' +
                '(should probably update your database)');
        },
        eventMouseover: function(calEvent, jsEvent, view) {

            $('.calendar_tooltip').remove();
            $('<div class="calendar_tooltip" style="position:absolute;left:'+(jsEvent.pageX-10)+'px;top:'+(jsEvent.pageY)+'px;z-index:20">'+calEvent.data+'</div>')
            .appendTo('body')
            .show();
            $('.calendar_tooltip').mouseover(function(){
                $(this).show();
            });
            $('.calendar_tooltip').mouseout(function(){
                $(this).hide();
            });
        },

        loading: function(bool) {
            if (bool) $('#loading').show();
            else $('#loading').hide();
        }

    });

    $('.showdetails').click(function() {
        var id=$(this).attr("id");
        $( ".showdetails"+id).dialog({
            width: 600
        });
    });
    $('.studentdetails').click(function() {
        var id2=$(this).attr("id");
        $(".studentdetails"+id2).dialog({
            width: 600
        });
    });
    $('.liststudents').click(function() {
        var id3=$(this).attr("id");
        $(".liststudents"+id3).dialog({
            width: 600
        });
    });
    $('.showcart').click(function() {
        // var id=$(this).attr("id");
        $( "#cart").dialog({
            width: 800
        });
    });
    $("#mail_category").change(function(){

        if ($("#mail_category").val() =='specificlass')
        {
            $("#to_user").hide();
            $("#to_class").show();
        }
        else if ($("#mail_category").val() =='specificuser')
        {
            $("#to_class").hide();
            $("#to_user").show();

        }
        else{
            $("#to_user").hide();
            $("#to_class").hide();
        }
    });
    $("#usr_county").change(function(){

        if ($("#usr_county").val() =='us')
        {
            $("#statediv").hide();
            $("#statedivus").show();
        }
        else{
            $("#statedivus").hide();
            $("#statediv").show();
        }
    });

    $("#search_user").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: "include/getusers.php",
                data: {
                    term: request.term
                //   country:  $("#usr_county").val()
                },
                dataType: "json",
                type: "GET",
                success: function(data){
                    response(data);
                }
            });
        },
        minLength: 2,
        select: function(event, ui) {
            $('#mail_to').val(ui.item.id);
        }
    });
    $('.ui_button').button();
    $('#login_form').hide();
    $('#contact_us').hide();
    //contact us
    $('#doContact').click(function() {
        $("#contact_us").toggle("slow");
        this.focus();
    });
    //chage item address display login form
    $('#doLogin').click(function() {
        $('#reg_form').hide();
        $('#login_form').show();
        $('#forgotpass_form').hide();
        $('#doLogin').hide();
    });
    $('#forgotpass_form').hide();
    //chage item address display forgot password form
    $('#doForgot').click(function() {
        $('#reg_form').show();
        $('#login_form').hide();
        $('#forgotpass_form').show();
        $('#doForgot').hide();
    });
    //chage item address
    $('#show_change_item_form').click(function() {
        $('#address_form').hide();
        $('#editlist_form').show();

    });
    // add new address
    $('#show_new_address_form').click(function() {
        $('#account_form').hide();
        $('#newpass_form').hide();
        $('#address_form').show();
    });
    $("#facebook").click(function(){
        window.location.href="http://www.facebook.com/";
    });


    $("#twitter").click(function(){
        window.location.href="http://twitter.com/";
    });
    // change Profile photo
    $('#photoimg').live('change', function(){
        $("#preview").html('');
        $("#preview").html('<img src="images/ajax-loader.gif" alt="Uploading...."/>');
        $("#imageform").ajaxForm({
            target: '#preview'
        }).submit();

    });
    // Course registeration
    $('#form_addcourse').ajaxForm({
        beforeSubmit: function() {
            $('#error').html('Please Wait Processing...').addClass("ui-state-highlight ui-corner-all");
        },
        url:'post.php?cmd=addcourse',
        data:$('#form_addcourse').serialize(),
        dataType : 'json',
        type:'POST',
        resetForm:true,
        success: function(data) {
            if (data.error === true) {
                $('#error').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#error').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all").fadeOut(3000);
            }
        }
    });
    // reply to message
    $('#reply_form').ajaxForm({
        beforeSubmit: function() {
            $('#reply_form').validate();
        },
        url:'post.php?cmd=msgreply',
        data:$('#reply_form').serialize(),
        dataType : 'json',
        type:'POST',
        resetForm:true,
        success: function(data) {
            if (data.error === true) {
                $('#response').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#response').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all").fadeOut(3000);
                location.reload();
            }
        }
    });
    // send note/message
    $('#contact_note_form').ajaxForm({
        beforeSubmit: function() {
            $('#reply_form').validate();
        },
        url:'post.php?cmd=sendnote',
        data:$('#contact_note_form').serialize(),
        dataType : 'json',
        type:'POST',
        resetForm:true,
        success: function(data) {
            if (data.error === true) {
                $('#response').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#response').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all").fadeOut(3000);
            }
        }
    });
    // Student / Teacher Course registeration form
    $('#creataccountForm').ajaxForm({
        beforeSubmit: function() {
            $('#error_reg').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=creataccount',
        data:$('#creataccountForm').serialize(),
        dataType : 'json',
        type:'POST',
        resetForm:false,
        success: function(data) {
            if (data.error == true) {
                $('#error_reg').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $(location).attr('href',data.msg);
            }
        }
    });
    // Student / Teacher Course request login form
    $('#reg_request_login').ajaxForm({
        beforeSubmit: function() {
            $('#error_log').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=course_login',
        data:$('#reg_request_login').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#error_log').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $(location).attr('href',data.msg);
            }
        }
    });
    // Free Demo Course registeration Form
    $('#submitLesson').ajaxForm({
        beforeSubmit: function() {
            $('#error').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=submitLesson',
        data:$('#submitLesson').serialize(),
        dataType : 'json',
        type:'POST',
        resetForm:true,
        success: function(data) {
            if (data.error === true) {
                $('#error').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#error').html(data.msg).fadeIn(1000).delay(500).addClass("txtorange").removeClass("txtred");
            }
        }
    });
    // Course Category
    $('#form_addcat').ajaxForm({
        beforeSubmit: function() {
            $('#result').html('Please Wait Processing...').fadeIn(500).delay(1500).addClass("ui-state-highlight ui-corner-all");
        },
        url:'post.php?cmd=addcat',
        data:$('#form_addcat').serialize(),
        dataType : 'json',
        type:'POST',
        resetForm:true,
        success: function(data) {
            if (data.error === true) {
                $('#result').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#result').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });
    // Add Resource
    $('#add_resource').ajaxForm({
        beforeSubmit: function() {
            $('#error44').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=add_resource',
        data:$('#add_resource').serialize(),
        dataType : 'json',
        type:'POST',
        resetForm:true,
        success: function(data) {
            if (data.error === true) {
                $('#error44').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#error44').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });
    // Add vedio link
    $('#vediolink').ajaxForm({
        beforeSubmit: function() {
            $('#error44').html('Please Wait Processing...').fadeIn(500).delay(1500).addClass("ui-state-highlight ui-corner-all");
        },
        url:'post.php?cmd=add_vediolink',
        data:$('#vediolink').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#error44').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#error44').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });
    // user registeration
    $('#trialdemo').ajaxForm({
        beforeSubmit: function() {
            $('#msg_sigup').html('Please Wait Processing...').fadeIn(500).delay(1500).addClass("ui-state-highlight ui-corner-all");
        },
        url:'post.php?cmd=reg_demo',
        data:$('#trialdemo').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#msg_sigup').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $(location).attr('href',data.msg);
            }
        }
    });
    // Add new Event
    $('#add_note').ajaxForm({
        beforeSubmit: function() {
            $('#result').html('Please Wait Processing...').fadeIn(500).delay(1500).addClass("ui-state-highlight ui-corner-all").fadeOut(3000);
        },
        url:'post.php?cmd=add_event',
        data:$('#add_note').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#result').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error ui-corner-all");
            }
            else{
                $('#result').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });
    // Forgot password form
    $('#forgotpassform').ajaxForm({
        beforeSubmit: function() {
            $('#forgoterror').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=forgot',
        data:$('#forgotpassform').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#forgoterror').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#forgoterror').html(data.msg).fadeIn(1000).delay(500).fadeOut(5000);
            }
        }
    });
    // user Profile form
    $('#profileform').ajaxForm({
        beforeSubmit: function() {
            $('#updatemsg').html('Please Wait Processing...').fadeIn(500).delay(1500).addClass("ui-state-highlight ui-corner-all");
        },
        url:'post.php?cmd=usrsettings',
        data:$('#profileform').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#updatemsg').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#updatemsg').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });
    // user Profile change password form
    $('#change_pass_form').ajaxForm({
        beforeSubmit: function() {
            $('#error_pass').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=newpass',
        data:$('#change_pass_form').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#error_pass').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#error_pass').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });

    // User Sign in form
    $('#signinform').ajaxForm({
        beforeSubmit: function() {
            $('#error').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=login',
        data:$('#signinform').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#error').html(data.msg).fadeIn(1000).delay(500).fadeOut(5000);
            }
            else{
                $(location).attr('href',data.msg);
            }
        }
    });

    // Course Update form
    $('#form_editcourse').ajaxForm({
        beforeSubmit: function() {
            $('#response_editcourse').html('Please Wait Processing...').fadeIn(500).delay(1500).addClass("ui-state-highlight ui-corner-all");
        },
        url:'post.php?cmd=update_course',
        data:$('#form_editcourse').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#response_editcourse').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#response_editcourse').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });
    // Sending Message form
    $('#form_compose_message').ajaxForm({
        beforeSubmit: function() {
            $('#response_message').html('Please Wait Processing...').fadeIn(500).delay(1500).addClass("ui-state-highlight ui-corner-all");
        },
        url:'post.php?cmd=send_message',
        data:$('#form_compose_message').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#response_message').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#response_message').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });
    // Teacher Course Update form
    $('#formteacher_editcourse').ajaxForm({
        beforeSubmit: function() {
            $('#error').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=teacher_editcourse',
        data:$('#formteacher_editcourse').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#response_editcourse').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#response_editcourse').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });

    // Admin Course Update form
    $('#formadmin_editcourse').ajaxForm({
        beforeSubmit: function() {
            $('#error').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=admin_editcourse',
        data:$('#formadmin_editcourse').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#response_editcourse').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#response_editcourse').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });
    // student Calendar
    //
    $('#formadmin_course_calendar').ajaxForm({
        beforeSubmit: function() {
            $('#error').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=student_course_calendar',
        data:$('#formadmin_course_calendar').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#response_editcourse').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#response_editcourse').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });
    // student Calendar End
    // Teacher Chane Course time and date for specific student
    $('#formteacher_editdatetime').ajaxForm({
        beforeSubmit: function() {
            $('#error').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=teacher_editdate',
        data:$('#formteacher_editdatetime').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#response_editcourse').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#response_editcourse').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });
    // Send Email form
    $('#send_mailform').ajaxForm({
        beforeSubmit: function() {
            $('#mail_responase').html('Please Wait Processing...').fadeIn(500).delay(1500).addClass("ui-state-highlight ui-corner-all");
        },
        url:'post.php?cmd=send_mail',
        data:$('#send_mailform').serialize(),
        dataType : 'json',
        type:'POST',
        success: function(data) {
            if (data.error === true) {
                $('#mail_responase').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-error");
            }
            else{
                $('#mail_responase').html(data.msg).fadeIn(1000).delay(500).addClass("ui-state-highlight ui-corner-all");
            }
        }
    });

    // Script for Request A Call Box Starts

    jQuery(".requestacall div.inactive").click(function(e) {
        e.preventDefault();
        jQuery("div#showdiv").toggle();
        jQuery(".requestacall div.inactive").toggleClass("active");

        if(jQuery(this).hasClass("inactive")){
            jQuery(this).removeClass("inactive");
            jQuery(this).addClass("active");
            jQuery('.inactive').hide();
        }
        else{
            jQuery(this).removeClass("active");
            jQuery(this).addClass("inactive");
        }
    });

    jQuery("div#showdiv").mouseup(function() {
        return false;
    });


    setTimeout(MyUpdate,1000);

});
function MyUpdate(){
    jQuery("object").each(function(){
        jQuery("object").append('<param name="wmode" value="opaque" />');
    });


}
// Script for Request A Call Box Ends




// Script For Play Button in Lessons Starts

function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr;
    for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d=document;
    if(d.images){
        if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
        for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){
                d.MM_p[j]=new Image;
                d.MM_p[j++].src=a[i];
            }
    }
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;
    if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n);
    return x;
}

function MM_swapImage() {
    //v3.0
    var i,j=0,x,a=MM_swapImage.arguments;
    document.MM_sr=new Array;
    for(i=0;i<(a.length-2);i+=3)
        if ((x=MM_findObj(a[i]))!=null){
            document.MM_sr[j++]=x;
            if(!x.oSrc) x.oSrc=x.src;
            x.src=a[i+2];
        }
}

function EvalSound(soundobj) {
    //alert(soundobj);
    var thissound=document.getElementById(soundobj);
    try {
        thissound.Play();
    }
    catch (e) {
        thissound.DoPlay();
    }

}
function toggleChecks(field) {
    if (document.listform.toggleAll.checked == true){
        for (i = 0; i < field.length; i++) {
            field[i].checked = true;
        }
    } else {
        for (i = 0; i < field.length; i++) {
            field[i].checked = false;
        }
    }

}
