arrArray = new Array();
intArrayCount = 0;
var imgHomeOn = new Image();
var imgHomeOff = new Image();
var imgBrandsOn = new Image();
var imgBrandsOff = new Image();
var imgWhoWeAreOn = new Image();
var imgWhoWeAreOff = new Image();
var imgWhatWeDoOn = new Image();
var imgWhatWeDoOff = new Image();
var imgContactUsOn = new Image();
var imgContactUsOff = new Image();

imgHomeOn.src = "img/btn_home_on.gif";
imgHomeOff.src = "img/btn_home_off.gif";
imgBrandsOn.src = "img/btn_brands_on.gif";
imgBrandsOff.src = "img/btn_brands_off.gif";
imgWhoWeAreOn.src = "img/btn_who_we_are_on.gif";
imgWhoWeAreOff.src = "img/btn_who_we_are_off.gif";
imgWhatWeDoOn.src = "img/btn_what_we_do_on.gif";
imgWhatWeDoOff.src = "img/btn_what_we_do_off.gif";
imgContactUsOn.src = "img/btn_contact_us_on.gif";
imgContactUsOff.src = "img/btn_contact_us_off.gif";

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 getPixelsFromTop(obj){
	objFromTop = obj.offsetTop;
	while(obj.offsetParent!=null) {
		objParent = obj.offsetParent;
		objFromTop += objParent.offsetTop;
		obj = objParent;
	}
	return objFromTop;
}

function fAdjustTableHeight(strMinHeight,strID){
	var intHeight = getPixelsFromTop(document.getElementById("bottom"+strID)) - getPixelsFromTop(document.getElementById("top"+strID));
	if(strMinHeight != "" && intHeight < strMinHeight) { intHeight = strMinHeight; }
	document.getElementById("left"+strID).style.height = intHeight + "px";
	document.getElementById("right"+strID).style.height = intHeight + "px";
	//alert(strMinHeight+"-"+strID);
}

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);
                }
        }
}

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 fFaceboxRegister(strLast,intIndex,strImage1,strImage2) {
	var strHTML = "<div align=\"center\" style=\"width:790px; padding:5px;\"><img src=\"" + strImage1 + "\" alt=\"\" border=\"0\" /></div><br />";
	strHTML += "<div align='center' style='position:relative; top:35px;'>";
	if(intIndex > 1) {
		strHTML += "<a href='#' onclick='fShowLinesheet(\"" + (parseInt(intIndex)-1) + "\");'>Previous</a>";
	}
	if(strLast != "true") {
		if(intIndex > 1) { strHTML += " | "; }
		strHTML += "<a href='#' onclick='fShowLinesheet(\"" + (parseInt(intIndex)+1) + "\");'>Next</a>";
	}
	strHTML += "</div>";
	arrArray[intIndex] = strHTML;
	intArrayCount = intArrayCount + 1;
}

function fShowLinesheet(strIndex) {
	var intIndex = parseInt(strIndex);
	jQuery.facebox(arrArray[intIndex]);
}