
// Old popup code for backwards compatibility with sign up page
function setUrl(url)
{
}

function _gotoprint(id)
{
	myWin = window.open("http://www.sonomadiet.com/publicsite/index.aspx?print=true&puid=" + id, 'myWin', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=640,height=715');
}


function ToggleBMI(alwayshide) {
	obj_item=document.getElementById('bmiinfo');
	visible=(obj_item.style.display!="none");
	if (visible || alwayshide) {
		obj_item.style.display="none";
	} else {
		obj_item.style.display="block";
	}
}


// BEGIN Generic popup/popunder code
function doPop()
{
	if (doPopUnder)
	{
		popunderwin = window.open(popUrl, 'popunderwin', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=700,height=550');
		popunderwin.focus();
	}
}

function noPop()
{
	doPopUnder = false;
}



function checkClose()
{
	setTimeout("checkClose_Part2()",100);
	
}

function checkClose_Part2()
{
if(window.opener.winID == "main") self.close();
}

function goRegister(url)
{
	if (url == "") {
		url = "/netregistration/register.aspx";
	}
	
	widthofwin = window.screen.width;
	heightofwin = window.screen.height;

	if (widthofwin > 800)
	{
		widthofwingo = 900
		heightofwingo = 850
	}
	if (widthofwin < 800)
	{
		widthofwingo = 630
		heightofwingo = 450
	}

    try {
		// If the opener of this page was a popunder, close the popunder
		if(self.opener.winID == "popunder") {
			self.opener.window.close();
		}

		if(self.opener.closed==false)
		{
			self.opener.doPopUnder = false;
			self.opener.location.href = url;
			window.close();
		}
		else
		{
			var win3 = window.open(url,'signupwin','toolbar=1,location=1,scrollbars=1,directories=1,status=1,menubar=1,resizable=1,width='+widthofwingo+',height='+heightofwingo);
		}
    }
    catch(e) {
		var win3 = window.open(url,'signupwin','toolbar=1,location=1,scrollbars=1,directories=1,status=1,menubar=1,resizable=1,width='+widthofwingo+',height='+heightofwingo);
	}
	finally {
		self.close();
	}
	
}
// END Generic popup/popunder code


/*********************************************
* Take cookie name and url
* Redirects to url if specified cookie is null
**********************************************/
function CookieNullRedirect(cookieName, redirUrl) {
    if (jQuery.cookie(cookieName) == null || jQuery.cookie(cookieName) == '')
        location.href = redirUrl;
}

/*********************************************
* Gets all checked checkboxes on the page
* Returns Array
**********************************************/
function GetArrSelectedCheckBoxID() {
    var selected_id = [];
    jQuery(':checkbox:checked').each(function(i) {
        selected_id[i] = jQuery(this).attr("id");
    });
    return selected_id;
}

/*********************************************
* Checks and gets Cookie by value name
* * Uses: jquery cookie
* * returns false if cookie is null
* * returns cookie value if cookie is set
**********************************************/
function GetCookieValueByKey(cookieName, keyName) {
    var cookieString = jQuery.cookie(cookieName);
    if (cookieString == null || cookieString == '') return false;
    var cookieStringObject = cookieString.split("&");
    var cookieVal = "";
    for (x = 0; x < cookieStringObject.length; x++) {
        var xobj = cookieStringObject[x].split('=');
        if (xobj[0] == keyName) cookieVal = xobj[1];
    }
    if (cookieVal == '') return false;
    return cookieVal;
}

/*********************************************
* Action on Submit of the Suggest NL Page
* * Gets all the selected id's on the page 
* * submits to specified url
* * Redirects to leadgen
**********************************************/
function SuggestNLSubmit(subscribeUrl, leadgenUrl, selected) {
    if (selected == '' || selected == null) {
        location.href = leadgenUrl;
        return false;
    } else {
        jQuery.getJSON(subscribeUrl, function(data) {
            location.href = leadgenUrl;            
            return false;
    });
        return false;
    }
}
