function submitDocument() {

	f = document.getElementById('ListingForm');

	if ( isValid(f) ) {
		hideButton();
		return true;
	} else {
		return false;
	}

}

function isValid() {
	/*
	if ( f['ListingForm:l-name'].value == "" ) {
		f['ListingForm:l-name'].focus();
		alert( "Please enter your full name." );
		return false;
	}
	
	if ( f['ListingForm:l-email'].value == "" ) {
		f['ListingForm:l-email'].focus();
		alert( "Please enter your email address." );
		return false;
	}
	
	if ( !isValidEmail(f['ListingForm:l-email'].value) ) {
		alert( "Please enter a valid email address." );
		f['ListingForm:l-email'].focus();
		return false;
	}
	
	if ( f['ListingForm:l-phone'].value == "" ) {
		alert( "Please enter the daytime phone number." );
		f['ListingForm:l-phone'].focus();
		return false;
	}
	*/
	
	if ( f['ListingForm:l-subject'].value == "" ) {
		alert( "Please enter a short description of your property." );
		f['ListingForm:l-subject'].focus();
		return false;
	}
	
	if ( f['ListingForm:l-dailyRate'].value == "" ) {
		alert( "Please enter the daily rate." );
		f['ListingForm:l-dailyRate'].focus();
		return false;
	}
	
	if ( !isDollar(f['ListingForm:l-dailyRate'].value) ) {
		alert( "Daily rate must be entered as a numeric value." );
		f['ListingForm:l-dailyRate'].focus();
		return false;
	}
	
	if ( !isDollar(f['ListingForm:l-weeklyRate'].value) ) {
		alert( "Weekly rate must be entered as a numeric value." );
		f['ListingForm:l-weeklyRate']
		return false;
	}

	// Make sure they enter the deposit as a number
	//if (f['ListingForm:l-security'].value != "") {
	
		if ( !isDollar(f['ListingForm:l-securityDeposit'].value) ) {
			alert( "Deposit must be entered as a numeric value." );
			f['ListingForm:l-securityDeposit'].focus();
			return false;
		}
		
	//}
		
	return true;

}

function isNumber(strValue){

    if(isNaN(strValue)){
         return false;
    }
    return true;
    
}

function isDollar( strValue ) { 

   var Chars = "0123456789.,$"; 
   
   for (var i = 0; i < strValue.length; i++)  { 
       if (Chars.indexOf(strValue.charAt(i)) == -1)  { 
			return false;  
       } 
   } 
   
   return true;
   
} 

function openWait() {
	var sbsWait = window.open( "wait.html", "sbsWait", "height=130,width=350,resizable=no,scrollbars=no,status=no,toolbar=no" )
}

function isValidEmail(emailAddress) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}

function hideButton() {

	nr = "ListingForm:SubmitButton";
	im = "ListingForm:WaitImage";
	if (document.layers)
	{
		document.layers[nr].visibility = 'hide';
		document.layers[im].visibility = 'visible';
	}
	else if (document.all)
	{
		document.all[nr].style.visibility = 'hidden';
		document.all[im].style.visibility = 'visible';
	}
	else if (document.getElementById)
	{
		document.getElementById(nr).style.visibility = 'hidden';
		document.getElementById(im).style.visibility = 'visible';
	}
	
}

/**
 * Shows the save button on the listing page
 * @return
 */
function showButton() {
	
	im = "ListingForm:SubmitButton";
	nr = "ListingForm:WaitImage";
	if (document.layers)
	{
		document.layers[nr].visibility = 'hide';
		document.layers[im].visibility = 'visible';
	}
	else if (document.all)
	{
		document.all[nr].style.visibility = 'hidden';
		document.all[im].style.visibility = 'visible';
	}
	else if (document.getElementById)
	{
		document.getElementById(nr).style.visibility = 'hidden';
		document.getElementById(im).style.visibility = 'visible';
	}
	
}

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);
}
