/*global javascript functions for mywebpilot sites v2.1*/
/*last update:2007 OCT 4*/

var oFCKeditorbase = "/javascripts/fckeditor-2.6.4/";

var scriptbase = '../../v2/';
var alphabet = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");

var mouseX;
var mouseY;
//document.onmousemove = getMouseXY;

	function changetabs (x) {
		var tags = new Array('similar','comments','actions');
		for (i=0; i <= tags.length-1; i++) {
			var y = document.getElementById(tags[i]+'tab').src;
			if (x == tags[i]) {
				y = y.replace(".off",".on");
			} else {
				y = y.replace(".on",".off");
			}
			document.getElementById(tags[i]+'tab').src = y;
			document.getElementById(tags[i]+'holder').style.display = 'none';
		}
		document.getElementById(x+'holder').style.display = 'block';
	}
	//similar comments actions

//custom function for horizontal sliders
	function panelslide (x) {
		if (document.getElementById('caption').style.width != '0px') {
			if (x == "details") {
				document.getElementById('detailstag').src = "../images/styles/default/details.on.png";
				hslidediv('details','281','0','8'); hslidediv('caption','281','0','8');
			} else if (x == "exif") {
				document.getElementById('exiftag').src = "../images/styles/default/exif.on.png";
				hslidediv('exif','281','0','8'); hslidediv('caption','281','0','8');
			}
			if (x != 'caption') { document.getElementById('captiontag').src = "../images/styles/default/caption.off.png"; }
		} else if (document.getElementById('details').style.width != '0px') {
			if (x == "caption") {
				document.getElementById('captiontag').src = "../images/styles/default/caption.on.png";
				hslidediv('caption','281','0','8'); hslidediv('details','281','0','8');
			} else if (x == "exif") {
				document.getElementById('exiftag').src = "../images/styles/default/exif.on.png";
				hslidediv('exif','281','0','8'); hslidediv('details','281','0','8');
			}
			if (x != 'details') { document.getElementById('detailstag').src = "../images/styles/default/details.off.png"; }
		} else if (document.getElementById('exif').style.width != '0px') {
			if (x == "caption") {
				document.getElementById('captiontag').src = "../images/styles/default/caption.on.png";
				hslidediv('caption','281','0','8'); hslidediv('exif','281','0','8');
			} else if (x == "details") {
				document.getElementById('detailstag').src = "../images/styles/default/details.on.png";
				hslidediv('details','281','0','8'); hslidediv('exif','281','0','8');
			}
			if (x != 'exif') { document.getElementById('exiftag').src = "../images/styles/default/exif.off.png"; }
		}
		//id="caption"
		//id="details"
		//id="exif"
	}

	function checkstate(x) {
		if (document.getElementById('state')) {
			if (x == "united states" || x == "United States") {
				document.getElementById('state').disabled = false;
				document.getElementById('showstates').style.display = 'block';
				if (document.getElementById('province')) {
					document.getElementById('province').selectedIndex = 0;
					document.getElementById('province').disabled = true;
					document.getElementById('showprovinces').style.display = 'none';
				}
			} else if(x == "canada" || x == "Canada") {
				if (document.getElementById('province')) {
					document.getElementById('province').disabled = false;
					document.getElementById('showprovinces').style.display = 'block';
				}
				document.getElementById('state').selectedIndex = 0;
				document.getElementById('state').disabled = true;
				document.getElementById('showstates').style.display = 'none';
			} else {
				document.getElementById('state').selectedIndex = 0;
				document.getElementById('state').disabled = true;
				document.getElementById('showstates').style.display = 'none';
				if (document.getElementById('province')) {
					document.getElementById('province').selectedIndex = 0;
					document.getElementById('province').disabled = true;
					document.getElementById('showprovinces').style.display = 'none';
				}
			}
		} else {
			alert('Error: The field for states is missing.');	
		}
	}

//custom dropdowns
	function showdropoptions (x,y) {
		//hide submit link/button to prevent accidental clicking mid-stride
		//document.getElementById('submit').style.display = 'none';

		if ((document.getElementById('drop_group')) && (document.getElementById('drop_group').style.display == 'block')) { document.getElementById('drop_group').style.display = 'none'; }
		if ((document.getElementById('drop_family')) && (document.getElementById('drop_family').style.display == 'block')) { document.getElementById('drop_family').style.display = 'none'; }
		if ((document.getElementById('drop_rating')) && (document.getElementById('drop_rating').style.display == 'block')) { document.getElementById('drop_rating').style.display = 'none'; }

		var layer = 'drop_' + x;
		if ((document.getElementById(layer).style.display == 'block') || (y == 'off')) {
			document.getElementById(layer).style.display = 'none';
			//unhide submit link/button
			//document.getElementById('submit').style.display = 'block';
		} else {
			document.getElementById(layer).style.display = 'block';
		}
	}

	function formsetvalue (x,y) {
		//set visible selection for user
		var selectedlayer = 'selected_' + x;
		document.getElementById(selectedlayer).innerHTML = y;
		//set hidden variable
		document.getElementById(x).value = y;
		//close list
		var layer = 'drop_' + x;
		document.getElementById(layer).style.display = 'none';
		//unhide submit link/button
		//document.getElementById('submit').style.display = 'block';
	}


//mouse position
	function getMouseXY (e) {
		var tempX = 0;
		var tempY = 0;
		mouseX = event.clientX + document.body.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop;
	}

	function showmovingdiv(x,y) {
		//mouseX = event.clientX + document.body.scrollLeft;
		//mouseY = event.clientY + document.body.scrollTop;
		var x = 'details1';
		var y = 'photodetailson';
		document.getElementById(x).className = y;
		document.getElementById('test').innerHTML = event.x + ',' + event.y;
		document.getElementById(x).style.top = event.y;
		document.getElementById(x).style.left = event.x;
		var speed = 10;
		//setTimeout("showmovingdiv(' + x + ',' + y + ')",speed);
		setTimeout("showmovingdiv()",speed);
	}

//sliding divs
	function slidediv(target,maxheight,minheight,speed) {
		var obj = document.getElementById(target).style.height;
		if (obj >= maxheight) {
			var targetheight = minheight;
			var action = "close";
		} else {
			var targetheight = maxheight;
			var action = "open";
		}
		beginslide(target,targetheight,action,speed);
	}

	function beginslide(target,targetheight,action,speed){
		var obj = document.getElementById(target).style.height;
		obj = parseInt(obj.replace("px",""));
		var rate = speed;
		if ((action = "open") && (obj < targetheight)) {
			if ((obj + rate) > targetheight) { rate = targetheight - obj; }
			document.getElementById(target).style.height = (obj + rate) + "px";
			setTimeout("beginslide('" + target + "'," + targetheight + "," + action + "," + speed + ")",speed);
		} else if ((action = "close") && (obj > targetheight)) {
			if ((obj - rate) < targetheight) { rate = obj - targetheight; }
			document.getElementById(target).style.height = (obj - rate) + "px";
			setTimeout("beginslide('" + target + "'," + targetheight + "," + action + "," + speed + ")",speed);
		}
	}


//sliding divs
	function hslidediv(target,maxwidth,minwidth,speed) {
		var obj = document.getElementById(target).style.width;
		if (obj >= maxwidth) {
			var targetwidth = minwidth;
			var action = "close";
		} else {
			var targetwidth = maxwidth;
			var action = "open";
		}
		beginhslide(target,targetwidth,action,speed);
	}

	function beginhslide(target,targetwidth,action,speed){
		var obj = document.getElementById(target).style.width;
		obj = parseInt(obj.replace("px",""));
		rate = 8;
		if ((action = "open") && (obj < targetwidth)) {
			if ((obj + rate) > targetwidth) { rate = targetwidth - obj; }
			document.getElementById(target).style.width = (obj + rate) + "px";
			setTimeout("beginhslide('" + target + "'," + targetwidth + "," + action + "," + speed + ")",speed);
		} else if ((action = "close") && (obj > targetwidth)) {
			if ((obj - rate) < targetwidth) { rate = obj - targetwidth; }
			document.getElementById(target).style.width = (obj - rate) + "px";
			setTimeout("beginhslide('" + target + "'," + targetwidth + "," + action + "," + speed + ")",speed);
		}
	}



//ajax
	var pagerequest;

	function reopenform(x,y) {
		document.getElementById(x).style.display = 'block';
		document.getElementById(y).innerHTML = '';
	}

	function loadXMLDoc(url,div,imagedirectory,letter,post,postvars,padding,loadingimage) {
		//you cannot cross domains or http/https
		if (imagedirectory) {
			var alldivs = div.split("|");
			for (i=0; i <= alldivs.length-1; i++) {
				var controls = alldivs[i].split(",");
				if (!padding) { var padding = "11px 11px 0 11px"; }
				if (!loadingimage) { var loadingimage = "loading2.gif"; }

				if (controls[1]) {
					if (opener.document.getElementById(controls[0])) {
						//opener.document.getElementById(controls[0]).innerHTML = '<div style="padding:' + padding + '; text-align:center;"><img src="' + imagedirectory + '/loading2.gif" width="32" height="32" /></div>';
						opener.document.getElementById(controls[0]).innerHTML = '<div style="padding:' + padding + '; text-align:center;"><img src="' + imagedirectory + '/' + loadingimage + '" /></div>';
					} else if (top.opener.document.getElementById(controls[0])) {
						//top.opener.document.getElementById(controls[0]).innerHTML = '<div style="padding:' + padding + '; text-align:center;"><img src="' + imagedirectory + '/loading2.gif" width="32" height="32" /></div>';
						top.opener.document.getElementById(controls[0]).innerHTML = '<div style="padding:' + padding + '; text-align:center;"><img src="' + imagedirectory + '/' + loadingimage + '" /></div>';
					}
				} else {
					//document.getElementById(controls[0]).innerHTML = '<div style="padding:' + padding + '; text-align:center;"><img src="' + imagedirectory + '/loading2.gif" width="32" height="32" /></div>';
					document.getElementById(controls[0]).innerHTML = '<div style="padding:' + padding + '; text-align:center;"><img src="' + imagedirectory + '/' + loadingimage + '" /></div>';
				}
			}
		}
		if (letter) {
			for (i=0; i <= alphabet.length-1; i++) {
				var usestyles = letter.split(",");
				if(alphabet[i] == usestyles[0]) {
					document.getElementById('alphanav' + alphabet[i]).className = usestyles[1];
					oldstyle = usestyles[1];
				} else {
					document.getElementById('alphanav' + alphabet[i]).className = usestyles[2];
				}
			}
		}
		pagerequest = false;
		// branch for native XMLHttppagerequestuest object
		if(window.XMLHttpRequest && !(window.ActiveXObject)) {
			try {
				pagerequest = new XMLHttpRequest();
			} catch(e) {
				pagerequest = false;
			}
		// branch for IE/Windows ActiveX version
		} else if(window.ActiveXObject) {
			try {
				pagerequest = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					pagerequest = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					pagerequest = false;
					alert('error');
				}
			}
		}
		if(pagerequest) {
	        pagerequest.onreadystatechange = function() { processpagerequestChange(div,imagedirectory); };
			if (post == "post") {
				var postdata;

				//get url supplied variables
				var urlpost = url.split("?");
				if (urlpost[1]) { postdata = urlpost[1]; }
				//get form supplied variables
/*
				var postvariables = postvars.split(",");
				for (i=0; i <= postvariables.length-1; i++) {
					if ((i == 0) && (postdata)) { postdata = postdata + '&amp;'; }
					if (i > 1) { postdata = postdata + '&amp;'; }
					//postdata = 'email=' + document.getElementById(postvariables[i]).value;
					postdata = postvariables[i] + '=' + document.getElementById(postvariables[i]).value;
				}
*/

				pagerequest.open("POST", url, true);
				pagerequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
//				pagerequest.setRequestHeader('Content-Type','multipart/form-data');
				pagerequest.send(postdata);
			} else {
				pagerequest.open("GET", url, true);
				pagerequest.send(postdata);
			}
		}
	}

	function processpagerequestChange(div,imagedirectory) {
		// only if pagerequest shows "loaded"
		if (pagerequest.readyState == 4) {
			// only if "OK"
			if (pagerequest.status == 200) {
				// ...processing statements go here...
				var alldivs = div.split("|");
				for (i=0; i <= alldivs.length-1; i++) {
					var controls = alldivs[i].split(",");
					if (controls[1]) {
						if (opener.document.getElementById(controls[0])) {
							opener.document.getElementById(controls[0]).innerHTML = pagerequest.responseText;
						} else if (top.opener.document.getElementById(controls[0])) {
							top.opener.document.getElementById(controls[0]).innerHTML = pagerequest.responseText;
						}
					} else {
						document.getElementById(controls[0]).innerHTML = pagerequest.responseText;
					}
				}
//				var pagerequest = '';
			} else {
				var alldivs = div.split("|");
				var controls = alldivs[0].split(",");
				document.getElementById(controls[0]).innerHTML = "Your request has timed out.<br />Please press the refresh button on your browser and try again.";
				alert("Your request has timed out.\nPlease press the refresh button on your browser and try again.");
				//alert("There was a problem accessing this data (" + pagerequest.status + ")\nPlease press the refresh button on your browser.");
				//alert("There was a problem retrieving the XML data:\n" + pagerequest.statusText);
			}
		}
	}


	//get flash to avoid IE activation message
	function getFlash (location,autostart,width,height,loop,variables) {
		if (autostart) { var autostart = 'true'; } else { var autostart = 'false'; }
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + width +'" height="' + height +'">');
		document.write('<param name="movie" value="' + location +'" />');
		document.write('<param name="FlashVars" value="' + variables +'" />');
		document.write('<param name="quality" value="high" /><param name="menu" value="false" /><param name="loop" value="' + loop +'" />');
		document.write('<embed src="' + location +'" width="' + width +'" height="' + height +'" loop="' + loop +'" flashVars="' + variables + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');
		document.write('</object>');
	}

//	editor window
	function editor(x) {
		var link = scriptbase + 'editor/edit.asp?hid=' + x;
		var editorwindow = '';
		if (!editorwindow.closed && editorwindow.location) {
			editorwindow.location.href = url;
		} else {
			editorwindow=window.open(link,'help','width=665,height=490,status=no,toolbar=no,location=no,menubar=no,scrollbars=no');
			if (!editorwindow.opener) { editorwindow.opener = self; }
		}
		if (window.focus) { editorwindow.focus(); }
		}

//	open popup
	function popup(x,y,z,a) {
		var link = x;
		var popupwindow = '';
		if (!popupwindow.closed && popupwindow.location) {
			popupwindow.location.href = url;
		} else {
			if (!y) { y = 665; }
			if (!z) { z = 490; }
			if (!a) { a = 'no'; }
			var options = 'width=' + y + ',height=' + z + ',status=no,toolbar=no,location=no,menubar=no,scrollbars=' + a;
			popupwindow=window.open(link,'help',options);
			if (!popupwindow.opener) { popupwindow.opener = self; }
		}
		if (window.focus) { popupwindow.focus(); }
		}

//	help/tutorial window
	function help(x) {
		if (!x) { var link = scriptbase + 'help/help.asp'; } else { var link = scriptbase + 'help/help.asp?hid=' + x; }
		var helpwindow = '';
		if (!helpwindow.closed && helpwindow.location) {
			helpwindow.location.href = link;
		} else {
			helpwindow=window.open(link,'help','width=703,height=501,status=no,toolbar=no,location=no,menubar=no,scrollbars=no');
			if (!helpwindow.opener) { helpwindow.opener = self; }
		}
		if (window.focus) { helpwindow.focus(); }
		}

//	open/close div buttons
	function showdiv(type,x,y) {
		if (type == 1) {
			//div header with max, min and close buttons
			if (y == 'min') {
				document.getElementById(x).style.display = 'none';
				document.getElementById('minbutton').style.display = 'none';
				document.getElementById('maxbutton').style.display = 'block';
				document.getElementById('closebutton').style.display = 'block';
			} else if (y == 'max') {
				document.getElementById(x).style.display = 'block';
				document.getElementById('maxbutton').style.display = 'none';
				document.getElementById('minbutton').style.display = 'block';
				document.getElementById('closebutton').style.display = 'block';
			} else if (y == 'close') {
				document.getElementById('statisticswindow').style.display = 'none';
				document.getElementById(x).style.display = 'none';
				document.getElementById('maxbutton').style.display = 'block';
				document.getElementById('minbutton').style.display = 'none';
				document.getElementById('closebutton').style.display = 'block';
			}
		} else if (type == 2) {
			//expandable twisty
			if (x == 'on') {
				document.getElementById(y + 'twistoff').style.display = 'none';
				document.getElementById(y + 'twiston').style.display = 'block';
				document.getElementById(y).style.display = 'block';
			} else {
				document.getElementById(y + 'twistoff').style.display = 'block';
				document.getElementById(y + 'twiston').style.display = 'none';
				document.getElementById(y).style.display = 'none';
			}
		} else if (type == 3) {
			//simple hide & show tabs whereas x is on, y is off
			document.getElementById(x).style.display = 'block';
			if (document.getElementById('tab_' + x)) { document.getElementById('tab_' + x).className = 'tabon'; }

			document.getElementById(y).style.display = 'none';
			if (document.getElementById('tab_' + y)) { document.getElementById('tab_' + y).className = 'taboff'; }
		}
		//document.getElementById("navigation").style.height = document.getElementById("content").style.height = document.getElementById("margin").style.height = '';
		//setcolumns();
		}

	function showphotos() {
			if (document.getElementById('photolist').style.display == 'none') {
				document.getElementById('photolist').style.display = 'block';
			} else {
				document.getElementById('photolist').style.display = 'none';
			}
		}

	function showdocuments() {
			if (document.getElementById('documentlist').style.display == 'none') {
				document.getElementById('documentlist').style.display = 'block';
			} else {
				document.getElementById('documentlist').style.display = 'none';
			}
		}

	function toggle(x) {
		if (document.getElementById(x).style.display == 'block') {
			document.getElementById(x).style.display='none';
		} else {
			document.getElementById(x).style.display='block';
			tempX = 0;
			tempY = 0;
			if (document.all) {
				tempX = event.clientX + document.body.scrollLeft;
				tempY = event.clientY + document.body.scrollTop;
			  } else {
				tempX = e.pageX;
				tempY = e.pageY;
			  }
//			alert(tempX + ':' + tempY);
			document.getElementById(x).style.top = tempY + 'px';
			document.getElementById(x).style.left = tempX + 'px';
		}
	}

	function photoadd(x,y) {
			var photoids = document.getElementById('photoids').value.split(",");
			var newphotoids = new Array;
			var found = 0;
			var count = 0;
			if (photoids[0]) {
				//1 or more images have already been selected
				for (i=0; i <= photoids.length-1; i++) {
					if(photoids[i].indexOf(x) != -1) {
							found=1;
						} else {
							//keep other entries in database
							newphotoids[count] = photoids[i];
							count++;
							document.getElementById(y).className = 'photoselected';
						}
				}
				if (found == 0) {
					newphotoids[count] = x;
				} else {
					document.getElementById(y).className = 'photonotselected';
				}
			} else {
				//first image selected
				newphotoids[count] = x;
				count++;
				document.getElementById(y).className = 'photoselected';
			}

			var photoids = newphotoids.join(",");
			document.getElementById('photoids').value = photoids;
		}

	function documentadd(x,y) {
			var documentids = document.getElementById('documentids').value.split(",");
			var newdocumentids = new Array;
			var found = 0;
			var count = 0;
			if (documentids[0]) {
				//1 or more images have already been selected
				for (i=0; i <= documentids.length-1; i++) {
					if(documentids[i].indexOf(x) != -1) {
							found=1;
						} else {
							//keep other entries in database
							newdocumentids[count] = documentids[i];
							count++;
//							document.getElementById(y).className = 'documentselected';
						}
				}
				if (found == 0) {
					newdocumentids[count] = x;
				} else {
//					document.getElementById(y).className = 'documentnotselected';
				}
			} else {
				//first image selected
				newdocumentids[count] = x;
				count++;
//				document.getElementById(y).className = 'documentselected';
			}

			var documentids = newdocumentids.join(",");
			document.getElementById('documentids').value = documentids;
alert(documentids);
		}

// opacity for element
	function opacity(id, opacStart, opacEnd, millisec, grayscale) { 
		//speed for each frame 
		var speed = Math.round(millisec / 100); 
		var timer = 0; 
		//determine the direction for the blending, if start and end are the same nothing happens 
		if(opacStart > opacEnd) { 
			for(i = opacStart; i >= opacEnd; i--) { 
				setTimeout("changeOpac(" + i + ",'" + id + "'," + grayscale + ")",(timer * speed)); 
				timer++; 
			} 
		} else if(opacStart < opacEnd) { 
			for(i = opacStart; i <= opacEnd; i++) 
				{ 
				setTimeout("changeOpac(" + i + ",'" + id + "'," + grayscale + ")",(timer * speed)); 
				timer++; 
			} 
		} 

	} 

	//change the opacity for different browsers 
	function changeOpac(opacity, id, grayscale) { 
//		ht = document.getElementsByTagName("html");
//		var object = ht[0].style;
		var object = document.getElementById(id).style; 
		object.opacity = (opacity / 100); 
		object.MozOpacity = (opacity / 100); 
		object.KhtmlOpacity = (opacity / 100); 
		object.filter = "alpha(opacity=" + opacity + ")"; 
		if (grayscale == 1) {
			object.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1, opacity=" + (opacity/100) + ")"; 
		} else {
			object.filter = "progid:DXImageTransform.Microsoft.BasicImage(opacity=" + (opacity/100) + ")"; 
		}
	} 

//	adjust columns
	function setcolumns() {
		var left = document.getElementById("navigation");
		var middle = document.getElementById("content");
		var right = document.getElementById("margin");
		var max = Math.max(left.offsetHeight,middle.offsetHeight,right.offsetHeight);
		left.style.height = (max+43) + "px";
		middle.style.height = max + "px";
		right.style.height = max + "px";
		}

//	math
	function formatcurrency2(num) {
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num)) { num = "0"; }
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
		if(cents<10) { cents = "0" + cents; }
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
			num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
		}
		return (((sign)?'':'-') + '$' + num + '.' + cents);
}

// dates
	function writedate() {
		var isnMonths = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		var today = new Date();
		document.write(isnMonths[today.getMonth()] + ' ' + today.getDate() + ', ' + today.getFullYear());
		}

	function writegreeting() {
		var today = new Date();
		var hours = today.getHours();
		var greeting;
		if (hours <= "11") {
			greeting = "Good Morning";
		} else {
			if (hours >= "12" && hours <= "17") {
				greeting = "Good Afternoon";
			} else {
				if (hours >= "18") { greeting = "Good Evening"; }
			}
		}
		document.write(greeting);
		}

//stylesheets
	function setstyle(title) {
	  var i, a, main;
	  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		  a.disabled = true;
		  if(a.getAttribute("title") == title) a.disabled = false;
		}
	  }
	}

//	prompts
	function deleteevent(deletelink,event) {
		var answer = confirm("Are you sure you want to delete the event\n\"" + event + "\"?");
		if ( answer == true ) { var url = deletelink; location.href = url; }
	}
	function deletedoc(deletelink,file) {
		var answer = confirm("Are you sure you want to delete\n\"" + file + "\"?");
		if ( answer == true ) { var url = deletelink; location.href = url; }
	}

//email
	/*encode emails to hide from crawlers*/
	function writeemail(x,y,z,a) {
		document.write('<a href=\"mailto:' + x);
		document.write('&#');
		document.write('64' + y + '.');
		document.write(z + '?subject=' + a + '\">');
		document.write(x);
		document.write('&#');
		document.write('64' + y + '.');
		document.write(z);
		document.write('<\/a>');
		}

	function writeemailshort(b,x,y,z,a) {
		document.write('<a href=\"mailto:' + x);
		document.write('&#');
		document.write('64' + y + '.');
		document.write(z + '?subject=' + a + '\">');
		document.write(b);
		document.write('<\/a>');
		}



//	cookies
	function setCookie (name, value, expires, path, domain, secure) {
		var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
		document.cookie = curCookie;
		}

	function getCookie (name) {
		var prefix = name + '=';
		var c = document.cookie;
		var nullstring = '';
		var cookieStartIndex = c.indexOf(prefix);
		if (cookieStartIndex == -1)
			return nullstring;
		var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
		if (cookieEndIndex == -1)
			cookieEndIndex = c.length;
		return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
		}

	function deleteCookie (name, path, domain) {
		if (getCookie(name))
			document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}


//	navigation
	function navigate(url) {
		location.href = url;
		}

//	forms
	function checkdiv(x,y,z) {
		if (!z) {
			if (document.getElementById(x).checked) {
				document.getElementById(y).style.display='none';
			} else {
				document.getElementById(y).style.display='block';
			}
		} else {
			if (document.getElementById(x).checked) {
				document.getElementById(y).style.display='block';
			} else {
				document.getElementById(y).style.display='none';
			}
		}
	}

	function autoformfill(x,y,z) {
		var entry = document.getElementById(x);
		if ((entry.value == y) && (z == 'focus')) { entry.value = ''; }
		if ((entry.value == '') && (z == 'blur')) { entry.value = y; }
	}

	function ratethis(x,y) {
		var choices = new Array;
		choices[0] = 'Click to rate, click again to leave unrated';
		choices[1] = 'Unacceptable, will not use again';
		choices[2] = 'Poor, unlikely to use again';
		choices[3] = 'Good, probably use again';
		choices[4] = 'Great, would likely use again';
		choices[5] = 'Excellent, would definitely use again';
		var z = x + '.0';
	if ((x == document.getElementById('rating').value) || (x == 0)) {	//unrate
		if (!y) { document.getElementById('rating').value = ''; }
			if (!document.getElementById('rating').value) {
				document.getElementById('ratingsimg').src = '../../images/ratings/0.gif';
				document.getElementById('ratingchoice').innerHTML = choices[0];
			} else {
				document.getElementById('ratingsimg').src = '../../images/ratings/' + document.getElementById('rating').value + '.0.gif';
				document.getElementById('ratingchoice').innerHTML = choices[document.getElementById('rating').value];
			}
		} else {		//rate
			if (!y) { document.getElementById('rating').value = x; }
			document.getElementById('ratingsimg').src = '../../images/ratings/' + z + '.gif';
			document.getElementById('ratingchoice').innerHTML = choices[x];
		}
	}

	function disablepaste() {
		var keypress =  event.keyCode;
		if ((keypress >= 48 && keypress <= 57 ) || (keypress >= 96 && keypress <= 105 )) {	 //numbers only
			if (x == y) { document.getElementById(z).focus(); }
		}
		}

	function jumpform(x,y,z) {
		var keypress =  event.keyCode;
		if ((keypress >= 48 && keypress <= 57 ) || (keypress >= 96 && keypress <= 105 )) {	 //numbers only
			if (x == y) { document.getElementById(z).focus(); }
		}
		}

	function validate(x,y) {
		var stop=0;
		var formfields = y.split(",");
		var validateerrors = new Array;
			validateerrors['weight'] = 'Please enter your weight.';
			validateerrors['name'] = 'Please enter your name.';
			validateerrors['email'] = 'Please enter a valid email address.';
			validateerrors['email_check'] = 'Please re-type a valid email address.';
			validateerrors['username'] = 'Please enter a username.';
			validateerrors['password'] = 'Please enter a password.';
			validateerrors['password_check'] = 'Please re-type a valid password.';
			validateerrors['subject'] = 'Please choose a subject.';
			validateerrors['comments'] = 'Please enter your comments.';
			validateerrors['category'] = 'Please select a category.';
			validateerrors['headline'] = 'Please add your headline.';
			validateerrors['details'] = 'Please add details.';
			validateerrors['memberid'] = 'Please select a member for this role.';
			validateerrors['start'] = 'Please select a date that this role begins (or began).';
			validateerrors['expire'] = 'Please select a date that this role expires (or expired).';
			validateerrors['caption'] = 'Please add your caption.';
			validateerrors['image1'] = 'Please select a photo to upload.';
			validateerrors['photoids'] = 'Galleries cannot be empty.  Please add a photo or remove the gallery.';
			validateerrors['bname'] = 'Please enter the name of the service provider.';
			validateerrors['bdescription'] = 'Please enter a description of the service provided.';
			validateerrors['blog'] = 'Please add your comments.';
			validateerrors['rating'] = 'Please rate this service provider.';

			validateerrors['commname'] = 'Please close this page and enter your community name.';
			validateerrors['commtype'] = 'Please close this page and select your community type.';
			validateerrors['firstname'] = 'Please close this page and enter your first name.';
			validateerrors['email'] = 'Please close this page and enter your email address.';
			validateerrors['commlongname'] = 'Please enter your community\'s full name.';
			validateerrors['commcountry'] = 'Please select your community\'s country.';
			validateerrors['commcity'] = 'Please enter your community\' city.';
			validateerrors['commstate'] = 'Please select your community\'s state.';
			validateerrors['blog'] = 'Please add your comments.';
			validateerrors['role'] = 'Please select your role in your community.';

			validateerrors['recipetitle'] = 'Please add a recipe title.';
			validateerrors['preptime'] = 'Please estimate a prep time.';
			validateerrors['cooktime'] = 'Please estimate a cook time.';
			validateerrors['servings'] = 'Please estimate the number of servings.';
			validateerrors['shopping'] = 'Please estimate the shopping needs';
			validateerrors['difficulty'] = 'Please estimate the difficulty of this recipe.';
			validateerrors['description'] = 'Please add a recipe description.';
			validateerrors['ingredients'] = 'Please add ingredients.';
			validateerrors['directions'] = 'Please add directions.';

		for (i=0; i < formfields.length && stop==0; i++) {
			if (document.getElementById(formfields[i]) && !document.getElementById(formfields[i]).value) {
				alert(validateerrors[formfields[i]]);
				if((document.getElementById(formfields[i]) && document.getElementById(formfields[i]).getAttribute('type') != 'hidden')) { document.getElementById(formfields[i]).focus(); }
				stop=1;
			} else if (!document.getElementById(formfields[i])) {
				stop=1;
			}
		}
		if (stop == 0) {
			if (document.getElementById('uploading')) { document.getElementById('uploading').style.display = 'block'; }
			document.getElementById(x).submit();
		}
		}

	function validatecc(x,y) {
		//validate credit card number
		var CC_Num = document.getElementById(x).value;
		if (!CC_Num) { return false; }
		var CC_Type = document.getElementById(y).value;
		var CCN_digits = "";
	
		for (var i = 0; i < CC_Num.length; i++) { 
			if ((CC_Num.charAt(i) == "0") || (CC_Num.charAt(i) == "1") || (CC_Num.charAt(i) == "2") || (CC_Num.charAt(i) == "3") || (CC_Num.charAt(i) == "4") || (CC_Num.charAt(i) == "5") || (CC_Num.charAt(i) == "6") || (CC_Num.charAt(i) == "7") || (CC_Num.charAt(i) == "8") || (CC_Num.charAt(i) == "9")) {
				CCN_digits = CCN_digits + CC_Num.charAt(i);
			}
		}
	
		var validcard = false;
		// msgind is used to communicate the type of alert 
		// 1=invalid prefix (prefix does not match card type)
		// 2=invalid number of digits in card number for the card type selected
	
		var msgind = 0;
		if (CC_Type == "1") {
			var CC_name = "American Express";
			if (CCN_digits.length == "15") {
				if ((CCN_digits.substring (0, 2) == "34") || (CCN_digits.substring (0, 2) == "37")) {
					validcard = true;
				} else {
					msgind = 1;
				}
			} else {
				msgind = 2;
			}
		} else if (CC_Type == "2") {
			var CC_name = "Discover";
			if (CCN_digits.length == "16") {
				if (CCN_digits.substring (0, 4) == "6011") {
					validcard = true;
				} else {
					msgind = 1;
				}
			} else { 
				msgind = 2;
			}
		} else if (CC_Type == "3") {
			var CC_name = "MasterCard";
			if (CCN_digits.length == "16") {
				if ((CCN_digits.substring (0, 2) >= "51") && (CCN_digits.substring (0, 2) <= "55")) {
					validcard = true;
				} else {
					msgind = 1;
				}
			} else { 
				msgind = 2;
			}
		} else if (CC_Type == "4") {
			var CC_name = "Visa";
			if ((CCN_digits.length == "16") || (CCN_digits.length == "13")) {
				if (CCN_digits.substring (0, 1) == "4") {
					validcard = true;
				} else {
					msgind = 1;
				}
			} else { 
				msgind = 2;
			}
		} else {
			alert ("Please choose a Credit Card Type.");
			document.getElementById(y).focus(); return false;
		}
	
		if (!validcard) {
			if (msgind == "1") {
				// Invalid prefix
				alert ("The Card Number ("+CC_Num + ") and the Card Type (" + CC_name + ") do not match.");
				document.getElementById(x).focus(); return false;
			} else if (msgind == "2") {
				// Invalid number of digits (length)
				alert ("The Card Number ("+CC_Num + ") is not the right length for the Card Type (" + CC_name + ").");
				document.getElementById(x).focus(); return false;
			}
		}
	
		var CheckSum = 0;
		for (var x = 1; x <= CCN_digits.length; x++) {
			var CurrentDigit = CCN_digits.charAt(CCN_digits.length - x);
			if (x % 2 == "0") {
				var WorkDigit = CurrentDigit * 2; 
				if (WorkDigit > 9) { 
					CheckSum = CheckSum + (1 - 0);
					CheckSum = CheckSum + (WorkDigit % 10);
				} else {
					CheckSum = CheckSum + (WorkDigit - 0);
				} 
			} else {
				CheckSum = CheckSum + (CurrentDigit - 0);
			}
		}
	
		if (CheckSum % 10) { 
			validcard = false; 
			alert ("I'm sorry, the Card Number ("+ CC_Num +") is not correct - perhaps there is a typo or two numbers are reversed?");
			document.getElementById(x).focus(); return false;
		} 
	}

	function getpreview(x) {
//		if (document.formadd.rating.value=="" ){  alert('Please select a rating.'); return false; }

		if(!document.getElementById(x).value) { alert('Please add your comments to preview.'); return false; }
		document.getElementById('pre' + x).value = document.getElementById(x).value;

		if (document.getElementById('rating')) {
			document.getElementById('prerating').value = document.getElementById('rating').value;
		}

		var popup = window.open('','popup','width=460,height=360,status=no,top=100,left=100');
		document.getElementById('preview').submit();
		popup.document.title="preview"
		return false;
	}

	function formatcurrency(x,y) {
		var allowchange = 1;
		testv=document.getElementById(x).value;
		testv=testv.replace(",","");
		testv=testv.replace("$","");

		if (allowchange) {
			rg=/\d*?\.?/;
			if(testv.indexOf(".")!=-1) {
				if(testv.length - testv.indexOf(".")>2) { return false;}
			}
		} else {
//			rg=/\d*?/;
		}

		if(rg.test(testv) && !isNaN(testv)) {
			return true;
		} else {
			return false;
		}
		}



	/*validate telephone numbers*/
	var zChar = new Array(' ', '(', ')', '-', '.');
	var maxphonelength = 14;
	var phonevalue1;
	var phonevalue2;
	var cursorposition;
	
	function formattelephone(x,object,e) { 
		if(e){ e = e; } else { e = window.event; } 
		if(e.which){ var keycode = e.which; } else { var keycode = e.keyCode; }
		ParseForNumber(x,object);
		if (x == "up") {
			if(keycode > 48){ ValidatePhone(object); }
		}
	}

	function ParseForNumber(x,object) {
		if (x == "up") {
			phonevalue1 = ParseChar(object.value, zChar);
		} else {
			phonevalue2 = ParseChar(object.value, zChar);
		}
	}
	
	function GetCursorPosition(){
		var t1 = phonevalue1;
		var t2 = phonevalue2;
		var bool = false;
		for (i=0; i<t1.length; i++) {
			if (t1.substring(i,1) != t2.substring(i,1)) {
				if(!bool) {
					cursorposition=i;
					bool=true;
				}
			}
		}
	}
	
	function ValidatePhone(object){
		var p = phonevalue1
		p = p.replace(/[^\d]*/gi,"")
	
		if (p.length < 3) {
			object.value=p
		} else if(p.length==3){
			pp=p;
			d4=p.indexOf('(')
			d5=p.indexOf(') ')
			if(d4==-1){
				pp="("+pp;
			}
			if(d5==-1){
				pp=pp+") ";
			}
			object.value = pp;
		} else if(p.length>3 && p.length < 7){
			p ="(" + p;	
			l30=p.length;
			p30=p.substring(0,4);
			p30=p30+") "
	
			p31=p.substring(4,l30);
			pp=p30+p31;
	
			object.value = pp;	
			
		} else if(p.length >= 7){
			p ="(" + p;	
			l30=p.length;
			p30=p.substring(0,4);
			p30=p30+") "
			
			p31=p.substring(4,l30);
			pp=p30+p31;
			
			l40 = pp.length;
			p40 = pp.substring(0,9);
			p40 = p40 + "-"
			
			p41 = pp.substring(9,l40);
			ppp = p40 + p41;
			
			object.value = ppp.substring(0, maxphonelength);
		}
		
		GetCursorPosition()
		
		if(cursorposition >= 0){
			if (cursorposition == 0) {
				cursorposition = 2
			} else if (cursorposition <= 2) {
				cursorposition = cursorposition + 1
			} else if (cursorposition <= 5) {
				cursorposition = cursorposition + 2
			} else if (cursorposition == 6) {
				cursorposition = cursorposition + 2
			} else if (cursorposition == 7) {
				cursorposition = cursorposition + 4
				e1=object.value.indexOf(')')
				e2=object.value.indexOf('-')
				if (e1>-1 && e2>-1){
					if (e2-e1 == 4) {
						cursorposition = cursorposition - 1
					}
				}
			} else if (cursorposition < 11) {
				cursorposition = cursorposition + 3
			} else if (cursorposition == 11) {
				cursorposition = cursorposition + 1
			} else if (cursorposition >= 12) {
				cursorposition = cursorposition + 1
			} else if (cursorposition >= 13) {
				cursorposition = cursorposition
			}
	
			var txtRange = object.createTextRange();
			txtRange.moveStart( "character", cursorposition);
			txtRange.moveEnd( "character", cursorposition - object.value.length);
			txtRange.select();
		}
	
	}
	
	function ParseChar(sStr, sChar) {
		if (sChar.length == null) {
			zChar = new Array(sChar);
		} else {
			zChar = sChar;
		}
		for (i=0; i<zChar.length; i++) {
			sNewStr = "";
			var iStart = 0;
			var iEnd = sStr.indexOf(sChar[i]);
			while (iEnd != -1) {
				sNewStr += sStr.substring(iStart, iEnd);
				iStart = iEnd + 1;
				iEnd = sStr.indexOf(sChar[i], iStart);
			}
			sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);
			sStr = sNewStr;
		}
		return sNewStr;
	}
	/*end validate telephone numbers*/



	function getSelectedRadio(buttonGroup) {
		// returns the array number of the selected radio button or -1 if no button is selected
		if (buttonGroup[0]) {	// if the button group is an array (one button is not an array)
			for (var i=0; i<buttonGroup.length; i++) {
				if (buttonGroup[i].checked) { return i; }
			}
		} else {
			if (buttonGroup.checked) { return 0; }	// if the one button is checked, return zero
		}
		return -1;	// if we get to this point, no radio button is selected
		}
	
	function getSelectedRadioValue(buttonGroup) {
		// returns the value of the selected radio button or "" if no button is selected
		var i = getSelectedRadio(buttonGroup);
		if (i == -1) {
			return "";
		} else {
			if (buttonGroup[i]) {	// Make sure the button group is an array (not just one button)
				return buttonGroup[i].value;
			} else {
				return buttonGroup.value;	// The button group is just the one button, and it is checked
			}
		}
		}	// Ends the "getSelectedRadioValue" function

	function getSelectedCheckbox(buttonGroup) {
		// Go through all the check boxes. return an array of all the ones that are selected (their position numbers). if no boxes were checked, returned array will be empty (length will be zero)
		var retArr = new Array();
		var lastElement = 0;
		if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
			for (var i=0; i<buttonGroup.length; i++) {
				if (buttonGroup[i].checked) {
					retArr.length = lastElement;
					retArr[lastElement] = i;
					lastElement++;
				}
			}
		} else { // There is only one check box (it's not an array)
			if (buttonGroup.checked) { // if the one check box is checked
				retArr.length = lastElement;
				retArr[lastElement] = 0; // return zero as the only array value
			}
		}
		return retArr;
		}
	
	function getSelectedCheckboxValue(buttonGroup) {
		// return an array of values selected in the check box group. if no boxes
		// were checked, returned array will be empty (length will be zero)
		var retArr = new Array(); // set up empty array for the return values
		var selectedItems = getSelectedCheckbox(buttonGroup);
		if (selectedItems.length != 0) { // if there was something selected
			retArr.length = selectedItems.length;
			for (var i=0; i<selectedItems.length; i++) {
				if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
					retArr[i] = buttonGroup[selectedItems[i]].value;
				} else { // It's not an array (there's just one check box and it's selected)
					retArr[i] = buttonGroup.value;// return that value
				}
			}
		}
		return retArr;
		}

	function move(fbox,tbox) {
		var arrFbox = new Array(); var arrTbox = new Array(); var arrLookup = new Array(); var i;
		for (i = 0; i < tbox.options.length; i++) {
			arrLookup[tbox.options[i].text] = tbox.options[i].value;
			arrTbox[i] = tbox.options[i].text;
		}
		
		var fLength = 0; var tLength = arrTbox.length;
		for (i = 0; i < fbox.options.length; i++) {
			arrLookup[fbox.options[i].text] = fbox.options[i].value;
			if (fbox.options[i].selected && fbox.options[i].value != "") {
				arrTbox[tLength] = fbox.options[i].text;
				tLength++;
			} else  {
				arrFbox[fLength] = fbox.options[i].text;
				fLength++;
			}
		}

		arrFbox.sort(); arrTbox.sort(); fbox.length = 0; tbox.length = 0; var c;
		for (c = 0; c < arrFbox.length; c++) {
			var no = new Option();
			no.value = arrLookup[arrFbox[c]];
			no.text = arrFbox[c];
			fbox[c] = no;
		}
		for (c = 0; c < arrTbox.length; c++) {
			var no = new Option();
			no.value = arrLookup[arrTbox[c]];
			no.text = arrTbox[c];
			tbox[c] = no;
		}
	}

	function moveall(fbox,tbox) {
		var arrFbox = new Array(); var arrTbox = new Array(); var arrLookup = new Array(); var i;
		for (i = 0; i < tbox.options.length; i++) {
			arrLookup[tbox.options[i].text] = tbox.options[i].value;
			arrTbox[i] = tbox.options[i].text;
		}
		
		var fLength = 0; var tLength = arrTbox.length;
		for (i = 0; i < fbox.options.length; i++) {
			arrLookup[fbox.options[i].text] = fbox.options[i].value;
			if (fbox.options[i].value != "") {
				arrTbox[tLength] = fbox.options[i].text;
				tLength++;
			} else {
				arrFbox[fLength] = fbox.options[i].text;
				fLength++;
			}
		}
	
		arrFbox.sort(); arrTbox.sort(); fbox.length = 0; tbox.length = 0; var c;
		for (c = 0; c < arrFbox.length; c++) {
			var no = new Option();
			no.value = arrLookup[arrFbox[c]];
			no.text = arrFbox[c];
			fbox[c] = no;
		}
		for(c = 0; c < arrTbox.length; c++) {
			var no = new Option();
			no.value = arrLookup[arrTbox[c]];
			no.text = arrTbox[c];
			tbox[c] = no;
		}
	}

	function maxchars(x,y,z,a) {
		if (document.getElementById(x).value.length > y) { document.getElementById(x).value = document.getElementById(x).value.substring(0,y); }
		if (!document.getElementById(x).value) { var count = 0; } else { var count = document.getElementById(x).value.length; }
		if (a) { z = a + ' ' + z; }
		document.getElementById(x + 'count').innerHTML = z+ ' (' + (y - count) + ' characters/spacers left)';
}

	function updateimage(x,y) {
		//note: image preview is not enabled by default in IE7
//		alert(document.getElementById('image' + x).value);
//		document.getElementById('imagepreview' + x).src = 'file:///' + document.getElementById('image' + x).value;
		if (document.getElementById('image' + x).value) {
			document.getElementById('imagepreview' + x).src = y;
			document.getElementById('existingimage').value = '';
			imageselect();
		}
	}

	function lowercase(textarea) {
		var s = textarea.value;
		var str = s.toLowerCase();
		textarea.value = str;
	}


	//stop form shouting
	var first_word;
	var littleWords = new Array("to", "in", "the", "of", "from", "a", "as", "an", "for", "and", "but", "with", "vs.", "or", "by", "if", "on", "v", "at");
	var allCaps = new Array("STS","AWD","4WD","CD","DVD","VCR","VHS");
	function changeCase(textarea) {
		first_word = true;
		var s = textarea.value;
		var str = s.toLowerCase();
		var str_temp = new Array();
		str_temp = str.split(" ");
		for (var i = 0; i < str_temp.length; ++i) {
			var pattern = /(^[\'\"]?)(\w)([\w]*)([\.\',:;]?)(.*)/;
			var word = str_temp[i];
			var result = pattern.exec(word);
			if (result != null) {
				str_temp[i] = toTitleCase(result, littleWords, allCaps);
			}
			first_word = getFirstWord(str_temp[i]);
		}
		var currLength = 0;
		for (var i = 0; i < str_temp.length; i++) {
			currLength += str_temp[i].length;
		}
		currLength += str_temp.length - 1;
		s = str_temp.join(" ");
		textarea.value = s;
	}
	function getFirstWord(word) {
		var ret = ( word.charAt(word.length-1) == ":");
		return ret;
	}
	function isInGroup(word, groupOfWords) {
	//	word = word.replace(/:/, "");
		for (var i = 0; i < groupOfWords.length; ++i) {
			if (groupOfWords[i] == word)
				return true;
		}
		return false;
	}
	function getCase(word, littleWords, allCaps) {
		if (isInGroup(word, littleWords)) {
			return 1;	//return 1 if it is a little word;
		}
		if (isInGroup(word, allCaps)) {
			return 2;	//return 2 if this is an allcaps word;
		}
		return 3;		//return 3 for all other words;
	}
	function toTitleCase(result, littleWords, allCaps) {
		var word_temp, word_result;
		//	result[0] contains the entire match
		//	result[1] contains the (leading) ["'] (if any)
		//	result[2] contains the first letter
		//	result[3] contains the rest of the letters
		//	result[4] contains the trailing punctuation (if any)
		//	result[5] conains the trailing stuff and junk (if any)
	
		word_temp = result[2] + result[3];
		var word_case = getCase(word_temp, littleWords, allCaps);
	
		switch (word_case) {
			case 1:
				if (first_word) {
					first_word = false;
					word_result = result[2].toUpperCase() + result[3];
				} else {
					word_result = word_temp;
				}
				break;
			case 2:
				word_result = word_temp.toUpperCase();
				break;
			case 3:
				word_result = result[2].toUpperCase() + result[3];
				break;
		}
	
		word_result = result[1] + word_result;
		for (var i = 4; i < result.length; i++) {
			word_result += result[i];
		}
		return word_result;
	}




	//flash detect
	function flashalert() {
		if (!hasRightVersion && (isWin || isMac)) { document.write('<div></div>'); }
	}

	var requiredVersion = 5;
	var useRedirect = false;
	var flashPage = "movie.html";
	var noFlashPage = "noflash.html";
	var upgradePage = "upgrade.html";
	var flash2Installed = false;
	var flash3Installed = false;
	var flash4Installed = false;
	var flash5Installed = false;
	var flash6Installed = false;
	var maxVersion = 6;
	var actualVersion = 0;
	var hasRightVersion = false;
	var jsVersion = 1.0;
	var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;
	var isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;
	jsVersion = 1.1;
	
	if(isIE && isWin){
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
		document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
		document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
		document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
		document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
		document.write('</SCR' + 'IPT\> \n');
	}
	
	function detectFlash() {
		if (navigator.plugins) {
			if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){	
				var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
				var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
				flash2Installed = flashVersion == 2;	
				flash3Installed = flashVersion == 3;
				flash4Installed = flashVersion == 4;
				flash5Installed = flashVersion == 5;
				flash6Installed = flashVersion == 6;
			}
		}
		for (var i = 2; i <= maxVersion; i++) {
			if (eval("flash" + i + "Installed") == true) actualVersion = i;
		}
	if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 2;

	if (actualVersion >= requiredVersion) {
		hasRightVersion = true;	
			if (useRedirect) {	
				if(jsVersion > 1.0) {	
					window.location.replace(flashPage);
				} else {
					window.location = flashPage;
				}
			}
		} else {
			if (useRedirect) {
				if(jsVersion > 1.0) {
					window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
				} else {
					window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
				}
			}
		}
//		alert('flash:' + actualVersion + '\nversion required:' + requiredVersion + '\nplay flash:' + hasRightVersion );
		}
	
	detectFlash();


