//Copyright (c) 2002 Dovetail Internet Technologies, LLC 
//Made for the exclusive use of Dovetail Internet Technologies, LLC 
//All Rights Reserved.

///////////////////////
//function: linkout
//Purpose: Open linkout confirmation page, and send the parameters correctly
//Context: Called by linkout to open the confirmation window.
//-------------
//
function linkout(url)
{

//url = replaceSubstring(url,':','\\:');
//url = replaceSubstring(url,'/','\\/');


	//open_window('http://' + window.location.hostname + 'linkout.aspx?' + url,'_blank',0,0,0,1,1,500,300,120) 
	open_window('linkout.aspx?' + url,'_blank',0,0,0,1,1,800,520,120) 
}

///////////////////////
//function: open_window
//Purpose: Opens a window with the specified characteristics
//Context: Called by linkout to open the confirmation window.
//-------------
function open_window(url,wname,dir,status,menu,scroll,resize,width,height,top) {		

		var mywin = window.open(url,wname,'directories='+dir+',status='+status+',menubar='+menu+',scrollbars='+scroll+',resizable='+resize+',width='+width+',height='+ height+',top='+top);
		if (mywin.parent.opener ==null)
			mywin.parent.opener = this.document;
		mywin.focus();		
}


//Called from popup  to cancel or confirm linkout

//get the querystring val, minus the '?'
var url= window.location.search.substring(1); 
///////////////////////
//Function: Confirm
// Purpose: Opens a new window with a specified URL
//-------------
function Confirm()
{

		var newwin = window.open(url);
		newwin.focus();
		window.close();
}

///////////////////////
//Function: ReplaceParent
// Purpose: Updates the caller's window.location with a specified URL. 
//			If no parent exisits, a new window is open.
//-------------
function replaceParent(){	
	
	if (window.opener && !window.opener.closed)//does the parent exist?
	{	window.opener.location=url;
		window.opener.focus();
	}
	else//parent ! found - may have been closed - open a new window
	{
		var newwin = window.open(url);
		newwin.focus();
	}
	
		window.close();

}

///////////////////////
//Function: Cancel
// Purpose: Closes current window and brings parent window to focus.
//			If no parent exists, a new window is opened with the homepage
//-------------

function Cancel () 
{

	if (window.opener && !window.opener.closed)//does the parent exist?
		window.opener.focus();
	else
		var newwin = window.open('/');
	window.close();
}








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




