/* Parses the querystring to find identifying vars for use in applying custom styles */
/*
	Querystring var is tsrc (template source)
	tsrc can take any four-digit numerical value
*/

function init()
{
	var qs 		= new Querystring();
	var t  		= qs.get("tsrc");							// get var if it exists
	var note 	= document.getElementById('special-note');	// grab ID for paragraph
	var tbody	= document.getElementById('tbody');			// grab ID for body
	var tform	= document.getElementsByTagName('form')[0];		// grab ID for form
	
	if (t === undefined || t === null)
	{
		note.innerHTML = '';
	}
	else
	{
		note.innerHTML = "You are logging in to the master database for<br>Properties For Horses and its<br>Affiliate Member Web Sites";
		var theader	= document.createElement('h1');							// the h1 element
		theader.style.textAlign = "center";
		switch (t)
		{
			case '1000':
				tbody.style.background = "#466 url('media/body_1000.png') no-repeat center center";
				var h_text	= document.createTextNode('Horse-Properties.info');		// h1 element text node
				break;
			case '1001':
				tbody.style.backgroundColor = "#D89167";
				tbody.style.backgroundImage = "none";
				var h_text	= document.createTextNode('Horse-Real-Estate.com');		// h1 element text node
				break;
			case '1002':
				tbody.style.backgroundColor = "#321";
				tbody.style.backgroundImage = "none";
				theader.style.color			= "#FFF";
				var h_text	= document.createTextNode('1EquestrianProperties.com');		// h1 element text node
				break;
			default:
				tbody.style.backgroundColor = "#F5F5F5";
				var h_text	= document.createTextNode('Properties For Horses');		// h1 element text node
				break;	
		}
		theader.appendChild(h_text);										// add text to h1 element
		document.body.insertBefore(theader,document.body.firstChild);		// append h1 to body before other content
	}
}

function add_onload(myfunc)		// allows multiple onload events to be loaded and used
{
	if(window.addEventListener)
		window.addEventListener('load', myfunc, false);
	else if(window.attachEvent)
		window.attachEvent('onload', myfunc);
}


function Querystring(qs) 
{ // optionally pass a querystring to parse
	this.params = {};
	this.get=Querystring_get;
	
	if (qs == null);
		qs=location.search.substring(1,location.search.length);

	if (qs.length == 0) 
		return;

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ');
	var args = qs.split('&'); // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var pair = args[i].split('=');
		var name = unescape(pair[0]);
		
		var value = (pair.length==2)
			? unescape(pair[1])
			: name;
		
		this.params[name] = value;
	}
}

function Querystring_get(key, default_) 
{
	var value=this.params[key];
	return (value!=null) ? value : default_;
}

add_onload(init);				// add init function to onload queue of events
