// resource server host
var resourceHost = "http://resources.ronkoliasphoto.com/";

// change the default slideshow duration
slideDuration = 2;

// check for a certain sting in the current address/url
function hasPath(sPath) {
	var re = new RegExp("\/" + sPath + "(\/|$)");
	return re.test(window.location)
}

// trim a string
function trimStr(argStr) {
	return argStr.replace(/^\s+|\s+$/g, "");
}

// page load events
function pageLoad() {
	// change the default slideshow duration
	// look at the body tags classes, if it is the homepage then swap
	// NOTE: this appears to DO NOTHING
	var bodyClass = document.getElementsByTagName("body")[0].className;
	if (bodyClass.indexOf("slideshow") != -1) {
		slideDuration = 2;
	}

	// init contact form
	var nameField = document.getElementById("contactFormName");
	if (nameField != null) {
		nameField.focus();
	}
}

// trim a form field
function trimTextBox(inputObj) {
	inputObj.value = trimStr(inputObj.value);
}

function isTextBoxValue(inputObj) {
	trimTextBox(inputObj);
	return inputObj.value.length > 0;
}

// form validator
function verifyContact(fm) {
	//alert("checking fm");

	// init the form
	fm.action = resourceHost + "contact_process.asp";
	
	// validate form
	if (!isTextBoxValue(fm.name)) {
		alert("Please provide your name.");
		return false;
	}
	if (!isTextBoxValue(fm.email) && !isTextBoxValue(fm.phone)) {
		alert("Please provide your phone number or email to reply to.");
		return false;
	}
	if (!isTextBoxValue(fm.message)) {
		alert("Please enter a message before continuing.");
		return false;
	}
	
	// all passed
}

// contact form, check for other referral option
function selectContactReferral(selectObj) {
	// get hold of the other box
	var otherBox = document.getElementById("referenceOtherBox");
	// safety
	if (otherBox == null) {
		return;
	}

	if (selectObj.value == "other") {
		otherBox.style.visibility = "visible";
		var textBox = document.getElementById("referenceOtherTextBox");
		if (textBox != null) {
			textBox.focus();
		}
	}
	else {
		otherBox.style.visibility = "hidden";
	}
}

// anchor, can't use # since smugmug uses it for conflicting purposes
function anchorTo(anchorName) {
	// we assume only one
	var anchorArr = document.getElementsByName(anchorName);
	if (anchorArr == null) {
		return;
	}

	var anchor = anchorArr[0];
	var offset = anchor.offsetTop;
	//alert("offset: " + offset);
	self.scrollTo(0, offset);
}
