$(function() {

  $('tr.even, tr.odd, tr.clean').hover(function() {
	$(this).addClass('hover');
  }).mouseout(function() {
	 $(this).removeClass('hover');
  });


  //table zebras (auto)
  //$("table tr:even").addClass("even");
  //$("table tr:odd").addClass("odd");


  $('#price-check').focus(function() {
	  if($(this).val() == '__-___')
		{
			$(this).val('');
			$(this).addClass('active');
		}
  });
  
  $('#price-check').blur(function() {
	  if($(this).val() == '')
		{
			$(this).val('__-___');
			$(this).removeClass('active');
		}
  });
  
  $('div.box-version-1, div.box-version-2, div.box-version-4').click(function() {
        var boxIndex = right(this.className, 1);
        var newLocation = $(this).find("div.text > h3 > a").attr('href');
        window.location = newLocation;
        //alert('idziemy tu: ' + newLocation);
  });

$('input#price-submit').click(function() {
	var checkedZip = $('input#price-check').val();
	if( checkedZip != '' && checkedZip != '__-___' && !checkzip( checkedZip) ) {
		alert('Kod pocztowy nie jest prawidłowy.\nProszę wprowadzić kod w formacie xx-xxx');
		return false;
	}
	else {
		return true;
	}
});
        


function checkzip(str)
{
	var validZip= /^[\d]{2}(-| )[\d]{3}$/;
        var validZip2 = /^[\d]{5}$/;
        
	if (validZip.exec(str) == null && validZip2.exec(str) == null)
		return false
	return true;
}


function right(str, n)
{
    if (n <= 0) return "";
    else if (n > String(str).length) return str;
    else 
        {
           var iLen = String(str).length;
           return String(str).substring(iLen, iLen - n);
        }
}




//	adjustpageheight();
//
//	function adjustpageheight()
//	{
//		var contentHeight = $('div.content-panel-inner').height() + 40;
//		var contentShadowHeight = contentHeight + 4;
//		var columnHeight = contentHeight + 20;
//
//		//alert('contentHeight: ' + contentHeight + '\ncontentShadowHeight: ' + contentShadowHeight + '\ncolumnHeight: ' + columnHeight);
//
//		$('div.content-panel-inner').css('height', contentHeight + 'px');
//
//		$('div.content-panel-shadow').css('height', contentShadowHeight + 'px');
//		$('div.content-panel-shadow div.shadow-top').css('height', contentShadowHeight + 'px');
//		$('div.content-panel-shadow div.shadow-bottom').css('height', contentShadowHeight + 'px');
//
//		$('div.middle-content-subpage').css('height', columnHeight + 'px');
//		$('div.middle-content-subpage-inner').css('height', columnHeight + 'px');
//		$('div.middle-content-subpage-inner div.page-left-col').css('height', columnHeight + 'px');
//		$('div.middle-content-subpage-inner div.page-right-col').css('height', columnHeight + 'px');
//	}
});
