var browserSniff = navigator.userAgent;
if (browserSniff.indexOf("MSIE") != -1) {
	browserType = "ie";
	} else if (browserSniff.indexOf("Gecko") != -1) {
	browserType = "mozilla";
	} else if (browserSniff.indexOf("Opera") != -1) {
	browserType = "opera";
	} else {
	browserType = "notKnown";
}

function openHelpBox(divID,linkID,fromLeft,fromTop) {
	var offsetPsearch = document.getElementById(linkID);
	while (offsetPsearch) {
		fromLeft += offsetPsearch.offsetLeft;
		fromTop += offsetPsearch.offsetTop;
		offsetPsearch = offsetPsearch.offsetParent;
	}
	// correct for MacIE body margin
		if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") {
		fromLeft += document.body.leftMargin;
		fromTop += document.body.topMargin;
	}

	document.getElementById(divID).style.display = "block";
	document.getElementById(divID).style.left = fromLeft + "px";
	document.getElementById(divID).style.top = fromTop + "px";
}

function closeHelpBox(divID) {
	document.getElementById(divID).style.display = "none";
}

/* Allows help text to be initially displayed inside textareas. User clicks inside textarea and help text disappears. */
var inputIDs = "Additional_Info,Short_Biography";
inputIDsArray = inputIDs.split(",");

var inputFlags = "Fresh,Fresh";
var inputFlagsArray = inputFlags.split(",");
var resetLinksArray = new Array("Reset0","Reset1");

function setHelp_voidTitles() {
	document.getElementById("Additional_Info").title = "";
	document.getElementById("Short_Biography").title = "";
	document.getElementById("ddDiscipline").title = "";
	document.getElementById("ddStyle").title = "";
	insertHelpText0();
	insertHelpText1();
}

function insertHelpText0() {
	document.getElementById("Additional_Info").value = "Here you can specify musical instrument, styles, specific visual arts media, etc...";
	document.getElementById("Additional_Info").style.fontStyle = "italic";
	inputFlagsArray[0] = "Fresh";
	document.getElementById("Reset0").innerHTML = "";
}

function insertHelpText1() {
	document.getElementById("Short_Biography").value = "Here you can enter a short biography (three or four lines)...";
	document.getElementById("Short_Biography").style.fontStyle = "italic";
	inputFlagsArray[1] = "Fresh";
	document.getElementById("Reset1").innerHTML = "";
}
/* NOTES: Opera requires 'value' instead of 'innerHTML' to work. ONMOUSEDOWN event handler must be used for clearInput(). ONCLICK doesn't work if user tries to select text in an attempt to manually delete it and the mouse pointer moves off textarea before they release the mouse button (mouse up). */

function clearInput(inputID) {
	for (var i=0; i<inputIDsArray.length; i++) {
		if (inputFlagsArray[i] == "Fresh" && inputID == inputIDsArray[i]) {
			document.getElementById(inputIDsArray[i]).value = "";
			document.getElementById(inputIDsArray[i]).style.fontStyle = "normal";
			inputFlagsArray[i] = "Used";
			document.getElementById(resetLinksArray[i]).innerHTML = "[ <a href=\"javascript: void insertHelpText" + i + "();\" title=\"Click here to reset this field and view the help text...\">&nbsp;Reset&nbsp;</a> ]";
			/* alert(inputFlagsArray[i]); */
		}
	}
}

function change_rsBG() {
	if (document.BioForm.Release_Statement.checked) {
		document.getElementById("ReleaseText").style.backgroundColor = "#FFFFFF";
		rsState = "checked";
	} else {
		document.getElementById("ReleaseText").style.backgroundColor = "#FFFFE1";
	}
}

function highlightRequiredOn() {
var reqFields = "Artist_Name,Contact_Name,Phone,Email,ddDiscipline,ddStyle,Short_Biography";
var reqFieldsArray = reqFields.split(",");
	for (var i=0; i<reqFieldsArray.length; i++) {
		document.getElementById(reqFieldsArray[i]).style.backgroundColor = "#FFFFE1";
	}
}

function highlightRequiredOff() {
var reqFields = "Artist_Name,Contact_Name,Phone,Email,ddDiscipline,ddStyle,Short_Biography";
var reqFieldsArray = reqFields.split(",");
	for (var i=0; i<reqFieldsArray.length; i++) {
		document.getElementById(reqFieldsArray[i]).style.backgroundColor = "#FFFFFF";
	}
}

function singleHighlightOff(hiliteLink) {
	hiliteLink.style.backgroundColor = "#FFFFFF";
}

function checkRelease() {
	var isChecked = document.BioForm.Release_Statement.checked;
		if (isChecked == false) {
			alert("You must read the RELEASE STATEMENT and agree to it \n by checking the box 'I AGREE' before submitting this form.");
		}
		if (isChecked == true) {
			checkTextareas();
		}
	return isChecked;
}

function checkTextareas() {
	if (document.getElementById("Additional_Info").value == "Here you can specify musical instrument, styles, specific visual arts media, etc...") {
		document.getElementById("Additional_Info").value = "";
	}
	if (document.getElementById("Short_Biography").value == "Here you can enter a short biography (three or four lines)...") {
		document.getElementById("Short_Biography").value = "";
	}
}

function okayReset() {
	var confirmValue = window.confirm("This will clear any and all data you entered into the form. \n Okay to proceed?");
		if (confirmValue == true) {
			document.getElementById("ReleaseText").style.backgroundColor = "#FFFFE1";
		}
	return confirmValue;
}

function testfillArtistBio() {
	document.BioForm.Artist_Name.value = "Rob Testing";
	document.BioForm.Contact_Name.value = "Rob Darrell";
	document.BioForm.Phone.value = "846-8168";
	document.BioForm.Phone2.value = "524-6453";
	document.getElementsByName("Cellphone[1]").checked = true;
	document.BioForm.Email.value = "test_abs@secure.ironspider.ca";
	document.BioForm.Web_Address.value = "http://www.ironspider.ca/";
	document.BioForm.Discipline.options[3].selected = true;
	document.BioForm.Style.options[1].selected = true;
	document.BioForm.Country_of_origin.value = "Canada";
	document.BioForm.Additional_Info.value = "Acrylic, oil and multimedia paintings on canvas, canvas board and masonite.";
	document.BioForm.Short_Biography.value = "Born and raised in Toronto, blah blah blah blah blah blah blah blah, etcetera, I'm so great, stuff like that... ";
	document.BioForm.Release_Statement.checked = true;
}


