function price_parse(mixed) {
   var tep_num;
   var tep = '';
   if (mixed.search(/\$/) > 0) {
     tep = mixed.substr(mixed.lastIndexOf("("),mixed.lastIndexOf(")") - mixed.lastIndexOf("("));
   }
   tep = tep.replace(/([.]*)([-])?[$]([0-9]{0,3})[,]?([0-9]{1,3}).([0-9]{2})/, "$2$3$4.$5").replace(/[^-0-9]*/,''); 
   tep_num = parseFloat(tep); 
   if (isNaN(tep_num)) tep_num = 0; 
   return tep_num;
}




function optTotal() {
   var sub;
   var price;
   var optSub;
   var frm;
   var tep_val;
   optSub = 0;

   frm = document.cart_quantity;
   for (i=0;i<frm.elements.length;i++) {
	if (frm.elements[i].tagName == "SELECT")
           optSub += price_parse(frm.elements[i].options[frm.elements[i].selectedIndex].innerHTML);
   }
   sub = document.getElementById('jSub');
   price = document.getElementById('jPrice');
   sub.innerHTML = "<strong>" + money_format((price_parse(price.value)) + optSub) + "</strong>";
   return;
}

function popupWindow(url) { 	
	window.open(url,'popupWindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150');
  return;
}

function emailFriend(product_id, man) {

	var url = "includes/modules/email_a_friend/email_a_friend.php?product_id=" + product_id + "&man=" + man;

	window.open(url, 'emailafriend', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=503,height=376,screenX=150,screenY=150,top=150,left=150');
  return;
}

function email_a_friend() {
	$('#email_box')

	// open window 
	.dialog({
		width: 600,
		height: 440,
		title: 'Email a Friend'
	})
	
	// empty contents
	.empty()
	
	.append('<span style="display:block; margin-top:100px; text-align:center; font-weight: bold; font-size: 45px; font-family: verdana; color: white;">Loading<br>Please Wait ...</span>')

	// load contents
	.load(JSconfig.serverName + '/includes/modules/email_a_friend/email_friends.php?' + (new Date()).getTime());
}

function r_list_pagination(page_id) {
	var products_id = $('#products_id').attr("value");
	$('ul.reviews_list').slideUp("slow");
	$.post(
		JSconfig.serverName + '/ajax/review_list.php',
		{
			page: parseInt(page_id),
			products_id: parseInt(products_id)
		},
		function(data){$('ul.reviews_list').empty().append(data).slideDown("slow")
	});
}
function pageselectCallback(page_id, numPage, maxentries){
	r_list_pagination(page_id);
	if(page_id == numPage - 1){
		if((page_id * 5) + 1 == maxentries){
			$('div.searchresult').text("Showing search results " + maxentries);
		} else {
			$('div.searchresult').text("Showing search results " + ((page_id * 5) + 1) + "-" + (maxentries));
		}
	} else{
		$('div.searchresult').text("Showing search results " + ((page_id * 5) + 1) + "-" + ((page_id * 5) + 5));
	}
}

function j_pagination(total_item) {
		$('div.pagination').pagination(total_item, {
		num_edge_entries: 2,
		num_display_entries: 8,
        callback: pageselectCallback
		});
}