function blank(){
	}

function contentload(theelement,theurl) {
		AjaxRequest.get(
	  		{
				'url':theurl,
				'onSuccess':function(req){ document.getElementById(theelement).innerHTML = req.responseText ; }
			}
		);
	}
function windowload(url){
	alert("hello");
	window.location=url;
}
function submitForm(theform,theelement,thenexturl,thenextelement,delay) {
	var t;
	var status = AjaxRequest.submit(
		theform,{
			'onSuccess':function(req){ document.getElementById(theelement).innerHTML = req.responseText; }
			
		}
	);
	if(typeof thenextelement !== 'undefined'){
		if(thenextelement=='_PAGE_LOAD'){
			if (typeof delay !== 'undefined'){
				
				t=setTimeout("windowload(thenexturl)",1000);
			}else{
				window.location=thenexturl;
			}
		}else{
			contentload(thenextelement,thenexturl);
		}
	}
	return status;

}

function form_meal_planner_submit(key,value){
	var theform=document.forms['frm_meal_planner'];
	switch (key){
		case "view":
			theform.f_mp_view.value=value;
			break;
		case "date":
			theform.f_mp_date.value=value;
			break;
	}
	theform.submit();
		
}

function menuClick(thetree,thenode){
		var objx=this[thetree];
		objx.toggleBranch(thenode, true);
	}
	
function gup(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function printView(print) {
	var script_url = "./printview.php";
	var m = gup('m');
	var a = gup('a');
	var mode = gup('mode');
	var recipe_id = gup('recipe_id');
	//alert('m= '+m+', a= '+a+', recipe_id='+recipe_id);
	popupURL = script_url+"?m="+m+"&a="+a+'&recipe_id='+recipe_id+'&mode='+mode+'&print='+print;
	if (window.printview) {
		   window.printview.location=popupURL;
		   window.printview.focus();
	} else {
		var printview=window.open(popupURL,"printview",'top=7,screenY=7,left=7,screenX=7,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=650,height=1000');
		if (navigator.appName.substring(0,8)=="Netscape" || navigator.appName=="Microsoft Internet Explorer") {
		   printview.location=popupURL;
		   printview.opener=self;
		}
		printview.focus();
	}

}
	
function showOrHideById(obj, showOrHide) {
		var w = document.getElementById(obj);
		if (showOrHide == null) {
			if (w.style.visibility == 'hidden') {
				showOrHide = 'show';
			} else {
				showOrHide = 'hide';
			}
		}
		if (showOrHide == 'show') {
			w.style.display = 'block';
			w.style.visibility = 'visible';
			//w.style.cssText += "display: block; visibility: visible;";
		} else {
			w.style.display = 'none';
			w.style.visibility = 'hidden';
			//w.style.cssText += "display: none; visibility: hidden;";
		}
}
//an item may not have visibility until the actual property gets set either via css or javascript directly, and i think doing this via css classes DOES NOT set the javascript-recognized variables
function showOrHideRowById(obj, showOrHide) {
	var w = document.getElementById(obj);

	if (showOrHide == null) {
		//alert(w.style.visibility);
		if (w.style.visibility == 'visible') {
			showOrHide = 'hide';
		} else {
			showOrHide = 'show';
		}
	}
	if (showOrHide == 'show') {
		if (document.all) {
			w.style.display = 'block';
			w.style.visibility = 'visible';
			w.style.cssText = "display: block; visibility: visible;";
		} else {
			w.style.display = 'table-row';
			w.style.visibility = 'visible';
			w.style.cssText = "display: table-row; visibility: visible;";
		}
	} else {
		w.style.display = 'none';
		w.style.visibility = 'hidden';
		w.style.cssText = "display: none; visibility: hidden;";
	}
}
//open little window
function openLitWin(url, height, width) {
	corpwindow = window.open(url, '_corp', 'left=100,top=100,width=' + (width != null ? width : 800) + ',height=' + (height != null ? height : 400) + ',scrollbars=yes,resize=yes,resizeable=yes,resizable=yes,location=no,toolbar=no,menubar=no,status=no,directories=no');
	corpwindow.focus();
}

function getHeight(layerID) {
	if (document.all) {
		return document.getElementById(layerID).offsetHeight;
	} else{
		//Throws "Null Value" bug in safari
		return document.defaultView.getComputedStyle(document.getElementById(layerID), null).getPropertyValue('height', null);
	}
}
//stops cachine of search result layer in IE: make this return 1 to allow caching
function randChars() {
	return ''+Math.round(Math.random()*10)+Math.round(Math.random()*10)+Math.round(Math.random()*10)+Math.round(Math.random()*10);
}

//strips newlines, deal with it
function getAjaxReturnTagValue(str, tagId) {
	r_begin = new RegExp('\\[\\[' + tagId + '\\]\\]', "gi");
	r_end   = new RegExp('\\[\\[\\/' + tagId + '\\]\\]', "gi");
	startTag = r_begin.exec(str);
	endTag   = r_end.exec(str);
	if (startTag && endTag 
	    && startTag.index >= 0 && endTag.index > 0) {
			return str.substring((startTag.index + tagId.length + 4), endTag.index);
	}
	return null;

	mystr = str;

	regexp = new RegExp('\\[\\[' + tagId + '\\]\\](.*)\\[\\[\\/' + tagId + '\\]\\]', "gi");
	if (str.search(regexp) > -1) {
		return RegExp.$1;
	}
}
function getSelectedRadioValue(radioObj) {
	for(var i=0; i < radioObj.length; i++) {
		if (radioObj[i].checked == true) {
			return radioObj[i].value;
		}
	}
	return 0;
}

function selectRadioByValue(radioObj, valueToSelect) {
	for(var i=0; i < radioObj.length; i++) {
		if (radioObj[i].value == valueToSelect) {
			radioObj[i].click();//checked = true;
			return true;
		}
	}
	return false;
}

//also used for un-highlighting
function highlight(obj, color) {
	obj.style.backgroundColor = color;
}



/*

5-star rating script
Author: Addam M. Driver
Date: 10/31/2006


Modified to allow changing a rating - grg 12/23/2007
//todo: change id's from single digits
rm'd:
	sMax = 0;	// Is the maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;	
		}
	}
	
*/

var sMax = 5;	// Is the maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made
var rated;

// Rollover for image Stars //
function ratingRoll(num){
	if(1 || !rated){
		s = num.id; // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById(i).className = "on";
				//document.getElementById("rateStatus").innerHTML = num.title;	
				holder = a+1;
				a++;
			}else{
				document.getElementById(i).className = "";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function rateOff(me){
	if(1 || !rated){
		if(!preSet){
			for(i=1; i<=sMax; i++){		
				document.getElementById(i).className = "";
				//document.getElementById("rateStatus").innerHTML = me.parentNode.title;
			}
		}else{
			ratingRoll(preSet);
			document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML;
		}
	}
}

// When you actually rate something //
function rateRecipe(me,id){
	if(1 || !rated){
		preSet = me;
		rated=1;
		sendRate(me,id);
		ratingRoll(me);
	}
}

function reviewSaved(results) {
	results = unescape(results);
	document.getElementById("reviewBox").innerHTML = results;
}
function ratingSaved(results) {
	results  = unescape(results);
	//alert(results);
	document.getElementById("rateStatus").innerHTML = results;// + " :: "+me.title;
}

function ratingPreselect(num) {
	preSet = document.getElementById(num);
	rated=1;
	ratingRoll(preSet);
	rateOff();
}

function randChars2() {//make this use the same one as items.add_edit.js at some point
	return ''+Math.round(Math.random()*10)+Math.round(Math.random()*10)+Math.round(Math.random()*10)+Math.round(Math.random()*10);
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel,id) {
	
	//alert("Your rating was: "+sel.title);
	callAjax('?m=items&a=recipe_add_edit_view&mode=view&taction=addRating&rid='+parseInt(id)+'&srs'+randChars2()+'&rate=' + sel.id, true, null, 'ratingSaved' );
}






/* ****************** */

//different from InWindow function in that it leaves space open at the top for navigation
function maximizeLayerInMealWell(layerId) {
	var w = document.getElementById(layerId);
	var windowDim = getScreenInnerSize();
	
	topSpace = 0;//100;
	bottomSpace =  0;//90;
	w.style.top = topSpace + 'px';
	w.style.width = (windowDim[0])+'px';
	w.style.height= (windowDim[1] - topSpace - bottomSpace)+'px';
	return;
}

function maximizeLayerInWindow(layerId) {
	var w = document.getElementById(layerId);
	var windowDim = getScreenInnerSize();

	w.style.width = windowDim[0]+'px';
	w.style.height= windowDim[1]+'px';	
	return;
}

function centerLayerInWindow(layerId) {
	var w = document.getElementById(layerId);
	var windowDim = getWindowInnerSize();
	
	var tleft = Math.round(windowDim[0] - parseInt(w.style.width))/2;
	var ttop  = Math.round(windowDim[1] - parseInt(w.offsetHeight))/2;
	//alert(windowDim[0]+'-'+parseInt(w.style.width)+'/2='+tleft);
	//alert(windowDim[1]+'-'+w.offsetHeight+'/2='+ttop);
	w.style.left = tleft+'px';
	w.style.top  = ttop+'px';
	
	return;
}

function getScreenInnerSize() {
	var myWidth  = document.all ? Math.max(Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth), document.body.scrollWidth) : (document.body ? document.body.scrollWidth : ((document.documentElement.scrollWidth != 0) ? document.documentElement.scrollWidth : 0));
	var myHeight = document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0));
	
  return new Array(myWidth, myHeight);
}

function getWindowInnerSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Array(myWidth-20, myHeight-20);
}

function showBlackout(layerId) {
	maximizeLayerInMealWell('blackout');
	showOrHideById('blackout', 'show');
}
function hideBlackout(layerId) {
	showOrHideById('blackout', 'hide');
}

//pass the anchor name
//<a name="anchorHashName">
function gotoAnchor(anchorHashName) {
	location.hash = anchorHashName;
	return void(0);
}
/*
http://frontendframework.com/javascript/javascript-window-size-scroll-width_height/

Window = {	
	//Returns an integer representing the width of the browser window (without the scrollbar).
	getWindowWidth : function() {
	return (document.layers||(document.getElementById&&!document.all)) ? window.outerWidth : (document.all ? document.body.clientWidth : 0);
	},
 
	//Returns an integer representing the height of the browser window (without the scrollbar).
	getWindowHeight : function() {	
	return window.innerHeight ? window.innerHeight :(document.getBoxObjectFor ? Math.min(document.documentElement.clientHeight, document.body.clientHeight) : ((document.documentElement.clientHeight != 0) ? document.documentElement.clientHeight : (document.body ? document.body.clientHeight : 0)));
	},	
 
	//Returns an integer representing the scrollWidth of the window. 
	getScrollWidth : function() {
	return document.all ? Math.max(Math.max(document.documentElement.offsetWidth, document.documentElement.scrollWidth), document.body.scrollWidth) : (document.body ? document.body.scrollWidth : ((document.documentElement.scrollWidth != 0) ? document.documentElement.scrollWidth : 0));
	},
 
	//Returns an integer representing the scrollHeight of the window. 
	getScrollHeight : function(){		
		return document.all ? Math.max(Math.max(document.documentElement.offsetHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.body.scrollHeight)) : (document.body ? document.body.scrollHeight : ((document.documentElement.scrollHeight != 0) ? document.documentElement.scrollHeight : 0));
	},			
 
	//Returns an integer representing the scrollLeft of the window (the number of pixels the window has scrolled from the left).
	getScrollLeft : function() {
		return document.all ? (!document.documentElement.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft) : ((window.pageXOffset != 0) ? window.pageXOffset : 0);
	},
 
	//Returns an integer representing the scrollTop of the window (the number of pixels the window has scrolled from the top).
	getScrollTop : function() {
		return document.all ? (!document.documentElement.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop) : ((window.pageYOffset != 0) ? window.pageYOffset : 0);
	}
}
*/