
$(document).ready( function(){

	//roll over function
	$(".roll-image").hover(
		function () {
			var img_orig = $(this).attr("src");
			var img_replace = img_orig.replace("_off.gif", "_on.gif");
			$(this).attr( "src", img_replace )
		},
		function () {
			var img_orig = $(this).attr("src");
			var img_replace = img_orig.replace("_on.gif", "_off.gif");
			$(this).attr( "src", img_replace )
		}
	);

	$(".nav_td_div").hover(
		function () {
			$(this).css('background-color', "#EDEF5C");
		},
		function () {
			$(this).css('background-color', "transparent");
		}
	);

	//Used to clear a form
	//eg $('#FormIdHere').clearForm();
	$.fn.clearForm = function() {
		this.each(function() {
			var type = this.type, tag = this.tagName.toLowerCase();

			if (tag == 'form')
				return $(':input',this).clearForm();
			if (type == 'text' || type == 'password' || tag == 'textarea')
				this.value = '';
			else if (type == 'checkbox' || type == 'radio')
				this.checked = false;
			else if (tag == 'select')
				this.selectedIndex = '';
		});
	};

	$("form input").keypress(function (e) {
		if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
			 $(this).parents('form').submit();
			return false;
		} else {
			return true;
		}
	});

//	$('#main_bubble_top').ifixpng();
//	$('#main_bubble_middle').ifixpng();
	$('#main_bubble_bottom').ifixpng();

});

function submitEnter(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13){
	   myfield.form.submit();
	   return false;
	}else{
	   return true;
	}
}

/*register functions */
function country_states(id, theform, the_element, prefix,clear){

	if(id == 840){
		toggleTable(prefix+'_el_1',1);
		toggleTable(prefix+'_el_2',0);
		toggleTable(prefix+'_el_3',0);

		toggleTable(prefix+'_el_not_man',0);
		toggleTable(prefix+'_el_man',1);

		theform.elements[prefix+"_state_province"][0].selected = true;
	}else if(id == 124){
		toggleTable(prefix+'_el_1',0);
		toggleTable(prefix+'_el_2',1);
		toggleTable(prefix+'_el_3',0);

		toggleTable(prefix+'_el_not_man',0);
		toggleTable(prefix+'_el_man',1);

		theform.elements[prefix+"_canada_province"][0].selected = true;
	}else{
		toggleTable(prefix+'_el_1',0);
		toggleTable(prefix+'_el_2',0);
		toggleTable(prefix+'_el_3',1);

		toggleTable(prefix+'_el_not_man',1);
		toggleTable(prefix+'_el_man',0);

		if(clear)
		theform.elements[the_element].value = "";
	}
}

function toggleTable(id,state) {
	if(state == 1){
		$("#"+id).show();
	}else if(state == 0){
		$("#"+id).hide();
	}else{
		$("#"+id).toggle();
	}
}

function show_hide_toggle(state, id){

	var tmp = $('#blog_comment_count-'+id).html();

	var count = tmp*1;

	if(count > 0){
		if(state == 1){
			$('#show_comment-'+id).hide();
			$('#hide_comment-'+id).show();
		}else{
			$('#show_comment-'+id).show();
			$('#hide_comment-'+id).hide();
			$('#blog_comment-'+id).html(' ');
		}
	}
}

function get_comments(id,target){

	$.get("/ajax_blog_comment/?id="+id, {  },
		function(data){
	  		$("#"+target).html(data);
	});
}

function post_mailing_list(){

	var parametri1 = $("input").serialize();

	//$("#AJ_mailing_list").html("Loading...");

	$.post("/ajax_mailing_list/?"+parametri1, {},
	  function(data){
	    	$("#AJ_mailing_list").html(data);
	  }
	);
}

function set_state(theform,str,the_element){
	theform.elements[the_element].value = str;
}

function submitForm(theform, theaction){
	theform.action = theaction;
	theform.submit();
}