function swap (elementID, imageUrl) {

    document.getElementById(elementID).style.backgroundImage = "url('"+imageUrl+"')";
}

function swapSrc (elementID, imageUrl) {

    document.getElementById(elementID).src = imageUrl;
}

function swapLoaded (imageName, imageFile) {

    if (!document.images) {
        return;
    } else {
        eval('document.images[imageName].src = '+ imageFile +'.src');
    }
}

function doBlankLogin (elName, elValue) {

    if (elValue == "") {
        document.getElementById(elName).value = "";
        document.getElementById(elName).className = "loginBox";
        document.getElementById(elName).style.background = "";
        document.getElementById(elName).style.backgroundColor = "#fff";
    }
}

function change_species_status (speciesID, ownStatus) {

	document.location = "/index.php?section=options&SpeciesID="+speciesID+"&OptionType="+ownStatus;
}

function do_cultivar_update (SpeciesID, listIn) {

	document.cultivarUpdateForm.SpeciesID.value = SpeciesID;
	document.cultivarUpdateForm.cultivarList.value = listIn;
	document.cultivarUpdateForm.target = "cultivarFrame";
	document.cultivarUpdateForm.submit();
}

function update_sell_status (speciesID, ownStatus) {

	document.optionFrame.location = "/index.php?section=options&SpeciesID="+speciesID+"&OptionType="+ownStatus+"&updateType=controlpanel";
}

function update_sell_type (speciesID, sellType) {

	document.optionFrame.location = "/index.php?section=options&SpeciesID="+speciesID+"&OptionType=SellType&SellType="+sellType+"&updateType=controlpanel";
}

function update_contact_option (optionIn, optionVal) {
	document.optionFrame.location = "/index.php?section=profilesubmit&type=contacttype&subtype="+optionIn+"&value="+optionVal;
}

function update_species_order (orderValue) {
	document.optionFrame.location = "/index.php?section=profilesubmit&type=displayorder&value="+orderValue;
}

function doCommonSearchVerify (form) {

	var errorStr = "";

	if (form.common.value.length < 3) {
		errorStr = "Common name must be at least 3 characters long\n";
	} else if (!form.common.value.match(/[a-z]/i)) {
		errorStr = errorStr + "Common name must contain letters\n";
	} else if (!form.common.value.match(/[aeiou]/i)) {
		errorStr = errorStr + "Common name must contain at least one vowel\n";
	}

	if (errorStr != "") {
		alert(errorStr);
		return false;
	} else {
		return true;
	}
}

function doSearchVerify (form) {

	var errorStr = "";

	if (form.Genus.value == "Genus" && form.Species.value == "Species") {

		errorStr = "Please enter a Genus or a Species\n";

	} else {

		if (form.Genus.value != "Genus" && form.Genus.value != "") {

			if (form.Genus.value.length < 3) {
				errorStr = "Genus must be at least 3 characters long\n";
			} else if (!form.Genus.value.match(/[aeiou]/i)) {
				errorStr = errorStr + "Genus must contain at least one vowel\n";
			}
		}

		if (form.Species.value != "Species" && form.Species.value != "" && form.Species.value != "sp." && form.Species.value != "spp.") {

			if (form.Species.value.length < 3) {
				errorStr = errorStr + "Species must be at least 3 characters long\n";
			} else if (!form.Species.value.match(/[aeiou]/i)) {
				errorStr = errorStr + "Species must contain at least one vowel\n";
			}
		}
	}

	if (errorStr != "") {
		alert(errorStr);
		return false;
	} else {
		return true;
	}
}

function toggle_value (clickType, boxName, boxValue) {

	if (clickType == "blur") {
		if (boxValue == "" || boxValue == boxName) {
			document.getElementById(boxName).value = boxName;
			document.getElementById(boxName).style.fontStyle = "italic";
			document.getElementById(boxName).style.color = "#777";
		} 
	} else {
		if (boxValue == boxName) {
			document.getElementById(boxName).style.fontStyle = "normal";
			document.getElementById(boxName).value = "";
			document.getElementById(boxName).style.color = "#000";
		}
	}
}

function notify () {

	var suggestion = document.suggestForm.suggestionList.value;

	if (suggestion.match(/[a-zA-Z]/)) {

		document.suggestForm.submit();
		document.getElementById('suggestFormDiv').style.display = 'none';
		document.getElementById('suggestSuccessDiv').style.display = 'block';
		document.suggestForm.suggestionList.value = '';
	}
}

function setSuggestion (useID, useName) {

	document.getElementById('suggestNameSpan').innerHTML = useName;
	document.suggestForm.UseID.value = useID;
}


function showRegisterElements (currentValue) {

	if (currentValue == "EMAIL") {
		document.getElementById("WebsiteAddressDiv").style.display = "none";
		document.getElementById("TelephoneNumberDiv").style.display = "none";
	} else if (currentValue == "WEBSITE") {
		document.getElementById("WebsiteAddressDiv").style.display = "block";
		document.getElementById("TelephoneNumberDiv").style.display = "none";
	} else {
		document.getElementById("WebsiteAddressDiv").style.display = "none";
		document.getElementById("TelephoneNumberDiv").style.display = "block";
	}
}

function showRegisterForm (accountType) {

	if (accountType == "seller") {

		document.getElementById("SellerDetails").style.display = "block";
		document.getElementById("SellerTerms").style.display = "block";
		document.getElementById("WebsiteDetails").style.display = "none";
		document.getElementById("wholeRegForm").style.display = "block";
		document.getElementById("websiteRegisterBlurb").style.display = "none";

	} else if (accountType == "website") {

		document.getElementById("SellerDetails").style.display = "none";
		document.getElementById("SellerTerms").style.display = "none";
		document.getElementById("WebsiteDetails").style.display = "block";
		document.getElementById("wholeRegForm").style.display = "block";
		document.getElementById("websiteRegisterBlurb").style.display = "block";

	} else {

		document.getElementById("wholeRegForm").style.display = "none";		
	}
}

function sortSellers (column, oldValue) {

	if (oldValue == "Desc") {
		newValue = "ASC";
	} else if (oldValue == "Asc") {
		newValue = "DESC";
	} else {
		newValue = "ASC";
	}

	document.sortForm.sortcolumn.value = column;
	document.sortForm.sorttype.value = newValue;
	document.sortForm.submit();
}

function go_url (choice) {

	if (choice == 'notlisted') {
		document.location='/faq.html#typenotlisted';
	} else if (choice != '') {
		var newURL = choice.replace(/,\ /, '-');
		var newURL = newURL.replace(/\ /, '-');
		document.location='/group/'+newURL+'.html';
	}
}

function show_form (inType) {

	if (inType == "species") {

		document.getElementById("choice-species").className = "checked";
		document.getElementById("choice-genus").className = "";
		document.getElementById("help-species").style.display = "block";
		document.getElementById("help-genus").style.display = "none";
		document.getElementById("species-add-species").style.display = "block";
		document.getElementById("species-add-genus").style.display = "none";
		document.getElementById("species-add-submit").value = "Add Species";
	} else {
		document.getElementById("species-add-species").style.display = "none";
		document.getElementById("species-add-genus").style.display = "block";
		document.getElementById("help-species").style.display = "none";
		document.getElementById("help-genus").style.display = "block";
		document.getElementById("choice-species").className = "";
		document.getElementById("choice-genus").className = "checked";
		document.getElementById("species-add-submit").value = "Add Genera";
	}

	document.getElementById("species-add-form").style.display = "block";
	document.getElementById("species-add-explain").style.display = "block";
}

function confirm_genus_alert_delete (genus, genusID, speciesID, buyerCode) {

	var answer = confirm('Delete alerts for all species within the genus: "'+genus+'"?');

	if (answer) {
		document.location = '/index.php?section=buysubmit&subsection=undo&GenusID='+genusID+'&SpeciesID='+speciesID+'&Code='+buyerCode;
	}
}

/***********************************************
* Cool DHTML tooltip script II- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="/images/tooltipArrow.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

