﻿


function MenuHover(item)
{
    
}
function UpdateProducts(control,lang)
{
    var box = control;//.getElementsByTagName("input")[0];
    var field = document.getElementById("ctl00_MainContent" + lang + "_hidProducts" + lang);
    if(box.checked)
    {
        field.value = field.value + $(control).attr('rel');
    }
    else
    {
        field.value = field.value.replace($(control).attr('rel'),"");
    }
}
function SetPage( )
{
    var div = document.getElementById("ctl00_SmallHeader_pnlSmallHeader");
    if(div != null)
    {
        var header = document.getElementById("header");
        var body = document.getElementById("body");
        header.className = header.className + " short_header";
        body.className = body.className  + " short_body";
    }
}
function SetFont(size)
{
    var direction = 1;
    var current = document.body.className;
    var other = "neither";
    if(size == "larger")
    {other = "smaller";}
    else if(size == "smaller")
    {other = "larger";}

    var num = parseInt(current.replace(size,"").replace("normal","").replace(other,""));

    if(current.indexOf(other) > -1)
    {direction = -1;current = other;}
    else{current = size}
    
    var end = parseInt(num + direction);

    if(end < 6 && end > 0)
    {
        document.body.className = current + end;
    }
    else if (end == 0)
    {
        document.body.className = "normal0";
    }
}
function ShowDiv(name)
{
    HideDiv("reviewit");
    HideDiv("rateit");
    HideDiv("emailit");

    var div = document.getElementById(name);
    div.style.display = "block";
}
function HideDiv(name)
{
    var div = document.getElementById(name);
    div.style.display = "none";
}
function Stars(num)
{
    var div = document.getElementById("userrating");
    div.style.backgroundImage = "url(/images/buttons/rate" + num + ".png)";
}
function Popup(img) {
    window.open(img,'Nutrition', 'width=260,height=425,status=0,toolbar=0,menubar=0,resizable=0,scrollbars=0');
}

// Functions by Justin Evans

// Randomly rotate featured recipes

var getFeaturedRecipe = function( lang ) {
    // 'lang' expects to be 'english' or 'spanish'
    var config = {
       english : [
            {
                title : 'Tortilla Soup',
                image : '/images/featured/feat-tortilla-soup-en.png',
                url : '/recipes/details.aspx?id=20'
            },
            {
                title : 'Chile Relleno',
                image : '/images/featured/feat-chile-relleno-en.png',
                url : '/recipes/details.aspx?id=23'
           },
           {
                title : 'Enchiladas Suizas',
                image : '/images/featured/feat-enchiladas-suizas-en.png',
                url : '/recipes/details.aspx?id=5'
           }
       ],
       spanish : [
           {
                title : 'Sopa de Tortilla',
                image : '/images/featured/feat-tortilla-soup-sp.png',
                url : '/recipes/details.aspx?id=20'
           },
           {
                title : 'Chiles Rellenos',
                image : '/images/featured/feat-chile-relleno-sp.png',
                url : '/recipes/details.aspx?id=23'
           },
           {
                title : 'Enchiladas Suizas',
                image : '/images/featured/feat-enchiladas-suizas-sp.png',
                url : '/recipes/details.aspx?id=5'
           }
       ]
    };
    
    if($('#featuredRecipe'))
    {
        var rnd = Math.floor(Math.random()* config[lang].length);
        
        $('#featuredRecipe').append('<a href="' + config[lang][rnd].url + 
                    '"><img src=' + config[lang][rnd].image + ' alt="' + 
                    config[lang][rnd].title + '" /></a>');
    }

}


// jQuery Plug-ins:

// $('form').clearForm()
// Resets form values

$.fn.clearForm = function() {
    return this.each(function() {
      var type = this.type, tag = this.tagName.toLowerCase();
      if (tag == 'form')
        return $(':input',this).clearForm();
      if (type == 'text' || type == 'password' || tag == 'textarea')
        this.value = '';
      else if (type == 'checkbox' || type == 'radio')
        this.checked = false;
      else if (tag == 'select')
        this.selectedIndex = -1;
    });
};

// Embed Flash Object (Uses swfobject.js, v. 2.2 and jQuery 1.4)

var embedProductTypeSWF = function(swfURL, containerID)
{
    if( typeof(swfURL) != "undefined" && swfURL != null && swfURL != ""  && typeof(containerID) != "undefined" && containerID != null && containerID != "" )
    {
    
        var flashvars = {};
        var params = {
            'play' : 'true',
            'loop' : 'true',
            'menu' : 'false',
            'quality' : 'high',
            'wmode' : 'transparent'
        };
        var attributes = {};
        var callbackFn = function() { return; }
    
        swfobject.embedSWF(swfURL, containerID, '565', '308', '6.0.0', '/functions/swfobject_2_2/expressInstall.swf', flashvars, params, attributes, callbackFn)    
    }
    return;
}

// Print Pop-UP

function printPreview(print_area)
{
    //Creating new page
    var pp = window.open();
    //Adding HTML opening tag with <HEAD> … </HEAD> portion 
    pp.document.writeln('<HTML><HEAD><title>Print Preview</title>');
    pp.document.writeln('<LINK href=http://10.9.8.33/styles/styles.css type="text/css" rel="stylesheet">');
    pp.document.writeln('<LINK href=http://10.9.8.33/styles/layout.css type="text/css" rel="stylesheet">');
    pp.document.writeln('<LINK href=http://10.9.8.33/styles/print.css ' + 
                        'type="text/css" rel="stylesheet" media="print">');
    pp.document.writeln('<base target="_self"></HEAD>');

    //Adding Body Tag
    pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0"');
    pp.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0">');
    //Adding form Tag
    pp.document.writeln('<form method="post">');

    //Creating two buttons Print and Close within a HTML table
    pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right>');
    pp.document.writeln('<INPUT ID="PRINT" type="button" value="Print" ');
    pp.document.writeln('onclick="javascript:location.reload(true);window.print();">');
    pp.document.writeln('<INPUT ID="CLOSE" type="button" ' + 
                        'value="Close" onclick="window.close();">');
    pp.document.writeln('</TD></TR><TR><TD></TD></TR></TABLE>');

    //Writing print area of the calling page
    pp.document.writeln(document.getElementById(print_area).innerHTML);
    //Ending Tag of </form>, </body> and </HTML>
    pp.document.writeln('</form></body></HTML>'); 
}

var showSplash = function() {
    var swfURL = '/flash/SupremoAnimation.swf';
    
    if(!readCookie('vvhome'))
    {
        createCookie('vvhome', 1, 365);
        
        // Show home page Flash pop-up
        
        $('body').append('<div id=\'splashContainer\'><div id=\'flashContainer\'></div></div>');
        
        var flashvars = {};
        var params = {
            'play' : 'true',
            'loop' : 'false',
            'menu' : 'false',
            'quality' : 'high',
            'wmode' : 'opaque'
        };
        var attributes = {};
        var callbackFn = function() { return; }
    
        swfobject.embedSWF(swfURL, 'flashContainer', '622', '348', '6.0.0', '/functions/swfobject_2_2/expressInstall.swf', flashvars, params, attributes, callbackFn)
        $('#splashContainer').hide();
        // Thickbox pop-up
        $('body').append('<a id=\'initThickbox\' class=\'thickbox\' href=\'#TB_inline?height=360&width=625&inlineId=splashContainer\'>Click to show splash!</a>');
/*
.TB_overlayBG 
{
    display: none;
    background-color:#000;
    filter:alpha(opacity=75);
    -moz-opacity: 0.75;
    opacity: 0.75;
}

*/

        tb_init('a.thickbox');

        $('#initThickbox').click();
        $('#initThickbox').hide();
        
        $('.TB_overlayBG')
            .css('display', 'block')
            .css('backgroundColor', '#000')
            .css('filter', 'alpha(opacity=75)')
            .css('-moz-opacity', '0.75')
            .css('opacity', '0.75');
        // And for Macs
        $('.TB_overlayMacFFBGHack').show();
        $('#TB_window').css('backgroundColor', '#fff');
    }
};

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
