/* common javsacript file */
// JavaScript Browser Sniffer
// Eric Krok, Andy King, Michel Plungjan Jan. 31, 2002
// see http://www.webreference.com/ for more information
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.

    var agt=navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();
    var is_minor = parseFloat(appVer);
    var is_major = parseInt(is_minor);

	var is_opera = (agt.indexOf("opera") != -1);

	var is_mac = (agt.indexOf("mac")!=-1);
    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       if(is_mac) {
           var iePos = agt.indexOf('msie');
           is_minor = parseFloat(agt.substring(iePos+5,agt.indexOf(';',iePos)));
       }
       else is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
       is_major = parseInt(is_minor);
    }

    var is_konq = false;
    var kqPos   = agt.indexOf('konqueror');
    if (kqPos !=-1) {                 
       is_konq  = true;
       is_minor = parseFloat(agt.substring(kqPos+10,agt.indexOf(';',kqPos)));
       is_major = parseInt(is_minor);
    }                                 

    var is_getElementById   = (document.getElementById) ? "true" : "false";
    var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
    var is_documentElement = (document.documentElement) ? "true" : "false";

    var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
    var is_khtml  = (is_safari || is_konq);

    var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
	var is_ie4   = (is_ie && is_major == 4);
    var is_ie5   = (is_ie && is_major == 5);
	var is_ie5up = (is_ie && is_minor >= 5);
	var is_ie5_5  = (is_ie && (agt.indexOf("msie 5.5") !=-1)); // 020128 new - abk
	var is_ie6   = (is_ie && is_major == 6);

// Show and hide tabs function

var run = 1
var imgsrc
var imghref
var imagesrc2
var imghref2
var tabrun1=1;
var tabrun2=1;

function show(id){
	document.getElementById(id).style.display="block";
}

function hideAll(obj,contentname,geosm,geolg,tabid){
	if(tabid == null){
		tabid="";
	}
	
	if (run == 1 && tabid=="") {
		imgsrc = document.getElementById('mainimg'+tabid).src;

		if (document.getElementById('imageShow'+tabid) != null)
		imghref = document.getElementById('imageShow'+tabid).href;
		run = 0;
		
	}
	else if (tabid=="1" && tabrun1 > 0){
        imgsrc = document.getElementById('mainimg'+tabid).src;

	    if (document.getElementById('imageShow'+tabid) != null)
	    imghref = document.getElementById('imageShow'+tabid).href;
	    tabrun1 = 0 ;
    }
	else if (tabid=="2" && tabrun2 > 0 ){
        imgsrc2 = document.getElementById('mainimg'+tabid).src;

	    if (document.getElementById('imageShow'+tabid) != null)
	      imghref2 = document.getElementById('imageShow'+tabid).href;
	    tabrun2 = 0 ;
	}
	tmp = document.getElementsByTagName('div');
	for (i=0;i<tmp.length;i++){
	    if (tabid ==""){
		    if (tmp[i].className == 'tab-content') tmp[i].style.display='none';
		    }
		else{
		    if (tmp[i].className == 'tab-content'+ tabid) tmp[i].style.display='none'; 
		    }
	}
	tmp = document.getElementsByTagName('a');
	for (i=0;i<tmp.length;i++){
		if (tmp[i].className == 'tab') tmp[i].id='';
	}
	document.getElementById(contentname).style.display="block";
	obj.setAttribute('id','current');
 	if ((contentname == 'geometry' + tabid))  {
		if (document.getElementById(contentname).style.display == 'none') {
			imgsrc = document.getElementById('mainimg'+tabid).src;
			imghref = document.getElementById('imageShow'+tabid).href;
		}
		if (geosm && geolg) {
			document.getElementById('imageShow' + tabid).href = geolg;
			document.getElementById('mainimg' + tabid).src = geosm;
		}
	} else {
	if (tabid=="" || tabid=="1") {
	    document.getElementById('mainimg'+tabid).src = imgsrc;
		document.getElementById('imageShow'+tabid).href = imghref;
	}
	else{
	    document.getElementById('mainimg'+tabid).src = imgsrc2;
		document.getElementById('imageShow'+tabid).href = imghref2;
	}
    }

}

/* function to have multiple events within the onload event */
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/*
addLoadEvent( function() {
    new Accordian('basic-accordian',5,'header_highlight');
});*/

function initialise() {
	var imgs = document.getElementsByTagName('img'), i;
	for (i = 0; i < imgs.length; ++i) {
		if (imgs[i].className == 'showHide') {
			imgs[i].style.display = 'block';
		}
	}
	var lis = document.getElementsByTagName('li'), i;
	for (i = 0; i < lis.length; ++i) {
		if (lis[i].className == 'shown') {
			lis[i].className = 'hidden';
		}
	}
}

function showHide(obj, remote) {
	if (remote == 'run') {
		var parentElement = document.getElementById(obj).parentNode;
	} else {
		var parentElement = obj.parentNode;
	}
	
	var parentElementClass = parentElement.className;
	if (parentElementClass.match('shown')) {
		parentElement.className = 'hidden';
		//parentElement.className.replace(/shown/,"hidden");
	}
	if (parentElementClass.match('hidden')) {
		parentElement.className = 'shown';
		//parentElement.className.replace(/hidden/,"shown");
	}
	//alert(parentElement.className);
}

/* random image loader script */
var rand1 = 0;
var useRand = 0;

images = new Array;
images[1] = new Image();
images[1].src = "../flash/adt/downloads_1.jpg";
images[2] = new Image();
images[2].src = "../flash/adt/downloads_2.jpg";
images[3] = new Image();
images[3].src = "../flash/adt/downloads_3.jpg";

function swapMe(obj) {
	whoToSwap = document.getElementById(obj);
	var imgnum = images.length - 1;
	do {
		var randnum = Math.random();
		rand1 = Math.round((imgnum - 1) * randnum) + 1;
	} while (rand1 == useRand);
	useRand = rand1;
	try {
	whoToSwap.src = images[useRand].src;
	} catch(e) {}
}

var surveyDiv;
var surveyDisplay;


function showSurvey() {
	surveyDiv = document.getElementById('surveyContainer');
	surveyDisplay = surveyDiv.style.display;
	if (surveyDisplay == 'none') {
		surveyDiv.style.display = 'block';
	} else {
		if (surveyDisplay == 'block') {
			surveyDiv.style.display = 'none';
		}
	}
}
