///////////////
// Global Utilities
///////////////
var noPhotoImage = '/_graphics/noPhoto.gif';

function Browser() {
	var ua = ' ' + navigator.userAgent.toLowerCase();

	if (navigator.appVersion.indexOf("Win") > 0) this.OS = "Win";	
	if (navigator.appVersion.indexOf("Mac") > 0) this.OS = "Mac";
	if (navigator.appVersion.indexOf("Win") > 0) this.isWin = true;	
	if (navigator.appVersion.indexOf("Mac") > 0) this.isMac = true;	
	
	this.isID = (document.getElementById) ? true : false;

    //this.isIE = ua.indexOf('msie') >= 0;
	this.isIE = (ua.indexOf("msie") > 0 && ua.indexOf("opera") == -1 && ua.indexOf("webtv") == -1 && ua.indexOf("konqueror") == -1);// 
    this.isNN = (ua.indexOf('netscape') >= 0 || ua.indexOf('gecko') >= 0);
    this.isAOL = ua.indexOf('aol') >= 0; 

	//look for the overly easy to find version number 
	var iVersion = parseFloat(navigator.appVersion);
	if (this.isIE) {
	  var sInfo = navigator.appVersion.toLowerCase().indexOf('msie') + 5;
	  iVersion = parseFloat(navigator.appVersion.substring(sInfo));	  
	} else if (ua.indexOf('netscape') >= 0){
	  var sInfo = ua.lastIndexOf('/') + 1;
	  iVersion = parseFloat(ua.substring(sInfo,ua.length));
	}
	this.version = iVersion;
}
var browser = new Browser();

	
function browserMaxX() {
	if (browser.isNN) {
		maxX = window.scrollX + window.innerWidth;
	}
	if (browser.isIE) {
		maxX = (document.documentElement.scrollLeft  != 0 ?	 document.documentElement.scrollLeft : document.body.scrollLeft)
			 + (document.documentElement.clientWidth != 0 ?  document.documentElement.clientWidth : document.body.clientWidth);
	}
	return maxX
}

function browserMaxY() {
	if (browser.isNN) {
		maxY = window.scrollY + window.innerHeight;
	}
	if (browser.isIE) {
		maxY = (document.documentElement.scrollTop    != 0 ? document.documentElement.scrollTop : document.body.scrollTop)
			 + (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
	}
	return maxY
}

function getPageOffsetLeft(el) {
  var x;
  x = el.offsetLeft;
  if (el.offsetParent != null){
    x += getPageOffsetLeft(el.offsetParent);
  }
  return x;
}

function getPageOffsetTop(el) {
  var y;
  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);
  return y;
}

var imageSwapSrc=null;
var imageSwapDest=null;
function swapImage(image,swapWith){
	if (!document.getElementById && !image)return;	
	imageSwapDest = image
	imageSwapSrc = image.src;
	image.src = swapWith;
	image.onmouseout = swapImageRestore;
}

function swapImageRestore(){
	if (imageSwapSrc != null && imageSwapDest && document.getElementById){
		imageSwapDest.src = imageSwapSrc;
		imageSwapSrc=null; 
		imageSwapDest=null;
	}
}

function noPhoto(el,size){
	el.src = noPhotoImage;
	el.width = size;
	el.height = size;
}

// openWindow options ----------
//titlebar=yes,menubar=no,directories=no,toolbar=no,
//location=no,status=no,scrollbars=no,resizable=yes
function openWindow(url, title, w, h, o, position) {
	if (position == 'center') {
		windowLeft = (screen.availWidth / 2) - (w / 2);
		windowTop = (screen.availHeight / 2) - (h / 2);	
		o +=',left='+windowLeft+',top='+windowTop;
	}else if (position == 'topLeft'){
		o +=',top=0,left=0';
	}else if (position == 'showBlueNav'){
		w = screen.availWidth - 157 - 12;
		h = w * .73;
		windowLeft = 157;	
		windowTop = 0;	
		o +=',left='+windowLeft+',top='+windowTop;
	}

	if (url.indexOf("?") != -1){//send the window size to popup
		var urlModifyer = '&';
	}else{
		var urlModifyer = '?';
	}
	url = url + urlModifyer + 'popupWidth=' + w + '&popupHeight=' + h;
	
	windowprops = "width=" + w + ",height=" + h + o;
	popup = window.open(url,title,windowprops);
	popup.focus();
}


//show select box when menu is hidden
function showSelect(){
	var obj;
	for(var i = 0; i < document.getElementsByTagName("select").length; i++){
		obj = document.getElementsByTagName("select")[i];
		if(!obj || !obj.offsetParent)
			continue;
		obj.style.visibility = 'visible';
	}
}

//hide select box when menu is visible
function hideSelect(activeLayer){
	var obj, currentEle, menuHeight;
	var top = 0;
	var left = 0;
	

	for(var i = 0; i < document.getElementsByTagName("select").length; i++){
		obj = document.getElementsByTagName("select")[i];
		currentEle = obj;
		top = getPageOffsetTop(currentEle);
		left = getPageOffsetLeft(currentEle);
		bottom = top + obj.offsetHeight;
		right = left + obj.offsetWidth;
			
		if(activeLayer != null){
			menuBottom = (activeLayer.offsetTop + activeLayer.offsetHeight);
			menuRight = (activeLayer.offsetLeft + activeLayer.offsetWidth);
			menuTop = activeLayer.offsetTop;
			menuLeft = activeLayer.offsetLeft;
				if(top < menuBottom && bottom > menuTop && left < menuRight && right > menuLeft){ 
					obj.style.visibility = 'hidden';
				}else{
					obj.style.visibility = 'visible';
				}
		}
		top = left = 0;
	}
}

function shakeWindow(n,x,y) {
	if(browser.isIE && (browser.isWin) && (!browser.isAOL)){
		if (parent.moveBy) {
			for (i = n; i > 0; i--) {
				for (j = (n/2); j > 0; j--) {
					if (y==1) {parent.moveBy(0,i)};y
					if (x==1) {parent.moveBy(i,0)};x
					if (y==1) {parent.moveBy(0,-i)};y
					if (x==1) {parent.moveBy(-i,0)};x
         			}
     			}
  		}
	}
}

//cps = countryPathSelected
function cpsSubmit(cps) {
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + (5 * 365 * 24*60*60*1000));
	set_Cookie("cps", cps, expdate);
	document.location.href = "http://" + cps;
}

function inputswap(el,compTo,setTo) {
	if(el.value==compTo) {
		el.value=setTo;
	}
}