function doDiv(id) {
	var obj, oimg;

	if (!(obj = document.getElementById('his_div_'+id))) return;
	if (!(oimg = document.getElementById('i_'+id))) return;
	
	if (!obj) {
		oimg.src = gc_path+"/images/minus.gif";
		return;
	}
	
	if (obj.style.display == 'block') {
		obj.style.display = 'none';
		oimg.src = gc_path+"/images/plus.gif";
	} else {
		obj.style.display = 'block';
		oimg.src = gc_path+"/images/minus.gif";
	}
}



function checkSearchField(obj) {
	if (obj.value == 'num') {
		document.getElementById('num_search').style.display='block';
		document.getElementById('reg_search').style.display='none';
	} else {
		document.getElementById('num_search').style.display='none';
		document.getElementById('reg_search').style.display='block';
	}
}


function tellServer(model, action, id, parent_id, v1, v2, v3) {
	window['ts'].document.getElementById('do_model').value = model;
	window['ts'].document.getElementById('tell_server').action.value = action;
	window['ts'].document.getElementById('tell_server').id.value = id;
	window['ts'].document.getElementById('tell_server').parent_id.value = parent_id;
	window['ts'].document.getElementById('tell_server').f1.value = v1;
	window['ts'].document.getElementById('tell_server').f2.value = v2;
	window['ts'].document.getElementById('tell_server').f3.value = v3;
	window['ts'].document.getElementById('tell_server').submit();
	return true;
}


function changeGoodPrice(id) {

	var elpname = 'el_price_'+id;
	var pname = 'price_'+id;

	var ch=document.order['basket['+id+']'].value*document.getElementById(elpname).innerHTML
	var delta = parseInt(document.getElementById(pname).innerHTML-ch);

	document.getElementById(pname).innerHTML = ch;
	
	changeSum(delta);
}

function changeSum(delta) {
	var sum = parseInt(document.getElementById('sum').innerHTML);
	document.getElementById('sum').innerHTML = sum - delta;
}

function showSum() {
	//var sum = parseInt(document.getElementById('sum').innerHTML);
	var sum=0;
	for (i=0; i<items.length; i++)	{
		sum+=items[i]["num"]*items[i]["price"];
	}
	document.getElementById('sum').innerHTML = sum;
}


function deleteGood(i) {
	items[i]["num"]=0;
	showSum();
	document.getElementById('numberChange').innerHTML=' ';
	document.getElementById('tr_'+items[i]["id"]).style.display='none';
	tellServer('basket', 'delete', '', '', items[i]["id"], '', '');
}

//display: none|inline|block|list-item|run-in|compact|marker|table|inline-table|table-row-group|table-header-group|table-footer-group|table-row|table-column-group|table-column|table-cell|table-caption;
function changeNumber(i) {
	items[i]["num"]=document.getElementById('good_'+items[i]["id"]).value;
	document.getElementById('price_'+items[i]["id"]).innerHTML=items[i]["num"]*items[i]["price"];
	showSum();
	document.getElementById('numberChange').innerHTML='Количество изменено';
	tellServer('basket', 'changeNumber', '', '', items[i]["id"], items[i]["num"], '');
}

function ShowSelectedOutletByFlag(sel) {
	var obj;
	var ind = sel.selectedIndex;
	outlet_flag = sel[ind].value;
	ShowOutletCitiesAndPoints();
}


function ShowSelectedOutlet(sel) {
	var obj;
	if (sel_outlet_city) {
		if ((obj = document.getElementById('outlet_city_'+sel_outlet_city))) obj.style.display = 'none';
	}
	var ind = sel.selectedIndex;
	sel_outlet_city = sel[ind].value;
	ShowOutletCitiesAndPoints();
}


function ShowOutletCitiesAndPoints() {
	var obj, this_outlet_flag;
	if (!('outlet_flag' in this)) this_outlet_flag = 7;
	else this_outlet_flag = outlet_flag
	if (sel_outlet_city && this_outlet_flag) {
		if (('points' in this) && points[sel_outlet_city]) {
			for (var i in points[sel_outlet_city]) {
				if ((obj = document.getElementById('outlet_point_'+i))) {
					if (((points[sel_outlet_city][i]^this_outlet_flag)<2) || (this_outlet_flag==7))	{
						obj.style.display = 'block';
					} else {
						obj.style.display = 'none';
					}
				}	
			}
		}
		
		if ((obj = document.getElementById('outlet_city_'+sel_outlet_city))) obj.style.display = 'block';
	}
}

function changePointered(id) {
	document.getElementById('thumb_pic_'+id).className = 'nopointered';
	document.getElementById('td_'+id).className = 'nopointered';
	if (id!=select_thumb_pic)
	document.getElementById('thumb_pic_'+select_thumb_pic).className = 'bordered';
}

function setPointer(id, pointer) {
	document.getElementById('thumb_pic_'+id).className = pointer;
}

var current_thumb_pic=0;
var select_thumb_pic=1;

function changeMainPic(id,psrc,pwidth,pheight) {
	var mobj, pobj;
	//if ((pobj = document.getElementById('thumb_pic_'+select_thumb_pic))) {
    if ((pobj = document.getElementById('td_'+select_thumb_pic))&&(current_thumb_pic!=select_thumb_pic)) {	
	pobj.className='bordered';
	document.getElementById('thumb_pic_'+select_thumb_pic).title='Кликните на фото для просмотра';
	}
	
	
		
	if ((pobj = document.getElementById('thumb_pic_'+id))) { 
	//if ((pobj = document.getElementById('td_'+id))) {	
		//pobj.className='selected';
		pobj.title=' ';
	    select_thumb_pic = id;
	} else {
		return;
	}
	if ((mobj = document.getElementById('main_pic'))) {
		mobj.src=psrc;
		mobj.width=pwidth;
		mobj.height=pheight;
	}

}

 function selectMainPic(id){
 	var pobj;
 	if(id==select_thumb_pic) return;
 	//if ((pobj = document.getElementById('thumb_pic_'+current_thumb_pic))&&(current_thumb_pic!=select_thumb_pic)) {
 	if ((pobj = document.getElementById('td_'+current_thumb_pic))&&(current_thumb_pic!=select_thumb_pic)) {	
	 		pobj.className='bordered';
	 	 		
	}
 	//if ((pobj = document.getElementById('thumb_pic_'+id))) {
 	if ((pobj = document.getElementById('td_'+id))) {
		pobj.className='current';
	    current_thumb_pic = id;
	}
 	
 }
 function mouseOut(){
  	var pobj;
 	if(current_thumb_pic!=select_thumb_pic)
 	if(pobj=document.getElementById('td_'+current_thumb_pic)) pobj.className='bordered';
 	current_thumb_pic=0;
 	
 	
 }



function openNew(obj, width, height, titul) {
	
	newwin = window.open('/images/spacer.gif', 'Information', 'toolbar=0,status=0,menubar=0,scrollbars=0,resizable=1,width=' + width + ',height=' + height);
	newwin.document.open();
	newwin.document.write('<title>'+ titul + '</title>');
 	newwin.document.write('<body style="margin-left:0; margin-right:0; margin-top:0; margin-bottom:0;padding-top:0; padding-left:0; padding-right:0; padding-bottom:0;"><a href="javascript:void(0)" onClick="window.close()"><img src="' + obj + '" border=0 alt="Закрыть"></a></body>');
 	newwin.document.close();
	newwin.focus();
}


function changeSearchType(sel, cat_parent_id) {
	var ind = sel.selectedIndex;
	if (ind == 1) document.getElementById('search_parent_id').value = cat_parent_id;
	else document.getElementById('search_parent_id').value = 2;
}
