$(document).ready(   function()    {      changePaymentDetails();      populateBackupStorage($('#versionDropDown1').val(), 'backupStorageDropDown1');   }   );function Backup(size,price) {    this.size = size;    this.price = price;}/* FORM SUBMISSION */function submitForm(){   var errorMessage = '';      errorMessage += validateComputers();   errorMessage += validateDetails();   errorMessage += validatePaymentDetails();           if( errorMessage.length > 0 )   {      alert("The following fields are incomplete or invalid:" + errorMessage);   }   else if( $('#terms').attr('checked') == false )   {      alert("You need to agree to the terms and conditions");   }   else   {           var firstName = $('#firstNameTxt').val();      var lastName = $('#lastNameTxt').val();      var company = $('#companyTxt').val();      var areaCode = $('#areacodeTxt').val();      var phoneNumber = $('#phoneTxt').val();      var email = $('#emailTxt').val();      var postcode = $('#postcodeTxt').val();      var country = $('#countryTxt').val();      var mobile = $('#mobileTxt').val();      var accountsEmail = $('#accountsEmailTxt').val();      var itEmail = $('#itEmailTxt').val();                              // 2 - credit card      // 3 - by phone      var paymentMethod = $('#paymentMethodDropDown').val();      if( paymentMethod == 'creditCard' )         paymentMethod = 2;      else         paymentMethod = 3;            var creditcardNumber = $('#creditCardNumberTxt').val();      var creditcardName = $('#creditCardNameTxt').val();      var creditcardType = $('#cardTypePaymentDropDown').val();      var creditcardExpires = $('#expiryMonthDropDown').val() + '/' + $('#expiryYearDropDown').val();      var cvv = $('#cvvPaymentTxt').val();            var phoneName = $('#phoneNameTxt').val();      var phoneDaytime = $('#daytimePhoneTxt').val();      var phoneAfterhours = $('#nighttimePhoneTxt').val();            var prices = new Array();      var details = new Array();      var versions = new Array();      var extras = new Array();      for(var i=1; i<=10; ++i)      {         if( $("#backupStorageDropDown" + i).length > 0 )            prices.push( $("#backupStorageDropDown" + i).val() );         else            prices.push('');                  //'NAME, TYPE'         if( $("#computerNameTxt" + i).length > 0 )             details.push( $("#computerNameTxt" + i).val() + ', ' + $("#typeDropDown" + i).val() );         else            details.push('');                     if( $("#versionDropDown" + i).length > 0 )             versions.push( $("#versionDropDown" + i).val() );         else            versions.push('');                     var extraString = ''         if( $("#oracleCheckBox" + i).length > 0  && $("#oracleCheckBox" + i).attr("checked") == true  )            extraString += 'Oracle Database Server|';         if( $("#sqlCheckBox" + i).length > 0  && $("#sqlCheckBox" + i).attr("checked") == true  )            extraString += 'SQL / mySQL Module|';         if( $("#lotusCheckBox" + i).length > 0  && $("#lotusCheckBox" + i).attr("checked") == true  )            extraString += 'Lotus Domino / Notes|';         if( $("#exchangeTxt" + i).length > 0 && parseFloat($("#exchangeTxt" + i).val()) > 0)            extraString += $("#exchangeTxt" + i).val() + ' Microsoft Exchange Mailboxes|';                   extras.push(extraString);                 }            var ipAddress = $('#ipAddress').val();      var totalAmount = $('#subTotal').html();                  $('#submitFormDiv').html('<img src="images/submit.gif" alt="submit" width="107" height="38" hspace="7" vspace="7" border="0" />');                     // POST data and save to database      $.post("php_includes/ProcessCustomPlan.php",             { firstName: firstName,               lastName: lastName,              company: company,              areaCode: areaCode,              phoneNumber: phoneNumber,              email: email,              country: country,              postcode: postcode,              mobile: mobile,              accountsEmail: accountsEmail,              itEmail: itEmail,                            paymentMethod: paymentMethod,              creditcardNumber: creditcardNumber,              creditcardName: creditcardName,              creditcardType: creditcardType,              creditcardExpires: creditcardExpires,              cvv: cvv,              phoneName: phoneName,              phoneDaytime: phoneDaytime,              phoneAfterhours: phoneAfterhours,                            price1: prices[0],              price2: prices[1],              price3: prices[2],              price4: prices[3],              price5: prices[4],              price6: prices[5],              price7: prices[6],              price8: prices[7],              price9: prices[8],              price10: prices[9],              detail1: details[0],              detail2: details[1],              detail3: details[2],              detail4: details[3],              detail5: details[4],              detail6: details[5],              detail7: details[6],              detail8: details[7],              detail9: details[8],              detail10: details[9],              version1: versions[0],              version2: versions[1],              version3: versions[2],              version4: versions[3],              version5: versions[4],              version6: versions[5],              version7: versions[6],              version8: versions[7],              version9: versions[8],              version10: versions[9],              extra1: extras[0],              extra2: extras[1],              extra3: extras[2],              extra4: extras[3],              extra5: extras[4],              extra6: extras[5],              extra7: extras[6],              extra8: extras[7],              extra9: extras[8],              extra10: extras[9],                            ipAddress: ipAddress,              totalAmount: totalAmount            },                                                function(data)            {               window.location="form-thanks.php";            });         }   }/* STORAGE SPACE */function addPrice(price, monthlyPriceDiv){   if( isNaN(price) )   {      $('#' + monthlyPriceDiv).val('');   }   else   {      $('#' + monthlyPriceDiv).val('$' + price);   }      calculateAmounts();}function typeChanged(type, id){   var versionDropDown = $('#versionDropDown'+id);   if( type == 'server' )   {      versionDropDown.attr("selectedIndex",1);      versionDropDown.attr("disabled", true);       populateBackupStorage(versionDropDown.val(), 'backupStorageDropDown'+id);   }   else   {      versionDropDown.attr("disabled", false);    }}function versionChanged( version,  id){      populateBackupStorage(version, 'backupStorageDropDown'+id);   displayExtraOptions(id);   calculateAmounts();  }var COMPUTERLIMIT = 10;var HIGHLIGHTCOLOUR = '#FFCF94';var DEFAULTCOLOUR = '#FFFFFF';var id = 2;var PRICEORACLE = '5.00';var PRICESQL = '5.00';var PRICELOTUS = '5.00';var PRICEMAILBOX = '1.00';var MAILBOXLIMIT = 450;function addComputer(){   // Validate number of computers   if( id > COMPUTERLIMIT )   {      $('#addCompDiv').html('To order more than 10 plans please contact us on 1300 661 105');      return;   }             var newRow = '';      newRow += '<tr id="row' + id + '">';   newRow += '<td height="35" valign="middle">';   newRow += '<input name="computerNameTxt' + id + '" type="text" id="computerNameTxt' + id + '" size="14" maxlength="20" />';   newRow += '</td>';      newRow += '<td height="18" align="left" valign="middle">';   newRow += '<select name="typeDropDown' + id + '" id="typeDropDown' + id + '" onchange="typeChanged( this.value, \'' + id + '\')">';   newRow += '<option value="desktop" selected="selected" >Desktop</option>';   newRow += '<option value="laptop" >Laptop</option>';   newRow += '<option value="server" >Server</option>';   newRow += '</select></td>';      newRow += '<td align="left" valign="middle">';   newRow += '<select name="versionDropDown' + id + '" id="versionDropDown' + id + '" onchange="versionChanged( this.value,  \'' + id + '\')">';   newRow += '<option value="standard" selected="selected" >Standard</option>';   newRow += '<option value="advanced" >Advanced</option>';   newRow += '</select>';   newRow += '</td>';      newRow += '<td align="left" valign="middle">';   newRow += '<select name="backupStorageDropDown' + id + '" id="backupStorageDropDown' + id + '" onchange="addPrice( this.value, \'monthlyPriceTxt' + id + '\' )" style="width: 135px;">';   newRow += '<option selected="selected">-Please Select-</option>';   newRow += '</select></td>';      newRow += '<td><div align="right">';   newRow += '<input id="monthlyPriceTxt' + id + '" size="10" maxlength="12" readonly="readonly" style="text-align:right" />';   newRow += '</div></td>';      newRow += '<td id="removeButtonTD' + id + '"><a href="javascript:removeComputer(\'' + id + '\');"><img src="images/remove2.gif" border="0" align="absmiddle" /></a></td>';   newRow += '</tr>';      newRow += '<tr id="advancedOptionsTr' + id + '"><td colspan="5"><div id="advancedOptionsDiv' + id + '"></div></td><td></td></tr>';      newRow += '<tr id="rowHR' + id + '"><td colspan="5"><hr /></td><td></td></tr>';      $('#computerRowsTable').append(newRow);   populateBackupStorage($('#versionDropDown' + id).val(), 'backupStorageDropDown' + id);   ++id;   calculateAmounts();   refreshRemoveButtons();}function displayExtraOptions(id){   var advancedOptionsDiv = $('#advancedOptionsDiv'+id);   var version = $('#versionDropDown'+id).val();      var output = '';   if( version == 'advanced' )   {         output += '<table cellpadding="0" cellspacing="0" border="0">';      output += '<tr>';      output += '<td align="right" width="532">Oracle Database Server';      output += '   <input type="checkbox" name="oracleCheckBox' + id + '" id="oracleCheckBox' + id + '" onClick="extraClicked(this.checked,PRICEORACLE,\'oracleTotalTxt' + id + '\')" /></td><td colspan="2"><input name="oracleTotalTxt' + id + '" type="text" id="oracleTotalTxt' + id + '" style="text-align:right" value="$0.00" size="10" readonly="readonly" /></td><td>&nbsp;</td>';      output += '</tr>';      output += '<tr>';      output += '<td align="right">SQL / mySQL Module';      output += '   <input type="checkbox" name="sqlCheckBox' + id + '" id="sqlCheckBox' + id + '" onClick="extraClicked(this.checked,PRICESQL,\'sqlTotalTxt' + id + '\')" /></td><td colspan="2"><input name="sqlTotalTxt' + id + '" type="text" id="sqlTotalTxt' + id + '" style="text-align:right" value="$0.00" size="10" readonly="readonly" /></td><td>&nbsp;</td>';      output += '</tr>';      output += '<tr>';      output += '<td align="right">Lotus Domino / Notes';      output += '   <input type="checkbox" name="lotusCheckBox' + id + '" id="lotusCheckBox' + id + '" onClick="extraClicked(this.checked,PRICELOTUS,\'lotusTotalTxt' + id + '\')" /></td>';      output += '<td colspan="2"><input name="lotusTotalTxt' + id + '" type="text" id="lotusTotalTxt' + id + '" style="text-align:right" value="$0.00" size="10" readonly="readonly" /></td><td>&nbsp;</td>';      output += '</tr>';      output += '<tr>';      output += '<td align="right">Microsoft Exchange Mailboxes 1-450';      output += '   <input name="exchangeTxt' + id + '" type="text" id="exchangeTxt' + id + '" value="0" size="2" style="text-align:right" onChange="mailboxesChanged(this,\'exchangeTotalTxt' + id + '\')" /></td><td colspan="2"><input name="exchangeTotalTxt' + id + '" type="text" id="exchangeTotalTxt' + id + '" style="text-align:right" value="$0.00" size="10" readonly="readonly" /></td><td>&nbsp;</td>';      output += '</tr>';      output += '</table>';                                              advancedOptionsDiv.html(output);         }   else if( version == 'standard' )   {      advancedOptionsDiv.html('');   }}function extraClicked(checked, amount, textField){   if( checked )      $('#'+textField).val('$'+amount);   else      $('#'+textField).val('$0.00');         calculateAmounts();}function mailboxesChanged(inputTxt,textField){   var amount;   if( isNaN(inputTxt.value) || parseFloat(inputTxt.value) < 0 ||  inputTxt.value.length == 0)   {      amount = 0;      inputTxt.value = 0;   }   else if( parseFloat(inputTxt.value) > MAILBOXLIMIT )   {      amount = MAILBOXLIMIT;      inputTxt.value = MAILBOXLIMIT;   }   else      amount = parseFloat(inputTxt.value) * parseFloat(PRICEMAILBOX);      amount = '$' + amount.toFixed(2);   $('#'+textField).val(amount);      calculateAmounts();}function refreshRemoveButtons(){   for(var i=1; i<id-1; ++i)   {      $('#removeButtonTD' + i).html('');   }      var currentID = id-1;   $('#removeButtonTD' + currentID).html('<a href="javascript:removeComputer(\'' + currentID + '\');"><img src="images/remove2.gif" border="0" align="absmiddle" /></a>');   }function removeComputer(currentID){   $('#row' + currentID).remove();   $('#rowHR' + currentID).remove();   --id;   refreshRemoveButtons();   calculateAmounts();      if( id == COMPUTERLIMIT )      $('#addCompDiv').html('<a href="javascript:addComputer();"><img src="images/add3.gif" border="0" align="absmiddle" /></a>');   }function calculateAmounts(){   var currentAmount = 0;   var totalAmount = 0;   var totalTaxAmount = 0;   var totalGrossAmount = 0;      for(var i=1; i<=id; ++i)   {      if( $("#backupStorageDropDown" + i).length > 0 )      {         currentAmount = $("#backupStorageDropDown" + i).val();         if( !isNaN(currentAmount) )            totalAmount += parseFloat(currentAmount);      }            // Check extras      if( $("#oracleCheckBox" + i).length > 0  && $("#oracleCheckBox" + i).attr("checked") == true  )         totalAmount += parseFloat(PRICEORACLE);      if( $("#sqlCheckBox" + i).length > 0  && $("#sqlCheckBox" + i).attr("checked") == true  )         totalAmount += parseFloat(PRICESQL);      if( $("#lotusCheckBox" + i).length > 0  && $("#lotusCheckBox" + i).attr("checked") == true  )         totalAmount += parseFloat(PRICELOTUS);      if( $("#exchangeTxt" + i).length > 0 )         totalAmount += parseFloat(PRICEMAILBOX)*parseFloat($("#exchangeTxt" + i).val());        }               totalTaxAmount = totalAmount / 10;   totalTaxAmount = totalTaxAmount.toFixed(2);      totalGrossAmount = parseFloat(totalAmount) + parseFloat(totalTaxAmount);   totalGrossAmount = totalGrossAmount.toFixed(2);      totalAmount = totalAmount.toFixed(2);      $('#gstTotal').html(totalTaxAmount);   $('#subTotal').html(totalAmount);   $('#total').val('$' + totalGrossAmount);}function populateBackupStorage(version, backupStorageDiv){   var price = '';   var size = '';   var backupArray = new Array();   var options = '<option value="-Please Select-">-Please Select-</option>';         if( version == 'advanced' )      backupArray = advancedBackupArray;   else if( version == 'standard' )      backupArray = standardBackupArray;   for(var i=0; i<backupArray.length; ++i)   {      price = parseFloat(backupArray[i].price);      price = price.toFixed(2);            size = backupArray[i].size;            options += '<option value="' + price + '">' + size + 'Gb - $' + price + '</option>';   }      $('#' + backupStorageDiv).html(options);         calculateAmounts();   resetMonthlyPrices();}function resetMonthlyPrices(){   for(var i=1; i<=id; ++i)   {      if( $("#backupStorageDropDown" + i).length > 0 )      {         currentAmount = $("#backupStorageDropDown" + i).val();         if( isNaN(currentAmount) )            $("#monthlyPriceTxt" + i).val('');                  }   }}function validateComputers(){      var valid = true;   var error = '';   for(var i=1; i<=id && valid; ++i)   {      if( $('#computerNameTxt' + i).length > 0 )      {         if( $('#computerNameTxt' + i).val().length == 0 )         {            error += "\n- computer name";            $('#computerNameTxt' + i).css('background-color',HIGHLIGHTCOLOUR);            valid = false;         }         else            $('#computerNameTxt' + i).css('background-color',DEFAULTCOLOUR);                  if( $("#backupStorageDropDown" + i).attr("selectedIndex") == 0 )         {            error += "\n- backup storage";            $('#backupStorageDropDown' + i).css('background-color',HIGHLIGHTCOLOUR);            valid = false;         }         else            $('#backupStorageDropDown' + i).css('background-color',DEFAULTCOLOUR);      }   }      return error;}/* YOUR DETAILS */function validateDetails(){   var error = '';   if( $('#firstNameTxt').val().length == 0 )   {      $('#firstNameTxt').css('background-color',HIGHLIGHTCOLOUR);      error += "\n- first name";   }   else      $('#firstNameTxt').css('background-color',DEFAULTCOLOUR);         if( $('#lastNameTxt').val().length == 0 )   {      $('#lastNameTxt').css('background-color',HIGHLIGHTCOLOUR);      error += "\n- last name";   }   else      $('#lastNameTxt').css('background-color',DEFAULTCOLOUR);       if( $('#emailTxt').val().length == 0 )   {      $('#emailTxt').css('background-color',HIGHLIGHTCOLOUR);      error += "\n- e-mail address";    }   else      $('#emailTxt').css('background-color',DEFAULTCOLOUR);      var emailRegex = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;   if( !emailRegex.test( $('#emailTxt').val() ) )   {      $('#emailTxt').css('background-color',HIGHLIGHTCOLOUR);      error += "\n- e-mail address";   }   else      $('#emailTxt').css('background-color',DEFAULTCOLOUR);      if( $('#areacodeTxt').val().length == 0 || isNaN($('#areacodeTxt').val()) )   {      $('#areacodeTxt').css('background-color',HIGHLIGHTCOLOUR);      error += "\n- area code";    }   else      $('#areacodeTxt').css('background-color',DEFAULTCOLOUR);      if( $('#phoneTxt').val().length == 0 )   {      $('#phoneTxt').css('background-color',HIGHLIGHTCOLOUR);      error += "\n- phone number";   }   else      $('#phoneTxt').css('background-color',DEFAULTCOLOUR);      var phoneRegex = /^[0-9 -]+$/;   if( !phoneRegex.test( $('#phoneTxt').val() ) )   {      $('#phoneTxt').css('background-color',HIGHLIGHTCOLOUR);      error += "\n- phone number";   }   else      $('#phoneTxt').css('background-color',DEFAULTCOLOUR);         if( !phoneRegex.test( $('#mobileTxt').val() ) )   {      $('#mobileTxt').css('background-color',HIGHLIGHTCOLOUR);      error += "\n- mobile number";   }   else      $('#mobileTxt').css('background-color',DEFAULTCOLOUR);      if( $('#postcodeTxt').val().length == 0 || isNaN($('#postcodeTxt').val()) )   {      $('#postcodeTxt').css('background-color',HIGHLIGHTCOLOUR);      error += "\n- post code";   }        else      $('#postcodeTxt').css('background-color',DEFAULTCOLOUR);               return error;}/* PAYMENT DETAILS */function showPopup(mother, type) {		if (!$("#popupBox").length) {			var mother = "#"+mother;			var htmlString = '';						switch (type) {				case "type":					htmlString ="<div id='popupBox'>You can only choose advanced plans for server type</div>";					break;				case "cvc":					htmlString = "<div id='popupBox' style='margin:-280px 0 0 0'><p class='subheader'>What is a CVC number?</p><p>The CVC or Card Verification Code is a 3 digit number that is used by credit card agencies as an added security precaution when handling internet transactions. It is the last 3 digits of the number found on the back of your credit card underneath the magnetic strip.</p><p align='center'><img src='images/cvc.gif'><p></div>";					break;			}			$(mother).append(htmlString);		}}function removePopup(mother) {	$("#popupBox").remove();}function displayPaymentDetailsValidation(){   $("#paymentDetailsValidationDiv p strong").html( validatePaymentDetails() );}function validatePaymentDetails(){   var nowDate;    var expiryDate;    var error = '';      var selectedPayment = $('#paymentMethodDropDown').val();         if( selectedPayment == 'creditCard' )   {      if( $('#creditCardNameTxt').val().length == 0 )      {         $('#creditCardNameTxt').css('background-color',HIGHLIGHTCOLOUR);         error += "\n- name on credit card";      }      else         $('#creditCardNameTxt').css('background-color',DEFAULTCOLOUR);                  if( $("#expiryMonthDropDown").attr("selectedIndex") == 0 )      {         $('#expiryMonthDropDown').css('background-color',HIGHLIGHTCOLOUR);         error += "\n- credit card expiry date";      }      else         $('#expiryMonthDropDown').css('background-color',DEFAULTCOLOUR);            if( $("#expiryYearDropDown").attr("selectedIndex") == 0 )      {         $('#expiryYearDropDown').css('background-color',HIGHLIGHTCOLOUR);         error += "\n- credit card expiry date";      }      else      {         $('#expiryYearDropDown').css('background-color',DEFAULTCOLOUR);               nowDate = new Date();         expiryDate = new Date();         expiryDate.setDate(1);         expiryDate.setMonth( parseInt($('#expiryMonthDropDown').val())-1 );         expiryDate.setYear( $('#expiryYearDropDown').val() );               if( expiryDate < nowDate )         {            $('#expiryMonthDropDown').css('background-color',HIGHLIGHTCOLOUR);            $('#expiryYearDropDown').css('background-color',HIGHLIGHTCOLOUR);            error += "\n- credit card expiry date";         }         else         {            $('#expiryMonthDropDown').css('background-color',DEFAULTCOLOUR);            $('#expiryYearDropDown').css('background-color',DEFAULTCOLOUR);         }      }                                                if( $('#creditCardNumberTxt').val().length == 0 )      {         $('#creditCardNumberTxt').css('background-color',HIGHLIGHTCOLOUR);         error += "\n- credit card number";      }      else         $('#creditCardNumberTxt').css('background-color',DEFAULTCOLOUR);               if( $('#cvvPaymentTxt').val().length == 0 )      {         $('#cvvPaymentTxt').css('background-color',HIGHLIGHTCOLOUR);         error += "\n- credit card verification number";      }      else         $('#cvvPaymentTxt').css('background-color',DEFAULTCOLOUR);    }   else if( selectedPayment == 'phone' )   {      if( $('#phoneNameTxt').val().length == 0 )      {         $('#phoneNameTxt').css('background-color',HIGHLIGHTCOLOUR);         error += "\n- payment contact name";      }      else         $('#phoneNameTxt').css('background-color',DEFAULTCOLOUR);            if( $('#daytimePhoneTxt').val().length == 0 )      {         $('#daytimePhoneTxt').css('background-color',HIGHLIGHTCOLOUR);         error += "\n- payment daytime phone number";      }      else         $('#daytimePhoneTxt').css('background-color',DEFAULTCOLOUR);                  if( $('#nighttimePhoneTxt').val().length == 0 )      {         $('#nighttimePhoneTxt').css('background-color',HIGHLIGHTCOLOUR);         error += "\n- payment after hours phone number";      }      else         $('#nighttimePhoneTxt').css('background-color',DEFAULTCOLOUR);   }               return error;}function changePaymentDetails(){   var selectedElement = $('#paymentMethodDropDown').val();   // Hide all the divs   $('#creditCardPaymentDiv').hide();   $('#phonePaymentDiv').hide();   $('#ipAddressDiv').hide();            // Show only the relevant div   if( selectedElement == 'creditCard' )   {      $('#creditCardPaymentDiv').show();      $('#ipAddressDiv').show();   }   else if( selectedElement == 'phone' )   {      $('#phonePaymentDiv').show();   }}