﻿/// <reference path="jquery.intellisense.js"/>
// =====================
// Close Accordian    
// =====================
function CloseAccPanels(id) {
  // change the classes
  document.getElementById('divHideShow'+id).style.visibility='hidden';
  document.getElementById('a'+id).className='arrow_closed';
  document.getElementById('aHead'+id).className='contents_headline_closed';
  $find('cpe'+id).collapsePanel();
  var hidState = document.getElementById('hid'+id);
  hidState.value = 'close';
//  // handle hiding of filters
//  if (id=='MAAcc') {
//    document.getElementById('divMAFilters').style.display='none';
//  }
};

// =====================
// Accordian Event Processing    
// =====================
function SetAccordians(panelid) {
	// panelid e.g MAAcc, PopAcc, FriendsAcc
  var obj = $find('cpe'+panelid);
  var hidState;
	hidState=document.getElementById('hid'+panelid)
  if (hidState.value=='open') {
    CloseAccPanels(panelid);
	}	
	else {		
		// open the panel
    // set the display style for the panel
    document.getElementById('divHideShow'+panelid).style.visibility='hidden';
    document.getElementById('divHideShow'+panelid).style.display='block';
    //expand the panel
    obj.expandPanel();
    hidState.value = 'open';        
    document.getElementById('divHideShow'+panelid).style.visibility='visible';
    // change the class
    document.getElementById('a'+panelid).className='arrow_open';
    document.getElementById('aHead'+panelid).className='contents_headline_open';
	}
};

// =====================
// hide/show alert setting details
// =====================
function ToggleAlertSetting(divid, alert, cpe) {
  // check to see what class is currently assigned to the div
  var div = document.getElementById(divid);
  var divclass = div.className;
  if (divclass=='alert_selected') {
    if (cpe=='cpeMA' || cpe=='cpeFriends'){
      // hide the lines and light edit
      document.getElementById(divid+'Display').style.display='none';
      document.getElementById(divid+'LinksDisplay').style.display='none';
    }
    // collapse the panel
    $find(cpe+alert).collapsePanel();
    // set the class of the div
    div.className='alert_deselected';
  }
  else {
    if (cpe=='cpeMA' || cpe=='cpeFriends') {
      // show the lines and line edit
      document.getElementById(divid+'Display').style.display='block';
      document.getElementById(divid+'LinksDisplay').style.display='block';
    }
    // expand the panel
    $find(cpe+alert).expandPanel();
    // set the class of the div
    div.className='alert_selected';
  }
}

// =====================
// hide/show notification details
// =====================
function ToggleNotification(divid, noti, cpe) {
  // check to see what class is currently assigned to the div
  var div = document.getElementById(divid);
  var divclass = div.className;
  if (divclass=='notification_selected') {
    // collapse the panel
    $find(cpe+noti).collapsePanel();
    // set the class of the div
    div.className='notification_deselected';
  }
  else {
    // expand the panel
    $find(cpe+noti).expandPanel();
    // set the class of the div
    div.className='notification_selected';
  }
}

// =====================
// Show Share Panel    
// =====================
function ShowSharePanel(elid, itemtype, notiid, alertid, userid, source) {
  // set the hidden field values of the panel
  document.getElementById('hidShareUserId').value = userid;
  document.getElementById('hidShareAlertId').value = alertid;
  document.getElementById('hidShareNotiId').value = notiid;
  document.getElementById('hidShareType').value = itemtype;
  document.getElementById('hidShareSource').value = source;
  // set the subject textbox value
  var subj;
  var heading;
  if (userid!=""){
    if (itemtype=='alert'){
      subj=document.getElementById('hid'+source+'Desc'+alertid).value;
      heading='Share Scout';
    }
    else if (itemtype=='noti') {
      subj=document.getElementById('hid'+source+'NotiDesc'+notiid).value;
      heading='Share Report';
    }
    // set the heading
    document.getElementById('spanSharePanelHeading').innerHTML=heading; 
    // set the subject
    document.getElementById('txtShareSubject').value = 'Check this out! '+subj;
    // set the location of the panel
    yuiSharePanel.cfg.setProperty("context", [elid, "tr", "br"]);
    // show the panel
    yuiSharePanel.show();
  }
  else{
    //show alert message indicating need to be logged in
    alert('You must be logged in to share scouts');
  }   
} 

// =====================
// Hide Share Panel    
// =====================
function CloseSharePanel(action) {
  var tbid;
  if (action=='send') {
    // process the sharing
    var userid = document.getElementById('hidShareUserId');
    var subj = document.getElementById('txtShareSubject');
    var msg = document.getElementById('txtShareBody');
    var chk = document.getElementById('chkShareSendMe');
    tbid = document.getElementById('hidShareEmailsTextBox').value;
    var to = document.getElementById(tbid);
    var itemtype = document.getElementById('hidShareType').value;
    var alertid = document.getElementById('hidShareAlertId').value;
    var notiid = document.getElementById('hidShareNotiId').value;
    var source = document.getElementById('hidShareSource').value;
    
    if (itemtype=='alert') {
      BNAlerts.Services.ShareAlert(userid.value, to.value, subj.value, msg.value, chk.checked, alertid, 8);
      SetAlertMsg('Your Scout was shared');
    }
    else if (itemtype=='noti') {
      BNAlerts.Services.ShareNotification(userid.value, to.value, subj.value, msg.value, chk.checked, alertid, notiid, 8);
      SetAlertMsg('Your Scout Report was shared');
    }    
  }
  // reset the To and Body
  document.getElementById('txtShareBody').value='';
  // close the panel
  yuiSharePanel.hide();
}
// =====================
// Truncate based on class assigned - uses jQueryTruncate plugin
// http://www.reindel.com/truncate/    
// =====================
$(function() {
    $(".bnTruncateSummary").truncate( 45,{
       chars: /\s/
   });
});
//$(function() {
//    $(".bnTruncate45").truncate( 45,{
//        chars: /\s/
//    });
//    $(".bnTruncateSafeEnd4518").truncateSafeEnd(45,18,{
//        chars: /\s/
//    });
//    $(".bnTruncateMid20").truncateMid(20,{
//        chars: /\s/
//    });
//});