// begin LOGO MOUSEOVER
    cw_off = new Image()
    cw_off.src = "http://www.lowcarbiseasy.com/images/cw_logo_colour_off.gif";
    cw_on = new Image()
    cw_on.src = "http://www.lowcarbiseasy.com/images/cw_logo_colour_on.gif"
// end LOGO MOUSEOVER









// begin OPEN POPUP WINDOW
// 1=delete, logout
// 2=friend, login, loginfail, printall, saveas
// 3=credits, disclaimer, help, security, terms
// 4=cookbook (add, contents, contents_sample, edit, section, view.htm, view_sample, x-y.htm)
function openWindow1(url) {
        popUpWin=window.open(url,'NewWindow1','toolbar=0,location=no,directories=0,status=0,menbar=0,scrollbars=0,resizable=0,width=300,height=300,top=200,left=200');
        if (navigator.appName == 'Netscape') {popUpWin.focus();}
}
function openWindow2(url) {
        popUpWin=window.open(url,'NewWindow2','toolbar=0,location=no,directories=0,status=0,menbar=0,scrollbars=0,resizable=0,width=600,height=450,top=100,left=100');
        if (navigator.appName == 'Netscape') {popUpWin.focus();}
}
function openWindow3(url) {
        popUpWin=window.open(url,'NewWindow3','toolbar=0,location=no,directories=0,status=0,menbar=0,scrollbars=1,resizable=0,width=650,height=500,top=30,left=30');
        if (navigator.appName == 'Netscape') {popUpWin.focus();}
}
function openWindow4(url) {
        popUpWin=window.open(url,'NewWindow4','toolbar=0,location=no,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=760,height=520,top=15,left=15');
        if (navigator.appName == 'Netscape') {popUpWin.focus();}
}
function openWindow5(url) {
        popUpWin=window.open(url,'NewWindow5','toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=760,height=520,top=15,left=15');
        if (navigator.appName == 'Netscape') {popUpWin.focus();}
}
// end POPUP WINDOW




// begin FLOATING TOP BUTTON (NO LONGER USED)
// note - appears on full size windows and size 1-3 popups only
function setVariables() {
imgwidth=18;  // logo width, in pixels
imgheight=18;  // logo height, in pixels
if (navigator.appName == "Netscape") {
horz=".left";
vert=".top";
docStyle="document.";
styleDoc="";
innerW="window.innerWidth";
innerH="window.innerHeight";
offsetX="window.pageXOffset";
offsetY="window.pageYOffset";
}
else {
horz=".pixelLeft";
vert=".pixelTop";
docStyle="";
styleDoc=".style";
innerW="document.body.clientWidth";
innerH="document.body.clientHeight";
offsetX="document.body.scrollLeft";
offsetY="document.body.scrollTop";
   }
}
function checkLocation() {
objectXY="branding";
var availableX=eval(innerW);
var availableY=eval(innerH);
var currentX=eval(offsetX);
var currentY=eval(offsetY);
x=availableX-(imgwidth+30)+currentX;
y=availableY-(imgheight+25)+currentY;
evalMove();
setTimeout("checkLocation()",10);
}
function evalMove() {
eval(docStyle + objectXY + styleDoc + horz + "=" + x);
eval(docStyle + objectXY + styleDoc + vert + "=" + y);
}
// end FLOATING TOP BUTTON





// begin REMOVE TOOLBAR FOR PRINTING
//GCB adapted for Firefox using http://www.webdeveloper.com/forum/archive/index.php/t-63381.html
function addhandlers(o) {
    o.onabort = handler;        o.onblur = handler;
    o.onchange = handler;       o.onclick = handler;
    o.ondblclick = handler;     o.onerror = handler;
    o.onfocus = handler;        o.onkeydown = handler;
    o.onkeypress = handler;     o.onkeyup = handler;
    o.onload = handler;         o.onmousedown = handler;
 //   o.onmouseout = handler;     o.onmouseover = handler;
    o.onmouseup = handler;      o.onmove = handler;
    o.onreset = handler;        o.onresize = handler;
    o.onselect = handler;       o.onsubmit = handler;
    o.onunload = handler;
} // Now use addhandlers() to register all event handlers on all

function handler(e) {
//e = window.event;   // Grab the event.
if (!e) var e = window.event;

//if (e.type.indexOf("focus"))	{
if (e.type && e.type.indexOf("focus"))	{
	FocusObject.accum++;
}
//if (e.type.indexOf("blur"))	{
if (e.type && e.type.indexOf("blur"))	{
	FocusObject.accum++;
}
//     window.status="handler: "+e.type+" cnt: "+FocusObject.accum;
     	if (FocusObject.accum >3)	{
	// The print dialog box has come up and the user has clicked "something", so re-display the toolbar.
//		if (navigator.appName == "Netscape") {
		if (document.layers) {
			document.layers["floatdiv"].visibility="show";
		}
//		else if (navigator.appName == "Microsoft Internet Explorer") {
		else if (document.all) {
			document.all.floatdiv.style.visibility="visible";
		}
//GCB added for Firefox
		else if (document.getElementById) {
			document.getElementById("floatdiv").style.display = "block";
// ? need something here to make page have focus and therefore toolbar to reappear ?
// e.g.				setTimeout("window.focus();", 10);
		}
		else {
		}
	}
}

function FocusObject(start) {
// this constructor creates our event counter, the count var is unused.
this.count = start;
}

function axaPrint() {
// create an object to track event counts
var focus = new FocusObject(0);
// an instance var, not currently used
focus.count=1;
// a class var, used as a global
FocusObject.accum=1;
// add handlers to start counting events
addhandlers(window);
addhandlers(document);
//user wants to print, lets switch off the toolbar
//	if (navigator.appName == "Netscape") {
	if (document.layers) {
		document.layers["floatdiv"].visibility="hide";
	}
//	else if (navigator.appName == "Microsoft Internet Explorer") {
	else if (document.all) {
		document.all.floatdiv.style.visibility="hidden";
	}
//GCB added for Firefox
	else {
		document.getElementById("floatdiv").style.display = "none";

	}
this.window.print();
}
// end REMOVE TOOLBAR FOR PRINTING



// begin TOGGLE MESSAGE
// http://www.webdeveloper.com/forum/showthread.php?t=60361
function toggle(obj) {
var sibling;
if(obj.nextSibling.nodeType==3) {
    sibling=obj.nextSibling.nextSibling;
    }
else {
    sibling=obj.nextSibling;
    }
sibling.style.display=(sibling.style.display=='none')? 'block' : 'none';
}
// end TOGGLE MESSAGE




// begin FLOATING TOOLBAR - - OLD - replaced by floatmenu.js 1-1-2010
// note - appears on cookbook size 4 popup windows only
// This script and many more are available free online at The JavaScript Source!! http://javascript.internet.com
function initiateVariables() {
if (navigator.appName == "Netscape") {
v=".top=";
dS="document.";
sD="";
y1="window.pageYOffset";
}
else {
v=".pixelTop=";
dS="";
sD=".style";
y1="document.body.scrollTop";
   }
}
function checkPosition() {
object="object1";
yy=eval(y1);
eval(dS+object+sD+v+yy);
setTimeout("checkPosition()",10);
//window.status=yy+" "+y1;
}
// function resetPosition() {
// object="object1";
// yy=eval(y1);
// yy=0;
// eval(dS+object+sD+v+yy);
// setTimeout("checkPosition()",10);
// window.status=yy+" "+y1;
// }
// end FLOATING TOOLBAR



// begin DISABLE RIGHT CLICK
// Original:  Martin Webb (martin@irt.org)
// This script and many more are available free online at The JavaScript Source!! http://javascript.internet.com
function right(e) {
return true;
if (navigator.appName == 'Netscape' && 
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' && 
(event.button == 2 || event.button == 3)) {
alert("Right-click has been disabled for copyright protection.");
return false;
}
return true;
}
document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;
// end DISABLE RIGHT CLICK
function clear(rowId) {
var ingRow=rowId;
//alert ("ingRow:"+ingRow)
var ing		=rowId+'ING';
var metric	=rowId+'METRIC';
var imperial	=rowId+'IMPERIAL';
var volume	=rowId+'VOLUME';
var carb	=rowId+'CARB';
//alert ("ele:"+document.edit.elements[carb].value)
document.edit.elements[metric].value='';
document.edit.elements[ing].value='';
document.edit.elements[imperial].value='';
document.edit.elements[volume].value='';
document.edit.elements[carb].value='';
updateCarbs();
}
function login(url) {
	//alert ("in login");
	openWindow4(url);
	//document.loginform.username.focus();
}



















// From FormChek.js
//
// 18 Feb 97 created Eric Krock
//
// (c) 1997 Netscape Communications Corporation

// decimal point character differs by language and culture
var decimalPointDelimiter = "."
var decimalPointDelimiter2 = ","

// whitespace characters
var whitespace = " \t\n\r";


var defaultEmptyOK = false


function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

// Removes all characters which appear in string bag from string s.

function stripCharsInBag (s, bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function stripWhitespace (s)

{   return stripCharsInBag (s, whitespace)
}



// isPositiveInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer > 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isPositiveInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isPositiveInteger.arguments.length > 1)
        secondArg = isPositiveInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a positive, not negative, number

    return (isSignedInteger(s, secondArg)
         && ( (isWhitespace(s) && secondArg)  || (parseInt (s) > 0) ) );
}


function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}


function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter || s == decimalPointDelimiter2) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter || c == decimalPointDelimiter2) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function dp (n) {
    var x = n * Math.pow(10, 2);
    var y = Math.round(x);
    var z = y / Math.pow(10, 2);
    return z;
    // return pad_with_zeros(z, 2);
}

function toPeriod (field)
{
	var x = field.value;
	//var float = "," // default;
  	if( (p=x.indexOf(",")) != -1 ) {
    		x = x.substring(0,p) + "." + x.substring(p+1);
		field.value = x;
	}
}


function updateCarbs()
{
	var i;
	var carbsFld;
	var carbsFldUB;
	var carbs = 0.00;
	var carbsPerServingFld;
	var carbsPerServing = 0.00;
	var servingsFld;
	var servings = 0.00;
	var totalCarbsFld;
	var totalCarbs = 0.00;

	carbsPerServingFld = "CPS";
	totalCarbsFld = "TC";
	servingsFld = "SERVINGS";

	var index;
	index = 0;
	for (i=0; i < document.edit.elements.length; i++) {
		var field = document.edit.elements[i].name;
		carbsFld = index + "CARBS";
		carbsFldUB = "ub" + index + "CARBS";
		if ((field.indexOf("CARB") >= 1) && (field.indexOf("CARB") <= 4)) {		// e.g. check fir 2CARB and ub2CARB
			// alert(field);

			if (!isNaN(parseFloat(stripWhitespace(document.edit.elements[field].value)))) {
				carbs = parseFloat(document.edit.elements[field].value);
				if (isFloat(carbs)) {
					totalCarbs += carbs;
				}
				// alert(carbs);
			}
			// document.edit.elements[totalCarbsFld].value = carbs;


			index++;
		}
	}

	servings =  stripWhitespace(document.edit.elements[servingsFld].value);


	carbsPerServing = 0;
	if (isFloat(servings)) {
		if (servings>0) {
			carbsPerServing = totalCarbs/servings;
		}
	}


	document.edit.elements[totalCarbsFld].value = dp(totalCarbs);
	document.edit.elements[carbsPerServingFld].value = dp(carbsPerServing);

}

// begin OPEN CENTRED WINDOW
function centerWindow(url,width,height,scroll)
{
 if (window.screen)
 {
  var aw = screen.availWidth;
  var ah = screen.availHeight;
  var x = aw/2 - width/2;
  var y = ah/2 - height/2;
 }
 var params="menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars="+scroll+",resizable=no,dependent,top="+y+",left="+x+",width="+width+",height="+height;
 popupWin = window.open(url, 'popup',params);
 popupWin.focus();
}
// end OPEN CENTRED WINDOW

// begin LOAD CHOSEN PAGE
function loadPage(page)
{
 window.opener.document.location=page;
 window.close();
}
// end LOAD CHOSEN PAGE
