
$(document).ready(function() {
	if(jQuery.browser.msie && (jQuery.browser.version == 6 || jQuery.browser.version == 7)){
		$('input[type="text"], input[type="password"], textarea').css('width', '250px');
	}
	
	
	// abuse modal form 
$("#report_abuse_form_call").colorbox({width:"806", height:"580"});

	
  /* registration forms */
  
    // highlighting rows 
    $('.form tr').click(function(){
      // cleaning rest
      $('tr.active').removeClass('active');
      $('.form_help_hint').hide();
      $(this).addClass("active");
    });
        
    // form help icon
    $('.form_help').click(function(){
      // cleaning previously selected tr (
      $('tr.active').removeClass('active');
      // applying new stuff
      $(this).parent().parent().addClass('active');
      // hiding
      if ($(this).parent().children('div.form_help_hint').is(":visible")) {
        if($('.form_validator_hint').is(":visible")) {
          $('.error_hint').slideToggle('fast');
        }
        $(this).parent().children('div.form_help_hint').slideToggle('fast');
      } else { // showing
        $('.form_help_hint').hide();
        if($('.form_validator_hint').is(":visible")) {
          $('.error_hint').remove();
        }
        $(this).parent().children('div.form_help_hint').slideToggle('fast');
      }
      return false; // clickable image on the same layer 
    });

    
  /*
  $('input[type="text"]').addClass("idleField");
	$('input[type="text"]').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		$(this).parent().parent().css("background", "#e5e5e5");
    });
  $('input[type="text"]').blur(function() {
  	$(this).removeClass("focusField").addClass("idleField");
		$(this).parent().parent().css("background", "none");
  });
  */  

});


/* helpers */
function isInteger(s) { 
  var i;
  for (i = 0; i < s.length; i++) {
    // Check that current character is number.
    var c = s.charAt(i);
    if (((c < "0") || (c > "9"))) return false;
  }
  // All characters are numbers.
  return true;
}

function stripCharsInBag(s, bag) { 
  var i;
  var returnString = "";
  // Search through string's characters one by one.
  // If character is not in bag, append to returnString.
  for (i = 0; i < s.length; i++)  {
    // Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
  }
  return returnString;
}



/*
 * TextLimit - jQuery plugin for counting and limiting characters for input and textarea fields
 * 
 * pass '-1' as speed if you don't want slow char deletion effect. (don't just put 0)
 * Example: jQuery("Textarea").textlimit('span.counter',256)
 *
 * $Version: 2007.10.24 +r1
 * Copyright (c) 2007 Yair Even-Or
 * vsync.design@gmail.com
 */
jQuery.fn.textlimit=function(counter_el, thelimit, speed) {
	var charDelSpeed = speed || 15;
	var toggleCharDel = speed != -1;
	var toggleTrim = true;
	
	var that = this[0];
	updateCounter();
	
	function updateCounter(){
		//jQuery(counter_el).text(thelimit - that.value.length);
		jQuery(counter_el).text(that.value.length);
	};
	
	this.keypress (function(e){ if( this.value.length >= thelimit && e.charCode != '0' ) e.preventDefault() })
	.keyup (function(e){
		updateCounter();
		if( this.value.length >= thelimit && toggleTrim ){
			if(toggleCharDel){
				// first, trim the text a bit so the char trimming won't take forever
				that.value = that.value.substr(0,thelimit+100);
				var init = setInterval
					( 
						function(){ 
							if( that.value.length <= thelimit){ init = clearInterval(init); updateCounter() }
							else{ that.value = that.value.substring(0,that.value.length-1); jQuery(counter_el).text('przycinam ...  '+(thelimit - that.value.length)); };
						} ,charDelSpeed 
					);
			}
			else this.value = that.value.substr(0,thelimit);
		}
	});
	
};
