// /_scripts/global.js
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() 
//=     PARAMETERS:     sMessage as string is the error reason 
//=						sUrl as string is the URL that raised the error 
//=						sLine is the line number of the error 
//=     RETURNS:        integer 
//=     PURPOSE:        All javascript errors are directed to this funciton by window.error 
//=						The true return value supresses any browser javascript errors. 
//=     AUTHOR:         Steve Jansen, Byte Interactive <stj@byteinteractive.com> 
//=     DATE:           Decmeber 11th, 2000 
//===============================================================================================================================================================
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()
//=	PARAMETERS:	none
//=	RETURNS:	true
//=	PURPOSE:	Event handler for onload of all pages
//=	AUTHOR:		Steve Jansen, Byte Interactive <stj@byteinteractive.com>
//=	DATE:		November 29th, 2000
//===============================================================================================================================================================
function onLoad()
{ 
	cacheImages();	//function to cache all rollover images
	//window.status = 'Welcome To ';
	return true;
}

//===============================================================================================================================================================
//=	FUNCTION: 	onResize()
//=	PARAMETERS:	none
//=	RETURNS:	true
//=	PURPOSE:	Event handler for resize of all pages in IE4+
//=	AUTHOR:		Steve Jansen, Byte Interactive <stj@byteinteractive.com>
//=	DATE:		November 29th, 2000
//===============================================================================================================================================================
function onResize()
{ 
	if (w3c)
		location.reload();
	return;
}

//===============================================================================================================================================================
//=	FUNCTION: 	cacheImages()
//=	PARAMETERS:	none
//=	RETURNS:	null
//=	PURPOSE:	Used for JavaScript rollovers.  This function preloads (caches) all "on" state images.
//=				Call this function from the body onload event.
//=	AUTHOR:		Steve Jansen, Byte Interactive <stj@byteinteractive.com>
//=	DATE:		November 30th, 2000
//===============================================================================================================================================================
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()
//=	PARAMETERS:	oImage (Image Object)
//=	RETURNS:	null
//=	PURPOSE:	Used for JavaScript rollovers.  This function changes the src of oImage to the "on" state
//=	AUTHOR:		Steve Jansen, Byte Interactive <stj@byteinteractive.com>
//=	DATE:		November 30th, 2000
//===============================================================================================================================================================
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		
	oImage.src = oImage.src.replace("_off.", "_on.");
				
	return;
}

//===============================================================================================================================================================
//=	FUNCTION: 	clearImages()
//=	PARAMETERS:	oImage (Image Object)
//=	RETURNS:	null
//=	PURPOSE:	Used for JavaScript rollovers.  This function resets all images to their "off" state upon the mouseout event
//=	AUTHOR:		Steve Jansen, Byte Interactive <stj@byteinteractive.com>
//=	DATE:		November 30th, 2000
//===============================================================================================================================================================
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()
//=	PARAMETERS:	url, name, w, h, rs, scr, cen
//=	RETURNS:	null
//=	PURPOSE:	Used for opening a new window with set properties
//=	AUTHOR:		David Alperovich, Byte Interactive <dalperovich@byteinteractive.com>
//= UPDATED:	David Whalen, Byte Interactive <david.whalen@byteinteractive.com>
//=	DATE:		December 11, 2001
//===============================================================================================================================================================
function openWindow(url, name, resize, width, height, 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);
	return ;
}

//===============================================================================================================================================================
//  FUNCTION:   getDHTMLObj
//  ARGUMENTS:  theStr - String to decode
//  PURPOSE:    Return a DHTML object, based on browser version
//  RETURNS:    Object
//  AUTHOR:     David Whalen <dw@byteinteractive.com>
//  DATE:       October 25, 2001
//===============================================================================================================================================================
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:   alertBox(url)
//  ARGUMENTS:  
//  PURPOSE:    Opens alert box in bric-a-brac section
//  RETURNS:    
//  AUTHOR:     Anthony Pagano <anthony.pagano@byteinteractive.com>
//  DATE:       February 12, 2003
//===============================================================================================================================================================
function alertBox(url)
{
	var width = 481;
	var height = 200;
	openWindow(url, 'message', false, width, height, false, true);
}

//===============================================================================================================================================================
//  FUNCTION:   changeURL(box)
//  ARGUMENTS:  
//  PURPOSE:    Drop down menu function used in bric-a-brac and drinks section
//  RETURNS:    
//  AUTHOR:     Anthony Pagano <anthony.pagano@byteinteractive.com>
//  DATE:       February 20, 2003
//===============================================================================================================================================================

function changeURL(box)
{
	document.location = box.options[box.selectedIndex].value			
}

// /_scripts/validate.js
//===============================================================================================================================================================
//=     FUNCTION:       isAlpha()
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it is letters only
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           Jun 21, 2001
//===============================================================================================================================================================
function isAlpha(theStr) {
	var theReg =  /^[A-Za-z]+$/;
	return(theReg.test(theStr));
}

//===============================================================================================================================================================
//=     FUNCTION:       isAlphaNumeric()
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it is letters or numbers only
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           Jun 21, 2001
//===============================================================================================================================================================
function isAlphaNumeric(theStr) {
	var theReg =  /^[A-Za-z0-9]+$/;
	return(theReg.test(theStr));
}

//===============================================================================================================================================================
//=     FUNCTION:       isEmail() 
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it represents a valid email address
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           April 18, 2001
//===============================================================================================================================================================
function isEmail(theStr) {
	var theReg = /^[\w\.\-]+\@[\w\.\-]+\.[\w.]{2,}$/;
	return(theReg.test(theStr));
}

//=====================================================================================================================================================
//  FUNCTION:   isNumber
//  ARGUMENTS:  sValue - string
//				theLowerBound - number specifying the minimum value
//				theUpperBound - number specifying the maximum value
//  PURPOSE:    Check and input string to see if it qualifies as a number within a set of bounds
//  RETURNS:    Boolean (true/false)
//  AUTHOR:     David Whalen, <dw@byteinteractive.com>
//  DATE:       June 1, 2001
//=====================================================================================================================================================
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()
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it is numeric only
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           May 14, 2001
//===============================================================================================================================================================
function isNumeric(theStr) {
	var theReg =  /^\d+$/;
	return(theReg.test(theStr));
}

//===============================================================================================================================================================
//=     FUNCTION:       isPhoneNumber() 
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it represents a valid US Phone Number.
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           April 17, 2001
//===============================================================================================================================================================
function isPhoneNumber(theStr) {
	var theReg = /^\(?\d{3}\)?\D?\d{3}\D?\d{4}$/;
	return(theReg.test(theStr));
}

//=====================================================================================================================================================
//  FUNCTION:   isString
//  ARGUMENTS:  theValue - string
//				theMinLength - number specifying the minimum string length
//				theMaxLength - number specifying the maximum string length
//  PURPOSE:    Check and input string to see if it qualifies as a string of an expected length
//  RETURNS:    Boolean (true/false)
//  AUTHOR:     David Whalen, <dw@byteinteractive.com>
//  DATE:       June 1, 2001 (updated June 21, 2001)
//=====================================================================================================================================================
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:       isZipCode() 
//=     PARAMETERS:     theStr as string is the text to check
//=     RETURNS:        boolean
//=     PURPOSE:        Check an input string to see if it represents a valid US ZIP Code.
//=     AUTHOR:         David Whalen, Byte Interactive <dw@byteinteractive.com> 
//=     DATE:           April 17, 2001
//===============================================================================================================================================================
function isZipCode(theStr) {
	var theReg =  /^\d{5}(\-\d{4})?$/;
	return(theReg.test(theStr));
}