function changePage() {

        if (parent.top.location != document.location)

            parent.location=document.location;

        }

//setTimeout ("changePage()", 300);



// ====================================================

// CROSS SITE SCRIPTING FIX

// ====================================================



function formatCode(s)  

    { 

        var str = ""; 

        var IN_TEXT    = 1; 

        var IN_ELEMENT = 2; 

        var state = IN_TEXT; 

 

        while (s.length > 0)  

        { 

            var endTagBreak, emptyTagBreak; 

            if (state == IN_ELEMENT)  

            { 

                var endIndex = s.indexOf(">"); 

                var endTag = (s.substring(0,1) == "/"); 

                if (endIndex != -1)  

                { 

                

                    str += "" + "&gt;"; 

                    //str += s.substring(0,endIndex) + "&gt;"; 

                    if (endTag && endTagBreak || emptyTagBreak) 

                        str += "<br>"; 

                    s = s.substring(endIndex+1, s.length); 

                    state = IN_TEXT; 

                } 

                else  

                { 

                    str += s + ""; 

                    s = ""; 

                } 

            } 

            else  

            { 

                var startIndex = s.indexOf("<"); 

                var endTags = new Array("H1", "H2", "H3", "H4", "H5", "H6", "BLOCKQUOTE", "TITLE", "BODY", "META", "HEAD", "SCRIPT","FORM","ALERT"); 

                var startTags = new Array("META", "HTML", "BODY", "HEAD"); 

     

            if (startIndex != -1)  

            { 

                var tagName; 

                var nameStartIndex; 

                var gtIndex = s.indexOf(">"); 

                var spaceIndex = s.indexOf(" "); 

                var slashIndex = s.indexOf("/"); 

                endTagBreak = false; 

                emptyTagBreak = false; 

 

                    if (slashIndex != -1 && slashIndex == startIndex+1) 

                        nameStartIndex = slashIndex + 1; 

                    else 

                        nameStartIndex = startIndex + 1; 

             

                    if (spaceIndex != -1 && spaceIndex > startIndex && spaceIndex < gtIndex) 

                        tagName = s.substring(nameStartIndex,spaceIndex); 

                    else if (gtIndex != -1) 

                        tagName = s.substring(nameStartIndex,gtIndex); 

                    else 

                        tagName = s.substring(nameStartIndex,s.length); 

 

                    for (var i=0; i<endTags.length; i++)  

                    { 

                        if (endTags[i] == tagName)  

                        { 

                            endTagBreak = true; 

                        break; 

                    } 

                } 

 

                for (var i=0; i<startTags.length; i++)  

                { 

                    if (startTags[i] == tagName)  

                    { 

                        emptyTagBreak = true; 

                    break; 

                    } 

                } 

                     

                str += s.substring(0,startIndex) + "&lt;"; 

                s = s.substring(startIndex+1, s.length); 

                    state = IN_ELEMENT; 

 

                } 

                else  

                { 

                    str += s; 

                        s = ""; 

                } 

            } 

     

        } 

 //alert(str);

        return str; 

    } 











//====================================================

// BROWSER CHECK

//====================================================

function BrowserCheck() { 

var b = navigator.appName 

    if (b=="Netscape") this.b = "ns" 

    else if (b=="Microsoft Internet Explorer") this.b = "ie" 

    else this.b = b 

        this.v = parseInt(navigator.appVersion) 

        this.ns = (this.b=="ns" && this.v>=4) 

        this.ns4 = (this.b=="ns" && this.v==4) 

        this.ns6 = (this.b=="ns" && this.v==5) 

        this.ns7 = (this.b=="ns" && this.v==6) 

        this.ns8 = (this.b=="ns" && this.v==7) 

        this.ie = (this.b=="ie" && this.v>=4)

        this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)

        this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)

        this.ie6 = (navigator.userAgent.indexOf('MSIE 6')>0)

        this.ie7 = (navigator.userAgent.indexOf('MSIE 7')>0)

        // through version 8 of IE

    if (this.ie5) this.v = 5 

    var p = navigator.platform

    this.mac = (navigator.appVersion.indexOf("Mac") != -1)

    this.win = (navigator.appVersion.indexOf("Win") != -1)

    this.otherOS = (! this.mac || ! this.win )

    this.min = (this.ns||this.ie) 

    this.ie5w = (this.ie5 && this.win)

} 

is = new BrowserCheck(); // keep this line to initialize JS object



function setLayerText(objName,x,newText) {

    if ((obj=MM_findObj(objName))!=null) {

        with (obj){

            if (is.ns4) {

                document.write("<span class=\"bodyPlain\">" + unescape(newText) + "</span>"); 

                document.close();

            }else{

                innerHTML = unescape(newText);

            }

        }

    }

}



function MM_findObj(n, d) { //v4.0

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && document.getElementById) x=document.getElementById(n); return x;

}



function clearIngredient(frm) {

    frm.value="";

}

    

function clearIngredient5() {

    document.form1.text1.value="";

    }

    

function clearEmail() {

    document.email.emailAddress.value="";

    }

    

function clearUser() {

    document.user.loginName.value="";

    }

    

function clearAns() {

    document.registration.challengeAns.value="";

    }

    

function clearAns2() {

    document.challenge.challengeans.value="";

    }

    

function clearYear() {

    document.registration.dobYYYY.value="";

    }

    



if (is.ns4) {

         var origWidth = window.innerWidth

         var origHeight = window.innerHeight

}

function restorePage() {

        if (is.ns4) {

                 if (origWidth != window.innerWidth || origHeight != window.innerHeight) {

                        history.go(0)

                }

        }

}



// ==========================================

// RECIPE SEARCH CONSOLE/PANEL SCRIPT

//==========================================

function KeywordSearch(){

    if (document.keywordSearch.u2.value == ""){

        if (is.ns4) {

            setLayerText("error","","Please enter a keyword or ingredient")

        }else{

            setLayerText("error","","Please enter a keyword or ingredient")

        }

    }else{

    document.keywordSearch.u2.value = formatCode(document.keywordSearch.u2.value);

    document.keywordSearch.submit()

    }

}



function ByTypeSearch(){



valMain = document.frmRecipeByType.cboMain.value;

valSecond = document.frmRecipeByType.cboSecond.value;

    if (valMain == null || valMain == "0" || valMain == ""){

        if (is.ns4) {

            setLayerText("errorSearch","","Please make a selection")

        }else{

            setLayerText("errorSearch","","Please make a selection")

        }

    }else{

    

    if(valMain == null || valMain == "0"){

        valMain = "";

        }



        if(valSecond == null || valSecond == "0"){

        valSecond = "";

        }

        

        document.location = "/Velveeta/main.aspx?s=recipe&m=recipe/knet_recipe_grid&u1=bytype&u2=" + valMain + "*" + valSecond;

    }

}





function ByNutritionSearch(){

valMain = document.frmRecipeByType.cboMain.value;

valSecond = document.frmRecipeByType.cboSecond.value;

    if (valMain == null || valMain == "0" || valMain == ""){

        if (is.ns4) {

            setLayerText("errorSearch","","Please make a selection")

        }else{

            setLayerText("errorSearch","","Please make a selection")

        }

    }else{

    

    if(valMain == null || valMain == "0"){

        valMain = "";

        }



        if(valSecond == null || valSecond == "0"){

        valSecond = "";

        }

        

        strDropDown1 = escape(document.frmRecipeByType.cboMain.options[document.frmRecipeByType.cboMain.selectedIndex].text);

        strDropDown2 = escape(document.frmRecipeByType.cboSecond.options[document.frmRecipeByType.cboSecond.selectedIndex].text);

        if (strDropDown1 == unescape("Select one"))

        {

            strDropDown1 = "";

        }

        if (strDropDown2 == unescape("Select one"))

        {

            strDropDown2 = "";

        }

        document.location = "/creamofwheat/main.aspx?s=recipe&m=recipe/knet_recipe_grid&u1=bynutrition&u2=" + valMain + "*" + valSecond + "**" + strDropDown1 + "*" +  strDropDown2 + "*";

    }

}





// DROP DOWN DYNAMIC CODE

function mmInitialize(parent, main, second, make_caption, model_caption, bnew, main_select_value, second_selected_value)

    {

    var rgMain;

 

    clearList(parent.cboMain);

    addElement(parent.cboMain, make_caption, 0);

    

    if (bnew == 'true')

        {

        for (var i = 0; i < mmMain.length; i++)

            {

            if (mmMain[i])

                {

                rgMain = mmMain[i].split('#');

                addElement(parent.cboMain, rgMain[0], rgMain[1]);

                }

            }

        }

    else

        {

        for (var i = 0; i < mmMkU.length; i++)

            if (mmMkU[i])

                {

                rgMain = mmMkU[i].split('#');

                addElement(parent.cboMain, rgMain[0], rgMain[1]);

                }

        }



    if (main)

        {

        setDefaultByText(parent.cboMain, main);

        mmChangeMain(parent, bnew, model_caption);

        if (second)

            setDefaultByText(parent.cboSecond, second);

        }

    else

        {

        setDefaultByValue(document.frmRecipeByType.cboMain, main_select_value);

        //parent.cboMain.selectedIndex = 0;

        mmChangeMain(parent, bnew, model_caption, second_selected_value);

        }

    }

    

function mmChangeMain(parent, bnew, model_caption, second_selected_value)

    {

    if (bnew == 'true')

        var SecondList = mmSecond[parent.cboMain.options[parent.cboMain.selectedIndex].value];

    else

        var SecondList = mmMdU[parent.cboMain.options[parent.cboMain.selectedIndex].value];



    clearList(parent.cboSecond);

    addElement(parent.cboSecond, model_caption, 0);

    if(SecondList)

        {

        var rgSeconds = SecondList.split('|');

        for (var i = 0; i < rgSeconds.length; i++)

            {

            if (rgSeconds[i])

                {

                var rgSecond = rgSeconds[i].split('#');

                addElement(parent.cboSecond, rgSecond[0], rgSecond[1]);

                }

            }

        parent.cboSecond.disabled = false;

        }

    else

        {

        parent.cboSecond.disabled = true;

        }

    setDefaultByValue(document.frmRecipeByType.cboSecond, second_selected_value);

    //parent.cboSecond.selectedIndex = 0;

    } 



function clearList(list) 

    {

    var i = 0;

    var o = list.options;



    for (i = o.length; i >= 0; --i)

        o[i] = null;

    list.disabled = true;

    }





function addElement(list, text_in, value_in)

    {

    var o = list.options;

    var nIdx;

    if (o.length < 0) //IE for Mac 4.5 sets length to -1 if list is empty

        nIdx = 0;

    else

        nIdx = o.length;

                

    o[nIdx] = new Option(text_in, value_in);

    

    list.disabled = false;

    }





function setDefaultByText(list, text_in)

    {

    with (list)

        {

        for (var i = 0; i < (options.length); i++)

             {

             if (options[i].text == text_in)

                 {

                 selectedIndex = i;

                 return;

                 }

             }

        }

    }





function setDefaultByValue(list, value_in)

    {

    with (list)

        {

        for (var i = 0; i < (options.length); i++)

             {

             if (options[i].value == value_in)

                 {

                 selectedIndex = i;

                 return;

                 }

             }

        }

    }

    

function GetResults(){

        document.frmRecipeByType.submit();

}

// ========================================

// END RECIPE SEARCH PANEL SCRIPT

//=========================================
