
/* ------------------- Start: Global Javascripts -- any theme can use these functions ------------------- */
	function GetObjRef (objId) {
		var returnObj = null;
		if (document.getElementById) {
			returnObj = document.getElementById(objId);
		}
		else if (document.all) {
			returnObj = document.all[objId];
		}
		return returnObj;
	}

	function GetTarget (e) {
		if (!e) {e = window.event;}
		if (!e) {return null;}
		var target;
		if (e.target) {
			target = e.target;
		}
		else if (e.srcElement) {
			target = e.srcElement;
		}
		return target;
	}
	function ReturnTarget (e, returnValue) {
		if (!e) {e = window.event;}
		if (!e) {return null;}
		var target;
		if (e.preventDefault && returnValue == false) {
			e.preventDefault ();
		}
		else if (e.returnValue) {
			e.returnValue = returnValue;
		}
		else {
			return returnValue;
		}
	}

	
	function GetBodyWidth () {
		if (document.body.clientWidth) {
			return document.body.clientWidth;
		}
		else if (document.width) {
			return document.width;
		}
		return null;
	}
	function GetBodyHeight () {
		if (document.body.clientHeight) {
			return document.body.clientHeight;
		}
		else if (document.height) {
			return document.height;
		}
		return null;
	}
	
	
	
	
	





	function SyncProp (prop, thisObjIds, targetObjIds, offsets, minValue, noresize) {
		if (offsets == null) {offsets = 0;}
		if (minValue == null) {minValue = -1;}
		if (noresize == null) {noresize = false;}
		var propL = prop.toLowerCase();

		var objPropValue = -1;
		var offset = 0;
		for (var i=0; i<thisObjIds.length; i++) {
			var thisObj = GetObjRef(thisObjIds[i]);
			if (thisObj && thisObj["offset" + prop]) {
				var tempOffset = 0;
				if (offsets[i]) {
					tempOffset = offsets[i];
				}
				else {
					tempOffset = offsets;
				}
				if (thisObj["offset" + prop] + tempOffset > objPropValue) {
					objPropValue = thisObj["offset" + prop] + tempOffset;
					offset = tempOffset;
				}
			}
		}
		if (objPropValue > -1) {
			if (objPropValue < minValue) {
				objPropValue = minValue;
			}
			for (var i=0; i<targetObjIds.length; i++) {
				var targetObj = GetObjRef(targetObjIds[i]);
				if (targetObj && targetObj.style) {
					var targetValue = objPropValue;
					targetObj.style[propL] = targetValue + "px";
				}
			}
		}
	}
	function SyncWidth (thisObjIds, targetObjIds, offsets, noresize) {
		return SyncProp ("Width", thisObjIds, targetObjIds, offsets, noresize);
	}
	function SyncHeight (thisObjIds, targetObjIds, offsets, noresize) {
		return SyncProp ("Height", thisObjIds, targetObjIds, offsets, noresize);
	}










	
	
	
	function SetMinForPosition (objId, prop1, prop2, minValue, defaultValue) {
		var obj = GetObjRef(objId);
		var offsetPropName = "offset" + prop1.charAt(0).toUpperCase() + prop1.substring(1, prop1.length);
		if (obj && obj.style) {
			obj.style[prop1] = "auto";
			obj.style[prop2] = defaultValue + "px";
			if (!obj[offsetPropName]) {
				trackingProp = obj.style[prop1];
			}
			if (obj[offsetPropName] < minValue) {
				obj.style[prop1] = minValue + "px";
				obj.style[prop2] = "auto";
				//GetObjRef("StatusH1").innerHTML = obj.style[prop1] + ";" + obj.style[prop2] ;
			}
		}
	}
	function SetMinLeftForRight (objId, minValue, defaultValue) {
		SetMinForPosition (objId, "left", "right", minValue, defaultValue)
	}
	function SetMinTopForBottom (objId, minValue, defaultValue) {
		SetMinForPosition (objId, "top", "bottom", minValue, defaultValue)
	}






	function SetWidthByRelativeObjects (objId, relativeObjIdArray, offset, left, minValue) {
		if (offset == null) { offset = 0;}
		if (minValue == null) { minValue = 0;}
		var thisObj = GetObjRef (objId);
		if (!thisObj) {
			return null;
		}
		var value2 = 0;
		for (var i=0; i<relativeObjIdArray.length; i++) {
			var tempObj = GetObjRef (relativeObjIdArray[i]);
			if (tempObj && tempObj.offsetWidth && value2 < (tempObj.offsetLeft + tempObj.offsetWidth)) {
				value2 = tempObj.offsetLeft + tempObj.offsetWidth;
			}
		}
		if (value2 < minValue) {
			value2 = minValue;
		}
		if (value2 != 0 || value2 < thisObj.offsetWidth) {
			if (thisObj.style) {
				thisObj.style.left = left + "px";
				thisObj.style.width = value2 + offset + "px";
			}
		}
	}
	function SetHeightByRelativeObjects (objId, relativeObjIdArray, offset, left, minValue) {
		if (offset == null) { offset = 0;}
		if (minValue == null) { minValue = 0;}
		var thisObj = GetObjRef (objId);
		if (!thisObj) {
			return null;
		}
		var value2 = 0;
		for (var i=0; i<relativeObjIdArray.length; i++) {
			var tempObj = GetObjRef (relativeObjIdArray[i]);
			if (tempObj && tempObj.offsetWidth && value2 < (tempObj.offsetTop + tempObj.offsetHeight)) {
				value2 = tempObj.offsetTop + tempObj.offsetHeight;
			}
		}
		if (value2 < minValue) {
			value2 = minValue;
		}
		if (value2 != 0 || value2 < thisObj.offsetHeight) {
			if (thisObj.style) {
				thisObj.style.top = left + "px";
				thisObj.style.height = value2 + offset + "px";
			}
		}
	}







	function SetWidthByPercentage (thisObjId, width, offset, parentObjId) {
		var thisObj = GetObjRef (thisObjId);
		if (offset == null) { offset = 0;}
		if (thisObj) {
			if (parentObjId == null) {
				if (document.body.clientWidth) {
					thisObj.style.width = Math.floor(document.body.clientWidth * width/100) + offset + "px";
				}
				else if (document.width) {
					thisObj.style.width = Math.floor(document.width * width/100) + offset + "px";
				}
			}
			else {
				var parentObj = GetObjRef (parentObjId);
				if (parentObj) {
					if (parentObj.offsetWidth) {
						thisObj.style.width = Math.floor(parentObj.offsetWidth * width/100) + offset + "px";
					}
				}
			}
		}
	}
	function SetHeightByPercentage (thisObjId, height, offset, parentObjId) {
		var thisObj = GetObjRef (thisObjId);
		if (offset == null) { offset = 0;}
		if (thisObj) {
			if (parentObjId == null) {
				if (document.body.clientHeight) {
					thisObj.style.height = Math.floor(document.body.clientHeight * height/100) + offset + "px";
				}
				else if (document.height) {
					thisObj.style.height = Math.floor(document.height * height/100) + offset + "px";
				}
			}
			else {
				var parentObj = GetObjRef (parentObjId);
				if (parentObj) {
					if (parentObj.offsetHeight) {
						thisObj.style.height = Math.floor(parentObj.offsetHeight * height/100) + offset + "px";
					}
				}
			}
		}
	}


	var pageName = "";
	/* START: Order Center */
		function OrderCenter_InitCountryStateDropDown (stateContainerId, countrySelectName) {
			if (document.forms["orderForm"] && pageName == "OrderCenter") {
				if (document.forms["orderForm"][countrySelectName]) {
					var stateContainer = GetObjRef (stateContainerId);
					if (stateContainer) {
						if (document.forms["orderForm"][countrySelectName].value.indexOf (",US,") > -1) {
							stateContainer.style.display = '';
						}
						else {
							stateContainer.style.display = "none";
						}
					}
				}
			}
		}
		function OrderCenter_SetStateByCountry (thisCountry, stateContainerId) {
			var stateContainer = GetObjRef (stateContainerId);
			if (stateContainer) {
				if (thisCountry.value.indexOf (",US,") > -1) {
					stateContainer.style.display = '';
				}
				else {
					stateContainer.style.display = "none";
				}
			}
		}
	/* END: Order Center */

/* -------------------  Start: Masthead Slideshow functions --------------------------------------- */

/* ---- Slideshow ---- */

function theSlideshow () {


	this.currentImage=1;
	this.speed=10;
	this.imageNum=5;
	this.officeId=0;
	

  
    	this.setOpacity= setOpacity;
    	this.fadeIn=fadeIn;
    	this.fadeOut=fadeOut;
    	this.startSlideshow=startSlideshow;
    	this.loadImages=loadImages;
  	this.playSlides= playSlides;

	function loadImages() {
		masterImage = document.getElementById('MastheadImage');
		/*imageUrl = masterImage.src;
		slashPos =(imageUrl.lastIndexOf('/'));
		imageUrl = imageUrl.substr(0,slashPos+1);*/
		masterImage.id = 'MastheadImage1';
		masterImage.src = "/download/" + this.officeId + "/masthead1.jpg";
		masterImage.style.position="absolute";
		masterImage.style.top = "0px";
		masterImage.style.left = "0px";
		masterParent = masterImage.parentNode;
		for (var x = 2; x <= this.imageNum; x++) {
			newImage=document.createElement('img');
			newImage.src="/download/" + this.officeId + "/masthead"+ x + ".jpg";
			newImage.height=masterImage.height;
			newImage.width=masterImage.width;
			newImage.style.position="absolute";
			newImage.style.top="0px";
			newImage.style.left="0px";
			newImage.style.display="none";
			newImage.id='MastheadImage' + x;
			masterParent.appendChild(newImage);
			}
	}

	function playSlides() {
		if (this.currentImage == this.imageNum) {
			nextImage = 1;
		}
		else {
			nextImage =  this.currentImage + 1;
		}
		currentImg=document.getElementById('MastheadImage'+ this.currentImage);	
		nextImg=document.getElementById('MastheadImage'+nextImage);	
		this.fadeOut(currentImg,100);
		this.fadeIn(nextImg,0);
		this.currentImage = nextImage;
		myGlobalVar = this;
      		window.setTimeout(function () {
			myGlobalVar.playSlides();
			}, this.speed * 1000);
	}
	
		
		
		
	function setOpacity(obj, opacity) {
 	 	opacity = (opacity == 100)?99.999:opacity;
  
  		// IE/Win
 	 	obj.style.filter = "alpha(opacity:"+opacity+")";
  
 	 	// Safari<1.2, Konqueror
 	 	obj.KHTMLOpacity = opacity/100;
  
 	 	// Older Mozilla and Firefox
 	 	obj.MozOpacity = opacity/100;
  
 	 	// Safari 1.2, newer Firefox and Mozilla, CSS3
 		 obj.style.opacity = opacity/100;
	}


	function fadeIn(obj,opacity) {
		obj.style.display="block";
    		if (opacity <= 100) {
      		this.setOpacity(obj,opacity);
      		opacity += 10;
		myGlobalVar = this;
      		window.setTimeout(function () {
			myGlobalVar.fadeIn(obj, opacity);
			}, 100);
    		}		
	}		

	function fadeOut(obj,opacity) {
		
    		if (opacity >=10) {
      		this.setOpacity(obj,opacity);
      		opacity -= 10;
		myGlobalVar = this;
      		window.setTimeout(function () {
			myGlobalVar.fadeOut(obj, opacity);
			}, 100);
    		}
		else {
			obj.style.display="none";
		}		
	}	


	function startSlideshow() {
		this.loadImages();
		myGlobalVar = this;
		window.setTimeout(function () {
			myGlobalVar.playSlides();
			}, this.speed * 1000);
	}


}

	

function Slideshow(officeNum,numberImages, slideSpeed) {
	var theShow = new theSlideshow();
	theShow.officeId=officeNum;
	if (numberImages) {
	theShow.imageNum=numberImages;
	}
	if (slideSpeed) {
	theShow.speed=slideSpeed;
	}
	if(window.addEventListener) {
	addEventListener('load',function () {
			theShow.startSlideshow();
			},false)
	} 
	else if(window.attachEvent) {
	attachEvent('onload',function () {
			theShow.startSlideshow();
			});
	}
}
		
/* ---- End Slideshow ---- */	

/* ---- Random Masthead Image ---- */


function getRandomNumber (size) {
	var ranNum= Math.floor(Math.random()*size);
	return ranNum;
}
	
function getRandomImage (officeNum,size){
	var randomNumber = getRandomNumber(size);
	var imageArray = new Array()
	for (var x = 0; x < size; x++)
		{	
		imageArray[x]="/download/" + officeNum + "/masthead" + (x+1) + ".jpg";
		}
	return imageArray[randomNumber];
	
}
	
function setRandomImage(officeNum,size) {
	document.getElementById('MastheadImage').src = getRandomImage(officeNum,size);
}


function RandomImage (officeNum,size) {
	if(window.addEventListener) {
	addEventListener('load',function () {
			setRandomImage(officeNum,size);
			},false)
	} 
	else if(window.attachEvent) {
	attachEvent('onload',function () {
			setRandomImage(officeNum,size);
			});
	}
}


		
/* ---- End Random Masthead Image ---- */	
	
/* -------------------  End: Masthead Slideshow functions --------------------------------------- */


/* ------------------- End: Global Javascripts -- any theme can use these functions ------------------- */

