// Javascript utilities


  function goToFrameCtl(target) {
    window.document.location = target;
  }
  
  function closeMe() {
    window.close();
  }

  function checkFormat(input) {
    output = parseInt(input);
    if (output == "NaN") {
      output = 1;
    }
    return output;
  }

  function getRandom(num) {
    return Math.floor(Math.random() * num) + 1;
  }

  function getAppVersion() {
   return navigator.appVersion;
  }

  function getAppName() {
   return navigator.appName;
  }

  function getCodeName() {
   return navigator.appCodeName;
  }

  function getLanguage() {
   return navigator.appLanguage;
  }

  function getPlatform() {
   return navigator.platform;
  }

  function getUserAgent() {
   return navigator.userAgent;
  }
  
  function getBrowser() {
    if (getUserAgent().indexOf("Opera") > -1) {
      return "Opera";
    }
    else if (getAppVersion().indexOf("IE") > -1) {
      return "IE";
    } 
    else {
      return getAppVersion();
    }
  }
  
  function showBrowser() {
    alert("Browser is " + getBrowser());
    return true;
  }
  
  
function openWin(fileName, title) {
     //myFloater = window.open('',title,'width=600,height=600')
     myFloater = window.open('',title)
     myFloater.location.href = fileName;
}

function setCommonLandF() {

}

function goToContents() {
    window.document.location = 'http://www.awonderfulchoice.com/index.html';
}

function goBack() {
    window.document.location = 'http://www.awonderfulchoice.com/feedback.html';
}

function recindCommonLandF() {
  document.write('</font>');
  document.write('</p>');
}

function writeLocator() {
  document.write('<p align="center">');
  document.write('<a class="nb" href="index.html">home</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="dandb.html">analysis</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="team.html">leadership</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="sites.html">web</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="train.html">training</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="consult.html">consultancy</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="uml.html">uml</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="oracle.html">oracle</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="java.html">java</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="mumps.html">cach&#233;</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="collab.html">collaborations</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="refs.html">references</a>');
  document.write('&nbsp;|&nbsp;');
  document.write('<a class="nb" href="info.html">company info</a>');
  document.write('</p>');
  
}

function writeBanner() {
	// This randomises the banner pic
	var bannerArray = new Array("winter_house_banner.jpg",
				"carcassonne.jpg",
				"poppies2.jpg",
				"poppies1.jpg");
	var posn = getRandom(bannerArray.length)-1;
	document.write("<center><img src='images/" + bannerArray[posn]
	               + "' alt='AWCFA Random Banner' class='logo' /></center>");
	
}

function writeFooter() {
  document.write('<hr>');
  document.write('<address>');
  document.write('<font size="2" face="Times New Roman"><i>Copyright A Wonderful Choice Ltd 2009 All rights reserved');
  document.write('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="feedback.html">Feedback<a>&nbsp;');
  if (getAppName()=="Netscape") {
   document.write (
     'To bookmark this site, click '
    +'<b>Bookmarks&nbsp;| Add&nbsp;bookmark</b> '
    +'or press <b>Ctrl+D</b>.'
   )
  }
  else if (getUserAgent().indexOf("Opera") > -1) {
    document.write (
	   'To bookmark this site, click '
	  +'<b>Bookmarks&nbsp;| Add&nbsp;bookmark</b> '
	  +'or press <b>Ctrl+T</b>.'
	 )
   }
   else if (parseInt(getAppVersion())>3) {
     document.write (''
    +'<a onMouseOver="self.status=\'Bookmark this site\'" '
    +' onMouseOut="self.status=\'\'" '
    +' href="javascript:window.external.AddFavorite'
    +'(\'http://www.awonderfulchoice.co.uk/it/\','
    +'\'A Wonderful Choice\')">'
    +'Click here to bookmark this site</a>.'
    )
   }

  document.write('</i></font>');
  document.write('</address>');
}

   
  // *********************  
  // Photo Album Utilities
  // *********************
  function displayPhotoAlbum(fileIndex) {
     currentPicture=fileIndex;
     if (getAppVersion().indexOf("IE 5") > -1) {
       myFloater = window.open('album.htm?fileIndex=' + fileIndex,'photoAlbum','width=750,height=550 scrollbars');
     } 
     else if (getAppVersion().indexOf("IE 6") > -1) {
       myFloater = window.open('album.htm?fileIndex=' + fileIndex,'photoAlbum','width=750,height=550 scrollbars');
     }
     else {
       myFloater = window.open('picture.htm','picture' + fileIndex,'width=750,height=550 scrollbars'); 
     }
  }

  function getPictureNumber() {
    return window.name.substring(7,window.name.length);
  }
  
  function getCurrentIndex() {
     var currentIndex = window.location.search;
     currentIndex = currentIndex.substring(11, currentIndex.length);
     if (currentIndex == "") {
       currentIndex = 0;
     }
     return currentIndex;
  }
  
  function previousPicture(currentIndex) {
     var prev = getPrevious(currentIndex);
     window.location ="album.htm?fileIndex=" + prev;
  }

  function nextPicture(currentIndex) {
     var next = getNext(currentIndex);
     window.location ="album.htm?fileIndex=" + next;
  }
    
  function getPrevious(currentIndex) {
     var nextIndex = 0;
     if (currentIndex == 0) {
       nextIndex = pictureArray.length-1;
     }
     else {
       nextIndex = + currentIndex - 1;
     }
     return nextIndex;
  }

  function getNext(currentIndex) {
     var nextIndex = 0;
     if (currentIndex == pictureArray.length-1) {
       nextIndex = 0;
     }
     else {
       nextIndex = + currentIndex + 1;
     }
     return nextIndex;
  }
  
  
  function displayThumbs() {
    var picsOnLine = 5;
    var picsFilled = 0;
    for (i=0; i<pictureArray.length; i++) {
      if (i%picsOnLine==0) {
        if (i > 0) {
          document.write("</tr>");  
        }
        document.write("<tr align='center'>");
        document.write("<td>");        
        drawCell(i);
        document.write("</td>");        
      }
      else {
        document.write("<td>");        
        drawCell(i);
        document.write("</td>");        
      }
    }
    document.write("</tr>");
  }
  
  function drawCell(i) {
    document.write("<table cellspacing=0 border=0 align='center'>");
    document.write("  <tr align='center'>");
    document.write("    <td>");
    document.write("      <A HREF='javascript:displayPhotoAlbum(" + i + ")'>");
    document.write("        <img BORDER='0' SRC='images/"+ pictureArray[i].thumbFile + ".jpg' width='" + pictureArray[i].thumbWidth + "' height='" + pictureArray[i].thumbHeight + "' ALT='" + pictureArray[i].pictureName +"'>");
    document.write("      </A>");
    document.write("    </td>");    
    document.write("  </tr>");    
    document.write("  <tr align='center'>");
    document.write("    <td>");
    document.write("     <font face='Arial' size='3' color='#3300FF'>");
    document.write(        pictureArray[i].pictureName);
    document.write("     </font>");    
    document.write("    </td>");    
    document.write("  </tr>");    
    document.write("</table>");
  }
  
  function preloadPictures() {
    for (i=0; i<pictureArray.length; i++) {
      document.write("<img BORDER='0' SRC='images/"+ pictureArray[i].thumbFile + ".jpg' width='1' height='1'>");  
      document.write("<img BORDER='0' SRC='images/"+ pictureArray[i].pictureFile + ".jpg' width='1' height='1'>"); 
    }
  }
  
   function displayScrollbars() {
    // Due to the general crappiness of IE have to fool
    // browser into displaying scroll bars by doing this onLoad
       resizeBy(1);
    }

  // *********************  
  // TextArea Utilities
  // *********************
  
  //Implement this onFocus trigger e.g. onFocus="positionCursor(this);"
   function positionCursor(ta) {
	//Strip whitespace
	ta.value = ta.value.replace(/\s+/g,' ').replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1'); 
   }
   
   function updateCountdown(ta, cf) {
   	var maxLength = ta.getAttribute('maxlength');
    	if (ta.value.length > maxLength) {
   		ta.value = ta.value.substring(0, maxLength-1);
   	} else {
   		cf.value = maxLength-ta.value.length;
   	}
   }
   
   function writeMaxLength(ta) {
   	var maxLength = ta.getAttribute('maxlength');
   	document.write(maxLength);
   }

  function getRandom(num) {
    return Math.floor(Math.random() * num) + 1;
  }
