// -----------------------------------------------
// - wsv-retail-web:htdocs/includes/js/popup.js
// -
// - @(#) wsv-retail-web_d13.6.0.1 07/26/10 19:11:40 popup.js NSI
// -----------------------------------------------

// -----------------------------------------------
// - This file contains popup window functions.
// -----------------------------------------------

// -----------------------------------------------
// This script closes ALL popups when called
// Only works when called from the creating page
// -----------------------------------------------
function closePopups()
{
 if (typeof win != 'undefined' && win && win != window && !win.closed) win.close();
}

// -----------------------------------------------
// This script closes ALL popups when called
// Only works when called from the parent
// -----------------------------------------------
function closeFullscreen()
{
  window.fullscreen.close();
}

// ----------------------------
// Display a popup window
// ----------------------------
function openDialogWindow(URL, windowName, width, height, left, top, status, resize, scroll)
{
   // force a fresh reload from the server
   uniqueId = genUniqueId();
   URL=URL+genUniqueParam('&');

  // window properties
   var windowProperties = 'height='+height+',width='+width+',top='+top+',left='+left+',scrollbars='+scroll+',resizeable='+resize+',status='+status+',titlebar=1,directories=0,menubar=0,location=0,toolbar=0,copyhistory=0,personal=0,hotkeys=0';

   // open the window
   eval("page"+uniqueId+ "= window.open(URL, '"+uniqueId+"', windowProperties);");
}

// ----------------------------
// Position a popup window topleft, topright, centre, botleft, or botright
// ----------------------------

	// this function calls a popupWindow where
	// win is the page address eg '../page.htm'
	// winWidth is the required window width in pixels
	// winHeight is the required window height in pixels
	// place is where the window should be placed .. choose from topleft, topright, centre, botleft, botright
	// winName is the name of the new window
	
	function popupWindow(win,winWidth,winHeight,place,winName){
	
	leftPos = 0; topPos = 0; // default variables for old browsers

		if (screen){ 
		
		   // checks specified parameters are not outside screen area
		   
    		if (winWidth>screen.width){
    		   winWidth = screen.width;
    		}
    		
    		if (winHeight>screen.height){
    		   winHeight = screen.height - 55;
    		}
    		
    		if (winWidth <= 0){
    		   winWidth = screen.width;
    		}
    		
    		if (winHeight <= 0){
    		   winHeight = screen.height - 55;
    		}
    		
			// positions window by checking place parameter
					
			if (place == 'topleft'){ // positions window in top left corner
			leftPos = 0;
			topPos = 0;
			}
			
			if (place == 'centre'){ // centers window
			leftPos = screen.width/2 - winWidth/2;
			topPos = screen.height/2 - winHeight/2;
			}
			
			if (place == 'topright'){ // positions window in top right corner
			leftPos = screen.width - 15 - winWidth; // minus 15 to prevent edge of window being off screen
			topPos = 0;
			}
			
			if (place == 'botleft'){ // positions window in bottom left corner
			leftPos = 0;
			topPos = screen.height - (winHeight + 55); // add 55 to prevent bottom of window being obscured by taskbar
			}
			
			if (place == 'botright'){ // positions window in bottom right corner
			leftPos = screen.width - 15 - winWidth; // minus 15 to prevent edge of window being off screen
			topPos = screen.height - (winHeight+55); // add 55 to prevent bottom of window being obscured by taskbar
			}
					
		}
		
		newWindow = window.open(win,winName,'toolbar=no,location=no,scrollbars=yes,resizable=yes,width='+winWidth+',height='+winHeight+',left='+leftPos+',top='+topPos+'');
		newWindow.focus();
	}

// -----------------------------
// Display a Hyperlink dialog box
// ------------------------------
function openHyperlinkDialog(URL)
{
   var width = 500;
   var height = 300;
   var leftPosition  = (screen.width - width) / 2;
   var topPosition = (screen.height - height) / 4;

   openDialogWindow(URL, 'Foo', width, height, leftPosition, topPosition, 0, 1, 0);
}


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

	 case "dwizard":
	    width = 770;
	    height = 580;
	    break;
	    
	 case "delete":
	    width = 400;
	    height = 230;
	    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;

	 case "new_wsm_here":
	    width = 476;
	    height = 416;
	    break;

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

   var token = URL.indexOf('?') > -1 ? '&' : '?';
   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 {
   	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();
   }
}

//-----------------------------------------
// Open Window for Support Center popups
//------------------------------------------

function openWindow(theURL,winName,features)
{
    window.open(theURL,winName,features);
}


// ----------------------
// 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();
}

// Are we using this one?
function newWindow(URL)
{
   window.open(URL, "", 'toolbar=1,scrollbars=1,location=1,status=1,menubar=1');
}


function NewWindow(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+',resizeable';
    win = window.open(mypage, myname, winprops);
    if (parseInt(navigator.appVersion) >= 4)
    {
	win.window.focus();
    }
}

  function logoutUser(returnURL)
  {
     var topWindow = top.opener;
     if (typeof topWindow == 'undefined' ) {
        top.location.href = returnURL;
    } else {

        top.opener.location.href = returnURL;
        self.close();
    }
    return false;
  }

/* Close out a wizard popup from WSV */
function endWizard(URL)
{
    // See if the window has an opener
    var hasOpener = (window.opener != null);
    var window_to_refresh = window.top;
    // get the opener of this window if it exists
    if (hasOpener)
    {
        window_to_refresh = window.opener.top;
    }

    // Get the content frame
    if (typeof window_to_refresh.frames["se_content"] != 'undefined')
    {
	window_to_refresh = window_to_refresh.frames["se_content"];
    }

    //  Refresh the url if needed
    if (URL != null && URL != 'null' && URL != '') {
       window_to_refresh.location.href = URL;
    }

    // Close the window if needed
    if (hasOpener)
    {
	self.close();
    }
}

/* Close out a wizard popup from WSV */
function retarget(URL, target)
{
    var win = null;
    if (target == '_top')
    {
        win = window.top;
    }
    else if (target == '_self')
    {
        win = window;
    }
    else
    {
        win = eval('window.' + target);
    }

    if (win != null)
    {
       win.location.href = URL;
    }
}


//<!-- END Javascript for Generic Pop-up -->

