<!--

var limit, next;

function validateEmail(item) {
	var lsAT;
	var lsDOT;
	lsAT = item.value.indexOf("@");
	lsDOT = item.value.indexOf(".");
	if (lsAT == -1 || lsDOT == -1 || item.value.indexOf(" ") != -1 ) {
		return false;
	}
	return true;
}

function validateProfile() {
    if (document.forms.profile.login.value=='') {
			alert("Введите Ваш логин");
			document.forms.profile.login.focus();
			return (false);
	}
    if  (!validateEmail(document.forms.profile.email)) {
			alert("Неправильный адрес электронной почты");
			document.forms.profile.email.focus();
			return (false);
	}
    if ((document.forms.profile.password.value=='') && (document.forms.profile.action.value=='register')) {
			alert("Введите пароль");
			document.forms.profile.password.focus();
			return (false);
	}
    if ((document.forms.profile.password2.value=='') && (document.forms.profile.action.value=='register')) {
			alert("Введите пароль второй раз");
			document.forms.profile.password2.focus();
			return (false);
	}
    if (document.forms.profile.password.value!='') {
		if (document.forms.profile.password.value != document.forms.profile.password2.value) {
			alert("Содержимое полей 'Пароль' и 'Пароль еще раз' должно быть одинаковыми");
			document.forms.profile.password.focus();
			return (false);
		}
		if (document.forms.profile.password.value.length<4) {
			alert("Длина пароля должна быть не менее 4 символов");
			document.forms.profile.password.focus();
			return (false);
		}
	}
	
    if ((!document.forms.profile.gender[0].checked) && (!document.forms.profile.gender[1].checked)) {
			alert("Укажите Ваш пол");
			return (false);
	}
    if ((!document.forms.profile.agreedtogetads[0].checked) && (!document.forms.profile.agreedtogetads[1].checked)) {
			alert("Укажите, желаете ли Вы стать членом клуба Мозг.Ру");
			return (false);
	}

	document.forms.profile.submit();
	return (false);
}


function setlimit(value) {
	limit = value;
}

function setnext(value) {
	next = value;
}

function display(id, str) {
  if (navigator.appName != "Microsoft Internet Explorer") {
    with (document[id].document) {
      open();
      write(str);
      close();
    }
  } else {
    
	document.all[id].innerHTML = str;
  }
}


function showclock()
{
	
	limit--;
	if (limit>0) {
		window.status = "Осталось " + limit + " секунд";
	} else {
		window.status = "";
	}
	if (limit==30) display("timer","Осталось "+limit+" секунд!");
	if (limit==10) display("timer","Осталось "+limit+" секунд!");
	if (limit==5) display("timer","Осталось "+limit+" секунд!");
	if (limit==4) display("timer","Осталось "+limit+" секунд!");
	if (limit==3) display("timer","Осталось "+limit+" секунд!");
	if (limit==2) display("timer","Осталось "+limit+" секунд!");
	if (limit==1) display("timer","Осталось "+limit+" секунд!");
	if (limit==0) display("timer","Время кончилось</b></font>");
	
	if (limit==-2) {
		  location.href=next;
	};
	
	setTimeout("showclock()",1000)
}


function isEmpty(field) {
  if (field.value=="") {

    if (field.name == "repository_name") {
      alert("Please, input repository name");
      return (true);
    }
    if (field.name == "folder_name") {
      alert("Please, input folder name");
      return (true);

    }
    if (field.name == "document_name") {
      alert("Please, input document name");
      return (true);

    }
    if (field.name == "attribute_name") {
      alert("Please, input attribute name");
      return (true);
    }
    if (field.name == "linktype_name") {
      alert("Please, input link type name");
      return (true);
    }
    if (field.name == "linktype_description") {
      alert("Please, input link type description");
      return (true);
    }

    if (field.name.indexOf("_path") != -1) {
      alert("Please, input path");
      return (true);
    }
    if (field.name == ("document_published")) {
      alert("Please, input published date");
      return (true);
    }    
  }
  return (false);
}


function hasUnsupportedSymbols(field) {
  if (escape(field.value).length != field.value.length || field.value.indexOf(".") != -1 || field.value.indexOf("+") != -1 || field.value.indexOf("/") != -1 || field.value.indexOf("\\") != -1) {
    if (field.name == "repository_name")
      alert("Repository name had unsupported symbols...");
    if (field.name == "folder_name")
      alert("Folder name had unsupported symbols...");
    if (field.name == "document_name")
      alert("Document name had unsupported symbols...");
    if (field.name == "attribute_name")
      alert("Attribute name had unsupported symbols...");
    if (field.name == "linktype_name")
      alert("Link type name had unsupported symbols...");
    field.focus();
    field.value = field.defaultValue;
    return (true);
  }
  return (false);
}


function checkField(field) {

  if (field.name == "repository_name" && field.value=="") {
    alert("Please, input repository name");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }

  if (field.name == "folder_name" && field.value=="") {
    alert("Please, input folder name");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }

  if (field.name == "folder_path" && field.value=="") {
    alert("Please, input folder path");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }


  if (field.name == "document_published" && field.value=="") {
    alert("Please, input published date");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }
  if (field.name == "document_name" && field.value=="") {
    alert("Please, input document name");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }
  if (field.name == "document_path" && field.value=="") {
    alert("Please, input document path");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }
  if (field.name == "document_template" && field.value=="") {
    alert("Please, input document template");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }

  if (field.name == "attribute_name" && field.value=="") {
    alert("Please, input attribute name");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }
  if (field.name == "attribute_path" && field.value=="") {
    alert("Please, input attribute path");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }

  if (field.name == "linktype_name" && field.value=="") {
    alert("Please, input link type name");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }
  if (field.name == "linktype_description" && field.value=="") {
    alert("Please, input link type description");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }

  if (field.name == "source_path" && field.value=="") {
    alert("Please, input source path");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }
  if (field.name == "destination_path" && field.value=="") {
    alert("Please, input destination path");
    field.focus();
    field.value = field.defaultValue;
    return (false);
  }
  if (field.name.indexOf("_name") != -1) {
    return hasUnsupportedSymbols(field);
  }
  return (true);
}


function checkForm(form) {
  
  var result = true;
  
  for (i=0;i<form.length;i++) {

    var field = form.elements[i];
    if (isEmpty(field)) {
	result = false;
	break;
    }
  
    if (field.name.indexOf("_name") != -1 && hasUnsupportedSymbols(field)) {
	result = false;
	break;
    }
  }
//  if (result)
//  form.submit();
  return (result);
//  return;
}


function confirm_delete(ref)
{
  if (confirm("Please, confirm delete"))
    window.location.href=ref;
}

function confirm_action(message,ref)
{
  if (confirm(unescape(message)))
    window.location.href=ref;
}

function openChooser(chooser,form,field) { 
  window.open(chooser+'/form='+form+'/field='+field,'chooser','resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,height=600,width=700');
}

function makeChoice(form,field,value) { 
  var code = 'window.opener.document.'+form+'.'+field+'.value="'+value+'"';
	eval(code);
	window.close();  
}

function smile () {
return;
}

function DoSmilie(addSmilie) {
	var revisedMessage;
	var currentMessage = document.forum.content.value;
	revisedMessage = currentMessage+" "+addSmilie+" ";
	document.forum.content.value=revisedMessage;
	document.forum.content.focus();
	return;
}
// -->

