

function contact()
{
	if(! (document.forms[0].name.value.match(/\w+/)))
	{
		alert('Please enter your name!');
		document.forms[0].name.focus();
	}
	else if(! (document.forms[0].email.value.match(/\w+/)))
	{
		alert('Please enter a valid email address!');
		document.forms[0].email.focus();
	}
	else if(! (document.forms[0].email.value == document.forms[0].email2.value))
	{
		alert('Email addresses do not match!');
		document.forms[0].email2.focus();
	}
	else
	{
		document.forms[0].form_ok.value=1;
		document.forms[0].submit();
	}
}

function submit_on_enter(e)
{
	var key = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	//alert(key);

	if(document.forms[0].task){document.forms[0].task.value='';}

	// SUBMIT PAGE IF ENTER IS PRESSED
	if(key == 13) { document.forms[0].submit(); }

	return true;
}

function login()
{
	if(! (document.forms[0].c_user.value.match(/\w+/)))
	{
		alert('Please enter a username!');
		document.forms[0].c_user.focus();
	}
	else if(! (document.forms[0].c_pass.value.match(/\w+/)))
	{
		alert('Please enter a password!');
		document.forms[0].c_pass.focus();
	}
	else
	{
		document.forms[0].submit();
	}
}

function login_init() 
{
	if(document.forms[0].c_user)
	{
		document.forms[0].c_user.focus();
	}
}

function logout()
{
	document.forms[0].logout.value='logout';
	document.forms[0].submit(); 
}

function change_password()
{
	document.forms[0].change_password.value=1;
	document.forms[0].submit(); 
}

function check_password_change()
{
	if(! (document.forms[0].pass_orig.value.match(/\w+/)))
	{
		alert('Please enter your original password!');
		document.forms[0].pass_orig.focus();
	}
	else if(! (document.forms[0].pass_new.value.match(/\w+/)))
	{
		alert('Please enter a new password!');
		document.forms[0].pass_new.focus();
	}
	else if(document.forms[0].pass_new.value != document.forms[0].pass_new_2.value)
	{
		alert('New Passwords do not match!');
		document.forms[0].pass_new.focus();
	}
	else
	{
		document.forms[0].change_password.value=2;
		document.forms[0].submit(); 
	}
}

function go(p)
{
	document.forms[0].page.value = p;
	document.forms[0].submit();
}

function add_listing()
{
	if(reqd_info_check())
	{
		document.forms[0].task.value='exec';
		document.forms[0].submit(); 	
	}
}

function edit_listing()
{
	if(reqd_info_check())
	{
		document.forms[0].page.value='edit';
		document.forms[0].task.value='exec';
		document.forms[0].submit(); 	
	}
}

function delete_picture(p)
{
	if(confirm('Are you sure you want to delete this picture?'))
	{
		if(reqd_info_check())
		{
			document.forms[0].page.value='edit';
			document.forms[0].task.value=p;
			document.forms[0].submit(); 	
		}
	}
}

function replace_special(s)
{
	if(confirm('Replace with current listing?'))
	{
		if(reqd_info_check())
		{
			document.forms[0].page.value='edit';
			document.forms[0].task.value=s;
			document.forms[0].submit(); 	
		}
	}
}

function search()
{
	document.forms[0].page.value='search';
	document.forms[0].task.value='exec_search';
	document.forms[0].stage.value='';
	document.forms[0].item.value='';
	document.forms[0].submit(); 	
}

function search_view(p)
{
	document.forms[0].page.value=p;
	document.forms[0].task.value='exec_search';
	document.forms[0].stage.value='';
	document.forms[0].item.value='';
	document.forms[0].submit(); 	
}

function clear_it(field)
{
	field.value = field.value.replace(/[\%\.\,\$]/g,"");
}

// FORMAT FINANCIAL FIELDS WITH COMMAS AND $
function format_financial(field)
{
	var s = field.value;

	if(s.length > 12)
	{
		s = '$' + s.substring(0,s.length-12) + ',' + s.substring(0,s.length-9) + ',' + s.substring(0,s.length-6) + ',' + s.substring(s.length-6,s.length-3) + ',' + s.substring(s.length-3,s.length);
	}
	else if(s.length > 9)
	{
		s = '$' + s.substring(0,s.length-9) + ',' + s.substring(s.length-9,s.length-6) + ',' + s.substring(s.length-6,s.length-3) + ',' + s.substring(s.length-3,s.length);
	}
	else if(s.length > 6)
	{
		s = '$' + s.substring(0,s.length-6) + ',' + s.substring(s.length-6,s.length-3) + ',' + s.substring(s.length-3,s.length);
	}
	else if(s.length > 3)
	{
		s = '$' + s.substring(0,s.length-3) + ',' + s.substring(s.length-3,s.length);
	}

	field.value = s;
}

function numbers_only(e) 
{
	 var key = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	 
	 if (key == 110 || key == 190 || key == 8 || key == 9 || key == 46 || (key > 47 && key < 58) || (key > 95 && key < 106)) return true; else return false;
}

function numbers_only_submit(e) 
{
	 var key = (navigator.appName == "Netscape") ? e.which : e.keyCode;
	 
	 // SUBMIT PAGE IF ENTER IS PRESSED
	 if(key == 13) { document.forms[0].submit(); }
	 
	 if (key == 110 || key == 190 || key == 8 || key == 9 || key == 46 || (key > 47 && key < 58) || (key > 95 && key < 106)) return true; else return false;
}

function add_picture()
{
	if(reqd_info_check())
	{
		document.forms[0].sfn.value = document.forms[0].picture_path.value;
		document.forms[0].page.value = 'picture';	
		document.forms[0].task.value = 'exec';	
		document.forms[0].submit();
	}
}

function reqd_info_check()
{
	//alert(document.forms[0].type_id.selectedIndex);

	if(! (document.forms[0].title.value.match(/\w+/)))
	{
		alert('Please enter a title!');
		document.forms[0].title.focus();
		return 0;
	}
	else if(! (document.forms[0].price.value.match(/\d+/)))
	{
		alert('Please enter a price!');
		document.forms[0].price.focus();
		return 0;
	}
	else if(! (document.forms[0].beds.value.match(/\w+/)) && document.forms[0].type_id.selectedIndex != 1 )
	{
		alert('Please enter the number of bedrooms!');
		document.forms[0].beds.focus();
		return 0;
	}
	else if(! (document.forms[0].baths.value.match(/\w+/)) && document.forms[0].type_id.selectedIndex != 1 )
	{
		alert('Please enter the number of bathrooms!');
		document.forms[0].baths.focus();
		return 0;
	}
	else
	{
		return 1;	
	}
}

// IF LAND HIDE BED AND BATH
function hide_bb()
{

}

function cancel()
{
	document.forms[0].page.value='search';
	document.forms[0].task.value='';
	document.forms[0].submit(); 
}

function show_db_task(item, task )
{
	if((task == 'delete') || (task == 'delete_picture') || (task == 'delete_link') )
	{
		if(confirm('Are you sure you want to delete this entry?'))
		{
			document.forms[0].task.value=task;
			document.forms[0].item.value=item;
			document.forms[0].submit();
		}	
	}
	else
	{
		document.forms[0].task.value=task;
		document.forms[0].page.value=task;
		document.forms[0].item.value=item;
		document.forms[0].submit();
	}
}

// REFRESHES THE OUTPUT OF SHOW_DB
function search_list(n)
{
	document.forms[0].first_record.value = n;
	document.forms[0].submit();
}

function change_img(obj,fil)
{
	if(obj.src.match("gt.gif"))
	{
		obj.src="../images/lt.gif";
		fil.value = '<';
	}
	else if(obj.src.match("lt.gif"))
	{
		obj.src="../images/eq.gif";
		fil.value = '=';
	}
	else
	{
		obj.src="../images/gt.gif";
		fil.value = '>';
	}
}

function web_filter_search(noq)
{
	document.forms[0].new_order_query.value=noq;
	document.forms[0].task.value='exec_search';
	document.forms[0].page.value='search';
	document.forms[0].item.value='';
	document.forms[0].submit();
}

function web_filter_search_view(noq,p)
{
	document.forms[0].new_order_query.value=noq;
	document.forms[0].task.value='exec_search';
	document.forms[0].page.value=p;
	document.forms[0].item.value='';
	document.forms[0].submit();
}


function number_search(type)
{
	document.forms[0].task.value='exec_search';
	document.forms[0].page.value='search';
	document.forms[0].item.value='';
	document.forms[0].stage.value=type;
	document.forms[0].submit();
}

function number_search_view(type,p)
{
	document.forms[0].task.value='exec_search';
	document.forms[0].page.value=p;
	document.forms[0].item.value='';
	document.forms[0].stage.value=type;
	document.forms[0].submit();
}

function search_next_prev(n)
{
	document.forms[0].task.value='exec_search';
	document.forms[0].page.value='search';
	document.forms[0].item.value=n;
	document.forms[0].submit();
}

function search_next_prev_view(n,p)
{
	document.forms[0].task.value='exec_search';
	document.forms[0].page.value=p;
	document.forms[0].item.value=n;
	document.forms[0].submit();
}


function swap_image(img,capt)
{
	//alert(capt.value);
	//alert(document.forms[0].main_pic_caption.value);
	
//alert(img.title);

	var tmp = img.src;
	var tmp2 = capt.value;
	var tmp3 = img.title;
	
	img.src = document.main_pic.src;
	img.title = document.main_pic.title;
	capt.value = document.forms[0].main_pic_caption.value;
	
	document.main_pic.src = tmp;
	document.main_pic.title = tmp3;
	document.forms[0].main_pic_caption.value = tmp2;
	
	//alert(document.forms[0].main_pic_caption.value);
}

function request_info(n)
{
	document.forms[0].task.value='';
	document.forms[0].page.value='contact';
	document.forms[0].item.value=n;
	document.forms[0].submit();
}

