function lineTotal(price,qty,div){
price = price;
total = (price)*qty;				
document.getElementById(div).innerHTML="R "+total;
}
function clearTotal(div){
document.getElementById(div).innerHTML="";
}
function qties(counter,value,button){
counter += value;
if(counter == 0){ button.disabled = true; } else { button.disabled = false; } 
}
function popUp2($url,w,h) {
   mywindow = window.open ($url,"mywindow","location=0,status=0,scrollbars=1,toolbar=0,menubar=0,titlebar=0,width=" + w + ",height=" + h + "");
  mywindow.moveTo(300,200);
 }
function qtytwo(counter,add,cart){
document.getElementById("totalqty").value = parseInt(document.getElementById("totalqty").value) - parseInt(document.getElementById(counter).value);
document.getElementById(counter).value =  parseInt(add);
document.getElementById("totalqty").value = parseInt(document.getElementById("totalqty").value) + parseInt(document.getElementById(counter).value);
if(document.getElementById("totalqty").value > 0){ cart.disabled = false; }  else { cart.disabled = true; }
}
function delitem(id,itemid,title){
if(confirm("Are you sure you want to remove this item from your cart?")){
	location.href='index.php?content=cart&action=delitem&id='+ id +'&item=' + itemid +''; }
}
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + 'R ' + num + '.' + cents);
}
function delitotal(deln,cart,delc,delt){
pDeln = parseInt(deln);
pDelc = pDeln+parseInt(cart);
delc.value = formatCurrency(pDeln);
delt.value = formatCurrency(pDelc);
}

function checkWholeForm(theForm) {
    var why = "";
    why += isEmptyName(theForm.name.value);
    why += isEmptyTel(theForm.tel.value);
    why += checkEmail(theForm.email.value);
    why += isEmptyMessage(theForm.comments.value);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}
// email
function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

function isEmptyName(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please include your name.\n";
  }
return error;	  
}
// non-empty textbox
function isEmptyTel(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please provide a contact number. \n";
  }else {
//test email for illegal characters
       var illegalChars= /[\@\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "Your contact number contains illegal characters.\n";
       }
    }
return error;	  
}
function isEmptyMessage(strng) {
var error = "";
  if (strng.length == 0) {
     error = "Please provide a message. \n";
  } 
return error;	  
}