function pop(obj, name, width, height) {
    if (!name) {
        name = 'pop';
    }
    if (!width) {
        width = 400;
    }
    if (!height) {
        height = 570;
    }
    popupWin = window.open(obj.href, name, 'width='+width+',height='+height);
    popupWin.focus();
}

function add2order(item_id){
    document.order_form.add_item_id.value = item_id;
    document.order_form.add_item_acc_id.value = '';
    document.order_form.submit();
}

function add2order_acc(item_id){
    document.order_form.add_item_acc_id.value = item_id;
    document.order_form.add_item_id.value = '';
    document.order_form.submit();
}

function add2preorder(item_id){
    document.preorder_form.item_id.value = item_id;
    document.preorder_form.item_id_acc.value = '';
    window.open('', 'preorder', 'top=100,left=100,width=350,height=215,resizable,scrollbars');
    document.preorder_form.submit();
}

function add2preorder_acc(item_id){
    document.preorder_form.item_id_acc.value = item_id;
    document.preorder_form.item_id.value = '';
    window.open('', 'preorder', 'top=100,left=100,width=350,height=215,resizable,scrollbars');
    document.preorder_form.submit();
}



function preloadImages(images_arr) {
    ccImageList = new Array ();
    for (counter in images_arr) {
        ccImageList[counter] = new Image();
        ccImageList[counter].src = images_arr[counter];
    }
}

function preview_image(img_src) {
    pic = new Image();
    pic.src = img_src;
    setTimeout("preload_image(pic)",100);
}

function preload_image(pic){
	if (pic.width==0 || pic.height==0) {
		setTimeout("preload_image(pic)",100);
	} else {
		view_image(pic.src, pic.width, pic.height);
	}
}


function view_image(img_src, img_width, img_height){
    if (img_width>screen.availWidth-150 || img_width==0) {
        win_width = screen.availWidth-150;
    } else {
        win_width = img_width+20;
    }
    if (img_height>screen.availHeight-150 || img_height==0) {
        win_height = screen.availHeight-150;
    } else {
        win_height = img_height+20;
    }
    win_top  = Math.abs((screen.availHeight-win_height)/3);
    win_left = Math.abs((screen.availWidth-win_width)/3);
    photoWindow = window.open('', '', "resizable=yes,top=" + win_top + ',left=' + win_left + ",width="+win_width+',height='+win_height+",status=0,menubar=0,toolbar=0,scrollbars=yes");
    photoWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'+img_src+'</title><style type="text/css"><!-- body {margin:0;padding:0} --></style>');
    photoWindow.document.write('<scr'+'ipt type=text/javascript>document.onkeypress = function CloseOnEsc(key) { if(document.all) { var keyCode = window.event.keyCode; } else { if (key.which == 0) {window.close();return;}   }  if (keyCode == 27) {window.close();return;} }</scr'+'ipt>');
    photoWindow.document.write('</head><body><img src="'+img_src+'" ');
    if ( (img_width>1) && (img_height>1) ) {
        photoWindow.document.write('width="'+img_width+'" height="'+img_height+'"');
    }
    photoWindow.document.write(' border=0 onclick="javascript:window.close();"></body></html>');
    photoWindow.document.bgColor="#f0f0f0";
    photoWindow.document.close()
}


function next_image(url) {
    image_id++;
    if (image_id > images_count) {
        image_id = 1;
    }
    document.getElementById('im_progress').innerHTML = image_id;
    document.getElementById('big_i_url').href = url+image_id+'/';
    document.getElementById('big_t_url').href = url+image_id+'/';
    document.images.small_img.src = small_images[image_id];
}

function prev_image(url) {
    image_id--;
    if (image_id < 1) {
        image_id = images_count;
    }
    document.getElementById('im_progress').innerHTML = image_id;
    document.getElementById('big_i_url').href = url+image_id+'/';
    document.getElementById('big_t_url').href = url+image_id+'/';
    document.images.small_img.src = small_images[image_id];
}

function stype_form_submit(url, attr) {
    sorttype = document.getElementById('stypeselect')
    stype = sorttype.options[sorttype.selectedIndex].value
    document.forms.stypeform.action = url + 'sort/' + stype + '/' + attr;
    document.stypeform.submit();
}

function stype_formbrands_submit(url) {
    sorttype = document.getElementById('stypebrands')
    stype = sorttype.options[sorttype.selectedIndex].value
    document.forms.stypeform.action = url + 'sort/' + stype + '/';
    document.stypeform.submit();
}

function createRequestObject() {
    var ro
    if (window.XMLHttpRequest) {
        ro = new XMLHttpRequest()
    } else if (window.ActiveXObject) {
        ro = new ActiveXObject('Microsoft.XMLHTTP')
    }
    return ro;
}

function handleResponse() {
    if(http.readyState == 4) {
        var response = http.responseText
        document.getElementById('pre').innerHTML = response > 0 ? 'Предварительный&nbsp;результат:&nbsp;'+response : 'Предварительный&nbsp;результат:&nbsp;0'
    }
}