//
//
//
function go_away_and_vote ( site_id, site_uri ) {
	$.post("/visit_ajax.html", { site_id: "" + site_id + "" },
		function(data){
			if( site_uri.indexOf("http://") == "0" ){
				location.href = site_uri;
			} else {
				location.href = 'http://'+site_uri;
			}
		}
	);

}

//
//
//
function ajax_vote ( site_id ) {
	$.post("/vote_ajax.html", { site_id: "" + site_id + "" },
		function(data){
			location.href='/';
		}
	);
}

//
// 
//
function isConfirm(sName, cName, sText) {
	if (sName.value == cName.value) {
		return true;
	} else {
		alert(sText);
		cName.focus();
		return false;
	}
}

//
// генерируем случайное число
//
function get_random () {
	var min_random = 0;
	var max_random = 10000;
	max_random++;
	var range = max_random - min_random;
	return Math.floor(Math.random()*range) + min_random;
}

//
// Проверяем формат e-mail
//
function check_email_format (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 dummy() { }

//
//
//
$(document).ready(function(){

	build_menu();
//	init_tabs();

});


//
//
//
function submit_form ( form_name ) {
	var is_correct = '1';
	$(".form_input_req,.form_input_req_").each(function (i) {
		if( $(this).attr("value") == "") {
			$(this).attr("className", "form_input_req_");
			$(this).focus();
			alert('Please check all required fields');
			is_correct = '0';
			return false;
		} else {
			$(this).attr("className", "form_input_req");
			if( $(this).attr("name") == "email" ){
				if( check_email_format ( $(this).attr("value") ) == false ) {
					$(this).attr("className", "form_input_req_");
					$(this).focus();
					alert('Please check e-mail format');
					is_correct = '0';
					return false;
				}
			}
		}
	});
	if( is_correct == "1" ) {
		$("#progress").css("display", "block");
		$("form#"+form_name+"").submit();
	}
}










//
//
//
function build_menu () {

	$("#menu ul li").each( function(i){

		$(this).mouseover( function(){
			if( $(this).attr("className") == "active" ){
				$(this).attr("className","hover_active");
			} else {
				$(this).attr("className","hover");
			}
		} );
		$(this).mouseout( function(){
			if( $(this).attr("className") == "hover_active" ){
				$(this).attr("className","active");
			} else {
				$(this).attr("className","");
			}
		} );

	} );

	$(".menu_link").each( function(i){ 
		$("#menu_title_" + eval(i + 1) ).mouseover(function(){
//			$("#submenu").show();
//			$(".submenu").hide();
			$("#menu_li_" + eval(i + 1) ).attr("className","menu_li_hover");
//			$("#submenu_"+ eval(i + 1)).fadeIn();
		});
		$("#menu_title_" + eval(i + 1) ).mouseout(function(){
			$("#menu_li_" + eval(i + 1) ).attr("className","menu_li");
		});
	} );

}

//
//
//
function init_tabs () {
	$(".tabs").each( function(){ 
		$( "#"+ $(this).attr("id") + "_headers li" ).mousedown(function(){ switch_tabs( $( this ).attr("id").replace("headers_","") ); });
		switch_tabs( $("#" + $(this).attr("id") + "_default").val() );
	} );
}

function init_tabs_ () {
	$(".tabs").each( function(){ 
		$( "#"+ $(this).attr("id") + "_headers li" ).mouseover(function(){
			if( $(this).attr("className") == "active" ){
				$( this ).attr("className","active");
			} else {
				$( this ).attr("className","hover");
			}
		});
		$( "#"+ $(this).attr("id") + "_headers li" ).mouseout(function(){
			if( $(this).attr("className") == "active"){
				$( this ).attr("className","active");
			} else {
				$( this ).attr("className","");
			}
		});
	} );
}

function switch_tabs ( active_tab_name, first_time ) {
	$(".tabs_content").css("display","none");
	$( "ul.tabs_headers li.active" ).attr("className","");
	$( "#" + active_tab_name.replace("_","_headers_") + "").attr("className","active");
	$( "#" + active_tab_name + "" ).css("display","block");
	init_tabs_();
}


