var wid;
// get next image on details scroll
function NextImage(direction, imgID)
{
//debugger;
	if (direction == 'f')
	{
		currentIndex = currentIndex + 1;
		if (currentIndex >= image_url.length)  currentIndex = 0;
		
	}
	else //direction = 'b'
	{
		currentIndex = currentIndex - 1;
		if (currentIndex < 0)  currentIndex = image_url.length-1;
		
	}
	
	var gfx = document.getElementById("gfx_img");
	var counter;
		
	if (imgID != null)
	{
		gfx.src = image_url[imgID];
		counter = imgID+1;
		currentIndex=imgID;
	}
	else
	{
		gfx.src = image_url[currentIndex];
		counter = currentIndex+1;
	}
	
	imgCounter.innerHTML=counter + ' of ' + image_url.length + ' Photos';
	
}

// get first image in details scroll
function FirstImage()
{
	var gfx = document.getElementById("gfx_img");
	gfx.src = image_url[0];
	imgCounter.innerHTML=1 + ' of ' + image_url.length + ' Photos';
}

function showPopUp(webID,type,w,h) 
{
	window.open('/DesktopModules/CooperAndCooper/PopUp.aspx?webID=' + webID + '&type=' + type, '_blank', 'height='+h+',width='+w+',toolbar=no,directories=no,status=no, menubar=no,scrollbars=yes,resizable=no,modal=yes'); 
}//showPopUp 


function showPrintListing(webID,type) 
{
	window.open('/DesktopModules/CooperAndCooper/PrintVersion.aspx?webID=' + webID + '&type=' + type, '_blank', 'height=550,width=700,toolbar=no,directories=no,status=no, menubar=no, scrollbars=yes, resizable=yes,modal=yes'); 
}//showPopUp 


function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function



