/**
 * misc.js - contains miscelaneous JavaScript routines
 * @author claymore
 * @uses jQuery
 * @version 0.1
 */
 
 /**
  * For using together with prototype $()-style selector handling changed to jQuery()-style
  */
 
 jQuery(function(){
 	//Joomla-style form fields, behaviour:
 	//  Initially displayed default value, when we focus on it, becomes empty only if current value is default.
 	//  When field loses focus, if it is empty, default value is displayed
 	jQuery(".joomla-style").each(function(i){
 		$jqE = jQuery(this);
 		if(!$jqE.val()){
			var $defVal = $jqE.attr('def_value');
			$jqE.addClass('default');
			$jqE.val($defVal);
		}
		
 		$jqE.focus(function(){
 			$this=jQuery(this);
 			if($this.hasClass('default')){
 				$this.removeClass('default');
 				$this.val('');
 			}
 		});
 		
 		$jqE.blur(function(){
 			$this= jQuery(this);
 			if(!$this.val()){
 				$this.addClass('default');
 				$this.val($this.attr('def_value'));
 			}
 		});
 	});
 	jQuery("#feedbackForm").submit(function(){
 		var $haveUnfilled = false;
 		
 		jQuery(".required").each(function($i){
 			var $jqEl = jQuery(this);
 			if( !$jqEl.val() || $jqEl.hasClass('default') ){
	 			//found unfilled
	 			jQuery('#error-main').text('Заполните все необходимые поля');
				$jqEl.focus();
	 			$haveUnfilled = true;
	 			return false;
 			}
 		});
 		
 		return $haveUnfilled === false;//if have unfilled, prevent standard submit action
 	});
 });
 
 function getAnotherCaptcha(){
    jQuery.ajax({
      type: 'POST',
      url : '/requests.php',
      data: 'ac=regen_captcha',
      complete: function(msg){
        if(msg.responseText){
          jQuery('#captcha_image').attr('src', '/netcat/modules/captcha/img.php?code='+msg.responseText);
          jQuery('#nc_captcha_code').attr('captcha_hash', msg.responseText);
          jQuery('#nc_captcha_hash').val(msg.responseText);
        }
      }
    });
    return false;
  }
