var mDocRoot = 'http://'+top.location.host+'/';
var loaderGif = '<center><img src="images/loading.gif" /></center>';

/*accordion left nav*/
window.addEvent('domready',function(){
    var SidebarMenu = new Accordion($$('.toggler'),$$('.element'));
    Sexy = new SexyAlertBox();
    DivOverLay();
    HighlighRow();
    DelSelected();
    SubmitForm();
    Paging();
    new DatePicker('.demo_allow_empty', {
            pickerClass: 'datepicker_dashboard',
            allowEmpty: true
        });



});

/*window.addEvent('domready',function(){
  var toggleThis = new Fx.Slide('newsadd',{
    duration:"1000",
    transition:Fx.Transitions.Pow.easeOut
  });

  toggleThis.hide().slideIn();

  $('aa').addEvent('click',function(e){
      e.stop();
      toggleThis.toggle();
  });

});
*/

function Paging(){
    if($('pages')){
        $('pages').getElements('a').addEvent('click',function(e){
            new Event(e).stop();

            /*var ur = root+this.getProperty('href');
            var url2 = ur.replace(/webpagecontent/i,'getgrid');*/

            var url2 = mDocRoot+this.getProperty('href').replace($('sUrl').innerHTML,$('dUrl').innerHTML);

            new Request({
                method : "get",
                url: url2,
                onRequest : function(){},
                onComplete : function(response){
                    /*document.body.set('html',response); */

                    $('s-content').empty().set('html',response);
                    window.fireEvent('domready');
                    /*window.location = ur;*/
                }
            }).send();
        });
    }
}

function datePicker(){
    if($('demo_allow_empty')){
        new DatePicker('demo_allow_empty', {
            pickerClass: 'datepicker_dashboard',
            allowEmpty: true
        });
    }
}

/*for delete*/
function deleteone(url){
	var confirmdel = confirm("Are you sure you want to delete this record?");
	if(confirmdel==true){
		window.location = url;
	}
}

function DelSelected(){
    if($('chk_all')){
      $('chk_all').addEvent('click',function(){
          var x = $('chk_all').value;
          var chkMe = false;
          if(x==1){
            chkMe = true;
            $('chk_all').value = 0;
          }
          else{
            chkMe = false;
            $('chk_all').value = 1;
          }
          $$('.chkme').each(function(el){
            el.checked = chkMe;
          }) ;
      });
    }
}

function HighlighRow(){
    $$('table.grid tr').each(function(el,i){
        var _do = i % 2 ? "even" : "odd";
        el.addClass(_do);

        el.addEvent('click',function(){
            if(el.hasClass('highlight')){
               el.removeClass('highlight').addClass(_do);
            }
            else{
               el.removeClass(_do).removeClass('mo').addClass('highlight');
            }
        });
    });
}

function DivOverLay(){
    if($$('.trigme') && $('tm')){
        $('tm').setStyles({
            opacity:0,
            display:'block'
        });

        $$('.trigme').addEvent('click',function(){
            $('tm').fade('in');
            $('tm').fade('0.7');
        });

        $('tt').addEvent('click',function(){
            $('tm').fade('out');
        });
    }
}

function SubmitForm(){
    if($('frmcontact')){
        var mrForm = $('frmcontact');

        mrForm.addEvent('submit',function(e){
            new Event(e).stop();

            var mrRequest = new Request({
                method : 'post',
                url : $('sHide').value,
                onRequest : function(){},//{$('loader').set('html',loaderGif+'<br>Please Wait...');},
                onComplete : function(response){
                    $('loader').empty();
                    if(response){
                        Sexy.error(response);
                    }
                    else{
                        if($('slocation')){
                            window.location = $('slocation').value;
                        }
                    }
                }
            }).send(mrForm);
        });
    }
}

bkLib.onDomLoaded(function() {
    new nicEditor({fullPanel : true}).panelInstance('news-content');
});



