function showhide(id)
{
      subject = document.getElementById(id);
      subject.style.display = subject.style.display!='block' ? 'block' : 'none';
}

function new_win(img, name, width, height) {
      w1=window.open('','new_window','resizable=no,menubar=no,status=no,scrollbars=no,width='+width+',height='+height+'');
      w1.document.open();
      w1.document.write("<html><head><title>"+name+"</title></head><body leftmargin=0 topmargin=0>");
      w1.document.write("<a href='javascript:window.close()'><img src="+img+" width="+width+" height="+height+" border=0 alt='"+name+"'></a>");
      w1.document.write("</body></html>");
      w1.document.close();
    w1.focus();
}

function order(goodid, userid){
        var s = "g"+goodid;
		var tmp = "tmp"+goodid;
		JsHttpRequest.query(
            '/lib/quickorder.inc.php', // backend
            {
                'goodid': goodid,
				'userid': userid,
				'kol': document.getElementById(s).value,
				'tmp': document.getElementById(tmp).value
            },
            // Function is called when an answer arrives.

            function(result, errors) {
                // Write errors to the debug div.
                document.getElementById("debug").innerHTML = errors;
                // Write the answer.
                document.getElementById(s).style.backgroundColor = "#b2ffb2";
                // document.getElementById("debug").innerHTML = result["pic"];
            },
            false  // do not disable caching
        );
}
function wprice(goodid, userid){
        var s = "g"+goodid;
		var w = "w"+goodid;
		if (document.getElementById(s).value > 0) { // товар уже заказан, меняем ему желательную цену
		JsHttpRequest.query(
            '/lib/quickwprice.inc.php', // backend
            {
                'goodid': goodid,
				'userid': userid,
				'price': document.getElementById(w).value
            },
            // Function is called when an answer arrives.

            function(result, errors) {
                // Write errors to the debug div.
                document.getElementById("debug").innerHTML = errors;
                // Write the answer.
                document.getElementById(w).style.backgroundColor = "#b2ffb2";
                //document.getElementById("debug").innerHTML = result["pic"];
            },
            false  // do not disable caching
        );
		}
		else // товар еще не заказан. меняем временную цену
		{
			var tmp = "tmp"+goodid;
			document.getElementById(tmp).value = document.getElementById(w).value;
		}
}

function changeOrder(orderid){
        var s = "kol"+orderid;
		JsHttpRequest.query(
            '/lib/quickchange.inc.php', // backend
            {
                'orderid': orderid,
				'kol': document.getElementById(s).value
            },
            // Function is called when an answer arrives.

            function(result, errors) {
                // Write errors to the debug div.
                //document.getElementById("debug").innerHTML = errors;
                // Write the answer.
                document.getElementById(s).style.backgroundColor = "#b2ffb2";
                // document.getElementById("debug").innerHTML = result["pic"];
            },
            false  // do not disable caching
        );
}
function changeWprice(orderid){
        var s = "wprice"+orderid;
		JsHttpRequest.query(
            '/lib/quickwpricechange.inc.php', // backend
            {
                'orderid': orderid,
				'price': document.getElementById(s).value
            },
            // Function is called when an answer arrives.

            function(result, errors) {
                // Write errors to the debug div.
                //document.getElementById("debug").innerHTML = errors;
                // Write the answer.
                document.getElementById(s).style.backgroundColor = "#b2ffb2";
                // document.getElementById("debug").innerHTML = result["pic"];
            },
            false  // do not disable caching
        );
}
function changeGprice(orderid){
        var s = "gprice"+orderid;
		JsHttpRequest.query(
            '/lib/quickgpricechange.inc.php', // backend
            {
                'orderid': orderid,
				'price': document.getElementById(s).value
            },
            // Function is called when an answer arrives.

            function(result, errors) {
                // Write errors to the debug div.
                //document.getElementById("debug").innerHTML = errors;
                // Write the answer.
                document.getElementById(s).style.backgroundColor = "#b2ffb2";
                // document.getElementById("debug").innerHTML = result["pic"];
            },
            false  // do not disable caching
        );
}
function deleteOrder(orderid){
        var s = "tr"+orderid;
		JsHttpRequest.query(
            '/lib/quickdelete.inc.php', // backend
            {
                'orderid': orderid
            },
            // Function is called when an answer arrives.

            function(result, errors) {
                // Write errors to the debug div.
                //document.getElementById("debug").innerHTML = errors;
                // Write the answer.
                document.getElementById(s).style.textDecoration = "line-through";
                document.getElementById(s).style.color = "#ccc";
				document.getElementById('kol'+orderid).disabled = true;
				//document.getElementById('wprice'+orderid).disabled = true;
                // document.getElementById("debug").innerHTML = result["pic"];
            },
            false  // do not disable caching
        );
}

function delChaim(orderid){
	if (confirm('Вы уверены, что хотите удалить эту заявку?')){
		var s = "li"+orderid;
		JsHttpRequest.query(
            '/lib/quickchaimdelete.inc.php', // backend
            {
                'orderid': orderid
            },
            // Function is called when an answer arrives.

            function(result, errors) {
                // Write errors to the debug div.
                //document.getElementById("debug").innerHTML = errors;
                // Write the answer.
                document.getElementById(s).style.textDecoration = "line-through";
                document.getElementById(s).style.color = "#ccc";
                //document.getElementById("debug").innerHTML = result["pic"];
            },
            false  // do not disable caching
        );
	}
}
