// BBBonline window popper
function Certify(URL) {
  popupWin = window.open(URL, 'Participant', 'location,scrollbars,width=450,height=300')
  window.top.name = 'opener';
}

//  helpful script window popper
function helpfulWin(url) {
quizWin=window.open(url, "", "toolbar=no,directories=no,status=no,location=0,resizable=no,scrollbars=no,menubar=no,width=600,height=385,screenY=25,screenX=25,top=25,left=25")  
quizWin.focus();
}	
	
// bookmark this page script
	function Favorites() {   
	window.external.AddFavorite(location.href, document.title)     
}

// copyright popup window
function copyPop(name,url,width,height) {
quizWin=window.open(url,name, "toolbar=no,directories=no,status=no,location=0,resizable=no,scrollbars=no,menubar=no,width="+width+",height="+height+",screenY=25,screenX=25,top=25,left=25")
}

// copyright popup window
function playPop(url) {
quizWin=window.open(url, "playlist", "toolbar=no,directories=no,status=no,location=0,resizable=no,scrollbars=no,menubar=no,width=360,height=200,screenY=25,screenX=25,top=25,left=25")  
}

// contact us popup window
function contactPop(url) {
quizWin=window.open(url, "", "toolbar=yes,directories=no,status=no,location=0,resizable=no,scrollbars=yes,menubar=no,width=800,height=595,screenY=25,screenX=25,top=25,left=25")  
}

// custom popup window
function customPop(url, iwidth, iheight) {
quizWin=window.open(url, "", "toolbar=yes,directories=no,status=no,location=0,resizable=no,scrollbars=yes,menubar=no,width=" + (iwidth+40) + ",height=" + (iheight+40) + ",screenY=25,screenX=25,top=25,left=25")  
}

// bbq popper  ***  may not be used in the redesign
function BBQPopUp(){
	open_window1('/outside/barbeque_tips1.html', 'width=310,height=350,location=no,menubar=no,resizable=yes,scrollbar=yes,status=no,titlebar=no,toolbar=no')
}

// generic window popper
function open_window1(url) {
        popupWin = window.open(url, '', "resizable=no,toolbar=no,scrollbars=yes,width=317,height=350");
}

// strip (01.23.2003)
// strips single quotes from page titles

function strip (ToStrip) {
	var QuoteChar = "'";
	var StrippedString = "";
	for (loop = 0; loop < ToStrip.length; loop++)
	{
	if (ToStrip.charAt(loop) != QuoteChar.charAt(0)) 
		StrippedString += ToStrip.charAt(loop);
	else
		StrippedString += "`";
	}
	return StrippedString;
}
// grab query string to be used for cookie
function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}
QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_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);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}

}
//cookie code starts here
QueryString_Parse();

var bikky = document.cookie;

function getCookiehms(name) { // use: getCookie("name");
  var index = bikky.indexOf(name + "=");
  if (index == -1) return null;
  index = bikky.indexOf("=", index) + 1;
  var endstr = bikky.indexOf(";", index);
  if (endstr == -1) endstr = bikky.length;
  return unescape(bikky.substring(index, endstr));
}

var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000); // plus 365 days

function setCookiehms(name, value) { // use: setCookie("name", value);
  if (value != null && value != "")
    document.cookie=name + "=" + escape(value) + "; path=/;  expires=" + expiry.toGMTString();
  bikky= document.cookie; // update bikky
}  

function subCookie() {
 // in every newsletter linked page
if (QueryString("subscriber") !== "") {
	setCookiehms("subscriber",QueryString("subscriber"));
}	
 if (QueryString("subscribe") !== "") {
	setCookiehms("subscriber",QueryString("subscribe"));	
	//alert("subscriber =" + QueryString("subscriber"));
	//alert("subscribe =" + QueryString("subscribe"));
}
 //on popular exit or entry pages (onLOAD)
if ((getCookiehms("subscriber") !== "1")  || (getCookiehms("subscriber")) == "null"){
	//window.open('/sub_pop.htm','win1','width=450,height=320,scrollbars=no,resizable=no,toolbar=no,screenY=25,screenX=25,top=25,left=25'); 
 };
}

//cookie code ends here

// date function
function getDate() {
var Today=new Date();
var ThisDay=Today.getDay();
var ThisDate=Today.getDate();
var ThisMonth=Today.getMonth()+1;
var ThisYear=Today.getFullYear();  //included if you wish to insert the year
var DayName=DayTxt(ThisDay);
var MonthName=MonthTxt(ThisMonth);
return DayName + " " + MonthName + " " + ThisDay + ", " + ThisYear;
}

function DayTxt (DayNumber) {
var Day=new Array();
Day[0]="Sunday";
Day[1]="Monday";
Day[2]="Tuesday";
Day[3]="Wednesday";
Day[4]="Thursday";
Day[5]="Friday";
Day[6]="Saturday";
return Day[DayNumber];
}

function MonthTxt (MonthNumber) {
var Month=new Array();
Month[1]="January";
Month[2]="February";
Month[3]="March";
Month[4]="April";
Month[5]="May";
Month[6]="June";
Month[7]="July";
Month[8]="August";
Month[9]="September";
Month[10]="October";
Month[11]="November";
Month[12]="December";
return Month[MonthNumber];
}

//used by simple_solutions.js, this_issye.js and special_offers.js
function Random(nMin, nMax) {
	// Returns a random number between nMin and nMax
	var iRand;
	iRand = Math.floor(Math.random()*(nMax-nMin+1))+nMin;
	return iRand
}

function getRandom(nCount, nMin, nMax, nUnique) {
	// Returns an array (with length nCount) of random numbers between nMin and nMax.
	// If nUnique is 1, then only unique random numbers are returned.
	// If nUnique is 0, then the same random number can be returned more than once.
	if ( ((nMax-nMin) < (nCount-1)) && nUnique==1) {
		alert("You are requesting more unique values than possible");
		return 0;
	}
	var ay = new Array(nCount);
	var n, j;
	var nFound;
	for (q=0;q<nCount;q++){
		n=Random(nMin, nMax);
		if (nUnique==1){
			nFound=1;
			while (nFound==1) {
				nFound=0;
				n=Random(nMin, nMax);
				for (j=0;j<nCount;j++){
					if (ay[j] == n){
						nFound=1;
					}
				}
			}
		}
		ay[q]=n;
	}
	return ay;
}


/*********************************************************************
   srchSubmitMain()
   Submit search form available from all pages
**********************************************************************/
function srchSubmit(form) {
 
  var query=form.q.value;

  query=replaceAll(query,"#","");

  form.q.value=query;
  return true;
}

/*********************************************************************
   replaceAll
   Replaces a substring with in a string with a new string
**********************************************************************/
function replaceAll (string, oldstr, newstr)
{ var st = string;
  if (oldstr.length == 0)
     return st;
  var idx = st.indexOf(oldstr);
  while (idx >= 0)
  {  st = st.substring(0,idx) + newstr + st.substr(idx+oldstr.length);
     idx = st.indexOf(oldstr);
  }
  return st;
}

function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}
 
 // Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}

