var global_registerform_init = false;
sws_global = {};

// dummy body load function
	function bodyLoad() {
		var thisTitle = document.title;
	}


// JavaScript Document
	function getElement(id) {
		if(document.all && !document.getElementById) {
			return document.all[id];
		} else {
			return document.getElementById(id);
		}
	}


// xajax drop-down code
	function showDetail(thisId,thisPlid,thisSeason) {
		thisDiv		= getElement("detail_"+thisId);
		thisTog 	= getElement("tog_"+thisId);
		
		if(thisDiv.style.display=="none") {
			thisDiv.style.display="";
			thisTog.innerText="-";
			xajax_writeDetailCell(thisId,thisPlid,thisSeason);
		} else {
			thisDiv.style.display="none";
			thisTog.innerText="+";
		}
	}
	
	function toggleDivVis(thisId) {
		thisDiv		= getElement("detail_"+thisId);
		thisTog 	= getElement("tog_"+thisId);
		
		if(thisDiv.style.display=="none") {
			thisDiv.style.display="table-row";
			thisTog.innerText="-";
		} else {
			thisDiv.style.display="none";
			thisTog.innerText="+";
		}
	}
// end xajax drop-down code

function loadScript(script_src,test_func){
	var head;
	var script;
	var loaded_scripts;
	var load_new = false;
	
	head = $$('head')[0];

	var s = head.select('[src="' + script_src + '"]');
	if(s.length == 0){
        script = new Element('script', { type: 'text/javascript', src: script_src });
        head.appendChild(script);
		
		if(test_func){ //if provided, wait until test_function is available
			    new PeriodicalExecuter(function(pe) {
					if (typeof window[test_func] != "undefined")
					{
						pe.stop();
					}
				}, 0.25);
		}
		
	}
	return true;
}

function loadCSS(css_src,test_str){
	var head;
	var css;
	var loaded_scripts;
	var load_new = false;
	
	head = $$('head')[0];

	var s = head.select('link');
	for(x =0; x < s.length; x++){
		var str = s[x].href;
		if( str.indexOf(test_str) > 0){
			load_new = true;
		}
	}
	
	if(! load_new){
        css = new Element('link', { type: 'text/css', rel: 'stylesheet', href: css_src });
        head.appendChild(css);
		
		if(test_str){ //if provided, wait until test_function is available
			    new PeriodicalExecuter(function(pe) {
						for(x =0; x < s.length; x++){
							var str = s[x].href;
							if( str.indexOf(test_str) > 0){
								pe.stop();
							}
						}
				}, 0.25);
		}

	}
	return true;
}


function dynamic_RegistrationLoad(){
	if(! global_registerform_init) {
		loadScript('/shared/js/modalbox/modalbox.js','Modalbox');
		loadCSS('/shared/js/modalbox/modalbox.css','modalbox.css');
		loadScript('/shared/js/sws/registration.js');
		global_registerform_init = true;
	} else {
		 dynamic_RegistrationCallback();
	}
}

function dynamic_RegistrationCallback(){
	Modalbox.show('/shared/html/register_form2.html', {title: 'StatewideStats.com User Register Form', width: 600}); return false;
}

function sws_fetchSettings(){
	new Ajax.Request('/api/settings.php', {
	  onSuccess: function(transport) {
		  sws_global['settings'] = transport.headerJSON;
		return transport.headerJSON;
	  }
	});
}

function sws_settings(){
	sws_fetchSettings();
	return sws_global['settings'];
}
