// JavaScript Document
var imageLoading=false;
var formPosted=false;
var responses=new Array;
var responseTitles=new Array;


// function from http://forums.devshed.com/t39065/s84ded709f924610aa44fff827511aba3.html
// author appears to be Robert Pollard

function sprintf()
{
   if (!arguments || arguments.length < 1 || !RegExp)
   {
      return;
   }
   var str = arguments[0];
   var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
   var a = b = [], numSubstitutions = 0, numMatches = 0;
   while (a = re.exec(str))
   {
      var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
      var pPrecision = a[5], pType = a[6], rightPart = a[7];

      numMatches++;
      if (pType == '%')
      {
         subst = '%';
      }
      else
      {
         numSubstitutions++;
         if (numSubstitutions >= arguments.length)
         {
            alert('Error! Not enough function arguments (' + (arguments.length - 1)
               + ', excluding the string)\n'
               + 'for the number of substitution parameters in string ('
               + numSubstitutions + ' so far).');
         }
         var param = arguments[numSubstitutions];
         var pad = '';
                if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
           else if (pPad) pad = pPad;
         var justifyRight = true;
                if (pJustify && pJustify === "-") justifyRight = false;
         var minLength = -1;
                if (pMinLength) minLength = parseInt(pMinLength);
         var precision = -1;
                if (pPrecision && pType == 'f')
                   precision = parseInt(pPrecision.substring(1));
         var subst = param;
         switch (pType)
         {
         case 'b':
            subst = parseInt(param).toString(2);
            break;
         case 'c':
            subst = String.fromCharCode(parseInt(param));
            break;
         case 'd':
            subst = parseInt(param) ? parseInt(param) : 0;
            break;
         case 'u':
            subst = Math.abs(param);
            break;
         case 'f':
            subst = (precision > -1)
             ? Math.round(parseFloat(param) * Math.pow(10, precision))
              / Math.pow(10, precision)
             : parseFloat(param);
            break;
         case 'o':
            subst = parseInt(param).toString(8);
            break;
         case 's':
            subst = param;
            break;
         case 'x':
            subst = ('' + parseInt(param).toString(16)).toLowerCase();
            break;
         case 'X':
            subst = ('' + parseInt(param).toString(16)).toUpperCase();
            break;
         }
         var padLeft = minLength - subst.toString().length;
         if (padLeft > 0)
         {
            var arrTmp = new Array(padLeft+1);
            var padding = arrTmp.join(pad?pad:" ");
         }
         else
         {
            var padding = "";
         }
      }
      str = leftpart + padding + subst + rightPart;
   }
   return str;
}

function validate_logonForm(theForm)
{
  if (theForm.Mobile) {
    if (theForm.Email.value=="" && theForm.Mobile.value=="") {
      alert("Please enter either your email address or mobile number.");
      theForm.Email.focus();
      return false;
    }
    if (theForm.Email.value!="" && theForm.Mobile.value!="") {
      alert("Please enter either your email address or mobile number, but NOT BOTH");
      theForm.Email.focus();
      return false;
    }
  }
  else if (theForm.Email.value=="") {
    alert("Please enter your email address");
    theForm.Email.focus();
    return false;
  }
  if (!validateEmailv2(theForm.Email.value)) {
    alert("Please enter a valid email address.");
	theForm.Email.focus();
	return false;
  }
  if (theForm.Password.value=="") {
    alert("Please enter your password.");
    theForm.Password.focus();
    return false;
  }
  if (theForm.Password.value.length > 16) {
    alert("Your password is more than 16 characters long. Please enter at most 16 characters");
	theForm.Password.focus();
	return false;
  }
  return true;
}

function validate_emailForm(theForm)
{
  if (theForm.Email.value=="" || !validateEmailv2(theForm.Email.value)) {
    alert("Please enter a valid email address.");
	theForm.Email.focus();
	return false;
  }
  return true;
}

function validate_emailResponseForm(theForm)
{
  if (formPosted)
    return false;
  if (theForm.subject.value=="") {
    alert('Please enter the subject of the email.');
	theForm.subject.focus();
	return false;
  }
  if (theForm.name.value=="") {
    alert('Please enter your name.');
	theForm.name.focus();
	return false;
  }
  if (theForm.email.value=="" || !validateEmailv2(theForm.email.value)) {
    alert("Please enter a valid email address.");
	theForm.email.focus();
	return false;
  }
  if (theForm.message.value=="") {
    alert('Please enter the message copy to send.');
	theForm.message.focus();
	return false;
  }
  if (theForm.sstat.checked && !confirm("Are you sure you want to set all offers selected above to SELLER CANCELLED ?\nOk - Offers will be cancelled\nCancel - You can amend your details")) {
    theForm.sstat.checked=false;
	return false;
  }
  formPosted=true;
  return true;
}


function toggleInspection(theForm,type)
{
  var e;
  if (type) {
    e=document.getElementById('pinspectionOn');
    e.style.display=theForm.pest[0].checked ? 'block' : 'none';
  }
  else {
    e=document.getElementById('inspectionOn');
    e.style.display=theForm.building[0].checked ? 'block' : 'none';
  }
}

function valid_number(s)
{
  // reg expression 
  // start with optional $ followed by optional spaces followed by at least one digit followed by zero or more groups of ',ddd' followed optionally by a decimal and at least one digit
  // ending optionally with one of k,K,m or M 
//  var r=/^\$?\s?\d+(,\d{3})*(\.\d+)?[kKmM]?$/;
  var r=/^\$?\s?\d+(,\d{3})*(\.\d+)?$/;	// don't allow the k or m afterall....
  return r.test(s);
}

function numeric_value(s)
{
  // strip out the $ or , from the string
  s=s.replace(/\$/g,'');
  s=s.replace(/\,/g,'');
  return parseFloat(s);
}

function check_offer_emails(theForm)
{
  var e1=theForm.email.value;
  var e2=theForm.cemail.value;
  var x;
  if ((e1=="" && e2=="") || e1==e2) {
    document.getElementById('e_error').style.display='none';
    return;
  }
  if (e1!="" && e2=="") {
    x='Enter your email in both the <i>Email</i> and <i>Confirm</i> fields';
    document.getElementById('e_emails').innerHTML=x;
    document.getElementById('e_error').style.display='block';
    return;
  }
  if (e1=="" && e2!="") {
    x='Enter your email address in Email field';
    document.getElementById('e_emails').innerHTML=x;
    document.getElementById('e_error').style.display='block';
    return;
  }
  else if (e1 != e2)  {
    x=e1+' &lt; &gt; '+e2;
    document.getElementById('e_emails').innerHTML=x;
    document.getElementById('e_error').style.display='block';
    return;
  }
}

function validate_offerform(theForm) 
{
  var d;
  var confirmedOffer=false;
  if (formPosted)
    return false;
  if (theForm.isalesperson && theForm.isalesperson.selectedIndex <= 0) {
    alert('Please select the sales person who introduced you or referred you to this site.');
    theForm.isalesperson.focus();
    return false;
  }  
  if (theForm.buyer.value=="") {
    alert('Please enter the buyer\'s name/s');
	theForm.buyer.focus();
	return false;
  }
  if (theForm.address.value=="") {
    alert('Please enter the buyer\'s address');
	theForm.address.focus();
	return false;
  }

  if (theForm.hphone.value=="" && theForm.wphone.value=="" && theForm.mphone.value=="") {
    alert('Please enter at least one contact number.');
	theForm.hphone.focus();
	return false;
  }
  if (theForm.email.value=="" || !validateEmailv2(theForm.email.value)) {
    alert('Please enter a valid email address.');
	theForm.email.focus();
	return false;
  }
  if (theForm.cemail.value == "") {
    alert('Please enter your email address again exactly in the \'Confirm\' field as a double check.');
	theForm.cemail.focus();
	return false;
  }
  if (theForm.cemail.value != theForm.email.value) {
    alert("The email address you have entered is different to the email address in the 'Confirm' field. Check you have entered your correct email address in to both fields.\n\nThis is a double check to help avoid typos");
	theForm.cemail.focus();
	return false;
  }
  if (theForm.offer.value=="") {
    alert('Please enter the offer');
	theForm.offer.focus();
	return false;
  }
  if (theForm.deposit.value=="") {
    alert('Please enter the deposit');
	theForm.deposit.focus();
	return false;
  }
  
  if (!valid_number(theForm.offer.value)) {
    alert("The offer amount you have entered - "+theForm.offer.value+" appears invalid. Please enter as a full amount such as 575,000");
    theForm.offer.focus();
	return false;
  }

  if (!valid_number(theForm.deposit.value))  {
    alert("The deposit amount you have entered - "+theForm.deposit.value+" appears invalid. Please enter a full amount such as 37,500");
    theForm.deposit.focus();
	return false;
  }  
  if (numeric_value(theForm.offer.value) < 1000) {
    alert('Please enter the full amount - eg. 575000 and not just 575');
	theForm.offer.focus();
	return false;
  }
  if (numeric_value(theForm.deposit.value) > 0 && numeric_value(theForm.deposit.value)*100.0/numeric_value(theForm.offer.value) > 10) {
    alert('The deposit should not exceed 10% of the offer ie. '+sprintf('%.0f',numeric_value(theForm.offer.value)*0.1));
	theForm.deposit.focus();
	return false;
  }
  if (theForm.depositNotes.value.length > 500) {
    alert('Please enter no more than 500 characters in the deposit notes. You have entered '+theForm.depositNotes.value.length);
	theForm.depositNotes.focus();
	return false;
  }
  
  if (!theForm.finance[0].checked && !theForm.finance[1].checked) {
    alert('Please select whether the contract will be subject to finance or not.');
	return false;
  }
/*  
  if (theForm.finance[0].checked) {
    if (theForm.bank.value=="") {
	  alert('Please enter the name of the bank/institution where finance will be sought');

	  theForm.bank.focus();
	  return false;
	}
	if (!theForm.financeDate[0].checked && !theForm.financeDate[1].checked && !theForm.financeDate[2].checked) {
	  alert('Please select the number of days for finance or select Other and enter the number of days manually');
	  return false;
	}
	if (theForm.financeDate[2].checked && isNaN(parseInt(theForm.financeDays.value))) {
	  alert('Please enter the number of days for finance if selecting the Other option.');
	  theForm.financeDays.focus();
	  return false;
	}
  }
*/  
  if (!theForm.building[0].checked && !theForm.building[1].checked) {
    alert('Please nominate whether a building inspection is required.');
	return false;
  }

  if (theForm.building[0].checked && !theForm.inspectionDate[0].checked && !theForm.inspectionDate[1].checked) {
    alert('Please nominate the date when the building inspection will be due. 7 or 14 days from contract date');
	return false;
  }
  if (!theForm.pest[0].checked && !theForm.pest[1].checked) {
    alert('Please nominate whether a pest inspection is required.');
	return false;
  }

  if (theForm.pest[0].checked && !theForm.pinspectionDate[0].checked && !theForm.pinspectionDate[1].checked) {
    alert('Please nominate the date when the pest inspection will be due. 7 or 14 days from contract date');
	return false;
  }

  if (theForm.property[0].checked) {
    if (theForm.conditionAddress.value=="") {
	  alert('Please enter the address of the property to settle.');
	  theForm.conditionAddress.focus();
	  return false;
	}
	if (!valid_number(theForm.conditionValue.value) || numeric_value(theForm.conditionValue.value) < 1000) {
	  alert('Please enter the full asking/contract price for the property to be settled (eg, 520,000 and not 520)');
	  theForm.conditionValue.focus();
	  return false;
	}
	if (!theForm.propertyContract[0].checked && !theForm.propertyContract[1].checked) {
	  alert('Please nominate whether the property to be settled is currently under contract.');
	  return false;
	}
  }
  
  if ((theForm.settlementdate.value=="" || theForm.settlementdate.value=='dd/mm/yyyy') && theForm.settlementdays.value=="") {
    alert('Please enter a settlement date or number of days after contract date until settlement.');
	theForm.settlementdate.focus();
	return false;
  }
  if ((theForm.settlementdate.value!="" && theForm.settlementdate.value!='dd/mm/yyyy')) {
    if (!(d=parseDate(theForm.settlementdate.value,'d/M/y'))) {
	  alert('You have entered an invalid date for settlement date.');
	  theForm.settlementdate.focus();
	  return false;
	}
	if (d.getTime() < (new Date).getTime()+(86400000*7)) {
	  alert('Your settlement date should be at least 7 days from now');
	  theForm.settlementdate.focus();
	  return false;
	}
  }
  else if (!valid_number(theForm.settlementdays.value) || isNaN(parseInt(theForm.settlementdays.value))) {
    alert('Please enter a valid number of days for the settlement or enter the settlement date.');
	theForm.settlementdays.focus();
	return false;
  }
  if (!theForm.authorise.checked) {
    alert('Please indicate you have checked the offer, read the terms & conditions and wish to submit the offer, by ticking the box at the bottom of the offer form.');
	return false;
  }
  if (theForm.code.value=="") {
    alert('Please enter the security code exactly as shown.');
	theForm.code.focus();
	return false;
  }
  if (!confirmedOffer && !confirm("Do you wish to submit the offer of - "+theForm.offer.value+" for consideration ?\nSubmit offer ?\n\nOK - Submit Offer\nCancel - Cancel & Edit Offer"))
    return false;
  formPosted=true;	
  theForm.b1.value="Submitting offer, please wait...";
  return true;
}

function viewOffer(id)
{
  window.open('view_offer.php?o='+id,'','width=620,height=650,scrollbars=1');
}

function makeOffer(c,p)
{
  window.open('https://www.offernow.com.au/offer.php?c='+c+'&p='+p,'','width=620,height=650,scrollbars=1');
}

function initOffer()
{
  window.open('https://www.offernow.com.au/init_offer.php','','width=620,height=650,scrollbars=1');
}

function s_amendOffer(id,v)
{
  window.open('/seller/counter_offer.php?o='+id+'&v='+v,'','width=620,height=650,scrollbars=1');
}

function s_cancelOffer(id,s,v)
{
  if (confirm("Are you sure you wish to cancel negotiations on offer #"+id+"?\nOk - Offer history will be archived and no further action will be possible\nCancel - Leave offer as is"))
    document.location='?d='+id+'&v='+v+'&s='+s;
}
function s_contractOffer(id,s,v)
{
  if (confirm("Are you sure you wish to update offer #"+id+" as converted to contract ?\nOk - Offer status will reflect this offer has been converted to a contract\nCancel - Leave offer as is"))
    //document.location='?d='+id+'&v='+v+'&s='+s;
    document.location='contract_status.php?o='+id+'&a=c';
}

function showAmend(ok,id)
{
  document.getElementById(id).style.display=(ok  > 0 ? 'none' : 'block');
  if (id=='financeAmend') 
	document.getElementById('financeOn').style.display=(ok > 0 ? 'none' : (document.getElementById('finRadOn').checked ? 'block' : 'none') );
  else if (id=='inspectionAmend') 
	document.getElementById('inspectionOn').style.display=(ok > 0 ? 'none' : (document.getElementById('insBuildOn').checked ? 'block' : 'none') );
  else if (id=='pinspectionAmend') 
	document.getElementById('pinspectionOn').style.display=(ok > 0 ? 'none' : (document.getElementById('insPestOn').checked ? 'block' : 'none') );
  else if (id=='offerAmend') { 
    document.getElementById('a_offerP').style.display=(ok != 0 ? 'none' : 'block');    
    document.getElementById('a_offerC').style.display=(ok != -1 ? 'none' : 'block');    
  }  
  else if (id=='depositAmend') { 
    document.getElementById('a_depositP').style.display=(ok != 0 ? 'none' : 'block');    
    document.getElementById('a_depositC').style.display=(ok != -1 ? 'none' : 'block');  
  }  

}

function validate_amendedofferform(theForm) 
{
  var d,pok,rok=true;
  var msg="",tmp;
  var confirmedOffer=false;
  if (formPosted)
    return false;
	
  if (theForm.aemail)
    if (theForm.aemail.value=="" || !validateEmailv2(theForm.aemail.value)) {
      alert("Please enter an email address to receive the offer form if you wish to negotiate and test the process fully.");
      theForm.aemail.focus();
      return false;
    }  
  if (theForm.buyer) {
    if (theForm.buyer.value=="") {
      alert('Please enter the buyer\'s name/s');
	  theForm.buyer.focus();
	  return false;
    }
    if (theForm.address.value=="") {
      alert('Please enter the buyer\'s address');
	  theForm.address.focus();
	  return false;
    }
    if (theForm.hphone.value=="" && theForm.wphone.value=="" && theForm.mphone.value=="") {
      alert('Please enter at least one contact number.');
	  theForm.hphone.focus();
	  return false;
    }
    if (theForm.email.value=="" || !validateEmailv2(theForm.email.value)) {
      alert('Please enter a valid email address.');
	  theForm.email.focus();
	  return false;
    }
  }
  else if (theForm.r_buyer.checked) {
    rok=false;
	msg="- Full details requested";
  }
  if (!theForm.offerOk[0].checked && !theForm.offerOk[1].checked && !theForm.offerOk[2].checked) {
    alert('Please nominate whether the offer price is acceptable.');
	return false;
  }
  if (!theForm.depositOk[0].checked && !theForm.depositOk[1].checked && !theForm.depositOk[2].checked) {
    alert('Please nominate whether the deposit price is acceptable.');
	return false;
  }
  if (!theForm.financeOk[0].checked && !theForm.financeOk[1].checked) {
    alert('Please nominate whether the finance are acceptable.');
	return false;
  }
  if (!theForm.inspectionOk[0].checked && !theForm.inspectionOk[1].checked) {
    alert('Please nominate whether the building inspection is acceptable.');
	return false;
  }
  if (!theForm.pinspectionOk[0].checked && !theForm.pinspectionOk[1].checked) {
    alert('Please nominate whether the pest inspection is acceptable.');
	return false;
  }
  if (theForm.propertyOk) {
    if (!theForm.propertyOk[0].checked && !theForm.propertyOk[1].checked) {
      alert('Please nominate whether the subject to sale of buyers property condition, or comment, is acceptable.');
	  return false;
    }
	pok=theForm.propertyOk[0].checked;
  }
  else
    pok=true;
  if (!theForm.conditionsOk[0].checked && !theForm.conditionsOk[1].checked) {
    alert('Please nominate whether the special conditions (or lack of) are acceptable.');
	return false;
  }
  if (!theForm.settlementOk[0].checked && !theForm.settlementOk[1].checked) {
    alert('Please nominate whether the settlement terms are acceptable.');
	return false;
  }
  
  // check if everything is ok
  if (rok && theForm.offerOk[0].checked && theForm.financeOk[0].checked && theForm.inspectionOk[0].checked && theForm.depositOk[0].checked && 
	  theForm.pinspectionOk[0].checked && theForm.conditionsOk[0].checked && theForm.settlementOk[0].checked && pok && theForm.comments.value=="" && 
		confirm("You have agreed to all terms on the offer. Do you wish to accept this offer ?\n\n OK - Accept Offer as is\nCancel - Amend offer / counter offer")) {
    formPosted=true;	
    theForm.b1.value="Submitting offer, please wait...";
    return true;
  }
  if (theForm.offerOk[1].checked) {
    if (theForm.offer.value=="") {
      alert('Please enter the new offer price');
	  theForm.offer.focus();
	  return false;
    }
    if (theForm.offer.value != "" && !valid_number(theForm.offer.value)) {
      alert("The offer amount you have entered - "+theForm.offer.value+" appears invalid. Please enter as a full amount such as 575,000");
      theForm.offer.focus();
	  return false;
    }

    if (theForm.offer.value != "" && numeric_value(theForm.offer.value) < 1000) {
      alert('Please enter the full amount - eg. 575000 and not just 575');
	  theForm.offer.focus();
	  return false;
    }
    msg += (msg.length ? "\n" : "")+"- Offer price amended ";
  }
  if (theForm.offerOk[2].checked) {
    if (theForm.offerNotes.value=="") {
      alert('Please enter your comment on the offer');
      theForm.offerNotes.focus();
      return false;
    }
    if (theForm.offerNotes.value.length > 500) {
      alert('Please enter no more than 500 characters in the offer notes. You have entered '+theForm.offerNotes.value.length);
      theForm.offerNotes.focus();
      return false;
    }
    msg += (msg.length ? "\n" : "")+"- Offer price commented ";
  }


  if (theForm.depositOk[1].checked) {
    if (theForm.deposit.value=="") {
      alert('Please enter the new deposit amount');
	  theForm.deposit.focus();
	  return false;
    }
  
    if (theForm.deposit.value != "" && !valid_number(theForm.deposit.value))  {
      alert("The deposit amount you have entered - "+theForm.deposit.value+" appears invalid. Please enter a full amount such as 37,500");
      theForm.deposit.focus();
	  return false;
    }  

    if (theForm.deposit.value != "" && numeric_value(theForm.deposit.value) > 0 && numeric_value(theForm.deposit.value)*100.0/numeric_value(theForm.offer.value) > 10) {
      alert('The deposit should not exceed 10% of the offer ie. '+sprintf('%.0f',numeric_value(theForm.offer.value)*0.1));
	  theForm.deposit.focus();
	  return false;
    }
    msg += (msg.length ? "\n" : "")+"- Deposit amended ";
  }
  if (theForm.depositOk[2].checked) {
    if (theForm.depositNotes.value=="") {
      alert('Please enter your comment on the deposit');
      theForm.depositNotes.focus();
      return false;
    }
  
    if (theForm.depositNotes.value.length > 1000) {
      alert('Please enter no more than 1000 characters in the deposit notes. You have entered '+theForm.depositNotes.value.length);
      theForm.depositNotes.focus();
      return false;
    }
    msg += (msg.length ? "\n" : "")+"- Deposit commented ";
  }


  if (theForm.financeOk[1].checked) {
    if (!theForm.finance[0].checked && !theForm.finance[1].checked) {
      alert('Please select whether the contract will be subject to finance or not.');
	  return false;
    }
    msg += (msg.length ? "\n" : "")+"- Subject to Finance: "+(theForm.finance[0].checked ? 'Yes' : 'No');
  }
  if (theForm.inspectionOk[1].checked) {
    if (!theForm.building[0].checked && !theForm.building[1].checked) {
      alert('Please nominate whether a building inspection is required.');
	  return false;
    }
    if (theForm.building[0].checked  && !theForm.inspectionDate[0].checked && !theForm.inspectionDate[1].checked) {
      alert('Please nominate the date when the inspection will be due. 7 or 14 days from contract date');
	  return false;
    }
	msg += (msg.length ? "\n" : "")+"- "+(theForm.building[0].checked ? "Building" : "No building")+" inspection";
  }
  if (theForm.pinspectionOk[1].checked) {
    if (!theForm.pest[0].checked && !theForm.pest[1].checked) {
      alert('Please nominate whether a pest inspection is required.');
	  return false;
    }

    if (theForm.pest[0].checked && !theForm.pinspectionDate[0].checked && !theForm.pinspectionDate[1].checked) {
      alert('Please nominate the date when the pest inspection will be due. 7 or 14 days from contract date');
	  return false;
    }
	msg += (msg.length ? "\n" : "")+"- "+(theForm.pest[0].checked ? "Pest" : "No pest")+" inspection";
  }
  if (theForm.propertyOk)
    if (theForm.propertyOk[1].checked)
	  msg += (msg.length ? "\n" : "")+"- Subject to sale condition responded to";
	
  if (theForm.settlementOk[1].checked) {
    if ((theForm.settlementdate.value=="" || theForm.settlementdate.value=='dd/mm/yyyy') && theForm.settlementdays.value=="") {
      alert('Please enter a settlement date or number of days after contract date until settlement.');
	  theForm.settlementdate.focus();
	  return false;
    }
    if ((theForm.settlementdate.value!="" && theForm.settlementdate.value!='dd/mm/yyyy')) {
      if (!(d=parseDate(theForm.settlementdate.value,'d/M/y'))) {
	    alert('You have entered an invalid date for settlement date.');
	    theForm.settlementdate.focus();
	    return false;
	  }
	  if (d.getTime() < (new Date).getTime()+(86400000*7)) {
	    alert('Your settlement date should be at least 7 days from now');
	    theForm.settlementdate.focus();
	    return false;
	  }
	  msg+=(msg.length ? "\n" : "")+"- Settlement: "+theForm.settlementdate.value;
    }
    else if (!valid_number(theForm.settlementdays.value) || isNaN(parseInt(theForm.settlementdays.value))) {
      alert('Please enter a valid number of days for the settlement or enter the settlement date.');
	  theForm.settlementdays.focus();
	  return false;
    }
	else
	  msg+=(msg.length ? "\n" : "")+"- Settlement: "+theForm.settlementdays.value+" days";
	  
  }
  if (theForm.comments.value != "") 
	  msg+=(msg.length ? "\n" : "")+"- Comments added";
  
  if (!theForm.authorise.checked) {
    alert('Please indicate you have checked the amended offer, read the terms & conditions and wish to submit the amended offer, by ticking the box at the bottom of the offer form.');
	return false;
  }
  if (theForm.code.value=="") {
    alert('Please enter the security code exactly as shown.');
	theForm.code.focus();
	return false;
  }
  
//  if (!confirm("Do you wish to submit the above offer with the following amendments:\n\n"+msg+"\n\nSubmit offer ?\n\nOK - Submit Offer\nCancel - Cancel & Edit Offer"))
    //return false;
  if (!confirm("Do you wish to submit the above offer response ?\n\nOK - Submit Response\nCancel - Cancel & Edit Offer"))
    return false;
  formPosted=true;	
  theForm.b1.value="Submitting offer, please wait...";
  return true;
}

function sellerViewed(id)
{
  var e;
  if (e=document.getElementById('o_'+id))
    e.style.fontWeight='normal';
}

function refreshPage()
{
  history.go(0);
}

function validate_feedbackform(theForm)
{
  if (formPosted)
    return false;
  if (!theForm.easy[0].checked && !theForm.easy[1].checked && !theForm.easy[2].checked	&& !theForm.easy[3].checked &&
		!theForm.easy[4].checked) {
    alert('Please nominate how easy or difficult you found the process.');
	return false;
  }
  if (!theForm.reuse[0].checked && !theForm.reuse[1].checked) {
    alert('Please nominate whether you would use the offer online process again.');
	return false;
  }
  theForm.b1.value='Submitting feedback, please wait...';
  formPosted=true;
  return true;
}


function validate_agentenquiryform(theForm)
{
  if (formPosted)
    return false;
  if (theForm.agency.value=="") {
    alert('Please enter your agency name.');
	theForm.agency.focus();
	return false;
  }
  if (theForm.suburb.value=="") {
    alert('Please enter the town.city your agency is located in.');
	theForm.suburb.focus();
	return false;
  }
  if (theForm.website.value=="") {
    alert('Please enter your agency\'s main web site.');
	theForm.website.focus();
	return false;
  }
  if (theForm.name.value=="") {
    alert('Please enter your name.');
	theForm.name.focus();
	return false;
  }
  if (theForm.phone.value=="") {
    alert('Please enter your phone number.');
	theForm.phone.focus();
	return false;
  }
  if (theForm.email.value=="" || !validateEmailv2(theForm.email.value)) {
    alert("Please enter a valid email address.");
	theForm.email.focus();
	return false;
  }
  formPosted=true;
  return true;
}

function showResponseOptions(id)
{
  var e=document.getElementById(id);
  for (var i=0; i < responseTitles.length; i++)
    e.options[e.options.length]=new Option(responseTitles[i],i);
}

function useResponseOption(id,msg)
{
  var e=document.getElementById(id);
  var m;
  if (e.selectedIndex >= 0 && parseInt(e.options[e.selectedIndex].value) >= 0) {
    m=document.getElementById(msg).value+responses[e.options[e.selectedIndex].value];
    document.getElementById(msg).value=m;
  }	
}

function showOfferResponseOptions(id,values)
{
  var e=document.getElementById(id);
  var a=(new String(values)).split(',');
  for (var i=0; i < a.length; i++)
    e.options[e.options.length]=new Option(responseTitles[a[i]],a[i]);
	
}

function setOfferResponse(id,i)
{
  document.getElementById(id).value=responses[i];
  closeOfferResponse();
}

function closeOfferResponse()
{
  document.getElementById('of_resp').style.display='none';
}

function selectOfferResponse(b,id,values)
{
  var e=document.getElementById('of_resp');
  var h="";
  var a=(new String(values)).split(',');
  for (var i=0; i < a.length; i++)
    h+='<div class="of_respv"><label>'+responseTitles[a[i]]+'</label>'+responses[a[i]]+'<br><br><input type="button" value="use this response" onclick="setOfferResponse(\''+id+'\','+a[i]+')" /> <input type="button" value="close window" onclick="closeOfferResponse()" /></div>';
  e.innerHTML=h; 
  e.style.top=b.offsetTop+25+'px';
  e.style.left=b.offsetLeft+25+'px';
  e.style.display='block'; 
}

function s_editbuyercontact()
{
  document.getElementById('s_buyercontact_edit').style.display='block';
}

function emailOffer(o,v)
{
  window.open('email_offer.php?o='+o+'&v='+v,'','width=600,height=490');
}

function validate_initofferform(theForm)
{
  if (formPosted)
    return false;
  if (theForm.address.value=="") {
    alert('Please enter the full street address. eg. 3/51 Gray Street');
   theForm.address.focus();
   return false; 
  }
  if (theForm.suburb.value=="") {
    alert('Please enter the suburb.');
    theForm.suburb.focus();
    return false;
  }
  if (theForm.contact.value=="") {
    alert('Please enter the name of the salesperson');
    theForm.contact.focus();
    return false;
  }
  if (theForm.email.value=="" || !validateEmailv2(theForm.email.value)) {
    alert('Please enter a valid email address for the salesperson.');
    theForm.email.focus();
    return false;
  }
  if (theForm.code.value=="") {
    alert('Please enter the security code exactly as shown.');
    theForm.code.focus();
    return false;
  }
  theForm.b1.value="Please wait....";  
  return formPosted=true;
  
}

