// from globalscript.js and brain.js, removing duplicates

function openStaticWindow(ThisURL,ThisWidth,ThisHeight){
  mypage = ''+ThisURL;
myname = "blank";
w = ThisWidth;
h = ThisHeight;
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+(wint-20)+',';
      settings +='left='+winl+',';
      settings +='scrollbars=yes,';
      settings +='resizable=yes';
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}


// Return query string portion of given URL
// Apply prefix to return value only if return value not zero length
function fb_getqstr(url, prefix)
{
  var parsed = url.split('?');
  var qstr_parms = '';
  if (parsed.length > 1)
    qstr_parms = parsed[1];
  if (prefix.length == 0)
    return qstr_parms;

  if (qstr_parms.length > 1)
    return prefix + qstr_parms;

  return '';
}

// Set up QueryString object
var fb_qstr = new Object();
fb_qstr.keys = new Array();
fb_qstr.values = new Array();

function fb_qstr_parse()
{
        var query = window.location.search.substring(1);
        var pairs = query.split("&");

        for (var i=0;i<pairs.length;i++)
        {
                var pos = pairs[i].indexOf('=');
                if (pos >= 0)
                {
                        var argname = pairs[i].substring(0,pos);
                        var value = pairs[i].substring(pos+1);
                        fb_qstr.keys[fb_qstr.keys.length] = argname;
                        fb_qstr.values[fb_qstr.values.length] = value;
                }
        }

}

// Get value from query string corresponding to given name
function fb_qstr_value(key)
{
	fb_qstr_parse();

        var value = null;
        for (var i=0;i<fb_qstr.keys.length;i++)
        {
                if (fb_qstr.keys[i]==key)
                {
                        value = fb_qstr.values[i];
                        break;
                }
        }
        return value;
}

// Allow for client 1x1 pixel tracking for games, brain game over logos, and specialized ads that can't do their own tracking
function loadTrackingPixel(URLtoTrigger)
{
	dcord = Math.random() * 100000000;
	dcpix = new Array();
	dcpix[0] = new Image();
	dcpix[0].src = URLtoTrigger;
}


// Write cookies (triggered from Flash)
function writeCookie() {

 	var today = new Date();
 	var expire = new Date();

 	expire.setTime(today.getTime() + 3600000*24*14);

	for(i=0;i<writeCookie.arguments.length;i++) {
		ckThing = writeCookie.arguments[i] + '=' + writeCookie.arguments[i+1]
		i++
		document.cookie = ckThing + '; path=/; expires=' + expire.toGMTString()
	}
}


// Get cookies for a Flash piece
function getCookiesForFlash() {
	cookString = "?" 
	// does the visitor have a cookie? 
	if(document.cookie != "") {
		theCook = document.cookie.split("; ")
		// add each part of the cookie to a string variable
		for (i = 0; i < theCook.length; i ++) {
			cookString += theCook[i] + "&"
		}
	}
}


// from inside brains
var win = null;

function openNextPage(myPage)
{
  // Force use of .html suffix
  if (myPage.indexOf('.htm') == myPage.length - 4)
    myPage += 'l';
  if (myPage.indexOf('?') >= 0)
    myPage += fb_getqstr(document.URL, '&');
  else
    myPage += fb_getqstr(document.URL, '?');
  win=window.open(myPage, "_self");
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function opensweepsbrain(myPage)
{
// where this function is different from the one above is that here, 
// we don't need to carry the laundry list of variables back to the Just for Fun Brain..
// we only need to carry the password back
  win=window.open(myPage, "_self");
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function openJFFBrain(myPage)
{
// where this function is different from the one above is that here, 
// we don't need to carry the laundry list of variables back to the Just for Fun Brain..
// we only need to carry the password back
  win=window.open(myPage, "_self");
  if (parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function openMathBrain(myPage)
{
// where this function is different from the one above is that here, 
// we don't need to carry the laundry list of variables back to the Math Brain..
// we only need to carry the password back
  win=window.open(myPage, "_self");
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function openReadingBrain(myPage)
{
// where this function is different from the one above is that here, 
// we don't need to carry the laundry list of variables back to the Just for Fun Brain..
// we only need to carry the password back
  win=window.open(myPage, "_self");
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function openWindow(ThisURL){
  mypage = ''+ThisURL;
  win=window.open(mypage,"_self");
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function openScratchPad(ThisURL){
  mypage = 'ScratchPadMathBasketball.html';
myname = "blank1";
w = 280;
h = 420;
  var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
  var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+(wint-20)+',';
      settings +='left='+winl+',';
      settings +='scrollbars=no,';
      settings +='resizable=no';
  win=window.open(mypage,myname,settings);
  if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
