/*
Code by Robertino Darmati <www.on-line.hr>
*/
verzija = function() {
	$("ver").innerHTML = "v.0.8";
}
/* CONFIGURATION */ 
//string za markere: class (0, 1, 2, ili 3) | icoW (širina ikone) | icoH (visina ikone) | shdwW (širina sjene) | shdwH (visina sjene) | icoAnX | icoAnY (sidro ikone X i Y) | nfoAnX | nfoAnY (sidro info balona X i Y) | icon (naziv slike ikone) | shadow (naziv slike sjene)
var colors = new Array('','#55b1b0','#ff9451','#ffffff','#ffd303','#85ff03','#03f0ff','#034aff','#e403ff','#ff0303','#669933','#660033','#CC0033','#CC0033','#CC9999','#CC6600','#6666FF','#FFFF00','#CCFFFF');
var iconsLocation = "http://www.foodrose.com/images/markers/";
var imgLocation = "http://www.foodrose.com/images/";

var newName = "";
var color = "";
rndNo = function(i){
	var n = Math.random();
	n = n * i;
	return Math.ceil(n);
};

gimmeColor = function(){
	var color = colors[rndNo(18)];
	return color;
}

gmap = function(){	
	if (GBrowserIsCompatible()) {
		var circle;
		var circleIndex;
		var rad;
		var angle;
		var polyg = new Array();
		var tport = new Array();
		var tportNoloc = new Array();
		var allgmarkers = [];
		var mE = 0;
		var mEn = 1;
		var cntr = 0;
		var cntrNoloc = 0;
		var nMarkerEvent;
		var ixIntNoloc = new Array();
		var circleExist;
		var mode = 0;
		var idx = 0;
		
		Array.prototype.sum = function() {
			return (! this.length) ? 0 : this.slice(1).sum() + ((typeof this[0] == 'number') ? this[0] : 0);
		};
		
		if(document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#SVG","1.1")){
			_mSvgEnabled = true;
			_mSvgForced = true; 
		} 
		
		var map = new GMap2(document.getElementById("map"));
		map.addMapType(G_PHYSICAL_MAP);
		map.setCenter(new GLatLng(44.115198, 16.116943), 7, G_PHYSICAL_MAP);
		map.addControl(new GMapTypeControl());
		map.addControl(new GLargeMapControl());
		map.enableScrollWheelZoom();
		map.disableDoubleClickZoom();
		sateliteProj = G_SATELLITE_MAP.getProjection();
		var mm = new MarkerManager(map, {trackMarkers:true});
		
// MARKERI ///////////////////////////////////////////////////////////////////////////////////////////		
		createMarkerN = function(point, html){
			var marker = new PdMarker(point, {
				draggable: true,
				id: cntr
			});
			nMarkerEvent = GEvent.addListener(marker, "click", function() {
				map.openInfoWindow(marker.getLatLng(), html);
			});
			GEvent.addListener(marker, "dragend", function(){
				//fillTport(marker);
				//updateRose();
				var id = marker.id;
				updateQty(id); 
			});
			return marker;
		}
		createMarkerDB = function(point,dbIcon){
			dbI = dbIcon.split("|");
			if (dbI[0]==1) {
				var dbIconParams = new GIcon();
				dbIconParams.iconSize=new GSize(dbI[1],dbI[2]);
				dbIconParams.shadowSize=new GSize(dbI[3],dbI[4]);
				dbIconParams.iconAnchor=new GPoint(dbI[5],dbI[6]);
				dbIconParams.infoWindowAnchor=new GPoint(dbI[7],dbI[8]);
				var dbIcon = new GIcon(dbIconParams, iconsLocation+dbI[9], null, iconsLocation+dbI[10]);
			}
			else {
				var dbIcon = foodIco;
			}
			var marker = new PdMarker(point, {
				draggable: false,
				icon: dbIcon,
				id: cntr
			});
			return marker;
		}
//////////////////////////////////////////////////////////////////////////////////////////////////////
		mFromDB = function(p,p1,dbIcon){
			if (cntr > 0) {
				if (mEn > 1) {
					map.removeOverlay(nMarker);
				}
				var pt = new GLatLng(parseFloat(p),parseFloat(p1));
				dbMarker = createMarkerDB(pt,dbIcon);
				map.addOverlay(dbMarker);
				//return mE;
			}
		}
		GEvent.addListener(map, "dblclick", function(marker, point){
			if(mode==1) {
				var odgovor = confirm("Ukoliko želite kreirati novu ružu jela kliknite OK");
				if(odgovor){
					document.location='/';
					mode=0;
					return false;
				} else { return false; }
			}
			if (cntr > 0) {
				if (mEn > 1) {
					map.removeOverlay(nMarker);
				}
				nMarker = createMarkerN(point, CustomInfoHtml(cntr));
				map.addOverlay(nMarker);
				nMarker.disableDragging();
				
				newName = "";
				//$("save_img").src = imgLocation + "save.png";
				//$("refresh_img").src = imgLocation + "refresh.png";

				GEvent.trigger(nMarker, "click");
				mEn = 2;
				//return mE;
/////////////////////////////////////////////////////////////////////////////////////////////////////				
			} else if(cntr === 0){
				uMarker = new PdMarker(point, {
					draggable: true,
					id: "startMarker",
					icon: startIco
				});
				
				map.addOverlay(uMarker);
				uMarker.enableDragging();
				
				GEvent.addListener(uMarker, "click", function() {
					map.openInfoWindow(uMarker.getLatLng(), centarInfoHtml());
				});
				
				GEvent.trigger(uMarker, "click");
				
				//Step forward in wizard
				$("st1").setStyle({ color: "#cccccc" });
				$("st2").setStyle({ color: "#2a6b6a" });
				$("ingN").setStyle({ display: "block" });
				
				GEvent.addListener(uMarker, 'dragend', function(){ updateRose();});
				cntr = 1;
				if (parseInt($('toolbar').getStyle('width')) < 1) {
					toggleToolbar();
				}
				showPG('foodroseCreate');
				//return mE;
			} else {
				alert("Već postoji!");
			}
		});
		
 		var baseIcon = new GIcon();
		baseIcon.iconSize=new GSize(20,20);
		baseIcon.iconAnchor=new GPoint(10,10);
		baseIcon.infoWindowAnchor=new GPoint(10,10);
		
		var startIco = new GIcon(baseIcon, iconsLocation+"crosshire.png", null);

		var foodIcon = new GIcon();
		foodIcon.iconSize=new GSize(18,31);
		foodIcon.shadowSize=new GSize(32,32);
		foodIcon.iconAnchor=new GPoint(5,31);
		foodIcon.infoWindowAnchor=new GPoint(5,31);
		var foodIco = new GIcon(foodIcon, iconsLocation+"markera.png", null, iconsLocation+"markera_sjena.png");
		
		var noIconP = new GIcon();
		noIconP.iconSize=new GSize(1,1);
		noIconP.shadowSize=new GSize(1,1);
		noIconP.iconAnchor=new GPoint(1,1);
		noIconP.infoWindowAnchor=new GPoint(1,1);
		var noIcon = new GIcon(noIconP, "/images/ms.png");
		
		clearMarker = function(){
				if(nMarker.getLatLng())
					alert(nMarker.getLatLng());
		}
		
/* ///////////////////////////////////////////////////////////  IZ BAZE  //////////////////////////////////////////////// */		
		populateIng = function(locArr){
			if (mEn > 1) {
				map.closeInfoWindow();
				map.removeOverlay(nMarker);
			}
			var bounds = new GLatLngBounds;
			gmarkers = [];
			ingPt = new Array();
			for(var a=0; a<locArr.length-1; a++){
				locArrSplitted=locArr[a].split(',');
				ingPt[a] = new GLatLng(parseFloat(locArrSplitted[0]),parseFloat(locArrSplitted[1]));
				bounds.extend(ingPt[a]);
				ingMarker = createMarker(ingPt[a],infoHtml(locArrSplitted[2],locArrSplitted[3],a,locArrSplitted[0],locArrSplitted[1],locArrSplitted[7]),locArrSplitted[7]);
				map.addOverlay(ingMarker);
			}
	        mm.addMarkers(gmarkers,0,17);
	        mm.refresh();
			
			if(gmarkers.length<=1) var zoom = map.getBoundsZoomLevel(bounds) - 5; 
			else var zoom = map.getBoundsZoomLevel(bounds) - 1;
			map.setZoom(zoom);
			map.setCenter(bounds.getCenter());
		}						
		
		function createMarker(point,html,dbIcon) {
			dbI = dbIcon.split("|");
			if (dbI[0]>0) {
				var dbIconParams = new GIcon();
				dbIconParams.iconSize=new GSize(dbI[1],dbI[2]);
				dbIconParams.shadowSize=new GSize(dbI[3],dbI[4]);
				dbIconParams.iconAnchor=new GPoint(dbI[5],dbI[6]);
				dbIconParams.infoWindowAnchor=new GPoint(dbI[7],dbI[8]);
				var dbIcon = new GIcon(dbIconParams, iconsLocation+dbI[9], null, iconsLocation+dbI[10]);
			}
			else {
				var dbIcon = foodIco;
			}
			var marker = new GMarker(point, {
				icon: dbIcon
			});
			var i = gmarkers.length;
			gmarkers.push(marker);
			allgmarkers.push(marker);
			GEvent.addListener(marker, "click", function() {
				map.openInfoWindow(marker.getLatLng(), html);
			});
			return marker;
		}
		
		addNolocMarker = function(qty){
			var noloc = Array();
			noloc['lat']=uMarker.getLatLng().lat().toFixed(6) * (-1);
			noloc['lng']=(180 - uMarker.getLatLng().lng()).toFixed(6);
			point = new GLatLng(noloc['lat'],noloc['lng']);
						
			var marker = new PdMarker(point, {
				id: cntr,
				icon: noIcon
			});
			map.addOverlay(marker);
			marker.setId(cntr);
			fillTport(marker,qty,1)
		}

		selectIng = function(){ /////////////////////////////////////////////// Nakon unosa količine u balonu namirnice
			var f = $('selectIngForm').serialize(true);
			if (f.Sqty) {
				var markerID = f.SingId;
				var ingName = document.createElement("input");
				ingName.setAttribute("type", "input");
				ingName.setAttribute("name", f.SingId);
				ingName.setAttribute("id", "ingName_" + cntr);
				ingName.setAttribute("value", f.SingName);
				//ingName.setAttribute("style", "font-size:10px");
				//ingName.setAttribute("style", "background-color:"+color);
				ingName.setAttribute("class", "frmMealElement");
				ingName.setAttribute("size", "23");
				/*ingName.setAttribute("onmouseover", "selectMarker("+markerID+","+cntr+")");
				ingName.setAttribute("onmouseout", "deselectMarker("+markerID+")");*/
				/*ingName.setAttribute("disabled", "false");*/
				
				var ingQty = document.createElement("input");
				ingQty.setAttribute("type", "input");
				ingQty.setAttribute("name", cntr + "ingQ");
				ingQty.setAttribute("id", "ingQty_" + cntr);
				ingQty.setAttribute("value", f.Sqty + " g.");
				ingQty.setAttribute("style", "font-size:10px; text-align:right;");
				ingQty.setAttribute("size", "5");
				ingQty.setAttribute("class", "frmMealElementQ");
				ingQty.setAttribute("onchange", "updateQty(" + cntr + ")");
				
				var delX = document.createElement("img");
				delX.setAttribute("src","/images/delXX.png");
				delX.setAttribute("id", "delX_" + cntr);
				delX.style.cursor = "pointer";
				delX.setAttribute("title", "Obriši namirnicu");
				delX.setAttribute("onclick", "deleteMarker("+cntr+","+markerID+")");
				
				var rowDiv = document.createElement("div");
				rowDiv.id = "rowDiv_" + cntr;
				rowDiv.setAttribute("style", "border-bottom:1px #57b2b1 dashed;padding:2px 0 2px 0;");
				var NcellDiv = document.createElement("div");
				NcellDiv.id = "NcellDiv_" + cntr;
				NcellDiv.setAttribute("style", "width:140px;display:inline;");
				var QcellDiv = document.createElement("div");
				QcellDiv.id = "QcellDiv_" + cntr;
				QcellDiv.setAttribute("style", "text-align:right;display:inline;");
				var XcellDiv = document.createElement("div");
				XcellDiv.id = "XcellDiv_" + cntr;
				XcellDiv.setAttribute("style", "text-align:right;display:inline;");
				var CcellDiv = document.createElement("div");
				CcellDiv.id = "CcellDiv_" + cntr;
				CcellDiv.setAttribute("style", "text-align:right;display:inline;width:10px;");
				
				var row = $("frmMeal").appendChild(rowDiv);
				Ncell = row.appendChild(NcellDiv);
				Qcell = row.appendChild(QcellDiv);
				Ccell = row.appendChild(CcellDiv);
				Xcell = row.appendChild(XcellDiv);
				Ncell.appendChild(ingName);
				Qcell.appendChild(ingQty);
				Xcell.appendChild(delX);
				
				if (f.mType == "ingMarker") {
					if (allgmarkers.length > 0) {
						for (var a = 0; a < allgmarkers.length; a++) {
							mm.removeMarker(allgmarkers[a]);
						}
					}
					mFromDB(f.ptLat, f.ptLng,f.mystring);
					fillTport(dbMarker,f.Sqty,0,markerID);
					mEn = 1;
					dbMarker.setTooltip(f.SingName+" - "+f.Sqty + " g.");
					dbMarker.setId(cntr);
					cntr++;
				}
				else {
					if (f.Sqty > 0) 
						nMarker.enableDragging();
						GEvent.removeListener(nMarkerEvent);
						fillTport(nMarker,f.Sqty);
						mEn = 1;
						nMarker.setTooltip(f.SingName +" - "+ f.Sqty + " g.");
						nMarker.setId(markerID);	
						cntr++;				
				}
						
				map.closeInfoWindow();
				//cntr++;
				createRose(uMarker.getLatLng(),color);
			} else if(f.mType == "ingMarker") { 
				map.closeInfoWindow();
			} else {
					map.closeInfoWindow();
					map.removeOverlay(nMarker);
				}
		}
		
		selectNoloc = function(){
			var foo;
			var noloc=1;
			//var markerID = cntrNoloc;
			var ingName = document.createElement("input");
			ingName.setAttribute("type", "input");
			ingName.setAttribute("name", ingName);
			ingName.setAttribute("id", "ingName_" + cntr);
			ingName.setAttribute("value", $("nolocName").value);
			ingName.setAttribute("style", "font-size:10px");
			//ingName.setAttribute("style", "background-color:white");
			ingName.setAttribute("class", "frmMealElement");
			ingName.setAttribute("size", "23");
			
			var ingQty = document.createElement("input");
			ingQty.setAttribute("type", "input");
			ingQty.setAttribute("name", cntrNoloc + "ingQnoloc");
			ingQty.setAttribute("id", "ingQty_" + cntr);
			ingQty.setAttribute("value", $("nolocQty").value + " g.");
			ingQty.setAttribute("style", "font-size:10px; text-align:right;");
			ingQty.setAttribute("size", "5");
			ingQty.setAttribute("class", "frmMealElementQ");
			ingQty.setAttribute("onchange", "updateQty(" + cntr + ")");
			
			var delX = document.createElement("img");
			delX.setAttribute("src","/images/delX.png");
			delX.setAttribute("id", "delX_" + cntr);
			delX.style.cursor = "pointer";
			delX.setAttribute("title", "Obriši namirnicu");
			delX.setAttribute("onclick", "deleteMarkerNoloc(" + cntr + ")");
			
			var rowDiv = document.createElement("div");
			rowDiv.id = "rowDiv_" + cntr;
			rowDiv.setAttribute("style", "border-bottom:1px #57b2b1 dashed;padding:2px 0 2px 0;");
			var NcellDiv = document.createElement("div");
			NcellDiv.id = "NcellDiv_" + cntr;
			NcellDiv.setAttribute("style", "width:140px;display:inline;");
			var QcellDiv = document.createElement("div");
			QcellDiv.id = "QcellDiv_" + cntr;
			QcellDiv.setAttribute("style", "text-align:right;display:inline;");
			var XcellDiv = document.createElement("div");
			XcellDiv.id = "XcellDiv_" + cntr;
			XcellDiv.setAttribute("style", "text-align:right;display:inline;padding-left:20px;");
			var CcellDiv = document.createElement("div");
			CcellDiv.id = "CcellDiv_" + cntr;
			CcellDiv.setAttribute("style", "text-align:right;display:inline;width:10px;");
			
			var row = $("frmMeal").appendChild(rowDiv);
			Ncell = row.appendChild(NcellDiv);
			Qcell = row.appendChild(QcellDiv);
			Xcell = row.appendChild(XcellDiv);
			Ncell.appendChild(ingName);
			Qcell.appendChild(ingQty);
			Xcell.appendChild(delX);
			 
			addNolocMarker($("nolocQty").value);
			$("nolocName").value = "";
			$("nolocQty").value = "";
			Effect.SwitchOff('nolocDiv');
			cntr++;
			createRose(uMarker.getLatLng(),color);
		}
		
		selectMeal = function(){
			var f = $('mealFrm').serialize(true);
			uMarker.setTooltip(f.mealName);
			map.closeInfoWindow();
			
			var titleEl = document.createElement("h4");
			titleEl.id = "_titleEl";
			titleEl.style.color = "#ffffff";
			titleEl.style.padding = "0 0 2px 5px";
			
			$("frmMeal").appendChild(titleEl);
			var title = document.createTextNode(f.mealName); 
			$("_titleEl").appendChild(title);
			tport[0] = new Array();
			tport[0]['cname'] = f.mealName;
		}
		
		selectMarker = function(id,cntr){
			var marker = map.getMarkerById(id);
			marker.setTooltip($("ingName_" + id).value + " - " + $("ingQty_" + id).value);
			marker.showTooltip();
			//marker.blink(true,400);
			//setTimeout('deselectMarker('+id+')', 2500);
		}
		
		deselectMarker = function(id){
			var marker = map.getMarkerById(id);
			marker.hideTooltip();
			//marker.blink(false,0);
		}
		
		updateQty = function(id){
			var marker = map.getMarkerById(id);
			var qty = parseInt($('ingQty_' + id).value);
			fillTport(marker,qty);
			updateRose();
		}
		
		updateRose = function(){
			if(cntr>0) createRose(uMarker.getLatLng());
		}
		
		deleteMarker = function(id,marker){
			var marker = map.getMarkerById(id);
			marker.display(false);
			var fM = $("frmMeal");
			var row = $("rowDiv_" + id);
			var meal = $("ingName_" + id); var qty = $("ingQty_" + id); var delX = $("delX_" + id); var NcellDiv = $("NcellDiv_" + id); var QcellDiv = $("QcellDiv_" + id); var CcellDiv = $("CcellDiv_" + id); var XcellDiv = $("XcellDiv_" + id); var rowDiv = $("rowDiv_" + id);
			NcellDiv.removeChild(meal);QcellDiv.removeChild(qty);XcellDiv.removeChild(delX);row.removeChild(NcellDiv);row.removeChild(QcellDiv);row.removeChild(CcellDiv);row.removeChild(XcellDiv);fM.removeChild(rowDiv);
			delete tport[id];
			if(cntr>1)createRose(uMarker.getLatLng());
		}
		
		deleteMarkerNoloc = function(id){
			var fM = $("frmMeal");
			var row = $("rowDiv_" + id);
			var meal = $("ingName_" + id); var qty = $("ingQty_" + id); var delX = $("delX_" + id); var NcellDiv = $("NcellDiv_" + id); var QcellDiv = $("QcellDiv_" + id); var CcellDiv = $("CcellDiv_" + id); var XcellDiv = $("XcellDiv_" + id); var rowDiv = $("rowDiv_" + id);
			NcellDiv.removeChild(meal);QcellDiv.removeChild(qty);XcellDiv.removeChild(delX);row.removeChild(NcellDiv);row.removeChild(QcellDiv);row.removeChild(CcellDiv);row.removeChild(XcellDiv);fM.removeChild(rowDiv);
			delete tport[id];
			updateRose();
		}

		
		fillTport = function(marker,qty,noloc,mid){
			var id = marker.id;
			getAngle = bearing(uMarker.getLatLng(), marker.getLatLng()) * 1;
			getDistance = distance(uMarker.getLatLng(), marker.getLatLng());

			if (id >= 1) {
				$("st3").setStyle({
					color: "#2a6b6a"
				});
				$("rad1").disabled = false;
				$("rad2").disabled = false;
				//$("finish").disabled = false;
			}
			if (!tport[id]) 
				tport[id] = new Array();
			tport[id]['qty'] = qty;
			tport[id]['center'] = uMarker.getLatLng();
			tport[id]['integPt'] = marker.getLatLng();
			tport[id]['distance'] = parseInt(getDistance);
			tport[id]['name'] = $("ingName_" + id).value;
			if (!noloc) {
				if (tport[id]['noloc'] == undefined) {
					tport[id]['noloc'] = 0;
				}
			}
			else 
				tport[id]['noloc'] = noloc;
			if (!mid) {
				if (tport[id]['mid'] == undefined) {
					tport[id]['mid'] = 0;
				}
			}
			else
				tport[id]['mid'] = mid;
		}


//   KRUG   //////////////////////////////////////////////////////////////////////////////////////////////////////

		function doDrawCircle(rad, center, color){
			if (circle) {
				map.removeOverlay(circle);
			}
			var circleRadius = rad;
			//var center = uMarker.getLatLng();			
			var bounds = new GLatLngBounds();			
			var circlePoints = Array();
			
			with (Math) {
				var d = circleRadius/6378.8;	// radians
				
				var lat1 = (PI/180)* center.lat(); // radians
				var lng1 = (PI/180)* center.lng(); // radians
		
				for (var a = 361 ; a > 0 ; a-- ) {
					var tc = (PI/180)*a;
					var y = asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc));
					var dlng = atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(y));
					var x = ((lng1-dlng+PI) % (2*PI)) - PI ; // MOD function
					var point = new GLatLng(parseFloat(y*(180/PI)),parseFloat(x*(180/PI)));
					circlePoints.push(point);
					bounds.extend(point);
				}
		
				if (d < 1.5678565720686044) circle = new GPolygon(circlePoints, '#000000', 2, 1, '#61ff7f', 0);	
				else circle = new GPolygon(circlePoints, '#61ff7f', 2, 1);
				map.addOverlay(circle);
				
//   LATICE    ////////////////////////////////////////////////////////////////////////////////////////////////////////
				//var i=0;
				for(var i=1; i<=cntr; i++){
					if (tport[i] != undefined) {
						var ptArr = Array();
						var MyColor = gimmeColor();
						tport[i]['angle']=bearing(center, tport[i]['integPt']);
						var a = parseInt(tport[i]['angle']);
						var w = parseInt(tport[i]['degree']); //širina trokuta
						var b = parseInt(w / 2);
						if (b > 90) 
							b = 90;
						var pt1 = a + b;
						var pt2 = a - b;
						if (pt1 > 360) 
							pt1 = b - (360 - a);
						if (pt2 < 0) 
							pt2 = 360 - (b - a);
						
						if (pt1 > pt2) { //Zakrivljenost stranice trokuta
							for (var a = pt2; a < pt1; a++) {
								ptArr.push(circlePoints[a]);
							}
						}
						else {
							for (var a = pt2; a < 361; a++) {
								ptArr.push(circlePoints[a]);
							}
							for (var b = 1; b < pt1; b++) {
								ptArr.push(circlePoints[b]);
							}
						}
						ptArr.push(tport[i]['integPt']);
						ptArr.push(circlePoints[pt2]);
						
						
						polyg[i] = new GPolygon(ptArr, "#000000", 2, 1, MyColor, 0.5);
						if (tport[i]['noloc'] == undefined || tport[i]['noloc'] != 1) {
							map.addOverlay(polyg[i]);
							bounds.extend(tport[i]['integPt']);
							/*$("ingName_" + i).setStyle({
								backgroundColor: MyColor,
								'color': "#000000"
							});*/
							$("CcellDiv_" + i).innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
							$("CcellDiv_" + i).setStyle({
								backgroundColor: MyColor,
								'color': "#000000"
							})
						}
					}
				}
			bounds.extend(center);
			var zoom = map.getBoundsZoomLevel(bounds) - 0;
			map.setCenter(bounds.getCenter());
			map.setZoom(zoom);
			//cntr++;
			//map.setCenter(bounds.getCenter());
			}
		}			
		
//   BEARING   /////////////////////////////////////////////////////////////////////////////////////////////
		 var degreesPerRadian = 180.0 / Math.PI;
		 var radiansPerDegree = Math.PI / 180.0;
		
		 // Returns the bearing in degrees between two points.
		 // North = 0, East = 90, South = 180, West = 270.
		 function bearing( from, to ) {
		       // See T. Vincenty, Survey Review, 23, No 176, p 88-93,1975.
		       // Convert to radians.
		       var lat1 = from.latRadians();
		       var lon1 = from.lngRadians();
		       var lat2 = to.latRadians();
		       var lon2 = to.lngRadians();
		
		       // Compute the angle.
		       var angle = - Math.atan2( Math.sin( lon1 - lon2 ) * Math.cos( lat2 ), Math.cos( lat1 ) * Math.sin( lat2 ) - Math.sin( lat1 ) * Math.cos( lat2 ) * Math.cos( lon1 - lon2 ) );
		       if ( angle < 0.0 ) angle  += Math.PI * 2.0;
		
		       // And convert result to degrees.
		       angle = angle * degreesPerRadian;
		       angle = angle.toFixed(1);
		
		       return angle;
		 }			
		
		addInputEl = function(id, ang){
			var input = document.createElement("input");
				input.setAttribute("type", "input");
				input.setAttribute("name", "int" + id);
				input.setAttribute("id", "int" + id);
				input.setAttribute("value", "");
				input.setAttribute("style", "font-size:10px");
				input.setAttribute("size", "10");

			var br = document.createElement("br");
			var lable = document.createTextNode("Namirnica " + id + ": ");
			
			document.getElementById("forma").appendChild(lable);
			document.getElementById("forma").appendChild(input);
			document.getElementById("forma").appendChild(br);
		}
		
		calcSt = function() {
			var qty = 0;
			var intQty = 0;
			for (var i = 1; i <= cntr; i++) {
				if (tport[i] != undefined) {
					if (tport[i]['qty'])
						intQty += parseInt(tport[i]['qty']) * 1;
				}
			}

			var ix = intQty / 360;
				
			for(var a = 1; a <= cntr; a++){
				if (tport[a]!=undefined) {
					if (tport[a]['qty'] != undefined) {
						qty = parseInt(tport[a]['qty']) * 1;
						tport[a]['degree'] = qty / ix;
					}
				}
			}
			return tport;
		}
	    
		distance = function(startPt, endPt){
			var lat1 = startPt.lat();
			var lon1 = startPt.lng();
			var lat2 = endPt.lat();
			var lon2 = endPt.lng();
			var toRad = Math.PI / 180;
			var R = 6371; // km
			var dLat = (lat2-lat1) * toRad;
			var dLon = (lon2-lon1) * toRad; 
			var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
			        Math.cos(lat1 * toRad) * Math.cos(lat2 * toRad) * 
			        Math.sin(dLon/2) * Math.sin(dLon/2); 
			var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
			var d = R * c;
			return d;
		}
	   
//  INDEX AUTOHTONOSTI   /////////////////////////////////////////////////////////////////////////////////////////
		helper = function(){
			alert("Counter: " + cntr + "; mE: " + mE);
		}
		calcIndex = function(rD,center){
			var ixInt = new Array();
			var ixFood;
			rDs = rD;
			for(var i = 1; i <= cntr; i++) {
				if (tport[i] != undefined) {
					if (tport[i]['distance'] != distance(center, tport[i]['integPt'])) {
						tport[i]['distance'] = distance(center, tport[i]['integPt']);
					}
				var d = tport[i]['distance'];
				var koefDist = Math.exp(-(Math.pow((d / (rD * 2)), 2) / 2));
				ixInt[i] = koefDist * (tport[i]['degree'] / 360);
				}
			}
			var index = Math.ceil(((parseFloat(ixInt.sum()))*100)) + "/" + rDs;
			if(circleExist==1) var ischecked = "checked";
			else var ischecked = "";
			$('authIdx').innerHTML = "Index autohtonosti: " + index + "&nbsp;<img id=\"chkimg\" src=\"/images/chkoff.png\" width=\"16\" height=\"16\" style=\"cursor:pointer;\" onclick=\"tgIndex();\" onmouseover=\"swap_img('chkimg', 'chkoff.png', 'chkoff_hov.png');\" onmouseout=\"swap_img('chkimg', 'chkoff_hov.png', 'chkoff.png');\" />";//<input type='checkbox' id='chkIx' name='chkIx' onchange='tgIndex();' " + ischecked + " />
			idx = Math.ceil(((parseFloat(ixInt.sum()))*100));
		}
				
		 doDrawIndexAuth = function(rad){
				var circleRadius = rad;
				var center = uMarker.getLatLng();
				var bounds = new GLatLngBounds();
				var circlePoints = Array();
				
				with (Math) {
					var d = circleRadius / 6378.8; // radians
					var lat1 = (PI / 180) * center.lat(); // radians
					var lng1 = (PI / 180) * center.lng(); // radians
					for (var a = 361; a > 0; a--) {
						var tc = (PI / 180) * a;
						var y = asin(sin(lat1) * cos(d) + cos(lat1) * sin(d) * cos(tc));
						var dlng = atan2(sin(tc) * sin(d) * cos(lat1), cos(d) - sin(lat1) * sin(y));
						var x = ((lng1 - dlng + PI) % (2 * PI)) - PI; // MOD function
						var point = new GLatLng(parseFloat(y * (180 / PI)), parseFloat(x * (180 / PI)));
						
						circlePoints.push(point);
						bounds.extend(point);
					}
					
					if (d < 1.5678565720686044) 
						circleIndex = new GPolygon(circlePoints, '#000000', 0, 0, '#ffd303', 0.3);
					else 
						circleIndex = new GPolygon(circlePoints, '#61ff7f', 2, 1);
					if(circleExist==1)
						map.removeOverlay(circleIndex);
					map.addOverlay(circleIndex);
					circleExist = 1;
			}
		}
		
		function doRemoveIndexAuth(){
			if (circleIndex) {
				map.removeOverlay(circleIndex);
				circleExist = 0;
				$("chkimg").src = imgLocation + "chkoff.png";
			}
		}
		
		doUpdateIndexAuth = function(){
			if (circleExist == 1) {
				doRemoveIndexAuth();
				doDrawIndexAuth($("rad2").value);
				$("chkimg").src = imgLocation + "chkon.png";
			}
		}
		
		tgIndex = function(){
			if ($("chkimg").src == imgLocation + "chkoff.png" || $("chkimg").src == imgLocation + "chkoff_hov.png") {
				doDrawIndexAuth($("rad2").value);
				$("chkimg").src = imgLocation + "chkon.png";
				return false;
			}
			else 
				doRemoveIndexAuth();
				$("chkimg").src = imgLocation + "chkoff.png";
				return false;
		}
		
//  POZICIONIRAJ MAPU  ////////////////////////////////////////////////////////////////////////////////////////////////////
		panMap = function(panx, pany){
			map.panBy(new GSize(panx, pany));
		}

//  SAVE/LOAD/PRINT  ////////////////////////////////////////////////////////////////////////////////////////////////////////////	
		saveFood = function(){
			if (cntr < 1) 
				return false;
			else {
				tport[0]['center'] = uMarker.getLatLng();
				var saveStr = tport[0]['cname'] + "::" + tport[0]['center'] + "::" + $("rad1").value + "::" + $("rad2").value + "::";
				for (i = 1; i <= tport.length; i++) {
					if (tport[i] != undefined) 
						//alert("Artikal: " + i + " - " + tport[i]['name'] + "; angle: " +tport[i]['angle'] +"; poz.nam.: "+tport[i]['integPt'] +"; udaljenost: "+tport[i]['distance'] +"; zastupljenost(stupnjevi): "+tport[i]['degree'] + "; Količina: " + tport[i]['qty']+"; Noloc: "+tport[i]['noloc']);
						saveStr += "|" + tport[i]['name'] + "::" + tport[i]['integPt'] + "::" + tport[i]['qty'] + "::" + tport[i]['noloc'] + "::" + tport[i]['mid'];
				}
				//saveRose(saveStr);
				myLightWindow.activateWindow({
					href: '/inc/save.php?act=save&str=' + saveStr,
					title: 'Spremanje ...',
					width: 300,
					height: 200
				});
			}
		}
		
		printRose = function(){
			if (cntr < 1) 
				return false;
			else {
				if (tport[0] == undefined) {
					tport[0] = new Array();
				}
				tport[0]['center'] = uMarker.getLatLng();
				tport[0]['cname'] = $("_titleEl").innerHTML;
				var saveStr = tport[0]['cname'] + "::" + tport[0]['center'] + "::" + $("rad1").value + "::" + $("rad2").value + "::" + idx + "::";
				for (i = 1; i <= tport.length; i++) {
					if (tport[i] != undefined) 
						//alert("Artikal: " + i + " - " + tport[i]['name'] + "; angle: " +tport[i]['angle'] +"; poz.nam.: "+tport[i]['integPt'] +"; udaljenost: "+tport[i]['distance'] +"; zastupljenost(stupnjevi): "+tport[i]['degree'] + "; Količina: " + tport[i]['qty']+"; Noloc: "+tport[i]['noloc']);
						saveStr += "|" + tport[i]['name'] + "::" + tport[i]['integPt'] + "::" + tport[i]['qty'] + "::" + tport[i]['noloc'] + "::" + tport[i]['mid'] + "::" + Math.round(tport[i]['distance']);
				}
				//saveRose(saveStr);
				myLightWindow.activateWindow({
					href: '/inc/print.php?act=print&str=' + saveStr,
					title: 'Spremanje ...',
					width: 500
				});
			}
		}
		
		setupRose = function(string){
			if (parseInt($('toolbar').getStyle('width')) < 1) {
				toggleToolbar();
			}
			showPG('toolbarDiv');
			
			var str = new Array();
			str = string.split('||');
			centStr = new Array();
			centStr = str[0].split('::');
			ingStr = new Array();
			$('rad1').value = parseInt(centStr[3]);
			$('rad2').value = parseInt(centStr[4]);
			
			var titleEl = document.createElement("h4");
			titleEl.id = "_titleEl";
			titleEl.style.color = "#ffffff";
			titleEl.style.padding = "0 0 5px 5px";
			
			$("loadFrmMeal").appendChild(titleEl);
			var title = document.createTextNode(centStr[1]); 
			$("_titleEl").appendChild(title);

			var latlng = centStr[2].split(',');
			var point = new GLatLng(parseFloat(latlng[0]),parseFloat(latlng[1]));
			loadCenter(point,centStr[1]);
			for (var i = 1; i < str.length; i++) {
				cntr++;
				ingStr[i] = new Array();
				ingStr[i] = str[i].split('::');
				loadRecept(ingStr[i][0],ingStr[i][2],cntr);
				var latlng = ingStr[i][1].split(',');
				var point = new GLatLng(parseFloat(latlng[0]),parseFloat(latlng[1]));
				if (ingStr[i][3] == 1) {
					marker = new PdMarker(point, {
						draggable: false,
						id: cntr,
						icon: noIcon
					});
				} else {
					marker = new PdMarker(point, {
						draggable: false,
						id: cntr
					});
				}
				marker.setTooltip(ingStr[i][0]);
				map.addOverlay(marker);
				//alert(ingStr[i][0]+" - "+ingStr[i][1]+" - "+ingStr[i][2]+" - "+ingStr[i][3]+" - "+ingStr[i][4]);
				fillTport(marker,ingStr[i][2],ingStr[i][3],ingStr[i][4]);
			}
			updateRose();
			mode = 1;
		}
		
		loadCenter = function(point, name){
			uMarker = new PdMarker(point, {
				draggable: false,
				id: "startMarker",
				icon: startIco
			});
			uMarker.setTooltip(name);
			map.addOverlay(uMarker);
		}
		
		loadRecept = function(name,qty,id){
			var ingName = document.createElement("input");
			ingName.setAttribute("type", "input");
			ingName.setAttribute("name", id);
			ingName.setAttribute("id", "ingName_" + id);
			ingName.setAttribute("value", name);
			ingName.setAttribute("class", "frmMealElement");
			ingName.setAttribute("size", "25");
			
			var ingQty = document.createElement("input");
			ingQty.setAttribute("type", "input");
			ingQty.setAttribute("name", id + "ingQ");
			ingQty.setAttribute("id", "ingQty_" + id);
			ingQty.setAttribute("value", qty + " g.");
			ingQty.setAttribute("style", "font-size:10px; text-align:right;");
			ingQty.setAttribute("size", "7");
			ingQty.setAttribute("disabled", "true");
			ingQty.setAttribute("class", "frmMealElementQ");
			ingQty.setAttribute("onchange", "updateQty(" + id + ")");
			
			
			
			var rowDiv = document.createElement("div");
			rowDiv.id = "rowDiv_" + id;
			rowDiv.setAttribute("style", "border-bottom:1px #57b2b1 dashed;padding:2px 0 2px 0;");
			var NcellDiv = document.createElement("div");
			NcellDiv.id = "NcellDiv_" + id;
			NcellDiv.setAttribute("style", "width:140px;display:inline;");
			var QcellDiv = document.createElement("div");
			QcellDiv.id = "QcellDiv_" + id;
			QcellDiv.setAttribute("style", "text-align:right;display:inline;");
			var CcellDiv = document.createElement("div");
			CcellDiv.id = "CcellDiv_" + id;
			CcellDiv.setAttribute("style", "text-align:right;display:inline;width:10px;");
			
			var row = $("loadFrmMeal").appendChild(rowDiv);
			Ncell = row.appendChild(NcellDiv);
			Qcell = row.appendChild(QcellDiv);
			Ccell = row.appendChild(CcellDiv);
			Ncell.appendChild(ingName);
			Qcell.appendChild(ingQty);
		}
		
		writeout = function(){
			for(var i = 1; i<=tport.length; i++){
				document.write(tport[i]+"<br />");
			}
			return false;
		}

		language = function(lang){
			//
			if (cntr > 0) {
				var upoz = confirm("Ako nastavite izgubit ćete do sada napravljeno. Želite li nastaviti?");
				if (upoz) {
					if (lang != 'hr') {
						var uodgovor = confirm("U ovoj rzvojnoj fazi aplikacije za izračunavanje ruže jela, nazivi namirnica na engleskom jeziku možda nisu kompletni. Želite li nastaviti?");
						if (odgovor) {
							document.location = '/?lang=' + lang;
							return false;
						}
						else {
							return false;
						} 
					} else {
						if(upoz){
							document.location = '/';
						} else return false;
					}
				} else {
					return false;
				}
			} else {
				if (lang != 'hr') {
					var odgovor = confirm("U ovoj rzvojnoj fazi aplikacije za izračunavanje ruže jela, nazivi namirnica na engleskom jeziku možda nisu kompletni. Želite li nastaviti?");
					if (odgovor) {
						document.location = '/?lang=' + lang;
						return false;
					}
					else {
						return false;
					} 
				} else {
					if(odgovor){
						document.location = '/';
					} else return false;
				}
			}
		}

//  RUN   ////////////////////////////////////////////////////////////////////////////////////////////////////////
		createRose = function(center,color){
			rad = $("rad1").value;
			var ixRad = parseInt($("rad2").value);
			if (polyg.length > 0) {
				for (var a = 1; a < polyg.length; a++) {
					map.removeOverlay(polyg[a]);
				}
			}
			calcSt();
			doDrawCircle(rad, center, color);
			calcIndex(ixRad,center);
			if(circleExist==1) doUpdateIndexAuth();
		}
		setSize();
		map.checkResize();
		//$("_save").disabled = false;
	}
}

//  ETC   /////////////////////////////////////////////////////////////////////////////////////////////////////////
setSize = function(){
	var currSize = document.viewport.getHeight() - 160;
	$('map').setStyle({
		height: currSize + "px"
	});
	$('PGoruzi').setStyle({
		height: (currSize - 20) + "px"
	});
	//setWidth();
}

setWidth = function() {
	var idxWidth = document.viewport.getWidth() - $("menuCol").getWidth() - $("subheaderBttn").getWidth() - $("menubar").getWidth() - $("lang").getWidth();
	$("authIdx").setStyle({ width: idxWidth + "px"});
	//alert($("authIdx").getWidth());
}

setSizeIframe = function(){
	var currSize = document.viewport.getHeight() - 200;
	$('PGoruziIf').setStyle({
		height: currSize + "px"
	});
}
setSizeIframe = function(){
	var currSize = document.viewport.getHeight() - 200;
	$('PGmapaIf').setStyle({
		height: currSize + "px"
	});
}
togglePage = function(id,w){
	if (parseInt($('Page'+id).getStyle('width')) < 1) {
		alert(parseInt($('Page'+id).getStyle('width')));
		$('Page'+id).setStyle({
			width: w+"px"
		});
		$('pageDiv'+id).setStyle({
			display: "block",
			width: w+"px"
		});
		panMap(-(w),0);
	}
	else {
		alert(parseInt($('Page'+id).getStyle('width')));
		$('Page'+id).setStyle({
			width: "0px",
			"border-right": "6px #55b1b0 solid"
		});
		$('pageDiv'+id).setStyle({
			display: "none"
		});
		panMap(w,0);
	}
}

//////////////////////////////////////////////////////////////////////////////////
infoHtml = function(ingId, ingName, foo, ptLat, ptLng, mystring){
	ingId = ingId * 100
	var html = '<h2>'+ingName+'</h2>';
	//html += mystring;
	html += '<form id="selectIngForm" name="selectIngForm" action="" onsubmit="return false">Količina: <input type="text" id="Sqty" name="Sqty" size="6" onkeydown="if (event.keyCode == 13) document.getElementById(\'addIngFromBaloon\').click();" class="txt" onmouseover="this.className=\'txt txthov\';" onmouseout="this.className=\'txt\';" /> g &nbsp;';
	html += '<input type="hidden" id="SingId" name="SingId" value="'+ingId+'" />';
	html += '<input type="hidden" id="SingName" name="SingName" value="'+ingName+'" />';
	html += '<input type="hidden" id="mType" name="mType" value="ingMarker" />';
	html += '<input type="hidden" id="ptLat" name="ptLat" value="' + ptLat + '" />';
	html += '<input type="hidden" id="ptLng" name="ptLng" value="' + ptLng + '" />';
	html += '<input type="hidden" id="ptLng" name="mystring" value="' + mystring + '" />';
	html += '<input type="button" id="addIngFromBaloon" name="addIngFromBaloon" value="Dodaj!" onclick="selectIng();" class="btn" onmouseover="this.className=\'btn btnhov\';" onmouseout="this.className=\'btn\';" /></form>';
	return html;
}
CustomInfoHtml = function(cntr){
	var html = '<h2>Nova namirnica</h2>';
	html += '<form id="selectIngForm" name="selectIngForm" action="" onsubmit="return false">Naziv: &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" id="SingName" name="SingName" value="'+ newName +'" size="20" onkeydown="if (event.keyCode == 13) document.getElementById(\'addIngFromBaloon\').click();" class="txt" onmouseover="this.className=\'txt txthov\';" onmouseout="this.className=\'txt\';" /><br />';
	html += 'Količina: <input type="text" id="Sqty" name="Sqty" size="6" onkeydown="if (event.keyCode == 13) document.getElementById(\'addIngFromBaloon\').click();" class="txt" onmouseover="this.className=\'txt txthov\';" onmouseout="this.className=\'txt\';" /> g &nbsp;';
	html += '<input type="hidden" id="SingId" name="SingId" value="'+cntr+'" />';

	html += '<input type="button" id="addIngFromBaloon" name="addIngFromBaloon" value="Dodaj!" onclick="selectIng();" class="btn" onmouseover="this.className=\'btn btnhov\';" onmouseout="this.className=\'btn\';" /></form>';
	return html;
}
centarInfoHtml = function(){
	var html = '<h2>Naziv jela</h2>';
	html += '<form id="mealFrm" name="mealFrm" action="" onsubmit="return false">Naziv jela:<br /><input type="text" id="mealName" name="mealName" size="19" onkeydown="if (event.keyCode == 13) document.getElementById(\'addMealFromBaloon\').click();" class="txt" onmouseover="this.className=\'txt txthov\';" onmouseout="this.className=\'txt\';" />&nbsp;';
	html += '<input type="button" id="addMealFromBaloon" name="addMealFromBaloon" value="Dodaj!" onclick="selectMeal();" class="btn" onmouseover="this.className=\'btn btnhov\';" onmouseout="this.className=\'btn\';" /></form>';
	return html;
}
//////////////////////////////////////////////////////////////////////////////////
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
	alert('Query Variable ' + variable + ' not found');
} 

var overlay = {
	click_on_overlay_hide: false,
	show_loading_image: true,
	loading_image: "images/ajax-loader.gif",
	$: function(id){
		return document.getElementById(id);
	},
	init: function(){
		var ol_div = document.createElement("div");
		ol_div.id = "overlay";
		ol_div.style.display = "none";
		ol_div.onclick = (this.click_on_overlay_hide)? overlay.hide : null;

		if(this.show_loading_image){
			var l_img = document.createElement("img");

			l_img.src = this.loading_image;
			l_img.style.position = "absolute";
			l_img.style.top = (((window.innerHeight)? window.innerHeight : document.body.clientHeight) / 2) + "px";
			l_img.style.left = (((window.innerWidth)? window.innerWidth : document.body.clientWidth) / 2) + "px";

			ol_div.appendChild(l_img);
		}
		document.body.appendChild(ol_div);
	},
	show: function(){
		if(this.$("overlay")){
			this.$("overlay").style.display = "";
			this.$("overlay").style.background = "#FFFFFF";
		}
	},
	hide: function(){
		if(overlay.$("overlay")){
			overlay.$("overlay").style.display = "none";
		}
	}
}

showPG = function(pg, w){
	$('toolbarDiv').setStyle({
		display: "none"
	});
	$("foodroseCreate").setStyle({display: "none"}); $("PGoruzi").setStyle({display: "none"}); $("PGmapa").setStyle({display: "none"});
	$(pg).setStyle({
		display: "block"
	});
	setSizeIframe();
}

preloadImg = function(){
	if (document.images){
		preload_image = new Image(81,25); 
		preload_image.src="/images/btnO.gif"; 
		preload_chkon = new Image(16,16); 
		preload_chkon.src="/images/chkon.png";
		preload_chkoff = new Image(16,16); 
		preload_chkoff.src="/images/chkoff.png";
		preload_chkoff_hov = new Image(16,16); 
		preload_chkoff_hov.src="/images/chkoff_hov.png";
		preload_save_hov = new Image(16,16); 
		preload_save_hov.src="/images/_save_hov.png";
		preload_save = new Image(16,16); 
		preload_save.src="/images/_save.png";
		preload_refresh_hov = new Image(16,16); 
		preload_refresh_hov.src="/images/_refresh_hov.png";
		preload_refresh = new Image(16,16); 
		preload_refresh.src="/images/_refresh.png";
		preload_print_hov = new Image(16,16); 
		preload_print_hov.src="/images/_print_hov.png";
		preload_print = new Image(16,16); 
		preload_print.src="/images/_print.png";
		preload_home_hov = new Image(16,16); 
		preload_home_hov.src="/images/_home_hov.png";
		preload_home = new Image(16,16); 
		preload_home.src="/images/_home.png";
	}
}  

toggleToolbar = function(){
	if (parseInt($('toolbar').getStyle('width')) < 250) { //ako ga nema
		$('toolbar').setStyle({ //otvori ga sa 250px
			width: "250px"
		});
		$('toolbarDiv').setStyle({ //i pokaži sadržaj
			display: "block"
		});
		panMap(-250,0);
	}
	else {
		$('toolbar').setStyle({ //ako je otvoren
			width: "0px",							//širinu mu podesi na 0px
			"border-right": "6px #55b1b0 solid"		//
		});
		$('toolbarDiv').setStyle({					//sakrij sadržaj
			display: "none"
		});
		$('foodroseCreate').setStyle({				//sakrij Tablicu
			display: "none"
		})
		$('PGoruzi').setStyle({				//sakrij Oruzi
			display: "none"
		})
		$('PGmapa').setStyle({				//sakrij O mapi
			display: "none"
		})
		panMap(250,0);
	}
	setSize();
}

toggleContent = function(slide){
	var currHeight = document.viewport.getHeight() - 180;
	$('slide-1').setStyle({
		height: "0px",
		display: "none"
	});
	$('slide-2').setStyle({
		height: "0px",
		display: "none"
	});
	$('slide-3').setStyle({
		height: "0px",
		display: "none"
	});
	$(slide).setStyle({
		display: "block",
		height: currHeight
	});
}

intImage = 2;
function chBtn() {
	switch (intImage) {
		case 1:
			$("startBtn").src = "/images/btnN.gif"
			intImage = 2
			return(false);
		case 2:
			$("startBtn").src = "/images/btnO.gif"
			intImage = 1
			return(false);
	}
}

sNoloc = function(){
	Effect.Grow('nolocDiv');
	$("nolocName").value = $("ingN").options[$("ingN").selectedIndex].text;
	return false;
}

resetNoloc = function() {
	$("nolocName").value = "";
	$("nolocQty").value = "";
	Effect.SwitchOff('nolocDiv');
}

addNoloc = function() {
	Effect.SwitchOff('nolocDiv');
}

printFR = function(){
	alert(document.getElementById(''))
}

swap_img = function(imgid,img,hov_img){
	if($(imgid).src==imgLocation + img) $(imgid).src = imgLocation + hov_img;
}
