$( 'document' ).ready(function(){
    $.fn.alignCenter = function() {
      var marginLeft = - $(this).width()/2 + 'px';
      var marginTop = - $(this).height()/2 + 'px';
      return $(this).css({'margin-left': marginLeft, 'margin-top': marginTop});
   };
   $.fn.togglePopup = function(){
      if ($('#popup').hasClass('hidden')) {
         if ($.browser.msie && $.browser.version == '6.0') {
            $('#opaco').height($(document).height()).toggleClass('hidden').click(function() { $(this).togglePopup(); } );
            $('#popup').css({'position': 'absolute', 'left': ($(document).width() / 2), 'top': ($(document).height() / 4)});
         }
         else {
            $('#opaco').height($(document).height()).toggleClass('hidden').fadeTo('slow', 0.7).click(function() { $(this).togglePopup(); } );
            $('#popup').css({'position': 'fixed', 'left': '50%', 'top': '50%'});
         }
         $('#popup').alignCenter().toggleClass('hidden');
      }
      else {
         $('#opaco').toggleClass('hidden').removeAttr('style').unbind('click');
         $('#popup').toggleClass('hidden');
      }
    };
})

function initVideo() {
   var fv = { backcolor: 'black', frontcolor: 'white', lightcolor: 'white', screencolor: 'black', repeat: 'single', autostart: true };
   fv['file'] = '/image/video2.flv';
   htmlOptions = { src: "/image/player.swf", width: '500', height: '400', flashvars: fv, replace: '<table class="noFlash"><tr><td align="center">Не установлен Adobe® Flash® Player<br /><a href="http://www.adobe.com/ru/products/flashplayer/" target="_blank">Установить</a></td></tr></table>' };
   $('#videoFlash').flash(htmlOptions, pluginOptions);
}

function checkEmail(obj){
    var str=obj.value;
    if(str=='') return true;
    if (/^([\w-~_]+\.)*[\w-~_]+@([\w-_]+\.){1,3}\w{2,4}$/.test(str))	return true;

alert("Неправильный e-mail адрес");
obj.focus();
return false;
}

function checkEmpty(obj){
    var str=obj.value;
    if (/\S/.test(str))	return true;

alert("Введите поисковую фразу");
obj.focus();
return false;
}


function zoom(name,format){
        var p=window.open('/zoom.php?n='+name,'preview_window',"width=10,height=10,top=0,left=0,location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,fullscreen=0");
        if(p)p.focus();
	return false;
}

function zoomGL(file){
        var p=window.open('/zoomGL.php?id='+file,'preview_window',"width=10,height=10,top=0,left=0,location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,fullscreen=0");
        if(p)p.focus();
	return false;
}

function zoomGLMP(file){
        var p=window.open('/zoomGLMP.php?id='+file,'preview_window',"width=10,height=10,top=0,left=0,location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,fullscreen=0");
        if(p)p.focus();
	return false;
}


function zoomCT(file){
        var p=window.open('/zoomCT.php?id='+file,'preview_window',"width=10,height=10,top=0,left=0,location=0,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,fullscreen=0");
        if(p)p.focus();
	return false;
}

function ch_sz(tobj,num){
        var obj=document.getElementById("IS_"+num);
        var st=tobj.value;
        obj.innerHTML=st.split('_')[1];
	return true;
}


function mm(url){
    var img=new Image;
    img.src=url;
    return img;
}

//var imgBkYes=mm('/i/note_yes.gif');
//var imgBkNo=mm('/i/note_no.gif');

function doBk(iid,section,price) {
   var obj,img;
   if(document.all) { obj= document.all['my_note_i'];}
   else {obj=document.getElementById('my_note_i');}
    if(!isInBk(iid)) {
        addToBk(iid+'_1');
         var noteBK=document.getElementById("noteBK");
         var count=parseInt(cookieVal("noteCount"))+1;
		 if(noteBK)
		 {
		  var ender='ов';
		  if(count<5) ender='a';
		  if(count==1) ender='';
		  noteBK.innerHTML=count+' товар'+ender;
		 }
         document.cookie ="noteCount="+count+"; path=/";
         img=imgBkYes;
    } else img=imgBkNo;
    if (img && img.complete) {
        obj.src=img.src;
        showBk(iid,section);
    }
return false;
}

function showBk(iid,section){
 var obj=document.getElementById("my_note");
 var obj1=document.getElementById("ti_"+iid+"_"+section);
 var ox,oy;
 for(ox=oy=0;obj1;obj1=obj1.offsetParent)ox+=obj1.offsetLeft, oy+=obj1.offsetTop;
 obj.style.top=oy-26; obj.style.left=ox;
 obj.style.display='block';
return false;
}

function dropBk(){
 var obj=document.getElementById("my_note");
 obj.style.display='none';
}

function cookieVal(cookieName) {
    thisCookie = document.cookie.split("; ")
        for (i = 0; i < thisCookie.length; i++) {
            if (cookieName == thisCookie[i].split("=")[0]) {
                return thisCookie[i].split("=")[1];
            }
        }
    return 0;
}


function isInBk(posNum){
    var p_cookie=document.cookie;
    var cookie;
    cookie=unescape(p_cookie.substr(p_cookie.indexOf('book=')+5,p_cookie.indexOf('-NSB')-p_cookie.indexOf('book=')-4));
    return cookie.indexOf('-'+posNum+'_')==-1?false:true;
}

function addToBk(code){
    var p_cookie=document.cookie;
    var cookie;
    cookie=unescape(p_cookie.substr(p_cookie.indexOf('book=')+5,p_cookie.indexOf('-NSB')-p_cookie.indexOf('book=')-5));
    p_cookie='book='+escape(cookie+'-'+code)+'-NSB; path=/';
    document.cookie=p_cookie;
}

var ldr=null;

function add(sel,v,n){
var newOpt=sel.appendChild(document.createElement('option'));
newOpt.text=n;
newOpt.value=v;
}

function chan(f,name,qw,parm)
{
 if(ldr&&ldr.readyState!=0) { ldr.abort() }
 ldr=selector();
 if(ldr)
 {
 	name.length = 0;
 	var now = new Date();
 	ldr.open("GET","/selector.plx?q="+parm+"&sel="+qw+"&t="+now.getSeconds(),true);
	ldr.onreadystatechange=function()
	{
	if(ldr.readyState==4 && ldr.responseText)
		{
			eval(ldr.responseText);
		}
	};
	ldr.send(null)
 }
}


function selector()
{
	var A=null;
	try{A=new ActiveXObject("Msxml2.XMLHTTP")}
	catch(e){try{A=new ActiveXObject("Microsoft.XMLHTTP")}
	catch(oc){A=null}}
	if(!A&&typeof XMLHttpRequest!="undefined") {A=new XMLHttpRequest()}
	return A
}

