// popUps.js

///////////////////////////////////////////////////////////////////////////////////////////////////
/// FUNCTIONS INCLUDED
//
// closeUpShop()
// goLog()
// goReg()
// goStore()
// launchFullWin (page)
// launchwin(winurl, winname, winfeatures)
// popLogin (page)
// popCredit ()
// showRegistrationForm ()
// whichBrowser()
// 
/////////////////////////////////////////////////////////////////////////////////////////////////// 
/// GLOBALS
//

var newWin;
var loginPop;

//var login = "http://" + location.hostname + "/~ReadyForce/login.html"; // login page
//var register = "http://" + location.hostname + "/~ReadyForce/register.html"; // registration page
//var credit = "http://" + location.hostname + "/~ReadyForce/siteCredit.html"; // site credits
//var store = "http://" + location.hostname + "/~ReadyForce/products/index.html"; // online store

var login = "http://" + location.hostname + "/login.html"; // login page
var register = "http://" + location.hostname + "/register.html"; // registration page
var credit = "http://" + location.hostname + "/siteCredit.html"; // site credits
var store = "http://" + location.hostname + "/products/index.html"; // online store
var mailer = "http://" + location.hostname + "/mailLink.html"; // mail a friend

//
///////////////////////////////////////////////////////////////////////////////////////////////////
//
/// IMPLEMENTATION
//
////////////////////////////////////////////////////////////////////////////////////////////////////


// Close the child window if the user
// closes the parent window first

function closeUpShop() {
  if (newWin != null) 
    if (typeof(newWin) == "object") 
      newWin.close();
	  
  if (loginPop != null)	  
	if (typeof(loginPop) == "object")
     loginPop.close();  
}

// open a login popup

function goLog() {
 popLogin(login);
}


// open a registration popup

function goReg() {
 popLogin(register);
}

// Open another browser window so that the user can't back up
// and empty his shopping bag by mistake. It will empty if the
// first page is reloaded!

function goStore() {
  //if(!whichBrowser()) { return; } // prevent old browsers from going further
    
  launchFullWin(store); 
}


// Open a popup

function popLogin (page) {
 var h = 300;
 var w = 400;
 //alert(page);
 var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
 var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
 
 var window_options = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no';
 
 loginPop = window.open(page, '', window_options);
 loginPop.focus();
}

function launchMediumWin(page, name) {
 var h = 600;
 var w = 800;
 //alert(page);
 var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
 var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
 
 var window_options = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',menubar=yes,scrollbars=yes,resizable=yes';
 
 loginPop = window.open(page, name, window_options);
 loginPop.focus();

}
 
// Open a window that occupies the entire screen

function launchFullWin (page) {
	 var sPreferences = '';
  
  // Estimate the size of a full screen
  
  var height = screen.availHeight;
  var width = screen.availWidth;
  
  // Sizing the browser window is highly browser dependent
  
  if(navigator.appName == "Netscape") {
   sPreferences = "outerWidth=" + width +
    ",outerHeight=" + height + 
    ",toolbar=yes,menubar=yes,status=yes,resizable=yes,screenX=0,screenY=0";
  }
  else {
  	// Assume Internet Explorer; it overestimates available height and width
	
   height = height - 120;
   width = width - 10;
   
   sPreferences = "width=" + width +
    ",height=" + height + 
    ',top=0,left=0,toolbar=yes,menubar=yes,location=yes,scrollbars=yes,status=yes,resizable=yes';	
  }	
	if(newWin == null) { 
    	newWin = window.open(page, "", sPreferences);
		newWin.focus();
	}
  	else if (!newWin.closed)
  		newWin.focus();
	
}


// Open a new window and set focus on it.
	
function launchwin(winurl, winname, winfeatures)
{
	
	newWin = window.open(winurl, winname, winfeatures);
	
	//delay a bit here because IE4 encounters errors
	//when trying to focus a recently opened window
 	
	setTimeout('newWin.focus();',250);
	
}


// Open a popup that contains the site credits page.

function popCredit () {
	var h = 400;
	var w = 450;
	
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	
	var window_options = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no';
	
	loginPop = window.open(credit, 'Credits', window_options);
	loginPop.focus();
}

// Open a popup that contains the mail to a friend page.

function popMailer () {
	var h = 430;
	var w = 356;
	
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	
	var window_options = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no';
	
	loginPop = window.open(mailer, 'Mail', window_options);
	loginPop.focus();
}


// overwrite ourself with a registration page

function showRegistrationForm () {
 document.location = register;
}

// check browser version and recommend better ones

function whichBrowser() {
	if (is.nav4up)
		return true;
	else if (is.ie4up)
		return true;
	else	
		alert("Your browser is " + navigator.userAgent);
	
	// redirect user to a page to get correct browser
		
	self.location.href = "browsers.htm";
		
	return false;
  }

