
var console,_cons,psYPWrsid,jQ,regrowth={};

jQuery.noConflict();
jQ=jQuery;

if(jQ.browser.msie && jQ.browser.version<7){
	try{document.execCommand('BackgroundImageCache',false,true)}catch(e){}
}

jQ(document).ready(function(){
	setCartEvents();
});


function setCartEvents(){
	var b=jQ('input[name="amount"]').click(setBottlesAmount);
	if(b.length==0)return;
	regrowth.bottles=b;
	jQ.each(regrowth.bottles, function(i,el){
		el=jQ(el);
		if(el.attr('checked')){
			el.click();
		}
	});
	jQ('input[name="shipping_method_id"]').click(setCartTotal);
}
function setBottlesAmount(){
	var b;
	b=jQ(this);
	b.parent().addClass('selected');
	jQ.each(regrowth.bottles, function(i,el){
		if(el!=b[0]){
			jQ(el).parent().removeClass('selected');
		}
	});
	pr=jQ(b.siblings()[1]).children('strong').text().match(/[0-9\.]+/);
	setCartTotal();
}
function setCartTotal(){
	var pr,sh,tot;
	jQ.each(regrowth.bottles, function(i,el){
		el=jQ(el);
		if(el.parent().hasClass('selected')){
			pr=Number(el.siblings().eq(1).children('strong').text().match(/[0-9\.]+/));
		}
	});
	sh=Number(jQ('input[name="shipping_method_id"]:checked').parents(0).eq(0).next().text().match(/[0-9\.]+/));
	jQ('#totalprice').html(myRound(pr+sh,2));
}
function myRound(x, n){
	var dec=Math.pow(10,n),
	val=(Math.round(dec*x)/dec).toString(),
	i=val.indexOf('.'),out;
	if(i<0){
		out=val+'.00';
	}else if(val.length-i==2){
		out=val+'0';
	}else{
		out=val;
	}
	return out;
}

var psYPWrsid;
function initSupportWindow(){
	var src=(location.protocol.indexOf("https")==0?"https://secure.providesupport.com/image":"http://image.providesupport.com")+"/js/rx-partners/safe-standard.js?ps_h=YPWr\u0026ps_t="+new Date().getTime();
	var js = document.createElement('script');
	js.setAttribute('language', 'javascript');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', src);
	document.getElementById('live_support').appendChild(js);
}

function openSupportWindow(){/*
	if(psYPWrsid){
		window.open("http://messenger.providesupport.com/messenger/rx-partners.html?ps_s=" + psYPWrsid + "&ps_mht=" + psYPWrmht, "_blank", "menubar=0,location=0,scrollbars=auto,resizable=1,status=0,width=500,height=560");
	}else{
		initSupportWindow();
		var timer = setInterval(function(){
			if(psYPWrsid){
				clearInterval(timer);
				openSupportWindow();
			}
		}, 5);
	}
*/
pscfwxow();/* return false; */
}

var imgCodeUrl;
function reloadImageCode(){
	var img=document.getElementById('vcode_img');
	if(!imgCodeUrl) imgCodeUrl=img.src;
	img.src=imgCodeUrl+'?'+Math.random();
}

function popItUp(u,w,h){
	var l=(screen.availWidth  - w) / 2, t=(screen.availHeight - h) / 2
	,op='toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+w+',height='+h+',left='+l+',top='+t
	window.open(u, '_blank', op)
}
function showCertificate(){popItUp('https://mysecurebilling.com/certificates.php',500,350)}
