// JavaScript Document

function shBlock() {
	if ($('div#auto').css("display") == "block") {
		$('div#auto').fadeOut(3000);
		setTimeout('$(\'div#track\').fadeIn(3000)', 2000);
		}
	else {
		$('div#track').fadeOut(3000);
		setTimeout('$(\'div#auto\').fadeIn(3000)', 2000);
		}
	}

function Search3(inp_id) {
	if((document.getElementById(inp_id).value=='поиск') || document.getElementById(inp_id).value=='' || document.getElementById(inp_id).value.length < 3) {
		alert('Строка поиска не должна быть короче 3 символов.'); 
		return false;
		}
	}

function ATF(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;

  //Gecko
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  //IE4+
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  //Opera7+
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;

  return true;
}

function zoom(i, t , w, h, wn) {
        var width = w;
        var height = h;
        var html = '';
        var params = 'left=' + ((screen.width - width) / 2) + ',top=' + ((screen.height - height - 50) / 2) + ',width=' + (width+41) + 'px,height=' + (height + 50) + 'px,scrollbars=no';
        html  = '<title>Zoom</title><body title="ЪБЛТЩФШ" onclick="self.close()" style="cursor:pointer" leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>';
        html += '<table width=100% height=100%><tr><td align=center valign=center>';
        html += '<img src="' + i + '" width="'+width+'" height="'+height+'">';
        html += '</td><tr></table>';
        var z_w = window.open('about:blank', wn, params);
        z_w.document.write(html);
        z_w.document.close();
        z_w.focus();
}

var form_locked = true;

function ch_program(link1, link2) {
	document.getElementById('svar1').style.visibility = (document.getElementById('program').value == '1' ? 'hidden' : '');
	document.getElementById('svar2').href = (document.getElementById('program').value == '1' ? link2 : link1) + 'index.php?authuserid=guest&authuserpass=guest';
	document.getElementById('svar3').href = (document.getElementById('program').value == '1' ? link2 : link1) + 'help/index.php#login';
	document.getElementById('recover1').href = (document.getElementById('program').value == '1' ? link2 : link1) + 'help/recover/';
	if (document.getElementById('program').value == '0' || document.getElementById('program').value == '1')
		form_locked = false;
	else
		form_locked = true;
}

function checklogin() {
	var errorList = [];
	login = document.getElementById('login');
	password = document.getElementById('password');
	discount = document.getElementById('discount');

	if (!login || !password || !discount)
		return false;

	if (login.value.length < 2)
		errorList.push('Поле логина должно быть не короче двух символов');

	if (password.value.length < 2)
		errorList.push('Поле пароля должно быть не короче двух символов');

	if (discount.value != '0' && (isNaN(discount.value) || discount.value > 100))
		errorList.push('Скидка должна быть указана в диапазоне от 0 до 100');

	if (!errorList.length) return  true;

	var errorMsg = "При заполнении формы допущены следующие ошибки:\n\n";

	for (i = 0; i < errorList.length; i++) {
        	errorMsg += errorList[i] + "\n";
	}
    	alert(errorMsg);
	return false;
}

