var totalPrice = 0;
function returnPrice(amount) {
var query_string = unescape(location.search.substr(1));
 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(query_string=="id=test01") { s = 1.05; }
 return s;
}

function checkPrice()
{
flowersPrice = returnPrice(document.forms['postDetails'].thePrice.value);
// now add the delivery charge
 var now = new Date();
 var month = now.getMonth()+1;
 var day = now.getDate();
 if (month.toString().length == 1){
  month = "0" + month;
 }
 if (day.toString().length == 1){
  day = "0" + day;
 }
 var todayString = now.getUTCFullYear() + "-" + month + "-" + day;
 var delDateString = document.forms['postDetails'].deliverydate.value;
 if (todayString==delDateString) {
  delCharge=6.95;}
 else {
  delCharge=5.95;
 }
 chocsPrice = document.forms['postDetails'].chocolates.value;
 totalPrice = returnPrice(flowersPrice*1+delCharge*1+chocsPrice*1);
 document.forms['postDetails'].deliverycharge.value = delCharge*1;
 document.forms['postDetails'].TransactionAmount.value = totalPrice;
 document.getElementById("priceupdate").innerHTML=totalPrice;
}
function addchocs()
{
 if (document.postDetails.chocbox.checked) {
  document.forms['postDetails'].chocolates.value = 9.99;
  }
 else {
  document.forms['postDetails'].chocolates.value = 0;
 }
 checkPrice();
}
function checkForm()
{
 if (document.forms['postDetails'].recipientsname.value.length == 0) {
  alert("Please enter the recipient's name");
  document.forms['postDetails'].recipientsname.focus();
  document.forms['postDetails'].recipientsname.select();
  return false;
 }
 if (document.forms['postDetails'].recipientsaddress.value.length == 0) {
  alert("Please enter the recipient's address");
  document.forms['postDetails'].recipientsaddress.focus();
  document.forms['postDetails'].recipientsaddress.select();
  return false;
 }
 var emailAddr = document.forms['postDetails'].CustomerEmail.value;
 var str = emailAddr; // email string
   var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
   var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
 if (!(!reg1.test(str) && reg2.test(str)) && document.forms['postDetails'].CustomerEmail.value.length !=0) {
// if syntax is valid
  alert("\"" + str + "\" is an invalid e-mail!");
  document.forms['postDetails'].CustomerEmail.focus();
  document.forms['postDetails'].CustomerEmail.select();
  return false;
 }
 if (document.forms['postDetails'].yourphone.value.length == 0) {
  alert("Please enter a telephone contact number in case we need to contact you in relation to your order.");
  document.forms['postDetails'].yourphone.focus();
  document.forms['postDetails'].yourphone.select();
  return false;
 }
 if (document.forms['postDetails'].yourname.value.length == 0) {
  alert("Please enter yourname please.");
  document.forms['postDetails'].yourname.focus();
  document.forms['postDetails'].yourname.select();
  return false;
 }
  if (document.forms['postDetails'].ownchoiceflag.value == '1') {
   if (document.getElementById("flowerchoice").innerHTML == 'Empty') {
    alert("Please choose some flowers");
    document.forms['postDetails'].flowerchoice.focus();
    document.forms['postDetails'].flowerchoice.select();
    return false;
   }
 }
  document.forms['postDetails'].submit();
}
