/**
 * Filename         : general.js
 * Created by       : Peter Hammans
 * Last modified by : Peter Hammans
 * Created          : 10 March 2005 16:02
 * Last Updated     : 10 March 2005 16:03
 * Comments         : Coordinating of functions for specific js files and general page manipulation
 */
var _isMac = (navigator.userAgent.match(/mac/i))?1:0;
function _cityAndGuildsLoad(){
 if(document.readyState) {
  if(!_isMac && document.readyState != "complete")
   return;
  else if( _isMac && document.readyState != "interactive" && (navigator.userAgent.match(/msie/i)))
   return ;
 };
 actionBar();
 relatedLinks();     
 if(document.getElementById("nav"))
  cssMenu("nav"); 
  caseStudy("casestudylink");
  printButton("printLink");
  hideSubmit("fSearchDirectToPage");
  if(document.getElementById("otherSites")){
   otherSites();
  };
};

if(window.addEventListener) window.addEventListener("load", _cityAndGuildsLoad, false);
else if(typeof document.onreadystatechange != "undefined") document.onreadystatechange = _cityAndGuildsLoad;
function toggleDisplay(oNode,sProperty) {
 if(isDefined(oNode)) {
  oNode.style.display=sProperty;    
 }
}
function isDefined(oElement) {
    return (typeof(oElement) == "undefined")?  false: true;
}
String.prototype.trim = function(){
 var s = this;
 while(s.substring(0,1) == " "){
  s = s.substring(1,s.length);
 };
 while(s.substring(s.length-1,s.length) == " "){
  s = s.substring(0,s.length-1);
 };
 return s;
};
function hideSubmit(sID){
 if((_isMac && typeof document.all != "undefined") || !document.getElementById(sID)){
  return;
 };
 oForm = document.getElementById(sID)
 if (oForm){
  oInputSubmit = oForm.getElementsByTagName("input")[0];
  if(oInputSubmit) {
    oInputSubmit.onchange = function(){
     oForm.submit();
    };
  }
  oInputSubmit.className = "hide";
 }
}
function relatedLinks() {
   var oContent = document.getElementById("content");
   if(oContent) {
         var oColumns = oContent.getElementsByTagName("div");
         var oColA,oColB;
         for(i=0;i<oColumns.length;i++) {         
          if(oColumns.item(i).className=="colA") {
           oColA = oColumns.item(i);
          }
          if(oColumns.item(i).className=="colB") {
           oColB = oColumns.item(i);
          }
         }
         if(oColA && oColB) {
          if(oColA.innerHTML.indexOf("<")!=-1 && oColB.innerHTML.indexOf("<")==-1) {
          oColA.className="colA colResized";
          oColA.innerHTML = "&nbsp;" + oColA.innerHTML;
          }
          if(oColA.innerHTML.indexOf("<")==-1 && oColB.innerHTML.indexOf("<")!=-1) {
           oColB.className="colB colResized";
           oColB.innerHTML = "&nbsp;" + oColB.innerHTML;
             }    
         }  
     }
}
function actionBar(){
	var oContent = document.getElementById("content");
	var oActionBar = document.getElementById("panel");
	if(oContent && oActionBar) {
		var nContentHeight = oContent.offsetHeight;
  		if(nContentHeight>oActionBar.offsetHeight) {
   			oActionBar.style.height = oContent.offsetHeight-27+"px";  
 		}else{
 			oContent.style.height = oActionBar.offsetHeight+27+"px";  
 		}
 	} 
}
function otherSites(){
 var a = document.getElementById("otherSites").getElementsByTagName("a");
 var s = ""
 s += "<form id=\"fOtherLinksForm\" action=\"#\" method=\"post\">";
 s += "<fieldset>";
 s += "<label for=\"fOtherLinks\">Our other sites</label>";
 s += "<select name=\"fOtherLinks\" id=\"fOtherLinks\">";
 for(var i=0; i<a.length; i++){
  s += "<option value=\"" + a[i].href + "\">" + a[i].firstChild.data + "</option>";
 };
 s += "</select>";
 s += "<input type=\"submit\" value=\"Go\" />";
 s += "</fieldset>";
 s += "</form>";
 document.getElementById("header").innerHTML += s;
 document.getElementById("fOtherLinksForm").onsubmit = function(){
  self.location = document.getElementById("fOtherLinks")[document.getElementById("fOtherLinks").selectedIndex].value;
  return false;
 };
};
function popreg(url)
{
var width = 600;
var height = 550;
window.open(url, "popreg", "WIDTH="+width+",HEIGHT="+height+ 
",location=0,resizable=1,status=0,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1"
    ).focus();
    return false;
    };