$(document).ready(function() {

// mailin

  $('#mailin').hide();
  $('#mhide').hide();
  
  $('#mshow').click(function() {
    $('#mailin').show('slow');
  	$('#mhide').show('fast');
   	$('#mshow').hide('fast');
    return false;
  });

  $('#mhide').click(function() {
    $('#mailin').hide('slow');
    $('#mhide').hide('fast');
    $('#mshow').show('fast');
    return false;
  });
  
// zarovka
	
setInterval(function(){$('#zarovka').fadeToggle("fast", "linear")},1000);

// lightbox	
	
 	$('#gallery a').lightBox({fixedNavigation:true});
    $('#gallery2 a').lightBox({fixedNavigation:true});
    $('.prodImage a').lightBox({fixedNavigation:true});
    $('.teaser a').lightBox({fixedNavigation:true});
	
// slider

// 	$("#slider").easySlider({
// 		auto: true, 
// 		continuous: false,
// 		numeric: true,
// 		speed: 800,
// 		pause: 4000
// 	});

// validation inputs

  $('#nickname').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('loginmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=login_availability&login=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('loginmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('loginmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#email').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('emailmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=email_check&email=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('emailmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('emailmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });


// $('#phone').blur(function () {
//     var t = this; 
//     if (this.value != this.lastValue) {
//       if (this.timer) clearTimeout(this.timer);
// 		document.getElementById('phonemsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
//       
//       this.timer = setTimeout(function () {
//         $.ajax({
//           url: 'ajax/validation.php',
//           data: 'action=phone_check&phone=' + t.value,
//           dataType: 'json',
//           type: 'post',
//           success: function (j) {
// 			if (j.ok)
// 				document.getElementById('phonemsg').innerHTML = '<strong>'+j.msg+'</strong>';
// 			else
// 				document.getElementById('phonemsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
//           }
//         });
//       }, 200);
//       
//       this.lastValue = this.value;
//     }
//   });

$('#address').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('addressmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=address_check&address=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('addressmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('addressmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#zip').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('zipmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=zip_check&zip=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('zipmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('zipmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#city').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('citymsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=city_check&city=' + t.value + '&zip=' + $('#zip').val() + '&country=' + $('#country').val(),
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('citymsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('citymsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#vat').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('vatmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=vat_check&vat=' + t.value + '&domicil=' + $('#domicil').val(),
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('vatmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('vatmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#comreg').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('comregmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=comreg_check&comreg=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('comregmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('comregmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });


$('#password').blur(function() {
	var strenght = passwordStrength($('#password').val(),$('#nickname').val())
	
	if (strenght < 34 )  message = '<span style=\'color:red\'>'+strenght+'%</span>'
    else if (strenght < 68 )  message = '<span style=\'color:orange\'>'+strenght+'%</span>'
    else message = '<span style=\'color:green\'>'+strenght+'%</span>'
	
	$('#passmsg').html(message)
	})


$('#password2').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('pass2msg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/validation.php',
          data: 'action=password2_check&password=' + t.value + '&pass=' + $('#password').val(),
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('pass2msg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('pass2msg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#securecode').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('secmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/checkSecureCode.php',
          data: 'secure_code=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('secmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('secmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#securecodeinv').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('secinvmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/checkSecureCodeInvitation.php',
          data: 'secure_code=' + t.value + '&email=' + $('#email').val(),
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('secinvmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('secinvmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });

$('#secureimage').blur(function () {
    var t = this; 
    if (this.value != this.lastValue) {
      if (this.timer) clearTimeout(this.timer);
		document.getElementById('secimgmsg').innerHTML = '<img src="'+script_path+'images/ajax-loader.gif" height="16" width="16" />';
      
      this.timer = setTimeout(function () {
        $.ajax({
          url: 'ajax/checkSecureImage.php',
          data: 'secure_image=' + t.value,
          dataType: 'json',
          type: 'post',
          success: function (j) {
			if (j.ok)
				document.getElementById('secimgmsg').innerHTML = '<strong>'+j.msg+'</strong>';
			else
				document.getElementById('secimgmsg').innerHTML = '<strong class=error>'+j.msg+'</strong>';
          }
        });
      }, 200);
      
      this.lastValue = this.value;
    }
  });
	
	
});


// jqModal

var openFlag;
	
function onWindowShow(){openFlag = true;}	
	
function openLabelWindow(label_id)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/labelInfo.php?id=' + label_id + '&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function reportSpam(contribution_id)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/contributionSpam.php?id=' + contribution_id + '&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function editContribution(contribution_id)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/contributionEdit.php?id=' + contribution_id + '&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function replyContribution(contribution_id)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/contributionReply.php?id=' + contribution_id + '&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function openMailWindow(item_id)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/mailFriend.php?id=' + item_id + '&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function openResponsesWindow()
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/mailResponse.php?stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function openAuctionBid(position,bid)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/auctionBid.php?position=' + position + '&bid='+bid+'&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function auctionPreview(position)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/getAuctionPreview.php?position=' + position + '&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function openInviteFriendWindow()
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/getInviteFriend.php?stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function openTermsOfUseWindow()
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/getTermsOfUse.php?stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function openForceMobilePhonePPL()
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/forceMobilePhonePPL.php?stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function displayProductLightBox(promo)
	{
		if (openFlag) $('#actionday').jqmHide();
		$('#actionDay').html('');
			$('#actionDay').jqm({ajax:script_path+'ajax/getProductLightbox.php?promo=' + promo + '&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#actionDay').jqmShow();
			onWindowShow();
	};
	
function openFeedoClub()
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/feedoClub.php?stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function openFeedoClubNoPoints(item_id)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/feedoClubNoPoints.php?item_id='+item_id+'&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function openWatchDog(item_id)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/watchDog.php?item_id='+item_id+'&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function viewMlmMember(member_id)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/viewMlmMember.php?member_id='+member_id+'&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function displayVolumeDiscountWindow(item_id)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/displayVolumeDiscountWindow.php?item_id='+item_id+'&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function displayConfirmFrmInsert(item_id,item_count)
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/displayConfirmFrmInsert.php?item_id='+item_id+'&item_count='+item_count+'&stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function displayChildrenRegistrationMessage()
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/displayChildrenRegistrationMessage.php?stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function displayMLMregistrationMessage()
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/displayMLMregistrationMessage.php?stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function displayMLMLInvitation()
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/displayMLMLInvitation.php?stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function displayMLMLInfoPanel()
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/displayMLMLInfoPanel.php?stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function displayMLMLHistory()
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/displayMLMLHistory.php?stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
	
function displayFacebookLoginMessage()
	{
		if (openFlag) $('#infoWindow').jqmHide();
		$('#infoWindow').html('');
			$('#infoWindow').jqm({ajax:script_path+'ajax/displayFacebookLoginMessage.php?stamp='+ new Date().getTime(), modal:true, toTop:false });
			$('#infoWindow').jqmShow();
			onWindowShow();
	};
// password strength meter

// Password strength meter
// This jQuery plugin is written by firas kassem [2007.04.05]
// Firas Kassem  phiras.wordpress.com || phiras at gmail {dot} com
// for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/

var shortPass = 'Too short'
var badPass = 'Bad'
var goodPass = 'Good'
var strongPass = 'Strong'



function passwordStrength(password,username)
{
    score = 0 
    
    //password < 4
    if (password.length < 4 ) return 0
    
    //password == username
    if (password.toLowerCase()==username.toLowerCase()) return 0
    
    //password length
    score += password.length * 4
    score += ( checkRepetition(1,password).length - password.length ) * 1
    score += ( checkRepetition(2,password).length - password.length ) * 1
    score += ( checkRepetition(3,password).length - password.length ) * 1
    score += ( checkRepetition(4,password).length - password.length ) * 1

    //password has 3 numbers
    if (password.match(/(.*[0-9].*[0-9].*[0-9])/))  score += 5 
    
    //password has 2 sybols
    if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5 
    
    //password has Upper and Lower chars
    if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  score += 10 
    
    //password has number and chars
    if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  score += 15 
    //
    //password has number and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/))  score += 15 
    
    //password has char and symbol
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/))  score += 15 
    
    //password is just a nubers or chars
    if (password.match(/^\w+$/) || password.match(/^\d+$/) )  score -= 10 
    
    //verifing 0 < score < 100
    if ( score < 0 )  score = 0 
    if ( score > 100 )  score = 100 
    
    //if (score < 34 )  return badPass 
    //if (score < 68 )  return goodPass
    //return strongPass
    return score
}


// checkRepetition(1,'aaaaaaabcbc')   = 'abcbc'
// checkRepetition(2,'aaaaaaabcbc')   = 'aabc'
// checkRepetition(2,'aaaaaaabcdbcd') = 'aabcd'

function checkRepetition(pLen,str) {
    res = ""
    for ( i=0; i<str.length ; i++ ) {
        repeated=true
        for (j=0;j < pLen && (j+i+pLen) < str.length;j++)
            repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen))
        if (j<pLen) repeated=false
        if (repeated) {
            i+=pLen-1
            repeated=false
        }
        else {
            res+=str.charAt(i)
        }
    }
    return res
}


function testGA(e1, e2, e3, e4) {
	alert(e1+':'+e2+':'+e3+':'+e4)
	return true;
}

