var validNums1 = '0123456789.tT';
var validNums = '0123456789.';
var validInt = '0123456789';
var validLetters = "'.%abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var validAll = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' /";
var inValidChars = "%[]+'^*";
var yesno;
var actionurl;
var ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;
var ie7 = navigator.userAgent.toLowerCase().indexOf('msie 7') != -1;
var webname="Boots Diets";

function getWinHeight(){

    var viewportheight;

     if (typeof window.innerHeight != 'undefined'){

     // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

     if (typeof window.innerHeight != 'undefined')
     {
          viewportheight = window.innerHeight
     }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

     else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientHeight != 'undefined' && document.documentElement.clientHeight != 0)
     {
           viewportheight = document.documentElement.clientHeight;
     }

     // older versions of IE

     }else
     {
           viewportheight = document.getElementsByTagName('body')[0].clientHeight;
     }

     return viewportheight;
}

function popup(theURL,winName,width,height,features) {
    var window_width = width;
    var window_height = height;
    var newfeatures= features;
    var window_top = (screen.height-window_height)/2;
    var window_left = (screen.width-window_width)/2;
    var wname = winName.replace(' ','');
    newWindow=window.open(''+ theURL + '',''+wname+'','width=' + window_width + ',height=' + window_height + ',top=' + window_top + ',left=' + window_left + ',' + newfeatures + '');
    newWindow.focus();
}


function setHomePage() {
	if (window.external)
	{
		document.body.style.behavior='url(#default#homepage)';
   		document.body.setHomePage(window.location.href);
	}
	else
	{
		alert("To set this page as your Home Page drag the Bookmark icon over the home icon in the toolbar");
	}
}


function nu_create_window(w,h,url)
{

var options = "width=" + w + ",height=" + h + ",resizable=no";
var new_window = window.open(url, "new_window", options);

}

function nu_changeText(id,newtext)
{
	var f, obj;
	if ((obj=findObj(id))!=null)
	{

		obj.innerHTML=newtext;
	}

}
function nu_hideObject(id)
{
	var f, obj;
	if ((obj=findObj(id))!=null)
	{

		obj.visible=newtext;
	}

}
function checkEmptyFields(frm) {
    if($('exDesc').value === ''
        || $('exDur').value === ''
            || $('exkc').value === '') {
            alert('Please Complete The Relevant Fields');
            return false;
    }
    else {
        $(frm).submit();
        return true;
    }
}
function nu_validateKeyPress(e, validSet)
{
    var key;
    var keychar;
    if(window.event || !e.which) { // IE
        key = e.keyCode; // IE
    }
    else if(e) {
        key = e.which;   // Netscape
    }
    else {
        return true;     // no validation
    }
    if(key<32) {
        return true;
    }
    keychar = String.fromCharCode(key);
    validSet += String.fromCharCode(8);
    var ind = validSet.indexOf(keychar);
    if (validSet.indexOf(keychar) < 0) {
      return false;
    }
    return true;
}
function nu_changeMeasure(f, imperial)
{
	//this will change the measures to the
	//required labels
	//the label ids on the page must match these setup
	var obj;

	if(!imperial)
	{
		nu_changeText('heightlabel1','ft');
		nu_changeText('heightlabel2','ins');
		nu_changeText('weightlabel1','st');
		nu_changeText('weightlabel2','lbs');
		showHideLayers('weightlabel2','show');
		showHideLayers('txtweight2','show');
		nu_changeText('measurechange','Click here to change to metric');
		nu_changeText('weightloss1','1/2 lb');
		nu_changeText('weightloss2','1 lb');
		nu_changeText('weightloss3','1 1/2 lb');
		nu_changeText('weightloss4','2 lb');
		f.ismetric.value="0"
	}
	else
	{
		nu_changeText('heightlabel1','m');
		nu_changeText('heightlabel2','cm');
		nu_changeText('weightlabel1','kg');
		showHideLayers('weightlabel2','hide');
		showHideLayers('txtweight2','hide');
//		nu_changeText('weightlabel2','&nbsp;g&nbsp;');
		nu_changeText('measurechange','Click here to change to imperial');
		nu_changeText('weightloss1','0.23 kg');
		nu_changeText('weightloss2','0.46 kg');
		nu_changeText('weightloss3','0.69 kg');
		nu_changeText('weightloss4','0.92 kg');


		f.ismetric.value="1"
	}


}


function isDate(DateToCheck){
if(DateToCheck==""){return false;}
var m_strDate = FormatDate(DateToCheck);
if(m_strDate==""){
return false;
}
var m_arrDate = m_strDate.split("/");
var m_DAY = m_arrDate[0];
var m_MONTH = m_arrDate[1];
var m_YEAR = m_arrDate[2];
if(m_YEAR.length > 4){return false;}
m_strDate = m_MONTH + "/" + m_DAY + "/" + m_YEAR;
var testDate=new Date(m_strDate);
if(testDate.getMonth()+1==m_MONTH){
return true;
}
else{
return false;
}
}//end function




function FormatDate(DateToFormat,FormatAs){
if(DateToFormat==""){return"";}
if(!FormatAs){FormatAs="dd/mm/yyyy";}

var strReturnDate;
FormatAs = FormatAs.toLowerCase();
DateToFormat = DateToFormat.toLowerCase();
var arrDate
var arrMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var strMONTH;
var Separator;

while(DateToFormat.indexOf("st")>-1){
DateToFormat = DateToFormat.replace("st","");
}

while(DateToFormat.indexOf("nd")>-1){
DateToFormat = DateToFormat.replace("nd","");
}

while(DateToFormat.indexOf("rd")>-1){
DateToFormat = DateToFormat.replace("rd","");
}

while(DateToFormat.indexOf("th")>-1){
DateToFormat = DateToFormat.replace("th","");
}

if(DateToFormat.indexOf(".")>-1){
Separator = ".";
}

if(DateToFormat.indexOf("-")>-1){
Separator = "-";
}


if(DateToFormat.indexOf("/")>-1){
Separator = "/";
}

if(DateToFormat.indexOf(" ")>-1){
Separator = " ";
}

arrDate = DateToFormat.split(Separator);
DateToFormat = "";
	for(var iSD = 0;iSD < arrDate.length;iSD++){
		if(arrDate[iSD]!=""){
		DateToFormat += arrDate[iSD] + Separator;
		}
	}
DateToFormat = DateToFormat.substring(0,DateToFormat.length-1);
arrDate = DateToFormat.split(Separator);

if(arrDate.length < 3){
return "";
}

var DAY = arrDate[0];
var MONTH = arrDate[1];
var YEAR = arrDate[2];




if(parseFloat(arrDate[1]) > 12){
DAY = arrDate[1];
MONTH = arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
YEAR = arrDate[0];
DAY = arrDate[2];
MONTH = arrDate[1];
}


for(var iSD = 0;iSD < arrMonths.length;iSD++){
var ShortMonth = arrMonths[iSD].substring(0,3).toLowerCase();
var MonthPosition = DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	MONTH = iSD + 1;
		if(MonthPosition == 0){
		DAY = arrDate[1];
		YEAR = arrDate[2];
		}
	break;
	}
}

var strTemp = YEAR.toString();
if(strTemp.length==2){

	if(parseFloat(YEAR)>40){
	YEAR = "19" + YEAR;
	}
	else{
	YEAR = "20" + YEAR;
	}

}


	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	MONTH = "0" + MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	DAY = "0" + DAY;
	}
	switch (FormatAs){
	case "dd/mm/yyyy":
	return DAY + "/" + MONTH + "/" + YEAR;
	case "mm/dd/yyyy":
	return MONTH + "/" + DAY + "/" + YEAR;
	case "dd/mmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1].substring(0,3) + " " + YEAR;
	case "mmm/dd/yyyy":
	return arrMonths[MONTH -1].substring(0,3) + " " + DAY + " " + YEAR;
	case "dd/mmmm/yyyy":
	return DAY + " " + arrMonths[MONTH -1] + " " + YEAR;
	case "mmmm/dd/yyyy":
	return arrMonths[MONTH -1] + " " + DAY + " " + YEAR;
	}

return DAY + "/" + strMONTH + "/" + YEAR;;

} //End Function


function findObj(theObj, theDoc)
{
  var p, i, foundObj;

  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

  return foundObj;
}


function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.

	RETVAL:
		The formatted number!
 **********************************************************************/
{
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number

	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign


	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);

	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}
function showHideLayers(name,visStr)
{

  var i, visStr, obj, args = showHideLayers.arguments;


    if ((obj = findObj(name)) != null)
    {

      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') visStr = 'visible';
        else if(visStr == 'hide') visStr = 'hidden';
      }
      obj.visibility = visStr;
    }

}

function confirmAddFavs(url)
{
    actionurl = url;
    createYESNO("Do you want to add this item to your Favourites?","/media/images/parts/dialog/confirm_favs.gif");

}

function confirmdelete(url,message)
{
	actionurl = url;
	createYESNO(message,"/media/images/parts/dialog/confirm_delete.gif","Confirm");

}
function confirmyes()
{
    window.location.href=actionurl;
}

function createYESNO(text,image,btntxt){
   if(! btntxt){
       btntxt="Yes";
   }
   var boxhtml = '<div class="diaryPopTR"><div class="diaryPopTL"><div class="diaryPopHdr"><a title="Close" class="dpClose" onclick="closeOverLay(\'YESNO\')" href="#url"></a></div><div class="diaryPopBR"><div class="diaryPopBL"><div id="ynContent" style="background-image:url('+image+');"><p>'+text+'</p><div id="confirmBtns" class="tlTXT"><div class="retButtonSml"><a onclick="removeYESNO()" href="#url"><span class="tl"><span class="br"><span class="btnTXT"><span class="aBtnPad">Cancel</span></span></span></span></a></div><div class="ctaButtonSml"><a onclick="confirmyes()" href="#url"><span class="tl"><span class="br"><span class="btnTXT"><span class="aBtnPad">'+btntxt+'</span></span></span></span></a></div><div class="clrFlt"></div></div><div class="clrFlt"></div></div></div></div></div></div>';
   createYESNODialog(boxhtml);
}

function createYESNOForm(text,image,f,btntxt){
   if(! btntxt){
       btntxt="Save";
   }
    var innerhtml = '<div class="diaryPopTR"><div class="diaryPopTL"><div class="diaryPopHdr"><a title="Close" class="dpClose" onclick="closeOverLay(\'YESNO\')" href="#url"></a></div><div class="diaryPopBR"><div class="diaryPopBL"><div id="ynContent" style="background-image:url('+image+');"><p>'+text+'</p><div id="confirmBtns" class="tlTXT"><div class="retButtonSml"><a onclick="removeYESNO()" href="#url"><span class="tl"><span class="br"><span class="btnTXT"><span class="aBtnPad">Cancel</span></span></span></span></a></div><div class="ctaButtonSml"><a onclick="document.forms[\''+f+'\'].submit();" href="#url"><span class="tl"><span class="br"><span class="btnTXT"><span class="aBtnPad">'+btntxt+'</span></span></span></span></a></div><div class="clrFlt"></div></div><div class="clrFlt"></div></div></div></div></div></div>';
    createYESNODialog(innerhtml);
}


function createYESNODialog(boxhtml){
    var box = $("YESNO");
    var added = false;
    if(box){
         document.body.removeChild(box);
         box = false;
    }

    if(!box)
    {
        box = document.createElement("div");
	box.id = "YESNO";
        box.setAttribute('style','display:none;')
        added = true;
    }

    box.innerHTML=boxhtml;

    if(added) document.body.appendChild(box);
    yesno = new Dialog.Box(document.getElementById("YESNO"));
            box.style.position = 'fixed';
            box.show();

}


function removeYESNO()
{
	yesno.hide();

        document.body.removeChild($("dialog_overlay"));
        document.body.removeChild($("YESNO"));

}

function swapDisplay(a,b,link,txt){
    var divA = document.getElementById(a);
    var divB = document.getElementById(b);
    var link = document.getElementById(link);

    if(divA && divB){

        if(divA.style.display=='block'){
            divA.style.display='none';
            divB.style.display='block'
            link.innerHTML=txt+' Metric';
        }
        else{
            divA.style.display='block';
            divB.style.display='none';
            link.innerHTML=txt+' Imperial';
        }
    }

    return false;
}
fixNum = function(f,decimal)
{
 if(f<0)
 	return "";
 return (1 * f).toFixed(decimal);
}


function setCookie(c_name,value,expiredays){
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function closeOverLay(id){

    var doverlay = $('dialog_overlay');
    var div = $(id);

    if(doverlay) {
        document.body.removeChild(doverlay);
    }
    if(div){
        document.body.removeChild(div);
    }
}

 function formSubmit(form,func)
  {
    if(checkHtWt(form))
        $(form).submit();

  }

  function checkHtWt(f){
    height= getHeight(f);
    weight = getWeight(f);
    if(!isMetric(f))
    {
            if((height <51)||(height>94))
            {
                    alert("The minimum and maximum heights allowed are 4ft 3in and 7ft 10in. Please make sure you are within these bounds!");
                    return false;
            }
            if(weight>560)
            {
                    alert("Based on the targets you have entered, it is advisable to consult with your GP before starting a weight loss and/or exercise programme, therefore our system will not allow you to continue registering at this time.");
                    return false;
            }
            if(weight<88)
            {
                    alert("The minimum and maximum weights allowed are 6st 4lbs and 40st. Please make sure you are within these bounds!");
                    return false;
            }
    }
    else
    {
            //if(f.txtheight1.value=="")(Commenting out as the form uses height1 not txtheight1)
            if(height=="")
            {
                    alert("Please re-enter height!");
                    return false;
            }
            if((height<130)||(height>240))
            {
                    alert("The minimum and maximum heights allowed is 1m 30cm and 2m 40cm. Please make sure you are within these bounds!");
                    return false;
            }
            if((weight>254000))
            {
                    alert("Based on the targets you have entered, it is advisable to consult with your GP before starting a weight loss and/or exercise programme, therefore our system will not allow you to continue registering at this time.");
                    return false;
            }

            if((weight<40000)||(weight>254000))
            {
                    alert("The minimum and maximum weights allowed are 40kg and 254kg. Please make sure you are within these bounds!");
                    return false;
            }

    }
    return true;
}

  function getWeight(f)
   {
    var w1 = document.getElementById(f).elements['weight1'].value;
    var w2 = document.getElementById(f).elements['weight2'].value;
    if(isMetric(f))
    {
            if(w1=='') return 0
            return (parseInt(w1) * 1000)

    }
    else
    {

            if(w1 == '') return 0
            return (parseInt(w1) * 14) + parseInt(w2==''?0:w2);
    }
  }
 function getHeight(f)
  {
    var h1 = document.getElementById(f).elements['height1'].value;
    var h2 = document.getElementById(f).elements['height2'].value;
    if(h1=='') h1="0";
    if(h2=='') h2="0";

    if(isMetric(f))
    {
            return (parseInt(h1) * 100) + parseInt(h2);
    }
    else
    {
            return (parseInt(h1) * 12) + parseInt(h2);
    }
}

function isMetric(f)
{

    var obj =document.getElementById(f).elements['measure'];
    if (obj!=null)
    {
            if(obj.value=="1")
                    return true;
            else
                    return false;
    }
    alert("not found");
    return false;
}

function tools_changeMeasure (id,imperial){

	var obj;
        var f;
        f = document.forms[id];

        if (f.measure.value=='1') imperial = false;

	if(!imperial)
	{
             //metric to imperial
             var h = parseInt(f.height1.value) * 100 + parseInt(f.height2.value);
             var w = f.weight1.value * 2.204622622 + .5;
             var ih1, ih2, iw1, iw2;

             if(isNaN(h)) h=0;
             if(isNaN(w)) w=0;

             h = (h * 0.393700787);
             ih1 = h / 12;
             ih2 = h % 12;
             iw1 = parseInt(w / 14);

             iw2 = w - (14 * iw1);

            f.height1.value=parseInt(ih1);
            f.height2.value=parseInt(ih2);
            f.weight1.value=parseInt(iw1);
            f.weight2.value=parseInt(iw2);

            nu_changeText('heightlabel1','ft');
            nu_changeText('heightlabel2','ins');
            nu_changeText('weightlabel1','st');
            nu_changeText('weightlabel2','lbs');
            showHideLayers('weightlabel2','show');
            showHideLayers('weight2','show');
            nu_changeText('measurechange','Click here to change to metric');
            f.measure.value="0"
	}
	else
	{

                //imperial to metric
                var h = parseInt(f.height1.value) * 12 + parseInt(f.height2.value==''?0:f.height2.value);
                var w = parseInt(f.weight1.value) * 14 + parseInt(f.weight2.value==''?0:f.weight2.value);

                if(isNaN(h)) h=0;
                if(isNaN(w)) w=0;

                var mh1, mh2;
                h = h * 2.54;
                h = h +.5;

                mh1 = h / 100;
                mh2 = h % 100;

                w = w * 0.45359237;
                //w = w * 0.45;

                f.weight1.value=FormatNumber(w,0,false,false,false);
                f.weight2.value="";
                f.height1.value=parseInt(mh1);
                f.height2.value=parseInt(mh2);

                nu_changeText('heightlabel1','m');
		nu_changeText('heightlabel2','cm');
		nu_changeText('weightlabel1','kg');
		showHideLayers('weightlabel2','hide');
		showHideLayers('weight2','hide');
//		nu_changeText('weightlabel2','&nbsp;g&nbsp;');
		nu_changeText('measurechange','Click here to change to imperial');
		f.measure.value="1"
	}



}

function checkEnterLogin(e,f){
    var characterCode;
    characterCode = e.keyCode;
    if(characterCode == 13){
        document.forms[f].submit();
    }
}

function checkEnterGeneric(e,frm){
    var characterCode;
    characterCode = e.keyCode;
    if(characterCode == 13){
        frm.submit();
    }
}

function clearInput(id) {

    var txt = id;
    var str = txt.value;
    if(str.indexOf("e.g") > -1) {
        txt.value='';
        txt.style.color='#000000';
    }

}

function alertBox(url){
    var id='AlertBox';
    var id2='AlertBox2';

    var box = document.getElementById(id);
    var box2 = document.getElementById(id2);
    var added = false;
    if(box){
         document.body.removeChild(box);
         added = false;
    }
    if(box2){
         document.body.removeChild(box2);
         added = false;
    }
    if(!box)
    {
        box = document.createElement("div");
        box.id = id;
        box.setAttribute('style','display:none;');
        added = true;
    }

    if(added) {
        document.body.appendChild(box);
    }
    ajax_UpdaterURL(url,id);
}

function alertBox2(url){
    var id='AlertBox2';
    var id2='AlertBox';
    var box = document.getElementById(id);
    var box2 = document.getElementById(id2);

    var added = false;
    if(box){
         document.body.removeChild(box);
         added = false;
    }
    if(box2){
         document.body.removeChild(box2);
         added = false;
    }
    if(!box)
    {
        box = document.createElement("div");
        box.id = id;
        box.setAttribute('style','display:none;');
        added = true;
    }

    if(added) {
        document.body.appendChild(box);
    }
    ajax_UpdaterURL(url,id);
}
function recipeAlertBox(url) {
    if($('AlertBox2') !== null) {
        $('AlertBox2').style.display = 'none';
    }
    if($('recipeAlertBox') !== null) {
        div = $('recipeAlertBox');
    }
    else {
        div = document.createElement('div');
        div.id = 'recipeAlertBox';
        div.className = 'recipeAlert';
    }
    ajax_UpdaterURL(url, 'recipeAlertBox');
    document.body.appendChild(div);
}
function closePreview() {
    document.body.removeChild($('recipeAlertBox'));
    if($('AlertBox2') !== null) {
        $('AlertBox2').style.display = 'block';
    }
}
function showBox(id,overlay){

    if(overlay){
        showbox = new Dialog.Box(document.getElementById(id));
        document.getElementById(id).style.position = 'fixed';
        document.getElementById(id).show();
    }
    else{
        document.getElementById(id).style.position = 'fixed';
        document.getElementById(id).style.display="block";
    }
}

function positionBox(h){
    var box = document.getElementById('AlertBox');
    if(box){
        if( typeof( window.innerWidth ) == 'number') {
        box.style.top = (window.innerHeight/2 - h) + "px";
        box.style.left = (window.innerWidth/2 - 235)  + "px";
        }
        else{
            box.style.top = (document.documentElement.clientHeight/2 - h) + "px";
            box.style.left = (document.documentElement.clientWidth/2 - 235) + "px";
        }
    }

}

function boxOverFlow(){

    var area = getWinHeight() - $('AlertBoxBtm').offsetTop;
    var mpContent = $('planDescription');
    var mpMenu = $('planMenu');
    var ab= $('AlertBox');
    var gs=$('genericScroll');
    p=document.getElementById("viewMenu");

    if(ab){
        var abStyle=ab.readAttribute('style');

        if(area<40){
            ab.writeAttribute('style', abStyle+';top:10px;');

            if(p.innerHTML.indexOf('menu')>-1) {
                mpContent.writeAttribute('style', 'height:260px;overflow:auto;padding-right:10px;display: block;');
                mpMenu.writeAttribute('style', 'height:260px;overflow:auto;padding-right:10px; display: none;');

            } else {
                mpContent.writeAttribute('style', 'height:260px;overflow:auto;padding-right:10px;display: none;');
                mpMenu.writeAttribute('style', 'height:260px;overflow:auto;padding-right:10px; display: block;');
            }

            if(gs)
                gs.writeAttribute('style', 'height:260px;overflow:auto;padding-right:10px;');

        }
    }
}

function positionBox2(h){
    var box = document.getElementById('AlertBox2');
    if(box){
        if( typeof( window.innerWidth ) == 'number') {
        box.style.top = (window.innerHeight/2 - h) + "px";
        box.style.left = (window.innerWidth/2 - 285)  + "px";
        }
        else{
            box.style.top = (document.documentElement.clientHeight/2 - h) + "px";
            box.style.left = (document.documentElement.clientWidth/2 - 285) + "px";
        }
    }

}
function countChecked(f,check)
{
     var frm = document.forms[f]; // or name where the first form is 0
     var count =0;
     if(f)
     {
        var ele = frm.elements[check];
        if(ele)
        {
            for(i=0; i < ele.length; i++) {
                if(ele[i].checked) count++;
            }
        }
     }
    return count;

}
function $RF(el, radioGroup) {
    if($(el).type && $(el).type.toLowerCase() == 'radio') {
        var radioGroup = $(el).name;
        var el = $(el).form;
    } else if ($(el).tagName.toLowerCase() != 'form') {
        return false;
    }

    var checked = $(el).getInputs('radio', radioGroup).find(
        function(re) {return re.checked;}
    );
    return (checked) ? $F(checked) : null;
}

function simplesHowHide(id){
    e = $(id);

    if(e){
        if(e.style.display=='none' || e.style.display==''){
           e.style.display='block';
        }
        else{
            e.style.display='none';
        }
    }
}
function handleAjaxErrors(errors){

    $('errors').style.display = 'block';

    var len = errors.errors.length;
    var er= '';
    for(i =0;i<len;i++){
        error= errors.errors[i];
        if(error.handlecode && 1  == 1){
            er += '<li>'+error.description+'</li>'
        }
    }
   $("error_field").innerHTML ='<ul id="errList">'+er+'</ul>';
}
function ShoppingListAlert(url, id) {
    box = new Dialog.Box(id);
    ajax_UpdaterURL(url, id, function() {
        $(id).className = 'shoppingListAlert';
    });
    $(id).style.position = 'fixed';
    box.show();
}
function setDefault(type, input, txt) {
    elem = $(input);
    if(type === 'focus' && elem.value === txt) {
        elem.className = 'text';
        elem.value = '';
    }
    else if(type === 'blur') {
        if(elem.value === '') {
            elem.className = 'text italic';
            elem.value = txt;
        }
    }
}
function loadSaveInput() {
    visible = $('save').checked;

    if(visible) $('saveName').style.display = 'block';
    else $('saveName').style.display = 'none';
}
function closeShoppingListAlert() {
    closeOverLay('loadBox');
    div = document.createElement('div');
    div.id = 'loadBox';
    document.body.appendChild(div);
}
function printBox(url) {
    div = document.createElement('div');
    div.id = 'PrintAlert';
    div.className = 'PrintAlert';
    document.body.appendChild(div);
    ajax_UpdaterURL(url, div.id, function() {});
    box = new Dialog.Box(div);
    box.show();
}

function getAbsolutePosition(obj) {

   var x = 0;
    var y = 0;
    var parent = obj;

    while (parent) {
        x += parent.offsetLeft;
        y += parent.offsetTop - parent.scrollTop;
        parent = parent.offsetParent;
    }
    return [x, y];
}

function eat(){
	var eatTracker = pageTracker._createEventTracker("CaloriesIn");
	eatTracker._trackEvent("Eat");
}

function getAbsolutePosition(obj) {

   var x = 0;
    var y = 0;
    var parent = obj;

    while (parent) {
        x += parent.offsetLeft;
        y += parent.offsetTop - parent.scrollTop;
        parent = parent.offsetParent;
    }
    return [x, y];
}

function alert_changeMeasure(resetdata, imperial)
{
	var f;
	var notice = $('measurechange');
	var w1 = $('weightlabel1');
	var w2 = $('weightlabel2');
	var txtw2 = $('txtweight2');
	//var waist = $('waistlabel1');

	f = document.forms["singleAlert"];

	if (imperial==null)
	{

		if(f.ismetric.value=="1")
			imperial=false;
		else
			imperial=true;
	}

	if(!imperial)
	{
		notice.update('Click here to change to metric');
		w1.update('&nbsp;&nbsp;stone');
		w2.update('&nbsp;&nbsp;lbs');
		//waist.update('&nbsp;&nbsp;ins');
		w2.show();
		txtw2.show()
		f.ismetric.value="0";
	}
	else
	{
		notice.update('Click here to change to imperial');
		w1.update('&nbsp;&nbsp;kg');
		//waist.update('&nbsp;&nbsp;cms');
		txtw2.hide()
		w2.hide();
		f.ismetric.value="1";
	}
}

function nu_inValidKeyPress(e, validSet)
{
    var key;
    var keychar;

    if(window.event || !e.which) // IE
        key = e.keyCode; // IE
    else if(e)
        key = e.which;   // Netscape
    else
        return true;     // no validation

if(key<32) return true;
    keychar = String.fromCharCode(key);
    validSet += String.fromCharCode(8);

    if (validSet.indexOf(keychar) > -1){
		alert("The following characters are not allowed in a password: %[]+'^*")
		return false;
	}


    return true;
}
function googleTrack(event,id) {
 var tracker = pageTracker._createEventTracker(event);
 tracker._trackEvent(id);
}
