// JavaScript Document
$(document).ready(function() { 

    // bind contact form using ajaxForm 
    $('#upload').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#cmscontent', 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() { 
            $('#cmscontent').fadeIn('slow'); 
        } 
    }); 

});


function edit(id)
 {
   $('#cmscontent').load('library/cms.php?t=edit&id=' + id);
 }

function update(id)
 {
   var pub;
   var pid;
   var d;
   var heading;
   var description;
   var c0py;

   pub = $("#publish:checked").val();
   pid = $("#parent_id").val();
   heading = escape($("#heading").val());
   d = $("#Y").val() + '-' + $("#m").val() + '-' + $("#d").val();
   description = escape($("#description").val());
   c0py = escape($("#copy").val());

    if (pub != 1)
     {
       pub = 0;
     }

   $('#cmscontent').load('library/cms.php?t=update&id=' + id + '&publish=' + pub + '&parent_id=' + pid + '&d=' + d + '&heading=' + heading + '&description=' + description + '&copy=' + c0py,'',function()
    {
      $('.m' + pid).load('library/cms.php?t=reload_menu&pid=' + pid);
      reload_aux_menu(86);
      reload_aux_menu(87);
    });
 }

function del(pid,id)
 {
   $('#cmscontent').load('library/cms.php?t=delete&id=' + id, function()
    {
      $('.m' + pid).load('library/cms.php?t=reload_menu&pid=' + pid);
      reload_aux_menu(86);
      reload_aux_menu(87);
    });
 }

function reload_aux_menu(pid)
 {
  $('#listMenu' + pid).load('library/cms.php?t=reload_aux_menu&pid=' + pid);
 }

function move_up(pid,id)
 {
   $('.m' + pid).load('library/cms.php?t=move_up&id=' + id + '&pid=' + pid);
 }

function move_down(pid,id)
 {
   $('.m' + pid).load('library/cms.php?t=move_down&id=' + id + '&pid=' + pid);
 }

function nouveau(id)
 {
   $('#cmscontent').load('library/cms.php?t=new&id=' + id);
 }

function insert(id)
 {
   var pub;
   var pid;
   var d;
   var heading;
   var description;
   var c0py;

   pub = $("#publish:checked").val();
   pid = $("#parent_id").val();
   heading = escape($("#heading").val());
   d = $("#Y").val() + '-' + $("#m").val() + '-' + $("#d").val();
   description = escape($("#description").val());
   c0py = escape($("#copy").val());

    if (pub != 1)
     {
       pub = 0;
     }

   $('#cmscontent').load('library/cms.php?t=insert&id=' + id + '&publish=' + pub + '&parent_id=' + pid + '&d=' + d + '&heading=' + heading + '&description=' + description + '&copy=' + c0py,'',function()
    {
      $('.m' + pid).load('library/cms.php?t=reload_menu&pid=' + pid);
      reload_aux_menu(86);
      reload_aux_menu(87);
    });

 }

function casa(id)
 {
   $('#cmscontent').load('library/cms.php?t=home&id=' + id);
 }

function previewImage(id)
 {
   $('#cmscontent').load('library/cms.php?t=previewImage&id=' + id);
 }

function toggle(id)
 {
   $(id).toggle();
 }
