<!--
// JavaScript Document
/* <head>
<title>General javascript</title>
<meta name="content-type" content="text/javascript; charset=iso-8859-1" />
<meta name="author" content="thebrentc@gmail.com" />
<meta name="copyright" content="CC BY SA" />
<meta name="reply-to" content="thebrentc@gmail.com" />
<meta name="language" content="en-gb" />
<meta name="content-script-type" content="javascript" />
<meta name="description" content="Generic javascript" />
<meta name="keywords" content="" />
<meta name="dependencies" content="" />
</head> */

//window.onerror = null;

function checkBrowser()
{
//	alert(navigator.userAgent);
	return !crapBrowser();	
}

function crapBrowser()
{
	if (navigator.userAgent.indexOf("MSIE") > -1)	
	{
		if (navigator.userAgent.indexOf("MSIE 8") > -1)	return true;		
	}
	else
	{
		return false;
	}
}

function goodBrowser()
{
	if (navigator.userAgent.indexOf("Firefox/3") > -1 || navigator.userAgent.indexOf("MSIE 8") > -1 || navigator.userAgent.indexOf("Safari") > -1 || navigator.userAgent.indexOf("Opera") > -1) 
	{
		return true;		
	}
	else
	{
		return false;
	}
}


function changecss(theClass,element,value) 
{
	// thanks: http://www.shawnolson.net
	//Find more JavaScripts at http://www.shawnolson.net/topics/Javascript/	
	//Last Updated on June 23, 2009
	//documentation for this script at
	//http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
	var cssRules;
	var added = false;
	for (var S = 0; S < document.styleSheets.length; S++)
	{
		if (document.styleSheets[S]['rules']) 
		{
			cssRules = 'rules';
		} 
		else if (document.styleSheets[S]['cssRules']) 
		{
			cssRules = 'cssRules';
		} 
		else 
		{
			return; //no rules found... browser unknown
		}
	
		for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) 
		{
			if (document.styleSheets[S][cssRules][R].selectorText == theClass) 
			{
				if(document.styleSheets[S][cssRules][R].style[element])
				{
					document.styleSheets[S][cssRules][R].style[element] = value;
					added=true;
					break;
				}
			}
		}
		if(!added)
		{
			if(document.styleSheets[S].insertRule)
			{
				document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+';}',document.styleSheets[S][cssRules].length);
			}
			else if (document.styleSheets[S].addRule) 
			{
				document.styleSheets[S].addRule(theClass,element+': '+value+';');
			}
		}
	 }
}

function addCSS(css)
{
	var head = document.getElementsByTagName('head')[0];
	var stylesheet = document.createElement('style');
	stylesheet.innerHTML = css;
	head.appendChild(stylesheet);
	return stylesheet;
}

/*
document.onkeydown = function onkey(e)
{
	if (!e) e = window.event;
	alert (e['keyCode'] + e['shiftKey']);
}
*/

function addLoadEvent(func) 
{
// thanks http://simon.incutio.com/archive/2004/05/26/addLoadEvent
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function querystring_add(href /* href type string */ ,variable , value)
{
	if (href.indexOf("?") < 0)	return href +"?"+variable+"="+value;			
	if (href.indexOf(variable+"=") < 0) return href +"&"+variable+"="+value;				
	var location = href.substr(0,href.indexOf("?"));
	var	querystring = href.substr(href.indexOf("?")+1);	
	var pairs = querystring.split("&");
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			if (argname == variable)
			{		
				pairs[i] = argname + "=" + value;
			}
		}
	}
	href = location;
	for (var c = 0; c < pairs.length; c++)
	{
		if (c == 0) href += "?"; else href += "&"; 
		href += pairs[c];
	}
	return href;
}

function firstToUpperCase(string)
{
	string = string.substr(0,1).toUpperCase()+string.substr(1);
	return string;
}

function inArray(string,array)
{
	for (var i = 0; i < array.length; i++)
	{
		if (string == array[i]) return true;
	}
	// else
	return false;
}

var embed_id = null;
function embed(file,id)
{
// requires xmlhttprequest.js
	embed_id = id;
	// send 
	http.open('GET',file,true);
	http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');  
	http.setRequestHeader('Connection','close'); //STUPID 400 FF ERROR FIX  // not needed ? http://beta.twelvestone.com/forum_thread/view/25052 
	http.onreadystatechange = embed_response;  	
	http.send(null);		
}

function embed_response()
{
	if (http.readyState == 4) 
	{	
		if (http.status != 200 && window.location.href.indexOf("http")>-1) 
		{
			return;
		}
		// get response text
		var response = (http.ResponseText)?http.ResponseText:http.responseText;		
		response = unescape(response);
		document.getElementById(window.embed_id).innerHTML = response;		
	}
}

// -->