﻿var sCurrentPage;
var sCurrentRecipe;

function TogglePageNav(sPage, sState) {
    var imgPage = getObject(sPage);
    
    // Never turn the current page nav off
    if ((sPage != sCurrentPage) || (sState == "on")) {
        imgPage.src = "/Images/" + sPage + "_" + sState + ".gif";
    }
}

function DisplayRules() {
    var dRulesContainer = getObject("rulesContainer");

    dRulesContainer.style.display = "block";
    dRulesContainer.style.top = (GetScrollY() + 150) + "px";
}

function HideRules() {
    var dRulesContainer = getObject("rulesContainer");

    dRulesContainer.style.display = "none";
}

function GetScrollY() {
  var nScrollY = 0;
  if( typeof( window.pageYOffset ) == "number" ) {
    //Firefox compliant
    nScrollY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    nScrollY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE standards compliant mode
    nScrollY = document.documentElement.scrollTop;
  }
  return nScrollY;
}

function DisplayRecipe(sRecipe, bIncludeContent) {
    var imgRecipe = getObject("imgRecipeList");
    
    imgRecipe.src = "/Images/recipeList_" + sRecipe + ".jpg";
    
    if (bIncludeContent) {
        sCurrentRecipe = sRecipe;
        HideAllRecipes();
        changeObjectDisplay("recipe" + sCurrentRecipe, "block");
    }
}

function HideAllRecipes() {
    changeObjectDisplay("recipeEmerald", "none");
    changeObjectDisplay("recipeDiamond", "none");
    changeObjectDisplay("recipePopSecret", "none");
}

function HighlightCurrentRecipe() {
    var imgRecipe = getObject("imgRecipeList");
    
    imgRecipe.src = "/Images/recipeList_" + sCurrentRecipe + ".jpg";
}

function ValidateChecked(sender, e) {
    var oSender = getObject(sender.id.replace("cv_",""));
    
    if (oSender.checked) e.IsValid = true;
    else e.IsValid = false;
}

function ClearText(txtField){
    if (txtField.defaultValue==txtField.value) {
        txtField.value = "";
        txtField.style.color = "#000000";
    }
}

function FillText(txtField){
    if (txtField.value=="") {
        txtField.value = txtField.defaultValue;
        txtField.style.color = "#666666";
    }
}

function HighlightSelectText(ddlstField){
    ddlstField.style.color = "#000000";
}

function getObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId);
    } else {
		return false;
    }
} // getObject

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
		// W3C DOM
		return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
		// MSIE 4 DOM
		return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
		// NN 4 DOM.. note: this won't find nested layers
		return document.layers[objectId];
    } else {
		return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
        styleObject.visibility = newVisibility;
        return true;
    } else {
		//we couldn't find the object, so we can't change its visibility
		return false;
    }
} // changeObjectVisibility

function changeObjectDisplay(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
        styleObject.display = newVisibility;
        return true;
    } else {
		//we couldn't find the object, so we can't change its visibility
		return false;
    }
} // changeObjectVisibility