function monthChanged(controlID)
{
    var serverControlPrefix = controlID.substr(0, controlID.lastIndexOf("ddl"));
	
    var objMonth = document.getElementById(serverControlPrefix + "ddlMonth");
    var objYear = document.getElementById(serverControlPrefix + "ddlYear");
    var objDay = document.getElementById(serverControlPrefix + "ddlDay");
	
    var currentMonth;
    var currentYear;
    var opt; // option
    var tempDate;
    var selectedDay;
	
    if ( objMonth && objYear && objDay )
    {
        selectedDay = objDay.selectedIndex;
        currentMonth = objMonth.options[objMonth.selectedIndex].value-1;
        currentYear = objYear.options[objYear.selectedIndex].value;
		
        objDay.options.length = 0;
        if ( currentMonth == -1 || currentYear == 0 )
        {
            return;
        }
        else
        {
            for ( var i=1; i <= 31; i++)
            {
	            tempDate = new Date (currentYear, currentMonth, i);
	            if ( tempDate.getDate() == i )
	            {
		            opt = document.createElement( "OPTION" );
		            opt.text = i;
		            opt.value = i;
		            try
		            {
		                objDay.add ( opt );
		            }
		            catch( e ) 
		            {
		                objDay.add ( opt, null );
		            }
	            }
            }
            if ( selectedDay > objDay.options.length )
            {
	            objDay.selectedIndex = objDay.options.length - 1;
            }
            else
            {
                if ( selectedDay == -1 )
                {
                    selectedDay = selectedDay + 1;
                }
	            objDay.selectedIndex = selectedDay;
            }
        }
    }
}

function MM_nbGroup(event, grpName) { //v6.0 
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;
  if(!d) d=document;
  
  // added by Andrew 8/27/2004 - maybe call this v4.1?
  for (i=0;i<d.forms.length;i++) {
    var j;
    for (j=0;j<d.forms[i].length;j++) {
      if (d.forms[i].elements[j].name.indexOf(n) != -1)
        n=d.forms[i].elements[j].name
    }
  }
  // end added
  
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n);
  
  return x;
}

function isChecked(n, d) { //v4.01
  var p,i,x;
  if(!d) d=document;
  
  // added by Andrew 8/27/2004 - maybe call this v4.1?
  for (i=0;i<d.forms.length;i++) {
    var j;
    for (j=0;j<d.forms[i].length;j++) {
      if (d.forms[i].elements[j].name.indexOf(n) != -1)
        n=d.forms[i].elements[j].name
    }
  }
  // end added
  
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n);
  if (x)
  {
     return x.checked;
  }
  else
  {
	return false;
  }
}

function CheckAsDeleted(n, d) { //v4.01
  var p,i,x;
  if(!d) d=document;
  
  // added by Andrew 8/27/2004 - maybe call this v4.1?
  for (i=0;i<d.forms.length;i++) {
    var j;
    for (j=0;j<d.forms[i].length;j++) {
      if (d.forms[i].elements[j].name.indexOf(n) != -1)
        n=d.forms[i].elements[j].name
    }
  }
  // end added
  
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && d.getElementById) x=d.getElementById(n);
  if (x)
  {
     return x.value="Y";
  }
  else
  {
	return x.value="";
  }
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var sDate = new Array();
var mName = new Array("January","February","March","April","May","June","July","August","September","October","November","December")
var wName = new Array("Su","Mo","Tu","We","Th","Fr","Sa")
var cFontName = "Arial, Helvetica, sans-serif;"
var KW_color = new Array("#ffffff","#ffcccc","#999999","#ffffff","#ccffcc","#cccccc","#000000","#000000")
var KW_cl=0;
var KW_od=-1;
var KW_tmo=0;
var KW_cWidth=170;
var KW_fd=-1;
var KW_ss=0;
var KW_sw=0;
var descx=-1;
var descy=-1;
var bwNN=(document.captureEvents)?1:0;
function popmousemove(e){descx=(bwNN)?e.pageX:event.x;descy=(bwNN)?e.pageY:event.y}
function KW_mouseInit(){
	if(bwNN)document.captureEvents(Event.MOUSEMOVE);document.onmousemove=popmousemove;
}
function m_class(m,d,y) {
	this.month=m;this.day=d;this.year=(y%100<10)?"0"+y%100:y%100;this.output=this.month+"/"+this.day+"/"+this.year;
	var kd=new Date();this.special=checkDates(this.month,this.day,this.year)
	this.today=((kd.getMonth()+1)==this.month && kd.getDate()==this.day && kd.getFullYear()==this.year)
	var td=new Date(this.year, (this.month-1), this.day+KW_od);this.past=(KW_od==-1)?0:(kd>td)
	var tf=new Date(kd.getFullYear(),kd.getMonth(),kd.getDate()+KW_fd);
	var d1=new Date(this.year, (this.month-1), this.day);
	this.future=(KW_fd==-1)?0:(tf<d1);this.ss=(this.special && KW_ss);
	this.display=(this.past || this.future || this.ss);
}


function checkDates(m1,d1,y1) { //v2.1.5
	var rStr=false;for(var i=0;i<sDate.length;i++) {var tDate=sDate[i].split(",");
		if (tDate[2]=="*" || tDate[2]==y1) {if (tDate[1]==d1 && tDate[0]==m1)	rStr=true;
		}}return rStr;
}

function KW_doCalendar(obj,E,m,y) { //v2.6.0
  var d=new Date();f=0;d.setDate(1);if (!m && m!=0) {m=d.getMonth();f=KW_cl}
  if (f==1 && MM_findObj('KW_selectedMonth').value!=-1)
  m=MM_findObj('KW_selectedMonth').value-1;d.setMonth(m);
  if (!y) y=d.getFullYear();if (f==1 && MM_findObj('KW_selectedYear').value!=-1)
  y=MM_findObj('KW_selectedYear').value;d.setFullYear(y);dy=d.getDay();if (!E) E=0;
  if(E==1)dy=(dy==0)?6:dy-1;dP=new Date();dP.setDate(1);dP.setMonth(m);dP.setDate(0);
  pStart=dP.getDate()-dy+1;dStr=new Array();for (i=pStart;i<dP.getDate()+1;i++) { tmo=(KW_tmo)?"":i;
  tMonth=(m==0)?"12":m;tYear=(m==0)?y-1:y;dStr[dStr.length]=new m_class(tMonth,tmo,tYear);
  }EOM=false;for (i=1;!EOM;i++){d.setDate(i);if (m!=d.getMonth()) EOM=true; else {
  dStr[dStr.length]=new m_class((Number(m)+1),i,y);}}cnt=1;si=0;
  if(E==1)si=(d.getDay()==0)?6:d.getDay()-1;else si=d.getDay();	for (i=si;i<7;i++) {
  tMonth=(m==11)?"1":Number(m)+2;tYear=(m==11)?Number(y)+1:y; tmo=(KW_tmo)?"":cnt;
  dStr[dStr.length]=new m_class(tMonth,tmo,tYear); cnt++;}pM=(m==0)?11:m-1;
  pY=(m==0)?y-1:y;nM=(m==11)?0:Number(m)+1;nY=(m==11)?Number(y)+1:y;
  wStr="<ht"+""+"ml><he"+""+"ad><st"+""+"yle type=\"text/css\"><!--  body { background-color: "+KW_color[6]+"}\ntd {  font-family: "+cFontName+" font-size: 12px; }\n.tblHdr { font-weight: bold; color: "+KW_color[0]+"; background-color: "+KW_color[6]+" }\n.subTbl{ color: "+KW_color[0]+"; background-color: "+KW_color[7]+";  text-align: center}-->\n</st"+""+"yle>\n<ti"+""+"tle>"+mName[m]+", "+y+"</ti"+""+"tle>\n</he"+""+"ad>\n<bo"+""+"dy  topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\" leftmargin=\"0\" onLoad=\"window.focus()\">\n<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n<tr>\n<td bgcolor=\""+KW_color[6]+"\">\n<table width=\"100%\" border=0>\n"
  wStr+="<tr>\n<td align=center bgcolor=\""+KW_color[6]+"\" class=\"tblHdr\" colspan=\"4\"><a href=\"javascript:window.opener.KW_doCalendar('"+obj+"',"+E+",'"+pM+"','"+pY+"');\" class=\"tblHdr\">&laquo</a>&nbsp;&nbsp;"+mName[m]+"&nbsp;&nbsp;<a href=\"javascript:window.opener.KW_doCalendar('"+obj+"',"+E+",'"+nM+"','"+nY+"');\"  class=\"tblHdr\">&raquo</a></td>\n<td colspan=3 align=center class=\"tblHdr\"><a href=\"javascript:window.opener.KW_doCalendar('"+obj+"',"+E+",'"+m+"','"+(y-1)+"');\" class=\"tblHdr\">&laquo</a>&nbsp;&nbsp;"+y+"&nbsp;&nbsp;<a href=\"javascript:window.opener.KW_doCalendar('"+obj+"',"+E+",'"+m+"','"+(Number(y)+1)+"');\"  class=\"tblHdr\">&raquo</a></td>\n</tr>\n"
  wStr+="<tr>\n";for(wdn=0;wdn<7;wdn++)wStr+="<td class=\"subTbl\">"+wName[wdn]+"</td>\n";wStr+="</tr>\n"
  for (x=0;x<parseInt(dStr.length/7);x++) {	wStr+="<tr>\n";	for (y=0;y<7;y++) {
  yT=(E==1)?5:0;bC=(y==yT||y==6)?KW_color[2]:KW_color[3];
  if ((y==yT||y==6) && KW_sw && !dStr[x*7+y].display) dStr[x*7+y].display=true;
  if ((Number(m)+1)!=dStr[x*7+y].month) bC=KW_color[5]; if (dStr[x*7+y].special)
  bC=KW_color[4];if (dStr[x*7+y].today) bC=KW_color[1];
  a0=(KW_cl!=1)?"":"window.opener.MM_findObj('KW_selectedMonth',window.opener.document).value='"+dStr[x*7+y].month+"';window.opener.MM_findObj('KW_selectedYear',window.opener.document).value='"+dStr[x*7+y].year+"'; "
  a1=(dStr[x*7+y].display)?"":"<a href=\"javascript:window.opener.MM_findObj('"+obj+"',window.opener.document).value='"+dStr[x*7+y].output+"';"+a0+" window.close();\" >";
  a2=(dStr[x*7+y].display)?"":"</a>";
  wStr+="<td align=\"center\" bgcolor="+bC+">"+a1+dStr[x*7+y].day+a2+"</td>\n";
	}	wStr+="</tr>\n";}	wStr+="<tr><td colspan=7></td></tr></table></td></tr></table></bo"+""+"dy></ht"+""+"ml>";
	var w;var h;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
	var screenX=(self.screenX)?self.screenX+20:window.screenLeft
	var screenY=(self.screenY)?self.screenY+70:window.screenTop
	w =(descx==-1)?parseInt(screen.width/2-75):descx+screenX;
	h=(descy==-1)?parseInt(screen.height/2-75):descy+screenY;
	if (isNaN(w)) w=descx+20
	if (isNaN(h)) h=descy+70
	} else {
	w=getAnchorWindowPosition(MM_findObj(obj).name).x;
	h=getAnchorWindowPosition(MM_findObj(obj).name).y;
	}
	
	
	var look='width='+KW_cWidth+',height=155,left='+w+',top='+h;	popwin=window.open('','calendar',look);
	popwin.document.open();	popwin.document.write(wStr);	popwin.document.close();
}

// This is a global variable used
// for passing data from the modal dialog
// back to the caller of doPopup
var _modalDialogReturnValue;

// Purpose: Launch an aspx page in a modal dialog window.
// Note that single letter variable names are used to maintain
// a smaller code foot print on the client. --> all comments should be stripped before sending.
function doPopup(title, controlUrl, height, width)
{
// Prepare shell htm for launching control

  var strHTML = ''
  strHTML = strHTML + '<html>';
  strHTML = strHTML + '  <head>';
  strHTML = strHTML + '    <title>' + title + '</title>';
  strHTML = strHTML + '    <script language="JavaScript" type="text/javascript" src="resnetjs.js"></script>';
  strHTML = strHTML + '  </head>';
  strHTML = strHTML + '  <body id="modalBody" name="modalBody" topmargin="0" marginwidth="0" marginheight="0" leftmargin="0" style="background-color: #FFFFCC;">';
  strHTML = strHTML + '    <iframe id="modalIFrame" name="modalIFrame" width="100%" height="100%" src="' + controlUrl + '" frameborder="0" scrolling="no"></iframe>';
  strHTML = strHTML + '  </body>';
  strHTML = strHTML + '</html>';

// Calculate coordinates of popup. -- center
  //var x = window.screenX + ((window.outerWidth - width) / 2)
  //var y = window.screenY + ((window.outerHeight - height) / 2)
  var flags = "scroll=no,modal=yes,screenX=" + x + ",screenY=" + y + ",resizable=yes,width=" + width + ",height=" + height;
  
  var x = (screen.width - width) / 2;
	var y = (screen.height - height) / 2;
	
	flags = "scroll=no,modal=yes,left=" + x + ",top=" + y + ",resizable=yes,width=" + width + ",height=" + height;
  
//open the modal dialog
  w=window.open('', 'popupWin', flags);

//write the html content to the window
  w.document.open();
  w.document.write(strHTML);
  w.document.close();

  // Since this method of popup is non-blocking
  // this value is not used... -- see doClosePopup  
  return _modalDialogReturnValue;
 
};
function doPopUPPrintPostcard(ctrl){
		window.open(ctrl);
}
function doPopUpAgentAnnouncement(control){
		doPopupCustom("Featured Property Demo",control,320,820);
}
function doPopUpEditContactInfo(control){
	doPopupCustom("Edit Contact Info",control,650,830);
};

// Purpose: Launch an aspx page in a modal dialog window.
// Note that single letter variable names are used to maintain
// a smaller code foot print on the client. --> all comments should be stripped before sending.
function doPopupCustom(title, controlUrl, height, width, flags)
{
// Prepare shell htm for launching control

  var strHTML = ''
  strHTML = strHTML + '<html>';
  strHTML = strHTML + '  <head>';
  strHTML = strHTML + '    <title>' + title + '</title>';
  strHTML = strHTML + '    <script language="JavaScript" type="text/javascript" src="resnetjs.js"></script>';
  strHTML = strHTML + '  </head>';
  strHTML = strHTML + '  <body id="modalBody" name="modalBody" topmargin="0" marginwidth="0" marginheight="0" leftmargin="0" style="background-color: #FFFFCC;">';
  strHTML = strHTML + '    <iframe id="modalIFrame" name="modalIFrame" width="100%" height="100%" src="' + controlUrl + '" frameborder="0" scrolling="yes"></iframe>';
  strHTML = strHTML + '  </body>';
  strHTML = strHTML + '</html>';

	// Calculate coordinates of popup. -- center
	  var x = window.screenX + ((window.outerWidth - width) / 2)
	  var y = window.screenY + ((window.outerHeight - height) / 2)
	  flags += ",screenX=" + x + ",screenY=" + y + ",resizable=yes,width=" + width + ",height=" + height;

	var x = (screen.width - width) / 2;
	var y = (screen.height - height) / 2;

	flags += ",left=" + x + ",top=" + y + ",resizable=yes,width=" + width + ",height=" + height;
	
	//open the modal dialog
	  
	w=window.open('', '_blank', flags);
	
	//write the html content to the window
	w.document.open();
	w.document.write(strHTML);
	w.document.close();
  
  // Since this method of popup is non-blocking
  // this value is not used... -- see doClosePopup  
  return;
 
};

// Purpose: Launch an aspx page in a modal dialog window.
// Note that single letter variable names are used to maintain
// a smaller code foot print on the client. --> all comments should be stripped before sending.
function doPopupCustomLender(title, controlUrl, height, width, flags, state)
{
// Prepare shell htm for launching control


  var strHTML = ''
  strHTML = strHTML + '<html>';
  strHTML = strHTML + '  <head>';
  strHTML = strHTML + '    <title>' + title + '</title>';
  strHTML = strHTML + '    <script language="JavaScript" type="text/javascript" src="resnetjs.js"></script>';
  strHTML = strHTML + '  </head>';
  strHTML = strHTML + '  <body id="modalBody" name="modalBody" topmargin="0" marginwidth="0" marginheight="0" leftmargin="0" style="background-color: #FFFFCC;">';
  strHTML = strHTML + '    <iframe id="modalIFrame" name="modalIFrame" width="100%" height="100%" src="' + controlUrl + '" frameborder="0" scrolling="no"></iframe>';
  strHTML = strHTML + '  <form action="' + controlUrl + '" name="frmloanweb" method="POST">';
  strHTML = strHTML + '  <input type="hidden" name="field1" value="0">';
  strHTML = strHTML + '  <input type="hidden" name="field2" value="' + state + '">';
  strHTML = strHTML + '  <input name="headerpk" type="hidden" value="36" /> ';
  strHTML = strHTML + '  <input type="hidden" name="field4" value="9999"> ';
  strHTML = strHTML + '  </form>';
  strHTML = strHTML + '  </body>';
  strHTML = strHTML + '</html>';

	// Calculate coordinates of popup. -- center
	//  var x = window.screenX + ((window.outerWidth - width) / 2)
	//  var y = window.screenY + ((window.outerHeight - height) / 2)
	//  flags += ",screenX=" + x + ",screenY=" + y + ",resizable=yes,width=" + width + ",height=" + height;

	var x = (screen.width - width) / 2;
	var y = (screen.height - height) / 2;

	flags += ",left=" + x + ",top=" + y + ",resizable=yes,width=" + width + ",height=" + height;
	
	//open the modal dialog
	  
	w=window.open('', '_blank', flags);
	
	//write the html content to the window
	w.document.open();
	w.document.write(strHTML);
	w.document.frmloanweb.submit();
	w.document.close();
  
  // Since this method of popup is non-blocking
  // this value is not used... -- see doClosePopup  
  return;
 
};


// Method attached to buttons in modal dialog to close and set return values
function doClosePopup(returnValue, targetElementID)
{
  parent.self.close();
  MM_findObj(targetElementID,parent.opener.document).value=returnValue;
}; 


// This function fills DateTime on DDL control in the 

function FillDateCorrect(ctrlDayName,ctrlMonthName,ctrlYearName){
				ddlDay = document.getElementById(ctrlDayName);        
				ddlMonth = document.getElementById(ctrlMonthName);
				ddlYear = document.getElementById(ctrlYearName);
				
				date = new Date();
				year = date.getFullYear();
				month = date.getMonth();
				
				if(ddlYear != null)
				{
						if(ddlYear.options[ddlYear.selectedIndex].value != '')
						{					
								year = ddlYear.options[ddlYear.selectedIndex].value;	
						}
				}
				if(ddlMonth != null)
				{					
						if(ddlMonth.options[ddlMonth.selectedIndex].value != '')
						{				
								month  = ddlMonth.options[ddlMonth.selectedIndex].value;										
						}
				}
				tempD = ddlDay.value;
				maxDays = 0;
				months31 = new Array(1,3,5,7,8,10,12);
				months30 = new Array(4,6,9,10,11);
				m_31 = false;
				m_30 = false;
				leap = false;
				for(i=0;i<months31.length;i++)
				{
						if(months31[i] == month)
						{
								m_31 = true;
								maxDays = 31;
						}
				}
				if(!m_31)
				{
						for(i=0;i<months30.length;i++){
								if(months30[i] == month)
								{
										m_30 = true;
										maxDays = 30;
								}	
						}
				}
				
				if(!m_31 && !m_30)
				{
						if(month == 2){
								leap = (year % 4 == 0 && (year % 100 == 0 || year % 400 ==0));
						}
						if(leap)
						{
								maxDays = 29;
						}
						else
						{
								maxDays = 28;
						}
				}
				for(i=31;i>0;i--)
				{
						ddlDay.options[i] = null;
				}				
				day = -1;
				for(i=0;i<maxDays; i++)
				{
						var option = new Option(i+1,i+1);
						ddlDay.options[i] = option;
						if(i == tempD)
						{
								day = i;
						}		
				}	
				if(day == -1)
				{
						ddlDay.value = maxDays;
				}
				else
				{
						ddlDay.value = day;
				}
		}			
//***********************************************************
// The following functions are called by the aspx code to
// launch various Modal Popup windows. Each doXxxx method
// is paired with a popup control specified as a JavaScript
// parameter.
//***********************************************************

//***************** ASSET MANAGER ****************************************************
function doAssetManagerPopUp(virtualPath, namingContainer, parentForm, doPostBack, showInactive)
{
  // Popup Asset manager dialog to allow the user to select an asset manager.
  var strURL = virtualPath + '/accountselect.aspx?template=popUpRTRAC';
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (parentForm) strURL += '&pf='+parentForm;
  if (doPostBack) strURL += '&dp='+doPostBack;
  if (showInactive) strURL += '&ActiveOnly=false';

  doPopupCustom('Select Asset Manager',strURL,500,728,'scroll=auto');
}

function doCloseAccount(userID, firstName, lastName, namingContainer, parentForm, doPostBack, email)
{
  var doc = parent.opener.document;
  var obj;
  
  parent.self.close();
  if (parentForm)  parentForm = parentForm.toLowerCase();

  if ((parentForm)&&(parentForm.indexOf('cnradminaddassetmanagers')>-1)) {
    //Handle case when called by AMS/WebUI/Admin/cnrAdminAddAssetManagers.ascx. 
    SetTextBoxWebControlValue(doc, namingContainer+'ctlHiddenAssetManagerId', userID);
  }

  //Handle case when called by Aggregator/WebUI/Admin/cnrAdminAddAggrAgent.ascx
  if ((parentForm)&&(parentForm.indexOf('cnradminaddaggragent')>-1)) {		
    SetTextBoxWebControlValue(doc, namingContainer+'ctlHiddenClientId', userID);
  }
	//Handle case when called by AMS/WebUI/Admin/cnrAdminAddAgent.ascx
  if ((parentForm)&&(parentForm.indexOf('cnradminaddagent')>-1)) {				
		SetTextBoxWebControlValue(doc, namingContainer+'ctlHiddenClientId', userID);	
  }

  else if ((parentForm)&&(parentForm.indexOf('cnreditsysclient')>-1)) {
    //Handle case when called by AMS/WebUI/Admin/cnrAdminAddAssetManagers.ascx. 
    SetTextBoxWebControlValue(doc, namingContainer+'ctlHiddenSysClientId', userID);
  } else {
    //Called by one of the following:
    //   ctlAMSClosingReport
    //   ctlAMSExpenseReport
    //   ctlAMSInventoryReport
    //   ctlAMSSalesReport
    //   ctlAMSTaskReport
    //   ctlPropertyInformation
    
    //Update asset manager id control (if it exists)
    SetTextBoxWebControlValue(doc, namingContainer+'txtPropertyInformationAssetManagerId', userID);

    //Update asset manager name control (if it exists)
    //SetLabelWebControlValue(doc, namingContainer+'ctlName', firstName+' '+lastName);
    SetNavigateUrlAndText(doc, namingContainer+'hplAssetManagerName', "MailTo:"+email, firstName+' '+lastName);
  }
  
  //Do a postback, if desired
  if (doPostBack == "True") {
    //Do a postback
    parent.opener.__doPostBack('', '');
  }
}

function doAddPropertyPopUp(virtualPath, namingContainer, targetActionControlID) {
  var strURL = virtualPath + '/Common/PageFactory.aspx?control=/Common/WebUI/PopUp/ctlPropAdd';
 
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (targetActionControlID) strURL += '&ac='+targetActionControlID;
  MM_openBrWindow(strURL,'','menubar=no, modal=yes, width=800, height=550');
}

function doCloseAddPropertyPopup(returnValue, targetElementID, actionTargetID)
{
  parent.self.close();
  MM_findObj(targetElementID,parent.opener.document).value=returnValue;
  parent.opener.__doPostBack(actionTargetID, '');
}; 

//***************** Aggregator Agent POPUP ******************************************

function	doAggrAgentPopUp(virtualPath, namingContainer, parentForm, doPostBack, title)
{
  // Popup Client dialog to allow the user to select a Aggregator Agent.
  var strURL = virtualPath + '/Common/PageFactory.aspx?control=/Common/WebUI/PopUp/ctlAggregatorsSelect&template=popUpRTRAC';
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (parentForm) strURL += '&pf='+parentForm;
  if (doPostBack) strURL += '&dp='+doPostBack;
  
  doPopup(title,strURL,500,728);
}

//***************** Agent POPUP ******************************************

function	doAgentPopUp(virtualPath, namingContainer, parentForm, doPostBack)
{
  // Popup Client dialog to allow the user to select a Aggregator Agent.
  //var strURL = 'factory2.aspx?control=/Common/WebUI/PopUp/ctlAgntsSelect&template=popUpRTRAC';
  var strURL = virtualPath + '/Common/PageFactory.aspx?control=/AMS/WebUI/popupSelectAgent&template=popUpRTRAC&mode=admin&ActiveOnly=false';
  
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (parentForm) strURL += '&pf='+parentForm;
  if (doPostBack) strURL += '&dp='+doPostBack;
  
  doPopupCustom('Select Agent',strURL,500,768,'scroll=auto');
}

//***************** CLIENT POPUP ****************************************************
function doClientPopUp(virtualPath, namingContainer, parentForm, doPostBack, showInactive)
{
	var det = '';
	var h = 500;
	var w = 800;
  if (parentForm)  parentForm = parentForm.toLowerCase();
  if ((parentForm)&&(parentForm.indexOf('ctlpropertyinformation')>-1)) {
		det = 'yes';
		h = 550;
		w = 850;
  }  

  // Popup Client dialog to allow the user to select a client.
  var strURL = virtualPath + '/Common/PageFactory.aspx?control=/Common/WebUI/PopUp/ctlClientSelect&template=POPUPRTRAC&det=' + det;
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (parentForm) strURL += '&pf='+parentForm;
  if (doPostBack) strURL += '&dp='+doPostBack;
  if (showInactive) strURL += '&ActiveOnly=false';

  doPopupCustom('Select Client',strURL,h,w,'scroll=auto');
}

function doCloseClient(clientID, clientName, clientPrimaryContact, clientPrimaryContactPhone, namingContainer, parentForm, doPostBack, clientPrimaryContactID, PrimaryContactEmail)
{
  var doc = parent.opener.document;
  var obj;
  
  parent.self.close();
  if (parentForm)  parentForm = parentForm.toLowerCase();
  //Handle case when called by AMS/WebUI/Admin/cnrAdminAddClient.ascx. 
  if ((parentForm)&&(parentForm.indexOf('cnradminaddclient')>-1)) {
    SetTextBoxWebControlValue(doc, namingContainer+'ctlHiddenClientId', clientID);
  }
 
  //Handle case when called by any of the report screens
  if ((parentForm)&&(parentForm.indexOf('report')>-1)) {
    SetTextBoxWebControlValue(doc, namingContainer+'txtClient', clientID);
  }

  //Handle case when called by AMS/WebUI/Admin/ctlPropertyInformation.ascx. 
  if ((parentForm)&&(parentForm.indexOf('ctlpropertyinformation')>-1)) {
    //Update client id control (if it exists)
    SetTextBoxWebControlValue(doc, namingContainer+'txtPropertyinformationClientID', clientID);

    //Update client name control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblPropertyinformationClientName', clientName);

    //Update client primary contact control (if it exists)
    //SetLabelWebControlValue(doc, namingContainer+'hplPropertyinformationClientPrimaryContact', clientPrimaryContact);
    SetNavigateUrlAndText(doc, namingContainer+'hplPropertyinformationClientPrimaryContact', 'MailTo:'+PrimaryContactEmail, clientPrimaryContact);

    //Update client primary contact phone control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblPropertyinformationClientPrimaryContactPhone', clientPrimaryContactPhone);
  
    //Update client primary contact ID control (if it exists)
    SetTextBoxWebControlValue(doc, namingContainer+'txtClientContactID', clientPrimaryContactID);
  }
  
  //Do a postback, if desired
  if (doPostBack == "True") {
    //Do a postback
    parent.opener.__doPostBack('', '');
  }
}

//***************** ATTORNEY POPUP ****************************************************
function doAttorneyPopUp(virtualPath, namingContainer, parentForm, doPostBack, showInactive)
{
  var det = '';
  if (parentForm)  parentForm = parentForm.toLowerCase();
  if ((parentForm)&&(parentForm.indexOf('ctleviction')>-1)) {
		det = 'yes';
  }
  if ((parentForm)&&(parentForm.indexOf('ctlforeclosureinformation')>-1)) {
		det = 'yes';
  }  
  if ((parentForm)&&(parentForm.indexOf('ctlpropclosing1')>-1)) {
		det = 'yes';
  }  
  // Popup Attorney dialog to allow the user to select a attorney.
  var strURL = virtualPath + '/Common/PageFactory.aspx?control=/Common/WebUI/PopUp/ctlAttorneySelect&template=popUpRTRAC&det=' + det;
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (parentForm) strURL += '&pf='+parentForm;
  if (doPostBack) strURL += '&dp='+doPostBack;
  if (showInactive) strURL += '&ActiveOnly=false';

  doPopupCustom('Select Attorney',strURL,550,728,'scroll=auto');
}

function doCloseAttorney(companyID, attorneyID, attorneyName, attorneyPrimaryContact, attorneyPrimaryContactPhone, attorneyPrimaryContactEmail, attorneyPrimaryContactFax, namingContainer, parentForm, doPostBack)
{
  var doc = parent.opener.document;
  var obj;
  
  parent.self.close();
  if (parentForm)  parentForm = parentForm.toLowerCase();
  if ((parentForm)&&(parentForm.indexOf('cnradminaddattorney')>-1)) {
    //Handle case when called by AMS/WebUI/Admin/cnrAdminAddAttorney.ascx. 
    obj=MM_findObj(namingContainer+'ctlHiddenAttorneyId', doc);
    if (obj) obj.value=attorneyID;
  }
  
  //Handle case when called by AMS/WebUI/Admin/ctlEviction.ascx. 
  if ((parentForm)&&(parentForm.indexOf('ctleviction')>-1)) {
    //Update client id control (if it exists)
    SetTextBoxWebControlValue(doc, namingContainer+'txtEvictionAttnyId', attorneyID);

    //Update client name control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblAttnyCompanyName', attorneyName);

    //Update client primary contact control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblAttnyContact', attorneyPrimaryContact);

    //Update client primary contact phone control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblAttnyPhone', attorneyPrimaryContactPhone);
  }
  
  //Handle case when called by AMS/WebUI/Admin/ctlForeclosureInformation.ascx
  if ((parentForm)&&(parentForm.indexOf('ctlforeclosureinformation')>-1)) {
    //Update client id control (if it exists)
    SetTextBoxWebControlValue(doc, namingContainer+'hdnAttnyContactID', attorneyID);

    //Update client id control (if it exists)
    SetTextBoxWebControlValue(doc, namingContainer+'txtCompanyId', companyID);

    //Update client name control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblCompanyName', attorneyName);

    //Update client primary contact control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblContactName', attorneyPrimaryContact);

    //Update client primary contact phone control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblContactPhone', attorneyPrimaryContactPhone);

    //Update client primary contact email control (if it exists)
    SetNavigateUrlAndText(doc, namingContainer+'hplContactEmail', "MailTo:"+attorneyPrimaryContactEmail, attorneyPrimaryContactEmail);
		//SetNavigateUrl(doc, namingContainer+'hplContactEmail', 'MailTo:' + attorneyPrimaryContactEmail);    
    //SetLabelWebControlValue(doc, namingContainer+'hplContactEmail', attorneyPrimaryContactEmail);    

    //Update client primary contact fax control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblContactFax', attorneyPrimaryContactFax);    
  }
  //Handle case when called by AMS/WebUI/Admin/ctlPropClosing1.ascx
  if ((parentForm)&&(parentForm.indexOf('ctlpropclosing1')>-1)) {
    //Update client id control (if it exists)
    SetTextBoxWebControlValue(doc, namingContainer+'txtContactId', attorneyID);

    //Update client name control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblCompanyName', attorneyName);

    //Update client primary contact control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblContactName', attorneyPrimaryContact);

    //Update client primary contact phone control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblContactPhone', attorneyPrimaryContactPhone);

    //Update client primary contact email control (if it exists)
    SetNavigateUrlAndText(doc, namingContainer+'hplContactEmail', "MailTo:"+attorneyPrimaryContactEmail, attorneyPrimaryContactEmail);
    
    //Update client primary contact fax control (if it exists)
    SetLabelWebControlValue(doc, namingContainer+'lblContactFax', attorneyPrimaryContactFax);    

    var obj1=MM_findObj(namingContainer+'lnkEmailClosingInstraction', doc);
    if (obj1) {
      obj1.style.visibility = 'hidden'; 
    }
    // we have to show label for displaying of info that email is not anaibled now
    obj1=MM_findObj('divEmailClosingInstractionDisabled', doc);
    if (obj1) {
      obj1.style.visibility = 'visible'; 
      obj1.style.display = 'block';
    }
    //"_ctl0_UltraWebTab1__ctl4__ctl0_ctlPropClosing_lnkEmailClosingInstraction" 
  }
  
  //Do a postback, if desired
  if (doPostBack == "True") {
    //Do a postback
    parent.opener.__doPostBack('', '');
  }
}

//***************** CONTACT ****************************************************
function doSelectContact(virtualPath, namingContainer)
{
  // Popup Select contact dialog to allow to select contact from list.
  // doPopup('Select Contact', '/ContactSelect.aspx?template=popUpRTRAC&Category=1&nc='+namingContainer,500,728);
  doPopup('Select Contact', virtualPath + '/Common/PageFactory.aspx?control=/AMS/WebUI/popupSelectContact&template=popUpRTRAC&nc='+namingContainer,550,728);
}
  
function doCloseContact(contactId, companyId, companyName, contactName, contactPhone, contactEmail, namingContainer)
{
  parent.self.close();
  MM_findObj(namingContainer+'txtContactId', parent.opener.document).value=contactId;
  MM_findObj(namingContainer+'lblCompanyName', parent.opener.document).innerHTML=companyName;
  MM_findObj(namingContainer+'lblContactName', parent.opener.document).innerHTML=contactName;
  //MM_findObj(namingContainer+'hplContactEmail', parent.opener.document).innerHTML=contactEmail;
  //MM_findObj(namingContainer+'hplContactEmail', parent.opener.document).href='MailTo:' + contactEmail;
  SetNavigateUrl(parent.opener.document, namingContainer+'hplContactEmail', 'MailTo:' + contactEmail);
 	SetLabelWebControlValue(parent.opener.document, namingContainer+'hplContactEmail', contactEmail);    
 	
  MM_findObj(namingContainer+'lblContactPhone', parent.opener.document).innerHTML=contactPhone;
}
// ******************************************************************************

//***************** Agent ****************************************************
function doSelectAgent(virtualPath, namingContainer)
{
  // Popup Asset manager dialog to allow the user to select an agent.
  doPopupCustom('Select Agent', virtualPath + '/Common/PageFactory.aspx?control=/AMS/WebUI/popupSelectAgent&template=popUpRTRAC&nc='+namingContainer,500,768,'scroll=auto');
}

function doCloseAgent(Id, firstName, lastName, companyName, city, state, zipCode, phone, email, namingContainer)
{
  parent.self.close();
  MM_findObj(namingContainer+'pd1AgentId' ,parent.opener.document).value=Id;
  MM_findObj(namingContainer+'lblCompany' ,parent.opener.document).innerHTML=companyName;
  MM_findObj(namingContainer+'lblAgentName' ,parent.opener.document).innerHTML=firstName+' '+lastName;
  MM_findObj(namingContainer+'lblPhone' ,parent.opener.document).innerHTML=phone;
  //MM_findObj(namingContainer+'hplEmail' ,parent.opener.document).innerHTML=email;
  //MM_findObj(namingContainer+'hplEmail' ,parent.opener.document).href='MailTo:' + email;
	SetNavigateUrlAndText(parent.opener.document, namingContainer+'hplEmail', 'MailTo:' + email, email);
}

//***************** PROPERTY EXPENSE ****************************************************
function doEditExpenseItem(virtualPath, situsID, expenseID)
{
  // Popup EditExepense dialog to allow the user to edit a property expense item
  doPopup('Edit Expense', virtualPath + '/Common/PageFactory.aspx?control=/AMS/WebUI/popupEditPropExpenseItem&template=popUpRTRAC&SitusID='+situsID+'&ExpenseID='+expenseID,300,750);
}
function doCloseEditExpenseItem()
{
  parent.self.close();
  parent.opener.__doPostBack('', '');
}
// ******************************************************************************

function setUploadSessionID(togSessionID)
{	

	document.getElementById('_ctl0_txtSessionID').value = togSessionID;  	
  __doPostBack('_ctl0$cmdLink','');

}

//***************** PROPERTY REPAIR ****************************************************
function doEditRepairItem(virtualPath, situsID, repairID)
{
  // Popup Edit Repair dialog to allow the user to edit a property repair item
  doPopup('Edit Repair Item', virtualPath + '/Common/PageFactory.aspx?control=/AMS/WebUI/popupEditPropRepairItem&template=popUpRTRAC&SitusID='+situsID+'&RepairID='+repairID,300,750);
}
function doCloseRepairItem()
{
  parent.self.close();
  parent.opener.__doPostBack('', '');
}
// ******************************************************************************

//***************** PROPERTY TASK ITEM ****************************************************
function doEditPropTaskItem(virtualPath, situsID, taskID)
{
  // Popup Edit Task dialog to allow the user to edit a property task item
  doPopup('Edit Task Item', virtualPath + '/Common/PageFactory.aspx?control=/AMS/WebUI/popupEditPropTaskItem&template=popUpRTRAC&SitusID='+situsID+'&TaskID='+taskID,250,700);
}
function doClosePropTaskItem()
{
  parent.self.close();
  parent.opener.__doPostBack('', '');
}
//****************** AM Property Comment EditPopUp *******************************************************
function doOpenAMCommentEdit(virtualPath, commentID)
{
  // Popup EditComment dialog to allow the user to edit a property comment
  doPopup('Edit Comment', virtualPath + '/Common/PageFactory.aspx?control=/Common/WebUI/PopUp/ctlPopupEditAMComment&template=popUpRTRAC&commentID='+commentID,300,750);
}
function doCloseAMCommentEdit()
{
  parent.self.close();
  parent.opener.__doPostBack('', '');
}
// ******************************************************************************
// ******************************************************************************

//***************** OFFERS AND COUNTERS ****************************************************
//function doChangeOfferListSort(SortBy, eventTarget) {
//  var v = document.getElementById("SortBy")
//  if (v) {
//	v.value = SortBy;
//	__doPostBack(eventTarget, '');
//  }
//}
function doChangeOfferStatus(statusID, offerID) {
  var v = document.getElementById("statusID")
  
  if (v) {
	v.value = offerID + "," + statusID;
	__doPostBack('', 'UpdateStatus');
  }
}

function changeStatus(OptionMask, OfferID,evt)
{
	var width=200;
	var height = 100;
	var strHTML = '';
	
	strHTML = strHTML + '<html><form>';
	strHTML = strHTML + '  <body id="modalBody" name="modalBody" topmargin="0" marginwidth="0" marginheight="0" leftmargin="0" style="background-color: #FFFFCC;">';
	
	//Possible options
	if (OptionMask & 1){
		strHTML = strHTML + '  <a href="javascript:window.opener.doChangeOfferStatus(0,' + OfferID + ');window.close();">Submitted</a><br> ';
	};

	if (OptionMask & 2){
		strHTML = strHTML + '  <a href="javascript:window.opener.doChangeOfferStatus(1,' + OfferID + ');window.close();">Cancelled (Can be re-activated)</a> ';
	};	
	
	if (OptionMask & 4){
		strHTML = strHTML + '  <a href="javascript:window.opener.doChangeOfferStatus(2,' + OfferID + ');window.close();">Hold</a><br> ';
	};	
	
	if (OptionMask & 8){
		strHTML = strHTML + '  <a href="javascript:window.opener.doChangeOfferStatus(3,' + OfferID + ');window.close();">Reject</a> ';
	};	

	strHTML = strHTML + '  </body></form>';
	strHTML = strHTML + '</html>';

	/*var screenX=(self.screenX)?self.screenX+20:window.screenLeft
	var screenY=(self.screenY)?self.screenY+70:window.screenTop
	var w =(descx==-1)?parseInt(screen.width/2-75):descx+screenX;
	var h=(descy==-1)?parseInt(screen.height/2-75):descy+screenY;
	if (isNaN(w)) w=descx+20
	if (isNaN(h)) h=descy+70
	var x = window.screenX + ((window.outerWidth - width) / 2)
	var y = window.screenY + ((window.outerHeight - height) / 2)
	*/
	
	var w;
	var h;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
	{
		var screenX=(self.screenX)?self.screenX+20:window.screenLeft
		var screenY=(self.screenY)?self.screenY+70:window.screenTop
		w =(descx==-1)?parseInt(screen.width/2-75):descx+screenX;
		h=(descy==-1)?parseInt(screen.height/2-75):descy+screenY;
		if (isNaN(w)) w=descx+20
		if (isNaN(h)) h=descy+70
	}
	else
	{
		w=evt.screenX+40;
		h=evt.screenY-40;
	}

	var look='width='+width+',height='+height+',left='+w+',top='+h;		
	popwin=window.open('','status',look);	
	popwin.document.open();	
	//popwin.document.focus();
	popwin.document.write(strHTML);	
	popwin.document.close();
	return _modalDialogReturnValue;
}

function showPicture(title, src)
{
	var width=400;
	var height = 400;
	var strHTML = '';
	strHTML = strHTML + '<html><title>' + title + '</title>';
	strHTML = strHTML + '  <body class="rtTableCream"><table width="100%" height="100%" class="rtTableCream"><tr><td width="100%" height="100%">';
	strHTML = strHTML + '  <img src=' + src + ' border=0 name="bpoImage" id="bpoImage" width="100%" height="100%"></td></tr><tr><td align="center">';
	strHTML = strHTML + '  <br><br><a href="javascript:window.close();">Close window</a><br><br></td></tr></table></body></html>';
	var screenX=(self.screenX)?self.screenX+20:window.screenLeft;
	var screenY=(self.screenY)?self.screenY+70:window.screenTop;
	var w =(descx==-1)?parseInt(screen.width/2-75):descx+screenX;
	var h=(descy==-1)?parseInt(screen.height/2-75):descy+screenY;
	if (isNaN(w)) w=descx+20;
	if (isNaN(h)) h=descy+70;
	var x = window.screenX + ((window.outerWidth - width) / 2);
	var y = window.screenY + ((window.outerHeight - height) / 2);
	var look='width='+width+',height='+height+',left='+w+',top='+h;
	popwin=window.open('','status',look);
	popwin.document.open();	
	//popwin.document.focus();
	popwin.document.write(strHTML);	
	popwin.document.close();
	return false;
}

function showPdf(param1, param2) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {theform = document.RTracForm;
}
else {theform = document.forms["RTracForm"];
}

theform.target = '_blank';			
theform.__EVENTTARGET.value = param1.split("$").join(":");
theform.__EVENTARGUMENT.value = param2;
theform.submit();

theform.target = '_self';			
theform.__EVENTTARGET.value = "";
theform.__EVENTARGUMENT.value = "";
}
// ******************************************************************************

//Function to set the value of a label webcontrol
function SetLabelWebControlValue(doc, id, newValue)
{
    var obj=MM_findObj(id, doc);
    if (obj) {
    //Use .innerHTML for label webcontrol
      obj.innerHTML=newValue; 
    }
}

//Function to set the value of a textbox webcontrol
function SetTextBoxWebControlValue(doc, id, newValue)
{		
    var obj=MM_findObj(id, doc);
    if (obj) {
    //Use .value for label webcontrol
      obj.value=newValue; 
    }
}

//Function to set the value of a DropDownList webcontrol
function SetDropDownListWebControlValue(doc, id, newValue)
{		
    var obj=MM_findObj(id, doc);
    if (obj) {
    //alert(obj.value = newValue);
       obj.value = newValue; 
    }
}

//Function to set the href value of a hyperlink webcontrol
function SetNavigateUrl(doc, id, newValue)
{		
    var obj=MM_findObj(id, doc);
    if (obj) {
				// format subject parameters line
				var oldUrl = obj.href;
				var i = oldUrl.indexOf('?subject');
				if (i > 0) {
						oldUrl = oldUrl.substring(i, oldUrl.length);
						obj.href=newValue + oldUrl; 
						obj.value = '';
				}
				else {
						obj.href = newValue;
						obj.value = '';
				}
    }
    
}

//Function to show/hide a tag element, used for 'Reports' menu
function show(tag)
{
	if (document.layers)
	{
		vista = (document.layers[tag].visibility == 'hide') ? 'show' : 'hide'
		document.layers[tag].visibility = vista;
	}
	else if (document.all)
	{
		vista = (document.all[tag].style.visibility == 'hidden') ? 'visible' : 'hidden';
		document.all[tag].style.visibility = vista;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(tag).style.visibility == 'hidden') ? 'visible' : 'hidden';
		document.getElementById(tag).style.visibility = vista;
	}
}

function hide(tag)
{
	if (document.layers)
	{
		current = (document.layers[tag].display == 'none') ? 'block' : 'none';
		document.layers[tag].display = current;
	}
	else if (document.all)
	{
		current = (document.all[tag].style.display == 'none') ? 'block' : 'none';
		document.all[tag].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(tag).style.display == 'none') ? 'block' : 'none';
		document.getElementById(tag).style.display = vista;
	}
}
// END : to show/hide a tag element, used for 'Reports' menu -->


//Called when the onpropertychanged event fires for an HTMLInputFile
function HTMLInputFilePropertyChange(id, target, arg) {
  var d;
  d = document.getElementById(id);
  if (d) {
    if (!arg) arg = '';
    {
        __doPostBack(target, arg);
    }
  }
}

// rnShowReportsDiv : Show the report div contained ctlAgentNav. This
// JS method is set as startup script in cnrAgentReports.
function rnShowReportsDiv() 
{
  var e = document.getElementById('reports');
  if (e) {
    show('reports');
  }
}; //rnShowReportsDiv

// rnFocusElement : focus the specified element on the specified form. 
// Optionally, select the element.

function rnFocusElement(formName, elemName, doSelect)
{
    var d = document.getElementById(elemName);
    if (d) {
        if (doSelect) {
            d.focus();
        }
    }
  
  //if (document.forms[formName][elemName] != null) {
  //  var elem = document.forms[formName].elements[elemName];
  //  elem.focus();
  //  if (doSelect) {
  //    elem.select();
  //  }
  //}
}; // function rnFocusElement

// rnTrim(string) : Returns a copy of a string without leading or trailing spaces
// PURPOSE: Remove trailing and leading blanks from our string.
// IN: str - the string we want to Trim
// RETVAL: A Trimmed string!
function rnTrim(str)
{
  var x=str;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}; // function rnTrim

// *******************************************************
// function allows sorting UltraWebGrid by given fieldID
// Purpose: Sorts the grid on the client-side by the column
//          that corresponds to the fieldID parameter
//
// FieldID: ControlID of the column you wish to sort by.
//
// Remarks: Reviewed by Kent 1/29/2005 - This function will 
//          only work for the TaskList usercontrol because
//          the gn variable is hardcoded. Pass in the gn
//          variable to remove this dependency.
//					Reviewed by EL 3/21/2005 - Now this function works also on Property TAB - task TAB
//					end on OfferSheet and CountersOffer sheet. But there were 2 problems:
//					1) to add string parameter to the function, because Infragistics Grid doesn't allow to add '' inside ""
//					2) sorting doesn't work on FireFox (window.event has no methods in firefox)
//*********************************************************
function srt(owner, fieldID) {
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
	}
	else return;
	var evnt=event;
  var gn='xctl0ctlTaskListctlWebGridctlUltraGrid';
  if (owner==1)
		gn='xctl0ctlTaskListctlWebGridctlUltraGrid';
	else {
		if (owner==2)
				gn='xctl0ctlWebGridctlUltraGrid';
		else
				gn='xctl0UltraWebTab1xctl12xctl0ctlPropTasksctlWebGridctlUltraGrid';
	}

  var se_t=gn+'c_0_'+fieldID;  //var se_t='xctl0ctlTaskListctlWebGridctlUltraGridc_0_14';
	var gs=igtbl_getGridById(gn);
	if(!gs)
		return;
	var se=igtbl_srcElement(evnt);
	while(se && (se.tagName!="TH" || se.id.length<gn.length || se.id.substr(0,gn.length)!=gn) && (se.tagName!="DIV" || !se.getAttribute("groupInfo")))
		se=se.parentNode;
	if(!se)
		return;
	
	var bandNo=0; 
	
	if(gs.Bands[bandNo].ClientSortEnabled)
	{
		gs.startHourGlass();
		gs.sortingColumn=se; 
		gs.oldColCursor=se.style.cursor;
		se.style.cursor="wait";
		window.setTimeout("igtbl_gridSortColumn('"+gn+"','"+se_t+"',false)",1);
	}
	else {
		gs.sortColumn(se.id,evnt.shiftKey);
		}
	if(gs.NeedPostBack) { 
		igtbl_doPostBack(gn,evnt.shiftKey?"shiftKey:true":"");
		}
}

// Called by the toggle featured link in the grid
// to change the selected property featured value.
// This procedure sets a hidden field that is
// consumed by the grid container.
function rtToggleFeaturedLink(listIndex, toggleValue)
{
  document.getElementById('ctlHiddenListIndex').value=listIndex;
  document.getElementById('ctlHiddenFeaturedFlag').value=toggleValue;
  parent.__doPostBack('', '');
}

// Called by the toggle status link in the grid
// to change the selected property IsActive value.
// This procedure sets a hidden field that is
// consumed by the grid container.
function rtIsActiveLink(listIndex, toggleValue)
{
  document.getElementById('ctlHiddenListIndex').value=listIndex;
  document.getElementById('ctlHiddenInactiveFlag').value=toggleValue;
  parent.__doPostBack('', '');
}

// *******************************************************
// Callback for client-side infragistics grid event.
//
// Purpose: To apply custom styles for featured and inactive
//          rows after the grid has been sorted by the
//          Infragistics client side java procedures.
//
// gridID:    ControlID of infragistics grid being sorted.
// columnID:  ColumnID of the column that the grid was
//            sorted by. -- Not used at this time.
//
// Remarks: This callback is setup by the 'use custom styles'
//          feature of the stdGridControl.
//*********************************************************
function rtgridAfterSortColumn( gridID, columnID)
{
  rtgridApplyCustomRowCss(gridID);
}

// *******************************************************
// Callback for client-side infragistics grid event.
//
// Purpose: To apply custom styles for featured and inactive
//          rows after the grid has been intialized by the
//          Infragistics client side java procedures.
//
// gridID:    ControlID of infragistics grid being sorted.
//
// Remarks: This callback is setup by the 'use custom styles'
//          feature of the stdGridControl.
//*********************************************************
function rtgridInitilize( gridID)
{
  // Ensure that on each redraw of the grid the toggle
  // values are reset.
  document.getElementById('ctlHiddenListIndex').value='';
  document.getElementById('ctlHiddenInactiveFlag').value='';
  document.getElementById('ctlHiddenFeaturedFlag').value='';
  
  rtgridApplyCustomRowCss(gridID);
}

// *******************************************************
// Helper function that styles the infragistics grid
// with the featured and Inactive styles defined by the
// CSS in the design template.
//
// Purpose: To apply custom styles for featured and inactive
//          rows.
//
// gridID:    ControlID of infragistics grid being sorted.
//
// Remarks: This callback is setup by the 'use custom styles'
//          feature of the stdGridControl.
//*********************************************************
function rtgridApplyCustomRowCss( gridID)
{
  var _grid = igtbl_getGridById(gridID);
  var _cellCount=_grid.Bands[0].Columns.length;

  // Due to problem with internal style variables
  // loss of state CSS classes for Inactive and Featured
  // need to be hard coded to ensure that they work properly
  // in combination with paging and sorting across postbacks.
  var _featuredStyle;
  if (_featuredStyle==null)
    {
    _featuredStyle=_grid.Bands[0].getColumnFromKey('ToggleFeaturedLink').SelCellClass;
    if (_featuredStyle=='')
      {
      // Fallback to hardcoded style in worst case.
      _featuredStyle='rt-webgrid-feature xctl0xctl0ctlWebGridctlUltraGrid-0-7-scic';
      }
    }
  var _inactiveStyle;
  if (_inactiveStyle==null)
    {
    _inactiveStyle=_grid.Bands[0].getColumnFromKey('ToggleStatusLink').SelCellClass;
    if (_inactiveStyle=='')
      {
      // Fallback to hardcoded style in worst case.
      _inactiveStyle='rt-webgrid-inactive xctl0xctl0ctlWebGridctlUltraGrid-0-5-scic';
      }
    }

 for (i=0; i < _grid.Rows.length; i++)
 {
  var _row = _grid.Rows.getRow(i);
  var _isFeaturedCell = _row.getCellFromKey('ToggleFeaturedLink');
  var _statusCell = _row.getCellFromKey('ToggleStatusLink');
  if (_statusCell.getValue() == 'Inactive')
    {
    // Need to change the styles on each visible cell
    for (j=0;j<_cellCount;j++)
      {
      var _cell=_row.getCell(j);
      
      _cell.Element.className = _cell.Element.className + ' ' + _inactiveStyle;
      //igtbl_changeStyle(gridID,_cell.Element,_inactiveStyle);
      } 
    }
  else
    {  
      if (_isFeaturedCell.getValue() == 'On')
      {
      // Need to change the styles on each visible cell

      for (j=0;j<_cellCount;j++)
        {
        var _cell=_row.getCell(j);
        _cell.Element.className = _cell.Element.className + ' ' + _featuredStyle;
        //igtbl_changeStyle(gridID,_cell.Element,_featuredStyle);
        } 
      }
    }
 } 
}

// Helper function for resizing reporting IFrame window
function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

// Helper function for resizing reporting IFrame window
function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
    var docHt = getDocHeight(iframeWin.document);
    // need to add to height to be sure it will all show
    if (docHt) iframeEl.style.height = docHt + 30 + "px";
  }
}

// Helper function for resizing reporting IFrame window
function resizeIFrame(frameUniqueName, fullSize, frameHeight)
  {	
   hide('div_' + frameUniqueName);
   
   var objFrame=document.getElementById('iframe_' + frameUniqueName);
   if (fullSize=='True')
    {
    objFrame.height=objFrame.document.body.scrollHeight+'px';
    }
   else
    {
		if (frameHeight)
			objFrame.height=frameHeight+'px';
		else
			objFrame.height=100+'px';
    }
   objFrame.style.display='block';
   }
   
//***************** CLIENT POPUP ****************************************************
function doSysClientPopUp(virtualPath, namingContainer, parentForm, doPostBack)
{
  // Popup Client dialog to allow the user to select a client.
  var strURL = virtualPath + '/Common/PageFactory.aspx?control=/Common/WebUI/PopUp/ctlClientSelect&template=popUpRTRAC&mode=sys';
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (parentForm) strURL += '&pf='+parentForm;
  if (doPostBack) strURL += '&dp='+doPostBack;

  doPopupCustom('Select SysClient',strURL,500,728,'scroll=auto');
}

//***************** CLIENT POPUP ****************************************************
function doRestrictedClientsPopUp(virtualPath, namingContainer, parentForm, doPostBack, userID)
{
  // Popup Client dialog to allow the user to select a client.
  var strURL = virtualPath + '/Common/PageFactory.aspx?control=/Common/WebUI/PopUp/ctlPopupClientsToUserSelection&template=popUpRTRAC&userID=' + userID;
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (parentForm) strURL += '&pf='+parentForm;
  if (doPostBack) strURL += '&dp='+doPostBack;
  doPopup('Select Clients for user ',strURL,200,600);
}

function doCloseRestrictedClients(namingContainer)
{
  parent.self.close();
  //MM_findObj(namingContainer+'hdnClientsList', parent.opener.document).value=strXMLClientsID;

  parent.opener.__doPostBack('', '');
}

//Function to set the href property prefix and text value of a hiperlink webcontrol
function SetNavigateUrlAndText(doc, id, newAddress, newText)
{
  var obj=MM_findObj(id, doc);
  if (obj) {
	  //Clear hyperlink' text value to avoid IE bug
	  //that changes innerText value on changing href property value
    obj.innerHTML = '';
		// format subject parameters line
		var oldUrl = obj.href;
		var i = oldUrl.indexOf('?subject');
		if (i > 0) {
				oldUrl = oldUrl.substring(i, oldUrl.length);
				obj.href = newAddress + oldUrl; 
				obj.value = '';
		}
		else {
				obj.href = newAddress;
				obj.value = '';
		}
	  //Use .innerHTML for hyperlink webcontrol
    obj.innerHTML = newText;      
  }
}

//Function sets the focus to the textbox toElementName 
//when the length of the value textbox fromElementName is >= than maxLength of fromElementName
//CALL THIS FUNCTION AS A 'onkeyup' EVENT HANDLER
function jumpFocus(fromElementName, toElementName)
{
	var objFromElement = fromElementName;
	var objToElement = toElementName;
	
	if (objFromElement && objToElement)
	{
		if (objFromElement.value.length >= objFromElement.maxLength)
		{
			if ((event.keyCode >= 96 && event.keyCode <= 105) || (event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode >= 48 && event.keyCode <= 57))
			{
				objToElement.focus();
			}
		}
	}
}



// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			if (document.documentElement && document.documentElement.scrollTop)
			{
				x=coordinates.x-document.documentElement.scrollLeft+window.screenLeft;
				y=coordinates.y-document.documentElement.scrollTop+window.screenTop;
			}
			else
			{
				x=coordinates.x-document.body.scrollLeft+window.screenLeft;
				y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y+20;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {

	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}

//***************** AGGREGATORS TRUSTED USERS POPUP ****************************************************
function doAddTrustedUsersPoPup(virtualPath, namingContainer, parentForm, doPostBack, userID)
{
  // Popup Client dialog to allow the user to select a client.
  var strURL = virtualPath + '/Common/PageFactory.aspx?control=/Common/WebUI/PopUp/ctlPopupAddTrustedUsers&template=popUpRTRAC&userID=' + userID;
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (parentForm) strURL += '&pf='+parentForm;
  if (doPostBack) strURL += '&dp='+doPostBack;
  doPopup('Select Users who trusted working with uploaded Properties',strURL,200,600);
}

function doCloseTrustedUsersPoPup(namingContainer)
{
  parent.self.close();
  parent.opener.__doPostBack('', '');
}
//***************** ASSET MANAGER ****************************************************
function doEditSitusPhotoPopUp(virtualPath, namingContainer, parentForm, doPostBack, index)
{
  // Popup Asset manager dialog to allow the user to select an asset manager.
  var strURL = virtualPath + '/Common/PageFactory.aspx?control=/Common/WebUI/PopUp/ctlEditPhoto&template=popUpRTRAC&imgIndex=' + index;
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (parentForm) strURL += '&pf='+parentForm;
  if (doPostBack) strURL += '&dp='+doPostBack;

  doPopup('Edit Property Image',strURL,350,330);
}

function doEditSitusPhotoPopUpMasterPage(virtualPath, namingContainer, parentForm, doPostBack, index)
{
//alert("AAA");
//alert(virtualPath);
//alert(namingContainer);
//alert(parentForm);
//alert(doPostBack);
//alert(index);
  // Popup Asset manager dialog to allow the user to select an asset manager.
  var strURL = virtualPath + '/EditPhotoPopUp.aspx?template=popUpRTRAC&imgIndex=' + index;
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (parentForm) strURL += '&pf='+parentForm;
  if (doPostBack) strURL += '&dp='+doPostBack;

  doPopup('Edit Property Image',strURL,350,330);
}

function doCloseEditSitusPhotoPoPup(doParentPostBack)
{
  parent.self.close();
  if (doParentPostBack) {
		//Request image update
		parent.opener.__doPostBack('UpdateImages', 'UpdateImages');
	}
}

function doCloseEditSitusPhotoPopUpMasterPage(doParentPostBack)
{
  parent.self.close();
  if (doParentPostBack) {
		parent.opener.__doPostBack('UpdateImages', 'UpdateImages');
	}
}

function doEditBPOPhotoPopUp(title, virtualPath, imageID, situsID, imageGroupID, imageClassID, taskIDFK, filePath, fileName, instanceGUID)
{
  // Popup Asset manager dialog to allow the user to select an asset manager.
  var strURL = virtualPath + '/Common/PageFactory.aspx?control=/Common/WebUI/PopUp/ctlEditBPOPhoto&template=popUpRTRAC&imageID=' + imageID + '&situsID=' + situsID + '&imageGroupID=' + imageGroupID + '&imageClassID=' + imageClassID + '&taskIDFK=' + taskIDFK + '&filePath=' + filePath + '&fileName=' + fileName + '&instanceGUID=' + instanceGUID;

  doPopup(title, strURL, 350, 330);
}

function fillPendingLeadCheckboxes(checkBoxListHiddenName, isUncheck)
{
	var csvLeadsToAccept = "";
	var leadID = "";
	var commaPosition = -1;
	var objCheckBox;
	
	csvLeadsToAccept = MM_findObj(checkBoxListHiddenName).value;
	
	while (csvLeadsToAccept.length > 0)
	{
		commaPosition = csvLeadsToAccept.indexOf(",");
		
		if (commaPosition > -1)
		{
			leadID = csvLeadsToAccept.substring(0, commaPosition);
		}
		else
		{
			leadID = csvLeadsToAccept;  //the last one
		}
		
		objCheckBox = document.getElementById(leadID);
		
		if (objCheckBox)
		{
			objCheckBox.checked = !isUncheck;
		}
		
		csvLeadsToAccept = csvLeadsToAccept.substring(commaPosition + 1);
	}
}

function addLeadToCSVList(chkAcceptID, checkBoxListHiddenName)
{
	var csvLeadsToAccept = "";
	var leadID = "";
	var commaPosition = -1;
	
	csvLeadsToAccept = MM_findObj(checkBoxListHiddenName).value;
	
	while (csvLeadsToAccept.length > 0)
	{
		commaPosition = csvLeadsToAccept.indexOf(",");
		
		if (commaPosition > -1)
		{
			leadID = csvLeadsToAccept.substring(0, commaPosition);
		}
		else
		{
			leadID = csvLeadsToAccept;  //the last one
		}
		
		if (leadID == chkAcceptID)
		{
			return;
		}
		
		csvLeadsToAccept = csvLeadsToAccept.substring(commaPosition + 1);
	}
	
	MM_findObj(checkBoxListHiddenName).value += chkAcceptID + ",";
}

function removeLeadFromCSVList(chkAcceptID, checkBoxListHiddenName)
{
	var csvLeadsToAccept = "";
	var csvTail = "";
	var leadID = "";
	var leadPosition = -1;
	var commaPosition = -1;
	
	csvLeadsToAccept = MM_findObj(checkBoxListHiddenName).value;
	
	leadPosition = csvLeadsToAccept.indexOf(chkAcceptID);
	
	if (leadPosition > -1)
	{
		csvTail = csvLeadsToAccept.substring(leadPosition);
	}
	
	while (leadPosition > -1)
	{
		commaPosition = csvTail.indexOf(",");
		csvLeadsToAccept = csvLeadsToAccept.substring(0,leadPosition);
		
		if (commaPosition > -1)
		{
			csvLeadsToAccept += csvTail.substring(commaPosition + 1)
		}
		
		leadPosition = csvLeadsToAccept.indexOf(chkAcceptID);
		
		if (leadPosition > -1)
		{
			csvTail = csvLeadsToAccept.substring(leadPosition);
		}
	}
	
	MM_findObj(checkBoxListHiddenName).value = csvLeadsToAccept;
}

function updateCSVLeadIDToAccept(obj, checkBoxListHiddenName)
{
	if (obj.checked)
	{
		addLeadToCSVList(obj.id, checkBoxListHiddenName);
	}
	else
	{
		removeLeadFromCSVList(obj.id, checkBoxListHiddenName);
	}
	return true;
}

function SendContactMessage(virtualPath, messageID) {
		doPopup('Send Email', virtualPath + '/SendContactMessage.aspx?contactMessageID=' + messageID,400, 550);
}

//***************** ATTORNEY POPUP ****************************************************
function doSelectAddressFromListOpen(virtualPath, namingContainer, parentForm, doPostBack, parentNamingContainer)
{
  var strURL = virtualPath + '/Common/PageFactory.aspx?control=/Common/WebUI/PopUp/ctlSelectAddress&template=POPUPFSBO';
  if (namingContainer) strURL += '&nc='+namingContainer;
  if (parentForm) strURL += '&pf='+parentForm;
  if (doPostBack) strURL += '&dp='+doPostBack;
  if (parentNamingContainer) strURL += '&pnc='+parentNamingContainer;

  doPopup('Select Address',strURL,500,802);
}
function doCloseSelectAddressFromList(address, city, state, zip, namingContainer, parentForm, doPostBack, parentNamingContainer)
{
		var doc = parent.opener.document;
		var obj;

		parent.self.close();

		SetTextBoxWebControlValue(doc, namingContainer+'txtStreetAddress', address);
		SetTextBoxWebControlValue(doc, namingContainer+'txtCity', city);
		SetDropDownListWebControlValue(doc, namingContainer+'ddlSitusState', state);
		SetTextBoxWebControlValue(doc, namingContainer+'txtZipCode', zip);
		SetLabelWebControlValue(doc, parentNamingContainer+'lblError', 'Please make any desired changes to the property address.');
		SetTextBoxWebControlValue(doc, namingContainer+'hdnADDress', address+city+state+zip);
}
