
function showIt1(div){
    if (document.getElementById) {  // for Netscape
      myDiv = document.getElementById(div);
         myDiv.style.display = 'block';
    }

    if (document.all) {     // for IE
      eval("myDiv = "+div+";");
         myDiv.style.display = 'block';
    }
}

function hideIt1(div){
     if (document.getElementById) {  // for Netscape
       myDiv = document.getElementById(div);
          myDiv.style.display = 'none';
     }

     if (document.all) {     // for IE
       eval("myDiv = "+div+";");
          myDiv.style.display = 'none';
     }
}

function calc1(iIndex) 
{
	id= 'sPackageNo' + iIndex;
    iCurPackageVal = eval(document.getElementById(id)).value;
	var obj = eval('document.getElementById(\'paypalform\').product'+iCurPackageVal);
	if(obj.checked) addtototal1(obj.value);
	else subfromtotal1(obj.value);
	if (document.getElementById('discount')) 
	{
		//hide discount
		hideIt1('show_discount');
		//fix total
		total_now = parseInt(document.getElementById('discount').innerHTML) +  parseInt(document.getElementById('paypalform').amount.value);		
		document.getElementById('total2').innerHTML = total_now.toFixed(2);
		showIt1('show_total');
		// reset discount
		document.getElementById('discount').innerHTML = 0;
		document.getElementById('total3').innerHTML = 0;
		// show voucher
		showIt1('show_voucher');
	}
	
}

function addtototal1(val) {
	var formEl = document.getElementById('paypalform');
	var theObj = document.getElementById('total');
	var theField = formEl.amount;
	var newVal = parseInt(strip_commas1(theObj.innerHTML)) + parseInt(val);
	theObj.innerHTML = number_format1(newVal);
	theField.value = newVal; 
	if(document.getElementById('ftotal'))
	{
		document.getElementById('ftotal').value = newVal;
	}
	if(parseInt(strip_commas1(theObj.innerHTML)) < 0){ theObj.innerHTML = 0; }
	if (document.getElementById('total2')) { 
		document.getElementById('total2').innerHTML = newVal.toFixed(2);
	}
	
}

function setTotalToZero() 
{
  document.getElementById('total').innerHTML = "0";
}

function subfromtotal1(val) {
	var formEl = document.getElementById('paypalform');
	var theObj = document.getElementById('total');
	var theField = formEl.amount;
	var newVal = parseInt(strip_commas1(theObj.innerHTML)) - parseInt(val);
	theObj.innerHTML = number_format1(newVal);
	theField.value = newVal;
	if(document.getElementById('ftotal'))
	{
		document.getElementById('ftotal').value = newVal;
	}
	if(parseInt(strip_commas1(theObj.innerHTML)) < 0) theObj.innerHTML = 0;
	
}

function strrev1(str) {
	var inp = str.toString();
	var outp = '';
	for (i=0; i<=inp.length; i++) outp = inp.charAt(i) + outp;
	return outp;
} 

function number_format1(num) {
	var tn = num.toString();
	var len = tn.length;
	if(len < 4) return tn;
	var rv = '';
	for(i=len-1; i>=0; i--) rv += (i % 3 == 0 && i != len-1 ? ',' : '') + tn.charAt(i);
	return strrev1(rv);
}

function strip_commas1(str) {
	var rv = '';
	for(i=0; i<str.length; i++) rv += (str.charAt(i) != ',' ? str.charAt(i) : '');
	return parseInt(rv);
}

