var oSrv = {
	processing: function(o)
	{
		this.storeProcessing(o);
		o.fadeTo(800, 0.2);
	},
	storeProcessing: function(o)
	{
		if(o.data('loadInProcess')){
			alert('данные в процессе получения');
			throw 'loadInProcess';
		}
		o.data('loadInProcess',true)
	},
	errorDisplay: function(jO, url, data)
	{
		var oId = jO.attr('id');
		jO.html('<div class="loading-error">Ошибка загрузки. <a href="#">Попробовать ещё раз</a></div>');
		jQuery('a',jO).click(function(){oSrv.load(oId, url, data); return false});
	},
	getElement: function(oId)
	{
		var o = document.getElementById(oId);
		if(!o){alert('Элемент с ид = "' + oId + '" не найден'); throw 'elementNotFound';}
		return jQuery(o);
	},
	load: function(oId, url, data, callback)
	{
		try{
			var jTarget = this.getElement(oId);
			this.processing(jTarget);
			var options = {
				type: "GET",
				url: url ? url : './common.dhtml.php',
				data: data? data : {},
				success: function(d){jTarget.html(d); try{if(jQuery.isFunction(callback))callback(d);}catch(e){}},
				error: function(){ oSrv.errorDisplay(jTarget, url, data);},
				complete: function(){jTarget.data('loadInProcess', false); jTarget.fadeTo(200,1, function(){jTarget.attr('style', null)});}, // если не занулить стиль элемента, то в ИЕ8 теряются стили шрифтов.
				dataType: 'html'};
			return jQuery.ajax(options);
		}catch(e){}
	},
	loadOnce: function(oId, url, data)
	{
		try{
			var jTarget = this.getElement(oId);
			if(!jTarget.data('loadOnceComplete')){
				jTarget.data('loadOnceComplete', true);
				return this.load(oId, url, data);}
		}catch(e){}
	}
};

function saCorrectContentImageSize(o){
	var iContentWidth = 800; //jQuery('#content div.main-content').innerWidth();
    if(o.width > iContentWidth){
        o.width = iContentWidth - 100;
        jQuery(o).fancyzoom({autoresize:false, imgDir:'/img/fancyzoom/'});
    }
}
jQuery(function() {
    jQuery("#content div.main-content img").each(function(i){
        if(this.width){
            saCorrectContentImageSize(this);
        }else{
            this.onload = function(){saCorrectContentImageSize(this)};
        }
    });
	jQuery('a.fancyzoom').fancyzoom({autoresize:false, imgDir:'/img/fancyzoom/'});
});
	
function checkAndSubmitForm(form){
  for (var i=0;i<form.elements.length;i++){ 
    if (form.elements[i].getAttribute("require")=='1')
      if (form.elements[i].value==""){ 
        if (form.elements[i].name!="secret")
                 alert("Поле "+form.elements[i].name+" должно быть заполнено"); 
        else alert("Поле секретного кода должно быть заполнено"); 
        return false;
      }
     } 
  form.submit();
}

function openPopup(url,w,h){
  win=open(url,
    "popup","toolbar=no,location=no,directories=no,"+
    "status=no,scrollbars=no,resizable=no,"+
    "copyhistory=no,left="+(window.screen.width-w)/2+",top="+
    (window.screen.height-h)/2+",width="+w+",height="+h);
  win.focus();
}
function popImage(imageURL, ttl, width, height){
  if(!width) width=100;
  if(!height) height=100;
  if(!ttl) ttl="...";
        var opt='scrollbars=no,width='+width+',height='+height+',left='+(window.screen.width-width)/2+',top='+(window.screen.height-height)/2+',status=yes';
        imgWin = window.open('','',opt);
        with (imgWin.document) {
                writeln('<html><head><title>'+ttl+'</title><style type="text/javascript">body {overflow: auto; margin: auto; margin:0; padding: 0;}</style>');
                writeln('<sc'+'ript type="text/javascript">');
                writeln('function resizePopup() {');
                writeln('width = document.images[0].width + 10; ');
                writeln('height = document.images[0].height + 50; ');
                writeln('window.resizeTo(width,height); ');
                writeln('if (window.innerWidth) { window.innerWidth = width - 10; window.innerHeight = height - 30; }');
                writeln('}');
                writeln('</s' + 'cript>');
    writeln('</head><body bgcolor="#FFFFFF" onload="resizePopup();">')
                writeln('<img src="'+imageURL+'" alt="Закрыть" onclick="window.close();" border="0" style="position: absolute; left: 0px; top: 0px; cursor: pointer;"/></body></html>');
                close();
        }
}
function add2basket(requestUrl){
  var a = jQuery.ajax({
    url : requestUrl,
    type:'post',  
    success: function(msg){
      var response = msg;
      //alert(response);
      //$("debug").innerHTML=response;
      if(response>0){

        if (typeof(korzina_setCount) == "function") { 
          korzina_setCount(response);
          alert("Товар добавлен в корзину!");
        }
      }else{  
        if (typeof(korzina_setCount) == "function") { 
          //alert("Ошибка добавления товара в корзину!");
          korzina_setCount(response);
        }
      }
    },
    error: function(){
      alert('Ошибка доступа!');
    }
  });
}

function PingSession(){
  var a = jQuery.get("/null.php");
}

function smartInput(id)
{
	var el = jQuery('#' + id);
	if (!el[0])
		return;

	el.focus(function()
	{
		if (this.defaultValue == this.value)
			this.value = '';
	});
	el.blur(function()
	{
		if (this.value == '')
			this.value = this.defaultValue;
	});
}

//setInterval("PingSession()", 300000);







