function isIE() {
	return( navigator.appName == 'Microsoft Internet Explorer');
}
function showImage( id, lang) {
	window.open( '/'+lang+'/Image/'+id, 'image', 'toolbar=no, menubar=no, location=no, personalbar=no, scrollbars=no, directories=no, status=no, resizable=no, left=1,top=1, width=200,height=200');
}
function fitImage() {
	var o = document.getElementById( 'popupImage');
	window.resizeTo( o.width+20, o.height+20);
}
function searchSubmit( form) {
	var phrase = $('input:text', form).val();
	if (phrase == '') {
		return( false);
	}
	var locate = form.action + phrase.replace( '/', '%20');
	if ($('#cat', form).length == 1) {
		locate += '/cat-'+$('#cat', form).val();
	}
	window.location.href = locate;
	return( false);
}


function hideElement( id) {
	document.getElementById( id).style.display = 'none';
}

function formValidate( form) {
	var valid = true;
	
	$('.required', form).each( function() {
		$(this).removeClass( "invalid");
		$('label[for='+this.id+']').removeClass( "invalid");
		if (this.tagName == "SELECT" && this.value == 0) {
			$(this).addClass( "invalid");
			valid = false;
		} else if (this.tagName == "INPUT" && this.type == "password" && false == /^.{5,}$/.test( this.value)) {
			$(this).addClass( "invalid");
			valid = false;
		} else if (this.tagName == "INPUT" && this.type == "checkbox" && false == this.checked) {
			$('label[for='+this.id+']').addClass( "invalid");
			valid = false;
		} else if ($(this).attr( "class").indexOf( "email") >= 0 && false == /^[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z0-9._%-]{2,4}$/.test( this.value)) {
			$(this).addClass( "invalid");
			valid = false;
		} else if (this.value == "") {
			$(this).addClass( "invalid");
			valid = false;
		}
	});
	$(".date", form).each( function() {
		$(this).removeClass( "invalid");
		if (this.value != '' && false == /^\d{4}-\d{1,2}-\d{1,2}$/.test( this.value)) {
			$(this).addClass( "invalid");
			valid = false;
		}
	});
	$(".zip", form).each( function() {
		$(this).removeClass( "invalid");
		if (false == /^\d{2}-\d{3}$/.test( this.value)) {
			$(this).addClass( "invalid");
			valid = false;
		}
	});
	return( valid);
}
function checkOrderForm( f) {
	if ($('input:radio', f).length > 0 && $('input:radio:checked').length == 0) {
		return( false);
	}
	return( true);
}
function showFilter( caller) {
	$('#cat_header').slideDown( 'slow');
	$(caller).hide();
	$('#filterHide').show();
	document.cookie = 'filter=1';
}
function hideFilter( caller) {
	$('#cat_header').slideUp( 'slow');
	$(caller).hide();
	$('#filterShow').show();
	document.cookie = 'filter=0';
}
function galleryImgFix() {
	var stdH = 100;
	if (this.height < stdH) {
		return( true);
	}
	if ($(this).width() > $(this.parentNode.parentNode).width()) {
		this.removeAttribute( 'height');
		this.width = $(this.parentNode.parentNode).width();
		$(this).css( 'margin-bottom', (stdH-$(this).height())+'px');
	}
}
$(document).ready( function() {
	$('.prod_gallery_item img').each( galleryImgFix).load( galleryImgFix);
	$( 'a.linkOut').click( function() { window.open( this.href); return( false); });
});