﻿function setVis(id, vis, displayNone) {
    if (id != '') {
        if (displayNone == undefined || (displayNone != true && displayNone != false)) {
            displayNone = true;
        }
	    obj = MM_findObj(id);
	    if (obj == undefined) {
	        return;
	    }
	    
	    if(document.getElementById || document.all){//all the modern browsers
		    obj.style.visibility = vis ? "visible" : "hidden";
		    if (displayNone) {
		        obj.style.display = vis ? "block" : "none";
		    }
	    }
	    else if(document.layers){//this is NS4
		    obj.visibility = vis ? "show" : "hide";
		    if (displayNone) {
    		    obj.display = vis ? "block" : "hide";
            }
	    }  
	}
}

function EmailSignup_Click(){
    document.getElementById('modalPageEmailSignup').style.top = getScrollY();
    document.getElementById('modalPageEmailSignup').style.display = "block";
    window.onscroll = function () { document.getElementById('modalPageEmailSignup').style.top = getScrollY(); };
}
function EmailSignup_Close(){
    document.getElementById('modalPageEmailSignup').style.display = "none";
}

function SendToFriend_Click(){
    document.getElementById('modalPageSendToFriend').style.top = getScrollY();
    document.getElementById('modalPageSendToFriend').style.display = "block";
    window.onscroll = function () { document.getElementById('modalPageSendToFriend').style.top = getScrollY(); };
}
function SendToFriend_Close(){
    document.getElementById('modalPageSendToFriend').style.display = "none";
}

function Comment_Click(cookingTipItemID){
    document.getElementById('cookingTipItemID').value = cookingTipItemID;
    document.getElementById('modalPageComment').style.top = getScrollY();
    document.getElementById('modalPageComment').style.display = "block";
    window.onscroll = function () { document.getElementById('modalPageComment').style.top = getScrollY(); };
}
function Comment_Close(){
    document.getElementById('modalPageComment').style.display = "none";
}

function Video_Click(video_file){
    document.getElementById('modalPageVideo').style.top = getScrollY();
    document.getElementById('modalPageVideo').style.display = "block";
    window.onscroll = function () { document.getElementById('modalPageVideo').style.top = getScrollY(); };
    var content = new SWFObject("../Resources/images/vidPlayer.swf", "vidPlayer", "708", "418", "7", "#000000");
    content.addVariable("videoName" , video_file);
    //content.addParam("wmode","transparent");
    content.write("VideoContainer");
}

function Video_Close(){
    document.getElementById('VideoContainer').innerHTML = '';
    document.getElementById('modalPageVideo').style.display = "none";
}

function getScrollY(){
    scrollY = 0;
    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }
    return scrollY + "px";
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function isMaxLength(txtBox) {
    if(txtBox) {
        return (txtBox.value.length <= 500);
    }
}

function isValidZip(zip) {
    if(zip.length == 5)
    {
        return(zip.match(/^\d+$/)); 
    }
    else return false;
}


function isMaxLength(obj)     
{   
    var max = 500;
    var val = obj.value
    var result = true;
    if (val.length > max)
    {
        alert("Please limit comments to 500 characters.");
        var stripped = val.substring(0, max);
        obj.value = stripped;
        result = false;
    }
    if (window.event)
    {
        window.event.returnValue = result; 
    }
    
    return result;
} 


