

var preloadedImages = new Array();

function preloadimages() {
	for (i=0; i < preloadimages.arguments.length; i++) {
		preloadedImages[i] = new Image();
		preloadedImages[i].src = preloadimages.arguments[i];
	}
}


var browser = "";

//detecting older netscapes
if (!document.all){browser = "Old Netscape"}

//detecting Opera if (navigator.userAgent.indexOf("Opera") > 0){browser = "Opera"}

//detecting IE
if (navigator.appName =="Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera") < 0){browser = "IE"}

//detecting newer Netscapes
if (navigator.appName == "Netscape" && document.all && navigator.userAgent.indexOf("Opera") < 0){browser = "NewNetscape"}



			if (browser=="IE"){
				document.writeln('<link rel="stylesheet" type="text/css" href="' + doc_root + '/styles/hw.css">');
			}else{
				document.writeln('<link rel="stylesheet" type="text/css" href="' + doc_root + '/styles/hw_ns.css">');
			}

    var primary=new Array
    var copyFlag=false;
    var copySecondary=new Array();

    function readSecondary(formName)
     {if (!copyFlag)
       {var secondaryOptions=self.document.forms[formName].elements.subcategory.options;
        var countSecondary=secondaryOptions.length

        copySecondary.length=countSecondary;
        for (var i=0;i < countSecondary;i++)
         {copySecondary[i]=new Option(secondaryOptions[i].text);
            copySecondary[i].value=secondaryOptions[i].value;
         }

        copyFlag=true;
       }

      return doSecondary(formName);
     }

    function doSecondary(formName)
     {var primaryIndex=self.document.forms[formName].elements.category.selectedIndex;
      var primary=self.document.forms[formName].elements.category.options[primaryIndex].value;
      var secondaryOptions=self.document.forms[formName].elements.subcategory.options;

      secondaryOptions.length=1;
      secondaryOptions[0]=new Option("-");
      secondaryOptions[0].value="_empty_";

      for (var i=0;i < copySecondary.length;i++)
       {if (copySecondary[i].value.substring(0,primary.length)==primary)
         {if (secondaryOptions[0].value!="_empty_") {secondaryOptions.length++;}
          secondaryOptions[secondaryOptions.length-1]=new Option(copySecondary[i].text);
          secondaryOptions[secondaryOptions.length-1].value=copySecondary[i].value;
         }
       }
       //secondaryOptions[0].selected=true;
       //secondaryOptions[0].defaultSelected=true;
      return true;
     }
/**
*	Function: 		selectGoTo
*	Description:	Takes a select list and sends the request to the corresponding value
*					of the selected option. 
**/
function linkTo(item) {

	var action 	= item.options[item.selectedIndex].value;
	document.location = action;
}

function populateYearOfBirth(selectid, selectedvalue)
{
	var formfield = document.getElementById(selectid);
	// Populate select list with years from 100 to 18 years before current year
	var now = new Date();
	var thisYear = now.getYear()
	var index = 1 ;
	for ( y = (thisYear-18) ; y >= (thisYear-100) ; y-- )
	{
		formfield[index] = new Option(y, y);
		if (selectedvalue && selectedvalue == y) { formfield.selectedIndex = index ; }
		index++ ;
	}
}

/**
*
*	LAYER
**/
// constructor
function Layer(layerId, lyrWidth, lyrHeight, startX, startY, endX, endY, lyrSpeed, easeFactor, lyrDelay, lyrDisplay, foTime, foPath) {
	// mandatory
	this.layerId 	= layerId;
	this.lyrWidth	= lyrWidth;
	this.lyrHeight	= lyrHeight;
	
	// movement
	this.moveTimeOut	= 10;						// in milliseconds, smaller value for fluent animation
	this.timeOutCalls	= 1000/this.moveTimeOut;	// number of timeout-call (movement call) for each second
	
	// optional with default values
	var windowWidth = (typeof( window.innerWidth ) == 'number')? window.innerWidth: document.documentElement.clientWidth;
	var windowHeight= (typeof( window.innerHeight ) == 'number')? window.innerHeight: document.documentElement.clientHeight;
	var centerX = windowWidth/2 - this.lyrWidth/2;
	var centerY = windowHeight/2 - this.lyrHeight/2;
	
	this.startX = (!startX)? 	(0-this.lyrWidth): startX;		// default to left outside the visible area
	this.startY = (!startY)? 	centerY: startY;
	this.endX	= (!endX)?		centerX: endX;
	this.endY	= (!endY)?		centerY: endY;
	
	this.lyrSpeed 	= (!lyrSpeed)?		100: lyrSpeed;
	this.easeFactor	= (!easeFactor)? 	0: easeFactor;
	this.lyrDelay	= (!lyrDelay)?		0: lyrDelay;
	this.lyrDisplay	= (!lyrDisplay)? 'yes': lyrDisplay;
	this.foTime	= (!foTime)? -1: foTime*1000;
	this.foPath	= (!foPath)? 'no': foPath;
	
	// fade out
	this.initStartX = this.startX;
	this.initStartY = this.startY;
	this.initEndX = this.endX;
	this.initEndY = this.endY;
	this.initEaseFactor = this.easeFactor;
	this.timeoutFOid = '';
	
	// easing the animation
	this.distance = (startX != endX)? Math.abs(this.startX - this.endX): Math.abs(this.startY - this.endY);
	this.dynSpeed = this.lyrSpeed;	// dynamic layer speed
}

// define methods
Layer.prototype.ShowLayer = function() {
	var layerElem = document.getElementById(this.layerId);
	var thisObjLyr = this; // help variable for setTimeout(), because "this" in window.setTimeout-function refer to Window Object
	
	if(layerElem!=null && this.IsLayerHidden()) {
		window.setTimeout(function(){thisObjLyr.DisplayLayer(layerElem)}, thisObjLyr.lyrDelay*1000);
		this.ResetToInit();
	}
}

Layer.prototype.DisplayLayer = function(layerElem) {
	var thisObjLyr = this;
	layerElem.style.left = this.startX + "px";
	layerElem.style.top = this.startY + "px";
	
	layerElem.style.display = 'block';
	
	if(this.lyrSpeed >= 0) this.MoveLayer();
	window.setTimeout(function(){thisObjLyr.IsReadyToFadeOut()}, 1000);
}

Layer.prototype.HideLayer = function() {
	var layer = document.getElementById(this.layerId);
	if (layer != null) {
		var thisObjLyr = this;
		window.clearTimeout(thisObjLyr.timeoutFOid);
		if(this.foTime > 0 && this.foPath != 'no') {
			this.FOMove();	
		} else {
			layer.style.display = 'none';
		}
	}
}

Layer.prototype.MoveLayer = function() {
	var layer = document.getElementById(this.layerId);
	
	if(layer!=null && this.lyrSpeed>0 && layer.style.display!='none') {
		if(this.easeFactor>0 && this.easeFactor<=100) this.UpdateSpeed();
		this.UpdatePosition();
	}
}

Layer.prototype.UpdatePosition = function() {
	var layer = document.getElementById(this.layerId);
	var thisObjLyr = this;
	var newX = (parseFloat(layer.style.left) < this.endX)? parseFloat(layer.style.left) + parseFloat(this.dynSpeed/this.timeOutCalls): parseFloat(layer.style.left) - parseFloat(this.dynSpeed/this.timeOutCalls);
	var newY = (parseFloat(layer.style.top) < this.endY)? parseFloat(layer.style.top) + parseFloat(this.dynSpeed/this.timeOutCalls): parseFloat(layer.style.top) - parseFloat(this.dynSpeed/this.timeOutCalls);
	
	layer.style.left = (this.startX!=this.endX)? newX + "px": layer.style.left;
	layer.style.top = (this.startY!=this.endY)? newY + "px": layer.style.top;
	
	if(!this.IsEndPos()) window.setTimeout(function(){thisObjLyr.MoveLayer()}, this.moveTimeOut);
}

Layer.prototype.FadeOut = function() {
	var thisObjLyr = this;
	if(this.foTime > 0) {
		if(this.foPath != 'no') {
			thisObjLyr.timeoutFOid = window.setTimeout(function(){thisObjLyr.FOMove()}, thisObjLyr.foTime);
		} else {
			thisObjLyr.timeoutFOid = window.setTimeout(function(){thisObjLyr.HideLayer()}, thisObjLyr.foTime);
		}
	}
}

Layer.prototype.FOMove = function() {
	this.ChangeStartEndPos();
	this.MoveLayer();
}

Layer.prototype.IsLayerHidden = function() {
	var layer = document.getElementById(this.layerId);
	var hiddenX = ((0 - parseFloat(layer.style.left)) >= this.lyrWidth) ? true: false;
	var hiddenY = ((0 - parseFloat(layer.style.top)) >= this.lyrHeight) ? true: false;
	
	if(layer.style.display == 'none' || hiddenX || hiddenY) {
		return true;
	} else return false;
}

Layer.prototype.GetPosX = function() {
	var layer = document.getElementById(this.layerId);
	return layer.style.left;
}

Layer.prototype.GetPosY = function() {
	var layer = document.getElementById(this.layerId);
	return layer.style.top;
}

Layer.prototype.IsReadyToFadeOut = function() {
	if (this.dynSpeed == 0 || this.IsEndPos()) {
		this.FadeOut();
	} else {
		var thisObjLyr = this;
		window.setTimeout(function(){thisObjLyr.IsReadyToFadeOut()}, 1000);
	}
}

Layer.prototype.IsEndPos = function() {
	var layer = document.getElementById(this.layerId);
	var isEndPos = false;
	
	// layer no longer between start and end position
	if((parseFloat(layer.style.left) < this.startX && parseFloat(layer.style.left) <= this.endX) || (parseFloat(layer.style.left) > this.startX && parseFloat(layer.style.left) >= this.endX) || (parseFloat(layer.style.top) < this.startY && parseFloat(layer.style.top) <= this.endY) || (parseFloat(layer.style.top) > this.startY && parseFloat(layer.style.top) >= this.endY)) {
		isEndPos = true;
	}
	
	return isEndPos;
}

Layer.prototype.ChangeStartEndPos = function() {
	var helpVarX = this.startX;
	var helpVarY = this.startY;
	
	this.startX = this.endX;
	this.startY = this.endY;
	
	this.endX = helpVarX;
	this.endY = helpVarY;

	this.dynSpeed = this.lyrSpeed;
	this.easeFactor = 0;
}

Layer.prototype.UpdateSpeed = function() {
	var currDistToEnd = this.GetCurrentDist();
	var easePerMove = this.timeOutCalls/this.easeFactor;
	if(this.dynSpeed > 0 && currDistToEnd < 1/3*this.distance) {
		this.dynSpeed -= easePerMove*1.5;
	} else if(this.dynSpeed <= 0){
		this.dynSpeed = 0;
	}
}

Layer.prototype.GetCurrentDist = function() {
	var layer = document.getElementById(this.layerId);
	
	currDistToEnd = (this.startX != this.endX)? parseFloat(layer.style.left) - this.endX: parseFloat(layer.style.top) - this.endY;
	
	return Math.abs(currDistToEnd);
}

Layer.prototype.ResetToInit = function() {
	this.startX = this.initStartX;
	this.startY = this.initStartY;
	this.endX = this.initEndX;
	this.endY = this.initEndY;
	
	this.dynSpeed = this.lyrSpeed;
	this.easeFactor = this.initEaseFactor;
}