$(document).ready(function(){$(".only_numbers").constrainInput({allowedCharsRegex:"\\d+|\\|,"});$("body").fixPng(); /*$('img[@src$=.png]').ifixpng();*/$("div#price_all").toggle(function(){$("span#price").show();$("div#price_all").html("Скрыть&nbsp;&nbsp;&nbsp;&nbsp;");},function(){$("span#price").hide();$("div#price_all").html("Все цены&nbsp;&nbsp;&nbsp;&nbsp;");});$("div#age_all").toggle(function(){$("span#age").show();$("div#age_all").html("Скрыть&nbsp;&nbsp;&nbsp;&nbsp;");},function(){$("span#age").hide();$("div#age_all").html("Все возраста&nbsp;&nbsp;&nbsp;&nbsp;");});$("div#brands_all").toggle(function(){$("span#brands").show();$("div#brands_all").html("Скрыть&nbsp;&nbsp;&nbsp;&nbsp;");},function(){$("span#brands").hide();$("div#brands_all").html("Все бренды&nbsp;&nbsp;&nbsp;&nbsp;");});$("table.main").hover(function(){$(this).addClass("tr_high");},function(){$(this).removeClass("tr_high");});});$(function(){var tabContainers=$('div.tabs > div');tabContainers.hide().filter(':first').show();$('div.tabs ul.tabNavigation a').click(function(){tabContainers.hide();tabContainers.filter(this.hash).show();$('div.tabs ul.tabNavigation a').removeClass('selected');$(this).addClass('selected');return false;}).filter(':first').click();});function addbasket(textid)
{$.ajax({url:'basket.php',data:'textid='+textid+'&add=add',type:'post',cache:false,dataType:'html',beforeSend:function(data){$('#bask_loading_'+textid).show();$('#bask'+textid).hide();},complete:function(data){$('#result').html(data.responseText);$('#bask_loading_'+textid).hide();$('#bask'+textid).show();$('#bask_added_'+textid).stop(true, true).hide().fadeIn(1000).fadeOut(2000);},error:function(){alert("Ошибка.\nПовторите запрос заново.");}});}
function delbasket(textid)
{var numbers_of_rows=$('#numbers_of_rows').val();$.ajax({url:'basket.php',data:'textid='+textid+'&del=del',type:'post',cache:false,dataType:'html',complete:function(data){$('#result').html(data.responseText);$('#'+textid).remove();finaly_summ();}});numbers_of_rows=numbers_of_rows-1;$('#numbers_of_rows').val(numbers_of_rows);if(numbers_of_rows==0){$.ajax({url:'basket.php',data:'&basket_state=true',type:'post',cache:false,dataType:'html',complete:function(data){$('#all_basket_table').html(data.responseText);tooltip.hide();}});}}
function renewbasket(textid)
{var quantity=$('#quantity_'+textid).val();if(isNaN(quantity)){quantity=1;$("#quantity_"+textid).val(quantity)}else{if(quantity<1||quantity>999){quantity=1;$("#quantity"+textid).val(quantity)}}
$.ajax({url:'basket.php',data:'textid='+textid+'&renew=renew&quantity='+quantity,type:'post',cache:false,dataType:'html',beforeSend:function(data){$('#img_item'+textid).html("<img src='images/loading1.gif' border='0'>");$('#quantity_'+textid).css({display:'none'});},complete:function(data){$('#result').html(data.responseText);$('#img_item'+textid).html("");$('#quantity_'+textid).css({display:'block'});finaly_summ();},error:function(){alert("Ошибка.\nПовторите запрос заново.");}});var price=$('#price'+textid).html();$('#summ'+textid).html(price*quantity);}
function finaly_summ(){var finaly_summ=0;$('.summ').each(function(el){finaly_summ=finaly_summ+Number($(this).text());});$('#finaly_summ').html(finaly_summ);var type=$('.delivery_type:radio:checked').val();if(type!=undefined){renew_itogo(type);}}
function rate_it(textid){var value=$('[name=RadioGroup]:checked').val();if(value==undefined){alert('Не выбрана оценка.');return false;}
$.ajax({url:'/rating.php',data:'textid='+textid+'&action=rate_it&value='+value,type:'post',cache:false,dataType:'html',beforeSend:function(data){$('#rating').html("<img src='images/loading2.gif' width='30' heigth='30'>");},complete:function(data){$('#rating').html(data.responseText);},error:function(){alert("Ошибка.\nПовторите запрос заново.");}});}
(function($)
{$.fn.constrainInput=function(config)
{var settings=$.extend({allowedCharsRegex:".*"},config);var re=new RegExp(settings.allowedCharsRegex);$.each(this,function()
{var input=$(this);var keypressEvent=function(e)
{e=e||window.event;var k=e.charCode||e.keyCode||e.which;if(e.ctrlKey||e.altKey||k==8||k==9||k==37||k==39)
{return true;}
else if((k>=41&&k<=122)||k==32||k==110||k>186)
{return(re.test(String.fromCharCode(k)));}
return false;}
input.bind("keypress",keypressEvent);});return this;};})(jQuery);jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};(function($){$.fn.maxChar=function(limit,options){settings=jQuery.extend({debug:false,indicator:'indicator',label:'',pluralMessage:' осталось ',rate:200,singularMessage:' осталось ',postMessageText:' символов',spaceBeforeMessage:' '},options);var target=$(this);var debug=settings.debug;var indicatorId=settings.indicator;var label=settings.label;var pluralMessage=settings.pluralMessage;var rate=settings.rate;var singularMessage=settings.singularMessage;var spaceBeforeMessage=settings.spaceBeforeMessage;var postMessageText=settings.postMessageText;var currentMessage='';var indicator=getIndicator(indicatorId);var limit=limit;var remaining=limit;var timer=null;if(label){indicator.text(label);}else{update(limit);}
$(this).focus(function(){if(timer==null){if(label){indicator.fadeOut(function(){indicator.text('')}).fadeIn(function(){start()});}else{start();}}});$(this).blur(function(){stop();if(label){indicator.fadeOut(function(){indicator.text(label)}).fadeIn();}});function getIndicator(id){var indicator=$('#'+id);if(indicator.length==0){target.after(spaceBeforeMessage+'<span id="'+id+'"></span>');indicator=$('#'+id)}
return indicator;}
function log(message){if(debug){try{if(console){console.log(message);}}catch(e){}}}
function start(){timer=setInterval(function(){update(limit)},rate);}
function stop(){if(timer!=null){clearInterval(timer);timer=null;}}
function update(limit){var remaining=limit-target.val().length;if(remaining<1){target.val(target.val().slice(0,limit));remaining=0;}
if(remaining==1){currentMessage=singularMessage+remaining+postMessageText;}else{currentMessage=pluralMessage+remaining+postMessageText;}
indicator.text(currentMessage);log(currentMessage);}};})(jQuery);
(function($){
	$.fn.extend(
	{
		fixPng: function( gif_file, attr, noreplace )
		{
			if( navigator.appVersion.match('MSIE 6') )
			{
				if( typeof gif_file == "undefined" )
				{
					gif_file = "/images/pixel.gif";
				}
				
				if( typeof noreplace == "undefined" )
				{
					noreplace = "noreplace";
				}
				
				if( typeof attr == "undefined" )
				{
					attr = "rel";
				}
				
				$("img").each(function()
				{
					var src = $(this).attr("src");
					var width = $(this).attr("width");
					var height = $(this).attr("height");
					var atributo = $(this).attr(attr);
					
					if( typeof atributo == "undefined" )
					{
						atributo = "rel";
					}
					
					if (src.indexOf(".png") != -1 && atributo.indexOf(noreplace) == -1 )
					{
						$(this).attr("src", gif_file);
						$(this).attr("width", width);
						$(this).attr("height", height);
						$(this).css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ src + "',sizingMethod='scale')");
					}
				});
			}
		}
	});
})(jQuery);
//------------------TOOLTIP--------------------------------------------------------------------------------
var qTipTag = "a,img"; //Which tag do you want to qTip-ize? Keep it lowercase!//
var qTipX = 0; //This is qTip's X offset//
var qTipY = 15; //This is qTip's Y offset//

//There's No need to edit anything below this line//
tooltip = {
  name : "qTip",
  offsetX : qTipX,
  offsetY : qTipY,
  tip : null
}

tooltip.init = function () {
	var tipNameSpaceURI = "http://www.w3.org/1999/xhtml";
	if(!tipContainerID){ var tipContainerID = "qTip";}
	var tipContainer = document.getElementById(tipContainerID);

	if(!tipContainer) {
	  tipContainer = document.createElementNS ? document.createElementNS(tipNameSpaceURI, "div") : document.createElement("div");
		tipContainer.setAttribute("id", tipContainerID);
	  document.getElementsByTagName("body").item(0).appendChild(tipContainer);
	}

	if (!document.getElementById) return;
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

	var a, sTitle, elements;

	var elementList = qTipTag.split(",");
	for(var j = 0; j < elementList.length; j++)
	{
		elements = document.getElementsByTagName(elementList[j]);
		if(elements)
		{
			for (var i = 0; i < elements.length; i ++)
			{
				a = elements[i];
				sTitle = a.getAttribute("title");
				if(sTitle)
				{
					a.setAttribute("tiptitle", sTitle);
					a.removeAttribute("title");
					a.removeAttribute("alt");
					a.onmouseover = function() {tooltip.show(this.getAttribute('tiptitle'))};
					a.onmouseout = function() {tooltip.hide()};
				}
			}
		}
	}
}

tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {//IE
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;

	} else {//Good Browsers
		x = evt.pageX;
		y = evt.pageY;
	}
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
}

tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	this.tip.style.display = "block";
}

tooltip.hide = function () {
	if (!this.tip) return;
	this.tip.innerHTML = "";
	this.tip.style.display = "none";
}

//window.onload = function () {
$(document).ready(function(){
	tooltip.init ();
});
