// JavaScript Document

function searchbox_in(){
	var val = $('search').value;
	if (val == "Basic Search"){
		$('search').style.color = "#000000";
		$('search').value = "";
	}
}

function searchbox_out(){
	var val = $('search').value;
	
	if (val == ""){
		$('search').style.color = "#999999";
		$('search').value = "Search";
	}
}

function mpsearchbox_in(){
	var val = $('q').value;
	if (val == "Search Marketplace"){
		$('q').style.color = "#000000";
		$('q').value = "";
	}
}

function mpsearchbox_out(){
	var val = $('q').value;
	
	if (val == ""){
		$('q').style.color = "#999999";
		$('q').value = "Search Marketplace";
	}
}


function section_nav(tooday, loc){
	rel_path = relPath(loc);
	$('dropdown').innerHTML = '';
	var pars = 'today=' + tooday;
	new Ajax.Updater('dropdown', rel_path + 'functions/php/sections.php', {asynchronous:true, method:'post', parameters:pars});
	$('dropdown').style.display = "block";
}

function freelink_nav(loc){
	rel_path = relPath(loc);
	$('dropdown').innerHTML = '';
	new Ajax.Updater('dropdown',  rel_path + 'functions/php/freelinks.php', {asynchronous:true});
	$('dropdown').style.display = "block";
}

function rotateMC(){
	var pars = "secnum=" + secnum;
	//alert(pars);
	new Ajax.Updater('mcstory', 'functions/newPHP/mainconent.php', {asynchronous:true, parameters:pars, method:'post', evalScripts:true});
}

function relPath(depth){
	var path = "";
	for (i = 1; i <= depth; i++){
		path = path + "../";
	}
	return path;
}

function clickAD(id, type, loc){
	var rel_path = relPath(loc);
	var pars = "id=" + id + "&table=" + type;
	new Ajax.Request(rel_path + 'functions/php/clickcounter.php', {asynchronous:true, method:'post', parameters:pars, onComplete:handle_responce});
}

function handle_responce(request){
	responce = request.responseText;
	$('errwin').innerHTML = "";
	$('errwin').innerHTML = responce;
	
}

function display_full(fullpath, relpath, container, option){
		var pars = 'fullpath=' + fullpath + '&relpath=' + relpath + '&option=' + option;
	new Ajax.Updater(container, '../functions/full.php',{asynchronous:true, method:'get', parameters:pars, evalScripts:true});
	$(container).style.display = "block";	
}

function show_hide(divid){
	var state = $(divid).style.display;
	
	if(state == "none"){
		$(divid).style.display = "block";
	}
	else{
		$(divid).style.display = "none";
	}
		
}

function scroll_mess_up(pos, flag){
	pos = pos - 10;

	$('message').style.marginTop = pos + "px"; 
	
	if (pos == -10){	
		cl = setTimeout("scroll_mess_up(" + pos +", " + flag + ")", 6000);
	}
	else if (pos <= -100){
		start_newMessage(flag, "up");
	}
	else{
		cl = setTimeout("scroll_mess_up(" + pos +", " + flag + ")", 100);
	}


}

function scroll_mess_up_fin(pos, flag){
	//alert(pos);
	pos = pos - 10;

	$('message').style.marginTop = pos + "px"; 
	
	if (pos <= -100){
		//alert("new")
		start_newMessage(flag, "up");
	}
	else{
		cl = setTimeout("scroll_mess_up(" + pos +", " + flag + ")", 100);
	}


}

function scroll_mess_down(pos, flag){
	pos = pos + 10;
	//$('errwin').innerHTML = pos;

	$('message').style.marginTop = pos + "px"; 
	
	if (pos == -10){	
		pos = pos + 11;
		cl = setTimeout("scroll_mess_up(" + pos +", " + flag + ")", 6000);
	}
	else if (pos >= 100){
		start_newMessage(flag, "up");
	}
	else{
		cl = setTimeout("scroll_mess_down(" + pos +", " + flag + ")", 100);
	}


}

function scroll_mess_down_fin(pos, flag){
	//alert(pos);
	pos = pos + 10;
	//$('errwin').innerHTML = pos;

	$('message').style.marginTop = pos + "px"; 
	
	 if (pos >= 100){
		start_newMessage(flag, "down");
	}
	else{
		cl = setTimeout("scroll_mess_down_fin(" + pos +", " + flag + ")", 100);
	}


}

function startup(divid){
	fgrow(divid);
}

