
function prepareTabs(){
	var activeTab;

	if (location.hash.substring(1)) {
		activeTab = location.hash.substring(1);
	} else {
		activeTab = $('div.tabContent:first').attr('id');
	}
	$('.tab a').click(function(){
		showTab(this);
		return false;
	});

	//works only if there is an image map with id "worldmap"
	//for "distributors" page
	$('#worldmap area').click(function(){
		showTab(this);
		return false;
	});

	$('.tab a').each(function(i){
		if(this.hash.substring(1) == activeTab){
			showTab(this);
		}
	});
	$('.tabContent h2').attr('style', 'display:none;');
}

function showTab(el){
	if(!el.hash.substring(1)) return;

	//location.hash = el.hash;
	$('.tab').removeClass('active');
	$('.tab a').each(function(i){
		if (this.hash == el.hash) {
			$(this).parent().addClass('active');
		}
	});
	
	$('.tabContent').hide();
	$('#' + el.hash.substring(1)).show();
}

function checkForm(f){
	formErrors = false;

	if (f.topic_content && f.topic_content.value.length < 2) {
		formErrors = "Enter message";
		f.topic_content.focus();
	}

	if (f.post_content && f.post_content.value.length < 2) {
		formErrors = "Enter message";
		f.post_content.focus();
	}

	if (f.email && !f.email.value) {
		formErrors = "Enter email";
		f.email.focus();
	}

	if (f.topic_title && !f.topic_title.value) {
		formErrors = "Enter topic";
		f.topic_title.focus();
	}

	if (f.topic_username && !f.topic_username.value) {
		formErrors = "Enter your name";
		f.topic_username.focus();
	}

	if (f.post_username && !f.post_username.value) {
		formErrors = "Enter your name";
		f.post_username.focus();
	}

	if (formErrors){
		alert(formErrors);
		return false;
	}else{
		return true;
	}
}

function openApplet(url,name,w,h) {
	window.open(url, name, "scrollbars=no,left=20,top=20,width="+ w+ ",height="+ h);
	return false;
}

function displayTime() {
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	if (minutes < 10) minutes = "0" + minutes;
	var seconds = now.getSeconds();
	if (seconds < 10) seconds = "0" + seconds;

	return '<span class="hour">'+hours+'</span>:<span class="minutes">'+minutes+'</span>'+
	'<span class="sec">'+seconds+'</span>'+
	'<span class="date">'+now.getDate()+'/'+ (now.getMonth()+1)+'/'+now.getFullYear()+'</span>';
}

