/* *************************************************
*
*  © 2001 Etensity, Inc.
*	Popup Window code (in JavaScript)
*		basic open/close version
*
*	Updated:	May 7, 2001
*	By:		Creative Development (Vienna)
*
*************************************************** */

function addSessionIdToFilename(filename) {
  // Add the session id to the given filename
 
  var processedFilename = filename;  
  
  var sessionId = null;
  var sessionParamString = ";jsessionid=";
    
  var theLoc = window.location + "";
  if (theLoc == null) return filename;
  
  locStrings = theLoc.split(sessionParamString);
  if (locStrings == null) return filename;
  
  if (locStrings.length > 1) {
  
     sessionIdPiece = locStrings[1];
     if (sessionIdPiece == null) return filename;
     
     var questIndex = sessionIdPiece.indexOf('?');
     if (questIndex != -1) {
        sessionId = sessionIdPiece.substring(0, questIndex);
     } else {
        sessionId = sessionIdPiece;
     }
  } else {
     return filename;
  }
  
  if (sessionId != null) {
  
      var filenameWithSessionId;
      
      arrayOfStrings = filename.split("?");
      if (arrayOfStrings == null) return filename;
      
      if (arrayOfStrings.length > 1) {
         firstPart = arrayOfStrings[0];
         secondPart = arrayOfStrings[1];
         filenameWithSessionId = firstPart + sessionParamString + sessionId + "?" + secondPart;
      } 
      else {
         filenameWithSessionId = filename + sessionParamString + sessionId;
      }
      
      processedFilename = filenameWithSessionId;
  } 
      
  return processedFilename;
}


function popupFAQ(filename) {
	// Show FAQ popup window based on features provided
	var processedFilename = addSessionIdToFilename(filename);
	faq_window = window.open( processedFilename , "faq_window", "left=110,top=90,width=400,height=300,resizable=1,scrollbars=1,toolbar=0,status=0,location=0,directories=0,menubar=0");
	faq_window.focus();
}

function popupGlossary(filename) {
	// Show glossary popup window based on features provided
	glossary_window = window.open( filename , "glossary_window", "left=110,top=90,width=571,height=489,resizable=1,scrollbars=1,toolbar=0,status=0,location=0,directories=0,menubar=0");
	glossary_window.focus();
}

function popupWizard(filename) {
//leaned out in the interest of clearing space
}

function popupSample(filename) {
	// Show Sample Web Site popup window based on features provided
	var processedFilename = addSessionIdToFilename(filename);
	sample_window = window.open( processedFilename , "sample_window", "left=120,top=100,width=750,height=560,resizable=1,scrollbars=1,toolbar=0,status=0,location=0,directories=0,menubar=0");
	sample_window.focus();
}

function popupHelp(filename) {
// Show Help Web Site popup window based on features provided
	var processedFilename = addSessionIdToFilename(filename);
	var browser = navigator.appName.substring(0,8);
	if (browser == "Netscape")
		help_window = window.open( processedFilename , "help_window", "left=120,top=50,width=800,height=530,resizable=1,scrollbars=1,toolbar=1,status=1,location=1,directories=1,menubar=1");
	else 
		help_window = window.open( processedFilename , "help_window", "left=120,top=50,width=800,height=675,resizable=1,scrollbars=1,toolbar=1,status=1,location=1,directories=1,menubar=1");
	
	help_window.focus();
}


function ClosePopup(filename) {
	// Close window from itself or opener

	if (!filename) {
		self.close();
	} else if (filename == "opener") {
		if (self.opener.open && !self.opener.closed) self.opener.close();
	} else {
		if (filename.lastIndexOf('_window') > 0) win = filename
			else win = getNameRoot(filename) + '_window';
		if (eval('window.' + win + ' && ' + win + '.open && !' + win + '.closed'))
			eval(win + '.close()');
	}
}

function NewPage(newURL) {
	// Changes main window to a new page and closes the popup
	self.opener.location.href = newURL;
	ClosePopup();
}

function popupTour(filename) {
	// Show Tour pages in a popup
	var processedFilename = addSessionIdToFilename(filename);
	tour_window = window.open( processedFilename , "tour_window", "left=120,top=100,width=570,height=330,resizable=1,scrollbars=1,toolbar=0,status=0,location=0,directories=0,menubar=0");
	tour_window.focus();
}

function popupTry(filename) {
// Show Try It pages in a popup
	var processedFilename = addSessionIdToFilename(filename);
	try_window = window.open( processedFilename , "try_window", "left=120,top=100,width=745,height=500,resizable=1,scrollbars=1,toolbar=1,status=0,location=0,directories=0,menubar=0");
	try_window.focus();
}	

function popupNameIt(filename) {
// Show Name It pages in a popup
	var processedFilename = addSessionIdToFilename(filename);
	nameit_window = window.open( processedFilename , "nameit_window", "left=120,top=100,width=400,height=300,resizable=1,scrollbars=1,toolbar=0,status=0,location=0,directories=0,menubar=0");
	nameit_window.focus();
}

function popupNameIt2(filename) {
// Show Name It pages in a popup
	var processedFilename = addSessionIdToFilename(filename);
	nameit_window = window.open( processedFilename , "nameit_window", "left=120,top=100,width=800,height=600,resizable=1,scrollbars=1,toolbar=0,status=0,location=0,directories=0,menubar=0");
	nameit_window.focus();
}

function popupShowSaving(filename) {
// Show Name It pages in a popup
	var processedFilename = addSessionIdToFilename(filename);
	nameit_window = window.open( processedFilename , "show_window", "left=120,top=100,width=430,height=395,resizable=0,scrollbars=0,toolbar=0,status=0,location=0,directories=0,menubar=0");
	nameit_window.focus();
}

function popupNewWSM(filename) {
// Show new WSM 4.0 pages in a popup
	var processedFilename = addSessionIdToFilename(filename);              
	wsm_window = window.open( processedFilename , "wsm_window", "left=120,top=100,width=459,height=411,resizable=0,scrollbars=0,toolbar=0,status=0,location=0,directories=0,menubar=0");
	wsm_window.focus();
}

function popupXMLHelp(filename) {
	// Show XML popup window based on features provided
	var processedFilename = addSessionIdToFilename(filename);
	xml_window = window.open( processedFilename , "xml_window", "left=110,top=90,width=555,height=545,resizable=1,scrollbars=1,toolbar=0,status=0,location=0,directories=0,menubar=0");
	xml_window.focus();
}

// Display a popup window, centered over window that launches it, such as SF > See all Samples > launch a sample > About this site
function atsPopup(mypage, myname, w, h, scroll)
	{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
function wsv(filename) {
	var processedFilename = addSessionIdToFilename(filename);
	wsv_window = window.open( processedFilename , "wsv_window", "left=10,top=10,width=780,height=590,resizable=1,scrollbars=1,toolbar=0,status=0,location=0,directories=0,menubar=0");
	wsv_window.focus();

}

function popUp(URL, type) 
{
   if (arguments.length == 2)
   {
      switch(type)
      {
 	case "fullscreen":
    	width = screen.availWidth - 40;
    	height = screen.availHeight - 40;
    	break;

	case "wsv":
		width = 780;
		height = 590;
		break;
			
  	case "delete":  
	    width = 400;
	    height = 230;
	    break;	    

	    
	 case "700x500":
	    width = 700;
	    height = 500;
	    break;
	    
	 case "save":
	    width = 450;
	    height = 300;
	    break;	    

	 case "item":
	    width = 640;
	    height = 555;
	    break;	    

	 case "learnmore":
	    width = 325;
	    height = 340;
	    break;	
	    
	 case "supportcenter":
	    width = 672;
	    height = 586;
	    break;		    
	    
	 case "moreinfo":
	    width = 650;
	    height = 600;
	    break;	

	 case "block":
	    width = 640;
	    height = 600;
	    break;	    

	 case "template":
	    width = 750;
	    height = 575;
	    break;	
	 
	 case "banner":
	    width = 780;
	    height = 320;
	    break;	    

	 case "headline":
	    width = 720;
	    height = 370;
	    break;	    

	 case "intuithome":
	    width = 780;
	    height = 580;
	    break;	    

	 case "preview":
	    width = 780;
	    height = 580;
	    break;	    

            }
   }
   else
   {
      width = 550;
      height = 560;
      type = "generic";
   }


   var token = URL.indexOf('?') > -1 ? '&amp;' : '?';
   uniqueId = genUniqueId();
   URL=URL+genUniqueParam(token);

   var leftPosition  = (screen.width - width - 20) / 2;
   var topPosition = (screen.height - height) / 4;

if ((type == "supportcenter") || (type == "intuithome") || (type == "learnmore")) {
   eval("win = window.open(URL, '"+type+"', 'toolbar=0,scrollbars=1,location=0,status=0,resizable=1,menubar=0,width="+width+",height="+height+"');");
} 
else if (type == "wsv") {
	eval("win = window.open(URL, '"+type+"', 'toolbar=0,scrollbars=1,location=0,status=0,resizable=1,menubar=0,width="+width+",height="+height+",left=10,top=10');");
}
else {
   eval("win = window.open(URL, '"+type+"', 'toolbar=0,scrollbars=1,location=0,status=0,resizable=1,menubar=0,width="+width+",height="+height+",left="+leftPosition+",top="+topPosition+"');");
}

   if (parseInt(navigator.appVersion) >= 4) 
   { 
      win.window.focus(); 
   }
}

// ----------------------
// Generate Unique Id
// ----------------------
function genUniqueId()
{
   day = new Date();
   return day.getTime();
}

// -------------------------------------------------
// Generate Unique parameter to be appended to the URL
// This will allow us to realod the HTML from the server
// -------------------------------------------------
function genUniqueParam(parameter)
{
   return parameter+'unique_id='+genUniqueId();
}

function connectToSF(nextURL)
{
    var sf_window = window.opener.top.top.opener;
    if (sf_window == null || sf_window == '' ||
        typeof sf_window == 'undefined' || sf_window.closed) 
    {
       sf_window = window.open(nextURL, "SF_WINDOW", 'toolbar=1,scrollbars=1,location=1,status=1,menubar=1');
    }
    else 
    {
       sf_window.location.href=nextURL;
    }
    sf_window.focus();
    self.close();
}

function connectToSFFromWsv(nextURL)
{
    var sf_window = window.top.opener;
    if (sf_window == null || sf_window == '' ||
        typeof sf_window == 'undefined' || sf_window.closed) 
    {
       sf_window = window.open(nextURL, "SF_WINDOW", 'toolbar=1,scrollbars=1,location=1,status=1,menubar=1,resizable=1'
);
    }
    else 
    {
       sf_window.location.href=nextURL;
    }
    sf_window.focus();
    self.close();
}

// Codes for the homepage....//

function navgo()
{
	box = document.forms[0].navi;
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

function imgOn(imgName,replace) {

if (document.images) {
imgReplace=new Image();
imgReplace.src=replace;

document[imgName].src = imgReplace.src;
}
}

function imgOff(imgName,restore) {
if (document.images) {
imgRestore=new Image();
imgRestore.src=restore;
document[imgName].src = imgRestore.src;
}
}
