function nolink() {
	return false;
}

function showImageViewer( obj ) {
	var c_image = document.getElementById ('showerimage');
	var c = document.getElementById ('shower');
	
	c.style.display = 'block';
	c_image.src = obj.href;
	c.style.left = obj.offsetWidth;
}

function closeImageViewer () {
	var c = document.getElementById ('shower');
	c.style.display = 'none';
}

function addtovartobacket( articul ) {
	var urlpart = '';
	var cnter = document.getElementById('cnt_' + articul);
	if( cnter !== null )
		urlpart = '/?tovar_counter=' + parseInt( cnter.value );
	openWindow( '/popupaddtobacket/' + articul + urlpart, 800, 600, 'centerWindow' );
	return false;
}

function popupBacket() {
	openWindow( '/popupaddtobacket', 800, 600, 'centerWindow' );
	return false;
}

function viewbigfoto( articul, id_image ) {
	openWindow( '/popupimage/' + articul + ( id_image ? '/' + id_image : '' ), 200, 200, 'centerWindow' );
	return false;
}

function openWindow( url, w, h, screen2 ) {
	var params = 'width=' + w + ',height=' + h;
	if( screen2 == 'centerWindow' ) {
		var wc	= parseInt( ( screen.availWidth - parseInt( w ) ) / 2 );
		var hc	= parseInt( ( screen.availHeight - parseInt( h ) ) / 2 ); 	
		params += ',screenX=' + wc + ',screenY=' + hc + ',left=' + wc + ',top=' + hc;
	}
	params += ',toolbar=no,scrollbars=yes,directories=no,status=no,menubar=no,location=no';
	window.open( url, '_blank', params );
}

function authform() {
	if(navigator.appName != "Opera") {
		fadeOpacity.addRule('authform1', 0, 0.8, 20);
		fadeOpacity('authsformtable', 'authform1');
	} else {
		setElementOpacity($('authsformtable'), 0.8)
	}
	$('authsform').style.display = "block";
	$('auth_username').focus();
}

function callform() {
	if(navigator.appName != "Opera") {
		fadeOpacity.addRule('callform1', 0, 0.8, 20);
		fadeOpacity('callsformtable', 'callform1');
                fadeOpacity('callsformtable2', 'callform1');
	} else {
		setElementOpacity($('callsformtable'), 0.8);
                setElementOpacity($('callsformtable2'), 0.8)
	}
	$('callsform').style.display = "block";
	$('call_fio').focus();
}

function closeauthform() {
	if(navigator.appName != "Opera") {
		fadeOpacity.back('authsformtable');
	}
	$('authsform').style.display = "none";
}
function closecallform() {
	if(navigator.appName != "Opera") {
		fadeOpacity.back('callsformtable');
	}
	$('callsform').style.display = "none";
}

function initBackets() {
	new Ajax.Updater('backet', '/checkbacket/');
}

function initScroll() {
	new Ajax.Updater('scroller', '/scroller/');
}

function initPoll() {
	new Ajax.Updater('lastpoll', '/lastpoll/');
}

function setnormalclass() {
	$('hardware_display').className = "scroller";
	allcount()
}

function gethardware(obj) {
	var msg = 0;
	if( $('tovarcount') ) {
		if(parseInt($('tovarcount').value) > 0) {
			if(!confirm('У вас сейчас есть выбранные товары\nВы действительно хотите очистить список?')) {
				msg = 1;
			}
		}
	}
	if( msg == 0 ) {
		var path = '/zone/ajax/';
		var ok = 0;
		if($('select_hardware').value != '0') {
			ok = 1;
			path += '?id=' + $('select_hardware').value;
		}
		if(ok == 1) {
			$('hardware_display').className = "loading";
			$('hardware_display').innerHTML = "<center>Подождите пока выполняется загрузка</center>";
			new Ajax.Updater('hardware_display', path, {onComplete: setnormalclass});	
		}
	}
}

function pleaseinput (obj, id) {
	if(obj.checked) {
		$('kolvo_' + id).disabled = 0;
	} else {
		$('kolvo_' + id).disabled = 1;
	}
}

function allcount() {
	var summa = 0;
	var kolvos = 0;
	var summa2 = 0;
	var summas = 0
	kolvos = document.getElementsByClassName('kolvo');
	for (var i = 0; i < kolvos.length; i++) {
		if(kolvos[i].value) {
			summa += parseInt(kolvos[i].value);
		}
	}
	$('tovarcount').value = parseInt(summa);
	summas = document.getElementsByClassName('summa');
	for (var i = 0; i < summas.length; i++) {
		if(summas[i].innerHTML) {
			summa2 += parseFloat(summas[i].innerHTML);
		}
	}
	$('tovarsumma').value = parseFloat(summa2).toFixed(2) + " " + $('valute').value;
	if(summa > 0) {
		$('makeorder').disabled = 0;
	} else {
		$('makeorder').disabled = 1;
	}
}

function summar (obj, id) {
	var reg = /(\d+){1,5}/;
	if(obj.value) {
		if(reg.test(obj.value)) {
			if(parseInt(obj.value) > 999) {
				alert('Число не может быть больше 999');
				obj.value = 999;
			}
			$('summa_' + id).innerHTML = (parseInt(obj.value) * parseFloat($('cena_' + id).value)).toFixed(2) + ' ' +  $('valute').value;
			allcount();
		} else {
			alert('Поле не может содержать других символов');
			obj.value = 0;
			allcount();
			$('summa_' + id).innerHTML = '0 ' +  $('valute').value;
		}
	} else {
		allcount();
	}
}

function sendPoll(obj) {
	var params = 'send=1&answer=' + obj.answer.value + '&sid=' + obj.sid.value + '&uid=' + obj.uid.value;
	new Ajax.Updater('lastpoll', '/lastpoll/', {method: 'post', parameters: (params), contentType: 'application/x-www-form-urlencoded'});
	return false;
}

function leftScroll() {
	new Ajax.Updater('scroller', '/scroller/?left');
}

function rightScroll() {
	new Ajax.Updater('scroller', '/scroller/?right');
}

function getCookie(name)  {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function actbg(obj)
{
	obj.style.background='url(images/actitem.gif) repeat-x left top';
}
function bg(obj)
{
	obj.style.background='transparent';
}

function clearform() {
	var err = '';
	var obj = document.backetformnew;
	
	obj.option.innerHTML = '';
	obj.option.options[0] = new Option('Выберите подраздел','none')
	obj.option.disabled = 1;
	obj.price.innerHTML = '';
	obj.price.options[0] = new Option('Выберите товар','none')
	obj.price.disabled = 1;
	obj.count.value = '';
	
	var imgA = new Object();
	
	imgA['closen'] = new Image(1, 1);
	imgA['closen'].src = "/templates/images/1px.gif";
	
	document.getElementById('itemimg').src = imgA['closen'].src;
	document.getElementById('iteminfo').innerHTML = '';
	
	obj.section.focus();
}
/*
function summatype( type )
{
	var obj = document.getElementsByName('cena' + type + '[]'); 
	var sum = 0;
	for (var i = 0; i < obj.length; i++)
	{
		sum += Math.round(obj[i].value*100)/100;
	}
	var obj = document.getElementById('summa_' + type); 
	obj.value = Math.round(sum*100)/100;
	summaAll();
}*/

function checkaddtovarform() {
	var err = '';
	var obj = document.backetformnew;
	if(obj.section.value == 'none') {
		err += 'Вы не выбрали раздел!\n';
		obj.section.focus();
	}
	if(obj.option.value == 'none' && err == '') {
		err += 'Вы не выбрали подраздел!\n';
		obj.option.focus();
	}
	if(obj.price.value == 'none' && err == '') {
		err += 'Вы не выбрали товар!\n';
		obj.price.focus();
	}
	if(obj.count.value == '' && err == '') {
		err += 'Вы не ввели количество экземпляров товара!\n'
		obj.count.focus();
	}
	if(err != '') {
		alert(err);
		return false;
	} else {
		return true;
	}
}

function chkstatusdel(obj) {
	if(obj.checked) {
		document.getElementById("del1").innerHTML='<b>требуется</b>';
	} else {
		document.getElementById("del1").innerHTML='<b>не требуется</b>';
	}
}

function chkstatusass(obj) {
	if(obj.checked) {
		document.getElementById("ass1").innerHTML='<b>требуется</b>';
	} else {
		document.getElementById("ass1").innerHTML='<b>не требуется</b>';
	}
}

function checkSearchForm( obj ) {
	if ( obj.q == "" ) {
		alert('Вы не ввели слово для поиска');
		obj.q.focus();
		return false;
	} else {
		obj.action = '/search/';
		return true;
	}
}
