<!--//
function updaterecip(it) {
	if (it.checked == true) {
		document.mails.to.disabled = true; document.mails.to.value='Всички потребители';
	} else {
		document.mails.to.disabled = false; document.mails.to.value='';
	}
}
function viewbullein(id) {
	if ($('#bcnt'+id).is(':hidden')) {
		$('.inline_msg').slideUp('slow');
		$('#bcnt'+id).slideDown('slow');
		$.ajax({type: 'GET',
			url: 'get_bulletin.php',
			cache: false,
			data: "id="+id+"",
			success: function(msg) {
				$('#bcnt'+id).html(msg);
			}});
	} else {
		$('#bcnt'+id).slideUp('slow');
	}
	return false;
}
function readmsg(id, type, noread) {
	var addon;
	
	if (type == 'system') {
		addon = 's';
	} else {
		addon = '';
	}
	
	if (!noread) {
		$('#s'+addon+id).attr('src', 'tpl/images/env1.gif');
	}
	
	if ($('#msg'+addon+id).is(':hidden')) {
		$('.inline_msg').slideUp('slow');
		$('#msg'+addon+id).slideDown('slow');
		$.ajax({type: 'GET',
			url: 'viewmsg.php',
			cache: false,
			data: "msg="+id+"&type="+type+"",
			success: function(msg) {
				$('#msg'+addon+id).html(msg);
			}});
	} else {
		$('#msg'+addon+id).slideUp('slow');
	}
	return false;
}
function VerifyRegistration() {
	var valid = 1
	var wrong = ""
	var addcheck = 1
	addcheck = CheckUser(document.registration.username.value);
	if (addcheck == 0) return false;
	if (document.registration.username.value == "") {
		valid = 0
		wrong = wrong + "Потребителско име, "
	}
	if (document.registration.email.value == "") {
		valid = 0
		wrong = wrong + "e-mail, "
	}
	if (document.registration.firstname.value == "") {
		valid = 0
		wrong = wrong + "име, "
	}
	if (document.registration.lastname.value == "") {
		valid = 0
		wrong = wrong + "фамилия, "
	}
	if (document.registration.country.value == "") {
		valid = 0
		wrong = wrong + "държава, "
	}
	if (document.registration.town.value == "") {
		valid = 0
		wrong = wrong + "град, "
	}
	if (document.registration.fnumber.value == "") {
		valid = 0
		wrong = wrong + "Факултетен номер, "
	}
	addcheck = CheckPass(document.registration.password.value);
	if (addcheck == 0) return false; 
	addcheck = CheckPass(document.registration.password2.value);
	if (addcheck == 0) return false;
	addcheck = CheckNumber(document.registration.fnumber.value);
	if (addcheck == 0) return false;
	if (document.registration.stitle.value == "") {
		valid = 0
		wrong = wrong + "Научна степен, "
	}
	if (document.registration.subject.value == "") {
		valid = 0
		wrong = wrong + "дисциплина, "
	}
	if (document.registration.password.value=="") { 
		valid = 0
		wrong = wrong + "парола, "
	}
	if (document.registration.password2.value=="") {
		valid = 0
		wrong = wrong + "парола (2), "
	}
	if (document.registration.password.value!=document.registration.password2.value) {
		valid = 0;
		alert("Паролите не съвпадат");
		return false;
	} 
	if (document.registration.terms.checked==false) {
		alert("Моля прочетете условията за използване на информационната мрежа!");
		valid = 0;
		return false;
		halt() 
	}
// Here we decide whether to submit the form. 
	if (valid==1) {
		return true;	} else { alert("Следните полета са празни: " + wrong + " Моля попълнете ги.") }
	return false;
}
//*******************************************************************************************
function CheckPass (ThePass) {
	var valid = 1
	var GoodChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVQXYZabcdefghijklmnopqrstuvwxyz"
	var i = 0
	if (ThePass.length < 6 || ThePass.length > 28) {
		alert("Паролата трябва да бъде повече от 6 и по-малко от 28 символа!")
		valid = 0
		return valid;
	}
	for (i =0; i <= ThePass.length -1; i++) {
		if (GoodChars.indexOf(ThePass.charAt(i)) == -1) {
			alert("Паролата може да съдържа само цифри и големи и малки латински букви!")
			valid = 0
			return valid;
		} // End if statement
	} // End for loop
	return valid
}
//*******************************************************************************************
function CheckUser (TheUser) {
	var valid = 1
	var GoodChars = "0123456789abcdefghijklmnopqrstuvwxyz_."
	var i = 0
	for (i =0; i <= TheUser.length -1; i++) {
		if (GoodChars.indexOf(TheUser.charAt(i)) == -1) {
			alert("Потребилтелското име може да съдържа само цифри, малки латински букви с синволите _ и .!")
			valid = 0;
			return valid;
		} // End if statement
	} // End for loop
	return valid
}
//*******************************************************************************************
function CheckNumber(TheNumber) {
	var valid = 1
	var GoodChars = "0123456789"
	var i = 0
	if (TheNumber=="") {
		valid = 1;
		return valid;
	}
	for (i =0; i <= TheNumber.length -1; i++) {
		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
			alert("Полето с факултетния номер може да съдъжа само цифри!")
			valid = 0
			return valid;
		} // End if statement
	} // End for loop
	return valid
}

function show(which) {
    var check = document.getElementById(which)
    if (check.style.display=='none') {
    document.getElementById(which).style.display = '';
    }
      else { document.getElementById(which).style.display = 'none';
    }
}
function sub(which) {
	if (which=='rest') { document.getElementById('lect').style.display = 'none'; 
						 document.getElementById('rest').style.display = '' ;
						 document.getElementById('lawtype').style.display = 'none';
						 document.uploader.subject2.value = ''; }
	if (which=='law') { document.getElementById('lect').style.display = 'none';
						document.getElementById('rest').style.display = '';
						document.getElementById('lawtype').style.display = '';
						document.getElementById('su').value = ''; }
	if (which=='lectinos') {document.getElementById('lect').style.display ='' ;
						document.getElementById('rest').style.display = 'none';
						document.getElementById('lawtype').style.display = 'none';
						document.getElementById('su').value = 'not';}
}
function state(which) {
    if (which=="1") {
    	  document.getElementById("fnumber").style.display = 'none'
    	  document.getElementById("clas").style.display = 'none'
    	  document.getElementById("title").style.display = ''
    	  document.getElementById("subject").style.display = ''
    	  document.registration.fnumber.value = '0'
    	  document.registration.stitle.value = ''
    	  document.registration.subject.value = ''
    	}
    if (which=="2") {
    	  document.getElementById("fnumber").style.display = ''
    	  document.getElementById("clas").style.display = ''
    	  document.getElementById("title").style.display = 'none'
    	  document.getElementById("subject").style.display = 'none'
    	  document.registration.stitle.value = 'not'
    	  document.registration.subject.value = 'not'
    	  document.registration.fnumber.value = ''
    	  document.registration.clas.value = ''
    	}
    if (which=="3") {
    	  document.getElementById("fnumber").style.display = 'none'
    	  document.getElementById("clas").style.display = 'none'
    	  document.getElementById("title").style.display = 'none'
    	  document.getElementById("subject").style.display = 'none'
    	  document.registration.stitle.value = 'not'
    	  document.registration.subject.value = 'not'
    	  document.registration.fnumber.value = '0'
      } 
}
function selall(name) {
	var check = true;
	formblock= document.doall;
	forminputs = formblock.getElementsByTagName('input');
	if (document.getElementById(name).checked == false) {
		check = false;
	}
	for (i = 0; i < forminputs.length; i++) {
		// regex here to check name attribute
		var regex = new RegExp(name, "i");
		if (regex.test(forminputs[i].getAttribute('name'))) {
			if (check == true) {
				forminputs[i].checked = true;
			} else {
				forminputs[i].checked = false;
			}
		}
	}
}

function ValidateImage() {
	if (document.uploader.image.value=='') { 
		alert("Моля изберете изображение") 
		halt()} 
  else {document.uploader.submit() }
}
//-->