// 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 = "Basic 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 = "section=" + secnum;
	//$('MainContent').innerHTML = pars;
	new Ajax.Updater('MainContent', 'functions/php/mainContent.php', {asnychronous:true, parameters:pars, method:'post'});

	if (secnum == 0){
		$('ts').style.color = "#4B89C4";
		$('local').style.color = "#9A2D2C";
		$('feat').style.color = "#9A2D2C";
		$('sports').style.color = "#9A2D2C";
		$('nat').style.color = "#9A2D2C";
		secnum = 1;
	}
	else if (secnum == 1){
		$('ts').style.color = "#9A2D2C";
		$('local').style.color = "#4B89C4";
		$('feat').style.color = "#9A2D2C";
		$('sports').style.color = "#9A2D2C";
		$('nat').style.color = "#9A2D2C";
		secnum = 2;		
	}
	else if (secnum == 2){
		$('ts').style.color = "#9A2D2C";
		$('local').style.color = "#9A2D2C";
		$('feat').style.color = "#4B89C4";
		$('sports').style.color = "#9A2D2C";
		$('nat').style.color = "#9A2D2C";
		secnum = 3;	
	}
	else if (secnum == 3){
		$('ts').style.color = "#9A2D2C";
		$('local').style.color = "#9A2D2C";
		$('feat').style.color = "#9A2D2C";
		$('sports').style.color = "#4B89C4";
		$('nat').style.color = "#9A2D2C";
		secnum = 4;	
	}
	else{
		$('ts').style.color = "#9A2D2C";
		$('local').style.color = "#9A2D2C";
		$('feat').style.color = "#9A2D2C";
		$('sports').style.color = "#9A2D2C";
		$('nat').style.color = "#4B89C4";
		secnum = 0;
	}
	
	
}

function MC(target){
	var pars = "section=" + target;
	//$('MainContent').innerHTML = pars;
	new Ajax.Updater('MainContent', 'functions/php/mainContent.php', {asnychronous:true, parameters:pars, method:'post'});
	if (target == 0){
		$('ts').style.color = "#4B89C4";
		$('local').style.color = "#9A2D2C";
		$('feat').style.color = "#9A2D2C";
		$('sports').style.color = "#9A2D2C";
		$('nat').style.color = "#9A2D2C";
	}
	else if (target == 1){
		$('ts').style.color = "#9A2D2C";
		$('local').style.color = "#4B89C4";
		$('feat').style.color = "#9A2D2C";
		$('sports').style.color = "#9A2D2C";
		$('nat').style.color = "#9A2D2C";
	}
	else if (target == 2){
		$('ts').style.color = "#9A2D2C";
		$('local').style.color = "#9A2D2C";
		$('feat').style.color = "#4B89C4";
		$('sports').style.color = "#9A2D2C";
		$('nat').style.color = "#9A2D2C";
	}
		else if (target == 3){
		$('ts').style.color = "#9A2D2C";
		$('local').style.color = "#9A2D2C";
		$('feat').style.color = "#9A2D2C";
		$('sports').style.color = "#4B89C4";
		$('nat').style.color = "#9A2D2C";
	}

	else{
		$('ts').style.color = "#9A2D2C";
		$('local').style.color = "#9A2D2C";
		$('feat').style.color = "#9A2D2C";
		$('sports').style.color = "#9A2D2C";
		$('nat').style.color = "#4B89C4";
	}

	secnum = target;	
}

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";
	}
		
}
