//Check to see if site had been loaded within another website's frameset.  If so, change location back
//to Campbell's Kitchen web site with no frames.
if (top != self) {
	//alert("location: " + location);
	//alert("top.location: " + top.location);
	top.location = location;
}

function ChangeFontSize(add){
	var minFontSize=10,maxFontSize=16;
	var oldSize = parseInt(document.body.style.fontSize,10);
	if (isNaN(oldSize)) oldSize = parseInt(FindRule(document.styleSheets[0],'body').style.fontSize,10);
	var newSize = oldSize+add;
	newSize = Math.max(Math.min(newSize,maxFontSize),minFontSize);
	document.body.style.fontSize=newSize+'pt';

	(/cpovisq=([^&]+)/i).test(location.search);
	var visID = RegExp.$1;
	var commbadge=new Image();
	commbadge.src=approot+"savebasefontsize.asp?size="+newSize+"pt&nocache="+((new Date())*1)+"&cpovisq="+visID;
	//window.open(commbadge.src,'fontpop');
	if (isIE && isMac) window.resizeBy(add>0?1:-1,0);
}

function InitPage(){
	var visitbtn, visitmenu, printpage;
	if (!(visitbtn=document.getElementById('visit')) || !(visitmenu=document.getElementById('visitmenu'))) DebugOut("Couldn't find visitbtn or visitmenu!",0);
	else{
		var imgs=visitmenu.getElementsByTagName('img');
		for (var i=0,len=imgs.length;i<len;i++){
			var img=imgs[i];
			img.onmouseover=Glow;
			img.onmouseout=DeGlow;
			var cimg=imgCache[imgCache.length]=new Image();
			cimg.src=img.src.replace('off','on');
		}

		visitbtn.menu = visitmenu;
		visitbtn.onclick=visitmenu.onmouseover=ShowVisitMenu;
		visitbtn.onmouseout=visitmenu.onmouseout=HideVisitMenu0;
		HideVisitMenu();
	}
	if ((printpage=document.getElementById('printpage')) && window.print){
		printpage.style.display='inline';
		if (getQueryStringValue("rc") == "861") {
			AttachEvent(printpage,'click',function(){callAtlasTag('dencps_ProjectSquashRecipePrint_10');},true);
		}
		AttachEvent(printpage,'click',function(){window.print();},true);
		
	}
	if ((printpage=document.getElementById('printpage2')) && window.print){
		printpage.style.display='inline';
		if (getQueryStringValue("rc") == "861") {
			AttachEvent(printpage,'click',function(){callAtlasTag('dencps_ProjectSquashRecipePrint_10');},true);
		}		AttachEvent(printpage,'click',function(){window.print();},true);
	}
	if ((printpage=document.getElementById('printpage3')) && window.print){
		printpage.style.display='inline';
		if (getQueryStringValue("rc") == "861") {
			AttachEvent(printpage,'click',function(){callAtlasTag('dencps_ProjectSquashRecipePrint_10');},true);
		}		AttachEvent(printpage,'click',function(){window.print();},true);
	}
	if (isIE && isMac){
		var links = document.links;
		var unviewable=/(pdf|bmp)$/i;
		for (var i=0,len=links.length;i<len;i++) if (unviewable.test(links[i].href)) links[i].target='';
	}
	
	
}

function getQueryStringValue(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}
function callAtlasTag(tagName) {
   var e = document.createElement("img");
   e.src = "http://switch.atdmt.com/action/" + tagName;
   document.getElementsByTagName("form")[0].appendChild(e); 
}

function ShowVisitMenu(){
	if (visitTimer) clearTimeout(visitTimer);
	visitTimer=null;
 	var img=document.getElementById('visit');
	img.src=img.src.replace('off','on');
	//img.onclick=HideVisitMenu;
	img.oldalt=img.alt;
	img.alt="";
	img.menu.style.display='block';
	if (isIE && isMac && !window.visitMenuIsShowing) window.resizeBy(1,0);
	window.visitMenuIsShowing=true;
	return true;
}

function HideVisitMenu0(){
	visitTimer=setTimeout('HideVisitMenu()',200);
}
function HideVisitMenu(){
	visitTimer=null;
 	var img=document.getElementById('visit');
	img.src=img.src.replace('on','off');
	if (img.oldalt) img.alt=img.oldalt;
	window.status='';
	img.menu.style.display='none';
	if (isIE && isMac && window.visitMenuIsShowing) window.resizeBy(-1,0);
	window.visitMenuIsShowing=false;
	return true;
}

function HideQuizSubmit(submit_div_name){
 	var submit_div=document.getElementById(submit_div_name);
	submit_div.style.display='none';
	return true;
}

function ShowQuizSubmit(submit_div_name){
 	var submit_div=document.getElementById(submit_div_name);
	submit_div.style.display='block';
	return true;
}

function HideQuizAnswer(answer_div_name){
 	var answer_div=document.getElementById(answer_div_name);
	answer_div.style.display='none';
	return true;
}

function ShowQuizAnswer(answer_div_name){
 	var answer_div=document.getElementById(answer_div_name);
	answer_div.style.display='block';
	return true;
}

function PopUp(a,features){
	if (!features) features='width=600,height=400,location=0,menubar=0,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0,channelmode=0,directories=0,fullscreen=0';
	if (!/resizable/.test(features)) features+=',resizable=1';
	if (!/scrollbars/.test(features)) features+=',scrollbars=1';
	var w = window.open(a.href,a.target,features);
	try{ w.focus() }catch(e){}
	/*
	//It looks like the following was to work with auto-expanding code that no longer exists.
	//Since the popups open to a fixed height which should never be taller than the screen, I've removed it. -- Gavin
	try{
		AttachEvent(w,'load',function(){
			try{
				var bh = w.document.body.offsetHeight;
				var html = w.document.getElementsByTagName('html');
				if (html && html.length>0){
					var hh = html[0].offsetHeight;
					var sh = screen.availHeight;
					//alert('html: ' + hh + '\nbody: ' + bh + '\nscren: ' + sh);
					var y_delta = (hh + 50 > sh) ? (sh - hh - 50) : 0;
					w.resizeBy(0,y_delta);
				}
			}catch(e_inner){}
		},false);
	}catch(e){}
	*/

	return PreventDefault();
}

function OpenOpinionPollPopUp(targetPage, quizID, pollContentID, answer, sectionID, sectionCode, makeSelectionPrompt)
{
	var mypopup;

	if (answer == null)
	{
		alert(makeSelectionPrompt);
	}
	else
	{
		mypopup = window.open(targetPage + '?action=process&quizID=' + quizID + '&pollContentID=' + pollContentID + '&answer=' + answer + '&sectionID=' + sectionID + '&sectionCode=' + sectionCode, 'opinionpollresults', 'width=500,height=520,scrollbars=no,resizable=no');
		mypopup.focus();
	}

	//make sure the page does not refresh by returning false!
	return false;
}

function Glow(){ this.src=this.src.replace('off','on') }
function DeGlow(){ this.src=this.src.replace('on','off') }

var imgCache=[];
AttachEvent(window,'load',InitPage,false);

//Needed to work around display bugs
var ua = navigator.userAgent.toLowerCase();
var isIE = /msie/.test(ua) && !/opera/.test(ua);
var isMac = /mac/.test(ua);

function Find(oID){ return document.getElementById?document.getElementById(oID):document.all?document.all[oID]:null }

// Find the value of the currently selected radio button in a form by the set's name
function RadioButtonValue(frm,radioName){
	var radios = frm.elements[radioName];
	for (var i=0,len=radios.length;i<len;i++) if (radios[i].checked) return radios[i].value;
	return null;
}
