function rolloverImg(imgName,imgSrc) {
	document.getElementById(imgName).src = imgSrc;
}

function confirmDelete(type, listingId, listingDesc) {
	var agree = confirm("Are you sure you want to delete the listing for the property at: " + listingDesc + "?");

	if (agree) {
		document.listingForm.recType.value = type;
		document.listingForm.recVal.value = listingId;
		document.listingForm.submit();
	}
}

var baseImgAltMsg = "";
function changeAdminImg(image, imageDesc, listing, longDescr, listingId) {
	if (image == "images/sm_noPhoto.gif") {
		document.getElementById("bigPic").src = "images/noPhoto.gif";	
		document.getElementById("imageDesc").innerHTML = "&nbsp;";
		document.updateForm.imgPath.value = "images/noPhoto.gif";	
		document.getElementById("deleteImgDiv").style.visibility = "hidden";
		document.getElementById("updateDescrDiv").style.visibility = "hidden";
	} else {
		document.getElementById("bigPic").src = image;	
		if(imageDesc == "") {
			imageDesc = "&nbsp;";
		}
		var imgName = image.substring(image.lastIndexOf("/")+1);
		document.getElementById("imageDesc").innerHTML = imageDesc;
		baseImgAltMsg = longDescr;
		document.getElementById("altPop").innerHTML = longDescr;

		var listingIdTxt = "";
		if(listingId != null && listingId != "") {
			listingIdTxt = "&listingId=" + listingId;
		}

		document.getElementById("deleteLink").href = "deleteRecord.asp?type=image&imgPath=" + imgName + "&listing=" + listing + listingIdTxt;
		document.updateForm.imgPath.value = imgName;
	}
}

function changeImg(image, imageDesc, longDescr) {
	if (image == "images/sm_noPhoto.gif") {
		document.getElementById("bigPic").src = "images/noPhoto.gif";	
		document.getElementById("imageDesc").innerHTML = "&nbsp;";
	} else {
		document.getElementById("bigPic").src = image;	
		if(imageDesc == "") {
			imageDesc = "&nbsp;";
		}
		document.getElementById("imageDesc").innerHTML = imageDesc;
		baseImgAltMsg = longDescr;
		document.getElementById("altPop").innerHTML = longDescr;
	}
}

function updateDescr(listingId, imgSrc, imgDesc) {
	page = "updateDescr.asp?updateType=descr&listingId=" + listingId + "&imgSrc=" + imgSrc;
	newWin = window.open(page, "updateWin", "width=375,height=600,top=20,left=200,resizable,scrollbars");	
}

function addImage(listingId) {
	page = "addImage.asp?updateType=image&listingId=" + listingId;
	newWin = window.open(page, "addImageWin", "width=350,height=500,top=100,left=200,resizable");	
}

function changeImage(listingId, fileName) {
	page = "changeImage.asp?updateType=image&listingId=" + listingId + "&fileName=" + fileName;
	newWin = window.open(page, "chgImageWin", "width=350,height=350,top=100,left=250,resizable");	
}

function validateFileType(thisForm, formElem, fileTypes) {
	if (formElem.value == "") {
		alert("Please select a file to upload.");
	} else {
		var validFileType = false;

		// Get the file extension
		var fileExt = formElem.value.substring(formElem.value.lastIndexOf("."), formElem.value.length);

		// Get all allowable file extensions & convert to array
		var fileTypeArr = fileTypes.split("|");
	
		// Determine if the extension for the file in question is allowable
		for (var i=0; i<fileTypeArr.length; i++) {
			if (fileExt == fileTypeArr[i]) {
				validFileType = true;
			}
		}
	
		// If a valid file type wasn't encountered, alert the user
		if (!validFileType) {
			// change the background color to bring focus to what is incorrect
			formElem.style.backgroundColor = "#FFFF99";
			alert("You have attempted to upload an invalid file type for this logo. Please try again.");
		} else {
			// Set the file name to the form
			thisForm.imgName.value = thisForm.imgName.value + fileExt;
		
			// Submit form if uploading a valid file type
			thisForm.submit();
		}
	}
}

function validateNumeric(thisForm, formElem) {
	if(formElem.value == "") {
		formElem.style.backgroundColor = "#FFFF99";
		formElem.focus();
		alert("Please input a listing price.");
		return;
	}
	
	if(isNumeric(formElem.value)) {
		thisForm.submit();
	} else {
		formElem.style.backgroundColor = "#FFFF99";
		formElem.focus();
		alert("Listing price must be a numeric value. Please remove any \nformatting characters such as '$' and ','.");
	}
}

function isNumeric(str) {
	var validChars = "0123456789.";
	var isNumber = true;
	var char;

	for (i = 0; i < str.length && isNumber == true; i++) { 
		char = str.charAt(i); 
		if (validChars.indexOf(char) == -1) {
			isNumber = false;
		}
	}
	return isNumber;
}


