// JavaScript Document
<!-- javascript for count order -->
function jfunc_onqty(var_no){
	var jqty = 'var_product_qty'+var_no;
	var jprice = 'var_product_price'+var_no;
	var jcost = 'var_product_cost'+var_no;
	
	var jqty = document.getElementById(jqty);
	var jprice = document.getElementById(jprice);
	var jcost = document.getElementById(jcost);
	
	jcost.value = jfunc_round_decimals(jqty.value * jprice.value, 2);
	
	if(jcost.value == "NaN.00"){
		alert("Please enter numbers only");
		jprice.value = "0.00";
		jqty.value = "1";	
		jcost.value = "0.00"
	}else{
		jfunc_add_subtotal();	
	}
}

function jfunc_add_subtotal(){
	var var_sub1total = 0;
	for (var_no=1; var_no<11; var_no++) { 
		var jcost = 'var_product_cost'+var_no;
		var jcost = document.getElementById(jcost).value;
				
		var var_sub1total = parseFloat(var_sub1total) + parseFloat(jcost);
	}
	document.getElementById('var_sub_total').value = jfunc_round_decimals(parseFloat(var_sub1total), 2);
	jfunc_get_total();
}

function jfunc_get_total(){
	document.getElementById('var_total').value = jfunc_round_decimals(parseFloat(document.getElementById('var_freight').value) + parseFloat(document.getElementById('var_sub_total').value), 2);
}


<!-- javascript for mouseover menu tr -->
function rollIn(thisItem) { 
	thisItem.style.background="#4aff00"; 
} 

function rollOut(thisItem) { 
	thisItem.style.background=""; 
}

<!-- javascript for mouseover menu top -->
function rollInMenu(thisItem) { 
	thisItem.style.backgroundImage="url(images/button_menu_on.gif)"; 
} 

function rollOutMenu(thisItem) { 
	thisItem.style.backgroundImage="url(images/button_menu_off.gif)"; 
}

<!-- Function for login box -->
function jfunc_check_login_box(){
	var var_form = document.frmMemberLoginBox;
	if((var_form.Member_Username.value == "") || (var_form.Member_Password.value == "")){
		alert('Please enter your username and password.');	
	}else{
		var_form.submit();	
		//alert('Both bla');
	}
}

<!-- member logout -->
function jfunc_member_logout ()
{
    var message = "Are you sure you want to Logout?";
    var return_value = confirm(message);
    if ( return_value == true )
        {
        document.location='member_login_process.php?Get_Member_Logout=true';
        }
}


<!-- javascript to show/hide subcat gallery -->
function jfunc_show_row(var_row_id, var_button){
	f = document.getElementById(var_row_id);
	b = document.getElementById(var_button);
	if(f.style.visibility == "hidden"){
		f.style.visibility = "visible";
		f.style.position = "relative";
		b.src = "images/button-minus.gif";
	}else{
		f.style.visibility = "hidden";
		f.style.position = "absolute";
		b.src = "images/button-plus.gif";
	}
}

<!-- function to round decimals -->
function jfunc_round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}
function pad_with_zeros(rounded_value, decimal_places) {
    // Convert the number to a string
    var value_string = rounded_value.toString()
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")
    // Is there a decimal point?
    if (decimal_location == -1) {
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {
        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length    
    if (pad_total > 0) {        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

<!-- FORM VALIDATION
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.title; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}