// BSUC JavaScript File

// Status Bar Message and Check From Colour Cookie

function Flash() {

	checkbg();

	var message="The Micheal Tippett Centre";
	window.status=message;

}









// Search Form Checker

function NoError(theForm)
{
  if (searchform.search.value == "")
  {
    alert("You must type something in.");
    searchform.search.focus();
    return (false);
  }
  if (searchform.search.value.length < 3)
  {
    alert("You must type something longer than 3 characters.");
    searchform.search.focus();
    return (false);
  }
  checkForProfanity(0)  
  checkForURL(0)	

  return (true);
}









// Cookie For Background Colour

var x;
var tob=0;

var d=new Date();
d.setTime(d.getTime()+(1000*60*60*24*30));
var thecookie;
var fgcookie;

function checkbg()
{
if(document.cookie.indexOf("bgcolor")!=-1)
	{
	thecookie=document.cookie;
	var cut=thecookie.indexOf("bgcolor=");
	var color=thecookie.substring(cut+8,cut+15);
	document.bgColor=color;
	}
}

function create(x)
{
createbg(x)
}

function createbg(x)
{
if(document.cookie.indexOf("bgcolor")==-1 && tob==0)
	{
	document.cookie="bgcolor="+x+";expires="+d.toGMTString();
	document.bgColor=x;
	}
else if(tob==0)
	{
	document.cookie="bgcolor="+x+";expires="+d.toGMTString();
	thecookie=document.cookie;
	document.bgColor=x;
	}
}








// Sidebar:
// The following handles requests from user to install an IGF sidebar tab (Netscape and Mozilla at present ...)				
// NB: using anything other than a full path for the web page results in a sulk
					
function sidebar_bsuc()

{ if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function"))
{ window.sidebar.addPanel ("BSUC","http://www.bathspa.ac.uk/sidebar/sb.asp",""); } 
}







// Profanity checker:
// variable k is the number of words to check for from the list below:

var k = 50;
var isProfane = new makeArray(k);
var word = new makeArray(k);

function checkForProfanity(elnum) {

var temp = document.searchform.search.value;
temp = temp.toLowerCase();

// List of words to screen for - ie swear words/slurs and HTML code:

word[1] = "shit";
word[2] = "fuck";
word[3] = "asshole";
word[4] = "crap";
word[5] = "cunt";
word[6] = "suck";
word[7] = "pussy";
word[8] = "cock";
word[9] = "cum";
word[10] = "penis";
word[11] = "dick";
word[12] = "fag";
word[13] = "idiot";
word[14] = "slut";
word[15] = "bitch";
word[16] = "gimp";
word[17] = "piss";
word[18] = "clit";
word[19] = "nigger";
word[20] = "blacky";
word[21] = "slitty";
word[22] = "wank";
word[23] = "negro";
word[24] = "xxxx";
word[25] = "xxxx";
word[26] = "xxxx";
word[27] = "xxxx";
word[28] = "xxxx";
word[29] = "<";
word[30] = "xxxx";
word[31] = "xxxx";
word[32] = "xxxx:";
word[33] = "arse";
word[34] = "fcuk";
word[35] = "about:";
word[36] = "sh*t";
word[37] = "s**t";
word[38] = "s*it";
word[39] = "s***";
word[40] = "fu*k";
word[41] = "f**k";
word[42] = "f*ck";
word[43] = "f***";
word[44] = "cu*t";
word[45] = "c**t";
word[46] = "c*nt";
word[47] = "c***";
word[48] = "co*k";
word[49] = "c**k";
word[50] = "c*ck";

// HTML terms are added to the list of ilegal words to stop people posting
// images, hyperlinks, applets, objects or malicious scripts. Please note
// that the word "script" cannot be added to the list as it causes loading
// errors, so "scrip" is used in its place... and will allow "script" to
// be detected!

// Checker:

for (var j = 1; j <= k; j++) {
isProfane[j] = temp.indexOf(word[j]);
}


for (var j = 1; j <= k; j++) {
   if (isProfane[j] != -1) {
      alert("Please refrain from entering swear words or bad language!");
      document.searchform.search.value = "";
      j = k + 1;
      document.searchform.search.focus();
       }
   else {}
}
}

function makeArray(n) {
   this.length = n
   for (var i = 1; i<=n; i++) {
       this[i] = new String();
   }
   return this
}








// URL checker:

// variable v is the number of words to check for from the list below:

var v = 4;
var isProfane = new makeArray(v);
var word = new makeArray(v);

function checkForURL(elnum) {

var temp = document.searchform.search.value;
temp = temp.toLowerCase();

// List of words to screen for - ie URLs:

word[1] = "www";
word[2] = "http";
word[3] = "ftp";
word[4] = "gopher";



// Checker:

for (var j = 1; j <= v; j++) {
isProfane[j] = temp.indexOf(word[j]);
}


for (var j = 1; j <= v; j++) {
   if (isProfane[j] != -1) {
      alert("URLs should be entered into the Location/Address bar of the browser, and not this search box!");
      document.searchform.search.value = "";
      j = v + 1;
      document.searchform.search.focus();
       }
   else {}
}
}

function makeArray(n) {
   this.length = n
   for (var i = 1; i<=n; i++) {
       this[i] = new String();
   }
   return this
}
