
		var DH = 0;
		var an = 0;
		var al = 0;
		var ai = 0;
		var visDiv = null;

		if (document.getElementById) {
		 ai = 1;
		 DH = 1;
		} else {
		 if (document.all) {
		  al = 1;
		  DH = 1;
		 } else {
		  browserVersion = parseInt(navigator.appVersion);
		  if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
		   an = 1;
		   DH = 1;
		  }
		 }
		}

		function fd(oi, wS) {
		 if (ai) return wS ? document.getElementById(oi).style : document.getElementById(oi);
		 if (al) return wS ? document.all[oi].style : document.all[oi];
		 if (an) return document.layers[oi];
		}
		
		
		function updateSizes(w,h) {
			var width = fd('width_ele',0);
		    var height = fd('height_ele',0);
			width.value = w;
			height.value = h;
		}
		
		function updateSizesAndClothSizes(w, h) {
			updateSizes(w, h);
			var form_id = "upload_form";
			var form = fd(form_id, 0);
			var stitchcount = parseInt(form.aida_size.value) + 0.0;
			var cloth_width_ele = fd('cloth_width_ele', 0);
			var cloth_height_ele = fd('cloth_height_ele', 0);
			cloth_width_ele.value = w/stitchcount;
			cloth_height_ele.value = h/stitchcount;
		}
		
		function updateSizeSelection(thisform, size) {
			if(size == 0) {
				updateSizesAndClothSizes(28,28);
			} else if(size == 1) {
				updateSizesAndClothSizes(50,40);
			} else if(size == 2) {
				updateSizesAndClothSizes(98,77);
			} else if(size == 3) {
				updateSizesAndClothSizes(150,119);
			} else {
				updateSizesAndClothSizes(-1, -1);
			}
			getSelectBoxValue("upload_form", "")
		}
		
		function updateByStitchSizes() {
			var width = fd('width_ele',0);
		    var height = fd('height_ele',0);
			var w = parseInt(width.value);
			var h = parseInt(height.value);
			if(isNaN(w)) {
				alert("Please enter a number for the pattern width");
				return;
			}
			if(isNaN(h)) {
				alert("Please enter a number for the pattern height");
				return;
			}
			width.value = '' + w;
			height.value = '' + h;
			updateSizesAndClothSizes(w,h);
		}
		
		function updateByClothSizes(updateSizeRadio) {
			if(updateSizeRadio) {
				var radio = fd("other_stitch_size", 0);
				radio.checked = "true";
			}
			var form_id = "upload_form";
			var form = fd(form_id, 0);
			var stitchcount = parseInt(form.aida_size.value);
			var cloth_width_ele = fd('cloth_width_ele', 0);
			var cloth_height_ele = fd('cloth_height_ele', 0);
			var cloth_width = parseFloat(cloth_width_ele.value);
			var cloth_height = parseFloat(cloth_height_ele.value);
			if(isNaN(cloth_width)) {
				alert("Please enter a number for the Aida cloth width");
				return;
			} 
			if(isNaN(cloth_height)) {
				alert("Please enter a number for the Aida cloth height");
				return;
			}
			cloth_width_ele.value = '' + cloth_width;
			cloth_height_ele.value = '' + cloth_height;
			updateSizes(parseInt(cloth_width*stitchcount), parseInt(cloth_height*stitchcount));
		}


		function validate_required(field,alerttxt)
		{
			with (field)
			{
				if (value==null||value=="")
				{alert(alerttxt);return false;}
				else {return true}
			}
		}

		function validate_int(value, min, max) {
			if(value == null || value.length == 0) return false;
			value = parseInt(value);
			if( isNaN(value)) {
				return false;
			}

			return (min <= value) && (value <= max);
		}
		

		function getBadWidthErrorMessage() {
			var e = fd('selectbysize', 1);
			if(e.visibility == "hidden" || e.display == "none") {
				return 'Please select a pattern width between 1 and 150 stitches';
			} else {
				var form_id = "upload_form";
				var form = fd(form_id, 0);
				var stitchcount = parseInt(form.aida_size.value);
				var maxsize = (''+150.0/stitchcount).substring(0,6);
				return 'Patterns may be at most 150 stitches wide (' + maxsize + '" for ' + stitchcount + ' count Aida cloth)';
			}
		}
		function getBadHeightErrorMessage() {
			var e = fd('selectbysize', 1);
			if(e.visibility == "hidden") {
				return 'Please select a pattern height between 1 and 120 stitches';
			} else {
				var form_id = "upload_form";
				var form = fd(form_id, 0);
				var stitchcount = parseInt(form.aida_size.value);
				var maxsize = (''+120.0/stitchcount).substring(0,6);
				return 'Patterns may be at most 120 stitches high (' + maxsize + '" for ' + stitchcount + ' count Aida cloth)';
			}
		}

		function validate_form(thisform)
		{
			with (thisform)
			{
				if (!validate_required(img,"Please select an image")) {img.focus();return false;}
				if (!validate_int(width.value, 1, 150)) {alert(getBadWidthErrorMessage());return false;}
				if (!validate_int(height.value, 1, 120)) {alert(getBadHeightErrorMessage());return false;}
				if (!validate_int(num_colors.value, 1, 50)) {alert('Please select a maximum number of thread colors to use between 1 and 50');return false;}
			}
		}
		
		function skip_validate_form(thisform)
		{
			with (thisform)
			{
			}
		}
		
		function updatePatternStyleVisibilities(show_gauge_id,select_by_stitches_id,select_by_size_id,size_toggle_id){
			var form_id = "upload_form";
			var form = fd(form_id, 0);
			var patternstyle = parseInt(form.pattern_style.value);
			if(patternstyle >= 3 && patternstyle <= 4) {
				// crochet/knitting patterns
				e = fd(select_by_stitches_id,1);
				if(e.visibility == "hidden") {
					togglevisibilities(select_by_stitches_id,select_by_size_id);
				}
				e = fd(size_toggle_id,1);
				e.visibility = "hidden";
				e.display = "none";
				e = fd(show_gauge_id,1);
				e.visibility = "visible";
				e.display = "block";
			} else {
				// cross stitch patterns
				e = fd(size_toggle_id,1);
				e.visibility = "visible";
				e.display = "block";
				e = fd(show_gauge_id,1);
				e.visibility = "hidden";
				e.display = "none";
			}
		}
		
		function togglevisibilities(layer_ref, layer_ref2){
			e = fd(layer_ref,1);
			e2 = fd(layer_ref2,1);
			if(e.visibility == "hidden") {
				e.visibility = "visible";
				e2.visibility = "hidden";
				e.display = "block";
				e2.display = "none";
			} else {
				e2.visibility = "visible";
				e.visibility = "hidden";
				e2.display = "block";
				e.display = "none";
			}
		}
		
		function togglehelpvisibility(layer_ref, text_change_ele){
			e = fd(layer_ref,1);
			txtchg = fd(text_change_ele, 0);
			if(e.visibility == "hidden") {
				e.visibility = "visible";
				e.display = "block";
				txtchg.innerHTML = "hide description"
			} else {
				e.visibility = "hidden";
				e.display = "none";
				txtchg.innerHTML = "what is this?"
			}
		}
		
		function pw() {
		 return window.innerWidth != null
		        ? window.innerWidth
		        : document.body.clientWidth != null ? document.body.clientWidth : null;
		}

		function mouseX(evt) {
		 if (evt.pageX)
		  return evt.pageX;
		 else if (evt.clientX)
		  return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft);
		 else return null;
		}

		function mouseY(evt) {
		 if (evt.pageY)
		  return evt.pageY;
		 else if (evt.clientY)
		  return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
		 else return null;
		}

		function popUp(evt,oi) {
		 if (DH) {
		  var wp = pw();
		  ds = fd(oi,1);
		  dm = fd(oi,0);
		  if (visDiv) visDiv.style.visibility = "hidden";
		  if (dm.offsetWidth) ew = dm.offsetWidth;
		  else if (dm.clip.width) ew = dm.clip.width;
		  tv = mouseY(evt) - 5;
		  lv = mouseX(evt) - (ew/4);
		  if (lv < 2) lv = 2;
		  else if (lv + ew > wp) lv -= ew/2;
		  // add some corrections, since we're in an outer div, which isn't in the upper left hand corner
		  lv -= 100;
		  tv -= 100;
		  //////////
		  if (!an) {
		   lv += 'px';
		   tv += 'px';
		  }
		  ds.left = lv;
		  ds.top = tv;
		  ds.visibility = "visible";
		  visDiv = dm;
		  //resetTimer();
		 }
		}

		function hide(evt,oi) {
		 if (DH) {
		  dm = fd(oi,0);
		  ds = fd(oi,1);
		  if (dm.offsetTop) {
		   tp = dm.offsetTop;
		   bt = tp + dm.offsetHeight;
		   lf = dm.offsetLeft;
		   rg = lf + dm.offsetWidth;
		  }
		  mx = mouseX(evt);
		  my = mouseY(evt);
		  if (mx < lf + 3 || my < tp + 3 || mx > rg - 3 || my > bt - 3)
		  {
		   ds.visibility = "hidden";
		   ds.left = -1000000;
		   ds.top = -1000000;
		  }
		  visDiv = null;
		 }
		}
		
