function scroll_thumbs(thumbs_list, direction){	if (thumbsScrollSize<=320) return false;
	thumbs = document.getElementById(thumbs_list);
	img_up = document.getElementById('img_scroll_up');
	img_dn = document.getElementById('img_scroll_down');
	oTop = thumbs.style.top.substring(0, thumbs.style.top.length - 2) * 1;
	nTop = oTop;
	ret = false;
	switch (direction){		case 'up':
			if (oTop!=0) {nTop = oTop+80;ret = true;}
			if (nTop==0&&oTop!=0)
				img_up.src=thumbsImgPath+'scroll_up_d.gif';
			if (((0-oTop+320) == thumbsScrollSize)&&((0-nTop+320) != thumbsScrollSize))
				img_dn.src=thumbsImgPath+'scroll_down.gif';
		break;		case 'down':
			if ((0-oTop+320) != thumbsScrollSize) {nTop = oTop-80;ret = true;}
			if (((0-nTop+320) == thumbsScrollSize)&&((0-oTop+320) != thumbsScrollSize))
				img_dn.src=thumbsImgPath+'scroll_down_d.gif';
			if (nTop!=0&&oTop==0)
				img_up.src=thumbsImgPath+'scroll_up.gif';
		break;
	}
	thumbs.style.top = nTop+'px';
	return ret;}

function scroll_thumbs_whell(thumbs_list){	if (event.wheelDelta >= 120)
		ret = scroll_thumbs(thumbs_list, 'up');
	else if (event.wheelDelta <= -120)
		ret = scroll_thumbs(thumbs_list, 'down');
	return !ret;
}

function select_item(num, defValue){	fldCount = document.getElementsByName('item['+num+'][count]');
	fldCount = fldCount[0];
	fldAdd = document.getElementsByName('item['+num+'][add]');
	fldAdd = fldAdd[0];
	if (fldAdd.checked){		fldCount.disabled = false;
		fldCount.style.backgroundColor = '#FFFFFF';
		fldCount.focus();
	}else{		fldCount.disabled = true;
		fldCount.value = defValue;
		fldCount.style.backgroundColor = '#D4D0C8';
	}
}

function select_all(checked){	for (i=itemCount-1; i>=0; i--){		fldAdd = document.getElementsByName('item['+i+'][add]');
		fldAdd = fldAdd[0];
		if (fldAdd.checked!=checked)
			fldAdd.click();
	}
}

function form_submit(id){	frm = document.getElementById(id);
	frm.submit();}

function basketSearchActive(value, active){	fldSearch = document.getElementsByName('search');
	fldSearch = fldSearch[0];
	if (value==''&&!active){		fldSearch.value = 'P/N';
		fldSearch.style.color = 'silver';
	}else if(value=='P/N'&&active){		fldSearch.value = '';
		fldSearch.style.color = 'black';
	}

}

function basketEdit(id){	fldText = document.getElementsByName('item['+id+'][count]');
	fldText = fldText[0];
	fldChange = document.getElementsByName('item['+id+'][change]');
	fldChange[0].value = '1';
	fldText.style.borderColor = 'Gray';
	aEdit = document.getElementById('item['+id+'][edit]');
	aApply = document.getElementById('item['+id+'][apply]');
	aEdit.style.display = 'none';
	aApply.style.display = 'block';
	fldText.readOnly = false;
	fldText.focus();
	fldText.select();}

function basketSave(){	for (i=1; i<=basketItemCount; i++){		fldText = document.getElementsByName('item['+i+'][count]');
		if (fldText[0].value==''){			alert(basketErrMessage);
			fldText[0].focus();
			fldText[0].select();
			return;
		}
	}
	frm = document.getElementById('edit');
	frm.action = basketUrlSave;
	frm.submit();
}

function set_field(name, value){	fld = document.getElementsByName(name);
	fld[0].value = value;
}

function search_check(id, disabled){	fldText = document.getElementsByName('item['+id+'][count]');
	fldText = fldText[0];
	fldText.disabled = disabled;
	if (disabled){
		fldText.value = fldText.defaultValue;
		fldChange = document.getElementsByName('item['+id+'][change]');
		fldChange[0].value = '0';
	}else
		fldText.focus();}

function isNotEmpty(elem) {
    var str = elem.value;
    if(str == null || str.length == 0) {
        return false;
    } else {
        return true;
    }
}

function checkForm(formID){	var frm = document.getElementById(formID);
	var err = 0;
	err += isNotEmpty(frm['login'])?0:1;
	err += isNotEmpty(frm['password'])?0:1;
	err += isNotEmpty(frm['cpassword'])?0:1;
	err += isNotEmpty(frm['email'])?0:1;
	err += isNotEmpty(frm['lang'])?0:1;
	err += isNotEmpty(frm['firstname'])?0:1;
	err += isNotEmpty(frm['lastname'])?0:1;
	err += isNotEmpty(frm['firm_type'])?0:1;
	if (frm['firm_type'].value==1){
		err += isNotEmpty(frm['inn'])?0:1;
		err += isNotEmpty(frm['firmname'])?0:1;
	}
	err += isNotEmpty(frm['currency'])?0:1;
	err += isNotEmpty(frm['country'])?0:1;
	if (isNotEmpty(frm['account_address1'])&&frm['account_address1'].value==adr1) err += 1;
	if (isNotEmpty(frm['account_address2'])&&frm['account_address2'].value==adr2) err += 1;
	if (isNotEmpty(frm['account_address3'])&&frm['account_address3'].value==adr3) err += 1;
	var acc_delivery = document.getElementsByName('account_delivery');
	if (acc_delivery[1].checked){
		if (isNotEmpty(frm['delivery_address1'])&&frm['delivery_address1'].value==adr1) err += 1;
		if (isNotEmpty(frm['delivery_address2'])&&frm['delivery_address2'].value==adr2) err += 1;
		if (isNotEmpty(frm['delivery_address3'])&&frm['delivery_address3'].value==adr3) err += 1;
	}
	err += isNotEmpty(frm['phone'])?0:1;
	if (err){
		alert(errMessage);
		return false;
	}else if (frm['password'].value!=frm['cpassword'].value){
		alert(errPassword);
		return false;
	}
	return true;}

function confirm_url(msg){	return window.confirm(msg);}

function open_confirm_url(msg, url){
	if (window.confirm(msg))
		window.location = url;
}


var path;

function isMenuChild(obj){	if (obj.tagName=='TD'&&obj.id=='menu')
		return true;
	else if (obj.tagName=='BODY')
		return false;
	else return isMenuChild(obj.parentNode);
}

function menu_restore(evt){	if (evt.explicitOriginalTarget==undefined)
		obj = evt.toElement;
	else
		obj = evt.explicitOriginalTarget;
	if (!isMenuChild(obj))
		showSubmenu(defaultMenu, 1);
}

var visibleMenuID;
var menuAnimationStep = 0;
var menuAnimationProcessing = false;

function menuAnimation(ShowID, HideID){	menuAnimationStep++;
	if (HideID>0){
		var objMenuHide = document.getElementById('submenu'+HideID);
		objMenuHide.style.overflow = 'hidden';
		if (menuAnimationStep==menuShowStep){
			objMenuHide.style.display = 'none';
		}else
			objMenuHide.style.height = menuHeights[HideID]-(menuHeights[HideID]*menuAnimationStep/menuShowStep)+'px';
	}
	if (ShowID>0){		var objMenuShow = document.getElementById('submenu'+ShowID);
		objMenuShow.style.display = 'block';
		objMenuShow.style.overflow = 'hidden';
		objMenuShow.style.height = (menuHeights[ShowID]*menuAnimationStep/menuShowStep)+'px';
	}
	if (menuAnimationStep==1){
		menuAnimationProcessing = true;
		ShowMenuTimer = setInterval('menuAnimation('+ShowID+', '+HideID+')', menuShowTime*1000/menuShowStep);
	}else if (menuAnimationStep==menuShowStep){
		clearInterval(ShowMenuTimer);
		menuAnimationStep = 0;
		visibleMenuID = ShowID;
		menuAnimationProcessing = false;
	}
}

function showSubmenu(ID, Anim){	if (ID==visibleMenuID) return;
	if (menuAnimationProcessing) return;
	if (Anim){		menuAnimation(ID, visibleMenuID);	}else{		if (visibleMenuID>0){			var objMenuHide = document.getElementById('submenu'+visibleMenuID);
			objMenuHide.style.display = 'none';
		}
		if (ID>0){
			var objMenuShow = document.getElementById('submenu'+ID);
			objMenuShow.style.display = 'block';
		}
		visibleMenuID = ID;
	}}

function access_allow(){	if (!user_registred)
		alert(forbidden_message);
	return user_registred;}

function swapText(obj, active, text){
	if (obj.value==''&&!active){
		obj.style.fontWeight = 'normal';
		obj.style.color = 'silver';
		obj.value = text;
	}else if(obj.value==text&&active){
		obj.value = '';
		obj.style.fontWeight = 'bold';
		obj.style.color = 'black';
	}

}

function basketComment(id){
	fldText = document.getElementsByName('item['+id+'][comment]');
	fldText = fldText[0];
	fldChange = document.getElementsByName('item['+id+'][changeComment]');
	fldChange[0].value = '1';
	fldText.style.borderColor = 'Gray';
	aEdit = document.getElementById('item['+id+'][commentEdit]');
	aApply = document.getElementById('item['+id+'][save]');
	aEdit.style.display = 'none';
	aApply.style.display = 'block';
	fldText.readOnly = false;
	fldText.focus();
	fldText.select();
}

function basketCommentSave(){
	for (i=1; i<=basketItemCount; i++){
		fldText = document.getElementsByName('item['+i+'][count]');
		if (fldText[0].value==''){
			alert(basketErrMessage);
			fldText[0].focus();
			fldText[0].select();
			return;
		}
	}
	frm = document.getElementById('edit');
	frm.action = basketUrlCommentSave;
	frm.submit();
}

function disable_delivery(){	da1 = document.getElementById('delivery_address1');
	da2 = document.getElementById('delivery_address2');
	da3 = document.getElementById('delivery_address3');
	da1.disabled = true;
	da2.disabled = true;
	da3.disabled = true;
	da1.style.border = '1px solid silver';
	da2.style.border = '1px solid silver';
	da3.style.border = '1px solid silver';
	show_stars2(0);
}

function enable_delivery(){
	da1 = document.getElementById('delivery_address1');
	da2 = document.getElementById('delivery_address2');
	da3 = document.getElementById('delivery_address3');
	da1.disabled = false;
	da2.disabled = false;
	da3.disabled = false;
	da1.style.border = '1px solid black';
	da2.style.border = '1px solid black';
	da3.style.border = '1px solid black';
	show_stars2(1);
}

