var gAutoPrint = true; 

function printSpecial()
{
	if (document.getElementById != null)	{
	    bV = parseInt(navigator.appVersion)
	    if (bV >= 4) window.print();
	}
	else {
		alert("Sorry, the print  feature is not available.");
	}
}

function MM_CheckFlashVersion(reqVerStr,msg) {
	with(navigator)	{
		var isIE = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
		var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
		if (!isIE || !isWin) { 
			var flashVer = -1;
			if (plugins && plugins.length > 0) {
				var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
				desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
				if (desc == "") flashVer = -1;
				else {
					var descArr = desc.split(" ");
					var tempArrMajor = descArr[2].split(".");
					var verMajor = tempArrMajor[0];
					var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
					var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
					flashVer = parseFloat(verMajor + "." + verMinor);
				}
			}
		}
	}
}

function whichBrs() {
    var agt = navigator.userAgent.toLowerCase();
    if (agt.indexOf("opera") != -1) return 'Opera';
    if (agt.indexOf("firefox") != -1) return 'Firefox';
    if (agt.indexOf("safari") != -1) return 'Safari';
    if (agt.indexOf("InternetExplorer") != -1) return 'Internet Explorer';
    if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
    if (agt.indexOf('\/') != -1) {
        if (agt.substr(0, agt.indexOf('\/')) != 'mozilla') {
            return navigator.userAgent.substr(0, agt.indexOf('\/'));
        }
        else if (agt.indexOf(' ') != -1)
            return navigator.userAgent.substr(0, agt.indexOf(' '));
        else return navigator.userAgent;
    }
}
var browserName = whichBrs();
if (browserName == "Safari") {
    var styleNode = document.createElement('link');
    styleNode.setAttribute('rel', 'stylesheet');
    styleNode.setAttribute('type', 'text/css');
    styleNode.setAttribute('href', 'css/bodybreaksafari.css');
    document.getElementsByTagName('head')[0].appendChild(styleNode);
}

function CreateBookmarkLink() {
    var title = "BodyBreak";
    var url = document.location.href;
    if (window.sidebar) { 						// Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url, "");
    }
    else if (window.external) { 			// IE Favorite
        window.external.AddFavorite(url, title);
    }
    else if (window.opera && window.print) { // Opera Hotlist
        window.sidebar.addPanel(title, url, "");
        return true;
    }
}
function toggle(element){
	var displayState = document.getElementById(element).style.display
	YAHOO.util.Dom.setStyle(['nutrition_menu', 'fitness_menu', 'health_menu', 'vitamin_menu', 'product_menu','news_menu'], 'display', "none");  
	if (displayState == "none" || displayState =="") {
		document.getElementById(element).style.display = 'block';
	}
}

YUI().use('node-base', function(Y) {
     function init() {
     	var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		sPage = sPage.substring(0,5);
		switch (sPage) {
		    case 'bodyb': YAHOO.util.Dom.setStyle(['nutrition_menu'], 'display', "block"); break;
   			case 'Nutri': YAHOO.util.Dom.setStyle(['nutrition_menu'], 'display', "block");   break;
   			case 'fitne': YAHOO.util.Dom.setStyle(['fitness_menu'], 'display', "block"); break;
   			case 'Healt': YAHOO.util.Dom.setStyle(['health_menu'], 'display', "block"); break;
   			case 'Vitam': YAHOO.util.Dom.setStyle(['vitamin_menu'], 'display', "block"); break;
   			case 'Produ': YAHOO.util.Dom.setStyle(['product_menu'], 'display', "block"); break;
   			case 'News_': YAHOO.util.Dom.setStyle(['news_menu'], 'display', "block"); break;
		}
 	
     }
     Y.on("domready", init);
     // As with all custom events, you can pass a context object and arguments that will be
     // passed to your handlers:
     // Y.on("domready", init, contexObject, argumentOne, argumentTwo, argumentN);
 });
// dropdown.js below
 var DDSPEED = 1;
 var DDTIMER = 1;

 function ddMenu(id, d) {
     var h = document.getElementById(id + '-ddheader');
     var c = document.getElementById(id + '-ddcontent');
     clearInterval(c.timer);
     if (d == 1) {
         clearTimeout(h.timer);
         if (c.maxh && c.maxh <= c.offsetHeight) { return }
         else if (!c.maxh) {
             c.style.display = 'block';
             c.style.height = 'auto';
             c.maxh = c.offsetHeight;
             c.style.height = '0px';
         }
         c.timer = setInterval(function() { ddSlide(c, 1) }, DDTIMER);
     } else {
         h.timer = setTimeout(function() { ddCollapse(c) }, 50);
     }
 }

 function ddCollapse(c) { // collapse the menu
     c.timer = setInterval(function() { ddSlide(c, -1) }, DDTIMER);
 }

 function cancelHide(id) { // cancel the collapse if a user rolls over the dropdown
     var h = document.getElementById(id + '-ddheader');
     var c = document.getElementById(id + '-ddcontent');
     clearTimeout(h.timer);
     clearInterval(c.timer);
     if (c.offsetHeight < c.maxh) {
         c.timer = setInterval(function() { ddSlide(c, 1) }, DDTIMER);
     }
 }

 function ddSlide(c, d) {// incrementally expand or contract the dropdown and change the opacity
     var currh = c.offsetHeight;
     var dist;
     if (d == 1) {
         dist = (Math.round((c.maxh - currh) / DDSPEED));
     } else {
         dist = (Math.round(currh / DDSPEED));
     }
     if (dist <= 1 && d == 1) {
         dist = 1;
     }
     c.style.height = currh + (dist * d) + 'px';
     c.style.opacity = currh / c.maxh;
     c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
     if ((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)) {
         clearInterval(c.timer);
     }
 }
 // mail.js below
 function toggleBox(szDivID, iState) {
     if (document.layers) {
         document.layers[szDivID].visibility = iState ? "show" : "hide";
     }
     else if (document.getElementById) {
         var obj = document.getElementById(szDivID);
         obj.style.visibility = iState ? "visible" : "hidden";
     }
     else if (document.all) {
         document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
     }
     if (iState) {
         document.getElementById("emailDivs").innerHTML = "";
         document.frm.txtemails.value = "";
         document.frm.txtownname.value = "";
         document.frm.txtownmail.value = "";
     }
 }

 function isemail(address) {
     var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
     if (reg.test(address) == false) {
         alert('Invalid Email Address');
         return false;
     }
 }

 function submitform() {
     if (document.frm.txtemails.value == "") {
         alert("Please  Enter EmailId !!");
         document.frm.txtemails.focus();
         return false;
     }
     if (isemail(document.frm.txtemails.value) == false) {
         document.frm.txtemails.focus();
         return false;
     }
     if (document.frm.txtownname.value == "") {
         alert("Please enter name !!");
         document.frm.txtownname.focus();
         return false;
     }
     if (document.frm.txtownmail.value == "") {
         alert("Please enter your email id !!");
         document.frm.txtownmail.focus();
         return false;
     }
     if (isemail(document.frm.txtownmail.value) == false) {
         document.frm.txtownmail.focus();
         return false;
     }
     email_process();
 }

 function email_process() { //Process page and send to php script for mailing
     var emailer = 'emailscript.php';
     var uri = document.location.pathname;
     var title = document.title;

     var to_address = document.getElementById('email_to').value;
     var from_address = document.getElementById('email_from').value;
     var from_name = document.getElementById('email_name').value;
     var email_self = (document.getElementById('email_self').checked == true) ? 1 : 0;

     var variables =
	    '&to=' + escape(to_address) +
	    '&from=' + escape(from_address) +
	    '&name=' + escape(from_name) +
	    '&self=' + escape(email_self) +
	    '&uri=' + uri +
	    '&title=' + escape(title);

     var callback = {
         success: function(o) {
             alert("successful callback " + o.responseText);
         },
         failure: function(o) {
             alert("failed to work");
         }
     }
     var transaction = YAHOO.util.Connect.asyncRequest('POST', emailer, callback, variables);
 }
 //  recipe.js below
 
 function selectUnits(type) {
     var tableCells = document.getElementById("ingredient_list");
     tableCells = tableCells.getElementsByTagName("td");

     for (i = 0; i < tableCells.length; i++) {
         var tableCell = tableCells[i];

         var tdClass = tableCell.getAttribute("className");
         if (tdClass == null) {
            tdClass = tableCell.getAttribute("class");
         }

         if (tdClass == "" || tdClass == null ||(tdClass == type)) {
             tableCell.style.display = "table-cell";
         }
         else {
             tableCell.style.display = "none";
         }
     }
 }

 var xmlhttp;
 function loadXMLDoc() {
     xmlhttp = null;
     if (window.XMLHttpRequest) {// code for all new browsers
         xmlhttp = new XMLHttpRequest();
     }
     else if (window.ActiveXObject) {// code for IE5 and IE6
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     }
     if (xmlhttp != null) {
         xmlhttp.onreadystatechange = state_Change;
         xmlhttp.open("GET", 'recipes.php', true);
         xmlhttp.send(null);
     }
     else {
         alert("Your browser does not support XMLHTTP.");
     }
 }

 function state_Change() {
     if (xmlhttp.readyState == 4) {// 4 = "loaded"
         if (xmlhttp.status == 200) {// 200 = OK
             var response = xmlhttp.responseText;
             document.getElementById("middleContentDetails").innerHTML = response;
         }
         else {
             alert("Problem retrieving XML data");
         }
     }
 } 