/*
	Author: Derek Harvey 
*/

/* TEXT COUNTER
		- Show the limited characters available
**********************************************/
function textCounter(field, countfield, maxlimit) {
	var counterField = document.getElementById(countfield);
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		counterField.value = (maxlimit - field.value.length);
	}
}

/* VALIDATE PROPERTY
		- Shell for validating the property
		- Utilizes isEmpty and showError
**********************************************/
function validateProperty(currentAction, stepID) {
	var theForm = document.forms.properties;
	switch (stepID) {
		case 1:
			if (isEmpty(theForm.property_name.value))
				return showError("'Property name' is a mandatory field");
			break;
		case 4:
			if (!isEmpty(theForm.ratePrice.value))
				return showError("Save OR Remove the 'Rate Price' you have entered to proceed");
			break;
		case 7:
			if (!isEmpty(theForm.ratePrice.value))
				return showError("Save OR Remove the 'Special Offer Price' you have entered to proceed");
			break;
	}
	theForm.action = currentAction;
	theForm.submit();
}

/* IS EMPTY
		- Check a string for an empty value
**********************************************/
function isEmpty(string) {
	if (string == '' || string == ' ') {
		return true;
	}
}

/* SHOW ERROR
		- Handle Error Messages
**********************************************/
function showError(error) {
	if (error.length > 0) {
		alert("Please note: " + error);
	} else {
		alert("Undefined Error");
	}
	return false;
}

/* SHOW ERROR
		- Handle Error Messages
**********************************************/
function getElement(elementID) {
	var elementObject = document.getElementById(elementID);
	if (elementObject)
		return elementObject;
	return false;
}

/* SHOW POPUP
**********************************************/
function displayPhotoPopup(url, wid, hei) {
	var newURL = url.replace('_medium', '');
	var newWIN = window.open(siteURL + '/view-photo/?p=' + newURL, 'name', 'height=' + hei + ',width=' + hei + ',resizable=1');
}

/* CHANGE PHOTO
		- Change the medium sized image based on a onClick event.
**********************************************/
function changePhoto(imageFile) {
	var newFile = imageFile.replace('_xsmall', '_medium');
	document.getElementById('mainPhoto').src = newFile;
}
