/**
 * This document only contains scripts that could/should be applied to any site
 */

var $j = jQuery.noConflict();

$j(document).ready(function() {
	
	$j.fn.setInputFieldValueFromLabel = function(labelContent, inputFieldId){
		$j(inputFieldId).val(labelContent).css('color', '#aaa');
		
		$j(inputFieldId).blur(function(){
			if($j(inputFieldId).val() == ''){
				$j(inputFieldId).val(labelContent).css('color', '#aaa');
			}
		});
		
		$j(inputFieldId).focus(function(){
			if($j(inputFieldId).val() == labelContent){
				$j(inputFieldId).val('');
			}
		});
	}
	
	$j('#product-custom-message').focus(function(e){
		if (this.value == this.defaultValue)
			this.value = ''; 
	});
	$j('#product-custom-message').blur(function(e){
		if (this.value == '') 
			this.value = this.defaultValue;
	});

	$j('#product-custom-message').keyup(function(e){
		var str = this.value;
		str = str.replace(/[^[a-zA-Z0-9]*/g, '');
		this.value = str;
	});

	/**
	 * Fix to be able to use css attribute selector for <td headers="something"> in Intercrap Explorer 6
	 * 
	 * Example:
	 * Write like this in your main stylesheet: td[headers="something"]{some-attribute: some-value;}
	 * And then do a normal class in your ie6 stylesheet: td.something{some-attribute: some-value;}
	 */
	if($j.browser.msie && $j.browser.version.substr(0,3) == '6.0'){
		if(document.body.getElementsByTagName('td').length > 0){
			for(i = 0; i < document.body.getElementsByTagName('td').length; i++){
				var header = new String(document.body.getElementsByTagName('td')[i].getAttribute('headers'));
				if(header != ''){
					document.body.getElementsByTagName('td')[i].setAttribute('className', header);
				}
			}
		}
	}	
});