//	RATE CARD SCRIPTS

if(typeof logc !== 'function'){
	function logc(inp){
		if (window.console){
			console.log(inp);
		}
		return inp;
	}
}

if (!Chem){ var Chem = {}; }

//	Updates State Terms and Cancellation Notice
//	Using user supplied zip code

Chem.UpdateTerms = (function(){
	return function(element){
		if (element.length == 0){ return; }
		this.state = element;
		this.init();
	}
})();

Chem.UpdateTerms.prototype = {
	change: function(){
		var data = {
			stateName: this.state.attr('value'),
			postalCode: $('#zip').attr('value'),
			orderString: $('#OrderString').attr('value'),
			countryCode: this.state.find('option:selected').parent().attr('ccode')
		},
		update = $.proxy(this.updateFields, this);

		$.ajax({
			data: data,
			type: 'POST',
			success: update,
			url: Chem.BuildUrl('subscribe', 'GetProductByStateName')
		});
	},
	updateFields: function(data){
		var notice = data.SubscribeText.CancelNotice;
		if (data.SubscribeText.SubscribeTextId != 14){
			$('#subterms').html(data.SubscribeText.Text);
			if (notice.length != 0){
				$('#cancelnotice').show().children('div').html(notice);
			}
			else {
				$('#cancelnotice').hide().children('div').html('');
			}
		}
		else {
			$('#subterms').html('');
			$('#cancelnotice').hide().children('div').html('');
		}
		$('#StateCode').attr('value', data.StateCode);
		$('span.product-months').text(data.OrderedProduct.Months);
		$('span.product-price').text('$' + data.ProductPrice.toFixed(2));
		$('#currentorder tr.tax td.price').text('$' + data.TaxAmount.toFixed(2));
		$('#currentorder tr.total td.price').text('$' + data.TotalAmount.toFixed(2));
		$('#CountryCode').attr('value', this.state.find('option:selected').parent().attr('ccode'));
	},
	init: function(){
		if (this.state.attr('value').length != 0){
			this.change();
		}
		var change = $.proxy(this.change, this);
		this.state.change(change).parents('form:first').find('#zip').change(change);
	}
};

Chem.UpdateCityState = (function(){
	return function(element){
		if (element.length == 0 || element.hasClass('js')){ return; }
		this.zip = element.addClass('js');

		element.parents('div.block:first').after($('<div id="csblock" class="block" style="display: none;"><label for="citystatesel">City, State</label><select id="citystatesel"><option value="">Select City, State</option><option value="notlisted">Not listed</option></select></div>'));

		var c = {
			city: $('#City'),
			state: $('#State'),
			terms: $('#subterms'),
			csblock: $('#csblock'),
			scode: $('#StateCode'),
			ccode: $('#CountryCode'),
			menu: $('#citystatesel'),
			ordstr: $('#OrderString'),
			notice: $('#cancelnotice'),
			price: $('span.product-price'),
			months: $('span.product-months'),
			tax: $('#currentorder tr.tax td.price'),
			total: $('#currentorder tr.total td.price')
		},
		data = new Chem.Data({
			oldZip: '',
			newZip: element.attr('value')
		}),
		cnst = new Chem.Const(c);

		this.getData = $.proxy(data.getData, data);
		this.setData = function(key, val){
			data.setData(key, val);
			return this;
		};
		this.getConst = cnst.getConst;

		this.init();
	}
})();

Chem.UpdateCityState.prototype = {
	showTextBox: function(){
		var c = this.getConst();
		c.city.parents('div.block:first').show();
		c.state.parents('div.block:first').show();
		return this;
	},
	hideTextBox: function(){
		var c = this.getConst();
		c.city.parents('div.block:first').hide();
		c.state.parents('div.block:first').hide();
		return this;
	},
	emptyTextBox: function(){
		var c = this.getConst();
		c.city.attr('value', '');
		c.state.attr('value', '');
		return this;
	},

	updateProdInfo: function(data){
		var c = this.getConst(), notice = data.SubscribeText.CancelNotice;
		if (data.SubscribeText.SubscribeTextId != 14){
			c.terms.html(data.SubscribeText.Text);
			if (notice.length != 0){
				c.notice.show().children('div').html(notice);
			}
			else {
				c.notice.hide().children('div').html('');
			}
		}
		else {
			c.terms.html('');
			c.notice.hide().children('div').html('');
		}
		c.scode.attr('value', data.StateCode);
		c.ccode.attr('value', data.CountryCode);
		c.months.text(data.OrderedProduct.Months);
		c.tax.text('$' + data.TaxAmount.toFixed(2));
		c.total.text('$' + data.TotalAmount.toFixed(2));
		c.price.text('$' + data.ProductPrice.toFixed(2));
	},
	getProdInfo: function(){
		var c = this.getConst(),
		data = {
			stateCode: c.scode.attr('value'),
			postalCode: this.zip.attr('value'),
			countryCode: c.ccode.attr('value'),
			orderString: c.ordstr.attr('value')
		},
		updateProdInfo = $.proxy(this.updateProdInfo, this);
		$.ajax({
			data: data,
			type: 'POST',
			success: updateProdInfo,
			url: Chem.BuildUrl('subscribe', 'GetProduct')
		});
	},

	updateCityStateFields: function(){
		var c = this.getConst(), val = c.menu.attr('value');
		switch(val){
			case(''):
				this.emptyTextBox();
				break;
			case('notlisted'):
				c.csblock.hide();
				this.emptyTextBox().showTextBox();
				break;
			default:
				var codes = val.split(', '), names = c.menu.children('option:selected').text().split(', ');
				c.city.attr('value', names[0]);
				c.state.attr('value', names[1]);
				c.scode.attr('value', codes[0]);
				c.ccode.attr('value', codes[1]);
				this.getProdInfo();
				break;
		}
	},

	addOptions: function(data){
		var opt = '', c = this.getConst(), city = c.city.attr('value'), state = c.state.attr('value');
		$.each(data, function(key, val){
			if (city == val.Name){
				opt += '<option selected="selected" value="' + val.StateCode + ', ' + val.CountryCode  + '">' + val.Name + ', ' + val.StateName + '</option>';
			}
			else {
				opt += '<option value="' + val.StateCode + ', ' + val.CountryCode  + '">' + val.Name + ', ' + val.StateName + '</option>';
			}
		});
		c.csblock.show();
		c.menu.children().slice(1, -1).remove().end().end()
		.children().eq(0).after(opt);
		if (data.length == 1){
			c.menu.children().eq(1).attr('selected', true);
			if (city.length == 0 && state.length == 0){
				c.menu.children().attr('selected', false).eq(0).attr('selected', true);
			}
			else if ((city.toLowerCase() == data[0].Name.toLowerCase() && state.toLowerCase() == data[0].StateName.toLowerCase()) || city.length == 0){
				c.city.attr('value', data[0].Name);
				c.state.attr('value', data[0].StateName);
				c.scode.attr('value', data[0].StateCode);
				c.ccode.attr('value', data[0].CountryCode);
				this.getProdInfo();
			}
			else{
				c.csblock.hide();
				this.showTextBox();
			}
		}
		else{
			var foundMatch = false;
			for (var i=0; i<data.length; i++){
				var d = data[i];
				if (d.Name.toLowerCase() == city.toLowerCase() && d.StateName.toLowerCase() == state.toLowerCase()){
					foundMatch = true;
					c.menu.children().eq(i+1).attr('selected', true);
				}
			}
			if (foundMatch){
				this.hideTextBox();
			}
			else {
				if (city.length != 0){
					c.csblock.hide();
					this.showTextBox();
				}
				else {
					this.emptyTextBox().hideTextBox();
				}
			}
		}
		this.setData('oldZip', this.zip.attr('value'));
	},

	updateCityStateList: function(data){
		var c = this.hideTextBox().getConst();
		switch(data.length){
			case(0):
				c.csblock.hide();
				this.showTextBox();
				break;
			default:
				this.addOptions(data);
				break;
		}
	},
	getCityStateList: function(){
		var c = this.getConst(),
		d = this.getData(),
		zipval = this.zip.attr('value'),
		data = {
			billPostalCode: zipval
		},
		updateCityStateList = $.proxy(this.updateCityStateList, this);
		if (zipval.length == 0){ return; }
		else if (zipval != d.oldZip){
			if (!c.city.is(':visible')){
				this.emptyTextBox();
			}
			$.ajax({
				data: data,
				type: 'POST',
				success: updateCityStateList,
				url: Chem.BuildUrl('subscribe', 'getCityList')
			});
		}
		else {
			if (c.city.attr('value').length == 0 && c.state.attr('value').length == 0){
				c.csblock.show();
				this.hideTextBox();
				c.menu.children().attr('selected', false).eq(0).attr('selected', true);
			}
		}
	},
	init: function(){
		var c = this.getConst(),
		change = $.proxy(function(){
			if (this.zip.attr('value').length == 0){ return; }
			else if ((c.city.is(':visible') && c.city.attr('value').length != 0) || (c.state.is(':visible') && c.state.attr('value').length != 0)){ return; }
			this.getCityStateList();
		}, this),
		updateCityStateFields = $.proxy(this.updateCityStateFields, this);

		if (this.zip.attr('value').length != 0){
			this.getCityStateList();
		}
		this.zip.blur(change);
		c.menu.change(updateCityStateFields);
	}
};

(function($) {

//	NUMBER FORMATING UTILITY

	$.numDec = function(num, len){
		var z = '';
		if (typeof num == 'undefined'){
			logc('$.numDec: Undefined number!');
			return;
		}
		var str = num.toString().split('.');
		if (str.length == 1){
			for (i=0; i<len; i++){
				z += '0';
			}
			return (num + '.' + z);
		}
		else {
			if (str[1].length < len){
				var diff = len - str[1].length;
				for (i=0; i<diff; i++){
					z += '0';
				}
				num = str[0] + '.' + str[1] + z;
			}
			else {
				pat = new RegExp('([0-9]{' + len + '})[0-9]+', "");
				num = str[0] + '.' + str[1].replace(pat, '$1');
			}
			return num;
		}
	}

//	PLUGIN: SHOW FLOATING RATE CARD

	$.fn.subscribe = function(){
		if(this.length == 0) return $(this);

//	Plugin settings

		var settings = {

		},

		$trigger = $(this),

//	Remove header subscribe button

		removeButton = function(){
			$('#banner').find('a.button.subscribe').parents('div.set').remove().end().end().find('.subscribe').removeClass('subscribe').attr('href', '/email');
		},

//	Check user subscription status

		successcallback = function(data){
			if (data == true){
				removeButton();
			}
		};

//	Initiate frame plugin

		$('body').insertFrame();

		var frame = $('body').data('frame'),
//		frameurl = $('#banner a.button.subscribe').attr('href');

		frameurl = '/subscribe?pop=true';

		frame.closecb = function(){
			$.chem.isSub({
				successcallback: successcallback
			});
		};

//	Show popup trigger click

		$trigger.click(function(){
			if (!$(this).hasClass('subscribe')) return;

			frame.updateurl(frameurl);
			setTimeout(function(){
				frame.showframe();
			}, 100);
			return false;
		});

		return $(this);
	}

//	PLUGIN: SHOW FLOATING RATE CARD ON CLICK

	$.fn.showSubPop = function(options){
		var showsub = function(element, options){

			var settings = $.extend({
				protocol: 'http:'
			}, options || {}),

			$btn = $(element),

			dest = {
				url: settings.protocol + '//' + document.domain + $btn.attr('href'),
				accepturl: window.location.protocol + '//' + document.domain + $btn.attr('accepturl'),
				rejecturl: window.location.protocol + '//' + document.domain + $btn.attr('rejecturl')
			};

			$('body').insertFrame();
			var frame = $('body').data('frame'),

			checkStatus = function(data){
				if(data == true){
					window.location = dest.accepturl;
				}
				else {
					window.location = dest.rejecturl;
				}
			},

			clickhandler = settings.clickhandler ||
				function( e ){
					frame.updateurl(dest.url);
					frame.closecb = function(){
						$.chem.isSub({
							successcallback: checkStatus
						});
					};

					frame.showframe();
					return false;
				};

			$btn.bind('click', { frame : frame, frame_src : dest.url }, clickhandler);

			if ($btn.hasClass('showonload')){
				$btn.trigger('click');
			}
		}

		return this.each(function(){
			var element = $(this);
			if (element.data('showsub')) return;
			var sub = new showsub(this, options);
			element.data('showsub', sub);
		});
	}

//	PLUGIN: UPDATE PRICE TABLE ON PRODUCT SELECTION

	$.fn.updatePrice = function(){
		if (this.length == 0){
			return $(this);
		}

		var $radio = $(this).find('input[type="radio"]'),

		stcode = $('#statecode').attr('value'),
		cncode = $('#countrycode').attr('value'),

		$subterms = $('#subterms'),
		$price = $('span.product-price'),
		$months = $('span.product-months'),
		$tax = $('#currentorder tr.tax').children('td.price'),
		$total = $('#currentorder tr.total').children('td.price'),

		changefn = function(e){
			if (e.target.tagName.toLowerCase() === 'input'){
				if ($(e.target).attr('type').toLowerCase() === 'radio'){
					return false;
				}
				else {
					e.stopPropagation();
					$(this).parents('form').trigger('submit');
					return false;
				}
			}
			var href = '/Subscribe/BillingInfo/?sprod=',
			$radio = $(this).find('input[type="radio"]'),
			fcb = function(){},
			scb = function(data){
				$subterms.html(data.SubscribeText.Text);
				$tax.text('$' + $.numDec(data.TaxAmount, 2));
				$price.text('$' + $.numDec(data.ProductPrice, 2));
				$total.text('$' + $.numDec(data.TotalAmount, 2));
				$months.text(data.OrderedProduct.Months);
			},
			rb = $radio.data('rbtn');
			rb.check();
			if ($price.length != 0){
				$.chem.getProduct({
					stateCode: stcode,
					countryCode: cncode,
					successcallback: scb,
					failurecallback: fcb,
					orderString: $(this).find('input[type="radio"]').attr('value')
				});
			}
			$('#editbillinginfo').attr('href', href + $radio.attr('value'));
		};

		$('div.rateplan').click(changefn);

		return $(this);
	}

//	PLUGIN: UPDATE PRICE TABLE ON PRODUCT SELECTION

	$.fn.freezePage = function(){
		if (this.length == 0 || $('iframe[name="subscribe"]').length == 0){
			return $(this);
		}
		$('body').css({
			overflow: 'hidden',
			height: $(window).height()
		});
		$(window).resize(function(){
			$('body').height($(window).height());
		});
		return $(this);
	}

//	PLUGIN: UPDATE PRICE TABLE ON PRODUCT SELECTION

	$.fn.dirUser = function(){
		if (this.length == 0 || $('iframe[name="subscribe"]').length == 0){
			return $(this);
		}
		var $btn = $(this).parent().children('a'),
		acceptUrl = $(this).attr('accepturl'),
		rejectUrl = $(this).attr('rejecturl'),
		clfn = function(){
			var scb = function(data){
				if (data == 'true'){
					window.location = acceptUrl;
				}
				else {
					window.location = rejectUrl;
				}
			},
			opt = {
				successcallback : scb
			};
			$.chem.isSub(opt);
			return false;
		};
		$btn.click(clfn);
	}

//	PLUGIN: GET CITY STATE DATA

	$.fn.getCityStateData = function(options){

		var csdata = function(element, options){
			var settings = $.extend({
			}, options || {}),

			$ms = '',
			$zip = $(element),
			zipval = $zip.attr('value'),
			$form = $zip.parents('form'),
			$city = $form.find('input.addrcity'),
			$state = $form.find('input.addrstate'),
			$txtbox = $form.find('div.citystatetext').hide();

//	Install select tag and hide city and state fields

			if ($('#citystatesel').length == 0){
				$zip.parents('div.block').after($('<div class="block"><label for="citystatesel">City, State</label><select id="citystatesel"><option>Select City, State</option><option value="notlisted">Not listed</option></select></div>').hide());
			}
			$menu = $('#citystatesel');

//	Check city text field and if not empty select
//	the appropriate option

			var updateMenu = function(){
				var city = $city.attr('value');
				if (city.length == 0) return;
				var $options = $menu.children().removeAttr('selected');
				for (i=0; i<$options.length; i++){
					var $i = $options.eq(i),
					text = $i.text().split(', ');
					if (city == text[0]){
						$i.attr('selected', true);
					}
				}
			},

			updateTermsPrice = function(options){
				var $promoterms = $('#promoterms'),
				$subterms = $('#subterms'),
				$notice = $('#cancelnotice'),
				$months = $('span.product-months'),
				$tax = $('#currentorder tr.tax').children('td.price'),
				$price = $('span.product-price'),
				$total = $('#currentorder tr.total').children('td.price'),
				scb = function(data){
					var price = data.ProductPrice,
					tax = data.TaxAmount,
					total = data.TotalAmount,

					subtext = data.SubscribeText.Text,
					promotext = data.SubscribeText.PromotionText,
					notice = data.SubscribeText.CancelNotice;

					if (notice.length > 50){
						$notice.html(notice);
					}
					else {
						$notice.html('');
					}
					$subterms.html(subtext);
					$promoterms.html(promotext);
					$tax.text('$' + $.numDec(tax, 2));
					$price.text('$' + $.numDec(price, 2));
					$total.text('$' + $.numDec(total, 2));
					$months.text(data.OrderedProduct.Months);
					$('#StateCode').attr('value', data.StateCode);
				},
				fcb = function(){};
				$.chem.getProduct({
					successcallback: scb,
					failurecallback: fcb,
					stateCode: options.stcode,
					countryCode: options.cncode,
					orderString: $('#OrderString').attr('value')
				});
			},

//	Insert city, state data retrieved and select option if
//	there is only one city or if city field has data

			insertOptions = function(data){
				$menu.children().slice(1, -1).remove();
				if(data.length == 0){
					$menu.parent().hide();
					$city.attr('value', '');
					$state.attr('value', '');
					$txtbox.show();
					return;
				}
				$txtbox.hide();
				for (i=0; i<data.length; i++){
					var d = data[i];
					$menu.children().eq(0).after($('<option value="' + d.CountryCode + ', ' + d.StateCode + '">' + d.Name + ', ' + d.StateName + '</option>'));
				}
				$menu.parents('div.block').show();
				if (data.length == 1){
					var text = $menu.children().eq(1).attr('selected', true).text().split(', ');
					$city.attr('value', text[0]);
					$state.attr('value', text[1]);
					updateTermsPrice({
						stcode: d.StateCode,
						cncode: d.CountryCode
					});
				}
				else if (data.length > 1){
					$menu.children().removeAttr('selected').eq(0).attr('selected', true);
					if ($city.attr('value').length != 0){
						updateMenu();
					}
				}
			},

			showTextBox = function(){
				$txtbox.show();
			},

//	Get data if zip code contains data

			getCityState = function(){
				$ms = $('input[name="modelstate"]');
				zipval = $zip.attr('value');
				if (zipval.length == 0){
					$menu.parent().hide();
					$city.attr('value', '');
					$state.attr('value', '');
					return;
				}
				else if (zipval.length < 5 || zipval.length > 7){
					alert('zip code entered is invalid');
					return;
				}
				$.chem.getCityState({
					zipcode: zipval,
					failurecallback: showTextBox,
					successcallback: insertOptions
				});
			},

			menuchange = function(){
				var val = $menu.attr('value').toLowerCase();
				switch (val){
					case('notlisted'):
						$menu.parent().hide();
						$txtbox.show();
					case('select city, state'):
						$city.attr('value', '');
						$state.attr('value', '');
						break;
					default:
						var $opt = $menu.children('option:selected'),
						text = $opt.text().split(', '),
						codes = $opt.attr('value').split(', ');
						$city.attr('value', text[0]);
						$state.attr('value', text[1]);
						var options = {
							stcode: codes[1],
							cncode: codes[0]
						};
						updateTermsPrice(options);
				}
			};
			getCityState();
			$zip.change(getCityState);
			$menu.change(menuchange);
		}

		return this.each(function(){
			var element = $(this);
			if (element.data('csdata')) return;
			var citystatedata = new csdata(this, options);
			element.data('csdata', citystatedata);
		});

	}

//	PLUGIN: DETECT CREDIT CARD TYPE

	$.fn.detectCardType = function(){
		if (this.length == 0){
			return $(this);
		}
		var cardtype = '',
		$icons = $('div.ccicons'),
		$amex = $icons.find('input[type="radio"]').eq(0),
		setDefault = function(){
			if (!$amex.attr('checked')){
				$icons.find('li').find('input').attr('checked', false);
				$amex.attr('checked', true);
			}
		},
		gettype = function(){
			var val = $(this).attr('value');
			if (!val){
				val = $('#CreditCardNumber').attr('value');
			}
			$icons.find('li').addClass('on').find('input');
			if (val.length > 12 && val.length < 17){
				cardtype = '';
				if (val.match(/^(5[1-5]\d{2})\d{12}$/)){
					cardtype = 'mscd';
				}
				else if (val.match(/^(4\d{3})(\d{12}|\d{9})$/)){
					cardtype = 'visa';
				}
				else if (val.match(/^3[4,7]\d{13}$/)){
					cardtype = 'amex';
				}
				else if (val.match(/^([6011]{4})([0-9]{12})$|^([62]{2})([0-9]{14})$|^(64[4-9])\d{13}$|^(65[0-9])\d{13}$/)){
					cardtype = 'disc';
				}
				else if (val.match(/(^(30)[0-5]\d{11}$)|(^(36)\d{12}$)|(^(38[0-8])\d{11}$)/)){
					cardtype = 'dnrs';
				}
				if (cardtype.length > 0){
					$icons
						.find('li.' + cardtype).addClass('on')
						.find('input').attr('checked', true).end()
						.siblings().removeClass('on')
						.find('input').attr('checked', false);
				}
				else {
					setDefault();
				}
			}
			else {
				setDefault();
			}
		};
		$(this).keyup(gettype).blur(gettype);
		gettype();
		return $(this);
	}

//	PLUGIN: SHOW SECURITY INFO

	$.fn.showSecInfo = function(options){
		var secinfo = function(element, options){

			var settings = $.extend({
			}, options || {}),

			$lnk = $(element),

			clfn = function(){
				if ($lnk.hasClass('off')){
					$lnk.html('Show Info &raquo;');
					$lnk.parent().siblings('div.info').hide();
				}
				else {
					$lnk.html('Hide Info &raquo;');
					$lnk.parent().siblings('div.info').show();
				}
				$lnk.toggleClass('off');
				return false;
			};

			$lnk.click(clfn);

		}

		return this.each(function(){
			var element = $(this);
			if (element.data('info')) return;
			var info = new secinfo(this, options);
			element.data('info', info);
		});
	}

//	UPDATE RATE CARD UI

	$.chem.updateRcUI = function(){

		$.chem.updateUI();

		try{
			$('div.sechelp').showinfo();					//	Ratecard Security Info Popup

			$('#CreditCardNumber').detectCardType();		//	Ratecard Detect Credit Card Type

//			$('#ZipCode').getCityStateData();				//	Retrieve city state data based on user supplied zip code
			new Chem.UpdateCityState($('#ZipCode'));

			$('input.numbersonly').acceptNumbersOnly();		//	Filters for ratecard text boxes
			$('#SecurityCode').setInputLimit({
				maxlength: 4
			});
			$('#CreditCardNumber').setInputLimit({
				maxlength: 16
			});

			$('#plans').updatePrice();						//	Update price table based on product selection

			$('#billinginfo').formSubmit();

			$('input.input-validation-error').parents('.textfield, .textarea').addClass('validation-error');

			$('#secinfo p.secure a').showSecInfo();

			$('#secinfo p.nwin').click(function(){
				var href = $(this).attr('href');
				$.secure_window(href, 'secure_billing');
				return false;
			});

			$('#divSubContainer input[type="radio"]').styleRadioBtn();
			$('#divSubContainer input[type="checkbox"]').styleCheckBox();

			new Chem.UpdateTerms($('select[name="State"]'));
		}
		catch(error){
			logc('Rate card ui update error');
			logc(error);
		}

	}

})(jQuery);

//	PLUGIN: SECURE WINDOW POPUP FOR RATE CARD

(function($){

$.secure_window = function(url, name, options){

	var parsed = [],
	settings = $.extend({
		status: 0,
		toolbar: 0,
		width: 850,
		menubar: 0,
		height: 520,
		location: 1,
		scrollbars: 1
	}, options);

	for (var attr in settings){
		parsed.push(attr + '=' + settings[attr]);
	}

	window.open(url, name, parsed.join(','), true);

};

})(jQuery);

//	INITIATE RATECARD UI

$(function(){

try{

	$('body').freezePage();
	$('#banner .subscribe').subscribe();
	$('.showsubpop').showSubPop();
	$('.free-comm-sub-popup').showSubPop({

		protocol: 'https:',

		clickhandler: function( e ){

			var frame = e.data.frame,
				frame_src = e.data.frame_src;

			frame.updateurl(frame_src);
			frame.closecb = e.data.frame.hideframe;
			frame.showframe();
			return false;

		}

	});

	if ($('#popPRofile').length != 0){
		$('a').focus(function(){
			$(this).trigger('blur');
		});
	}

	$('iframe[name="subscribe"]').dirUser();
	$.chem.updateRcUI();

	$('body a.print-notice').live('click', function(){
		var url = Chem.BuildUrl('Subscribe', 'CancelNotice') + '?StateCode=' + $('#StateCode').attr('value');
		window.open(url, 'cancel_notice', 'location=1, status=1, scrollbars=1, top=100, left=100, width=800, height=650');
		return false;
	});

	if ($('#print-cancel-notice').length != 0){ window.print(); }
}
catch(error){
	logc(error)
}

});


