function checkmail(value) {
	reg = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
	if (!value.match(reg)) {
		return false; 
	}
	else{
		return true;
	}
}

function goURL(url){
	window.location = url;
}

function showE(domain,location,user){
	var address = user + "@" + domain + "." + location;
	document.write("<a href='mailto:"+address+"'>"+address+"</a>");
}

function win_open(url,win_name,features) {
	window.open(url,win_name,features);
}

function showSubMenu(id){
	if (id>0){
		var sub_id = "sub_"+id;
		document.getElementById (sub_id).style.display = "block";
	}
}
function hideSubMenu(id){
	if (id>0){
		var sub_id = "sub_"+id;
		document.getElementById (sub_id).style.display = "none";
	}
}

$(document).ready(function(){
	
	function showErrInput(id){
		var el = "#" + id;
		$(el).animate({backgroundColor:"#faffbd",}, 200 );
		$(el).animate({backgroundColor:"#fff",}, 200 );
		$(el).animate({backgroundColor:"#faffbd",}, 500 );
	}	
	
	$("#kcaptchaRefresh").click(function(){
		var kcaptchaCode = $("#kcaptchaImage img");
		var kSrc = ($(kcaptchaCode).attr("src"));
		
		$(kcaptchaCode).attr("src", "/img/kcaptcha_load.gif");
		
		$(kcaptchaCode).oneTime("1s", function() {
			$(this).attr("src", kSrc+'?'+Math.random());
		});
	});
	

	$("form#feedbackForm #send").click(function(){
		//
		// get form fields value
		//
		var name = $("input#name").val();
		var org = $("input#org").val();
		var phone = $("input#phone").val();
		var email = $("input#email").val();
		var message = $("textarea#message").val();
		var code = $("input#code").val();
		
		//
		// check value
		//
		//if (name == ""){$("input#name").addClass("error");}else{$("input#name").removeClass("error");}
		if (name == ""){
			showErrInput("name");
		}
		
		if (email == ""){
			showErrInput("email");
		}
		else{
			if (checkmail(email) == false){
				showErrInput("email");
			}
		}
		if (message == ""){
			showErrInput("message");
		}
		
		if (code == ""){
			showErrInput("code");
		}
		
		
		if (name != "" &&  phone != "" && email != "" && (checkmail(email) != false) && message != "" && code != ""){
			$("form#feedbackForm").submit();
		}else{
			//alert("Необходимо заполнить поля!");
		}
		
		
	});
	
	/*$("#mainContent h1").each(function(){
		$(this).wrap("<span class='h1'></span>");
	});*/
});
