// JavaScript Document
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function changeDesc(n){
	document.getElementById("desc").innerHTML = descArray[n];
}

function gotoListings(sel){
	location.href = "viewlistings.cfm?area=" + sel.value.replace("&","%26");
}

function changeTab(tab) {
	for(i=0;i<document.getElementsByName('content').length;i++) {
		myContent=document.getElementsByName('content')[i];
		myContent.style.display='none';
	}
	myContent=document.getElementsByName('content')[tab];
	myContent.style.display='';
}

function changePrograms(tab) {
	myContent = document.getElementById('programcontent'+tab);
	if (myContent.style.display == '') {
		myContent.style.display = 'none';
	} else {
		myContent.style.display = '';
	}
}

function validateAppraise(frm) {
	msg = '';
	if (frm.phone.value == '') {
		msg = '\n  Phone' + msg;
		frm.phone.focus();
	}
	if (frm.city.value == '') {
		msg = '\n  City' + msg;
		frm.city.focus();
	}
	if (frm.address.value == '') {
		msg = '\n  Address' + msg;
		frm.address.focus();
	}
	if (frm.email.value == '') {
		msg = '\n  Email Address' + msg;
		frm.email.focus();
	}
	if (frm.lastname.value == '') {
		msg = '\n  Last Name' + msg;
		frm.lastname.focus();
	}
	if (frm.firstname.value == '') {
		msg = '\n  First Name' + msg;
		frm.firstname.focus();
	}
	if (msg == '') {
		return true;
	} else {
		alert('Please fill in the following required fields:' + msg);
		return false;
	}
}
function changePayments(op) {
	for (i=1; i<10; i++){
		document.getElementById("option"+i).style.display = "none";
	}
	document.getElementById("option"+op).style.display = "";
}

function totalPayments(num) {
	total = 0;
	for (i=0;i<document.getElementsByName("Options"+num).length;i++) {
		option = document.getElementsByName("Options"+num)[i].value.split("||");
		if (document.getElementsByName("Options"+num)[i].checked) {
			total = total + parseFloat(option[1]);
		}
	}
	total = parseFloat(total)  * 1.06;
	document.getElementsByName("paymentTotal")[0].value = formatCurrency(total);
}

function checkAdvertising(frm){
	ad1 = false;
	ad2 = false;
	for (i=0;i<document.getElementsByName("Options2").length;i++){
		if (document.getElementsByName("Options2")[i].value == "Prepaid Advertising 1||350") {
			ad1 = document.getElementsByName("Options2")[i].checked;
		}
		if (document.getElementsByName("Options2")[i].value == "Prepaid Advertising 2||500") {
			ad2 = document.getElementsByName("Options2")[i].checked;
		}
	}
	if (ad1 && ad2) {
		alert("You should only select one\nof the Prepaid Advertising Packages.");
		return false;
	} else {
		return true;
	}
			
}

function changeAdvertising(i){
	for (x=0;x<document.getElementsByName("Options2").length;x++){
		if (document.getElementsByName("Options2")[x].value.substr(0,21) == "Prepaid Advertising " + i) {
			document.getElementsByName("Options2")[x].checked = false;
		}
	}
}

function checkContactForm(frm){
	msg = "";
	if (frm.Message.value == "") {
		frm.Message.focus();
		msg = "\n  Message" + msg;
	}
	if (frm.phone.value == "") {
		frm.phone.focus();
		msg = "\n  Phone" + msg;
	}
	if (frm.address.value == "") {
		frm.address.focus();
		msg = "\n  Address" + msg;
	}
	if (frm.name.value == "") {
		frm.name.focus();
		msg = "\n  Name" + msg;
	}
	if (msg != "") {
		alert("Please fill in the following required fields:" + msg);
		return false
	} else {
		return true;
	}
}

function checkAccountCreation(frm){
	msg = "";
	if (frm.j_password.value == "") {
		frm.j_password.focus();
		msg = "\n  Password" + msg;
	} else {
		if (frm.j_password.value != frm.j_password2.value	) {
			msg = "\n Passwords do not match" + msg;
			frm.j_password.focus();			
		}
	}
	if (frm.j_email.value == "") {
		frm.j_email.focus();
		msg = "\n  Email" + msg;
	}
	if (frm.phone.value == "") {
		frm.phone.focus();
		msg = "\n  Telephone Number" + msg;
	}
	if (frm.lastname.value == "") {
		frm.lastname.focus();
		msg = "\n  Last Name" + msg;
	}
	if (frm.firstname.value == "") {
		frm.firstname.focus();
		msg = "\n  First Name" + msg;
	}
	if (msg != "") {
		alert("Please fill in the following required fields:" + msg);
		return false
	} else {
		frm.action = "listyourhome.cfm";
		return true;
	}		
}
function selectAllOptions(selStr)
{
  	var selObj = document.getElementById(selStr);
  	for (var i=0; i<selObj.options.length; i++) {
    	selObj.options[i].selected = true;
  	}
}
function addFeature(){
	optlength = document.getElementById('propertyfeature').options.length;
	if (optlength < 18){
		val = prompt('Feature to add:','','Feature');
		if(val){
			document.getElementById('propertyfeature').options[optlength] = null;
			document.getElementById('propertyfeature').options[optlength] = new Option(val,val);
		}
	} else {
		alert('You are only allowed a maximum of 18 features.');
	}
}

function removeFeature(){
	selOption = document.getElementById('propertyfeature').selectedIndex;
	if (selOption != -1){
		document.getElementById('propertyfeature').options[selOption] = null;
	}
}
function checkBriefDescription(){
	bdesclength = document.getElementById('briefdescription').value.length;
	if (bdesclength > 400){
		document.getElementById('briefdescription').value = document.getElementById('briefdescription').value.substr(0,400);
		document.getElementById('charcount').value=document.getElementById('briefdescription').value.length;
	} else {
		document.getElementById('charcount').value=bdesclength;
	}
}