/*******************************************************************************/
//functions for making rollovers in per_nav

		function nav_overs(elem)
		{
			var pnav = document.getElementById(elem);
			var nav_ims = pnav.getElementsByTagName('img');
			for(i=0;i<nav_ims.length;i++){
				//dont try to make rollovers for images with no_rollover class
				if(nav_ims[i].className != 'no_ro'){
					nav_ims[i].onmouseover=function(){this.src = splitSrc(this.src); }
					nav_ims[i].onmouseout=function(){this.src = splitSrc(this.src); }
				}
			}
			
		}
		
		//helper function for rollovers
		function splitSrc(imgsrc){			
			//now break it into parts so that we can change it to the over state
			var this_ext = imgsrc.substring(imgsrc.length-4,imgsrc.length);
			//flag the current state (on/off)
			var state = imgsrc.substring(imgsrc.length-7,imgsrc.length-4) == '_on' ? true : false;
				
				if(state){
					var this_src_split = imgsrc.split('_on');
					var newsrc = this_src_split[0]+''+this_ext;
				}else{
					var this_src_split = imgsrc.split(this_ext);
					var newsrc = this_src_split[0]+'_on'+this_ext;
				} 
			return newsrc;
		}
		
/*******************************************************************************/		
//function to increase flash holder's height
		staticCount = 1; //use 0 to cannibalize init
		function growDivOrig(divid, newhei){
			if(staticCount > 0){
			
			//hardcoding div id until flash can be changed
			divid='prod_menu'; // container div
			objid='productline2'; // object tag
			embid='productline2e'; // embed tag
			
			//gather up the objects that need to be resized
			var elem = document.getElementById(divid);
			var obj = document.getElementById(objid);
			if(document.getElementById(embid)){var emb = document.getElementById(embid);}else{var emb = false;}
			
			//in the case of a negative int, we return this
			var elemHei = sansPX(elem.style.height);
		
			//if a negative int is passed, just skip to returning the current height
			if(newhei >= 0){
			
				//used for testing only
				//document.getElementById('prod_detail_bottom').innerHTML = newhei;

				//resize the 3 elements
				elem.style.height = newhei+'px';
				obj.style.height = newhei+'px';
				if(emb){emb.style.height = newhei+'px';}
			 
			}else{
				return elemHei;
			}
			}else{
				staticCount++;
			}
		}


/*******************************************************************************/
// function to verify forgotten password

		function checkForgotPassword(formelem){
			
			emailaddress = document.getElementById(formelem).value;
			var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
			
			var isEmail = re.test(emailaddress);
			
			if(isEmail){
			document.getElementById('passsent').style.display = 'block';
			document.getElementById('forgotstep1').style.display = 'none';
			
			var postdata = "email="+emailaddress;
			$.ajax({
				type: "GET",
				url: "ajax/sendpassword.aspx",
				data: postdata
			});
			
			}else{
			document.getElementById('forgotemailerrors').innerHTML = 'The email address you entered was not valid.'
			}
		}

/*******************************************************************************/
// function to count chars in a form element - updates element innerHTML with count and trims string when hits max
		
		function countChars(elem,max,update){
			var curVal = document.getElementById(elem).value;
			var curCnt = curVal.length + 1;

			if(curCnt > max){
				curVal = curVal.substring(0,max);
				document.getElementById(elem).value = curVal;
			}
			
			document.getElementById(update).innerHTML = curCnt;
		}

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

parseParams() function written by Todd Resudek for Supersimple.org
Released November 2006

This function will parse any query string parameters into an array of key-value
pairs. 

The purpose is to be able manipulate a page, using variables, without the need
for a server-side technology.

The script runs itself onload, and stores all params into an associative array.
To access a specific value, use params[key]; (eg. alert(params['product']); )


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

//calls the parse function when the window loads
//remove this line if you want to call the parsing manually
window.onload = function(){parseParams();}

function parseParams(){
	
	//store the current window location
	var loc = window.location.toString();
		
	//grab the query string from the location	
	var queriesB = loc.indexOf('?');
	var queries = loc.substring(queriesB +1, loc.length);
	
	//break up into array of pairs
	var query = queries.split('&');
	
	//init an array to hold the key/value pairs
	params = new Array();
	
	for(var i=0; i < query.length; i++){
		//split into key value pairs
		curVar = query[i].split('=');
		
		//make a new hash of those key/value pairs
		params[curVar[0]] = curVar[1];
	}
	
	//adapted for use with product detail deep linking
	var ret = params['feature'] ? params['feature'] : 0;
	return ret;
}

/*******************************************************************************/		
		
		
		function searchrecipes( control , searchtype )
		{
		
		if (searchtype == 'keyword')
		{
			params = ( control.value != "" && control.value != "Search Recipes" ) ?  "?keywords=" + control.value : "";
			window.location = baseurl + 'searchresults.aspx' + params;
		}
		else if (searchtype == 'product')
		{
			if ( control.value < 0 )
			{
				catid = control.value * (-1);
				//alert(catid);
				params = "?productcategoryid=" + catid;
				//alert(params);
				window.location = baseurl + 'searchresults.aspx' + params;				
			}
			else
			{
			params = ( control.value != "9999" && control.value != "0") ?  "?productid=" + control.value : "";
			window.location = baseurl + 'searchresults.aspx' + params;
			}
		}
		else if (searchtype == 'quick')
		{
			if (control.value == "fast")
			{
				window.location = baseurl + 'searchresults.aspx?fastandeasy=true';
			}
			else if (control.value == "pop")
			{
				window.location = baseurl + 'searchresults.aspx?mostpopular=true';
			}
			else if (control.value == "feat")
			{
				window.location = baseurl + 'searchresults.aspx?featured=true';
			}
			else if (control.value == "feat")
			{
				window.location = baseurl + 'searchresults.aspx';
			}

			
		}

		}//end of function
		
		//function for switching product detail information
		function showProductFeature(feat){
			var menu = document.getElementById('prod_info_menu');
			var menuItems = menu.getElementsByTagName('li');
			var menuText = new Array('divdescription','divnutritioninfo','divingredients','divcookingdirections');
			
			
			//hide all menus
			for(i=0;i<menuItems.length;i++){
				if(i != feat){
				document.getElementById(menuText[i]).style.display = 'none';			
				menuItems[i].className = '';
				}else{
				menuItems[i].className = 'prodmenu_act';
				}
			}
			//show the requested area
			document.getElementById(menuText[feat]).style.display = 'block';
		}
		
		
		//************************* ajax shared functions
		
		//builds a xmlrequestobject used for AJAX 
		//For more information on ajax technology go to http://en.wikipedia.org/wiki/AJAX
		function getHTTPObject() {
		  var xmlhttp;
		  /*@cc_on
		  @if (@_jscript_version >= 5)	
			try {
			  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			  try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			  } catch (E) {
				xmlhttp = false;
			  }
			}
		  @else
		  xmlhttp = false;
		  @end @*/
		  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			try {
			  xmlhttp = new XMLHttpRequest();
			} catch (e) {
			  xmlhttp = false;
			}
		  }
		  return xmlhttp;
		}
		
		openRulesAndReg = function(){
			window.open(baseurl + 'betterTogether.html','TermsAndConditions','width=300,height=600,scrollbars=1,locationbar=false,toolbars=false');		
		}