﻿/********* misc functions ***********/
function popRecipe(url) {
	var title = "recipe";
	var width = 496;
	var height = 640;
	var params = "location=no,directories=no,menubar=yes,toolbar=yes,height="+ height +",width="+ width +",scrollbars=yes";
	popWindow(url, title, params);
}

function popNutrition(url) {
	var title = "Cheerios";
	var width = 960;
	var height = 500;
	var params = "location=no,directories=no,menubar=yes,toolbar=yes,height="+ height +",width="+ width +",scrollbars=yes";
	popWindow(url, title, params);
}

function popSendAFriend(sourceURL, pageType) {
	var url = "TellAFriend.aspx"
	var queryFlag = 0;
	
	if (sourceURL != "") {
		url += "?sourceURL="+ sourceURL;
		queryFlag = 1;
	}
	
	if (pageType != "") {
		if (queryFlag = 0) {
			url += "?";
		} else {
			url += "&";
		}
		url += "pageType="+ pageType;
	}
	
	var title = "TellAFriend";
	var width = 565;
	var height = 585;
	var params = "location=no,directories=no,menubar=no,toolbar=no,height="+ height +",width="+ width +",scrollbars=yes";
	popWindow(url, title, params);
}

function popWindow(url, title, params) {
	var newwin = window.open(url, title, params);
}

function printWindow() {
	if (window.print) {
		self.print();
	} else {
		alert("Your browser does not support this functionality.");
	}	
}

function switchLang () {
	engDelimiter = '/en/';
	freDelimiter = '/fr/';
	newURL = switchLangSearch(engDelimiter, freDelimiter);
	if (newURL != 'null') {
		self.location = newURL;
		return;
	} 
}

function switchLangSearch (engDelim, freDelim) {
	docURL = document.URL;
	newURL = 'null';
	engPosition = 0;
	frePosition = 0;
	charStart = 0;
	charEnd = docURL.length + 1;
	engDelimiter = engDelim;
	freDelimiter = freDelim;
	do {
		var test = docURL.substr(charStart, engDelimiter.length);
		if (test == engDelimiter) { engPosition = charStart;}
		charStart++;
	}
	while (charStart < charEnd - engDelimiter.length);
	if (engPosition > 0) {
		newURL = docURL.substr(0,engPosition) + freDelimiter + docURL.substr((engPosition + engDelimiter.length),docURL.length);
	} else {
		charStart = 0;
		do {
			var test = docURL.substr(charStart, freDelimiter.length)
			if (test == freDelimiter) { frePosition = charStart;}
			charStart++;
		}
		while (charStart < charEnd - freDelimiter.length);
		if (frePosition > 0) {
			newURL = docURL.substr(0,frePosition) + engDelimiter + docURL.substr((frePosition + freDelimiter.length),docURL.length);
		}
	}
	return newURL;
}

/********* browser detection ***********/
var ie = (document.all)? true:false;
var ns5 = (navigator.appName.indexOf("Netscape") !=-1 && parseInt(navigator.appVersion) >= 5) ?true:false;
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;	
var isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false; 
var isIE4Mac = (isMac && isIE) ? true:false;
var isNS6 = ((navigator.appName.indexOf("Netscape") != -1) && (parseInt(navigator.appVersion) > 4)) ? true:false;

/********* code for flash detection ***********/
var requiredVersion = 5;	

var flash2Installed = false;		
var flash3Installed = false;		
var flash4Installed = false;		
var flash5Installed = false;		
var flash6Installed = false;	
var flash7Installed = false;	

var maxVersion = 7;					
var actualVersion = 0;				
var hasRightVersion = false;

if(isIE && !isMac){ 
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
	document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');	
	document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
	document.write('</SCR' + 'IPT\> \n'); 			
}

if (navigator.plugins){								
	if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){		

		var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
		var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
		var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));

		flash2Installed = (flashVersion == 2)?true:false;		
		flash3Installed = (flashVersion == 3)?true:false;
		flash4Installed = (flashVersion == 4)?true:false;
		flash5Installed = (flashVersion == 5)?true:false;
		flash6Installed = (flashVersion == 6)?true:false;
		flash7Installed = (flashVersion == 7)?true:false;
	}
}

for (var i = 2; i <= maxVersion; i++){	
	if (eval("flash" + i + "Installed") == true) actualVersion = i;
}

if (actualVersion >= requiredVersion){ 				
	hasRightVersion = true;	
} 						
//alert(actualVersion +' ~ '+ hasRightVersion +' ~ '+ requiredVersion);

/********* write flash movie to home page ***********/
function writeFlash(movie, pic, altTagCopy, width, height) {
	if (hasRightVersion) {
		 if(isIE && !isMac){
			document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash/cabs/swflash.cab#version=2,0,0,0" ID="header" WIDTH='+ width +' HEIGHT='+ height +'>');
			document.write('<PARAM NAME=movie VALUE="'+ movie +'">'); 
			document.write('<PARAM NAME=quality VALUE=high>'); 
			document.write('<PARAM NAME=scale VALUE=exactfit>'); 
			document.write('<PARAM NAME=bgcolor VALUE=#ffffff>');
			document.write('<PARAM NAME=menu VALUE=false>');
			document.write('<PARAM NAME=loop VALUE=true>');
			document.write('</OBJECT>');
		} else {
			document.write('<EMBED SRC="'+ movie +'" NAME=header WIDTH='+ width +' HEIGHT='+ height +' SCALE=exactfit QUALITY=high LOOP=true MENU=false BGCOLOR=#ffffff TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>');   
	  	}
	 } else {
		document.write('<link rel="stylesheet" href="styles/CheeriosStyleSheet.css" type="text/css"><table border="0" cellpadding="0" cellspacing="0"><tr><td valign="top" align="right"><img src="med/toggle_leftSide.gif" width=21 height=206 border=0><br><a href="en/index.aspx" onMouseover="document.images[\'toggleEnglish\'].src=\'med/button.Engon.gif\'; document.images[\'toggleAnigif\'].src=\'med/Eng_toggle.gif\';" onMouseout="document.images[\'toggleEnglish\'].src=\'med/button.Engoff.gif\';"><img name="toggleEnglish" src="med/button.Engoff.gif" width=90 height=26 border=0></a></td><td valign="top"><img name="toggleAnigif" src="med/Eng_toggle.gif" border=0 width=229 height=232></td><td valign="top"><img src="med/toggle_rightSide.gif" width=30 height=206 border=0><br><a href="fr/index.aspx" onMouseover="document.images[\'toggleFrench\'].src=\'med/button.Fraon.gif\'; document.images[\'toggleAnigif\'].src=\'med/FR_toggle.gif\';" onMouseout="document.images[\'toggleFrench\'].src=\'med/button.Fraoff.gif\';"><img name="toggleFrench" src="med/button.Fraoff.gif" width=90 height=26 border=0></a></td></tr><tr><td><img src="med/spacer.gif" width=21 height=1 border=0></td><td><img src="med/toggle_bottomSide.gif" border=0></td><td><img src="med/spacer.gif" width=30 height=1 border=0></td></tr></table>');
	 }
}

/********* cookie functions ***********/
function writeCookie(cookieName, cookieValue) {
		document.cookie = cookieName +"="+ cookieValue +";path=/;";
}

function readCookie(cookieName) {
	var strCookie = document.cookie;
	var startIndex = strCookie.indexOf(cookieName+"=");
	var cookieValue = "";
	
	if (startIndex != -1) { // cookie exists, get value
		startIndex = strCookie.indexOf("=", startIndex) + 1;
		var endIndex = strCookie.indexOf(";", startIndex);
		if (endIndex == -1) {
			endIndex = strCookie.length;
		}
		
		cookieValue = unescape(strCookie.substring(startIndex, endIndex));
	}
	
	return cookieValue;
}
