function jump(str) {
        this.location = str;
        return false;
}

		  	function  b_zap() {
 
		  		$j('#z_zapros').attr('value', '1');
		  	}

// определяем браузер
var agent = navigator.userAgent.toLowerCase();
var ie6 = (agent.indexOf("msie 6.")!=-1);
var ie7 = (agent.indexOf("msie 7.")!=-1);
var ie = (agent.indexOf('msie')!=-1);
var ienot7 = (ie && !ie7);
var ff = !ie && (agent.indexOf('mozilla') != -1);
var opera = !!window.opera;


function vAjax() {
        var aj = null;

        try {
                aj = new XMLHttpRequest();
        }
        catch (e) {}

        if (!aj) try {
                aj = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (e) {}

        if (!aj) try {
                aj = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (e) {}

        return aj;
}

function DatsOpera(el) {
        if (!!window.opera && document.getElementById(el)) {
                document.getElementById(el).innerHTML = 'shift+ctrl';
        }
}

function KbdNavigate(e)
{
        if (!e) e = window.event;

        if (e.ctrlKey) {
                var link = null;
                switch (e.keyCode ? e.keyCode : e.which ? e.which : null)        {
                        case 0x25:
                                link = document.getElementById('headlink_prev');
                                break;
                        case 0x27:
                                link = document.getElementById('headlink_next');
                                break;
                }
                if (link && link.href) document.location = link.href;
        }
}
document.onkeydown = KbdNavigate;

function OpenPic(node, width, height) {
        ur = node.href;
        str = '';
        title = node.title;
        if (!title)
                title = node.firstChild.title;

        navi = navigator.userAgent.toLowerCase();
        if (navi.indexOf("msie 6.") != -1) {
                resWidth = 48;resHeight = 117;brow = 'ie6';initwidthadd = 36;initheightadd = 66;
        } else if (navi.indexOf("msie 7.") != -1) {
                resWidth = 48;resHeight = 140;brow = 'ie7';initwidthadd = 36;initheightadd = 67;
        } else if (navi.indexOf("safari") != -1) {
                resWidth = 24;resHeight = 94;brow = 'safari';initwidthadd = 20;initheightadd = 66;
        } else {
                resWidth = 40;resHeight = 115;initwidthadd = 32;initheightadd = 66;brow = '';
        }
        if (height > screen.availHeight) {
                resHeight = 0;
                height = screen.availHeight-66;
                if (brow == 'safari') height -= 50;
        }

        if (width) {
                str += ',width=' + (width + initwidthadd);
                str += ',left=' + parseInt((screen.availWidth - (width + initwidthadd)) / 2)
        }
        if (height) {
                str += ',height=' + (height + initheightadd);
                str += ',top=' + parseInt((screen.availHeight - (height + initheightadd)) / 2)
        }

        opts = 'resizable=yes,location=no,menubar=no,titlebar=no,scrollbars=yes,status=no,toolbar=no,fullscreen=no,dependent=yes'+str;
        var q = '/openpic.php?i=' + encodeURI(ur) + '&t=' + encodeURI(title) + '&b=' + brow;

        var a = window.open(q,'imagDetail',opts);return false;

        var a = window.open('about:blank','imagDetail',opts);
        var html = "<html><head><link type='text/css' rel='stylesheet' href='/css/main.css' /><\/head>";
        html += "<body style='margin:0px; text-align: center; vertical-align: middle'><div style='padding: 10px'>";
        html += "<img onclick='window.close()' ";
        html += "onload=\"window.resizeTo(Math.min(screen.availWidth+"+resWidth+",this.width+"+resWidth+"),Math.min(screen.availHeight+"+resHeight+",this.height+"+resHeight+"))\" ";
        html += "style='cursor:pointer; padding-bottom:10px' src='"+ur+"' alt='Закрыть' title='Закрыть' \/>";
        html += "<div>"+title+"<\/div>";
        html += "<\/div><\/body><\/html>";
        a.document.write(html);
        a.document.close();

        return false;
}

function $(id) {
        if (!this.cache) this.cache = new Array();
        if (this.cache[id]) return this.cache[id];
        return (this.cache[id] = document.getElementById(id));
}

function ChangeSizes(node) {
        colors = item_sizes[node.value];
        if (colors.length == 1) {
                $('colors_select').innerHTML = '<span id="' + colors[0].id + '">' + colors[0].name + '</span><input type="hidden" name="color" value="' + colors[0].id + '" />';
        } else {
                last = -1;
                if ($('colors_select').firstChild.value) {
                        last = $('colors_select').firstChild.value;
                } else {
                        m = $('colors_select').firstChild.id.match(/(\d+)/);
                        if (m)
                                last = m[1];
                }

                txt = '<select name="color">';
                for (i = 0, len = colors.length; i < len; i++) {
                        sel = colors[i].id == last ? ' selected="selected"' : "";
                        txt += '<option value="' + colors[i].id + '"' + sel + '>' + colors[i].name + '</option>';
                }
                txt += '</select>';
                $('colors_select').innerHTML = txt;
        }
}

function HideOrders() {
        cont = $('orders').getElementsByTagName('h3');
        for (i = 0, len = cont.length; i < len; i++) {
                cur = cont[i];
                cur.firstChild.className = 'dashed';
                cur.nextSibling.style.display = 'none';
                cur.firstChild.onclick = HideOrders_func;
        }
}
function HideOrders_func() {
        if (this.className) {
                this.className = '';
                this.parentNode.nextSibling.style.display = '';
        } else {
                this.className = 'dashed';
                this.parentNode.nextSibling.style.display = 'none';
        }
}



function get_click2(img,idimg)
{

$j.get("/imgover.php", { img: img},
  function(data){
    $j("#fullimgf").animate({opacity:"0"},500,function(){
    $j("#fullimgf").html(data)
    $j(".addimg img").css({border:"3px solid black"});
    $j("#img"+idimg).css({border:"3px solid #f7c824"});
    $j("#fullimgf").animate({opacity:"1"},500)
 });

    });

}

function vizible_search_d()
{
$j("#d_search").show();
$j("#d_r_search").hide();
$j("#dop_param").val("act");
}

function hide_search_d()
{
$j("#d_search").hide();
$j("#d_r_search").show();
$j("#dop_param").val("");
}

$j(document).ready(function(){

$j('.catalogue-text a').tooltip({
    track: false,
    delay: 100,
  showURL: false,
    showBody: '',
    opacity: '0.9'
  });
$j('#middle a').tooltip({
    track: false,
    delay: 100,
  showURL: false,
    showBody: '',
    opacity: '0.9'
  });

$j(".hint").tooltip({
  bodyHandler: function() {
        var hint = $j(this).attr("id").substring(5);
    return $j("#hnt_"+hint).html();
  },
  track: false,
    delay: 100,
  showURL: false,
    showBody: '',
    opacity: '0.9'
});


$j(".bglight").tooltip({
  bodyHandler: function() {
        var hint_t = $j(this).attr("id").substring(10);
    return $j("#txtpodsk_"+hint_t).html();
  },
  track: false,
    delay: 100,
  showURL: false,
    showBody: '',
    opacity: '0.9'
});


$j("#bgl").tooltip({
  bodyHandler: function() {
        var hint_t = $j(this).attr("id").substring(10);
    	return $j("#dddsasd").html();
  },
  track: false,
    delay: 100,
  showURL: false,
    showBody: '',
    opacity: '0.9'
});

$j(".bglight_t").tooltip({
  bodyHandler: function() {
        var hint_t = $j(this).attr("id").substring(10);
    return $j("#txtpodsk_"+hint_t).html();
  },
  track: false,
    delay: 100,
  showURL: false,
    showBody: '',
    opacity: '0.9'
});


$j(".discountitem").tooltip({
  bodyHandler: function() {
        
    return $j("#discnt_hidd").html();
  },
  track: false,
    delay: 100,
  showURL: false,
    showBody: '',
    opacity: '0.9'
});

$j(".discountitem_v").tooltip({
  bodyHandler: function() {
        
    return $j("#discnt_hidd").html();
  },
  track: false,
    delay: 100,
  showURL: false,
    showBody: '',
    opacity: '0.9'
});

$j("#type_d1").tooltip({
  bodyHandler: function() {
        
    return $j("#type_d1_tooltip").html();
  },
  track: false,
    delay: 100,
  showURL: false,
    showBody: '',
    opacity: '0.9'
});

$j("#type_d2").tooltip({
  bodyHandler: function() {
        
    return $j("#type_d2_tooltip").html();
  },
  track: false,
    delay: 100,
  showURL: false,
    showBody: '',
    opacity: '0.9'
});


$j("#show_form").click(function () {
	$j("div.bzakaz").hide();
	$j("div.ff").show("slow");
});

$j("#show_form").click(function () {
	$j("div.bzakaz").hide();
	$j("div.ff").show("slow");
});

$j("#checkout_no_reg").click(function () {

	if ($j("#f_email").val() == '' || $j("#f_email").val().length < 6) {
		alert('Поле "E-mail" обязательно для заполнения!');
		return false;
	}
	if ($j("#f_name").val() == '' || $j("#f_name").val().length < 2) {
		alert('Поле "Имя" обязательно для заполнения!');
		return false;
	}
	
	if ($j("#f_phone").val() == '' || $j("#f_phone").val().length < 2) {
		alert('Поле "Мобильный телефон" обязательно для заполнения!');
		return false;

	}
	
	if ($j("#f_address").val() == '' || $j("#f_address").val().length < 10) {
		alert('Поле "Адрес доставки" обязательно для заполнения!');
		return false;
	}
	return true;
});





jQuery.fn.check = function(mode) {
   // если mode не определен, используем 'on' по умолчанию
   var mode = mode || 'on';
   
   // В функцию неявно передана коллекция выбранных элементов.
   // Поэтому с этой коллекцией можно работать, как с любой другой
   // коллекцией элементов в jQuery
   // В нашем случае мы воспользуемся методом each()
   return this.each(function() 
   {
     switch(mode) {
       case 'on':
         this.checked = true;
         break;
       case 'off':
         this.checked = false;
         break;
       case 'toggle':
         this.checked = !this.checked;
         break;
     }
   });
 };

});

function vis_all(idr)
{

if (document.getElementById("visall"+idr).checked == true)
         {

            $j("#pd"+idr+" .all").check('on');
         }
        else
         {
           $j("#pd"+idr+" .all").check('off');
         }



}

function hid_all(idr)
{

$j("#sph"+idr).hide();
$j("#spv"+idr).show();
}

function ch_f()
{
	$j("#result").html("");
	var reg = $j("#reg").val();
	if(reg == 0){ // город не выбран
		$j("#type_d").css({ display:"none" })
	} else if (reg == 1) { // Москва
		$j("#result").html("<span style='font-size:16px;font-weight:bold'>250 руб</span>");
		$j("#type_d").css({ display:"none" })
	} else if(reg == 2) {
		$j("#result").html("Стоимость доставки<br /> обговаривается с оператором по <br />тел.: +7 (495) 661-87-91");
		$j("#type_d").css({ display:"none" })
	} else {
		$j("#type_d").css({ display:"block" })
	}
}

function submr() {
	if (document.getElementById("type_d1").checked == true) {
		var type_d = 1;
	} else {
		var type_d = 2;
	}
	var reg = $j("#regi").val();
	var item = $j("#item_id").val();
	$j.get("/dostavka.php",
	       {ajax:true, region: reg, id: item, type: type_d},
	       function(data) {

		$j("#dost_price").html(data);
		/*
		if(reg == 82) {
			$j('#result').html("<span style='font-size:16px;font-weight:bold'>250,00 руб</span>");
		} else if(data == "Стоимость доставки обговаривается с оператором по тел.: +7 (495) 661-87-91" && reg != 2)
		{
			$j.get("dostavka.php?ajax=true", { region: reg, id: item, type: '2'}, function(kurier) {
				$j("#result").html('Доставка в Ваш город только курьером: ' + kurier);
			});
		} else
		{
			$j("#result").html(data);
		}
		setNewPrice($j("#result span").html());*/
	});
}

function pr_dost(iditem)
{
    $j("#pr_dost").html('Введите город:<br /><input type="text" name="regionin" id="regisuggest" onchange="ch_f();" />');
    $j("#pr_dost").append('<div id="type_d" style="margin-bottom:5px"><input id="type_d1" type="radio" name="type" value="1" checked="checked" onchange="submr();" /><label for="type_d1"> Транспортная</label><br /><input  type="radio" name="type" value="2" id="type_d2" onchange="submr();" /><label for="type_d2"> Курьерская</label></div>');
    $j("#pr_dost").append('<input type="hidden" name="region" id="regi" value="0" onchange="ch_f(); submr();" />');
	
    $j.getScript("/get_region_list.php?id=" + iditem, function() {
        $j("#regisuggest").autocomplete(listregions, {
		    formatItem: function(row, i, max) {
			    return row.name;
		    },
		    formatMatch: function(row, i, max) {
			    return row.name;
		    },
		    formatResult: function(row) {
			    return row.name;
		    }
        }).result(function(event, data, formatted) {
            $j.each(listregions, function(key, value) { 
                if (listregions[key].name == formatted) {
		    region = listregions[key].id;
		    if (document.getElementById("type_d1").checked == true) {
				var type_d = 1;
			} else {
				var type_d = 2;
			}
                    $j("#regi").val(region);
		    submr();
		    /*$j.get("dostavka.php",
			   {id: iditem, ajax: true, region: region, type: type_d},
			   function(data) {
			       $j("#dost_price").html(data)
			   });*/
                }
            });
        });
	});
}

function InputPlaceholder (input, value, cssFilled, cssEmpty) {
        var thisCopy = this
        
        this.Input = input
        this.Value = value
        this.SaveOriginal = (input.value == value)
        this.CssFilled = cssFilled
        this.CssEmpty = cssEmpty

        this.setupEvent (this.Input, 'focus', function() {return thisCopy.onFocus()})
        this.setupEvent (this.Input, 'blur',  function() {return thisCopy.onBlur()})
        this.setupEvent (this.Input, 'keydown', function() {return thisCopy.onKeyDown()})

        if (input.value == '') this.onBlur();

        return this
}

InputPlaceholder.prototype.setupEvent = function (elem, eventType, handler)
{
        if (elem.attachEvent)
        {
                elem.attachEvent ('on' + eventType, handler)
        }

        if (elem.addEventListener)
        {
                elem.addEventListener (eventType, handler, false)
        }
}

InputPlaceholder.prototype.onFocus = function()
{
        if (!this.SaveOriginal &&  this.Input.value == this.Value)
        {
                this.Input.value = ''
        }
        else
        {
                        this.Input.className = ''
        }
}

InputPlaceholder.prototype.onKeyDown = function()
{
        this.Input.className = ''
}

InputPlaceholder.prototype.onBlur = function()
{
        if (this.Input.value == '' || this.Input.value == this.Value)
        {
                this.Input.value = this.Value
                this.Input.className = this.CssEmpty
        }
        else
        {
                this.Input.className = this.CssFilled
        }
}


function toggle(idName)
{
               var theMenu = document.getElementById(idName);
               if (theMenu.style.display == 'block') {
                   theMenu.style.display = 'none';
               } else {
                   theMenu.style.display = 'block';
               }
}


jQuery(function($){
   $.mask.addPlaceholder('~',"[+-]");
   $("#f_phone").mask("9999999999");
});

