jQuery(function(){
	if ( jQuery('#content_area').find('table tr td b:contains("Please login to access your administration area.")').length ==0 ) {
	//	var name_check_url = window.location.protocol + '//' + window.location.host + '/myaccount.asp';
		var name_check_url = '/myaccount.asp';
		jQuery.ajax({
		url: name_check_url,
		type: 'GET',
		cache: false,
		success: function(data){
				if (jQuery(data).find('#customer_name').length ){
				var nm =', ' + jQuery(data).find('#customer_name').text(); 
				jQuery('#customer').html(nm);
				}
				else if ( PageName() == 'shoppingcart.asp' || PageName() == 'one-page-checkout.asp')
				{
				//jQuery('table[width="265"]').css('display','none');	
				}
			}
		});
	}
});

jQuery(function(){

	if ( typeof global_Current_ProductCode != "undefined" && jQuery("[name^=SELECT___] ").length )
	{

/* Copyright (c) 2009 Michael Manning (actingthemaggot.com) Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.*/
(function(A){A.fn.extend({currency:function(B){var C={s:",",d:".",c:2};C=A.extend({},C,B);return this.each(function(){var D=(C.n||A(this).text());D=(typeof D==="number")?D:((/\./.test(D))?parseFloat(D):parseInt(D)),s=D<0?"-":"",i=parseInt(D=Math.abs(+D||0).toFixed(C.c))+"",j=(j=i.length)>3?j%3:0;A(this).text(s+(j?i.substr(0,j)+C.s:"")+i.substr(j).replace(/(\d{3})(?=\d)/g,"$1"+C.s)+(C.c?C.d+Math.abs(D-i).toFixed(C.c).slice(2):""));return this})}})})(jQuery);jQuery.currency=function(){var A=jQuery("<span>").text(arguments[0]).currency(arguments[1]);return A.text()};

		function recal(){
			if(jQuery('select[name^="SELECT___"]').length ){
				//add up all selected options
				jQuery('select[name^="SELECT___"]').each(function(){
				var recal_var = 0;
				recal_var = jQuery(this).find("option:selected").text();	
			
					if (recal_var.indexOf('[Subtract -$') >0){
					price_result = recal_var.split('$')[1].slice(0,-1).replace(/,/g,'');
					current_val=current_val-price_result;
					}
					else if (recal_var.indexOf('[Add $') >0){
					price_result = parseFloat(recal_var.split('$')[1].slice(0,-1).replace(/,/g,''));
					current_val=current_val+price_result;
					}
				}); //each function
			} //if length

			if (jQuery('input[name^="SELECT___"][type="radio"]').length ){
				//add up all radio
				jQuery('input[name^="SELECT___"][type="radio"]:checked').each(function(){
				var recal_var = 0;
				recal_var = jQuery.trim(jQuery(this).next("span").text());

					if (recal_var.indexOf('[Subtract -$') >0){
					price_result = recal_var.split('$')[1].slice(0,-1).replace(/,/g,'');
					current_val=current_val-price_result;
					}
					else if (recal_var.indexOf('[Add $') >0){
					price_result = parseFloat(recal_var.split('$')[1].slice(0,-1).replace(/,/g,''));
					current_val=current_val+price_result;
					}
				}); //
			} //if length

			if (jQuery('input[name^="SELECT___"][type="checkbox"]').length ){
				//add up all radio
				jQuery('input[name^="SELECT___"][type="checkbox"]:checked').each(function(){
				var recal_var = 0;
				recal_var = jQuery.trim(jQuery(this).next("span").text());
	
					if (recal_var.indexOf('[Subtract -$') >0){
					price_result = recal_var.split('$')[1].slice(0,-1).replace(/,/g,'');
					current_val=current_val-price_result;
					}
					else if (recal_var.indexOf('[Add $') >0){
					price_result = parseFloat(recal_var.split('$')[1].slice(0,-1).replace(/,/g,''));
					current_val=current_val+price_result;
					}
				}); //each function
			} //if length
                        if (jQuery('#updated_price_row').length ){jQuery('#updated_price_row').remove();}
			if (current_val !== product_orig_price )
			{
			jQuery('font.pricecolor.colors_productprice').closest('tr').after('<tr id="updated_price_row"><td><span class="updated_price_text"><b>Price with Options: </span><span class="updated_price">$'+jQuery.currency(current_val,{s:",",d:".",c:2})+ '</span></td></tr>');
			} else {
			jQuery('font.pricecolor.colors_productprice').find('.price1:last').html('$' + jQuery.currency(current_val,{s:",",d:".",c:2}));
			}	
			current_val=product_orig_price;
		}

	var parent = jQuery('input[type="radio"][name^="SELECT___"],input[type="checkbox"][name^="SELECT___"]').parent('td');
	parent.contents().filter(function() { return this.nodeType != 1; }).wrap('<span></span>');
	var current_val;
	var price_result;
	var product_orig_price = parseFloat(jQuery('font.pricecolor.colors_productprice:not(.pricecolorsmall)').find('.price1:last').text().replace('$','').replace(/,/g,''));
	current_val = product_orig_price;
	recal();
		jQuery('select[name^="SELECT___"],input[name^="SELECT___"]').change(function(){
		recal();
		}); //change

	jQuery("a[href^='javascript:change_option']").click(function(){
		var result_href = jQuery(this).attr('href').match(/\'(.*?)\'/)[1];
		var result_val = jQuery(this).attr('href').match(/\,(.*?)\)/)[1];
		change_option(result_href,result_val);
		recal();
		return false;
	});
	}
}); //doc

jQuery(function(){
	if (typeof global_Current_ProductCode !="undefined" && jQuery('.acc_sim').length ) {
		var product_acc_table = jQuery('.acc_sim').closest('table');
		jQuery(product_acc_table).find('a.productnamecolorsmall.colors_productname').each(function(){
		var acc_title_name = jQuery(this).attr('title').substring(0, jQuery(this).attr('title').lastIndexOf(','));
		jQuery(this).text(acc_title_name);
		});
	}
});

//thickbox function 
function thickbox(){ 
$("a[id^='product_photo_zoom_url']").click(function(){    
var img_fix; 
var t = this.title || null; 
var s = $("img#product_photo").attr("src"); 
var g = this.rel || false; 
if (s.lastIndexOf('-T.jpg') !=-1) { 
img_fix = (s.replace("-T.jpg",".jpg")); 
} 
else 
{ 
img_fix = (s.replace("T.jpg",".jpg")); 
} 
tb_show(t,img_fix,g); 
return false; 
}); 
} 
//thickbox init end


jQuery(function(){
	if (typeof global_Current_ProductCode !="undefined" && jQuery('#product_id').length ) {
	jQuery('#product_id').html('ID # ' +global_Current_ProductCode);	
	}
});


jQuery(function(){
	if ( typeof global_Current_ProductCode != "undefined" && jQuery('.avail_tr').length){
		jQuery('.avail_tr').each(function(){
		var $this=jQuery(this);
		var avil_pc_code=jQuery(this).find('.avail_td').text();
			jQuery.ajax({
				url: '/v/check_availability.asp?product_code=' +avil_pc_code,
				type: 'GET',
				cache: false,
				async: false,
					success: function(data){
  		    			var xml;
  						if (typeof data == "string" && jQuery.browser.msie ) {
 							xml = new ActiveXObject("Microsoft.XMLDOM");
 							xml.async = false;
   							xml.loadXML(data);
  						} else {
  							xml = data;
						}
					jQuery($this).find('.avail').text(jQuery(xml).find('Availability').text().replace('<div class="global_msg blue">','').replace('<div class="global_msg yellow">','').replace('</div>',''));
					} 
			});
		});
	}
});
