function init()
{
	doPreload()
	startHighlight()
}

function activatetri(n){
	tri = document.getElementById('tri' + n)
	if(tri)
	{
		if(tri.src == trioff.src) tri.src = trion.src
		else tri.src = trioff.src
	}
}

function activatearr(n){
	arr = document.getElementById('arr' + n)
	if(arr)
		if(arr.src == boff.src) arr.src = bon.src
		else arr.src = boff.src
}

function movedown(id)
{
	frm = document.getElementById('frmEditRule')
	frm.mode.value = "movedown"
	if(frm)
	{
		frm.toggleid.value = id
		frm.submit()
	}
}

function moveup(id)
{
	frm = document.getElementById('frmEditRule')
	frm.mode.value = "moveup"
	if(frm)
	{
		frm.toggleid.value = id
		frm.submit()
	}
}


function dotoggle(id)
{
	frm = document.getElementById('frmEditRule')
	frm.mode.value = "toggle"
	if(frm)
	{
		frm.toggleid.value = id
		frm.submit()
	}
}

function swapContainer(pid,cid)
{
	eval("location.href='EditContainer.asp?pid=" + pid + "&cid=" + cid + "'")
}

function pop(url,id,args)
{
    window.open(url,id,args)
}
function GetCopy()
{
	return '&copy; ' + GetYear()
}

function dohand(obj)
{
	obj.style.cursor = 'pointer'
}

function printindex()
{
	if(document.getElementById('lnkprint').innerHTML == 'Print this page')
	{
		document.getElementById('header').style.display = 'none'
		document.getElementById('nav').style.display = 'none'
		document.getElementById('tagline').style.display = 'none'
		document.getElementById('lnkprint').innerHTML = 'Back to normal view'
	}
	else
	{
		document.getElementById('header').style.display = 'block'
		document.getElementById('nav').style.display = 'block'
		document.getElementById('tagline').style.display = 'block'
		document.getElementById('lnkprint').innerHTML = 'Print this page'
	}
}


function printpage()
{
	if(document.getElementById('lnkprint').innerHTML == 'Print this page')
	{
		document.getElementById('header').style.display = 'none'
		document.getElementById('nav').style.display = 'none'
		document.getElementById('innerstrap').style.display = 'none'
		document.getElementById('lnkprint').innerHTML = 'Back to normal view'
	}
	else
	{
		document.getElementById('header').style.display = 'block'
		document.getElementById('nav').style.display = 'block'
		document.getElementById('innerstrap').style.display = 'block'
		document.getElementById('lnkprint').innerHTML = 'Print this page'
	}
}

function GetADate()
{
	var d = new Date()
	var months = new Array()
	months[0] = "January"
	months[1] = "February"
	months[2] = "March"
	months[3] = "April"
	months[4] = "May"
	months[5] = "June"
	months[6] = "July"
	months[7] = "August"
	months[8] = "September"
	months[9] = "October"
	months[10] = "November"
	months[11] = "December"
	return d.getDate() + ' ' + months[d.getMonth()] + ' ' + d.getFullYear()
}



function GetYear()
{
	var d = new Date()
	return d.getFullYear()
}


function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

function swapImage(img1, img2){
	img1.src = img2.src
}

function setFocus(id)
{
	el = document.getElementById(id)
	if(el) el.focus()
}

function rollin(obj, c){
	//eval("obj.style.cssText='background-color:" + c + "'")
	eval("obj.style.cssText = 'border:solid 1px #000000'")
	obj.style.cursor = 'pointer'
}
function rollout(obj, c){
	//eval("obj.style.cssText='background-color:" + c + "'")
	eval("obj.style.cssText = 'border:solid 1px #b0b0b0'")
}

function forgottenPassword()
{
	var frm = document.getElementById('frmLogin')
	if(frm)
	{
		if(isEmail(frm.email.value))
		{
			frm.action = document.form1.action + "?mode=forgot"
			frm.submit()
		}
		else
		{
			alert("Please enter an email address")
			frm.email.focus()
		}
	}
}

function isEmail(e)
{
	if(e.indexOf("@") > 0 && e.indexOf(".") > 0)
		return true
	else
		return false
}

function validate(frm)
{
	if(frm)
	{
		if(!isEmail(frm.email.value))
		{
			alert("Please enter an email address")
			frm.email.focus()
			return false
		}
		if(frm.name.value == "")
		{
			alert("Please enter a name")
			frm.name.focus()
			return false
		}
		if(frm.co.value == "")
		{
			alert("Please enter a company name")
			frm.co.focus()
			return false
		}
		if(frm.addr1.value == "")
		{
			alert("Please enter an address")
			frm.addr1.focus()
			return false
		}		
		if(frm.addr2.value == "")
		{
			alert("Please enter an address")
			frm.addr2.focus()
			return false
		}		
		if(frm.message.value == "")
		{
			alert("Please enter a message")
			frm.message.focus()
			return false
		}		
		if(frm.country.selectedIndex == 0)
		{
			alert("Please select a country")
			frm.country.focus()
			return false
		}		
		
		return true
	}
}
function val(frm)
{
	if(frm)
	{
		if(frm.firstname.value == "")
		{
			alert("Please enter a first name")
			frm.firstname.focus()
			return false
		}
		if(frm.lastname.value == "")
		{
			alert("Please enter a last name")
			frm.lastname.focus()
			return false
		}
		if(!isEmail(frm.email.value))
		{
			alert("Please enter an email address")
			frm.email.focus()
			return false
		}
		if(frm.message.value == "")
		{
			alert("Please enter a message")
			frm.message.focus()
			return false
		}
		return true
	}
}
function doLogIn()
{
	var frm = document.getElementById('frmLogin')
	if(frm)
	{
		if(!isEmail(frm.email.value))
		{
			alert("Please enter an email address")
			frm.email.focus()
		}
		else if(frm.password.value == "")
		{
			alert("Please enter a password")
			frm.password.focus()
		}
		else
		{
			frm.submit()
		}		
	}
}


function doEditDets()
{
	var frm = document.getElementById('frmEditDets')
	if(frm)
	{
		if(frm.firstname.value == "")
		{
			alert("Please enter a first name")
			frm.firstname.focus()
		}
		else if(frm.surname.value == "")
		{
			alert("Please enter a second name")
			frm.surname.focus()
		}
		else if(!isEmail(frm.email.value))
		{
			alert("Please enter an email address")
			frm.email.focus()
		}
		else if(frm.pwd.value == "")
		{
			alert("Please enter a password")
			frm.pwd.focus()
		}
		else
		{
			frm.submit()
		}		
	}
}


function doEditWebs()
{
	var frm = document.getElementById('frmEditWebs')
	if(frm)
	{
		frm.submit()
	}
}


function doEditContacts()
{
	var frm = document.getElementById('frmEditContacts')
	if(frm)
	{
		frm.submit()
	}
}


function doSend()
{
	var frm = document.getElementById('frmCompose')
	if(frm)
	{
		if(frm.subject.value == "")
		{
			alert("Please enter a subject")
			frm.subject.focus()
		}
		else if(frm.message.value == "")
		{
			alert("Please enter a message")
			frm.message.focus()
		}
		else
		{
			frm.submit()
		}		
	}
}

function doAddContact()
{
	var frm = document.getElementById('frmAdd')
	if(frm)
	{
		frm.submit()
	}
}






function setActiveStyleSheet(title) {  var i, a, main;
  createCookie("style", title, 365);  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {      a.disabled = true;      if(a.getAttribute("title") == title) a.disabled = false;  
    }  }}
function getActiveStyleSheet() {  var i, a;  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled)
		return a.getAttribute("title");  }  return null;}function getPreferredStyleSheet() {	var i, a;	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {		if(a.getAttribute("rel").indexOf("style") != -1			&& a.getAttribute("rel").indexOf("alt") == -1			&& a.getAttribute("title")) 
			return a.getAttribute("title");	}	return null;}function createCookie(name,value,days) {	if (days) {		var date = new Date();		date.setTime(date.getTime()+(days*24*60*60*1000));		var expires = "; expires="+date.toGMTString();	}	else expires = "";	document.cookie = name+"="+value+expires+"; path=/";}function readCookie(name) {	var nameEQ = name + "=";	var ca = document.cookie.split(';');	for(var i=0;i < ca.length;i++) {		var c = ca[i];		while (c.charAt(0)==' ') c = c.substring(1,c.length);		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);	}	return null;}
var cookie = readCookie("style");var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

function emaillink()
{
	alert(location.href)
}





function doPreload()
{
	preload('bhomeoff','../images/btn_home_off.jpg')
	preload('bhomeon','../images/btn_home_on.jpg')
	
	preload('baaoff','../images/btn_aa_off.jpg')
	preload('baaon','../images/btn_aa_on.jpg')
	preload('baacurroff','../images/btn_aa_current_off.jpg')
	preload('baacurron','../images/btn_aa_current_on.jpg')
	
	preload('bcontactoff','../images/btn_contact_off.gif')
	preload('bcontacton','../images/btn_contact_on.gif')
	preload('bcontactcurroff','../images/btn_contact_current_off.gif')
	preload('bcontactcurron','../images/btn_contact_current_on.gif')
	
	preload('bproff','../images/sub_btn_pr_off.jpg')
	preload('bpron','../images/sub_btn_pr_on.jpg')
	preload('bprcurroff','../images/sub_btn_pr_current_off.jpg')
	preload('bprcurron','../images/sub_btn_pr_current_on.jpg')
	
	preload('bsloff','../images/sub_btn_sl_off.jpg')
	preload('bslon','../images/sub_btn_sl_on.jpg')
	preload('bslcurroff','../images/sub_btn_sl_current_off.jpg')
	preload('bslcurron','../images/sub_btn_sl_current_on.jpg')
	
	preload('bpcoff','../images/sub_btn_pc_off.jpg')
	preload('bpcon','../images/sub_btn_pc_on.jpg')
	preload('bpccurroff','../images/sub_btn_pc_current_off.jpg')
	preload('bpccurron','../images/sub_btn_pc_current_on.jpg')
	
	preload('bregoff','../images/sub_btn_reg_off.jpg')
	preload('bregon','../images/sub_btn_reg_on.jpg')
	preload('bregcurroff','../images/sub_btn_reg_current_off.jpg')
	preload('bregcurron','../images/sub_btn_reg_current_on.jpg')
	
	preload('bcsoff','../images/sub_btn_cs_off.jpg')
	preload('bcson','../images/sub_btn_cs_on.jpg')
	preload('bcscurroff','../images/sub_btn_cs_current_off.jpg')
	preload('bcscurron','../images/sub_btn_cs_current_on.jpg')
	
	preload('bcosoff','../images/sub_btn_cos_off.jpg')
	preload('bcoson','../images/sub_btn_cos_on.jpg')
	preload('bcoscurroff','../images/sub_btn_cos_current_off.jpg')
	preload('bcoscurron','../images/sub_btn_cos_current_on.jpg')
	
	preload('bnutoff','../images/sub_btn_nut_off.jpg')
	preload('bnuton','../images/sub_btn_nut_on.jpg')
	preload('bnutcurroff','../images/sub_btn_nut_current_off.jpg')
	preload('bnutcurron','../images/sub_btn_nut_current_on.jpg')
	
	preload('baadoff','../images/sub_btn_aad_off.jpg')
	preload('baadon','../images/sub_btn_aad_on.jpg')
	preload('baadcurroff','../images/sub_btn_aad_current_off.jpg')
	preload('baadcurron','../images/sub_btn_aad_current_on.jpg')
	
	preload('bbloff','../images/sub_btn_bl_off.jpg')
	preload('bblon','../images/sub_btn_bl_on.jpg')
	preload('bblcurroff','../images/sub_btn_bl_current_off.jpg')
	preload('bblcurron','../images/sub_btn_bl_current_on.jpg')
	
	preload('beurooff','../images/btn_euronet.jpg')
	preload('beuroon','../images/btn_euronet_on.jpg')
	preload('trioff','../images/others/trioff.gif')
	preload('trion','../images/others/trion.gif')	
}

function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

function swapImage(i1, i2)
{
	if(i1 && i2)i1.src = i2.src
}



function fillControl(n){

	var arr1 = new Array()
	for(var i = 0; i < 24; i++) arr1[i] = ""
	arr1[n - 1] = "<b>&middot;&nbsp;"
	var arr2 = new Array()
	for(var i = 0; i < 24; i++) arr2[i] = ""
	arr2[n - 1] = "&nbsp;&middot;</b>"

	if(parent.control == null) return
	
    parent.control.document.close()
    parent.control.document.open()
    
    parent.control.document.write("<html><head></head><body bgcolor=white>")
    parent.control.document.write("<table bgcolor=white cellpadding=0 cellspacing=0 border=0 align=center>")
    
    parent.control.document.write("<tr height=2><td height=2><img src=images/pixel.gif width=1 height=2 border=0></td></tr>")
            
    parent.control.document.write("<tr><td align=center>")
    parent.control.document.write("<table cellpadding=0 cellspacing=0 border=0>")
    parent.control.document.write("<tr><td align=left>")
    if(n != 1)
		parent.control.document.write("<a href=vital" + (n - 1) + ".htm target=content><img src=images/prev.gif border=0 width=91 height=20></a>")
	else	
		parent.control.document.write("<img src=images/prev.gif border=0 width=91 height=20>")
    parent.control.document.write("</td>")
        
        
    parent.control.document.write("<td align=center>")
    
    parent.control.document.write("<table cellpadding=1 cellspacing=0 border=0 bgcolor=black>")
    parent.control.document.write("<tr><td align=left>")
    parent.control.document.write("<table height=18 cellpadding=0 cellspacing=0 border=0 bgcolor=white>")
    parent.control.document.write("<tr height=18><td style=font-size:12px;font-family:arial; height=18 align=left>")
    parent.control.document.write(arr1[0] + "<a href=vital1.htm target=content>1</a>" + arr2[0] + "&nbsp;")
    parent.control.document.write(arr1[1] + "<a href=vital2.htm target=content>2</a>" + arr2[1] + "&nbsp;")
    parent.control.document.write(arr1[2] + "<a href=vital3.htm target=content>3</a>" + arr2[2] + "&nbsp;")
    parent.control.document.write(arr1[3] + "<a href=vital4.htm target=content>4</a>" + arr2[3] + "&nbsp;")
    parent.control.document.write(arr1[4] + "<a href=vital5.htm target=content>5</a>" + arr2[4] + "&nbsp;")
    parent.control.document.write(arr1[5] + "<a href=vital6.htm target=content>6</a>" + arr2[5] + "&nbsp;")
    parent.control.document.write(arr1[6] + "<a href=vital7.htm target=content>7</a>" + arr2[6] + "&nbsp;")
    parent.control.document.write(arr1[7] + "<a href=vital8.htm target=content>8</a>" + arr2[7] + "&nbsp;")
    parent.control.document.write(arr1[8] + "<a href=vital9.htm target=content>9</a>" + arr2[8] + "&nbsp;")
    parent.control.document.write(arr1[9] + "<a href=vital10.htm target=content>10</a>" + arr2[9] + "&nbsp;")
    
    parent.control.document.write(arr1[10] + "<a href=vital11.htm target=content>11</a>" + arr2[10] + "&nbsp;")
    parent.control.document.write(arr1[11] + "<a href=vital12.htm target=content>12</a>" + arr2[11] + "&nbsp;")
    parent.control.document.write(arr1[12] + "<a href=vital13.htm target=content>13</a>" + arr2[12] + "&nbsp;")
    parent.control.document.write(arr1[13] + "<a href=vital14.htm target=content>14</a>" + arr2[13] + "&nbsp;")
    parent.control.document.write(arr1[14] + "<a href=vital15.htm target=content>15</a>" + arr2[14] + "&nbsp;")
    parent.control.document.write(arr1[15] + "<a href=vital16.htm target=content>16</a>" + arr2[15] + "&nbsp;")
    parent.control.document.write(arr1[16] + "<a href=vital17.htm target=content>17</a>" + arr2[16] + "&nbsp;")
    parent.control.document.write(arr1[17] + "<a href=vital18.htm target=content>18</a>" + arr2[17] + "&nbsp;")
    parent.control.document.write(arr1[18] + "<a href=vital19.htm target=content>19</a>" + arr2[18] + "&nbsp;")
    parent.control.document.write(arr1[19] + "<a href=vital20.htm target=content>20</a>" + arr2[19] + "&nbsp;")
    
    parent.control.document.write(arr1[20] + "<a href=vital21.htm target=content>21</a>" + arr2[20] + "&nbsp;")
    parent.control.document.write(arr1[21] + "<a href=vital22.htm target=content>22</a>" + arr2[21] + "&nbsp;")
    parent.control.document.write(arr1[22] + "<a href=vital23.htm target=content>23</a>" + arr2[22] + "&nbsp;")
    parent.control.document.write(arr1[23] + "<a href=vital24.htm target=content>24</a>" + arr2[23] + "&nbsp;")
    parent.control.document.write("</td>")
    parent.control.document.write("</tr></table>")
    parent.control.document.write("</td>")
    parent.control.document.write("</tr></table>")
    
    parent.control.document.write("</td>")
                    
        
    parent.control.document.write("<td align=right>")
    if(n == 24)
		parent.control.document.write("<img src=images/next.gif border=0 width=91 height=20>")
	else	
		parent.control.document.write("<a href=vital" + (n+1) + ".htm target=content><img src=images/next.gif border=0 width=91 height=20></a>")
    parent.control.document.write("</td>")
    parent.control.document.write("</tr>")
    parent.control.document.write("</table>")
        
    parent.control.document.write("</td></tr></table>")
    parent.control.document.write("</body></html>")
    
    parent.control.document.close()

}



function startHighlight()
{
	var term
	if(location.href.indexOf('?term=') != -1)
	{
		term = location.href.substring(location.href.indexOf('?term=') + 6)
		if(term.length > 1) highlightSearchTerms(term)
	}
}


/*
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<span style='color:black; font-weight:bold;'>";
    highlightEndTag = "</span>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}


/*
 * This displays a dialog box that allows a user to enter their own
 * search terms to highlight on the page, and then passes the search
 * text or phrase to the highlightSearchTerms function. All parameters
 * are optional.
 */
function searchPrompt(defaultText, treatAsPhrase, textColor, bgColor)
{
  // This function prompts the user for any words that should
  // be highlighted on this web page
  if (!defaultText) {
    defaultText = "";
  }
  
  // we can optionally use our own highlight tag values
  if ((!textColor) || (!bgColor)) {
    highlightStartTag = "";
    highlightEndTag = "";
  } else {
    highlightStartTag = "<font style='color:" + textColor + "; background-color:" + bgColor + ";'>";
    highlightEndTag = "</font>";
  }
  
  if (treatAsPhrase) {
    promptText = "Please enter the phrase you'd like to search for:";
  } else {
    promptText = "Please enter the words you'd like to search for, separated by spaces:";
  }
  
  searchText = prompt(promptText, defaultText);

  if (!searchText)  {
    alert("No search terms were entered. Exiting function.");
    return false;
  }
  
  return highlightSearchTerms(searchText, treatAsPhrase, true, highlightStartTag, highlightEndTag);
}


/*
 * This function takes a referer/referrer string and parses it
 * to determine if it contains any search terms. If it does, the
 * search terms are passed to the highlightSearchTerms function
 * so they can be highlighted on the current page.
 */
function highlightGoogleSearchTerms(referrer)
{
  // This function has only been very lightly tested against
  // typical Google search URLs. If you wanted the Google search
  // terms to be automatically highlighted on a page, you could
  // call the function in the onload event of your <body> tag, 
  // like this:
  //   <body onload='highlightGoogleSearchTerms(document.referrer);'>
  
  //var referrer = document.referrer;
  if (!referrer) {
    return false;
  }
  
  var queryPrefix = "q=";
  var startPos = referrer.toLowerCase().indexOf(queryPrefix);
  if ((startPos < 0) || (startPos + queryPrefix.length == referrer.length)) {
    return false;
  }
  
  var endPos = referrer.indexOf("&", startPos);
  if (endPos < 0) {
    endPos = referrer.length;
  }
  
  var queryString = referrer.substring(startPos + queryPrefix.length, endPos);
  // fix the space characters
  queryString = queryString.replace(/%20/gi, " ");
  queryString = queryString.replace(/\+/gi, " ");
  // remove the quotes (if you're really creative, you could search for the
  // terms within the quotes as phrases, and everything else as single terms)
  queryString = queryString.replace(/%22/gi, "");
  queryString = queryString.replace(/\"/gi, "");
  
  return highlightSearchTerms(queryString, false);
}


/*
 * This function is just an easy way to test the highlightGoogleSearchTerms
 * function.
 */
function testHighlightGoogleSearchTerms()
{
  var referrerString = "http://www.google.com/search?q=javascript%20highlight&start=0";
  referrerString = prompt("Test the following referrer string:", referrerString);
  return highlightGoogleSearchTerms(referrerString);
}

