function fFocus(tthis) {
	tthis.className = "cssFocus";
}

function fBlur(tthis) {
	tthis.className = "";
}

function fMouseOut(tthis) {
	if(tthis.className != "cssFocus") {
		tthis.className = "";
	}
}

function fMouseOver(tthis) {
	if(tthis.className != "cssFocus") {
		tthis.className = "cssOver";
	}
}

function fVerifyEmail(strEmail) {
	re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;
	if (re.test(strEmail)) {
		return true;
	} else {
		return false;
	}
}

function fVerifyInput(strID, strText) {
	var oInput = document.getElementById(strID);
	if(oInput.value == "") {
		oInput.style.background = "#ffcccc";
		return strText;
	} else {
		oInput.style.background = "";
		return "";
	}
}

function fVerifyInputLength(strID, intLength, strText) {
	var oInput = document.getElementById(strID);
	if(oInput.value.length < intLength) {
		oInput.style.background = "#ffcccc";
		return strText;
	} else {
		oInput.style.background = "";
		return "";
	}
}

function fVerifyRadio(strID, strText) {
	var oRadio = document.getElementsByName(strID);
	for(i=0; i<oRadio.length; i++) {
		if(oRadio[i].checked) {
			return "";
		}
	}
	return "Please answer " + strText + ".\n";
}

function fVerifySelect(strID, strText) {
	var oElement = document.getElementById(strID);
	if(oElement.selectedIndex == 0) {
		oElement.style.background = "#ffcccc";
		oElement.focus();
		return strText;
	} else {
		oElement.style.background = "#ffffff";
	}
	return "";
}

function fShow(strDiv) {
	document.getElementById(strDiv).style.visibility = "visible";
	document.getElementById(strDiv).style.display = "block";
}

function fHide(strDiv) {
	document.getElementById(strDiv).style.visibility = "hidden";
	document.getElementById(strDiv).style.display = "none";
}


function fToggle(strID) {
	if(document.getElementById(strID).style.visibility == "hidden") {
		fShow(strID);
	} else {
		fHide(strID);
	}
}

function fToggleDiv(strDiv) {
	var objDiv = document.getElementById(strDiv);
	if(objDiv.style.visibility == "hidden") {
		objDiv.style.visibility = "visible";
		objDiv.style.display = "block";
		if(document.getElementById(strDiv + "plus")) {
			document.getElementById(strDiv + "plus").src = strRootPath + "img/img_minus.gif";
		}
		if(document.getElementById(strDiv + "Header")) {
			document.getElementById(strDiv + "Header").className = "cssLeftNavRed";
		}
	} else {
		objDiv.style.visibility = "hidden";
		objDiv.style.display = "none";
		if(document.getElementById(strDiv + "plus")) {
			document.getElementById(strDiv + "plus").src = strRootPath + "img/img_plus.gif";
		}
		if(document.getElementById(strDiv + "Header")) {
			document.getElementById(strDiv + "Header").className = "cssLeftNav";
		}
	}
}

function fAJAXRequest(strTarget, strURL) {
	if(window.XMLHttpRequest) {
		oRequest = new XMLHttpRequest();
		oTarget = strTarget;
		oRequest.onreadystatechange = fAJAXChangeWhenReady;
		oRequest.open("GET", strURL, true);
		oRequest.send(null);
	} else if(window.ActiveXObject) {
		oRequest = new ActiveXObject("Microsoft.XMLHTTP");
		if(oRequest) {
			oTarget = strTarget;
			oRequest.onreadystatechange = fAJAXChangeWhenReady;
			oRequest.open("GET", strURL, true);
			oRequest.send();
		}
	}
}

function fAJAXChangeWhenReady() {
    if(oRequest.readyState == 4) {
    	if(document.getElementById(oTarget)) {
    		document.getElementById(oTarget).innerHTML = oRequest.responseText;
    	}
    }
}

function fClearDefault(strID, strValue, strDefault) {
        if(strValue == strDefault) {
                document.getElementById(strID).value = "";
        }
}

function fSetDefault(strID, strDefault) {
        if(document.getElementById(strID).value == "") {
                document.getElementById(strID).value = strDefault;
        }
}

function fNewsletterSignup(strEmail) {
        if(strEmail == "") {
                alert("Please enter an email address before we continue.");
                document.getElementById("txtEmail").focus();
        } else {
                var oAjax = $.ajax({ type: "get", url: "ajaxSaveEmail.php", dataType: "html", data: "txtEmail="+strEmail, async:false });
                if(oAjax.responseText == "ADDED") {
                        alert("Thank you, you have successfully signed up for the newsletter!");
                        document.getElementById("txtEmail").value = "";
                } else if(oAjax.responseText == "") {
                        alert("Network could not be reached! Are you online?");
                } else if(oAjax.responseText == "INVALID EMAIL") {
                        alert("Please enter a valid email address.");
                        document.getElementById("txtEmail").focus();
                } else {
                        alert("There was an error trying to link this artwork. The server said: \n"+oAjax.responseText);
                }
        }
}
