window.onerror = onError;

var w3c = (document.getElementById) ? 1:0
var ns4 = (document.layers) ? 1:0
var ie4 = (document.all) ? 1:0
var pc	= (navigator.platform.indexOf('Win') == 0) ? 1:0;
var mac	= (navigator.platform.indexOf('Mac') == 0) ? 1:0;

function onError(sMessage, sURL, sLine) 
{ 
        var sPrompt; 
        sPrompt = "________________________________________________________\n\n" 
        sPrompt += "A client-side javascript error has occured.\n" 
        sPrompt += "________________________________________________________\n\n" 
        sPrompt += "Line:\t" + sLine + "\n" 
        sPrompt += "Reason:\t" + sMessage + "\n" 
        sPrompt += "URL:\t" + sURL + "\n" 
                
        //test to see if this is the development site 
      	if (location.href.indexOf('byteinteractive.com') > 0) 
                window.alert(sPrompt); 
                
        return true; 
 } 

function onLoad()
{ 
	cacheImages();	//function to cache all rollover images
	//window.status = 'Welcome To ';
	return true;
}

function onResize()
{ 
	if (w3c)
		location.reload();
	return;
}

function cacheImages()
{
	var i;
	
	var oImages = new Array(document.images.length);			//array of image objects
	//reset all rollover images to their "off" state
	for (i=0; i<document.images.length; i++)
	{
		if ( document.images[i].src.search(/\_off\.(gif|jpg)/) > 0 )
		{	
			oImages[i] = new Image();
			oImages[i].src = document.images[i].src.replace("_off.", "_on.");
		}
	}
	return;
}

function setImage(oImage)
{
	var i;

	//first reset all rollover images to their "off" state
	for (i=0; i<document.images.length; i++)
	{
		if ( document.images[i].src.search(/\_on\.(gif|jpg)/) )
			document.images[i].src.replace("_on.", "_off.");
	}
	
	//now set the image to be in the "on" state		
	eval(oImage).src = eval(oImage).src.replace("_off.", "_on.");
				
	return;
}

function clearImages()
{
	var i;
	
	//reset all rollover images to their "off" state
	for (i=0; i<document.images.length; i++)
	{
		if ( document.images[i].src.search(/\_on\.(gif|jpg)/) > 0 )
			document.images[i].src = document.images[i].src.replace("_on.", "_off.");
	}
	return;
}

function openWindow(url, name, width, height, resize, scroll, center)
{
	var sParams = '';
	name = (name == null) ? '' : name;

	sParams += 'width=' + width;
	sParams += ',height=' + height;
	sParams += (resize || resize == 'true') ? ',resizable=yes' : ',resizable=no';
	sParams += (scroll || scroll == 'true') ? ',scrollbars=yes' : ',scrollbars=no';
	sParams += (center || center == 'true') ? ',left=' + ((screen.width - width) / 2) : '';
	sParams += (center || center == 'true') ? ',top=' + ((screen.height - height) / 2) : '';

	window.name = 'opener';
	var popupWin = window.open(url, name, sParams);
	popupWin.focus();
	return;
}

function openPrivacy()
{
	window.open('/privacy.html','privacy','scrollbars=yes,status=no,width=678,height=400')
}

function openCoffeeTerms()
{
	window.open('/coffeebreak/terms.asp','coffeeterms','scrollbars=yes,status=no,width=470,height=210')
}

function openTerms()
{
	window.open('/terms.html','terms','scrollbars=yes,status=no,width=678,height=400')
}

function openRules()
{
	window.open('/rules.html','rules','scrollbars=yes,status=no,width=678,height=400')
}

function openWinners()
{
	window.open('/promotions/winners.asp','winners','scrollbars=no,status=no,width=450,height=379')
}

function openTeachersPrivacy()
{
	window.open('/teachers/privacy-new.html','privacy','scrollbars=yes,status=no,width=678,height=400')
}

function openTeachersTerms()
{
	window.open('/teachers/terms_new.html','terms','scrollbars=yes,status=no,width=678,height=400')
}

function getDHTMLObj(objName)
{
	if (document.getElementById)
		return document.getElementById(objName);
	else if (document.all)
		return document.all[objName];
	else if (document.layers)
		return document.layers[objName];
	else
		return null;
} 

function isAlpha(theStr) {
	var theReg =  /^[A-Za-z]+$/;
	return(theReg.test(theStr));
}

function isAlphaNumeric(theStr) {
	var theReg =  /^[A-Za-z0-9]+$/;
	return(theReg.test(theStr));
}

function isEmail(theStr) {
	var theReg = /^[\w\.\-]+\@[\w\.\-]+\.[\w.]{2,}$/;
	return(theReg.test(theStr));
}

function isNumber(theValue, theLowerBound, theUpperBound) {
	var retVal = false;
	if (isNumeric(theValue)) {
		retVal = true;
		if (isNumeric(theLowerBound)) {
			retVal = retVal && (theLowerBound <= theValue);
		}
		if (isNumeric(theUpperBound)) {
			retVal = retVal && (theValue <= theUpperBound);
		}
	}	
	return retVal;
}

function isNumeric(theStr) {
	var theReg =  /^\d+$/;
	return(theReg.test(theStr));
}

function isPhoneNumber(theStr) {
	var theReg = /^\(?\d{3}\)?\D?\d{3}\D?\d{4}$/;
	return(theReg.test(theStr));
}

function isString(theValue, theMinLength, theMaxLength) {
	if (isNumeric(theMinLength) && isNumeric(theMaxLength)) {
		retVal = ((theMinLength <= theValue.length) && (theValue.length <= theMaxLength));
	} else if (isNumeric(theMinLength)) {
		retVal = (theMinLength <= theValue.length);
	} else if (isNumeric(theMaxLength)) {
		retVal = (theValue.length <= theMaxLength);
	} else {
		retVal = (0 < theValue.length);
	}
	return retVal;
}

function wordCount(sText,nLimit)
{
	var outVal;
	var sValue=sText;
	sValue=sValue.split(" ");
	
	outVal=(sValue.length < (nLimit+1));
	return outVal 
}

function isZipCode(theStr) {
	var theReg =  /^\d{5}(\-\d{4})?$/;
	return(theReg.test(theStr));
}

function openHomeFlash()
{
document.write ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="591" height="524" id="bic_home_2" align="middle" VIEWASTEXT>');
document.write ('<param name="allowScriptAccess" value="sameDomain" />');
document.write ('<param name="movie" value="bic_home.swf" />');
document.write ('<param name="quality" value="high" />');
document.write ('<param name="bgcolor" value="#666666" />');
document.write ('<embed src="bic_home.swf" quality="high" bgcolor="#666666" width="591" height="524" name="bic_home_2" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write ('</object>');
}

function openTeachersHomeFlash()
{
document.write ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="591" height="524" id="bic_home_teachers_reaction" align="middle">');
document.write ('<param name="allowScriptAccess" value="sameDomain" />');
document.write ('<param name="movie" value="/teachers/bic_home_teachers_reaction3.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#666666" /><embed src="/teachers/bic_home_teachers_reaction3.swf" quality="high" bgcolor="#666666" width="591" height="524" name="bic_home_teachers_reaction" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write ('</object>');
}

function openClub()
{
	window.open('/teachers/kidsclub.aspx','kidsclub','scrollbars=yes,status=no,width=678,height=400')
}