$(document).ready(function () {

	// Site main menu
	$("#mainmenu li").hoverIntent(
		function() {
			$(".sub", this).fadeIn('fast');
		}, function() {
			$(".sub", this).fadeOut("fast");
		}
	);

	/**************************************************************************/

	// Forum Topics Open Close (Close button)
	$("#forum .close").click(function () {
		$(this).parent().parent().css('display', 'none');
	});

	// Forum Topics Open Close (Open button)
	function ocTopics(id) {
		$('#' + id).css('display');

		return false;
	}

	/**************************************************************************/

	// Search field value change
	$('#search_box .field').focus(function () {

		if($(this).attr('value') == 'מה ברצונך למצוא?') {
			$(this).attr('value', '');
		}

	});

	$('#search_box .field').blur(function () {

		if($(this).attr('value') == '') {
			$(this).attr('value', 'מה ברצונך למצוא?');
		}

	});

	/**************************************************************************/

	$('#addcomment').click(function () {
		$('#addcommentform').show('slow');
	});
	
	$('.commOptions_AddComm').click(function () {
		$('#addcommentform').show('slow');
	});
	
	$('.commOptions_Hide').click(function () {
		var clickedItem = $(this).attr("id");
		var regex_num = clickedItem.match(/[\d\.]+/g);
		var hideDiv = '#comm_' + regex_num[0];
		$(hideDiv).hide('slow');
		$('#addcommentform').hide('slow');
	});
		
	$('#invalid_captcha').click(function () {
		$('#addcommentform').show('slow');
		$('#comm_message').remove();
	});

	$('.close').click(function () {
		$('#addcommentform').hide();
	});
	
	$('.author').click(function () {
		var clickedItem = $(this).attr("id");
		var showDIV = '#comm_' + clickedItem;
		$(showDIV).show('slow');	
	});
	
	/**************************************************************************/
	
	//IE 6,7 footer of forum fix/////////////////////////////////////////////////////
	var browser = navigator.appName;
	var version = navigator.appVersion;
	var page = document.location.href;
	
	if(browser.indexOf("Microsoft Internet Explorer") != -1 && (version.indexOf("MSIE 6.0") != -1 || version.indexOf("MSIE 7.0") != -1)){		
		
		var rightSideHeight = $("#rightside").height();
		$("#leftside").css("min-height", rightSideHeight);
		//$("#leftside").height(rightSideHeight);
	}
	
	/**************************************************************************/

});

//Function to validate an mail address
function ValidateMail(){
	var mail = document.getElementById('emailComm').value;
	var mail_reg = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		
	if(!mail.match(mail_reg) && mail != ''){
		alert('אנא הכנס כתובת דואר אלקטרוני תקינה');
		return false;
	}	
	return true;
}

//Function to validate a comment form
function ValidateCommentForm(){
	var mail = document.getElementById('emailComm').value;
	var name = document.getElementById('nameComm').value;
	var theme = document.getElementById('themeComm').value;
	var message = document.getElementById('messageComm').value;
	
	var mail_reg = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		
	if(!mail.match(mail_reg) || mail == ''){
		alert('!אנא הכנס כתובת דואר אלקטרוני תקינה');
		return false;
	}
	
	if(name == ''){
		alert('!אנא הכנס שם פרטי');
		return false;
	}
	
	if(theme == ''){
		alert('!אנא הכנס נושא התגובה');
		return false;
	}
	
	if(message == ''){
		alert('!אנא כנס תוכן התגובה');
		return false;
	}
	
	return true;
}

//Function to check input of bug report
function CheckInput(){
	var hiddenValue = document.getElementById('url').value;
	var mailValue = document.getElementById('email_reporter').value;
	var descriptionValue = document.getElementById('description').value;
	var mail_reg = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
	if(hiddenValue != ""){
		return false;
	}
	
	if(descriptionValue == ""){
		alert('אנא הכנס את תאור התקלה');
		return false;
	}
	
	if(mailValue == ""){
		alert('אנא הכנס כתובת דואר אלקטרוני');
		return false;
	}
	
	if(mailValue != ""){
		if(!mailValue.match(mail_reg)){
			alert('אנא הכנס כתובת דואר אלקטרוני תקינה');
			return false;
		}			
	}
		
	return true;
}
