﻿$(function () {
    $(".scrollable").scrollable({ circular: true, vertical: true, size: 1 }).autoscroll({ autoplay: true, steps: 1, interval: 5000 });
    $('a[href^="http://www"], a[href$=".doc"], a[href$=".pdf"], a[href$=".ppt"], a[href$=".xls"]').click(function () {
        window.open(this.href);
        return false;
    });
    AddPlayer();
    $('.datepicker').datepicker({
        inline: true
    });

});
function AddPlayer() {
    flowplayer(".videoplayer", "/Content/flowplayer.commercial-3.2.2.swf", {
        key: '#$e08aea0d31dfd365cf0',
        clip: {
            scaling: 'fit'
        },
        logo: {
            url: '/Content/images/LogoQ8Tv.png',
            fullscreenOnly: true,
            top: 20,
            left: 20,
            opacity: 0.7

        }
    });

}
function AddButtonDocumentClick() {
   // alert('aggiungo documento');
    var options = {
        //target: '#zone_document',   // target element(s) to be updated with server response 
       // beforeSubmit: showRequest,  // pre-submit callback 
        success: showResponse  // post-submit callback 

        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 

        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    };

    // bind form using 'ajaxForm' 
    $('#DocumentForm').ajaxForm(options); 
//    var form = $('form#DocumentForm');
//    $(':submit', form).click(function (event) {
//        event.preventDefault();
//        $.post(form.attr('action'), form.serialize(),
//        function (data, status) {
//            if (status == 'success') {
//                $('#zone_document').parent().html(data);
//             
//            }
//        }
//    );
//    });
}
function showRequest(formData, jqForm, options) {
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData);

    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 

    alert('About to submit: \n\n' + queryString);

    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true;
}
function showResponse(responseText, statusText, xhr, $form) {
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 

    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 

    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 

//    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
    //        '\n\nThe output div should have already been updated with the responseText.');
    $('#zone_document').parent().html(responseText);
} 
function AddButtonClick() {
    //alert('AddButtonClick');
    var form = $('form#ContentForm');
    //if (form.length > 0) { alert('beccato'); }
    $(':submit', form).click(function (event) {
        //alert('Posto il form');
        event.preventDefault();
        $.post(form.attr('action'), form.serialize(),
        function (data, status) {
            if (status == 'success') {
                $('#zoneContent').parent().html(data);
                AddPlayer();

            }
        }
    );
    });
}
function editdocument() {
   // alert('Bottone Attivo');
   // alert('editdocument');
  //  $(".datePicker").datepicker({ showOn: 'both', buttonImage: "/Content/images/calendar.png" });
    AddButtonDocumentClick();
    $('.datepicker').datepicker({
        inline: true
    });
}

function editzone() {
    // alert('pluto chiamato');
    AddButtonClick();
    $('.xeditor').tinymce({
        script_url: '/Scripts/tiny_mce/tiny_mce.js',
        theme: "advanced",
        auto_resize: true,
        plugins: "autoresize,paste,searchreplace,table",
        content_css: "/Content/BpmEdit.css?" + new Date().getTime(),
        theme_advanced_buttons1:"bold,italic,underline|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3:"tablecontrols",
        theme_advanced_font_sizes: "10px,12px,13px,14px,16px,18px,20px",
        font_size_style_values: "10px,12px,13px,14px,16px,18px,20px",
        setup: function (ed) {
            ed.onChange.add(
	        function (ed, evt) {
	            // alert('Modificato');
	            //  ed.triggerSave();

	        }
	    )
        }

        //        plugins: "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
        //        theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
        //        theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        //        theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        //        theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
        //        theme_advanced_toolbar_location: "top",
        //        theme_advanced_toolbar_align: "left",
        //        theme_advanced_statusbar_location: "bottom",
        //        theme_advanced_resizing: true,
        //        content_css: "css/content.css",
        //        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",
        //        template_replace_values: {
        //            username: "Some User",
        //            staffid: "991234"
        //        }
    });
}


