/*
	Base javascript code to be referenced from all pages
	Author: MFP
	Version: $Id: fcbasescript.js,v 1.1.1.1 2005/08/02 23:25:52 atg Exp $
*/

function openWin (winURL,winName,winParams) 
{
	var popWindow = open(winURL,winName,winParams);
	if (window.focus && popWindow!=null) 
	{
		popWindow.focus();
		if (popWindow.opener == null) popWindow.opener = self;
	}
}

function openWinRequired (winURL,winName,winParams) 
{
	var popWindowRequired = open(winURL,winName,winParams);
	if (isNullWindow(popWindowRequired)==true) {
		return;
	}
	else 
	{
		if (popWindowRequired.opener == null) popWindowRequired.opener = self;
		if (window.focus) popWindowRequired.focus();
	}
}

function cartPopupWin(url, width, height, techSupport) {
	  if (width == null)
	  	width = 510;
	  if (height == null)
	  	height = 500;
	  	
      winStats='height=' + height + ',width=' + width + ',status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,directories=no,resizable=yes';
   if (navigator.appName.indexOf("Microsoft")>=0) {
      winStats+=',left=50,top=50'
      
    }else{
      winStats+=',screenX=50,screenY=50' 
    }
	//append referer to URL for livePerson
	if (url.indexOf("liveperson.net") != -1) {
		if (url.indexOf("?") != -1) {
			var urlParams = new Array();
			urlParams = url.split("?");
			var baseURL = urlParams[0];
			var params = urlParams[1];
			var newParams = "referrer="+escape(document.location);
			if (techSupport) {
				newParams += '&special='+escape('postChatURL:http://www.franklincovey.com/Product_Support/m1_online_survey.html,postChatParms:scrollbars=1 width=800 height=800 resizable=1');
			}
			newParams += "&"+params;
			url = baseURL+"?"+newParams;
		}
		else url+="?referrer="+escape(document.location);
	}
    popWin=window.open(url,"FranklinCovey",winStats);
    popWin.focus();
}

function openQuote(sURL2){
	newwindow2=open(sURL2,"one2e","scrollbars=yes,toolbar=no,directories=no,menubar=no,resizable=no,status=no,width=411,height=175");
	if (window.focus) {
		newwindow2.focus();
	}
}

function jumpCategory(formname, selectname) {
	/*
	Given a formname and a select element name this script assumes that the 
	select element contains options whos values are urls and directs accordingly
	*/
	var selectObj = document.forms[formname].elements[selectname];
	var which = selectObj[selectObj.selectedIndex].value;
	if (which != "") document.location.href=which;
}

function noCookies(newPage){
		alert("Cookies are required to use the FranklinCovey Shopping web site.");
		//document.location = '/shopping/nocookies.html';
		//document.location = 'http://www.franklincovey.com/';
		document.location = newPage;
}

function testCookies(newPage){
	if(document.cookie){
		var cookieoff = "ATG=";
		document.cookie = cookieoff;
		//alert("Stall");
		var cookieval = "ATG=true";
		document.cookie = cookieval;
		if(document.cookie.indexOf(cookieval) == -1)
			noCookies(newPage);
	} else {
			noCookies(newPage);
	}
}

function isNullWindow(win) {
//	if(win == null || win.focus == null)
	if(win == null)
	{
		var text = "This site requires pop-ups to be enabled.\n";
		text += "If you would like to view this content, please disable\n";
		text += "any pop-up blocking software and restart your browser.\n\n";
		alert(text);
		return true;
	}
	return false;
}

//////script used for element positioning of "new" and "limited qty" images
// overly simplistic test for IE
isIE = (document.all ? true : false);
// both IE5 and NS6 are DOM-compliant (well, sort of...)
isDOM = (document.getElementById ? true : false);

// get the true offset of anything on NS4, IE4/5 & NS6, even if it's in a table!
function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent;
 }
 return iPos;
}

function getDivStyle(divname) {
 var style;
 if (isDOM) { style = document.getElementById(divname).style; }
 else { style = isIE ? document.all[divname].style
                     : document.layers[divname]; } // NS4
 return style;
}

function hideElement(divname) {
 getDivStyle(divname).visibility = 'hidden';
}

// annoying detail: IE and NS6 store elt.top and elt.left as strings.
function moveBy(elt,deltaX,deltaY) {
 elt.left = parseInt(elt.left) + deltaX;
 elt.top = parseInt(elt.top) + deltaY;
}

function toggleVisible(divname, belowPos) {
 divstyle = getDivStyle(divname);
 if (divstyle.visibility == 'visible' || divstyle.visibility == 'show') {
   divstyle.visibility = 'hidden';
 } else {
   fixPosition(divname, belowPos);
   divstyle.visibility = 'visible';
 }
}

function setPosition(elt,positionername,isPlacedUnder, howFarBelow) {
 var positioner;
 if (isIE) {
  positioner = document.all[positionername];
 } else {
  if (isDOM) {
    positioner = document.getElementById(positionername);
  } else {
    // not IE, not DOM (probably NS4)
    // if the positioner is inside a netscape4 layer this will *not* find it.
    positioner = document.images[positionername];
  }
 }
 elt.left = getAbsX(positioner)+4;
 elt.top = getAbsY(positioner) + (isPlacedUnder ? positioner.height : howFarBelow);
}

function fixPosition(divname, belowPos) {
 divstyle = getDivStyle(divname);

 positionerImgName = divname + 'Pos';
 isPlacedUnder = false;
 if (!isPlacedUnder) {
  setPosition(divstyle,positionerImgName,false,belowPos);
 } else {
  setPosition(divstyle,positionerImgName,true,belowPos)
 }
}

// fixPositions() puts everything back in the right place after a resize.
function fixPositions()
{
 // add a fixPosition call here for every element
 // you think might get stranded in a resize/reflow.
// fixPosition('mookie');
}



