// JavaScript Document

	function writePItem(a_id, a_class, item_id, item_name, item_price, item_save, c_value, in_class, ip_class, is_class, w_save, is_selected){ // Write Product Item
		if(is_selected == 1){
			is_selected_text = ' checked="checked"';
		}else{
			is_selected_text = '';
		}
		document.write('<a href="javascript:select_item('+"'"+item_id+"'"+');" class="'+a_class+'">');
		document.write('<input type="radio" name="cc" id="'+item_id+'" value="'+c_value+'" onclick="select_item('+"'"+item_id+"'"+');"'+is_selected_text+' /><span class="regular_text_smaller">Select this quantity</span><br />');
		document.write('<span class="'+in_class+'">'+item_name+'</span> for Only <span class="'+ip_class+'">$'+item_price+'</span>');
		if(w_save == 1){
			document.write('<br /><span class="'+is_class+'">'+item_save+'</span>');
		}
		document.write('</a>');
	}

	function writeSItem(shipping_id, shipping_type, shipping_amount, is_checked){ // Write Shipping Choices
		if(is_checked == 1){
			is_checked_text = ' checked="checked"';
		}else{
			is_checked_text = '';
		}
		document.write('<input type="radio" name="stype" id="shipping'+shipping_id+'" value="'+shipping_type+'" onclick="compute_all();"'+is_checked_text+' /> <strong>'+shipping_type+' $'+shipping_amount+'</strong> ');
		document.write('<input type="hidden" name="shipping'+shipping_id+'_price" id="shipping'+shipping_id+'_price" value="'+shipping_amount+'" />');
	}

	function writeDEFCompute(def_st_value, def_at_value){
		document.write('<br /><br />Sub Total: <input type="text" name="amount_or" id="amount_or" class="text_embeded" readonly="YES" value="'+def_st_value+'" /><br />');
		document.write('Total Amount of Order: <input type="text" name="amount_total" id="amount_total" class="text_embeded" readonly="YES" value="'+def_at_value+'" /><br /><br />');
		document.write('<input type="submit" name="checkout" value="  Checkout  " class="checkout" />');
	}

	function select_item(pvx_id){

		var ctr = 1;

		while(ctr <= 4){
			document.getElementById('item_0'+ctr).checked = false;
			ctr+=1;
		}

		document.getElementById(pvx_id).checked = true;
		pvxValue = "p"+document.getElementById(pvx_id).value;
		document.getElementById('amount_or').value = document.getElementById(pvxValue).value;
		document.getElementById('c').value = document.getElementById(pvx_id).value;

		compute_all();

	}

	function compute_all(){
		var se_it = document.getElementById('c').value;
		var am_or = parseFloat(document.getElementById('p'+se_it).value);
		
		if(document.getElementById('shipping0').checked == true){
			
			if(se_it == '3' || se_it == '4'){
				document.getElementById('amount_total').value = number_format(am_or,2,'.','');
				document.getElementById('shipping_type').value = "AIRMAIL - FREE SHIPPING";
				document.getElementById('amount_shipping').value = 0;
			}
			else{
				document.getElementById('amount_total').value = number_format(am_or + 9.95,2,'.','');
				document.getElementById('shipping_type').value = "AIRMAIL";
				document.getElementById('amount_shipping').value = 9.95;
			}

		}
		if(document.getElementById('shipping1').checked == true){

			document.getElementById('amount_total').value = number_format(am_or + 24.95,2,'.','');
			document.getElementById('shipping_type').value = "FEDEX";
			document.getElementById('amount_shipping').value = 24.95;

		}

	}

	function number_format(a, b, c, d) {
		
		a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
		e = a + '';
		f = e.split('.');
		
		if (!f[0]) {
			f[0] = '0';
		}
		
		if (!f[1]) {
			f[1] = '';
		}
		
		if (f[1].length < b){
			g = f[1];
				for (i=f[1].length + 1; i <= b; i++){
					g += '0';
				}
			f[1] = g;
		}
		
		if(d != '' && f[0].length > 3){
			h = f[0];
			f[0] = '';

			for(j = 3; j < h.length; j+=3){
				i = h.slice(h.length - j, h.length - j + 3);
				f[0] = d + i +  f[0] + '';
			}

			j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
			f[0] = j + f[0];
		}

		c = (b <= 0) ? '' : c;
		return f[0] + c + f[1];

	}

	function privacy(pageName){
		
		window.open(pageName, 'ProCalisX', 'toolbar=yes,location=no,directories=no,status=yes,menubar=no,scrollbars=1,resizable=yes,copyhistory=yes,width=450,height=500');
		
	}
