function disp( form ){
	var s = '';
	for( var i=0 ; i<form.elements.length ; i++ ){
		var e = form.elements[ i ];
		s +=  e.name + ":" + e.value + "\n";
	}
	alert(s);
}
function collectPhotoIds( activeformname , listelename , op ){
	for( var f=0 ;  f < document.forms.length ; f++ ){
		var form = document.forms[f];
		for( var e=0 ; e < form.elements.length ; e++ ){
			var ele = form.elements[ e ];
			if( 'checkbox' == ele.type && ele.checked ){
				document.getElementById( activeformname ).innerHTML += '<input type="hidden" name="' + listelename + '" value="' + ele.name + '">';
			}
		}
	}
	if( op ){
		document.getElementById( activeformname ).innerHTML += '<input type="hidden" name="' + op + '" value="true">';
	}
	form = document.forms[ activeformname ];
	form.submit();
	return true;
}
function setvisibility( photoform , divid ){
	phototype = photoform[ 'phototype' ].value;
	var disp = 'block';
	if( 'school' == phototype ){
		disp = 'none';
		//we're changing a photo from plant photo to schoolphoto, so rewrite the data
		//photoform.submit();
	}
	if( 'fruiting' == phototype ){
		photoform.speciesid.value = 3;
		photoform.stage.value = 'fruiting';
		//photoform.submit();
	}
	if( 'gphw' == phototype ){
		photoform.stage.value = 'inflower';
		document.getElementById( divid + '_gphw' ).style.display = 'block';
		document.getElementById( divid + '_species' ).style.display = 'none';
		document.getElementById( divid + '_stage' ).style.display = 'none';
	}
	else{
		document.getElementById( divid + '_gphw' ).style.display = 'none';
		document.getElementById( divid + '_species' ).style.display = 'block';
		document.getElementById( divid + '_stage' ).style.display = 'block';
	}
	document.getElementById( divid ).style.display = disp;
}
var activediv = false;
function ajReloadItem( itemdivid , ajurl , photoform , divid ){
	activediv = itemdivid;
	qstring = '';
	if( photoform ){
		var phototype =  photoform.phototype.value ;
		if( 'school' == phototype ){
			qstring = qstringiseFormValues( photoform );
			ajax( ajurl , qstring , reWrite );
		}
		if( 'fruiting' == phototype ){
			photoform.speciesid.value = 3;
			photoform.stage.value = 'fruiting';
			qstring = qstringiseFormValues( photoform );
			ajax( ajurl , qstring , reWrite );
		}
		if( divid && 'gphw' == phototype ){
			photoform.stage.value = 'inflower';
			qstring = qstringiseFormValues( photoform );
			ajax( ajurl , qstring , reWrite );
			document.getElementById( divid + '_gphw' ).style.display = 'block';
			document.getElementById( divid + '_species' ).style.display = 'none';
			document.getElementById( divid + '_stage' ).style.display = 'none';
		}
		else if( divid ){
			if( photoform.speciesid.value > 0 && photoform.stage.value != '' ){
				qstring = qstringiseFormValues( photoform );
				ajax( ajurl , qstring , reWrite );
			}
			setvisibility( photoform , divid );
		}
	}
	else{
		//rotator link
		ajax( ajurl , qstring , reWrite );
	}
	return false;
}
function qstringiseFormValues( form ){
	var keys = [ 'id' , 'formname' , 'phototype' ,  'speciesid' , 'speciesidGphw' , 'stage' ];
	var params = [];
	var msg = '';
	for( var i in keys ){
		var ele = form[ keys[ i ] ];
		msg = ele.name + "=" + ele.value;
		params.push( msg );
	}
	return params.join( '&' ) ;
}
function reWrite( s ){
	document.getElementById( activediv ).innerHTML = s ;
}
function setAllImgChx( value ){
	for( var f=0 ;  f < document.forms.length ; f++ ){
		var form = document.forms[f];
		for( var e=0 ; e < form.elements.length ; e++ ){
			var ele = form.elements[ e ];
			if( 'checkbox' == ele.type ){
				ele.checked = value;
			}
		}
	}
	return false;
}
function addElementValue( formname , elename, value ){
	//alert( formname + ' ' + elename + ' ' + value );
	document.getElementById( formname ).innerHTML += '<input type="hidden" name="' + elename + '" value="' + value + '">';
	return false;
}
function setAllChx( form , value ){
	for( var i=0; i < form.elements.length; i++ ){
		var ele = form.elements[ i ];
		if( 'checkbox' == ele.type ){
			var ele = form.elements[ i ];
			ele.checked = value;
		}
	}
}
function reconcileAllcontrol( form , name ){
	//name is the name of the all control
	var chx = [];
	for( var i=0; i < form.elements.length; i++ ){
		var ele = form.elements[ i ];
		if( 'checkbox' == ele.type ){
			if( name == ele.name ){
				var control = ele;
			}
			else{
				chx.push( ele );
			}
		}
	}
	var controlchecked = 'on';
	for( var j in chx ){
		var ele = chx[ j ];
		if( !ele.checked ){
			controlchecked = '';
		}
	}
	control.checked = controlchecked;
}


/*pop up functions*/


function openHC() {
	window.open("http://www.greatplanthunt.org/flash/games/HabitatChallenge/index.html","mywindow","menubar=0,resizable=0,resizable=0,width=1024,height=768");
}
function openHH() {
	window.open("http://www.greatplanthunt.org/flash/games/HerbyHavoc/index.html","mywindow","menubar=0,resizable=0,resizable=0,width=1024,height=768");
}
function openPON() {
	window.open("http://www.greatplanthunt.org/flash/games/PlantOrNot/index.html","mywindow","menubar=0,resizable=0,resizable=0,width=1024,height=768");
}
function openSS() {
	window.open("http://www.greatplanthunt.org/flash/games/SunflowerSurprise/index.html","mywindow","menubar=0,resizable=0,resizable=0,width=1024,height=768");
}
