﻿// JScript File


myWait = "<IMG SRC='../../images/icons/please_wait.gif' align='center' ALT='' border='0'>"

var max_image_width = 0;
var max_image_height = 0;
var subnet_username = "";
var subnet_country = "";
var subnet_diocese = "";
var photo_array;
var myPhotoCount = 0;
var myThumbCount = 0;
var myThumbDisplay = 5;
var myStartPhoto = 0;
var interval = "";
var myGalleryID = "";
var myCurrent = "";

var mySlideShowRunning = 0;

var w = 0;
var  h = 0;
var myWidth = 0;
var myHeight = 0;

function startup(){
    alertSize();
   w = myWidth;
    myDiv = document.getElementById('floating_div');
    myDiv.style.left=0;
    myDiv.style.width=myWidth;
    myDiv.style.height=myHeight * 1.5;
    checkForChanges() 
}

function alertSize() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
}

function checkForChanges()
{ 
     setInterval("sizeDetect()", 200); 
}

function sizeDetect()
{
    alertSize();
     if(!(w == myWidth))
     {
          w = myWidth;
          myDiv = document.getElementById('floating_div');
          myDiv.style.width=myWidth;
          myDiv.style.height=myHeight * 1.5;
     }
}

function getGallery(gallery_id, username, requestType, par1){

               myGalleryID = gallery_id;   
               subnet_username = username;
               
               if  (requestType != "6"){
                       var myRegExp = new RegExp(/\_/)
                       myDirArray = username.split(myRegExp);
                       subnet_country = myDirArray[0]
                       subnet_diocese = myDirArray[1]
               }
              else
              {
                myRenameValue = username
               }
               
               //Rename the Gallery
               if  (requestType == "1"){
                   var myRename = document.getElementById("rename_box_" + par1);
                   var myRenameValue =  myRename.value
               }
               else
               {
                       if  (requestType == "6" || requestType == "7"){
                                   if  (requestType == "6"){
                                            var myCommunitySpan = document.getElementById("community_wait_" + username);
                                           myCommunitySpan.innerHTML = myWait;
                                   }
                                myRenameValue = username
                       }
                      else
                      {
                                myRenameValue = ""
                       }
               }
                
                myReturn =  gallery_id + "`" + requestType + "`" + myRenameValue + "`" + par1
               // alert(myReturn);
                UseCallback_gallery(myReturn);
    
}

function GetGalleryFromServer(TotalStr, context){
   // alert(TotalStr);
    
    var myRegExp = new RegExp(/\`/)
    var myTotal = TotalStr;
    myTotalArray = myTotal.split(myRegExp);   
   
    if (myTotalArray[0] == "#") {
     
                        var a = window.location.href                    
                        window.location.href = a

    }
    else
    {     
        if (myTotalArray[0] == "%") {
         
                                                var myCommunitySpan = document.getElementById("community_wait_" + myTotalArray[1]);
                                               myCommunitySpan.innerHTML = "";

        }
        else
        {  
              if (myTotalArray[0] == "1") {
                          //alert(myTotalArray[2])
                          myEdit = document.getElementById("rename_area_" + myTotalArray[1]);
                          myEdit.innerHTML = myTotalArray[2]
                   }
                   else
                   {
                           if (myTotalArray[0] == "1") {
                                  //alert(myTotalArray[2])
                                  myEdit = document.getElementById("rename_area_" + myTotalArray[1]);
                                  myEdit.innerHTML = myTotalArray[2]
                           }
                           else
                           {
                                
                                        
                               var javaWords = document.getElementById("java_words").value; 
                               var myRegExp2 = new RegExp(/\|/)
                               javaWords_array = javaWords.split(myRegExp2);    
                                    
                                var myRegExp = new RegExp(/\|/)
                                var myPhotos = myTotalArray[2];
                                photo_array = myPhotos.split(myRegExp);    
                                                         
                                //     alert("myTotalArray: " +   myTotalArray.length);
                           
                                      if (myTotalArray.length == 3){
                                     
                                           // alert(javaWords_array[6]);
                                      
                                      
                                     }
                                     else
                                     {
                                
                                           //set the headet title of the gallery 
                                            var myGalleryTitle = document.getElementById("gallery_title_div");
                                            myGalleryTitle.innerHTML = "<p class='header_gallery_name'>" + myTotalArray[3] + "</p>";

                                            showThumbs(0);   
                                            
                                            showPhoto(myPhotoCount)    
                                             
                                        //    var myPrev = document.getElementById("prev_div");
                                        //    myPrev.style.visibility = 'hidden';
                                            var myAd = document.getElementById("ad1_java");
                                            myAd.style.display = 'none';
                                            var myGallery = document.getElementById("floating_div");
                                            myGallery.style.visibility = 'visible';
                                            var myGallery = document.getElementById("nav_container");
                                            myGallery.style.visibility = 'visible';
                                            var myGallery = document.getElementById("info_div");
                                            myGallery.style.visibility = 'visible';
                                       
                                      }  
                           
                           } 
                  }
         }
         }
}


function nextPhoto(){
   if (myPhotoCount < photo_array.length - 1){
        myPhotoCount = myPhotoCount + 1
   }
   
    showPhoto(myPhotoCount)

}

function prevPhoto(){
   if (myPhotoCount > 0){
        myPhotoCount = myPhotoCount - 1   
   }
 
    showPhoto(myPhotoCount)
}

function showPhoto(myVar){

       var javaWords = document.getElementById("java_words").value; 
       var myRegExp2 = new RegExp(/\|/)
       javaWords_array = javaWords.split(myRegExp2);    
        
                
       var myRegExp = new RegExp(/\~/)
       var myPhotos = photo_array[myVar];
       photo_details_array = myPhotos.split(myRegExp);    
       var myPhoto = "http://www.cathspace.com/general/image_display/display_image.aspx?" + photo_details_array[0] + "&size=400"
       document.images["main_photo"].src = myPhoto;

        var myTitle = document.getElementById("photo_title"); 
        myTitle.innerHTML = "<p class='photo_title'>" + photo_details_array[1] + "</p>";
       
        var myEditPhoto = document.getElementById("info_area"); 
        myEditPhoto.style.visibility = 'hidden'; 
        var myEditPhoto = document.getElementById("info_area"); 
        myEditPhoto.style.visibility = 'hidden'; 
             
     var myNext = document.getElementById("next_div");  
     if (myPhotoCount == photo_array.length - 1){
        myNext.style.visibility = 'hidden';
        }   
       else
       {
        myNext.style.visibility = 'visible';
       } 
 
     var myPrev = document.getElementById("prev_div");  
     if (myPhotoCount > 0){
        myPrev.style.visibility = 'visible';
        }   
       else
       {
        myPrev.style.visibility = 'hidden';
       }           
        
}

//when a thumbnail is clicked this diplays that thumbnail based on the photo array number

function gotoPhoto(myVar){
    myPhotoCount = myVar
  if (myVar < photo_array.length - 1){
        var myNext = document.getElementById("next_div");
        myNext.style.visibility = 'visible';
   }
   else
   {
        var myNext = document.getElementById("next_div");
        myNext.style.visibility = 'hidden';
   }

   if (myVar > 0){          
        var myPrev = document.getElementById("prev_div");
        myPrev.style.visibility = 'visible';
   }  
   else
   {
        var myPrev = document.getElementById("prev_div");
        myPrev.style.visibility = 'hidden';
   }
    showPhoto(myVar)
}

//displays five thumbnails at the top of gallery

function showThumbs(myVar){    
   var myThumb_Div = document.getElementById("nav_thumbs");  
   myCount = 0 

    var myThumb = "<table width=1 cellspacing='2'><tr valign='top'>"
    
   if (myThumbCount > 0) {
    myThumb = myThumb + "<td><a href='javascript:prevThumb();' style='color:white'><img src='../../images/gallery/left_small.gif' border='0' /></a></td>" 
   }
   
   var thumb_array = photo_array
   
    for(x=myVar;x<photo_array.length;x++){
    
        myCount = myCount + 1 
       
        var myRegExp = new RegExp(/\~/)
        var myThumbs = thumb_array[x];
        thumb_details_array = myThumbs.split(myRegExp);     
       
        myThumb = myThumb + "<td><a href='javascript:gotoPhoto(" + x + ");'><img src='http://www.cathspace.com/general/image_display/display_image.aspx?" + thumb_details_array[0] + "&size=50&u=1' border='0' ></a></td>"

       if(myCount == myThumbDisplay){
            x = thumb_array.length
       } 
       
    } 
  
   if (myThumbCount < thumb_array.length - myThumbDisplay) {
    myThumb = myThumb + "<td><a href='javascript:nextThumb();' style='color:white'><img src='../../images/gallery/right_small.gif' border='0' /></a></td></tr></table>"
   }

    myThumb_Div.innerHTML = myThumb
} 


function nextThumb(){

   myThumbCount= myThumbCount + 1
   showThumbs(myThumbCount); 

}

function prevThumb(){

   myThumbCount= myThumbCount - 1
   showThumbs(myThumbCount); 

}


function showGallery(){
    var myEntirePage = document.getElementById("transbox");
    myEntirePage.style.filter = "alpha(opacity=20)";
    myEntirePage.style.filter.apply;
    var myGallery = document.getElementById("nav_container");
    myGallery.style.visibility = 'visible';
    var myGallery = document.getElementById("info_div");
    myGallery.style.visibility = 'visible';
    var myGallery = document.getElementById("floating_div");
    myGallery.style.visibility = 'visible';
}

function hideGallery(){
    stopInterval();
    var myNext = document.getElementById("next_div");
    myNext.style.visibility = 'visible';
    var myPrev = document.getElementById("prev_div");
    myPrev.style.visibility = 'visible';
    var myPhoto = "http://www.cathspace.com/images/spacer.gif"
    document.images["main_photo"].src = myPhoto;
    myPhotoCount = 0;
    myThumbCount = 0;
    var myEditPhoto = document.getElementById("info_area"); 
    myEditPhoto.style.visibility = 'hidden';
    var myNext = document.getElementById("next_div");
    myNext.style.visibility = 'hidden';
    var myPrev = document.getElementById("prev_div");
    myPrev.style.visibility = 'hidden';
    var myGallery = document.getElementById("info_div");
    myGallery.style.visibility = 'hidden';
    var myGallery = document.getElementById("nav_container");
    myGallery.style.visibility = 'hidden';   
    var myEntirePage = document.getElementById("transbox");
    var myAd = document.getElementById("ad1_java");
    myAd.style.display = 'block';
    myEntirePage.style.filter = "alpha(opacity=100)";
    myEntirePage.style.filter.apply;
   myEntirePage.display = 'none'; 
    var myGallery = document.getElementById("floating_div");
    myGallery.style.visibility = 'hidden';   
}

function showUpload(myVal){
    var myGallery = document.getElementById("upload_html");
   var myTag = document.getElementById("hide_show");

    myGallery.style.display = (myGallery.style.display == "none")?"inline":"none";
   
//     if (myGallery.style.display == "none") 
//        {  
//            myTag.innerHTML = "show upload";
//        }
//    else
//        {  
//            myTag.innerHTML = "hide upload";
//        }
}


function slideShow()
{ 
 if (mySlideShowRunning == 1)
 {
    stopInterval();
    showPhoto(myPhotoCount)
}
else
{
    myStartPhoto = myPhotoCount
    startInterval();
    var myGallery = document.getElementById("nav_container");
    myGallery.style.visibility = 'hidden';          
    var myGallery = document.getElementById("info_div");
    myGallery.style.visibility = 'hidden';
}
}


function startInterval()
{
    interval = window.setInterval("nextSlide()",4000);
}

function stopInterval()
{
    window.clearInterval (interval);
    interval="";
    var myGallery = document.getElementById("nav_container");
    myGallery.style.visibility = 'visible';
    var myGallery = document.getElementById("info_div");
    myGallery.style.visibility = 'visible';
    mySlideShowRunning = 0;      
}

function nextSlide(){
  //alert("mySlideShowRunning " + mySlideShowRunning+ "myStartPhoto " + myStartPhoto + "myPhotoCount " + myPhotoCount);
   if (mySlideShowRunning == 1 && myStartPhoto == myPhotoCount)
   {
        //alert("stop");
        stopInterval();
   }
   else
   {
        //alert("run");
        mySlideShowRunning = 1;
        myPhotoCount = myPhotoCount + 1;
   }
   
    showPhoto(myPhotoCount)
   
        if(myPhotoCount == photo_array.length - 1){
            myPhotoCount = -1
       }  

}


function displayEdit(gallery_id, username, myVal, myDelete)
{ 

//alert(gallery_id + " _ " + username + " _ " + myVal + " _ " + myDelete)

        myEdit = document.getElementById('edit_area_' + myVal);
        
         if (myEdit.style.display == 'inline')
        {  

            document.images["arrow_textbox_"+(myVal)].src = "../../images/portal/right_gray.gif"; 
            myEdit.style.display = 'none';
             document.getElementById("community_area_" + gallery_id).style.display  = "none"; 

        }
        else
        {
       
         document.images["arrow_textbox_"+(myVal)].src = "../../images/portal/down_gray.gif"; 
         myEdit.style.display = 'inline';

       
        }     
        
       var javaWords = document.getElementById("java_words").value; 
       
       var myRegExp2 = new RegExp(/\|/)
       javaWords_array = javaWords.split(myRegExp2);    

          if (myDelete == 0)
          {
              myEdit.innerHTML = "<p class='list_gallery_details' align='right'><a href='javascript:renameEdit(&quot;" + gallery_id + "&quot;,&quot;" + username + "&quot;," + myVal + ");'>" + javaWords_array[0] + "</a> | <a href='javascript:uploadEdit(&quot;" + gallery_id + "&quot;," + myVal + ");'>" + javaWords_array[1] + "</a> | <a href='javascript:unlinkEdit(&quot;" + gallery_id + "&quot;);'>" + javaWords_array[3] + "</a> | <a href='javascript:deleteEdit(&quot;" + gallery_id + "&quot;,&quot;" + username + "&quot;," + myVal + ",2);'>" + javaWords_array[4] + "</a></p>"
          }
          else
          {
                  if (myDelete == 1)
                  {
                      myEdit.innerHTML = "<p class='list_gallery_details' align='right'><a href='javascript:renameEdit(&quot;" + gallery_id + "&quot;,&quot;" + username + "&quot;," + myVal + ");'>" + javaWords_array[0] + "</a> | <a href='javascript:uploadEdit(&quot;" + gallery_id + "&quot;," + myVal + ");'>" + javaWords_array[1] + "</a> | <a href='javascript:openCommunities(&quot;" + gallery_id + "&quot;);'>" + javaWords_array[2] + "</a> | <a href='javascript:deleteEdit(&quot;" + gallery_id + "&quot;,&quot;" + username + "&quot;," + myVal + ",2);'>" + javaWords_array[4] + "</a></p>"
                  }
                  else
                  {
                      myEdit.innerHTML = "<p class='list_gallery_details' align='right'><a href='javascript:renameEdit(&quot;" + gallery_id + "&quot;,&quot;" + username + "&quot;," + myVal + ");'>" + javaWords_array[0] + "</a> | <a href='javascript:uploadEdit(&quot;" + gallery_id + "&quot;," + myVal + ");'>" + javaWords_array[1] + "</a></p>"
          }          
          }

}

function renameEdit(gallery_id, username, myVal)
{ 
    myRenameBox = document.getElementById('rename_box_' + myVal);
  
    if (myRenameBox == null) {
          myRename = document.getElementById('rename_area_' + myVal);
          myCurrent = myRename.innerText
          myCurrent2 = myRename.innerHTML
          myRename.innerHTML = "<p class='list_gallery_details'><input id='rename_box_" + myVal + "' type='text' size=45 class='box_one' value='" + myCurrent +"' />&nbsp;<a href='javascript:getGallery(&quot;" + gallery_id + "&quot;,&quot;" + username + "&quot;,1," + myVal + ");'>" + javaWords_array[7] + "</a>"
        }
       else
       {
          myRename = document.getElementById('rename_area_' + myVal);
          myRename.innerHTML = myCurrent2;
       } 

}

function uploadEdit(myGalleryId, myVal)
{ 
    if (myGalleryId != '00000000-0000-0000-0000-000000000000'){
          myRename = document.getElementById('rename_area_' + myVal);
          myCurrent2 = myRename.innerText
          myCurrent = myRename.innerHTML;
          myGalleryTitle = document.getElementById("gallery_upload_title");
          myGalleryTitle.innerHTML = myCurrent;
          Hidden1 = document.getElementById("gallery_upload1_gallery_title_hidden");
          Hidden1.value= myCurrent2;
          Hidden2 = document.getElementById("gallery_upload1_gallery_id_hidden");
          Hidden2.value= myGalleryId;
      }
      else
      {
          myGalleryTitle = document.getElementById("gallery_upload_title");
          myGalleryTitle.innerHTML = "<p class='header_14'>New Gallery</p>";
      }
          showUpload(myVal);
}

function unlinkEdit(gallery_id)
{ 

       var javaWords = document.getElementById("java_words").value; 
       var myRegExp2 = new RegExp(/\|/)
       javaWords_array = javaWords.split(myRegExp2);    
       
        var YesNo = confirm(javaWords_array[8])
        if (YesNo == true) {
                   getGallery(gallery_id,"",7,"");
        } 
} 


function deleteEdit(gallery_id, username, myVal, myDelete)
{ 

       var javaWords = document.getElementById("java_words").value; 
       var myRegExp2 = new RegExp(/\|/)
       javaWords_array = javaWords.split(myRegExp2);   
    if (myDelete == 2){
        var YesNo = confirm(javaWords_array[9])
        if (YesNo == true) {
                   getGallery(gallery_id,username,2,myVal);
        } 
       else 
       {
            var YesNo = confirm(javaWords_array[10])
            if (YesNo == true) {
                       getGallery(gallery_id,username,5,myVal);
            } 
        } 
   }
   else
   { 
        var YesNo = confirm(javaWords_array[11])
        if (YesNo == true) {
                   getGallery(gallery_id,username,3,myVal);
        } 
    } 

}

function newEdit(){

    getGallery("","",300,"");

}

function openCommunities(myDiv){

//if (document.getElementById("community_plus_" + myDiv).style.display == "none"){

//    document.getElementById("community_plus_" + myDiv).innerHTML = "-"
//    
//}
//else
//{

//    document.getElementById("community_plus_" + myDiv).innerHTML = "+"
//    
//} 

    document.getElementById("community_area_" + myDiv).style.display = (document.getElementById("community_area_" + myDiv).style.display == "none") ? "inline" : "none";

}

//       function sendBlogAssociationsDetails(myBlogId, myCommunityId, myCommunityType, myCommunityName, actionType){
//           
//          if (actionType == 'd'){
//          
//                 if (confirm("Do you want to remove this blog from this community meeting point?")) {
//                 //alert("yes")
//                    UseCallback_blog_association(myBlogId + "|" + myCommunityId + "|" + myCommunityType + "|d");
//                 } 
//                 else 
//                 {
//                 //alert("no")
//                 }          
//          }
//          else
//          {
//           
//                 if (confirm("Do you want to add this blog to the community meeting point of " + myCommunityName + "?")) {
//                 //alert("yes")
//                    UseCallback_blog_association(myBlogId + "|" + myCommunityId + "|" + myCommunityType + "|a");
//                 } 
//                 else 
//                 {
//                 //alert("no")
//                 }
//          }
//        }
//      

//       function returnBlogAssociationFromServer(TotalStr, context){
//            alert(TotalStr);
//       }
