    var ImageControls = new Array();
    var nMainImageHeight;
    var nThumbHeight;
    var bEnabled;
   
    
	function DhJS_ImageControl(sDisplayName, sImageUrl, sCaption, nImageWidth, nImageHeight, sAltText)
    {
           this.Image = new Image;
		   this.Image.src = sImageUrl
		   this.Image.name = sDisplayName;
		   this.Image.width = nImageWidth;
		   this.Image.height = nImageHeight;
		   this.Image.alt = sAltText
		   this.Image.Description = sCaption
	}
	
	function SwapImage(intId)
	{		
	    var elMain;
	    var elDisplayName;

		elMain = window.document.getElementById("main");
		elDisplayName = window.document.getElementById("displayName");

		elMain.src = ImageControls[intId].Image.src;
		elMain.width = ImageControls[intId].Image.width;
		elMain.height = ImageControls[intId].Image.height;
		
		if(elDisplayName.textContent)
		   elDisplayName.textContent = ImageControls[intId].Image.name;
		else   
		   elDisplayName.innerText = ImageControls[intId].Image.name;	
			
		return false;
	}
	
	
	function OnAddImage()
	{
	    if ( window.document.getElementById("ImageTitle").value == "" )
		{
		    alert("You must enter a title for the image. The title will be displayed under the image on the gallery page of the website.");
			return false;
		}
		
		
		var strImage = window.document.getElementById("mainimage").value
	    var str = strImage.toLowerCase() 
		if  ( str.indexOf(".jpg") == -1 && str.indexOf(".jpeg") == -1 && str.indexOf(".gif") == -1 )
		{
		     alert("Images must be jpeg or gif images. If the image is in a different format, open it in an image editing program and save it as a jpeg.");
			 window.document.getElementById("mainimage").value = "";
			 return false;		
		} 
		return true;
	}
   
    function OnEditImage()
	{
	    if ( window.document.getElementById("ImageTitle").value == "" )
		{
		    alert("You must enter a title for the image. The title will be displayed under the image on the gallery page of the website.");
			return false;
		}
		
		var str = window.document.getElementById("mainimage").value
	    str = str.toLowerCase();
		if  ( str != "" && str.indexOf(".jpg") == -1 && str.indexOf(".jpeg") == -1 && str.indexOf(".gif") == -1)
		{
		     alert("Images must be jpeg images. If the image is in a different format, open it in an image editing program and save it as a jpeg.");
			 return false;		
		} 
		
		return true;
	}
   
   function OnDeleteImage()
   {
       return confirm("Are you sure you wish to delete this image?");
   }
   
   
   function onTextItemDelete()
   {
       return confirm("Are you sure you wish to delete this item?");
   }
   
   function onAddEditTextPage(strMode)
   {
	   if (strMode == "Add")
	   {
	       if (window.document.getElementById("Title_CaseStudy").value == "" && window.document.getElementById("Body_CaseStudy").value == "" && window.document.getElementById("Image").value == "")
		   {
		        alert("Cannot add an empty section. Please enter either a title, text, or image, or any combination of these items.");
				return false;
			}       
	   }
	   else
	   {		    
		   if (Rtrim(window.document.getElementById("Title_CaseStudy").value) == "" && Rtrim(window.document.getElementById("Body_CaseStudy").value) == "" && HasNoImages() )
	       {
	            alert("Cannot add an empty section. Please enter either a title, text, or image, or any combination of these items.");
				return false;
	       }
	   }    
       return true;
   }
   
   function Rtrim(strVal)
   {
	   if (strVal)
	   {
		   for (i = 0; i < strVal.length; i++ )
		   {
		       if (strVal.charAt(i) != " ")
			   {
				  return strVal.substr(i, strVal.length)
		        }
		   }
		   return ""
	   }
	   else
	      return ""
   }
   
   	function IsInteger(strArg)
	{
	    try
		{
		
	    	if( ! strArg)
		       return false;
		   else
		   {
		       var c;
			   var sNums = "0123456789";
			   
			   for (c = 0; c < strArg.length; c++)
			   {
			      sChar = strArg.substr(c, 1); 
				  if (sNums.indexOf(sChar) == -1 )
				      return false;
			   }
		   
		   }
		
		   return true;
		
		}
		catch(e)
		{
		    return false;
		}
	
	}
	
	function onEditGallery()
	{	
		var aryConfirm = new Array();
		var nConfirmCount = 0;
		var bResize = false;
		var strConfirm = "";
		var nIndex;
		
		if (! IsInteger( window.document.getElementById("ImageHeight").value ))
		{
		    alert("The Image Height Must Be Numeric. Fractions or decimals are not allowed.");
			return false;
		}
		
		if (! IsInteger( window.document.getElementById("ThumbHeight").value ))
		{
		    alert("The Thumbnail Height Must Be Numeric. Fractions or decimals are not allowed.");
			return false;
		}
		/*    var nMainImageHeight;
    var nThumbHeight;
    var bEnabled; */
        //alert(nMainImageHeight + "  " + nThumbHeight + "   " + bEnabled);
       //alert(window.document.EditParagraph.Enabled);
        if (window.document.getElementById("Enabled").checked != bEnabled)
        {
            if (bEnabled)    
                aryConfirm[nConfirmCount++] = "disable this gallery from being viewed";   
            else
                aryConfirm[nConfirmCount++] = "enable this gallery";      
        }
           
        if (window.document.getElementById("ImageHeight").value != nMainImageHeight)
        {
            bResize = true;
            aryConfirm[nConfirmCount++] = "resize all main images" 
            
        }
        
        if (window.document.getElementById("ThumbHeight").value != nThumbHeight)
        {
            bResize = true;
            aryConfirm[nConfirmCount++] = "resize all thumbnail images" 
            
        }
        
        if ( nConfirmCount > 0 )
        {
            strConfirm = "This action will ";
            
            for (nIndex = 0; nIndex < nConfirmCount; nIndex++)
            {
               if( (nConfirmCount > 1) && (nIndex == nConfirmCount - 1) )
                  strConfirm += "and ";
               else if((nConfirmCount > 1) && (nIndex < nConfirmCount - 1))
                  strConfirm += ", ";
                strConfirm +=  aryConfirm[nIndex] + " \r";              
            }
            
            if (bResize == true)
               strConfirm += "Resizing the gallery images may take a few moments, depending on how many images are in this gallery. \r";
            
            strConfirm += "Click OK to continue or Cancel to stop.";  
            return confirm(strConfirm);
        
        }       
		return true;
	}
   
   function HasNoImages()
   {
		if (window.document.getElementById("RemoveImage"))
		{
		     if (  window.document.getElementById("RemoveImage").checked == true)
			 {
				return true;
			 }
        }
		
		
		if (window.document.getElementById("Image").value == "" )
		{
		    if (window.document.getElementById("CurrentImage") )
		    {
			    if( window.document.getElementById("CurrentImage").value == "" )
			    {
					 return true;
			     }
			}    
		    else
            {
			    return true;	    
		     }
		} 
		return false;
   }
   