jQuery.noConflict();

/**
 *
 * Full ragistration users
 *
 * @name   userFullRegistration
 * @return void
 * @last 28.07.2009
 *
 **/

function text_counter(th, maxlimit) {
	var field = jQuery(th);
	if ( field.val().length > maxlimit ) {
		field.val(field.val().substring(0, maxlimit));
    return false;
  }
}

function strip_tags(str) {
 var result = str.replace(/<\/?[^>]+>/gi, "");

 result = result.replace(/&nbsp;/gi, "");
 return result;
}

function imposeMaxLength(e, Object, MaxLen){
  var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);
  // Ignore special keys
  if (e.ctrlKey || e.altKey || key < 32)
    return true;

  return (Object.value.length <= MaxLen);
}

function sortObjects(prefix,obj,chapter){
 var opts = {hoursToLive: 0,path: '/'};

 jQuery.cookies.set(chapter+'-'+prefix+'-filter', jQuery(obj).attr('value'), opts);

 if (prefix == 'country') {jQuery.cookies.set(chapter+'-regions-filter', '0', opts);jQuery.cookies.set(chapter+'-city-filter', '0', opts);}
 if (prefix == 'regions') {jQuery.cookies.set(chapter+'-city-filter', '0', opts);}
 jQuery(obj).parents("form").submit();
}


function onlyDigitsKey(e)
{
  // Make sure to use event.charCode if available
  var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);

  // Ignore special keys
  if (e.ctrlKey || e.altKey || key < 32)
    return true;

  key = String.fromCharCode(key);
  return /\d/.test(key);
}

function checkLastCommentPos(){

 var option = {};
 var header = jQuery('#guiFirstCommId').val();

 option['lastId'] = header;
 jQuery.ajax({
		  type     : "POST",
		  url      : "/comments/check-new-comment",
		  async    : true,
		  data     : option,
		  dataType : "json",
		  success  : function(data){
                      if (data.have_new > 0) {
                       firstId     = jQuery('#guiLastCommentId').val();

                       var newVal = jQuery('#guiHdnIdent'+firstId).parent('li').prev().find('.special').val();
           //            alert(newVal+' and '+firstId);

					   jQuery('#guiLiLastCommentItem'+firstId).animate({ opacity: "hide" }, 1500, function(){
                        jQuery('#guiFirstCommId').val(data.have_new);
                        jQuery('#guiLastCommentId').val(newVal);
                        jQuery(data.html).insertBefore('#guiLiLastCommentItem'+header);
                        jQuery('#guiLiLastCommentItem'+data.have_new).hide();
                        jQuery('#guiLiLastCommentItem'+data.have_new).animate({ opacity: "show" }, 1500);
					   });

                      }
                      lastId = data.have_new;
					},
		  error    : function (){}
	  });

 setTimeout(function(){checkLastCommentPos();},10000);
}

/**
 *
 * Check field
 *
 * @name   userFullRegistration
 * @return void
 * @last 19.06.2010
 * @params
 *         tp  - blur/focus
 *         obj - object
 *         str - string
 **/
function checkField(obj, str, tp) {
 if (tp == "blur") {
  if (jQuery(obj).val() == '') {jQuery(obj).val(str);jQuery(obj).css('color','#666666').removeClass('inputNonAbsolut_foto_load').addClass('inputPasive_foto_load');}
 }else{
        if (jQuery(obj).val()==str){ jQuery(obj).val('');jQuery(obj).css('color','#000000')
		                                                            .removeClass('inputPasive_foto_load').addClass('inputNonAbsolut_foto_load');
																	}
      }
}
///////////////////////////////////////////////////////////////////////////////

jQuery(function () {

 if (jQuery('#guiDivGuestCount').attr('id') == 'guiDivGuestCount') {
   jQuery.ajax({
		  type     : "POST",
		  url      : "/index/get-count-online-users",
		  async    : true,
		  dataType : "json",
		  success  : function(data){
                      if (data.unregister > 0 || data.notshowed > 0) {
                       jQuery('#guiDivGuestCount').html(data.string);
                       jQuery('#guiDivGuestCount').animate({ opacity: "show" }, 1500);
                      }
					},
		  error    : function (){}
	  });
 }

 if (jQuery('#guiBtnAddToPurse').attr('id') == 'guiBtnAddToPurse') {
  jQuery('#guiBtnAddToPurse').click(function(){
   jQuery(this).attr('value','загрузка ...');
   jQuery(this).attr('disabled',true);
   window.location.href = "/user/my-purse";
  });
 }


 jQuery('.photoListBox.doHover').hover(function(){
   jQuery(this).addClass("roundedBlock");
   jQuery(this).find('.transVertical').addClass("transVerticalGray");
   jQuery(this).find('.actionImg2').addClass("actionImg3");
   jQuery(this).find('.sled').addClass("actionImg3");

 }, function(){
   jQuery('.round').remove();
   jQuery(this).removeClass("roundedBlock");
   jQuery('.transVertical').removeClass("transVerticalGray");
   jQuery('.actionImg2').removeClass("actionImg3");
   jQuery('.sled').removeClass("actionImg3");
 });
 
 //
  jQuery('.tablph').hover(function(){
   jQuery(this).find('.sled').addClass("actionImg3");

 }, function(){

   jQuery('.sled').removeClass("actionImg3");
 });
 //
 //
  jQuery('.pravo').hover(function(){
   jQuery(this).find('.sled').addClass("actionImg3");

 }, function(){

   jQuery('.sled').removeClass("actionImg3");
 });
 //
 

  jQuery.each(jQuery('div.photoRatings'), function() {
      jQuery(this).find('img:first').css("margin-left","0px");
  });

});

jQuery(document).ready(function() {
  if (jQuery('#guiLastCommentId').attr('id') == 'guiLastCommentId') {
  setTimeout(function(){checkLastCommentPos();},10000);
 }
});

