function writeCount() {
   count++;
   document.write(" " + count);
   }


function WriteMlsPrp(num, prp) 
{ 
   Response.Write('<strong>');
   Response.Write('<a href="');
   
   prp += " ";
   prp = prp.substring(0, prp.indexOf(" "));
   

   Response.Write(GetDetailPagePrp(num, prp));
   Response.Write('" ID=mlsprp target="_self">');
   Response.Write(num);
   Response.Write('</a></strong>');
   
	if(gOpenWinDef == true)
	{
		Response.Write('<script>');
		Response.Write('mlsprp.target = ReportPage');
		Response.Write('</script>');
	}
}


function writePhoneNumber(phone) {
	var reNum = /\d/g;
	var numArray = Array();
	var rtnVal = String();
	
	var strPhone = String(phone);
	strPhone = strPhone.replace(/ /g,"");
	
	if(strPhone.length==0) {
	   document.write("&nbsp;");
	   return;
	   }
	
	numArray = strPhone.match(reNum);

	if(numArray == null)
	{
	   document.write("&nbsp;");
	   return;		
	}
	
	var len = numArray.length;
	
	if (len == 10)	// Format (xxx)xxx-xxxx
	{
		for(i = 0; i < 10; i++)
		{
			if(i == 0) rtnVal += '(';
			if(i == 3) rtnVal += ')';
			if(i == 6) rtnVal += '-';
			rtnVal += numArray[i];
		}		
	}
	else if (len == 7)  // Format xxx-xxxx
	{
		for(i = 0; i < 7; i++)
		{
			if(i == 3) rtnVal += '-';
			rtnVal += numArray[i];
		}	
	}
	else if (len > 10)  // Format (xxx)xxx-xxxx - xxxx for extension
	{
		for(i = 0; i < len; i++)
		{
			if(i == 0) rtnVal += '(';
			if(i == 3) rtnVal += ')';
			if(i == 6) rtnVal += '-';
			if(i == 10) rtnVal += ' - ';
			rtnVal += numArray[i];
		}		
	}
	else	// No format just print the number
	{
		for(i=0; i < len; i++)
		{
			rtnVal += numArray[i];
		}
	}
	
	document.write(rtnVal);
}

function writeDate(date) {
   listDate = new String(date);

   if(listDate.length == 0) {
      return;
      }
   
   document.write(FormatEditDate(date));
   }

function writeDate4Yr(date) {
   listDate = new String(date);

   if(listDate.length == 0) {
      return;
      }
   
   document.write(FormatEditDate4Yr(date));
   }

function FormatEditDate(date) {
   listDate = new String(date);

   if(listDate.length == 0)
      return "";

   year  = listDate.substring(2, 4); 
   month = listDate.substring(5, 7); 
   day   = listDate.substring(8,10);

   return ( month + "/" + day + "/" + year );
   }

function FormatEditDate4Yr(date) {
   listDate = new String(date);

   if(listDate.length == 0)
      return "";

   year  = listDate.substring(0, 4); 
   month = listDate.substring(5, 7); 
   day   = listDate.substring(8,10);

   return ( month + "/" + day + "/" + year );
   }

//-----------------------------------------------------------------------------

function DecommifyNumber(num)
{
	var regexp = /\W/g;
	var internal = new String(num);	// Make sure its a string

	internal = internal.replace(regexp, "");
		
	return internal;
}

function CommifyNumber(num)
{
	return SetCommas(DecommifyNumber(num));
}

//-----------------------------------------------------------------------------

function SetCommas(num) {
   if(typeof(num)=="undefined")
      num = new String("0");
   else
      num = new String(num);

	// 1. drops everything after "."
	// 2. adds comma from 3333333 to 3333,333
	// 3. adds rest of commas 3,333,333
   return num.replace(/^([^\.]*)\.?.*$/, '$1').replace(/(\d)(\d{3})$/, '$1,$2').replace(/(\d)(\d{3}),/g, '$1,$2,');

   }
   
function writeCommas(num) {
   document.write(SetCommas(num));
   }

function IsSome(str) {
   str = new String(str);
   if(str.length<=0)     { str="";  return "false" };
   
   str = str.substring(0, 255);
   if(str=="NaN")        { str="";  return "false" };
   if(str=="undefined")  { str="";  return "false" };
   
   if(str=="") return "false";
   
   return "true";
   }

//-----------------------------------------------------------------------------

function RoundFloat(num, pos) {
	if (typeof "num"=="string" && num.length==0)  return;
   
	var offset = Math.pow(10, parseInt(pos));
	var result = Math.round(parseFloat(num)*parseInt(offset))/parseInt(offset);
	
	return String(result);
   }

function RoundFixed(num, pos) {
	var internal = String(RoundFloat(num,pos));
	
	if (typeof "internal"=="string" && internal.length==0)  return;
	if ((internal.indexOf(".") == -1) && (pos > 0)) internal += ".";
	for(var i = (internal.length - 1 - internal.indexOf(".")); i < pos; i++)
	{
		internal += '0';	
	}
	
	return String(internal);
	}

//-----------------------------------------------------------------------------

function writeDecimal0(num) {
   if(IsSome(num)=="false") return;
   
   document.write(Math.round(num));
   }


function writeDecimal1(num) {
   if(IsSome(num)=="false") return;

   var i = new String(Math.round(num*10)/10);
   if      (i.length>1 && i.charAt(i.length-2) == ".") {} // do nothing
   else if (i.length>0 && i.charAt(i.length-1) == ".") {i +=  "0";}
   else                                                {i += ".0";}
   document.write(i);
   }


function writeDecimal2(num)  { document.write(returnDecimal2(num));  }
function returnDecimal2(num) {
   if(IsSome(num)=="false") return " "; 

   var i = new String(Math.round(num*100)/100);
   if      (i.length>2 && i.charAt(i.length-3) == ".") {} // do nothing
   else if (i.length>1 && i.charAt(i.length-2) == ".") {i +=   "0";}
   else if (i.length>0 && i.charAt(i.length-1) == ".") {i +=  "00";}
   else                                                {i += ".00";}
   return i;
   }


function writeDecimal4(num)  { document.write(returnDecimal4(num));  }
function returnDecimal4(num) {
   if(IsSome(num)=="false") return " "; 

   var i = new String(Math.round(num*10000)/10000);
   if      (i.length>4 && i.charAt(i.length-5) == ".") {} // do nothing
   else if (i.length>3 && i.charAt(i.length-4) == ".") {i +=     "0";}
   else if (i.length>2 && i.charAt(i.length-3) == ".") {i +=    "00";}
   else if (i.length>1 && i.charAt(i.length-2) == ".") {i +=   "000";}
   else if (i.length>0 && i.charAt(i.length-1) == ".") {i +=  "0000";}
   else                                                {i += ".0000";}
   return i;
   }


function writeDecimal2_noz(num) {
   if(IsSome(num)=="false") return;

   var i = new String(Math.round(num*100)/100);
   document.write(i);
   }


function writeSlash(str) {
   var result = new String("");
   var numChars = 5;
   var ct = 1;
   var idx = 0;
   var i;

   for(i = 0; i < str.length/numChars; i++) {
      temp = str.substring(idx, ct*5);
      blank = temp.indexOf(" ");
      if(blank > 0) // remove trailing blanks
         temp = temp.substring(0, blank);
    
      if(temp.length > 0 && ct == 1)
         result += temp; // no slash on first entry
      else
         result += (" / " + temp);

      ct++;
      idx += 5;
      }
   document.write(result);
   }


function convertDecimalToInt(num) {
   if (typeof num == "number") {
      num = num.toString();
      }
   var offset = num.indexOf(".");

  num = num.substring(0, offset);
  document.write(num);
   }

// ----------------------------------------------------
// writePropertyType()
//STOP USING THIS CRITTER--- SHOULD NOT BE LOCKING THIS STUFF INTO A STD WEB (THEY VARY BY CONTRACT)

//
// This function accepts one of the four table names
// res, cnd, mul, or llf and writes out a string for
// human readability.
//
function writePropertyType(type) {
   // Use a temporary so we don't change what was given to us.
   var tmp = new String(type);
   tmp = tmp.toLowerCase();

   if (tmp == "res") {
      document.write("Residential");
      }
   else if (tmp == "lnd") {
      document.write("Vacant Land");
      }
   else if (tmp == "com") {
      document.write("Commercial");
      }
   else { // Default to spitting out what came in.
      document.write(type);
      }
   }


// ----------------------------------------------------
//STOP USING THIS CRITTER--- SHOULD NOT BE LOCKING THIS STUFF INTO A STD WEB (THEY VARY BY CONTRACT)
// writeStatus()
//
// This function accepts one of the six status names
// act, pend, closd, incom, exp, with and writes out a string for
// human readability.
//
function writeStatus(Stat) {
   // Use a temporary so we don't change what was given to us.
   var tmp = new String(Stat);
   tmp = tmp.toLowerCase();

   if(tmp == "incom") 
      document.write("<font color=\"#ff0000\">Incomplete</font>");
   else if(tmp == "act")
	  document.write("<font color=\"#008000\">Active</font>");
   else if(tmp == "ko")
      document.write("<font color=\"#008000\">Active with a Kick-out</font>");
   else if(tmp == "opt")
      document.write("<font color=\"#008000\">Active with an Option</font>");
   else if(tmp == "con")
      document.write("<font color=\"#008000\">Active with a Contingency</font>");  	
   else if(tmp == "pend" || tmp == "pnd")
	  document.write("<font color=\"#ffa500\">Pending</font>");
   else if(tmp == "closd")
      document.write("<font color=\"#808080\">Closed</font>");
   else if(tmp == "sld")
      document.write("<font color=\"#808080\">Sold</font>");
   else if(tmp == "with" || tmp == "wth")
	  document.write("<font color=\"#800080\">Withdrawn</font>");
   else if(tmp == "can")
	  document.write("<font color=\"#800080\">Cancelled</font>");
   else if(tmp == "tom")
	  document.write("<font color=\"#800080\">Temporarily off the Market</font>");
   else if(tmp == "exp")
      document.write("<font color=\"#000000\">Expired</font>");
   else
      document.write(Stat);
   }


function UpperLower(line) {
   var l1;
   line = new String(line);
   line = line.toUpperCase();
   l1 = new String(line.substring(0, 1));
   line = line.toLowerCase();
   line = l1 + line.substring(1, 255);
   return(line);   
   }

