<!--

// commonFuncs.js




var PicHead = "";
var PicTail = "";
var PicAlign = "";
var iAlign = "";
var pFormat = "";
var tFormat = "";
var FormatCode = "";
var p = "";
var TN = "";
var PFN = "";
var Title = "";
var lineOut = new Array();
//var lineNum = 0;

var jsFORMAT_CODE_POS_I_ALIGN=4;
var jsFORMAT_CODE_POS_PARAGRAPH=1;
var jsFORMAT_CODE_POS_TITLE=2;
var jsSHOW_LISTING=116;

function prepareLineOut(fc)
{

  FormatCode = fc;
  iAlign  = getFormat(FormatCode,jsFORMAT_CODE_POS_I_ALIGN);
  PicHead = "";
  PicTail = "";
  PicAlign = "";
  switch(iAlign){
    case 'R': PicAlign=" align='RIGHT' "; break;
    case 'L': PicAlign=" align='LEFT' "; break;
    case 'C':
      PicAlign = "";
      PicHead = "<div align='center'>";
      PicTail = "</div>"
      break;
  }
  p = p.replace(/<LEAD>/i,'<span id="Leader">');
  p = p.replace(/<\/LEAD>/i,'</span>');
  pFormat = getFormat(FormatCode,jsFORMAT_CODE_POS_PARAGRAPH);
  tFormat = getFormat(FormatCode,jsFORMAT_CODE_POS_TITLE);
  if (TN.length > 0) lineOut[lineOut.length] = PicHead + '<img ' + PicAlign + 'src="' + TN + '">' + PicTail;
  else if (PFN.length > 0) lineOut[lineOut.length] = PicHead + '<img ' + PicAlign + 'src="' + PFN + '">' + PicTail;
  if (tFormat != "NONE") Title = Title.replace(/<[^>]+><\/[^>]+>/g,"");
  if (Title.length > 0){
    if (tFormat != 'NONE') lineOut[lineOut.length] = '<span class="ParagraphTitle">' + Title + '</span>';
    else lineOut[lineOut.length] = Title;
  }
  if (pFormat == "NONE") {
    p = p.replace(/&quot;/g,'"');
    p = p.replace(/&#39;/g,"'");
  }
  if (p.length > 0) lineOut[lineOut.length] = p;
  if (PicAlign = "'RIGHT' ") PicAlign = "'LEFT' ";
  else PicAlign = "'RIGHT' ";
}





function writeThumbnailLine(imgName,w,h,vTourState,vTourTemplate,AgencyNum,PropNum,linkLine,transType)
{
  newH = h;
  newW = w;
  if (w > 120) {
    newW = 120;
    newH = Math.floor((h * (100 / w)) + 0.5);
  } else if (h > 80) {
    newH = 80;
    newW = Math.floor((w * (67 / h)) + 0.5);
  }

//alert("newW: " + newW + "\nnewH: " + newH);



  l = Math.floor((100 - newW) / 2 + 0.5);
  t = Math.floor((67 - newH) / 2 + 0.5);
//alert("left: " + l + "\ntop: " + t);


  tF = '<td><div style="width: 100px; height: 67px; clip: rect(0 99 66 0); overflow: hidden;">';
//alert(tF);

  tL = '<a href="javascript:vTourDisplay(';
  tL = tL + "'" + vTourState + "','" + vTourTemplate + "','" + AgencyNum + "','" + PropNum + "','" + linkLine + "'," + transType + ')">';

  tM = '<img src="' + imgName + '" height="' + newH + '" width="' + newW + '" border="0" style="left: ' + l + 'px; top: ' + t + 'px; position: relative">';
//alert(tM);

  tE = '</a></div></td>';
//alert(tF + "\n" + tL + "\n" + tM + "\n" + tE);
  document.writeln(tF + tL + tM + tE);

}

function log10(x) {return Math.LOG10E * Math.log(x);}


function formatNum(v,n)
{

//alert("v: " + v + "\nn: " + n);
  p = new Array;
  p[0] = 10;
  p[1] = 100;
  p[2] = 1000;
  p[3] = 10000;
  p[4] = 100000;
  p[5] = 1000000;
  z = "0000000000";
  if (n > 6) n = 6;
  if (n < 0) n = 0;
  s = "";
  if (v < 0) s = "-";
  retVal = "";
  v = Math.abs(v);
  f = v - Math.floor(v);
  if (n > 0) f *= p[n-1] + 0.5;
  f = Math.floor(f);
  v = Math.floor(v);
  if (v < 1) retVal = "0";
  while(v >= 1) {
    v = Math.floor(v);
    u = v % 1000;
    v = v / 1000;
    if (v >= 1){
      if (u < 10) t = ",00" + u;
      else if (u < 100) t = ",0" + u;
      else t = "," + u;
    } else t = u;
    retVal = t + retVal;
  }
  retVal = s + retVal;

  if (n > 0){
    if (f == 0) retVal = retVal + "." + z.slice(0,n);
    else {
      u = Math.ceil(n - log10(f)) - 1;
      t = "." + z.slice(0,u) + f;
      retVal = retVal + t;
    }
  }
  retVal = s + retVal;
  return(retVal);
}
    

/*
 * vTourDisplay()
 * Parameters:
 *  serviceType: 0 web site only, 1 v Tour Only, 2 Both
 *
 */


function vTourDisplay(vTourState,vtourTemplate,AgencyNum,PropNum,linkLine,transType)
{

/*
t = "vTourState: " + vTourState;
t = t + "\nvtourTemplate: " + vtourTemplate;
t = t + "\nAgencyNum: " + AgencyNum;
t = t + "\nPropNum: " + PropNum;
t = t + "\nlinkLine: " + linkLine;
t = t + "\ntransType: " + transType;
alert(t);
*/
  if (vTourState.length < 2){
    window.location = linkLine;
    return;
  }

  extractionString = /([^-]*)-(\d)/;
  res = vTourState.match(extractionString);
  if (res != null){
    vTourKey = res[1];
    vTourState = res[2];
  } else {
    alert("Bad Extraction");
  }

  if (AgencyNum.indexOf(".") < 0 || vTourState=='1') lForepart = "http://web1.realestateby.net";
  else lForepart = "http://www." + AgencyNum;
  switch(vTourState){
    case '0':
      window.location = linkLine;
      break;
    case '1': 
      h = lForepart + "/cgi-bin/CompanyInternal?stdout+401+" + AgencyNum + "+101+" + PropNum + "+IE+" + transType + "+" + vtourTemplate;
      window.open(h,"","toolbar=no,location=no,scrollbars=no,width=540,height=440",false);
//      window.location = linkLine;
      break;
    case '2':
      h = lForepart + "/cgi-bin/CompanyInternal?stdout+401+" + AgencyNum + "+101+" + PropNum + "+IE+" + transType + "+" + vtourTemplate;
      window.open(h,"","toolbar=no,location=no,scrollbars=no,width=540,height=440",false);
      window.location = linkLine;
      break;
  }
}






function showFeatured(DynPCode,pageType,homePageNum,IntListingNum,cgiPrefix,AgencyNum,DraftNum)
{
  if (DynPCode  == "FEATURED") return;
  pattern = /\+([^\+]*)\+([^\+]*)\+([^\+]*)\+([^\+]*)\+([^\+]*)/;
  g = window.location + "";
  t = pattern.exec(g);
  if (t == null) return;
  if (t.length < 5) return;
  if (t[1] != "115" || t[4] != "3") return;
  if (pageType != homePageNum) return;
//  IntListingNum = '%s';
  if (IntListingNum.length == 0) return;
  if (IntListingNum == '0') return;
  h = cgiPrefix + "CompanyInternal?stdout+" + jsSHOW_LISTING + "+" + AgencyNum + "+" + DraftNum + "+" + IntListingNum;
  window.open(h,"realestatebynetFeatured","toolbar=no,location=no,scrollbars=yes,width=770,height=800",false);
}






function renderDate(pre,date,post,date_format)
{
  mnths = new Array("January ","February ","March ","April ","May ","June ","July ","August ","September ","October ","November ","December ");
  re = /(\d\d\d\d)-(\d\d)-(\d\d)/;
  dateDecompose = re.exec(date);
  if (dateDecompose == null) return;
  /*
    dateDecompose[1] = year
    dateDecompose[2] = month
    dateDecompose[3] = day
  */


  if (ymd == "0000-00-00") t = pre + "&nbsp;" + post;
  else {
      switch(date_format){
        case 1:
          i = dateDecompose[2] - 1;
          t = pre + mnths[i] + dateDecompose[3] + ", " + dateDecompose[1] + post;
          break;
        case 2:
          t = pre + dateDecompose[2] + "/" + dateDecompose[3] + "/" + dateDecompose[1] + post;
          break;
        default:
          t = pre +  dateDecompose[1] + "-" + dateDecompose[2] + "-" + dateDecompose[3] + post;
          break;
      }
  }
  document.writeln(t);
  return;
}




//-->
