/* tab info - editTopic form */
function reloadTopicForm(form) {
	if (form.page.value == "editTopic") {
		form.action = form.action + "/" + form.topicid.value + "/"
				+ "edit.html";
	} else {
		form.action = form.action + "/" + form.topicid.value + "/" + "add.html";
	}
	form.submit();
	return true;
}

/* tab photos */
function check_email(email) {
	return email.match(/^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) != null;
}

function openPhoto(src, height, width, id) {
	var out = window
			.open(
					'',
					'Window',
					'left=40,top=40,width='
							+ width
							+ ',height='
							+ height
							+ ',innerheight='
							+ height
							+ ',innerwidth='
							+ width
							+ ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
	out.document.write('<html><head>');
	out.document
			.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
	out.document.write('<title></title>');
	out.document.write('</head>');
	out.document
			.write('<body bgcolor="white" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">');
	out.document
			.write('<div style="float: left"><a href="#" onclick="javascript:self.close();"><img src="' + src + '" border="0" title="Click here to close window" alt="image"/></a></div>');
	out.document.write('</body></html>');
	out.document.close();
	out.focus();
}

function checkPhotoForm(form) {
	if (form.firstname.value == "") {
		alert("Please enter your first name!")
		return false
	}
	if (!(check_email(form.email.value))) {
		alert('Incorrect email address');
		return false;
	}
	if (form.status.value == "Status") {
		alert("Choose your status");
		return false
	}
	if (form.pic_month.value == "-1") {
		alert("Choose month of the picture");
		return false
	}
	if (form.pic_year.value.match(/^\d{4}$/) == null) {
		alert("Enter the year of the picture");
		return false
	}
	year = parseInt(form.pic_year.value);
	d = new Date();
	if (year < 1910 || year > d.getFullYear()) {
		alert("Enter the correct year of the picture");
		return false
	}
	if (form.description.value == "") {
		alert("Enter the description");
		return false
	}
	if (form.pic.value.match(/\.(jpe?g|png|bmp|gif|tif?f)$/i) == null) {
		alert("Select a valid image file");
		return false
	}
	return true;
}

/* review Rate */

function checkReviewForm(form) {
	if (form.firstname.value == "") {
		alert("Please enter your first name!")
		return false
	}
	if (!(check_email(form.email.value))) {
		alert('Incorrect email address');
		return false;
	}
	if (form.status.value == "Status") {
		alert("Choose your status");
		return false;
	}
	if (form.review.value == "") {
		alert("Please write a review");
		return false;
	}
	if (form.review.value.match(/(<a\s+.*?href|\[url|\[link)/i) != null) {
		alert("Content of review looks like spam");
		return false;
	}
	if (form.graduation_date.value == "-1"
			&& form.graduation_flag.checked == false
			&& form.status.value != "Teacher" && form.status.value != "Parent"
			&& form.status.value != "Student") {
		alert('Select graduation information');
		return false;
	}
	if (!form.terms.checked) {
		alert("You must agree with terms!")
		return false;
	}
	return true;
}

// TODO: fix ids
function hideme(value) {
	elem = document.getElementById('graduation');
	elem2 = document.getElementById('graduation_date');
	elem3 = document.getElementById('graduation_flag');
	if (value == "Teacher" || value == "Parent" || value == "Student") {
		elem.style.visibility = 'hidden';
		elem2.style.visibility = 'hidden';
		elem3.style.visibility = 'hidden';
	} else {
		elem.style.visibility = 'visible';
		elem2.style.visibility = 'visible';
		elem3.style.visibility = 'visible';
	}
	return true;
}

//TODO: fix ids
function hidemeDate(value) {
	elem = document.getElementById('graduation_date');
	elem2 = document.getElementById('graduation_flag');
	if (value != "-1") {
		elem2.style.visibility = 'hidden';
	} else {
		elem2.style.visibility = 'visible';
	}
}
