$(function(){
   $('.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();
        }
    });
    $('#green-contents').css('display', 'none');
    $('#black-contents').css('display', 'none');
    $('#blue-contents').css('display', 'none');
    $('#white-contents').css('display', 'none');
    $('ul li').click(function() {
        $('#red-contents').css('display', 'none');
        $('#green-contents').css('display', 'none');
        $('#black-contents').css('display', 'none');
        $('#blue-contents').css('display', 'none');
        $('#white-contents').css('display', 'none');
        if ($(this).attr('id') == '1') $('#red-contents').css('display', '');
        if ($(this).attr('id') == '2') $('#green-contents').css('display', '');
        if ($(this).attr('id') == '3') $('#black-contents').css('display', '');
        if ($(this).attr('id') == '4') $('#blue-contents').css('display', '');
        if ($(this).attr('id') == '5') $('#white-contents').css('display', '');
    });
    $('#green').smartpaginator({
        totalrecords: 100,
        recordsperpage: 10,
        datacontainer: 'mt',
        dataelement: 'tr',
        initval: 0,
        next: 'Next',
        prev: 'Prev',
        first: 'First',
        last: 'Last',
        theme: 'black'
    });
    $('#black').smartpaginator({
        totalrecords: 50,
        recordsperpage: 1,
        datacontainer: 'divs',
        dataelement: 'div',
        initval: 0,
        next: 'Next',
        prev: 'Prev',
        first: 'First',
        last: 'Last',
        theme: 'black'
    });
   $('#white').smartpaginator({
        totalrecords: 10,
        recordsperpage: 1,
        datacontainer: 'divs',
        dataelement: 'div',
        initval: 0,
        next: 'Next',
        prev: 'Prev',
        first: 'First',
        last: 'Last',
        theme: 'black'
    });
  $('#blue').smartpaginator({
        totalrecords: 50,
        recordsperpage: 1,
        datacontainer: 'divs',
        dataelement: 'div',
        initval: 0,
        next: 'Next',
        prev: 'Prev',
        first: 'First',
        last: 'Last',
        theme: 'black'
    });
 $('#red').smartpaginator({
        totalrecords: 32,
        recordsperpage: 4,
        length: 4,
        next: 'Next',
        prev: 'Prev',
        first: 'First',
        last: 'Last',
        theme: 'red',
        onchange: function(newPage) {
            $('#r').html('Page # ' + newPage);
        }
    });

    $('textarea#autotextares').autoResize({
        // On resize:
        onResize : function() {
            $(this).css({
                opacity:0.8
            });
        },
        // After resize:
        animateCallback : function() {
            $(this).css({
                opacity:1
            });
        },
        // Quite slow animation:
        animateDuration : 300,
        // More extra space:
        extraSpace : 40
    });
    $("#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);
        }
    });
    $('textarea.tinymce').tinymce({
        // Location of TinyMCE script
        script_url : 'components/scripts/javascript/tiny_mce/tiny_mce.js',

        // General options
        theme : "advanced",
        plugins : "safari,pagebreak,style,layer,table,save,advhr,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,link,unlink,anchor,image,cleanup,help,code,|,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,cite,abbr,acronym,del,ins,attribs|,outdent,indent,blockquote,|,undo,redo,",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : false,

        // Example content CSS (should be your site CSS)
        content_css : "css/content.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "lists/template_list.js",
        external_link_list_url : "lists/link_list.js",
        external_image_list_url : "lists/image_list.js",
        media_external_list_url : "lists/media_list.js",
        height: '400px',
        width: '800px'

    });
    $('.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...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        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("txtorange").removeClass("txtred");
            }
        }
    });
    // 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:true,
        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("txtorange").removeClass("txtred");
            }
        }
    });
        // Add vedio link
    $('#vediolink').ajaxForm({
        beforeSubmit: function() {
            $('#error44').html('Please Wait Processing...').fadeIn(500).delay(1500).fadeOut(3000);
        },
        url:'post.php?cmd=add_vediolink',
        data:$('#vediolink').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("txtorange").removeClass("txtred");
            }
        }
    });
    // 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");
            }
        }
    });

    // 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");
            }
        }
    });

    // 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('ul.sf-menu').superfish();
    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();
    }

};

