addEvent(window,'load',externalLinks);
addEvent(window,'load',externalform);
addEvent(window,'load',auto_off);

function webinar(type) {
	if(type=='over') {
		document.getElementById('saladworks_webinar').src='/images/webinar_over.png';
	} else {
		document.getElementById('saladworks_webinar').src='/images/webinar.png';
	}
}

function new_webinar(type) {
	if(type=='over') {
		document.getElementById('saladworks_webinar').src='/images/square/webinar_over.png';
	} else {
		document.getElementById('saladworks_webinar').src='/images/square/webinar.png';
	}
}

function check_time(frm){
	var del=document.getElementById('otype');
	var times=document.getElementById('otime');
	if(!document.getElementById('pt') || !document.getElementById('dt')) {
		alert("Sorry we are currently closed, please come back at our regular shcedule of hours");
		return false;
	}
	if(!del.value) {
		alert("Please choose either pickup or delivery");
		return false;
	}
	var pt=document.getElementById('pt');
	var dt=document.getElementById('dt');
	if(del.value=='pickup' && !times.value) {
		alert("Please choose an estimated pickup time");
		return false;
	}
	if(del.value=='delivery' && !times.value) {
		alert("Please choose an estimated delivery time");
		return false;
	}
	return true;
}

function externalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") &&
        anchor.getAttribute("rel") == "external"){
      anchor.target = "_blank";
//      anchor.innerHTML = anchor.innerHTML + " &#xBA;";
    }
    if (anchor.getAttribute("href") &&
        anchor.getAttribute("rel") == "protected"){
      anchor.target = "_saladworks";
      anchor.innerHTML = anchor.innerHTML + " *";
    }
 }
}

function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}
// Reusable removeEvent function
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}

function externalform() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("form");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("method") &&
        anchor.getAttribute("rel") == "external"){
      anchor.target = "_saladworks";
    }
 }
}

function Fanaticly_Fresh() {}

function set_corner() {
document.getElementById('content').style.borderBottomRightRadius="55px";
document.getElementById('content').style.borderBottomLeftRadius="55px";
}

function reset_geo(frm) {
	if(document.getElementById('content-salad')) {
		document.getElementById('content-salad').style.background="/Content/Images/salad_backdrop.jpg";
	}
	document.getElementById('geoform').reset();
return false;
}

function numbersonly(e){
var unicode = e.charCode ? e.charCode : e.keyCode;
	if(unicode == 46) {
		return true;
	} else {
		if(unicode != 8){ 
			if(unicode < 48 || unicode > 57){
				return false;
			} else {
				return true;
			}
		} else {
			return true;
		}
	}
}
/*
window.onload = function(){
	var button1_up = new Image();
	button1_up.src = "/images/myfeshspace.jpg";
	var button1_over = new Image();
	button1_over.src = "/images/myfeshspace_rollover.jpg";
	var lis = document.getElementById('myfresh');
	var im = document.getElementById('myfreshimage');
	lis.onmouseover = function(){im.src = button1_over.src;};
	lis.onmouseout = function(){im.src = button1_up.src;};
};
*/
function isEmpty(aTextField) 
{
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}

function serverFunction(url)
{
	 var req = false;
	 // For Safari, Firefox, and other non-MS browsers
	 if (window.XMLHttpRequest) {
		  try {
			   req = new XMLHttpRequest();
		  } catch (e) {
			   req = false;
		  }
	 } else if (window.ActiveXObject) {
		  // For Internet Explorer on Windows
		  try {
			   req = new ActiveXObject("Msxml2.XMLHTTP");
		  } catch (e) {
			   try {
			   req = new ActiveXObject("Microsoft.XMLHTTP");
			   } catch (e) {
			   req = false;
			   }
		  }
	 }

	 if (req) {
	 // Synchronous request, wait till we have it all

	 req.open('POST', url, false);
	 req.send(null);
	 return(req.responseText);
	 } else {
	 alert("Sorry, your browser does not support " +
		  "XMLHTTPRequest objects. This page requires " +
		  "Internet Explorer 5 or better for Windows, " +
		  "or Firefox for any system, or Safari. Other " +
		  "compatible browsers may also exist.");
	 }
}

function geo_location(frm) {
	frm.action="../saladworks_inc/ajax.inc.php?type=geo_form";
	var searchit=document.getElementById('search_loc');
	var ts=document.getElementById('tstates').value;
	var ssr=document.getElementById('sr');
	if(document.getElementById('content-salad')) {
		document.getElementById('content-salad').style.background="none";
	}
	SIMMLLC.submit(frm, {'onStart' : startCallback, 'onComplete' : write_latlng});
	//if(searchit.value != 'SR') {
		//add_line('buttons','Search Results');
	//	searchit.value='SR';
	//}
}

function geo_location_calc(frm) {
	frm.action="../saladworks_inc/ajax.inc.php?type=geo_form_calc";
	var searchit=document.getElementById('search_loc');
	var ts=document.getElementById('tstates').value;
	var ssr=document.getElementById('sr');
	if(document.getElementById('content-salad')) {
		document.getElementById('content-salad').style.background="none";
	}
	SIMMLLC.submit(frm, {'onStart' : startCallback, 'onComplete' : write_latlng});
	//if(searchit.value != 'SR') {
		//add_line('buttons','Search Results');
	//	searchit.value='SR';
	//}
}

function cancel_order() {
	var x=confirm('Are you sure you want to cancel your online order?');
	if(x) {
		var ajax = new sack();
		url="../saladworks_inc/ajax.inc.php?type=cancel_order";
		ajax.requestFile = url;	// Specifying which file to get
		ajax.onCompletion = function(){ window.location=ajax.response;}
		ajax.runAJAX();		// Execute AJAX function
		return false;
	}
}

function expand_menu(group){
	var ajax = new sack();
	url="../saladworks_inc/ajax.inc.php?type=expand_menu&id="+group;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){ window.location=ajax.response; }//alert(ajax.response); }
	ajax.runAJAX();		// Execute AJAX function
}

function createMarker(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
}

function auto_off() {
	if (document.getElementById('geoform') || document.getElementById('register') || document.getElementById('userform')) {
		if(document.getElementById('geoform')) {
			var f = document.getElementById('geoform');
		} else if(document.getElementById('register')) {
			var f = document.getElementById('register');
		} else if(document.getElementById('userform')) {
			var f = document.getElementById('userform');
		}
		var u = f.elements[1];
		f.setAttribute("autocomplete", "off");
		//u.focus();
	}
}
	  
function mapsLoaded() {
	var lat=document.getElementById('lat').value;
	var lng=document.getElementById('lng').value;
	var txt=document.getElementById('txt').value;
	var size=parseFloat(document.getElementById('size').value);

	var carrotIcon = new GIcon(G_DEFAULT_ICON);
	carrotIcon.image = "http://saladworks.com/images/carroticon.png";
	markerOptions = { icon:carrotIcon };
					
   	var map = new google.maps.Map2(document.getElementById("map"));
	var center = new GLatLng(lat,lng);
    var point = new GLatLng(lat,lng);
	map.setCenter(center, size);
	map.addControl(new GSmallMapControl());
   // map.addControl(new GMapTypeControl());
	var marker = new GMarker(point,markerOptions)
	map.addOverlay(marker);
	marker.openInfoWindowHtml(txt);
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(txt);});
	purge(marker);
}
function loadMaps() {
  google.load("maps", "2", {"callback" : mapsLoaded});
}

function initLoader(key) {
  var script = document.createElement("script");
  script.src = "http://www.google.com/jsapi?key="+key+"&callback=loadMaps";
  script.type = "text/javascript";
  document.getElementsByTagName("head")[0].appendChild(script);
}
function startCallback() {
	return true;
}

function completeCallback(response) {
	document.getElementById('nr').innerHTML = response;
}

function nutrition_location(id) {
	var ajax = new sack();
	url="../saladworks_inc/ajax.inc.php?type=quick_location&loc="+id;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){ window.location=ajax.response; }
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function open_ajax(page,id,title) {
	var wpage="../saladworks_inc/ajax.inc.php?type=";
	ajaxwin=dhtmlwindow.open("ajaxbox", "ajax", wpage+page, title, "width=550px,height=454px,left=300px,top=180px,resize=1,scrolling=1");
	ajaxwin.onclose=function(){}
	var ajax = new sack();
	url = wpage+"lat_long&id="+id;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		var returnvalue=ajax.response.split("@");
		var lat=returnvalue[0];
		var lng=returnvalue[1];
		var key=returnvalue[2];
		var txt=returnvalue[3];
		document.getElementById('lat').value=lat;
		document.getElementById('lng').value=lng;
		document.getElementById('txt').value=txt;
		initLoader(key);
	}
	ajax.runAJAX();
	return false;
}

function write_latlng(response) {
	var returnvalue=response.split("@");
	var lat=returnvalue[0];
	var lng=returnvalue[1];
	document.getElementById('lat').value=lat;
	document.getElementById('lng').value=lng;
	document.getElementById('searchr').innerHTML=response;
}

function write_n(response) {
	document.getElementById('nr').innerHTML=response;
}

function run_report() {
	var ajax = new sack();
	var j=document.getElementById('run_report').value;
	url ="reports.php?report_type=run_report&report_id="+j;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){ write_n(ajax.response); }
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function view_list(obj) {
	var j=document.getElementById(obj).innerHTML;
	document.getElementById('nr').innerHTML=j;	
}
function add_line(li,data) {
	var obj = document.getElementById(li);
	var nli = document.getElementById("sr");
	nli.innerHTML = data;
}

function get_code_promo(){
	var ajax = new sack();
	var list=new Array() ;
	var total=0;
	var id=document.getElementById('promo_code').value;
		url="../saladworks_inc/ajax.inc.php?type=get_code_promo&item="+id;
		ajax.requestFile = url;	// Specifying which file to get
		ajax.onCompletion = function(){
		var data=ajax.response.split("@");
		if(data[0]=='false') {
			alert(data[1]);
		} else {
			document.getElementById('promo_id').value=data[1];
			document.getElementById('menu').submit();
		}
		}
		ajax.runAJAX();		// Execute AJAX function
		return false;
}

function order_now(id,type) {
 	switch(type){
    case '0':
		var ajax = new sack();
		url="../saladworks_inc/ajax.inc.php?type=change_item&item="+id;
		ajax.requestFile = url;	// Specifying which file to get
		ajax.onCompletion = function(){
		document.getElementById('menu').action='/order_online';
		document.getElementById('id').value=id;
		document.getElementById('menu').submit();
		}
		ajax.runAJAX();		// Execute AJAX function
	break
    case '3':	
		var ajax = new sack();
		var list=new Array() ;
		var total=0;
		var result2 =null;
		var frm=document.getElementById('menu');
		for (i=0; i<frm.elements.length; i++){
			if(frm.elements[i].type=="checkbox") {
				if(frm.elements[i].checked==true) {
					list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
				} 
			} else {
				list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
				if(frm.elements[i].name.slice(0,4) == 'food') {
					total=total+frm.elements[i].value;
				}
			}
		}
		var result1=list.join() //creates the String "Apple,Oranges"
		var result2=list.join("&") //creates the String "Apple*Oranges"
		if(total==0) {
			alert('Please choose a product');
		} else {
			url="../saladworks_inc/ajax.inc.php?type=purchase_food&item="+id+"&"+result2;
			ajax.requestFile = url;	// Specifying which file to get
			ajax.onCompletion = function(){
	/*
			document.getElementById('menu').action='/order_online/order_process';
			document.getElementById('id').value=id;
			document.getElementById('product_id').value=id;
			document.getElementById('fd_order').value=ajax.response;
			document.getElementById('menu').submit();
			alert(ajax.response);
	*/
			var data=ajax.response.split("@");
			if(data[0]=='false') {
				if(data[1]=='HTTP') {
					window.location=data[0];
				} else {
					alert(data[1]);
				}
			} else {
				window.location=data[0];
			};
			}
			ajax.runAJAX();		// Execute AJAX function
		}
		return false;
	break
	default:
		var ajax = new sack();
		url="../saladworks_inc/ajax.inc.php?type=purchase_food&item="+id+"&food["+id+"]=1";
		ajax.requestFile = url;	// Specifying which file to get
		ajax.onCompletion = function(){
		var data=ajax.response.split("@");
			if(data[0]=='false') {
				if(data[1]=='HTTP') {
					window.location=data[0];
				} else {
					alert(data[1]);
				}
			} else {
				window.location=data[0];
			};
			}
		ajax.runAJAX();		// Execute AJAX function
		return false;
	/*
		messageObj.setShadowOffset(5);	// Large shadow
		url="../saladworks_inc/ajax.inc.php?type=add_to_cart&id="+id;
		display_window(url,375,305);
	*/
	break
	}
}

function startcheckout(frm) {
	document.getElementById('sworder').value='checkout';
	pause_process('geoform');
	document.getElementById('geoform').submit();
}

function pause_process(frm){
	return check_time(frm);
	if(document.getElementById('sw-process_order')) {
		document.getElementById('sw-process_order').style.display='none';	
		document.getElementById('processing_hold').style.display='block';	
	}
	return true;
}

function change_time(type) {
	var times=document.getElementById(type).value;
	if(type=='pt') {
		document.getElementById('otype').value='pickup';
	} else {
		document.getElementById('otype').value='delivery';
	}
		document.getElementById('otime').value=times;
}

function show_card(image,card,id) {
	var im=document.getElementById('card_image');
	var rd=document.getElementById('card');
	im.innerHTML='<img src="/images/gift_cards/large/'+image+'" alt="'+card+'" />';
	im.innerHTML+='<br /><strong>'+card+'</strong>';
	document.getElementById('card_id').value=id;
	rd.innerHTML=card;
	purge(im);
	purge(rd);
}

function use_gift_add(id) {
	var ajax = new sack();
	url="../saladworks_inc/ajax.inc.php?type=use_gift_add&id="+id;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		//alert(ajax.response);
		var data=ajax.response.split("@");
		document.getElementById('billing_address').value=data[0];
		document.getElementById('billing_sub_address').value=data[1];
		document.getElementById('billing_city').value=data[2];
		document.getElementById('billing_state').value=data[3];
		document.getElementById('billing_zipcode').value=data[4];
		document.getElementById('fname').value=data[5];
		document.getElementById('lname').value=data[6];
		document.getElementById('phone_number').value=data[8];
		}
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function gift_card_process(frm) {
	var ajax = new sack();
	var attention = "#FFFFD5";
	var theone='nope';
	if(!document.getElementById('card_id').value) {
		alert("Please Choose a Gift Card.");
		return false;
	}
	if(!document.getElementById('total').value) {
		alert("Please enter how many gift cards you want to purchase");
		document.getElementById('total').focus();
		document.getElementById('total').style.background=attention;
		return false;
	}
	if(!document.getElementById('amount').value) {
		alert("Please enter how much you want the gift card to be worth.");
		document.getElementById('amount').focus();
		document.getElementById('amount').style.background=attention;
		return false;
	}
	if(!document.getElementById('ship_fname').value) {
		alert("Please enter the FIRST NAME of the person you wish to send this card to.");
		document.getElementById('ship_fname').focus();
		document.getElementById('ship_fname').style.background=attention;
		return false;
	}
	if(!document.getElementById('ship_lname').value) {
		alert("Please enter the LAST NAME of the person you wish to send this card to.");
		document.getElementById('ship_lname').focus();
		document.getElementById('ship_lname').style.background=attention;
		return false;
	}
	if(!document.getElementById('address').value) {
		alert("Please enter the ADDRESS of the person you wish to send this card to.");
		document.getElementById('address').focus();
		document.getElementById('address').style.background=attention;
		return false;
	}
	if(!document.getElementById('city').value) {
		alert("Please enter the CITY of the person you wish to send this card to.");
		document.getElementById('city').focus();
		document.getElementById('city').style.background=attention;
		return false;
	}
	if(!document.getElementById('zipcode').value) {
		alert("Please enter the ZIPCODE of the person you wish to send this card to.");
		document.getElementById('zipcode').focus();
		document.getElementById('zipcode').style.background=attention;
		return false;
	}
	if(parseFloat(document.getElementById('min').value) > parseFloat(document.getElementById('amount').value)) {
		alert("Your Dollar amount is below the minimum.\r\nPlease enter a new amount.");
		document.getElementById('amount').focus();
		document.getElementById('amount').style.background=attention;
		return false;
	}
	/*
	for (i=0;i<document.forms['standard'].elements['shipping'].length;i++){
		if (document.forms['standard'].elements['shipping'][i].checked==true) {
			theone=i;
		}
	}
	if(theone == 'nope') {
		alert("Please choose a Shipping Type.");
		return false;
	}
	*/
	var list=new Array() ;
	for (i=0; i<frm.elements.length; i++){
	
		if(frm.elements[i].type=="checkbox") {
			if(frm.elements[i].checked==true) {
				list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
			} 
		} else {
			list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
		}
	}
	var result1=list.join() //creates the String "Apple,Oranges"
	var result2=list.join("&") //creates the String "Apple*Oranges"
	url="../saladworks_inc/ajax.inc.php?type=gift_card_add&"+result2;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){window.location=ajax.response;
		/*
		document.getElementById('card_items').innerHTML=ajax.response;
		document.forms['standard'].reset();
		*/
		}
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function gifts_card_edit(frm){
	var ajax = new sack();
	var attention = "#FFFFD5";
	var theone='nope';
	if(!document.getElementById('edit_amount').value) {
		alert("Please enter how much you want the gift card to be worth.");
		document.getElementById('edit_amount').focus();
		document.getElementById('edit_amount').style.background=attention;
		return false;
	}
	if(!document.getElementById('edit_ship_fname').value) {
		alert("Please enter the FIRST NAME of the person you wish to send this card to.");
		document.getElementById('edit_ship_fname').focus();
		document.getElementById('edit_ship_fname').style.background=attention;
		return false;
	}
	if(!document.getElementById('edit_ship_lname').value) {
		alert("Please enter the LAST NAME of the person you wish to send this card to.");
		document.getElementById('edit_ship_lname').focus();
		document.getElementById('edit_ship_lname').style.background=attention;
		return false;
	}
	if(!document.getElementById('edit_address').value) {
		alert("Please enter the ADDRESS of the person you wish to send this card to.");
		document.getElementById('edit_address').focus();
		document.getElementById('edit_address').style.background=attention;
		return false;
	}
	if(!document.getElementById('edit_city').value) {
		alert("Please enter the CITY of the person you wish to send this card to.");
		document.getElementById('edit_city').focus();
		document.getElementById('edit_city').style.background=attention;
		return false;
	}
	if(!document.getElementById('edit_zipcode').value) {
		alert("Please enter the ZIPCODE of the person you wish to send this card to.");
		document.getElementById('edit_zipcode').focus();
		document.getElementById('edit_zipcode').style.background=attention;
		return false;
	}
	var list=new Array() ;
	for (i=0; i<frm.elements.length; i++){
	
		if(frm.elements[i].type=="checkbox") {
			if(frm.elements[i].checked==true) {
				list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
			} 
		} else {
			list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
		}
	}
	var result1=list.join() //creates the String "Apple,Oranges"
	var result2=list.join("&") //creates the String "Apple*Oranges"
	url="../saladworks_inc/ajax.inc.php?type=gift_card_add&"+result2;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){window.location='/'+document.getElementById('path').value;
		}
	ajax.runAJAX();		// Execute AJAX function
	return false;
	
}

function delete_gift_card(id) {
	var ajax = new sack();
	var x= confirm("Are you sure you want to remove this gift card?");
	if(x) {
	url="../saladworks_inc/ajax.inc.php?type=gift_card_remove&id="+id;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		window.location='/'+ajax.response;
		/*if(document.getElementById('row').value) {
			document.getElementById('card_table').deleteRow(document.getElementById('row').value);
		}
		if(ajax.response =='' || ajax.response =='0.00') {
			document.getElementById('ttcost').innerHTML='';	
			document.getElementById(id).style.display='none';
		} else {
			document.getElementById('ttcost').innerHTML='$'+ajax.response;	
		}
		addRowListeners();*/
		}
	ajax.runAJAX();		// Execute AJAX function
	}
}

function insRow(id,response){
	document.getElementById('card_items').innerHTML=response;
	/*
	var data=response.split("@");
		document.getElementById(id).style.display='inline';
		var rw=2;
		var txt="<a href=\"javascript:void(edit_gift_card('"+data[0]+"'));\">Edit</a>";
		var rmv="<a href=\"javascript:void(delete_gift_card('"+data[0]+"'));\">x</a>";
		if(document.getElementById('row').value) {
			document.getElementById(id).deleteRow(document.getElementById('row').value);
			var rw=document.getElementById('row').value;
		}
		var x=document.getElementById(id).insertRow(rw);
		var a=x.insertCell(0);
		var b=x.insertCell(1);
		var c=x.insertCell(2);
		//var d=x.insertCell(3);
		var e=x.insertCell(3);
		var f=x.insertCell(4);
		var g=x.insertCell(5);
		var h=x.insertCell(6);
		a.innerHTML=data[1];
		b.innerHTML=data[2];
		c.innerHTML='$'+data[3];
		//d.innerHTML='$'+data[3];
		e.innerHTML=data[4];
		f.innerHTML='$'+data[5];
		g.innerHTML=txt;
		h.innerHTML=rmv;
		document.getElementById('ttcost').innerHTML='$'+data[6];
		purge(document.getElementById(id));
		*/
	addRowListeners();
}

function addRowListeners() {
	document.getElementById('row').value='';
	function showRowNum() {
		if('number' == typeof this.rowIndex) {
		document.getElementById('row').value=this.rowIndex;
		}
	}
	if(document.getElementById) {
		var table = document.getElementById('card_table'), rows;
		if(table && (rows = table.rows)) {
			for(var i = 0, n = rows.length; i < n; ++i) {
				rows[i].onclick = showRowNum;
			}
		}
	}
}

function edit_card_message(id) {
	messageObj.setShadowOffset(5);	// Large shadow
	url="../saladworks_inc/ajax.inc.php?type=gift_card_edit&id="+id;
	display_window(url,700,420);
}

function edit_gift_card(id) {
	var ajax = new sack();
	url="../saladworks_inc/ajax.inc.php?type=gift_card_get&id="+id;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		var data=ajax.response.split("@");
		document.getElementById('card_o_id').value=data[0];
		document.getElementById('card_id').value=data[1];
		document.getElementById('total').value=data[4];
		for (i=0;i<document.forms['standard'].elements['shipping'].length;i++){
			if (document.forms['standard'].elements['shipping'][i].value==data[7]) {
				document.forms['standard'].elements['shipping'][i].checked=true;
			}
		}
		for (i=0;i<document.forms['standard'].elements['amount'].length;i++){
			if (document.forms['standard'].elements['amount'][i].value==data[5]) {
				document.forms['standard'].elements['amount'][i].selected=true;
			}
		}
		document.getElementById('message').value=data[6];
		document.getElementById('ship_fname').value=data[8];
		document.getElementById('ship_lname').value=data[9];
		document.getElementById('ship_company').value=data[10];
		document.getElementById('ship_phone').value=data[11];
		document.getElementById('city').value=data[12];
		document.getElementById('state').value=data[13];
		document.getElementById('zipcode').value=data[14];
		document.getElementById('address').value=data[15];
		document.getElementById('address1').value=data[16];
		if(document.getElementById('card_image')) {
			var im=document.getElementById('card_image');
		} else {
			var im=document.getElementById('card_single_image');
		}
		im.innerHTML='<img src="/images/gift_cards/large/'+data[3]+'" alt="'+data[2]+'" />';
		im.innerHTML+='<br /><strong>'+data[2]+'</strong>';
		if(document.getElementById('card')) {
			var rd=document.getElementById('card');
			rd.innerHTML=data[2];
			purge(rd);
		}
		purge(im);
		;}
		//document.getElementById('editcard').submit();
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function order_location(id) {
	var ajax = new sack();
	//url ="reports.php?report_type=order_location&item="+id;
	url ="../saladworks_inc/ajax.inc.php?type=order_location&items="+id;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		//alert(ajax.response);
		window.location=ajax.response;
		//document.getElementById('location').value=id;
		//document.getElementById('order').submit();
		; }
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function quick_menu(id) {
	var ajax = new sack();
	url="../saladworks_inc/ajax.inc.php?type=quick_menu&id="+id;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){window.location=(ajax.response); }
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function open_food(id) {
	messageObj.setShadowOffset(5);	// Large shadow
	url="../saladworks_inc/ajax.inc.php?type=show_food&id="+id;
	display_window(url,520,400);
}

function nutrition_board(id) {
	messageObj.setShadowOffset(5);	// Large shadow
	url="../saladworks_inc/ajax.inc.php?type=nutrition_board&id="+id;
	display_window(url,241,511);
}

function display_window(url,w,h){
	messageObj.setSource(url);
	messageObj.setCssClassMessageBox(false);
	messageObj.setSize(w,h);
	messageObj.setShadowDivVisible(true);	// Enable shadow for these boxes
	messageObj.display();
	return false;
}


function set_login() {
	messageObj.setShadowOffset(5);	// Large shadow
	url="../saladworks_inc/ajax.inc.php?type=login_form";
	display_window(url,420,230);
}

function webinar_signup() {
	messageObj.setShadowOffset(5);	// Large shadow
	url="../saladworks_inc/ajax.inc.php?type=webinar_signup";
	display_window(url,415,285);
}

function brochure() {
saladworks=open('/franchisebrochure.html',"saladworks","scrollbars=no,toolbar=no,location=0,directories=no,menu bar=no,resizable=no,status=no,width=1252,height=676,left=200,top=150");
}

function location_map() {
	messageObj.setShadowOffset(5);	// Large shadow
	url="../saladworks_inc/ajax.inc.php?type=loc_image";
	display_window(url,500,500);
}

function closeMessage() {messageObj.close();}

function check_webinar(frm) {
	var ajax = new sack();
	var list=new Array() ;
	for (i=0; i<frm.elements.length; i++){
	
		if(frm.elements[i].type=="checkbox") {
			if(frm.elements[i].checked==true) {
				list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
			} 
		} else {
			list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
		}
	}
	var result1=list.join() //creates the String "Apple,Oranges"
	var result2=list.join("&") //creates the String "Apple*Oranges"
	url ="../saladworks_inc/ajax.inc.php?type=webinar_signup"+"&"+result2;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){give_notice(ajax.response);}
	document.getElementById('sdata').innerHTML='<p>&nbsp;</p><h3>Registering Data - please wait...</h3>' ;
	ajax.runAJAX();		// Execute AJAX function
	return false;
	}

function give_notice(response) {
	document.getElementById('sdata').innerHTML=response;
}

function check_email_login(frm) {
	var ajax = new sack();
	var list=new Array() ;
	for (i=0; i<frm.elements.length; i++){
	
		if(frm.elements[i].type=="checkbox") {
			if(frm.elements[i].checked==true) {
				list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
			} 
		} else {
			list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
		}
	}
	var result1=list.join() //creates the String "Apple,Oranges"
	var result2=list.join("&") //creates the String "Apple*Oranges"
	url ="../saladworks_inc/ajax.inc.php?type=check_email_login"+"&"+result2;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){report_login(ajax.response);}
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function report_login(response) {
	alert(response);	
}

function guest_login() {
	var ajax = new sack();
	url="../saladworks_inc/ajax.inc.php?type=guest_login";
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){window.location=ajax.response;}
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function change_extra(msg) {
	var ajax = new sack();
	var v=document.getElementById(msg).value;
	url="../saladworks_inc/ajax.inc.php?type=change_extra&id="+v;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){return false;}
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function default_location(id,name) {
	var ajax = new sack();
	url="../saladworks_inc/ajax.inc.php?type=default_location&loc="+id;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		alert(name+' has been set as your Default Saladworks Location.\r\nYou are now being redirected.');
		window.location='/menu';
		}
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function change_base(id) {
	//clicker();
	var ajax = new sack();
	url ="../saladworks_inc/ajax.inc.php?type=change_base&base="+id;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		if(ajax.response != 'no' && document.getElementById('side_'+id).checked==true) {
			document.getElementById('base').src=ajax.response;
		};
	}
	ajax.runAJAX();		// Execute AJAX function
	//setTimeout("clicker()",400);
	return false;
}


function clear_side(cat) {
//	clicker();
	var cost_a = document.getElementById('it_cost');
	var cost_b = document.getElementById('bit_cost');
	var cost_c = document.getElementById('abit_cost');
	var cost_d = document.getElementById('fd_order');
	var ptot=parseFloat(document.getElementById('group_'+cat).value);
	var totl=document.getElementById('group_'+cat);
	var side_cost=parseFloat(document.getElementById('total_'+cat).value);
	var formObject = document.forms['geoform'].elements['side['+cat+']'];
	var cost_e= document.getElementById('food_order');
	ptot=Number(ptot);
	side_cost=Number(side_cost);
	var ad=0;
	if(isNaN(ptot)) {
		ptot=1;	
	}
	if(isNaN(side_cost)) {
		var side_cost=0;
	}
	if(ptot==1) {
		var va=parseFloat(cost_d.value)-parseFloat(side_cost);
		var rs =va.toFixed(2);
		cost_a.innerHTML = rs;
		cost_b.innerHTML = rs;
		cost_c.innerHTML = rs;
		if(isNaN(cost_d.value)) {
			cost_d.value = cost_e.value;
		} else {
			cost_d.value = rs;
		}
		totl.value=0;
	}
//	setTimeout("clicker()",400);
}

function update_side(cat) {
//	clicker();
	var cost_a = document.getElementById('it_cost');
	var cost_b = document.getElementById('bit_cost');
	var cost_c = document.getElementById('abit_cost');
	var cost_d = document.getElementById('fd_order');
	var ptot=parseFloat(document.getElementById('group_'+cat).value);
	var totl=document.getElementById('group_'+cat);
	var side_cost=parseFloat(document.getElementById('total_'+cat).value);
	var formObject = document.forms['geoform'].elements['side['+cat+']'];
	var cost_e= document.getElementById('food_order');
	var ad=0;
	ptot=Number(ptot);
	side_cost=Number(side_cost);
	if(isNaN(ptot)) {
		ptot=0;	
	}
	if(isNaN(side_cost)) {
		var side_cost=0;
	}
	if(ptot==0) {
		var va=parseFloat(cost_d.value)+parseFloat(side_cost);
		if(isNaN(ptot)) { pt=0;}
		var rs =va.toFixed(2);
		cost_a.innerHTML = rs;
		cost_b.innerHTML = rs;
		cost_c.innerHTML = rs;
		cost_d.value = rs;
		totl.value=1;
	}
//	setTimeout("clicker()",400);
}

function check_calc(cat) {
	//clicker();
	var nutrients= new Array("cal","protein","carb","fat","sodium","fiber","sugar","chol","satfat");
	var ajax = new sack();
	var formObject = document.forms['geoform'].elements;
	var mi=parseFloat(document.getElementById('mi').value);
	var mc=Number(document.getElementById('mc').value);
	var cost_a = document.getElementById('it_cost');
	var cost_b = document.getElementById('bit_cost');
	var cost_c = document.getElementById('abit_cost');
	var cost_d = document.getElementById('fd_order');
	var cost_f = document.getElementById('cd_order');
	var cost_e= document.getElementById('food_order');
	var ct=parseFloat(document.getElementById('ac_group_'+cat).value);
	var ptot=parseFloat(document.getElementById('group_'+cat).value);
	var totl=document.getElementById('group_'+cat);
	var side_cost=parseFloat(document.getElementById('total_'+cat).value);
	var total=0;
	var x=0;
	var m=0;
	var list=new Array() ;
		for (i=0;i<formObject.length;i++) {
			if(formObject[i].value == 0) {
				formObject[i].value='';
			}
			if(formObject[i].className == 'field-ops' && formObject[i].checked!=false) {
				list[x] =escape(formObject[i].value);
				if(formObject[i].alt=='side['+cat+']') {
					m++;
				}
				x++;
			}
		}
	ptot=Number(ptot);
	side_cost=Number(side_cost);
	mi=Number(mi);
	if(isNaN(m)) {m=Number(0);}
	if(isNaN(ct)) {ct=Number(0);}
	if(isNaN(pt)) {pt=Number(0);}
	if(isNaN(ptot)) {ptot=Number(0)}
	if(isNaN(side_cost)) { side_cost=0;}
	if(cat != 8) {
		if(x > mi) {
			var pt=ptot+1;
			var pr=pt.toFixed(2);
			if(isNaN(ct)) { ct=Number(0);}
			if(isNaN(pt)) { pt=Number(0);}
			if(isNaN(m)) { m=Number(0);}
			if(isNaN(side_cost)) { side_cost=0;}
			//alert('A::::MC='+mc+' X='+x+' MI=='+mi);
			if(mc<x) {
				var va=parseFloat(cost_d.value)+parseFloat(side_cost);
			} else {
				var va=parseFloat(cost_d.value)-parseFloat(side_cost);
			}
			var rs =va.toFixed(2);
			cost_a.innerHTML = rs;
			cost_b.innerHTML = rs;
			cost_c.innerHTML = rs;
			cost_d.value = rs;
		} else {
			var pt=ptot-1;
			var pr=pt.toFixed(2);
			if(isNaN(side_cost)) {
				var side_cost=0;	
			}
			var va=parseFloat(cost_d.value)-parseFloat(side_cost);
			//alert('B-----b'+pt+'='+pr+'='+side_cost);
			if(isNaN(ct)) { ct=0;}
			if(cost_e.value <= va) {
				var rs =va.toFixed(2);
				if(isNaN(rs)) {
					var rs = cost_e.value;
				}
				cost_a.innerHTML = rs;
				cost_b.innerHTML = rs;
				cost_c.innerHTML = rs;
				cost_d.value = rs;
			}
		}
		if(pt < 0) {
			pt=0;	
		}
		totl.value=pt;
		document.getElementById('mc').value=x;
	}
	var result2=list.join("|"); //creates the String "Apple*Oranges"
	url ="../saladworks_inc/ajax.inc.php?type=new_calc&items="+result2;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		var r=ajax.response.split("@");
		for(xx=0;xx<nutrients.length;xx++){
			var st = nutrients[xx];
			if(document.getElementById(st+'_total')) {
				document.getElementById(st+'_total').innerHTML = parseFloat(r[xx]);
			}
		}
		var im=r[9].split("|");
		document.getElementById('slide_image').innerHTML='';
			for (i=0;i<im.length;i++) {
				if(im[i]!='') {
					document.getElementById('slide_image').innerHTML+=' <img class="side-imagelist" id="image_'+im[i]+'" src="/images/sides/'+im[i]+'"" />';
				}
			}
		};
	ajax.runAJAX();		// Execute AJAX function
	purge(document.getElementById('slide_image'));
//	setTimeout("clicker()",400);
	return false;
}

function clicker(){
	var thediv=document.getElementById('displaybox');
	if(thediv.style.display == "none"){
		thediv.style.display = "";
	}else{
		thediv.style.display = "none";
		thediv.innerHTML = '';
	}
	return false;
}
function check_delivery() {
	if(document.getElementById('pay_at_pickup').checked==true) {
		document.getElementById('order-type').selectedIndex==0;
		document.getElementById('pt').style.display='inline';
		document.getElementById('dt').style.display='none';
	}
}

function order_type(delpk) {
	if(document.getElementById('pt') && document.getElementById('dt')) {
		if(delpk=='pt'){
			document.getElementById('pt').style.display='inline';
			document.getElementById('dt').style.display='none';
		} else {
			document.getElementById('dt').style.display='inline';
			document.getElementById('pt').style.display='none';
		}
	}
}

function change_calculator() {
	var t = document.getElementById('product_id').value;
	var ajax = new sack();
	url="../saladworks_inc/ajax.inc.php?type=change_item&item="+t;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		 //document.getElementById('geoform').submit();
		 window.location.reload();
		if(ajax.response==1) {
		 //window.location='/menu/nutrition'; 
		};
	}
	ajax.runAJAX();		// Execute AJAX function
		return false;
}

function change_order() {
	var t = document.getElementById('product_id').value;
	var ajax = new sack();
	url="../saladworks_inc/ajax.inc.php?type=change_item&item="+t;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		if(ajax.response==1) {
		 window.location='/order_online'; 	
		};
	}
	ajax.runAJAX();		// Execute AJAX function
		return false;
}

function remove_item(id,itemname) {
 var x=window.confirm('By clicking "OK" you will remove the '+itemname+' from the menu.\r\nDo you wish to Continue?');
 	if(x) {
	var ajax = new sack();
	url="../saladworks_inc/ajax.inc.php?type=remove_cart_item&item="+id;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		if(ajax.response==1) {
		 window.location='/order_online/fresh_cart'; 	
		} else {
			alert(ajax.response);	
		};
	}
	ajax.runAJAX();		// Execute AJAX function
		return false;
	}	
}

function user_profile(tag,v) {
	messageObj.setShadowOffset(5);	// Large shadow
	url="../saladworks_inc/ajax.inc.php?type=user_manage_profile&item="+tag+"&data="+v;
	display_window(url,500,500);
}

function order_user_profile(tag,v) {
	messageObj.setShadowOffset(5);	// Large shadow
	url="../saladworks_inc/ajax.inc.php?type=user_order_check&item="+tag+"&data="+v;
	display_window(url,500,500);
}

function user_order_check(tag) {
	messageObj.setShadowOffset(5);	// Large shadow
	url="../saladworks_inc/ajax.inc.php?type=user_order_check&item="+tag;
	display_window(url,500,500);
}

function add_myfav(tp,v,fav) {
	var ajax = new sack();
	var cost=document.getElementById('fd_order').value;
	url="../saladworks_inc/ajax.inc.php?type=my_fav&item="+tp+"&ordertype="+v+"&cost="+cost;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		alert(ajax.response);
		document.getElementById(fav).innerHTML='My Favorite!';
		purge(fav);
	}
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function open_my_fav(fid) {
	messageObj.setShadowOffset(5);	// Large shadow
	url="../saladworks_inc/ajax.inc.php?type=open_my_fav&item="+fid;
	display_window(url,500,500);
}

function order_fav_type() {
	var fav=document.getElementById('fav_id').value;
	if(document.getElementById('form').value=='remove') {
		var x= confirm("Are you sure you want to remove this item from your Favorites?");
		if(x) {
			document.getElementById('userform').action='/my_account';
			return true;
		} else {
			closeMessage();
			return false;	
		}
	} else {
		var ajax = new sack();
		url="../saladworks_inc/ajax.inc.php?type=add_my_fav&item="+fav;
		ajax.requestFile = url;	// Specifying which file to get
		ajax.onCompletion = function(){
			if(ajax.response==1) {
		 		window.location='/order_online/fresh_cart'; 	
			} else {
				alert(ajax.response);	
			}
		}
		ajax.runAJAX();		// Execute AJAX function
		return false;
	}
}


function user_manage_order(frm) {
	var ajax = new sack();
	var list=new Array() ;
	for (i=0; i<frm.elements.length; i++){
	
		if(frm.elements[i].type=="checkbox") {
			if(frm.elements[i].checked==true) {
				list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
			} 
		} else {
			list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
		}
	}
	var result1=list.join()
	var result2=list.join("&")
	url="../saladworks_inc/ajax.inc.php?type=user_manage_order_update&"+result2;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		var data=ajax.response.split("@");
		if(data[0]==1) {
			//alert(ajax.response);
			if(data[1]=='address') {
				if(document.getElementById(data[2])) {
					document.getElementById(data[2]).checked=false;
				}
				document.getElementById('del_'+data[2]).innerHTML=data[3];
				if(document.getElementById('no_cc')) {
					document.getElementById('no_cc').style.display='none';
				}
			} else {
				alert(data[3]);
			}
			closeMessage();
		} else {
			alert(ajax.response);	
		};
	}
	ajax.runAJAX();		// Execute AJAX function
	return false;
	purge(data);
	purge(result2);
}

function user_manage_form(frm) {
	var ajax = new sack();
	var list=new Array() ;
	for (i=0; i<frm.elements.length; i++){
	
		if(frm.elements[i].type=="checkbox") {
			if(frm.elements[i].checked==true) {
				list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
			} 
		} else {
			list[i] = frm.elements[i].name+"="+escape(frm.elements[i].value);
		}
	}
	var result1=list.join()
	var result2=list.join("&")
	url="../saladworks_inc/ajax.inc.php?type=user_manage_form&"+result2;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		if(ajax.response==1) {
		 window.location='/my_account'; 	
		} else {
			alert(ajax.response);	
		};
	}
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function pay_later() {
	var ajax = new sack();
	if(document.getElementById('pay_at_pickup').checked==true) {
		var pay_now='pay_later';					  
	} else {
		var pay_now='';					  
	}
	url="../saladworks_inc/ajax.inc.php?type=pay_later&item="+pay_now;
	ajax.requestFile = url;	// Specifying which file to get
	ajax.onCompletion = function(){
		if(ajax.response!=1) {
			alert(ajax.response);	
		};
	}
	ajax.runAJAX();		// Execute AJAX function
	return false;
}

function form_check() {
   var HOLT = "#ee8120";
	if(!document.geoform.fname.value) {
		alert("Please enter your first name.");
		document.geoform.fname.focus();
		document.geoform.fname.style.background=HOLT;
		return false;
	}
   if(!document.geoform.lname.value) {
		alert("Please enter your last name.");
		document.geoform.lname.focus();
		document.geoform.lname.style.background=HOLT;
		return false;
    }
    if(!document.geoform.state.value) {
		alert("Please select a state.");
		document.geoform.state.focus();
		document.geoform.state.style.background=HOLT;
		return false;
    }
   if(!document.geoform.email.value) {
		alert("Please enter your email.");
		document.geoform.email.focus();
		document.geoform.email.style.background=HOLT;
		return false;
    }
   if(document.geoform.confirm_email.value != document.geoform.email.value) {
		alert("Please confirm your email.");
		document.geoform.confirm_email.focus();
		document.geoform.confirm_email.style.background=HOLT;
		return false;
    }
   if(!document.geoform.home_phone.value) {
		alert("Please enter your Phone Number.");
		document.geoform.home_phone.focus();
		document.geoform.home_phone.style.background=HOLT;
		return false;
    }
    if (!email_syntax(document.geoform.email.value)) {
		alert("Invalid email, please correct.");
		document.geoform.email.focus();
		document.geoform.email.style.background=HOLT;
		return false;
    }
    return true;
}

function email_syntax(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	if (str.indexOf(" ")!=-1){
		return false
	}
 return true;				
}


function purge(d) {
    var a = d.attributes, i, l, n;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            n = a[i].name;
            if (typeof d[n] === 'function') {
                d[n] = null;
            }
        }
    }
    a = d.childNodes;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            purge(d.childNodes[i]);
        }
    }
}

