function showHideServingSizer( bShow ) {
	var oDiv = document.getElementById( 'containerServingSize' );
	if ( null != oDiv ) {
		if ( bShow )
			oDiv.style.display = 'block';
		else
			oDiv.style.display = 'none';
	}
}
function heartOn( bHover ) {
	var sImgSrc = '';
	var oImg = document.getElementById( 'myHeart' );
	if ( null != oImg ) {
		sImgSrc = String( oImg.src );
		if ( bHover ) {
			oImg.src = sImgSrc.replace( '.off.gif', '.gif' );
		} else {
			oImg.src = sImgSrc.replace( '.gif', '.off.gif' );
		}
	}
}
function updateServingSize( newValueObj ) {
	//if ( String( newValue ).length != 0 ) {
	if ( null != newValueObj ) {
		var origSize = parseInt( newValueObj.origSize );
		var newSize = parseInt( newValueObj.newSize );
		
		if ( ( null != origSize ) && ( null != newSize ) ) {
			if ( origSize == newSize ) {
				var sOut = 	'You have not provided a serving size value that differs from the original serving size.\n\n' + 
							'Enter the new serving size, then again click Update.\n' +
							'To cancel and keep the original serving size, simply click the close (x) button';
				window.alert( sOut );
				return;
			}
			
			var operator = null;
			
			if ( newSize > origSize )
				operator = 'multiplyer';
			if ( newSize < origSize )
				operator = 'divisor';
	
			var sUrl = 	'ViewRecipe.asp?RecipeId=' + newValueObj.RecipeId +
						'&RecipeName=' + newValueObj.RecipeName + 
						'&osv=' + newValueObj.origSize + 
						'&nsv=' + newValueObj.newSize + 
						'&op=' + operator;
			document.location = sUrl;
		}
	}
}
function $( obj ) {
	if ( document.all ) return document.all[ obj ];
	if ( document.layers ) return document.layers[ obj ];
	if ( document.getElementById ) return document.getElementById( obj );
	return null;
}


Number.prototype.fraction=fraction;
function fraction( decimal ) {
	if(!decimal)
		decimal = this;

	var whole = String(decimal).split('.')[0];
	decimal = parseFloat("." + String(decimal).split('.')[1] );
	num = "1";
	for( z=0; z<String(decimal).length-2; z++ ){
		num += "0";
	}
	num = parseInt(num);
	decimal = decimal*num;
	for( z=2; z<decimal+1; z++ ) {
		if( (decimal%z==0) && (num%z==0) ) {
			decimal = decimal/z;
			num = num/z;
			z=2;
		}
	}
	return ( (whole==0) ? "" : whole + " ") + decimal + "/" + num;
}
function sanitize( oElement ) {
	var sOut = String( oElement.value );
	if ( sOut.length > 0 )
		oElement.value = encodeURIComponent( sOut );
}
function isZeroLen( sValue ) {
	return String( sValue ).length == 0;
}
function getCookie( cookieName ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var aCookies = document.cookie.split( ';' );
	var aTempCookie = '';
	var sCookieName = '';
	var sCookieValue = '';
	var bFoundCookie = false; // set boolean t/f default f

	for ( i = 0; i < aCookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		aTempCookie = aCookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		sCookieName = aTempCookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed cookieName
		if ( sCookieName == cookieName )
		{
			bFoundCookie = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( aTempCookie.length > 1 )
			{
				sCookieValue = unescape( aTempCookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return sCookieValue;
			break;
		}
		aTempCookie = null;
		sCookieName = '';
	}
	if ( !bFoundCookie )
	{
		return null;
	}
}
//alert( String("whateva's").replace(/'/g, "&#146;") );
//alert(String.fromCharCode(47));
	function sanitizeInput( oElement ) {
		var sOutputValue = String( oElement.value );
		var slash = String.fromCharCode(47);

		/** Globally replace any semiColon char ';' first, as they will be injected by 
			any entity escaping that follows, thus being both necessary and valid.
		**/

		sOutputValue = sOutputValue.replace( /\;/g, "&#059;" );
		sOutputValue = sOutputValue.replace( /\!/g, "&#033;" );
		sOutputValue = sOutputValue.replace( /\"/g, "&#034;" );
		sOutputValue = sOutputValue.replace( /\'/g, "&#039;" );
		sOutputValue = sOutputValue.replace( /</g, "&lt;" );
		sOutputValue = sOutputValue.replace( />/g, "&gt;" );
		sOutputValue = sOutputValue.replace( /%/g, "&#037;" );
		sOutputValue = sOutputValue.replace( slash, "&#047;" );
		sOutputValue = sOutputValue.replace( /<script>/gi, "" );
		sOutputValue = sOutputValue.replace( /<\/script>/gi, "" );
		sOutputValue = sOutputValue.replace( /\(/g, "&#040;" );
		sOutputValue = sOutputValue.replace( /\)/g, "&#041;" );
		sOutputValue = sOutputValue.replace( /\)\;/g, "&#041;&#059;" );
		sOutputValue = sOutputValue.replace( /\*/g, "&#042;" );
		sOutputValue = sOutputValue.replace( /\+/g, "&#043;" );
		sOutputValue = sOutputValue.replace( /\,/g, "&#044;" );
		sOutputValue = sOutputValue.replace( /\-/g, "&#045;" );
		sOutputValue = sOutputValue.replace( /\./g, "&#046;" );
		sOutputValue = sOutputValue.replace( /\:/g, "&#058;" );
		
		oElement.value = sOutputValue;
		//alert(sOutputValue);
		return true;
	}
	
	function sanitizeKeywords( oElement ) {
		var sOutputValue = String( oElement.value );
		var slash = String.fromCharCode(47);

		/** Globally replace any semiColon char ';' first, as they will be injected by 
			any entity escaping that follows, thus being both necessary and valid.
		**/

		sOutputValue = sOutputValue.replace( /\;/g, "&#059;" );
		sOutputValue = sOutputValue.replace( /\!/g, "&#033;" );
		sOutputValue = sOutputValue.replace( /\"/g, "&#034;" );
		sOutputValue = sOutputValue.replace( /\'/g, "&#039;" );
		sOutputValue = sOutputValue.replace( /</g, "&lt;" );
		sOutputValue = sOutputValue.replace( />/g, "&gt;" );
		sOutputValue = sOutputValue.replace( /%/g, "&#037;" );
		sOutputValue = sOutputValue.replace( slash, "&#047;" );
		sOutputValue = sOutputValue.replace( /<script>/gi, "" );
		sOutputValue = sOutputValue.replace( /<\/script>/gi, "" );
		sOutputValue = sOutputValue.replace( /\(/g, "&#040;" );
		sOutputValue = sOutputValue.replace( /\)/g, "&#041;" );
		sOutputValue = sOutputValue.replace( /\)\;/g, "&#041;&#059;" );
		sOutputValue = sOutputValue.replace( /\*/g, "&#042;" );
		sOutputValue = sOutputValue.replace( /\+/g, "&#043;" );
		//sOutputValue = sOutputValue.replace( /\,/g, "&#044;" );
		sOutputValue = sOutputValue.replace( /\-/g, "&#045;" );
		sOutputValue = sOutputValue.replace( /\./g, "&#046;" );
		sOutputValue = sOutputValue.replace( /\:/g, "&#058;" );
		
		oElement.value = sOutputValue;
		//alert(sOutputValue);
		return true;
	}
	function safeEventAttach( target, eventType, functionRef, captureScope ) {
	    var attached = false;
	    if ( target.addEventListener ) {
	        if ( typeof captureScope == 'undefined' )
	            captureScope = false;
	            
	        target.addEventListener( eventType, functionRef, captureScope );
	        attached = true;
	    }
	    
	    if ( !attached && !target.addEventListener && target.attachEvent ) {
	        target.attachEvent( "on" + eventType, functionRef );
	        attached = true;
	    }
	    
	    if ( !attached )
	        throw ( 'Client side event could not be attached.' );
	}