function toggle(obj) {
	if (obj.style.display == "none") {
		obj.style.display = "";
	}
	else {
		obj.style.display = "none";
	}
}

function showPh(oid, mlnum, mid, phone, divid) {
		document.getElementById(divid).innerHTML = "<span class='smTextBold'>Phone:</span> <span class='smText'> " + phone + '</span>';
		if(navigator.appName=='Netscape'){
			var objHTTP = new XMLHttpRequest();
		}
		else if (navigator.appName.indexOf("Explorer") > 0) {
			var objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (objHTTP) {
			objHTTP.open('GET','doBrokerPhone.cfm?officeid='+oid+'&MLNUM='+mlnum+'&MEMBER_NUMBER='+mid, false);
			objHTTP.send(null);
		}
}

	
function isMLNUM(obj)
{
	var re = /([^0-9]){1,}/g;

	if (re.test(obj.value) == true)
	{
		alert('The format of your MLS number appears to be incorrect.  The proper format is digital');
		obj.value = '';
		obj.select();
		return false;
	}	
	
	return true;
}

function isZipCode(obj)
{
	var re = /([0-9]){5}/g;

	if (re.test(obj.value) == false && obj.value!='')
	{
		alert('The format of the Zip Code you entered appears to be incorrect.  The proper format is: 77002');
		obj.value = '';
		obj.select();
		return false;
	}	
	
	return true;
}

function isNumeric(obj, descr)
{
	var re = /([^0-9]){1,}/g;

	if (re.test(obj.value) == true)
	{
		alert('The value, "' + obj.value + '", you entered for ' + descr + ' is not a number.  Please enter a number.');
		obj.value = '';
		obj.focus();
		return false;
	}	
}

function fnCompareRangeValues(objMin, objMax, descrMin, descrMax)
{
	if (parseInt(objMin.value) > parseInt(objMax.value))
	{
		alert('The value you entered for ' + descrMin + ' is greater than the value you entered for ' + descrMax + '.');
		return false;
	}

	return true;
}

function fnClearFormObjects(frm)
{
	for(x=1; x < arguments.length; x++)
	{	
		if (arguments[x].type == 'checkbox')
		{	
			arguments[x].checked = false;
		}
		else
		{
			arguments[x].value = '';
		}
	}
}

function validChar(strInput){
	var j;
	for(j=0; j<strInput.length; j++){
		x = strInput.charAt(j);
		if ( (x > "z") || 
				(x > "Z" && x < "a") ||
				(x > "9" && x < "A") || 
				( (x<"0") && !(x =="," || x ==" " || x=="-"|| x=="'") )
			)
		{
			return false;
		}
	}
	return true;
}

function validNumList(obj) {
	var strInput = obj.value;
	var blnWellFormat = 0;
	for(j=0; j<strInput.length; j++){
		x = strInput.charAt(j);
		// first has to been 1 - 9
		if (j==0 && (x < '1' || x > '9')) {
			blnWellFormat = 1;
			break;
		} 
		// last has to been 0 - 9
		else if ( j== strInput.length && (x < '0' || x > '9') ) {
			blnWellFormat = 2;
			break;
		}
		// comma inbetween number 
		else if (x == ',') {
			y = strInput.charAt(j-1);
			if (y < '0' || y > '9') blnWellFormat = 3;
			y = strInput.charAt(j+1);
			if (y < '0' || y > '9') blnWellFormat = 4;
		}
		// middle has to been 1 - 9 or ','
		else if ( (x < '0' || x > '9') && x != ',' ) {
			blnWellFormat = 5;
			break;
		}
	}			
	if (blnWellFormat!=0) {
		alert ('MLS Area is in wrong format. Error Number ' + blnWellFormat);
		obj.focus();
		return false;
	}
	return true;
}

function redrawList(objList, order, popURL, dispName, sortlink) {
		
		objHTTP = getHTTPObject()
		objHTTP.open("GET", popURL + ".cfm?sort="+order, false)
		objHTTP.send(null);
		strList = objHTTP.responseText;
		pos = strList.lastIndexOf('|');
		strList = strList.substring(0, pos);	
		
		objList.length = 0;
		objList.style.width='160px';
		objList.options[0] = new Option("ALL " + dispName, "")
		aryList = strList.split('|')
		for (i=0; i<aryList.length; i++) {
			arrTemp=aryList[i].split(',');
			objList.options[i+1] = new Option(LTrim(arrTemp[0]), arrTemp[1])
		}
		if (order == 1) {
			document.getElementById(sortlink).innerHTML = "<a href=\"javascript:redrawList(document.getElementById('" + objList.id + "'), 0, '" + popURL + "', '" + dispName + "', '" + sortlink + "');\">Sort " + dispName + " By Number</a>"
		}
		else {
			document.getElementById(sortlink).innerHTML = "<a href=\"javascript:redrawList(document.getElementById('" + objList.id + "'), 1, '" + popURL + "', '" + dispName + "', '" + sortlink+ "');\">Sort " + dispName + " Alphabetically</a>"
		}
}

function getHTTPObject() {
	if(navigator.appName=='Netscape'){
		var objHTTP = new XMLHttpRequest();
	}
	else if (navigator.appName.indexOf("Explorer") > 0) {
		var objHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objHTTP;
}
	
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

function fnValidateForm(frm)
{	
	if (frm.name=='frmQuickSearch') {
		if (frm.QUICKSEARCH.value=='' || frm.QUICKSEARCH.value== 'Enter Address or MLS Number') {
			alert("Please enter your quick search criteria");
			return false;
		}
	}
	else {
			
			if ( (frm.LISTING_PRICE_MIN) && (frm.LISTING_PRICE_MIN.value != '' && frm.LISTING_PRICE_MAX.value != '') )	{
				if (fnCompareRangeValues(frm.LISTING_PRICE_MIN, frm.LISTING_PRICE_MAX, 'Minimum Price', 'Maximum Price') == false)	{
					return false;
				}
			}
			
			if ( (frm.SQURE_FEET_MIN) && (frm.SQURE_FEET_MIN.value != '' && frm.SQURE_FEET_MAX.value != ''))
			{
				if (fnCompareRangeValues(frm.SQURE_FEET_MIN, frm.SQURE_FEET_MAX, 'Minimum Square Feet', 'Maximum Square Feet') == false){
					return false;
				}
			}
		
			if (!isZipCode(frm.ZIP_CODE)){
				return false;
			}
			
			<!-- prevent special char for input text field -->
			for (i=0; i<frm.elements.length; i++){
				if (frm.elements[i].type=="text"){
					if(!validChar(frm.elements[i].value)){
						alert("please don't put special character in " + frm.elements[i].name +  " field");
						return false;
					}
				}
			}
			
			j = 0;
			//prevent too many seletions for MLS_AREA
			for(i=0; i<frm.MLS_AREA.options.length; i++){
				if(frm.MLS_AREA.options[i].selected) {
					j++;
				}
				if (j>10) {
					alert("Please do not select more than 10 MLS Areas.");
					return false;
				}
			}
			
			j=0;
			//prevent too many seletions for and city
			for(i=0; i<frm.LOCATION.options.length; i++){
				if(frm.LOCATION.options[i].selected) {
					j++;
				}
				if (j>10) {
					alert("Please do not select more than 10 Locations.");
					return false;
				}
			}

	}
	return true;
}


function printable()
{
 var bgc;
 var fgc;
 var lc;
 var vlc;
 var alc;
 var bkg;
 bgc = document.bgColor;
 fgc = document.fgColor;
 lc =  document.linkColor;
 vlc = document.vlinkColor;
 alc = document.alinkColor; 
 bkg = document.body.background;
 document.bgColor = "white"; 
 document.fgColor = "black";
 document.linkColor = "black";
 document.vlinkColor = "black";
 document.alinkColor = "black";
 document.body.background = "";
 focus()
 print()
 document.bgColor = bgc;
 document.fgColor = fgc;
 document.linkColor = lc;
 document.vlinkColor = vlc;
 document.alinkColor = alc;
 document.body.background = bkg;
}

function showdiv(id){
	if (document.getElementById(id)) {
		document.getElementById(id).style.display = 'block';
	}
}

function hidediv(id){
	if (document.getElementById(id)) {
		document.getElementById(id).style.display = 'none';
	}
}

function showBuyDiv(obj){
	if(obj.checked){
		document.getElementById("divBuy").style.display = '';
		document.getElementById("divLease").style.display = 'none';
		document.frmSearch.LEASE_PRICE_MIN.selectedIndex = 0;
		document.frmSearch.LEASE_PRICE_MAX.selectedIndex = 0;
		for (var i=0; i < document.frmSearch.PROP_TYPE.length; i++ ) {
			document.frmSearch.PROP_TYPE[i].checked = false;
		}
	}
}
function showLeaseDiv(obj){
	if(obj.checked){
		document.getElementById("divLease").style.display = '';
		document.getElementById("divBuy").style.display = 'none';
		document.frmSearch.LISTING_PRICE_MIN.selectedIndex = 0;
		document.frmSearch.LISTING_PRICE_MAX.selectedIndex = 0;
		for (var i=0; i < document.frmSearch.Property_Class_ID.length; i++ ) {
			document.frmSearch.Property_Class_ID[i].checked = false;
		}
	}
}

function writeToLayer(id, sHTML) {

  var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
 
  if (!el) return;
  if (typeof el.innerHTML!="undefined") {
      el.innerHTML = sHTML;
  } else if (document.layers) {
			el.document.write(sHTML);
			el.document.close();
  }
}

function loadDate (shtml) {
	
}