﻿// JScript File
var notecopytarget = null;

function OpenItemWin() {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;
    var xOffset = (xMax - 500)/2, yOffset = (yMax - 350)/2;
    window.open('','ItemWin','width=500,height=350,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',copyhistory=no,directories=no, menubar=no,location=no,scrollbars=no,resizable=no') ;
}
function ShowImage() {
    if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax=480;
    var xOffset = (xMax - 600)/2, yOffset = (yMax - 600)/2;
    window.open('','PhotoWin','width=600,height=600,screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',copyhistory=no,directories=no, menubar=no,location=no,scrollbars=no,resizable=no') ;
}
function AddCart(id) {
	//if (document.getElementById('cart_frame')) document.body.removeChild(document.getElementById('cart_frame'));
	var q = document.getElementById('q' + id);
	var i = document.getElementById('i' + id);
	if (q != null && i != null && q.value != '' && i.value != '') {
	    var url = '/cart.aspx?quantity=' + q.value + '&item_id=' + parseInt(i.value) + '&action=buy';
	    var fr = document.createElement("iframe");
	    fr.id = "cart_frame";
	    fr.name = "cart";
	    fr.src = url;
	    fr.style.display = 'none';
	    document.body.appendChild(fr);
	    window.fr = fr;
	    updatenb();
	    return false;
	}
	else {
	    alert('Введите количество!');
	    return false;
	}
}
function SwitchImage(i, l) {
    var d = document.getElementById("image" + i);
    if (d != null) {
        $("div.largeimage").hide();
        $("div.hlargeimage").hide();
        $("div.hscrollimage").hide();
        $(d).show();
        $("a.photolink").removeClass("photolinkactive");
        $(l).addClass("photolinkactive");
    }
    return false;
}
function OpenMenu(obj) {
    $("a[@id=" + obj + "]+div").toggle("fast");
    $("a[@id=" + obj + "]").toggleClass("cat_minus");
    return false;
}
function round(number,X) {
// rounds number to X decimal places, defaults to 2
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function updatenb() {
    $("#nbcontent").empty().append('<div style="padding: 30px; text-align: center;"><strong class="green">... загрузка ...</strong></div>');
    $.ajax({
        type: "GET",
        url: "/notebook.aspx?a=s&r=" + Math.random()*Math.random(),
        success: function(msg){
            $("#nbcontent").empty().append(msg).html(msg);
            
            }
    });
}

function loadnb(t) {
if (t == '[-]') {
    $('#nbcontent').slideUp('slow', function() {$("#nbcontent").empty();});
    $('#nbsize').text('[+]');
    $.cookie('nbstatus', '0', 30);
    } 
else {
    $('#nbcontent').show();
    $('#nbsize').text('[-]');
    $.cookie('nbstatus', '1', 30);
    updatenb();
    }
  return false;
}
function fixnb(obj) {
    if (obj.checked) {
        $('#notebook').css('position', 'fixed');
        $('#notebook').DraggableDestroy();
    }
    else {
        $('#notebook').css('position', 'absolute');
        $('#notebook').Draggable(
	    {
		    zIndex: 	1000,
		    ghosting:	true,
		    opacity: 	0.7,
		    handle:     '#nbhead',
		    onChange:   function() { $.cookie('nbtop', $('#notebook').css('top'), 30); $.cookie('nbleft', $('#notebook').css('left'), 30); }
	    });
   }
}
function nbadd(m) {
    if (m == 0) {
        $('#notes').hide();
        $('#addnote').show();
    }
    else if (m == 1) {
        if ($('#nbnote').val() != '') {
            $.post("/notebook.aspx?a=a",
                { note: $('#nbnote').val() },
                function(data){
                nbadd(-1);
                updatenb();
            });
        }
        else {
            alert('Пустой комментарий!');
        }
    }
    else if (m == -1) {
        $('#notes').show();
        $('#addnote').hide();
        $('#nbnote').val('');
    }
    return false;
}
function delnote(note_id) {
    $.post("/notebook.aspx?a=d",
            { id: note_id },
                function(data){
                updatenb();
            });
    return false;
}
function copynote(note_id) {
    if (notecopytarget != null)
        $(notecopytarget).val($(notecopytarget).val() + ' ' + $('#note'+note_id).text());
    else alert('Некуда копировать :)');
    return false;
}