// search submit checkers
var search_default = "Enter keywords"; 

function check_search()
{
	if(document.form_search.keywords.value == search_default)
	{ document.form_search.keywords.value = ""; }
}

function check_search2()
{
	if(document.form_search.keywords.value == "")
	{ document.form_search.keywords.value = search_default; }
}

function search()
{
	if(document.form_search.keywords.value == "" || document.form_search.keywords.value == search_default)
	{ 
	document.form_search.keywords.value = search_default; 
	return false; 
	}
	else
	{ 
	document.form_search.submit(); 
	return true; 
	}
}

function reveal_filter()
{
	check_search(); 
	document.getElementById('div_filter').style.display = 'block'; 
}

function hide_filter()
{
	check_search2(); 
	document.getElementById('div_filter').style.display = 'none'; 
}


// focus checkers
function check_focus_1()
{
	if(document.form_login.form_email.value != "")
	{ document.form_login.form_password.focus(); }
	else
	{ document.form_login.form_email.focus(); }
}

function check_focus_2()
{
	document.form_comment.form_comment.focus(); 
}

function check_focus_3()
{
	document.form_reset.form_email2.focus(); 
}


// registration form submit checker
function check_form_terms()
{ 
	if(document.form_register.form_agree.checked == true)
	{ 
	document.form_register.submit(); document.form_register.submitButton.disabled = true; 
	return true; 
	}
	else
	{ 
	alert("You must agree to our Terms of Use in order to complete registration."); 
	return false; 
	}
}


// got u refresh
var gotu_count = 0; 
function refresh_gotu()
{ 
document.getElementById('div_gotu').innerHTML = '<img src=\"gotu/generate.php?mode=refresh&count='+gotu_count+'\" width=\"200\" height=\"50\" border=\"0\" alt=\"\"><br>'; 
gotu_count++; 
}


// toggle function
function toggle(id)
{
	if (document.layers)
	{
		current = (document.layers[id].display == 'none') ? 'block' : 'none';
		document.layers[id].display = current;
	}
	else if (document.all)
	{
		current = (document.all[id].style.display == 'none') ? 'block' : 'none';
		document.all[id].style.display = current;
	}
	else if (document.getElementById)
	{
		vista = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
		document.getElementById(id).style.display = vista;
	}
}


// window popper
function pop_window(url,width,height)
{ thewindow = window.open(url,'TheShiznitPopOut','width='+width+',height='+height+',toolbars=no,scrollbars=yes,copyhistory=yes,status=no'); }


// image fader functions
var image_count = 0; 
var image_alpha = 0; 
var direction = "up"; 
var init; 
function run_images()
{ init = setTimeout("load_image(); run_images()", 25); }

function load_image()
{
var object = document.getElementById(image_array[image_count]).style; 
object.display = "block"; 
object.opacity = (image_alpha / 100); 
object.MozOpacity = (image_alpha / 100); 
object.filter = "alpha(opacity=" + image_alpha + ")"; 

	if(direction == "down")
	{ 
	image_alpha = image_alpha - 2; 
	if(image_alpha < -10) { next_image(); }
	}
	else
	{ 
	image_alpha = image_alpha + 2; 
	if(image_alpha > 200) { prev_image(); }
	}

}

function prev_image()
{
	if(image_array.length <= 1)
	{ clearTimeout(init); }
	else
	{ direction = "down"; }	
}

function next_image()
{ 
var object = document.getElementById(image_array[image_count]).style; 
object.display = "none"; 
object.opacity = 0; 
object.MozOpacity = 0; 
object.filter = "alpha(opacity=0)"; 
image_count = image_count + 1; 
if(image_count == image_array.length) { image_count = 0; }
direction = "up"; 
}

function initial()
{ run_images(); }


// ticker functions
var last_li = 0; 
var gap = 20; 
var width = 0; 
var pause = 0; 

function move_lis()
{ 
var lis = document.getElementById('featured_items').getElementsByTagName('li');

	if(pause == 0)
	{

		for(i=0; i< lis.length; i++) 
		{ 
		lis[i].style.marginLeft = (parseInt(lis[i].style.marginLeft) - 1)+"px"; 

			if(parseInt(lis[i].style.marginLeft) < -lis[i].offsetWidth)
			{
			lis[i].style.marginLeft = (parseInt(lis[last_li].style.marginLeft) + lis[last_li].offsetWidth + gap)+"px"; 
			last_li = i; 
			}

		}

	}

}

var newstimer; 
function run_timer()
{ newstimer = setTimeout("move_lis();run_timer()",15); }

function init_newsbox()
{
var lis = document.getElementById('featured_items').getElementsByTagName('li');

	for(i=0; i< lis.length; i++) 
	{ 
	lis[i].style.width = lis[i].offsetWidth+"px"; 
	lis[i].style.marginLeft = width+"px"; 
	width += (lis[i].offsetWidth + gap); 
	lis[i].onmouseover = function () { pause = 1; }
	lis[i].onmouseout = function () { pause = 0; }
	last_li = i; 
	}

setTimeout("run_timer()",1000); 

}


// innerHTML functions
var contenttorestore = ""; 
function set_content(id,content)
{ 
contenttorestore = document.getElementById(id).innerHTML; 
document.getElementById(id).innerHTML = content; 
}

function restore_content(id)
{ 
document.getElementById(id).innerHTML = contenttorestore; 
}


// content loader functions
function toggle_contentmenu(id)
{
var now = new Date().getTime() / 1000; 
var s = parseInt(now, 10); 
ajaxpage('update_recentcontent.php?content_id='+id+'&rand='+s,'dyn_contentmenu');
}


// ratingbox loader functions
function load_ratingbox(id)
{
var now = new Date().getTime() / 1000; 
var s = parseInt(now, 10); 
ajaxpage('update_ratingbox.php?review_id='+id+'&rand='+s,'dyn_ratingbox');
}

function display_rating(rating)
{ 
	document.getElementById('userrating').style.backgroundImage = "url(images/ratingstars_"+rating+".gif)"; 
}

function submit_rating(id,rating)
{
var now = new Date().getTime() / 1000; 
var s = parseInt(now, 10); 
ajaxpage('update_ratingbox.php?review_id='+id+'&rating='+rating+'&action=submit&rand='+s,'dyn_ratingbox');
}