// JavaScript Document

$(function() {

/*Auto Grow */
// $('.input-textarea textarea').elastic();  

/* Watermarks */
$('.input-text, .input-textarea').each(function() {
	var $this = $(this);
	$this.find(':input').watermark( $this.find('label').text().replace(/\*\s?/gi, '') + '...', {className:'watermark', useNative:false} );
});

/* Stylish Select */
$('.input-select select').each(function(){
	var $this = $(this);
	$this.sSelect().change(function() {
		$this = $(this);
		if($this.getSetSSValue() == '') {
			$this.closest('.input-select').find('.selectedTxt').addClass('watermark');
		} else {
			$this.closest('.input-select').find('.selectedTxt').removeClass('watermark');
		}
	});
	if($this.getSetSSValue() == '') {
		$this.closest('.input-select').find('.selectedTxt').addClass('watermark');
	}
	$this.closest('.input-select').find('.newListSelected').addClass( $this.attr('class') );
});
if( $.browser.msie ) {
	var selCount = $(".input-select").size();
	$(".input-select").each(function(){
		$this = $(this);
		$this.css("z-index", selCount - $(".input-select").index(this));
	});
}
/* Simple Scroll */
//$('.form-item-select .newListSelected ul').jScrollPane();

/* Focus class */
$('.input-text input, .input-textarea textarea').focus(function(e) {
	$('.focus').removeClass('focus');
	$(this).closest('.form-item').find('.input').addClass('focus');
	$(this).closest('.form-item').find('.label').fadeIn(200);
	e.stopPropagation();
	$("body").click();
});
$('.input-text input, .input-textarea textarea').click(function(e) {
	e.stopPropagation();
});
$('.input-text input, .input-textarea textarea').blur(function(e) {
	$('.focus').removeClass('focus');
	$(this).closest('.form-item').find('.label').fadeOut(200);
});

/* Checkbox */
$('.input-checkbox input[type=checkbox]').checkbox({
	cls: 'jquery-checkbox',
	empty: '/~images/spacer.gif'
}).click(function(e) {
	$("body").click();
});

/* Clear Form */
$('a.btn-clearform').click(function() {
	$( $(this).attr('rel') ).submit();
});

$(".btn-print, #wrResult .content, #wrResult .screen-loading").hide();

$(".btn-print").click(function(e) {
	window.print();
});

$("form[name^=formHWProdCal]").wrGateway({
	appName:"ElectricProductCalculator",
	transform: "/products/heatweave/calculator/_content/www/_inc/products-heatweave-calculator-exec.asp",
	target: "#wrResult .content",
	success:function(d) {
	},
	error:function(x,s,e) {
		$("#wrResult .content").html( x.responseText );
	},
	onSubmit:function(e) {
		$("input#heatedArea").val( $("input#floorArea").val() - $("input#unheatedArea").val() );
		$(".btn-print, #wrResult .content").fadeOut(200);
		$("#wrResult .screen-loading").fadeIn(200);
	},
	onComplete:function(){
		$('.input-text, .input-textarea').each(function() {
			var $this = $(this);
			$this.find(':input').watermark( $this.find('label').text().replace(/\*\s?/gi, '') + '...', {className:'watermark', useNative:false} );
		});
		
		$(".item:has(.navi) .products").scrollable({
			size:1,
			vertical:true,
			clickable:false,
			onSeek:function(){
			}
		}).navigator({navi:'.navi'});
		
		$(".optional-button").click(function(){
			$parent = $(this).closest(".line");
			if( $parent.is(".optional-disabled") ) {
				$parent.find(".item").fadeTo(200, 1);
			} else {
				$parent.find(".item").fadeTo(200, .3);
			}
			$parent.toggleClass("optional-disabled");
		});
		
		$(".btn-print, #wrResult .content").fadeIn(500);
		$("#wrResult .screen-loading").fadeOut(200);
			
	},
	onTransform:function(d) {
	}
});

$("#productType").each(function() {
	var $this = $(this);
	$this.change(function(e) {
		var $this = $(this);
		switch( $this.val() ) {
			case "mat" :
			$("#productSpacing").val("2.5").change().attr("disabled", "disabled");
			$("#qkProdType").html("TapeMat");
			break;
			case "cable" :
			$("#productSpacing").removeAttr("disabled");
			$("#qkProdType").html("WarmWire");
		}
	});	
}).change();

});
