function getNow()
{
   var now=new Date();
   var month=now.getMonth()+1;
   var day=now.getDate();
   if(month<=9)
      month="0"+month;
   if(day<=9)
      day="0"+day;
   return (month+"/"+day+"/"+now.getYear())
}
function handleClientAction(actionType)
{
   window.open('client_action_page.html?actionType='+actionType,'Client Action Page','width=400,height=400,resizable=0,scrollbars=0,toolbar=0,location=0,status=1,directories=0,copyhistory=0');
}
function makeStatusChangePage(commentElement,submitElement)
{
   var win=window.open('blank.html','Client','height=400,width=400,resizable=0,scrollbars=0,toolbar=0location=0,status=0,directories=0,copyhistory=0');
   win.document.write(
      "<html>\n"+
      "<head><title>Client Action Page</title></head>\n"+
      "<script language='javascript'>\n"+
      "<!---->\n"+
      "</script>\n"+
      "<img src='images/client_action_page.gif' border=0 valign='top' vspace=0 hspace=0>\n"+
      "<h3>Status Changed</h3>\n"+
      "Please enter comments below:<br>\n"+
      "<textarea name='text' rows=10 cols=40></textarea><br>\n"+
      "<input type='button' value='Submit' onClick=\"window.opener."+commentElement+".value=text.value;window.opener."+submitElement+".click();window.close();\">&nbsp;\n"+
      "<input type='button' value='Cancel' onClick=\"window.close();\">");
}
function makeReviewTermsPage(commentElement,submitElement,fee1,fee1Desc,fee2,fee2Desc,fee3,fee3Desc,dueDate)
{
   var win=window.open('blank.html','Client','height=400,width=400,resizable=0scrollbars=0,toolbar=0,location=0,status=0,directories=0,copyhistory=0');
   win.document.write(
      "<html>\n"+
      "<head><title>Client Action Page</title></head>\n"+
      "<img src='images/client_action_page.gif' border=0 valign='top' vspace=0 hspace=0>\n"+
      "<h3>Review Appraisal Terms</h3>\n"+
      "<table border=0>\n"+
      "<tr><td>Fee 1:</td><td>$"+fee1+"</td><td>"+fee1Desc+"</td></tr>\n"+
      "<tr><td>Fee 2:</td><td>$"+fee2+"</td><td>"+fee2Desc+"</td></tr>\n"+
      "<tr><td>Fee 3:</td><td>$"+fee3+"</td><td>"+fee3Desc+"</td></tr>\n"+
      "<tr><td>Due Date:</td><td>"+dueDate+"</td></tr>\n"+
      "</table>\n"+
      "Please enter comments below:<br>\n"+
      "<textarea name='text' rows=5 cols=40></textarea><br>\n"+
      "<input type='button' value='Accept Terms' onClick=\"window.opener."+commentElement+".value='accepted:'+text.value;window.opener."+submitElement+".click();window.close();\">&nbsp;\n"+
      "<input type='button' value='Reject Terms' onClick=\"window.opener."+commentElement+".value='rejected:'+text.value;window.opener."+submitElement+".click();window.close();\">&nbsp;\n"+
      "<input type='button' value='Cancel' onClick=\"window.close();\">");
}
function makeCancellationOptionPage()
{
   var win=window.open('cancellation_option_page.php','Cancelling_Appraisal','height=150,width=325,resizable=0,scrollbars=0,toolbar=0,location=0,status=0,directories=0,copyhistory=0');
}
function makeClientNotificationPage()
{
   var win=window.open('client_notification_page.php','Cancelling_Appraisal','height=150,width=325,resizable=0,scrollbars=0,toolbar=0,location=0,status=0,directories=0,copyhistory=0');
}
function makeDeliveryPage(id)
{
   var win=window.open('delivery_page.php?id='+id,'Client','height=400,width=400,resizable=1,scrollbars=0,toolbar=0,location=0,status=0,directories=0,copyhistory=0');
}
function makePaystubEmailPopup(appraiserID,before,after)
{
   var win=window.open('paystub_email_popup.php?id='+appraiserID+'&before='+before+'&after='+after,'Email','height=520,width=700,status=0,toolbar=0,location=0,directories=0,copyhistory=0');
}
function makeInvoiceEmailPopup(clientID)
{
   var win=window.open('invoice_email_popup.php?id='+clientID,'Email','height=520,width=700,status=0,toolbar=0,location=0,directories=0,copyhistory=0');
}
function makeAppraisalEmailPopup(appraisalID)
{
   var win=window.open('appraisal_email_popup.php?id='+appraisalID,'Email','height=520,width=700,status=0,toolbar=0,location=0,directories=0,copyhistory=0');
}
function makeClickbillEmailPopup(appraisalID)
{
   var win=window.open('clickbill_email_popup.php?id='+appraisalID,'Email','height=520,width=700,statusbar=0,resizable=0,scrollbars=0,toolbar=0,location=0,status=1,directories=0,copyhistory=0');
}
function makeFileAccessEmailPopup(appraisalID)
{
   var win=window.open('file_access_email_popup.php?id='+appraisalID,'Email','height=520,width=630,statusbar=0,resizable=0,scrollbars=0,toolbar=0,location=0,status=1,directories=0,copyhistory=0');
}
function makeAppraisalFileDownloadPopup(params)
{
   var win=window.open('download_appraisal_file.php?'+params,'File_Download','height=170,width=330,statusbar=0,resizable=1,scrollbars=0,toolbar=0,location=0,status=0,statusbar=0,directories=0,copyhistory=0');
}
function makeInvoicePopup(appID)
{
   var win=window.open('appraisal_invoice.php?id='+appID,'Invoice_Page','height=700,width=700,statusbar=0,resizable=1,toolbar=0,location=0,status=0,directories=0,copyhistory=0');
}
function checkNumericInput(element)
{
   if(element.value=='')
      return true;
   var val=parseFloat(element.value);
   if(isNaN(val)||element.value!=val)
   {
      element.value='';
      alert('Invalid value for numeric field: '+element.name+'.');
      return false;
   }
   else
      element.value=val
   return true;
}
function checkEmail(email)
{
   reg=new RegExp("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$");
   if(email.value==""||!reg.test(email.value))
   {
      alert("Email must be of the form a@b.c.");
      return false;
   }
   return true;
}
function updateToList(address_list,to)
{
   var str='';
   var first=true;
   for(i=address_list.options.length-1;i>=0;i--)
      if(address_list.options[i].selected)
         if(first)
         {
            str=address_list.options[i].value;
            first=false;
         }
         else
            str=address_list.options[i].value+", "+str;
   to.value=str;
}
var curr_location=null;
var win=null;
var TRange=null;
var oldStr;
function findString(str)
{
   if(parseInt(navigator.appVersion)<4)
      return;
   var strFound;
   if(top.frames['mainFrame']==null)
      win=self;
   else
   {
//alert('before location='+curr_location+'\nwin.loc='+(win==null?'null':win.location));
      if(curr_location==null||win.location==null||win.location!=curr_location)
      {
         TRange=null;
         win=top.frames['mainFrame'];
         curr_location=win.location+'';
      }
   }
   if(navigator.appName=="Netscape")
   { // NAVIGATOR-SPECIFIC CODE
      strFound=win.find(str);
      if(!strFound)
      {
         strFound=win.find(str,0,1);
         while(win.find(str,0,1))
            continue
      }
   }
   if(navigator.appName.indexOf("Microsoft")!=-1)
   { // EXPLORER-SPECIFIC CODE
//alert("TRange:"+TRange);
      if(TRange==null||strFound==0||str!=oldStr)
      {
         TRange=win.document.body.createTextRange();
         oldStr=str;
         strFound=TRange.findText(str)
         if(strFound)
         {
            TRange.select();
            if(confirm("Find Next?"))
            {
               findString(str);
               return;//for the climb out of recursion.
            }
            else
               return;
         }
      }
      if(TRange!=null)
      {
         try
         {
            TRange.collapse(false);
         }
         catch(ex)
         {
            win=top.frames['mainFrame'];
            curr_location=win.location+'';
            TRange=win.document.body.createTextRange();
         }
         strFound=TRange.findText(str);
         if(strFound)
         {
            TRange.select();
            if(confirm("Find Next?"))
            {
               findString(str);
               return;//for the climb out of recursion.
            }
            else
               return;
         }
      }
   }
   if(!strFound)
      alert("String '"+str+"' not found!")
}
function highlight(checkbox,rowclass)
{
   if(checkbox.checked)
   {
      while(checkbox.tagName!='TR')
         checkbox=checkbox.parentElement;
      checkbox.className='highlightrow';
   }
   else
   {
      while(checkbox.tagName!='TR')
         checkbox=checkbox.parentElement;
      if(typeof(rowclass)!='undefined')
         checkbox.className=rowclass;
      else
         checkbox.className='';
   }
}
function currencyFormat(obj)
{
   var amount;
   if(obj.value==null)
      amount=obj;
   else
      amount=obj.value;
   tmpStr=new String(amount);
   rExp=/,/g;
   amount=tmpStr.replace(rExp,"");
   if(amount=='0'||amount=='')
   {
      if(obj.value!=null)
         obj.value='0.00';
      return '0.00';
   }
   var i=parseFloat(amount);
   if(isNaN(i))
      i=0.00;
   var minus='';
   if(i<0)
      minus='-';
   i=Math.abs(i);
   i=parseInt((i+.005)*100);
   i=i/100;
   s=new String(i);
   if(s.indexOf('.')<0)
      s+='.00';
   if(s.indexOf('.')==(s.length-2))
      s+='0';
   s=minus+s;
   if(obj.value!=null)
      obj.value=s;
   return s;
}
function updateMultipayTotal(checkbox,selected_total,amount)
{
   var total=parseFloat(selected_total.value.substr(1));//for the '$'
   var amnt=parseFloat(amount);
   var tot=total;
   if(checkbox.checked)
      total+=amnt;
   else
      total-=amnt;
//alert('amount:"'+amount+'"\namnt:"'+amnt+'"\ntotal:"'+total+'"\ncurrency:"'+currencyFormat(total)+'"');
   total=currencyFormat(total);
   selected_total.value='$'+total;
}
function setSelRange(inputEl, selStart, selEnd)
{
   if(inputEl.setSelectionRange)
   {
      inputEl.focus();
      inputEl.setSelectionRange(selStart,selEnd);
   }
   else if(inputEl.createTextRange)
   {
      var range=inputEl.createTextRange();
      range.collapse(true);
      range.moveEnd('character',selEnd);
      range.moveStart('character', selStart);
      range.select();
   }
}
