function HideContent(d) {
	if(d.length < 1) {
		return;
	}
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	if(d.length < 1) {
		return;
	}
	//alert(d);
	document.getElementById(d).style.display = "block";
}
function ReverseContentDisplay(d) {
	if(d.length < 1) {
		return;
	}
	if(document.getElementById(d).style.display == "none") {
		document.getElementById(d).style.display = "block";
	} else {
		document.getElementById(d).style.display = "none";
	}
}
// popup window
function NewWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,resizable=yes,status=yes'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function NewWindow2(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable=yes,status=yes'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function showPic(whichpic) {
	if (document.getElementById) {
		document.getElementById('placeholder').src = whichpic.href;
  		if (whichpic.title) {
			document.getElementById('desc').childNodes[0].nodeValue = whichpic.title;
		} else {
			document.getElementById('desc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
		}
		return false;
	} else {
		return true;
	}
}

function showonlyone(thechosenone) {
	var imgs = document.getElementsByTagName("div");
	for(var x=0; x<imgs.length; x++) {
		name = imgs[x].getAttribute("name");
		if (name == 'imgbox') {
			if (imgs[x].id == thechosenone) {
				imgs[x].style.display = 'block';
			} else {
				imgs[x].style.display = 'none';
			}
		}
	}
}

function change(imageName,imageSrc,id){
	document.getElementById(imageName).src = imageSrc;
	document.getElementById(imageName).style.display = '';
	el = document.getElementById(id);
	if (el.style.display == 'none') {
        el.style.display = '';
        el = document.getElementById('img' + id);
    } else {
        el.style.display = 'none';
        el = document.getElementById('img' + id);
    }
}

function compute1(frm,e,todo)
/* compute1 function takes three parameters. //
* First parameter is the form that the element is within. Expected input should be "this.form"
* Second parameter is to accept the value assigned to the checkbox
* Last parameter is to instruct the script what to do. Values should either be 1/0. 1=addition and 0=subtraction
// End notes */
{
var tot = Number(frm.total.value);
	frm.total.value=(todo!=1)?tot-Number(e):tot+Number(e);
}


function calculate() {
	A1 = document.frm.product.value;
	B1 = document.frm.shipping.value;
	C1 = (A1+B1);
	alert (document.frm.product.value);
	document.frm.total.value = ((document.frm.product.value) + (document.frm.shipping.value));
}

function calc() {
	var form = document.forms.frm;
	var a = Number( getSelectedValue(form.elements.product) ); 
	var b = Number( getSelectedValue(form.elements.shipping) );
	
	if ( isNaN(a) || isNaN(b) ) {
	
	} else {
		// calculate total
		total = a + b;
		if(isNaN(total))
		total = "0";
		sign = (total == (total = Math.abs(total)));
		total = Math.floor(total*100+0.50000000001);
		cents = total%100;
		total = Math.floor(total/100).toString();
		if(cents<10)
		cents = "0" + cents;
		for (var i = 0; i < Math.floor((total.length-(1+i))/3); i++)
		total = total.substring(0,total.length-(4*i+3))+','+
		total.substring(total.length-(4*i+3));
		form.elements.total.value = 'ZAR' + ' ' + (((sign)?'':'-') + total + '.' + cents);
		// calculate discount
		discount = a*0.25;
		//discount = discount;
		sign2 = (discount == (discount = Math.abs(discount)));
		discount = Math.floor(discount*100+0.50000000001);
		cents2 = discount%100;
		discount = Math.floor(discount/100).toString();
		if(cents2<10)
		cents2 = "0" + cents2;
		for (var i = 0; i < Math.floor((discount.length-(1+i))/3); i++)
		discount = discount.substring(0,discount.length-(4*i+3))+','+
		discount.substring(discount.length-(4*i+3));
		form.elements.discount.value = 'ZAR' + ' ' + (((sign2)?'':'-') + discount + '.' + cents2);
		// total with discount
		totaldiscount = (a + b) - (a*0.25);
//		alert(totaldiscount);
//		if(isNaN(totaldiscount))
//		totaldiscount = "0";
		sign3 = (totaldiscount == (totaldiscount = Math.abs(totaldiscount)));
		totaldiscount = Math.floor(totaldiscount*100+0.50000000001);
		cents3 = totaldiscount%100;
		totaldiscount = Math.floor(totaldiscount/100).toString();
		if(cents3<10)
		cents3 = "0" + cents3;
		for (var i = 0; i < Math.floor((totaldiscount.length-(1+i))/3); i++)
		totaldiscount = totaldiscount.substring(0,totaldiscount.length-(4*i+3))+','+
		totaldiscount.substring(totaldiscount.length-(4*i+3));
		form.elements.invoice.value = 'ZAR' + ' ' + (((sign3)?'':'-') + totaldiscount + '.' + cents3);
	}
	
	if (a == "22800") {
		form.elements.hid_product.value = "ZEINTOP986";
	} else if (a == "28800") {
		form.elements.hid_product.value = "ZEINTOP987";
	}
	
	if ((b == "3600") || (b == "3300") || (b == "4600")) {
		form.elements.hid_shipping.value = "CIF Sea Freight";
	} else if ((b == "4950") || (b == "6325") || (b == "8050")) {
		form.elements.hid_shipping.value = "CIF Air Freight";
	}
}
 
function getSelectedValue(flds) {
  var i = 0;
  var len = flds.length;
  
  while (i < len) {
    if (flds[i].checked) {
      return flds[i].value;
    }
    i++;
  }
  
  return "";
}

function GetCountry() {
	//document.getElementById('frm').action='ordernow';
	//document.getElementById('frm').setAttribute('action','ordernow');
	/*document.getElementById('TheForm').submit();*/
	//alert(document.getElementById('frm').action);
}
