jQuery.fn.vibrate = function(conf) {
        var config = jQuery.extend({
                speed: 20, 
                duration: 2000, 
                frequency: 10000, 
                spread: 3
        }, conf);

        return this.each(function() {
                var t = jQuery(this);

                var vibrate = function() {
                        var topPos = Math.floor(Math.random() * config.spread) - ((config.spread - 1) / 2);
                        var leftPos = Math.floor(Math.random() * config.spread) - ((config.spread - 1) / 2);
                        var rotate = Math.floor(Math.random() * config.spread - (config.spread - 1) / 2);
                        t.css({position: 'relative', left: leftPos +'px', top: topPos +'px', WebkitTransform: 'rotate(' +rotate +'deg)'});
                };

                var doVibration = function () {
                        
						var vibrationInterval = setInterval(vibrate, config.speed);

                        var stopVibration = function() {
                                clearInterval(vibrationInterval);
                                t.css({position: 'static'});
                        };

                        setTimeout(stopVibration, config.duration);
                };				
				doVibration();
        });
};

$(document).ready(function() {
   var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");

	var height = $(window).height();
	height = height-110;
	$('#wrapper').css('min-height', height);
	if (badBrowser) {
		$('#wrapper').css('height', height+40);
	}

   if (badBrowser) {
     // get all pngs on page
     $('img[src$=.png]').each(function() {
       if (!this.complete) {
         this.onload = function() { fixPng(this) };
       } else {
         fixPng(this);
       }
     });
   }  




	$(".tab1").keypress( function() {
		checkBG('.tab1');
	});
	$(".tab1").keyup( function() {
		checkBG('.tab1');
	});
	$(".tab1").keydown( function() {
		checkBG('.tab1');
	});
	
	$(".tab2").keypress( function() {
		checkBG('.tab2');
	});
	$(".tab2").keyup( function() {
		checkBG('.tab2');
	});
	$(".tab2").keydown( function() {
		checkBG('.tab2');
	});

function checkBG(inputu) {
  if( $(inputu).val().length != 0) {
	$(inputu).addClass('hoverimp');
  } else {
	$(inputu).removeClass('hoverimp');
  }
}

  $("input").focus( function() {
	  $(this).parent(".input").addClass('hover');
  });

  $("input").blur( function() {
	  $(this).parent(".input").removeClass('hover');
  });


// CHECK EMAIL //
function checkData() {
  var html = $.ajax({
	url: "check.php",
	data: "i=1&mail="+ $('#user').val() +"&pass="+$('#pass').val(),
	async: false
   }).responseText;
  
  return html;
}
function changePass() {
  var html = $.ajax({
	url: "check.php",
	data: "i=3&mail="+ $('#user').val() +"&pass="+$('#pass').val() +"&newpass="+$('#newpass').val() +"&newpassc="+$('#newpassc').val(),
	async: false
   }).responseText;
  
  return html;
}
function getServer() {	
  var html = $.ajax({
	url: "check.php",
	data: "i=2&mail="+ $('#user').val(),
	async: false
   }).responseText;
	$('#form').attr('action', html)
}
$("#form").submit(function(){
	$(".error").css('display', 'none');
	$(".loading").css('display', 'block');

	  var rasp = checkData();
	  if(rasp === 'valid') {
		  getServer();
		  return true;
	
	  } else {
		var conf = {
				frequency: 5000,
				spread: 6,
				duration: 500
			};	
		$("#vibrate").vibrate(conf);
		  
		$(".error").css('display', 'block');
		$(".loading").css('display', 'none');
		$('.tab1').val('')
		$('.tab2').val('')
		checkBG('.tab2');
		checkBG('.tab1');
	  }

return false;
});

$("#formC").submit(function(){
	$(".error").css('display', 'none');
	$(".loading").css('display', 'block');

	  var rasp = changePass();
	  if(rasp === 'valid') {
		  //alert('s-a schimbat');
		  window.location = "index.php?changedpass";
		  //return true;
	
	  } else {
		$(".error").css('display', 'block');
		$(".loading").css('display', 'none');
		  $('#pass').val('')
	  }

return false;
});

// CHECK EMAIL //

  $('.error').click(function() { $(".error").css('display', 'none'); });
  
});


var init = function() {
	document.getElementById("user").focus();
};
if( window.addEventListener ) {
    window.addEventListener('load',init,false);
} else if( document.addEventListener ) {
    document.addEventListener('load',init,false);
}

var blank = new Image();
 blank.src = 'http://s1.bodaishin.ro/images/pixel.gif';
 
 function fixPng(png) {
   // get src
   var src = png.src;
   // set width and height
   if (!png.style.width) { png.style.width = $(png).width(); }
   if (!png.style.height) { png.style.height = $(png).height(); }
   // replace by blank image
   png.onload = function() { };
   png.src = blank.src;
   // set filter (display original image)
   png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
 }
