//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   B . C .   C O N S U L T I N G   G R O U P
//      C U S T O M   S O F T W A R E   S O L U T I O N S
//
//   W E B   B A S E D   S O L U T I O N S
//      J A V A S C R I P T   F U N C T I O N A L I T Y   D O C U M E N T
//      F O R   I M A G E   H A N D L E R   M O D U L E S   v 1 . 0 4
//
//      ( C ) 2 0 0 5 - 0 7   B . C .   C O N S U L T I N G
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                A L E R T   N O T I F I C A T I O N S
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
 var catNmeToShrt = "Category Name is too short.";
 var descToShrt = "Description is too short.";
 var noGalKeyImg = "In order to enable the gallery feature, you must select an image for the Gallery Selector.";
 var noFileSelected = "No file was selected to upload.";
 var noImageName = "You need to provide this image with a name.";
//
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   I M A G E  +  C A T E G O R Y   A D M I N I S T R A T I V E   F U N C T I O N S
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//----------------------------------------------------------------------
//  doIDchange - Change event id on admin edit/add form.
//----------------------------------------------------------------------
 function doIDchange(efObj){
   document.location = '?' + efObj.name + '=' + efObj.options[efObj.selectedIndex].value
 }
//

 function doFileAdm(thObj){
//define the form object...

  var frmObj = document.FileFrm;
//Check OpMode for process...
//------------------------------------------------

  if(frmObj.OpMode.value == 1){ //Delete image mode
    var minSelected = false; //create min object flag
   //Loop each form object to find at least one checked box
    for(x = 0; x < frmObj.elements.length; x++){
      if(frmObj.elements[x].type == 'checkbox'){
        if(frmObj.elements[x].checked){ minSelected = true; }
      }
    }
   //Check if at least one delete is checked.
    if(!minSelected){ return false; }
   //Set next operation stage code
    frmObj.OpMode.value = "4";
  } //Close OpMode 1
//------------------------------------------------

  if(frmObj.OpMode.value == 2){ //Add image mode
   //check that a file was selected
    if(frmObj.File0.value.length < 1){
      alert(noFileSelected);
      frmObj.File0.focus();
      return false;
    }
   //check that the image has a name for alt tag
    if(frmObj.Name0.value.length < 1){
      alert(noImageName);
      frmObj.Name0.focus();
      return false;
    }
   //Set next operation stage code
    frmObj.OpMode.value = "5";

  } //Close OpMode 2

//------------------------------------------------

  if(frmObj.OpMode.value == 3){ //Change image settings mode
   //check that the image has a name for alt tag
    if(frmObj.Name0.value.length < 1){
      alert(noImageName);
      frmObj.Name0.focus();
      return false;
    }
   //Set next operation stage code
    frmObj.OpMode.value = "6";

  } //Close OpMode 3
//------------------------------------------------

//Now Submit the form to save the new password.
   return true;
 }
//
//----------------------------------------------------------------------
//  doDelimgCat - Delete current image category & associated galleries.
//----------------------------------------------------------------------
 function doDelimgCat(thsObj){
   var frmObj = thsObj.form;
   var evtID = frmObj.CatID.options[frmObj.CatID.selectedIndex].value;
   var evtDscr = frmObj.Summary.value;
   if(confirm("Are you sure you wish to delete Category #" + evtID + " known" + CrLf + " as '" + evtDscr + "' ?")){
     frmObj.OpMode.value = "2";
     frmObj.submit();
   }else{
     alert("Delete aborted.");
   }
 }
//----------------------------------------------------------------------
//  doEvtImgSelector - Open the Image Selector window.
//----------------------------------------------------------------------
 function doImgSelector(catID){
   Opening('../nav/img_chooser.php?CatID=' + catID,350,800,'imgSelWin');
 }
//----------------------------------------------------------------------
//  doSelImg - Select an Image from the Image Selector Window and
//                pass the ID value back to the parent form.
//----------------------------------------------------------------------
 function doSelImg(imgID){
   var imgSObj = opener.document.getElementById('ImageID');
   var frmObj = imgSObj.form;
   frmObj.ImageID.value = imgID;
   frmObj.submit_btn.disabled = false;
   window.close();
 }
//----------------------------------------------------------------------
//  doAdmSaveImgCat - Handle the event admin edit/add form.
//----------------------------------------------------------------------
 function doAdmSaveImgCat(thsObj){
   var frmObj = document.imgcat_edit;
   //var frmObj = thsObj.form;
//Check OpMode for process...
//------------------------------------------------
  if(frmObj.OpMode.value == 0){  //Event form input compliance tests
  //Check for a summary that is too short.
   if(frmObj.Summary.value.length < 4){
     alert(catNmeToShrt);
     frmObj.Summary.focus();
     return false;
   }
  //Check for a description that is too short.
   if(frmObj.Description.value.length < 8){
     alert(descToShrt);
     frmObj.Description.focus();
     return false;
   }
  //Check for a keyImage if Gallery turned on
   if(frmObj.mkGallery.options[frmObj.mkGallery.selectedIndex].value != 0 && frmObj.ImageID.value < 1){
     alert(noGalKeyImg);
     frmObj.ImageID.focus();
     return false;
   }
  //Disable the UI in prep for submit...
   frmObj.submit_btn.disabled = true;
   frmObj.OpMode.value = '1';  //Setup for save stage
  } //Close OpMode 0 If
  return true; //Go and submit!  :-]
 }
//
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//                I M A G E   H A N D L E R   F U N C T I O N S
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//

//----------------------------------------------------------------------
//  doImage - resizes the pop up full size image window to the
//                 size of the image or maximum screen and then
//                 resizes the image to match the window.
//----------------------------------------------------------------------

 function doImage(imgID){
  Opening('sec-imgpop.php?ImgID=' + imgID,200,200,'imgWin',false);
  return;
 }
//----------------------------------------------------------------------
//  resizeImgWin - resizes the pop up full size image window to the
//                 size of the image or maximum screen and then
//                 resizes the image to match the window.
//----------------------------------------------------------------------

 function resizeImgWin(){
 //Check that App version is new enough to support these calls
   if (parseInt(navigator.appVersion) < 4) {
     alert(oldBrowser);
     return;
   }
 //Find the size of the window
   if (navigator.appName == "Netscape") {
     var cWidth = window.innerWidth;
     var cHeight = window.innerHeight;
   }
   if (navigator.appName.indexOf("Microsoft") != -1) {
     var cWidth = window.document.body.offsetWidth;
     var cHeight = window.document.body.offsetHeight;
   }
 //Find placeholder image size
   var newHeight = (document.enlgImage.height + 20);
   var newWidth = (document.enlgImage.width + 20);
 //If image larger than the screen, compensate.
   if(newHeight > (screen.height - 30)){ newHeight = (screen.height - 30); }
   if(newWidth > (screen.width - 10)){
     newWidth = Math.round((document.enlgImage.width * (screen.height - 30)) / document.enlgImage.height)
   }
 //Resize the window to the appropriate image or screen dimensions.
   window.resizeTo(newWidth,newHeight);
 //Center Window to screen
   var newX = ((screen.width - 10) - newWidth) / 2;
   var newY = ((screen.height - 30) - newHeight) / 2;
   moveTo(newX,newY);
 //Resize the div embeded image to the new window size.
   document.realImg.height = newHeight;
   document.realImg.width = newWidth;
 //Resize the fakeout image to the new window size.
   document.enlgImage.height = newHeight;
   document.enlgImage.width = newWidth;
 //Set the onResize handler to rescale if window resizes.
   window.onresize = resizeImgWin;
 }
//----------------------------------------------------------------------
//  imgWinSetup - creates the div and real image tags to produce a
//                "background" image behind the fake spacer image.
//                Image is setup to the proper height and width of the
//                popup window.  This is done to prevent image theft.
//----------------------------------------------------------------------
 function imgWinSetup(){
 //Check that App version is new enough to support these calls
   if (parseInt(navigator.appVersion) < 4) {
     alert(oldBrowser);
     return;
   }
 //Find the size of the window
   if (navigator.appName == "Netscape") {
     var cWidth = window.innerWidth;
     var cHeight = window.innerHeight;
   }
   if (navigator.appName.indexOf("Microsoft") != -1) {
     var cWidth = window.document.body.offsetWidth;
     var cHeight = window.document.body.offsetHeight;
   }
 //Create the embeded div and img tags.
   var imgStr = "<div id='enlgImg' style='position:absolute;left:0;top:0;z-index:-1'><img name='realImg' border=0 src='" + file_src + "' width='" + cWidth + "' height='" + cHeight +"'></div>";
 //Write the tag to the browser... but make it will not appear in view source!
   document.write(imgStr);
 }
//
//---------------------------------------------------------------------------
//             * * * *   E N D   O F   F I L E   * * * *
//---------------------------------------------------------------------------
