//JABR MOSS SITE SCRIPTS Do not mdify or delete
var selectedLinkTabId;
function SI_body() {
	var d = document;
	
	if (d.body && d.body.style) {
		d.body.style.height = "26px";
		d.body.style.height = "auto";
		}
	}

function SI_positionFooter() {
	var d = document,w=window,dE=d.documentElement,dB=d.body;;
	if (!d.getElementById || !d.body.offsetHeight) return;
	
	// Reset our footer's margin-top...
	var footer = d.getElementById('footer');

	if (!footer) return;
	
	var mt = (footer.style.marginTop)?parseInt(footer.style.marginTop):0;
	
	var windowH	= (typeof(w.innerHeight)=='number')?w.innerHeight:(dE&&dE.clientHeight)?dE.clientHeight:(dB&&dB.clientHeight)?dB.clientHeight:0;
	
	var contentH	= d.getElementById('container').offsetHeight - mt;
	
	
	var footerMT	= (contentH <= windowH)?windowH-contentH:0;
	if (footerMT>0) {
		d.getElementById('footer').style.marginTop = footerMT + 'px';
		}
	}
	
function SI_init() {
	SI_positionFooter();
	SI_body();
	
	}
window.onload = SI_init; 
window.onresize = SI_positionFooter;
//**************************// FAQ expand / collapse  END //************************************

function MM_swapImgRestore() { //v3.0
	
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//v3.0
function MM_swapImage()
{
    var i,j=0,x,a=MM_swapImage.arguments;
    document.MM_sr=new Array;
    for(i=0;i<(a.length-2); i += 3)
    {
        if ((x=MM_findObj(a[i]))!=null)
        {
            document.MM_sr[j++]=x;  
            x.oSrc=x.src; x.src=a[i+2];
        }
    }
}

function swap603(id, index, image)
{
    for(i = index; i > 0; i--)
    {
        var idcurrent = id.replace(eval('/star' + index + '/'), 'star' + i.toString())
        var img = document.getElementById(idcurrent);
        img.src = image;
    }
}

/*
 * -----------------------------------------
 * C605(ProductSelectBox)
 * -----------------------------------------
 */
    //var currentImageIndex = 0;
	function ShowNextImage(id, index,pInfo)
		{
			index--;
			if(index < 0)
			{
				index = pInfo.length-1;				
			}			
			var a = document.getElementById(id+'_currentImage');
			a.innerHTML = pInfo[index].productImage;	
			a.href = pInfo[index].productLink;		
			document.getElementById(id+'_productLinkId').innerHTML = pInfo[index].productDisplayName;
			document.getElementById(id+'_productLinkId').href = pInfo[index].productLink;
			return index;
		}
		function ShowPreviousImage(id, index,pInfo)
		{	
			index++;
			if(index >pInfo.length-1)
			{
    			index =0;	
			}				    		
			var a = document.getElementById(id+'_currentImage');
			a.innerHTML = pInfo[index].productImage;	
			a.href = pInfo[index].productLink;				    
			
			document.getElementById(id+'_productLinkId').innerHTML = pInfo[index].productDisplayName;
			document.getElementById(id+'_productLinkId').href = pInfo[index].productLink;					
			return index;
		}

        function ShowNextAccessory(id, index,pInfo)
		{
		     index++;
			if(index >pInfo.length-1)
			{
    			index =0;	
			}				    		
			var a = document.getElementById(id+'_currentImage');
			a.innerHTML = pInfo[index].productImage;	
			a.href = pInfo[index].productLink;				    
			
			document.getElementById(id+'_productLinkId').innerHTML = pInfo[index].productDisplayName;
			document.getElementById(id+'_productLinkId').href = pInfo[index].productLink;					
			return index;
		}
	
	    function ShowPreviousAccessory(id, index,pInfo)
		{	
			
            index--;
			if(index < 0)
			{
				index = pInfo.length-1;				
			}			
			var a = document.getElementById(id+'_currentImage');
			a.innerHTML = pInfo[index].productImage;	
			a.href = pInfo[index].productLink;		
			document.getElementById(id+'_productLinkId').innerHTML = pInfo[index].productDisplayName;
			document.getElementById(id+'_productLinkId').href = pInfo[index].productLink;
			return index;
		}

//************************** FAQ expand / collapse  ************************************

	var _h  = {};
// constructor
_h.Tree = function(id) { 
		
//img/htree_item.gif
		this.id = id;
		this.cookiePath = "/";
		this.useIcons   = true;
		this.useCookies = false;
		this.foldersAsLinks = false;
		this.oneSibling = true;
		this.icon = {
			align    :  "left",
			open		:	"/sites/Jabra/Style Library/Images/arrow_open.gif",
			closed	    :	"/sites/Jabra/Style Library/Images/arrow_closed.gif",
			item		:	"/sites/Jabra/Style Library/Images/blank.gif"
		};
		this.navigation = this._keyNavigation;
};
_h.Tree.prototype.isSupported = (document.createElement &&
											document.getElementById && 
											document.getElementsByTagName);
_h.Tree.prototype.build = function() {
	if (!this.isSupported) return;
	this._list = document.getElementById(this.id);
	if (!this._list) return;
	this._list.className = "hTreeJS";
	var aLI = this._list.getElementsByTagName("li");
	for (var i=0;i<aLI.length;i++) {
		var oLI			= aLI[i];
		var aUL = oLI.getElementsByTagName("ul");
		if (aUL.length>0) {
			var oUL = aUL[0];
			oLI._hTree_folder = true;
			oUL.setAttribute('id',this.id+'-'+i);
			this.CreateTreeFolder(oLI,oUL);
		} else {
			oLI._hTree_folder = false;
			this.CreateTreeItem(oLI);
		}
	}
};
_h.Tree.prototype.CreateTreeFolder = function( oLI, oUL ) {
		var me = this;

		if (this.useCookies) { oLI._hTree_open = ((_h.getCookie(oUL.id)) == '1')?true:false; }
		oLI._hTree_open = (_h.hasClass(oUL, "open"))?true:oLI._hTree_open;
		oLI._hTree_open = (_h.hasClass(oUL, "closed"))?false:oLI._hTree_open;
		
/* Link */
		var aLinks = oLI.getElementsByTagName("a");
		if (!aLinks) this.CreateTreeItem(oLI); 
		
		var oLink = aLinks[0];
		if (oLink.parentNode != oLI) this.CreateTreeItem(oLI); 
		
		if (this.foldersAsLinks == false) { 
			oLink.href = "#";
			oLink.onclick = function() {
				me.toggle(oLI);
				return false;
			}
		}
		oLink.onkeydown = function(e) {
			var code;
			if (!e) var e = window.event;
			if (e.keyCode) code = e.keyCode;
			else if (e.which) code = e.which;
			me.navigation(code, oLI);
		}
		
		oLink._hTree_oLI = oLI;


/* IMG */		
		var oIMG = null;
		if (this.useIcons) {
			oIMG = document.createElement("img");

			oIMG.src = oLI._hTree_open ? this.icon.open : this.icon.closed;
			oIMG.alt = oLI._hTree_open ? "-": "+";
			oIMG.onclick = function() {
				me.toggle(oLI);
				return false;
			}
			oIMG._hTree_oLI = oLI;

			if (this.icon.align == "left") {
				oLI.insertBefore(oIMG,oLink);
			} else {
				oLI.insertBefore(oIMG,oLink.nextSibling);
			}
		}
		
		oLI._hTree_oUL		= oUL;
		oLI._hTree_oIMG	= oIMG;
		oLI._hTree_oLink  = oLink;

		oUL._hTree_oLI		= oLI;
		oUL.style.display = oLI._hTree_open?'block':'none'; 
	};
			
_h.Tree.prototype.CreateTreeItem = function(oLI) {
		var me = this;
		
		var aLinks = oLI.getElementsByTagName("a");
		if (aLinks) {
			var oLink = aLinks[0];
			if (oLink) {
				if (oLink.parentNode == oLI) {
					oLink.onkeydown = function(e) {
						var code;
						if (!e) var e = window.event;
						if (e.keyCode) code = e.keyCode;
						else if (e.which) code = e.which;
						me.navigation(code, oLI);
					}
				}
				oLI._hTree_oLink  = oLink;
			}		
		}

		oLI._hTree_open = false;

		if (this.useIcons) {
			var oIMG = document.createElement("img");

			oIMG.src = this.icon.item;
			oIMG.alt = ""; //alt-text on item img
			if (this.icon.align == "left") {
				oLI.insertBefore(oIMG,oLI.firstChild);	// 
				//oLI.insertBefore(oIMG,oLI.firstChild);	
			} else {
				oLI.insertBefore(oIMG,oLI.firstChild.nextSibling);	
			}
		}
	};							
_h.Tree.prototype.toggle = function (oLI) {
		if (oLI._hTree_folder == true) {
			if (oLI._hTree_open == true) { 
				this.collapse(oLI); 
			} else { 
				if (this.oneSibling == true) {
					this.closeSiblings(oLI);
				}
				this.expand(oLI); 
			}
		}
	};
_h.Tree.prototype.collapse = function (oLI) {
		var oIMG = oLI._hTree_oIMG;
		var oUL	= oLI._hTree_oUL;
	
		oUL.style.display = "none";
		if (oIMG) {
			oIMG.src = this.icon.closed;
			oIMG.alt = "+";
		}
		oLI._hTree_open = false;
		_h.setCookie(oUL.id, "0", this.cookiePath); 
}	
_h.Tree.prototype.expand = function (oLI) {
		var oIMG = oLI._hTree_oIMG;
		var oUL	= oLI._hTree_oUL;

		oUL.style.display = "block";  
		if (oIMG) {
			oIMG.src = this.icon.open;
			oIMG.alt = "-";
		}
		oLI._hTree_open = true;
		_h.setCookie(oUL.id, "1", this.cookiePath);
}	
_h.Tree.prototype.select = function(oLI) {
		if (oLI._hTree_oLink)
			oLI._hTree_oLink.focus()
};
_h.Tree.prototype.closeSiblings = function(oLI) {
		var oUL = oLI.parentNode;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x] != oLI) {
				if (oUL.childNodes[x]._hTree_open) {
					this.collapse(oUL.childNodes[x]);
				}
			}
		}
};
_h.Tree.prototype.getNextLI = function(oLI) {
		var oUL = oLI.parentNode;
		var bCurrentLI = false;
		for (var x=0; x < oUL.childNodes.length; x++) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oLI == oUL.childNodes[x]) {
				bCurrentLI = true;
				continue;
			}
			if (bCurrentLI == true) {
				return oUL.childNodes[x];
			}
		}
		return this.getNextLI(oUL.parentNode);
};
_h.Tree.prototype.getPrevLI = function(oLI) {
		var oUL = oLI.parentNode;
		var bCurrentLI = false;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x] == oLI) {
				bCurrentLI = true;
				continue;
			}
			if (bCurrentLI == true) {
				if (oUL.childNodes[x]._hTree_open) {
					return this.getLast(oUL.childNodes[x]);
				} else {
					return oUL.childNodes[x];
				}
			}
		}
		return oUL.parentNode;
};
_h.Tree.prototype.getLast = function(oLI) {
		var oUL = oLI._hTree_oUL;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x]._hTree_open) {
				return this.getLast(oUL.childNodes[x]);
			} else {
				return oUL.childNodes[x];
			}
		}
};
_h.Tree.prototype._keyNavigation = function(code, oLI) {	
		if ((code == 37) || (code == 38) || (code == 39) || (code == 40)) {
			var oIMG = oLI._hTree_oIMG;
			var oUL	= oLI._hTree_oUL;
			
			if (code == 37) { /* Left */
				if (oLI._hTree_open) {
					this.toggle(oLI);
				} else {
					this.select(oLI.parentNode.parentNode);
				}
			} else if (code == 38) { /* Up */
				var oLI_prev =  this.getPrevLI(oLI); 
				if (oLI_prev) { this.select(oLI_prev);}
				return false;
			} else if (code == 39) { /* Right */
				if (oLI._hTree_open) {
					if (oLI.getElementsByTagName("li")) {
						this.select(oLI.getElementsByTagName("li")[0])
					}
				} else {
					this.toggle(oLI);
				}
			} else if (code == 40) { /* Down */
				if (oLI._hTree_open) {
					if (oLI.getElementsByTagName("li")) {
						this.select(oLI.getElementsByTagName("li")[0])
					}
				} else {
					var oLI_next = this.getNextLI(oLI);
					if (oLI_next) { this.select(oLI_next); }
				}
			}
		} else {
			return true;
		}
};


// Helper functions
_h.getCookie = function(name) { 
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) {
			var endstr = document.cookie.indexOf (";", j);
			if (endstr == -1) endstr = document.cookie.length;
			return unescape(document.cookie.substring(j, endstr));
 		}
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}
_h.setCookie = function(key, value, path) {
	document.cookie= key + "=" + escape(value) + ((path) ? "; path=" + path : "");
}
_h.hasClass = function (el, className) {
	var cs, j
	cs = el.className.split(" ");
	for (j = 0; j < cs.length; j++) {
		if (cs[j] == className) {
			return true;
		}
	}
	return false;
} 
_h.addClass = function (el, className) {
	if (el.className==null) 
		el.className='';
	el.className+=(el.className.length>0?' ':'')+className;
}
_h.removeClass = function (el, className) {
  var cs, j, remainClass
  remainClass = new Array();
  cs = el.className.split(" ");
  for (j = 0; j < cs.length; j++) {
    if (cs[j] != className) {
      remainClass.push(cs[j]);
	 }
  }
  el.className = remainClass.join(" ");
}
_h.addEvent = function (oEl, sEvent, sFunction, useCapture) {	
	if (oEl) {
		if (oEl.addEventListener) { // MOZ
			oEl.addEventListener(sEvent,sFunction,useCapture);
			return true;
		} else if (oEl.attachEvent) { // IE5
			var r = oEl.attachEvent("on"+sEvent,sFunction);
			return r;
//		} else if (document.all) { // IE4
//			eval('oEl.on'+sEvent+'='+sFunction+';');
//		} else {
//		  alert("Handler could not be attached");
		}
	}
}

// Array.push() - Add an element to the end of an array
if (typeof(Array.prototype.push) == 'undefined') {
  Array.prototype.push = function() {
  	var currentLength = this.length;
  	for (var i = 0; i < arguments.length; i++) {
  		this[currentLength + i] = arguments[i];
  	}
  	return this.length;
  };
}

//**************************// FAQ expand / collapse  END //************************************ 

//********************** expand / collapse for sitemap START //**********************
var _s  = {};
// constructor
_s.SiteTree = function(id) { 
		
//img/htree_item.gif
		this.id = id;
		this.cookiePath = "/";
		this.useIcons   = true;
		this.useCookies = false;
		this.foldersAsLinks = false;
		this.oneSibling = true;
		this.icon = {
			align    :  "left",
			open		:	"../Images/black_open1_1601.gif",
			closed	    :	"../Images/black_closed1_1601.gif",
			item		:	"../Images/red_closed_1601.gif"
		};
		this.navigation = this._keyNavigation;
};
_s.SiteTree.prototype.isSupported = (document.createElement &&
											document.getElementById && 
											document.getElementsByTagName);
_s.SiteTree.prototype.build = function() {
	if (!this.isSupported) return;
	this._list = document.getElementById(this.id);
	if (!this._list) return;
	this._list.className = "sSiteTreeJS";
	var aLI = this._list.getElementsByTagName("li");
	for (var i=0;i<aLI.length;i++) {
		var oLI			= aLI[i];
		var aUL = oLI.getElementsByTagName("ul");
		if (aUL.length>0) {
			var oUL = aUL[0];
			oLI._sSiteTree_folder = true;
			oUL.setAttribute('id',this.id+'-'+i);
			this.CreateSiteTreeFolder(oLI,oUL);
		} else {
			oLI._sSiteTree_folder = false;
			this.CreateSiteTreeItem(oLI);
		}
	}
};
_s.SiteTree.prototype.CreateSiteTreeFolder = function( oLI, oUL ) {
		var me = this;

		if (this.useCookies) { oLI._sSiteTree_open = ((_s.getCookie(oUL.id)) == '1')?true:false; }
		oLI._sSiteTree_open = (_s.hasClass(oUL, "open"))?true:oLI._sSiteTree_open;
		oLI._sSiteTree_open = (_s.hasClass(oUL, "closed"))?false:oLI._sSiteTree_open;
		
/* Link */
		var aLinks = oLI.getElementsByTagName("a");
		if (!aLinks) this.CreateSiteTreeItem(oLI); 
		
		var oLink = aLinks[0];
		if (oLink.parentNode != oLI) this.CreateSiteTreeItem(oLI); 
		
		if (this.foldersAsLinks == false) { 
			oLink.href = "#";
			oLink.onclick = function() {
				me.toggle(oLI);
				return false;
			}
		}
		oLink.onkeydown = function(e) {
			var code;
			if (!e) var e = window.event;
			if (e.keyCode) code = e.keyCode;
			else if (e.which) code = e.which;
			me.navigation(code, oLI);
		}
		
		oLink._sSiteTree_oLI = oLI;


/* IMG */		
		var oIMG = null;
		if (this.useIcons) {
			oIMG = document.createElement("img");

			oIMG.src = oLI._sSiteTree_open ? this.icon.open : this.icon.closed;
			oIMG.alt = oLI._sSiteTree_open ? "-": "+";
			oIMG.onclick = function() {
				me.toggle(oLI);
				return false;
			}
			oIMG._sSiteTree_oLI = oLI;

			if (this.icon.align == "left") {
				oLI.insertBefore(oIMG,oLink);
			} else {
				oLI.insertBefore(oIMG,oLink.nextSibling);
			}
		}
		
		oLI._sSiteTree_oUL		= oUL;
		oLI._sSiteTree_oIMG	= oIMG;
		oLI._sSiteTree_oLink  = oLink;

		oUL._sSiteTree_oLI		= oLI;
		oUL.style.display = oLI._sSiteTree_open?'block':'none'; 
	};
			
_s.SiteTree.prototype.CreateSiteTreeItem = function(oLI) {
		var me = this;
		
		var aLinks = oLI.getElementsByTagName("a");
		if (aLinks) {
			var oLink = aLinks[0];
			if (oLink) {
				if (oLink.parentNode == oLI) {
					oLink.onkeydown = function(e) {
						var code;
						if (!e) var e = window.event;
						if (e.keyCode) code = e.keyCode;
						else if (e.which) code = e.which;
						me.navigation(code, oLI);
					}
				}
				oLI._sSiteTree_oLink  = oLink;
			}		
		}

		oLI._sSiteTree_open = false;

		if (this.useIcons) {
			var oIMG = document.createElement("img");

			oIMG.src = this.icon.item;
			oIMG.alt = ""; //alt-text on item img
			if (this.icon.align == "left") {
				oLI.insertBefore(oIMG,oLI.firstChild);	// 
				//oLI.insertBefore(oIMG,oLI.firstChild);	
			} else {
				oLI.insertBefore(oIMG,oLI.firstChild.nextSibling);	
			}
		}
	};							
_s.SiteTree.prototype.toggle = function (oLI) {
		if (oLI._sSiteTree_folder == true) {
			if (oLI._sSiteTree_open == true) { 
				this.collapse(oLI); 
			} else { 
				if (this.oneSibling == true) {
					this.closeSiblings(oLI);
				}
				this.expand(oLI); 
			}
		}
	};
_s.SiteTree.prototype.collapse = function (oLI) {
		var oIMG = oLI._sSiteTree_oIMG;
		var oUL	= oLI._sSiteTree_oUL;
	
		oUL.style.display = "none";
		if (oIMG) {
			oIMG.src = this.icon.closed;
			oIMG.alt = "+";
		}
		oLI._sSiteTree_open = false;
		_s.setCookie(oUL.id, "0", this.cookiePath); 
}	
_s.SiteTree.prototype.expand = function (oLI) {
		var oIMG = oLI._sSiteTree_oIMG;
		var oUL	= oLI._sSiteTree_oUL;

		oUL.style.display = "block";  
		if (oIMG) {
			oIMG.src = this.icon.open;
			oIMG.alt = "-";
		}
		oLI._sSiteTree_open = true;
		_s.setCookie(oUL.id, "1", this.cookiePath);
}	
_s.SiteTree.prototype.select = function(oLI) {
		if (oLI._sSiteTree_oLink)
			oLI._sSiteTree_oLink.focus()
};
_s.SiteTree.prototype.closeSiblings = function(oLI) {
		var oUL = oLI.parentNode;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x] != oLI) {
				if (oUL.childNodes[x]._sSiteTree_open) {
					this.collapse(oUL.childNodes[x]);
				}
			}
		}
};
_s.SiteTree.prototype.getNextLI = function(oLI) {
		var oUL = oLI.parentNode;
		var bCurrentLI = false;
		for (var x=0; x < oUL.childNodes.length; x++) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oLI == oUL.childNodes[x]) {
				bCurrentLI = true;
				continue;
			}
			if (bCurrentLI == true) {
				return oUL.childNodes[x];
			}
		}
		return this.getNextLI(oUL.parentNode);
};
_s.SiteTree.prototype.getPrevLI = function(oLI) {
		var oUL = oLI.parentNode;
		var bCurrentLI = false;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x] == oLI) {
				bCurrentLI = true;
				continue;
			}
			if (bCurrentLI == true) {
				if (oUL.childNodes[x]._sSiteTree_open) {
					return this.getLast(oUL.childNodes[x]);
				} else {
					return oUL.childNodes[x];
				}
			}
		}
		return oUL.parentNode;
};
_s.SiteTree.prototype.getLast = function(oLI) {
		var oUL = oLI._sSiteTree_oUL;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x]._sSiteTree_open) {
				return this.getLast(oUL.childNodes[x]);
			} else {
				return oUL.childNodes[x];
			}
		}
};
_s.SiteTree.prototype._keyNavigation = function(code, oLI) {	
		if ((code == 37) || (code == 38) || (code == 39) || (code == 40)) {
			var oIMG = oLI._sSiteTree_oIMG;
			var oUL	= oLI._sSiteTree_oUL;
			
			if (code == 37) { /* Left */
				if (oLI._sSiteTree_open) {
					this.toggle(oLI);
				} else {
					this.select(oLI.parentNode.parentNode);
				}
			} else if (code == 38) { /* Up */
				var oLI_prev =  this.getPrevLI(oLI); 
				if (oLI_prev) { this.select(oLI_prev);}
				return false;
			} else if (code == 39) { /* Right */
				if (oLI._sSiteTree_open) {
					if (oLI.getElementsByTagName("li")) {
						this.select(oLI.getElementsByTagName("li")[0])
					}
				} else {
					this.toggle(oLI);
				}
			} else if (code == 40) { /* Down */
				if (oLI._sSiteTree_open) {
					if (oLI.getElementsByTagName("li")) {
						this.select(oLI.getElementsByTagName("li")[0])
					}
				} else {
					var oLI_next = this.getNextLI(oLI);
					if (oLI_next) { this.select(oLI_next); }
				}
			}
		} else {
			return true;
		}
};


// Helper functions
_s.getCookie = function(name) { 
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) {
			var endstr = document.cookie.indexOf (";", j);
			if (endstr == -1) endstr = document.cookie.length;
			return unescape(document.cookie.substring(j, endstr));
 		}
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}
_s.setCookie = function(key, value, path) {
	document.cookie= key + "=" + escape(value) + ((path) ? "; path=" + path : "");
}
_s.hasClass = function (el, className) {
	var cs, j
	cs = el.className.split(" ");
	for (j = 0; j < cs.length; j++) {
		if (cs[j] == className) {
			return true;
		}
	}
	return false;
} 
_s.addClass = function (el, className) {
	if (el.className==null) 
		el.className='';
	el.className+=(el.className.length>0?' ':'')+className;
}
_s.removeClass = function (el, className) {
  var cs, j, remainClass
  remainClass = new Array();
  cs = el.className.split(" ");
  for (j = 0; j < cs.length; j++) {
    if (cs[j] != className) {
      remainClass.push(cs[j]);
	 }
  }
  el.className = remainClass.join(" ");
}
_s.addEvent = function (oEl, sEvent, sFunction, useCapture) {	
	if (oEl) {
		if (oEl.addEventListener) { // MOZ
			oEl.addEventListener(sEvent,sFunction,useCapture);
			return true;
		} else if (oEl.attachEvent) { // IE5
			var r = oEl.attachEvent("on"+sEvent,sFunction);
			return r;
//		} else if (document.all) { // IE4
//			eval('oEl.on'+sEvent+'='+sFunction+';');
//		} else {
//		  alert("Handler could not be attached");
		}
	}
}

// Array.push() - Add an element to the end of an array
if (typeof(Array.prototype.push) == 'undefined') {
  Array.prototype.push = function() {
  	var currentLength = this.length;
  	for (var i = 0; i < arguments.length; i++) {
  		this[currentLength + i] = arguments[i];
  	}
  	return this.length;
  };
}

//**************************// expand / collapse for sitemap END //************************************

 
    function COWSetProductDropDown(elm) {
        var sel = document.getElementById('selectproductname');
        if (elm.value != '') {
            if (allproductlist) {
                var i=0;
                var len = 1;
                if (sel) {
                    sel.options.length=1;
                }
                for (var i=0;i<allproductlist.length;i++) {
                    if (elm.value == allproductlist[i].family) {
                        sel.options.length = sel.options.length + 1;
                        sel.options[len].value = i;
                        sel.options[len].text = allproductlist[i].name;
                        len = len + 1;
                    }
                }
                sel.disabled = false;
            }
        } else {
            sel.options.length = 1;
            sel.disabled=true;
        }
    }
    
    function COWSelectProduct(elm) {
        if (elm.value != '') {
            if (allproductlist) {
                var url = allproductlist[elm.value].url;
                window.location = url;
            }
        }
    }

//************************** Component 102 Start ************************************  

function CMASelectCategory(elm) {
    window.location = elm.value;
}

//************************** Component 102 End ************************************ 
 
//************************** Component 501 Starts *********************************
var AllChoiceSets = new Array();

function Choice(id) 
{ 
    this.id = id;
    this.isOn = false; 
    this.isEnabled = false;
}

function ChoicesSet()
{
    var choices;
    var formvarid;
}

function VerifyChoices(products)
{
    for(var formvarid in AllChoiceSets)
    {
        var choicesObject = AllChoiceSets[formvarid];
        var formelement = document.getElementById(formvarid);
        for(var choiceid in choicesObject.choices)
        {
            var yes = false;
            choiceobject = choicesObject.choices[choiceid];
            for(var idx in products)
            {
                yes |= products[idx][choiceid];
                if(yes)
                {
                    choiceobject.isEnabled = true;
                    var optionobjectlabel = document.getElementById(lblval + choiceid);
                    if(optionobjectlabel != null)
                    {
                        optionobjectlabel.className = 'w200_tx_501';
                    }
                    else if(formelement.tagName == "SELECT")
                    {
                        PopulateSelect(formelement, choiceid, true);
                    }
                    break;
                }
            }
            if(!yes)
            {
                choiceobject.isEnabled = false;
                var optionobjectlabel = document.getElementById(lblval + choiceid);
                if(optionobjectlabel != null)
                {
                    optionobjectlabel.className = 'w200_tx_501_disab';
                }
                else if(formelement.tagName == "SELECT")
                {
                    PopulateSelect(formelement, choiceid, false);
                }
            }
        }
    }
}

function Switch(choiceid)
{
    var choicesObject = GetChoicesObject(choiceid);
    if(choicesObject != null)
    {
        var choiceobject = choicesObject.choices[choiceid];
        
        if(choiceobject.isEnabled)
        {
            var formelement = document.getElementById(choicesObject.formvarid);
            if(formelement.tagName == "SELECT")
            {
                for(var id in choicesObject.choices)
                {
                    choicesObject.choices[id].isOn = false;
                }
                if(formelement.value != '')
                {
                    choiceobject.isOn = true;
                }
            }
            else
            {
                var choiceimg = document.getElementById(imgval + choiceid);
                if(choiceimg != null)
                {
                    if(choiceimg.src == imgoff.src)
                    {
                        choiceobject.isOn = true;
                        choiceimg.src = imgon.src;
                        UnSelectOthers(choicesObject, choiceid);
                    }
                    else
                    {
                        choiceobject.isOn = false;
                        choiceimg.src = imgoff.src;
                    }
                }
                formelement.value = choiceid;
            }
            if(SomeSelected())
            {
                
                VerifyOtherChoices(choiceid);
                Search();
            }
            else
            {
                VerifyChoices(Search());
            }
        }
    }
}

function VerifyOtherChoices(choiceid)
{
    var choicesObjectForCurrent = GetChoicesObject(choiceid);

    var resultsForOtherChoices = new Array();
    var otherOnChoices = new Array();
    for(var formvarid in AllChoiceSets)
    {
        var choicesObject = AllChoiceSets[formvarid];
        if(formvarid != choicesObjectForCurrent.formvarid)
        {
            for(var idt in choicesObject.choices)
            {
                if(choicesObject.choices[idt].isOn)
                {
                    otherOnChoices[idt] = choicesObject.choices[idt];
                }
            }
        }
    }
    
    for(var idx1 in p)
    {
        var yes = true;
        for(var id1 in otherOnChoices)
        {
            yes &= p[idx1][id1];
        }
        if(yes && resultsForOtherChoices[p[idx1].FamilyId] == null)
        {
            resultsForOtherChoices[p[idx1].FamilyId] = p[idx1];
            resultsForOtherChoices[p[idx1].FamilyId].ProductId = p[idx1].ProductId;
            resultsForOtherChoices[p[idx1].FamilyId].FamilyId = p[idx1].FamilyId;
        }
    }

    for(var formvarid in AllChoiceSets)
    {
        var resultsToScan;
        var choicesObject = AllChoiceSets[formvarid];
        if(formvarid != choicesObjectForCurrent.formvarid)
        {
            resultsToScan = GetResultsForOtherChoices(choicesObject);
        }
        else
        {
            resultsToScan = resultsForOtherChoices;
        }
        
        var formelement = document.getElementById(formvarid);
        for(var id in choicesObject.choices)
        {
            var yes = false;
            choiceobject = choicesObject.choices[id];
            for(var idx in resultsToScan)
            {
                yes |= resultsToScan[idx][id];
                if(yes)
                {
                    choiceobject.isEnabled = true;
                    var optionobjectlabel = document.getElementById(lblval + id);
                    if(optionobjectlabel != null)
                    {
                        optionobjectlabel.className = 'w200_tx_501';
                    }
                    else if(formelement.tagName == "SELECT")
                    {
                        PopulateSelect(formelement, id, true);
                    }
                    break;
                }
            }
            if(!yes)
            {
                choiceobject.isEnabled = false;
                var optionobjectlabel = document.getElementById(lblval + id);
                if(optionobjectlabel != null)
                {
                    optionobjectlabel.className = 'w200_tx_501_disab';
                }
                else if(formelement.tagName == "SELECT")
                {
                    PopulateSelect(formelement, id, false);
                }
            }
        }
    }
}

function GetResultsForOtherChoices(choicesObject)
{
    var resultsForOtherChoices = new Array();
    var otherOnChoices = new Array();
    for(var formvarid in AllChoiceSets)
    {
        if(formvarid != choicesObject.formvarid)
        {
            for(var idt in AllChoiceSets[formvarid].choices)
            {
                if(AllChoiceSets[formvarid].choices[idt].isOn)
                {
                    otherOnChoices[idt] = AllChoiceSets[formvarid].choices[idt];
                }
            }
        }
    }

    for(var idx1 in p)
    {
        var yes = true;
        for(var id1 in otherOnChoices)
        {
            yes &= p[idx1][id1];
        }
        if(yes && resultsForOtherChoices[p[idx1].FamilyId] == null)
        {
            resultsForOtherChoices[p[idx1].FamilyId] = p[idx1];
            resultsForOtherChoices[p[idx1].FamilyId].ProductId = p[idx1].ProductId;
            resultsForOtherChoices[p[idx1].FamilyId].FamilyId = p[idx1].FamilyId;
        }
    }
    return resultsForOtherChoices;
}

function Search()
{
    var count = 0;
    var results = new Array();
    for(idx = 0; idx < p.length; idx++)
    {
        var yes = true;
        if(SomeSelected())
        {
            for(var formvarid in AllChoiceSets)
            {
                var choiceobjects = AllChoiceSets[formvarid];
                for(var choiceid in choiceobjects.choices)
                {
                    var choiceobject = choiceobjects.choices[choiceid];
                    if(choiceobject.isOn)
                    {
                        yes &= p[idx][choiceid];
                    }
                }
            }
        }
        if(yes && results[p[idx].FamilyId] == null)
        {
            results[p[idx].FamilyId] = p[idx];
            results[p[idx].FamilyId].ProductId = p[idx].ProductId;
            results[p[idx].FamilyId].FamilyId = p[idx].FamilyId;
            count++;
        }
    }
    DrawResults(results, count);
    return results;
}

function SomeSelected()
{
    var yes = false;
    for(var formvarid in AllChoiceSets)
    {
        var choicesObject = AllChoiceSets[formvarid];
        for(var choiceid in choicesObject.choices)
        {
            yes |= choicesObject.choices[choiceid].isOn;
            if(yes)
            {
                return yes;
            }
        }
    }
    return yes;
}

function UnSelectOthers(choicesObject, choiceid)
{
    for(var id in choicesObject.choices)
    {
        if(id != choiceid)
        {
            var choiceobject = choicesObject.choices[id];
            if(choiceobject.isEnabled && choiceobject.isOn)
            {
               choiceobject.isOn = false;
               var choiceimg = document.getElementById(imgval + id);
               choiceimg.src = imgoff.src;
            }
        }
    }
}

function GetChoicesObject(choiceid)
{
    var choiceObject;
    for(var formvarid in AllChoiceSets)
    {
        if(AllChoiceSets[formvarid].choices[choiceid] != null)
        {
            return AllChoiceSets[formvarid];
        }
    }
}

function PopulateSelect(sel, choiceid, enabled)
{
    var arrayname = GetChoicesObject(choiceid).arrayopts;
    sel.disabled = false;
    if(sel.options[0] == null)
    {
        var count = 0;
        for(var x in arrayname)
        {
            if(count == 0)
            {
                sel.options[0] = arrayname[x];
                break;
            }
        }
    }
    if(enabled)
    {
        var found = false;
        for(magic = 0; magic < sel.options.length; magic++)
        {
            if(sel.options[magic].value == choiceid)
            {
                found = true;
                break;
            }
        }
        if(!found)
        {
            sel.options[sel.options.length] = arrayname[choiceid];
        }
    }
    else
    {
        var temp;
        for(magic = 0; magic < sel.options.length; magic++)
        {
            if(sel.options[magic].value == choiceid)
            {
                temp = magic;
                break;
            }
        }
        if(temp > 0)
        {
            sel.options[temp] = null;
        }
    }
    if(sel.options.length == 1)
    {
        sel.options[0].selected = true;
        sel.disabled = true;
    }
}

function DrawResults(products, count)
{
    if(resultsTable && resultsTable != null)
    {
        comparisonCounter = 0;
        var mainTBody;
        try
        {
            mainTBody = resultsTable.firstChild;
            var currRows = new Array();
            var len = mainTBody.rows.length;
            for(ii = 0; ii < mainTBody.rows.length; ii++)
            {
                currRows[ii] = mainTBody.rows[ii];
            }
            
            for(jj = 0; jj < currRows.length; jj++)
            {
                mainTBody.removeChild(currRows[jj]);
            }
        }
        catch(e)
        {
            resultsTable.innerHTML = "";
            mainTBody = document.createElement('TBODY');
            resultsTable.appendChild(mainTBody);
        }
        var rows = (count % 2 == 0) ? count / 2 : (count / 2) + 0.5;
        for(x = 0; x < rows; x++)
        {
            var tr = document.createElement('TR');
            mainTBody.appendChild(tr);

            var td1 = document.createElement('TD');
            tr.appendChild(td1);
            p1 = GetProductFromList(products, x, true, count);
            td1.innerHTML = DisplayProduct(p1, x);

            var td2 = document.createElement('TD');
            td2.className = 'w10_502';
            tr.appendChild(td2);

            var td3 = document.createElement('TD');
            tr.appendChild(td3);
            p1 = GetProductFromList(products, x, false, count);
            td3.innerHTML = DisplayProduct(p1, x);

            if(x != rows - 1)
            {
                var trspacer = document.createElement('TR');
                var tdspacer = document.createElement('TD');
                tdspacer.className = 'h10_502';
                tdspacer.colSpan = '3';
                tdspacer.innerHTML = "&nbsp;";
                trspacer.appendChild(tdspacer);
                mainTBody.appendChild(trspacer);
            }
        }
    }
}

function DisplayProduct(product, x)
{
    if(product != null)
    {
        var result;
        //set x == 0 if the different top display is needed again
        if(x == -1)
        {
            var divtopprodHTML = document.getElementById('divtopprod').innerHTML;
            result = divtopprodHTML;
        }
        else
        {
            var divnormalprodHTML = document.getElementById('divnormalprod').innerHTML;
            result = divnormalprodHTML;
        }
        for(var h1 in product)
        {
            while(result.indexOf("[" + h1 + "]") != -1)
            {
                result = result.replace("[" + h1 + "]", product[h1]);
            }
        }
        return result;
    }
    return "&nbsp";
}

function GetProductFromList(products, row, left, count)
{
    var pridx = 0;
    var pr;
    var ct = 0;
    if(left)
    {
        pridx = row * 2;
    }
    else
    {
        pridx = row * 2 + 1;
    }
    for(var hh in products)
    {
        if(ct == count)
        {
            return null;
        }
        if(ct == pridx)
        {
            return products[hh];
        }
        ct++; 
    }
}
//************************** Component 501 Ends ***********************************

//************************** Component 607 Starts ************************************  

// start ajax

var thirdPartyProductXmlHttp = null;
var thirdPartyProductSelectId = null;
var tppPreselection = null;

function initManufacturers(serviceUrl, manuListId, tppSelectId, siteId, languageId)
{
    var manuval = Cookies.value(manuListId);
    var manuList = document.getElementById(manuListId);
    
    if(manuval != "")
    {
        var prodval = Cookies.value(tppSelectId);
        
        // iterate over manufacturers to see if pre-selection is valid (it might
        // not be to a restriction to one manufacturer)
        for(var i = 0; i < manuList.options.length; i++)
        {
            if(manuList.options[i].value == manuval)
            {
                manuList.value = manuval;
                tppPreselection = prodval;
                break;
            }
        }
    }
    
    loadTpps(serviceUrl, manuList, tppSelectId, siteId, languageId);
}

function loadTpps(serviceUrl, sel, tppSelectId, siteId, languageId)
{
    var manufacturerId = sel.value;
        
    thirdPartyProductSelectId = tppSelectId;            
    var tppSelect = document.getElementById(tppSelectId);
    
    tppSelect.disabled = true;
    tppSelect.options[0].text = phoneModelsLoadingVal;
    
    try
    { 
        //Opera, Firefox, IE7, ...
        thirdPartyProductXmlHttp = new XMLHttpRequest();
    }
    catch (error)
    { 
        try 
        { 
            thirdPartyProductXmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE 6 and below
        } 
        catch (error)
        { 
            return false; 
        }
    }
    
    if (thirdPartyProductXmlHttp)
    {
        thirdPartyProductXmlHttp.onreadystatechange = thirdpartyProductsAjaxCallback;
    
        thirdPartyProductXmlHttp.open('POST', serviceUrl + '/crmservice.asmx', true);
        thirdPartyProductXmlHttp.setRequestHeader("SOAPAction", "http://www.jabra.com/GN.Public.Services/GetThirdPartyProductsForManufacturer");
        thirdPartyProductXmlHttp.setRequestHeader('Content-Type', 'text/xml');
        
        thirdPartyProductXmlHttp.send('<?xml version="1.0" encoding="utf-8"?>' +
            '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\n' +
            '  <soap:Body>\n' +
            '    <GetThirdPartyProductsForManufacturer xmlns="http://www.jabra.com/GN.Public.Services">\n' +
            '      <siteId>' + siteId + '</siteId>\n' +
            '      <languageId>' + languageId + '</languageId>\n' +
            '      <manufacturerId>' + manufacturerId + '</manufacturerId>\n' +
            '    </GetThirdPartyProductsForManufacturer>\n' +
            '  </soap:Body>\n' +
            '</soap:Envelope>\n');

    }
}

function thirdpartyProductsAjaxCallback()
{
    if(thirdPartyProductXmlHttp.readyState == 4)
    {
        var nodes = thirdPartyProductXmlHttp.responseXML.getElementsByTagName("WsThirdPartyProduct");
        var tppSelect = document.getElementById(thirdPartyProductSelectId);
        
        while(tppSelect.options.length > 1)
        {
            tppSelect.options[tppSelect.options.length - 1] = null;
        }
        
        for(var i = 0; i < nodes.length; i++)
        {
            var tppNode = nodes[i];
            tppSelect.options[tppSelect.options.length] = new Option(tppNode.childNodes[1].firstChild.nodeValue, tppNode.childNodes[0].firstChild.nodeValue);
        }
        
        if(tppPreselection != null)
        {   
            // don't assign value directly, first look if it is in the list. it might not, if it 
            // not attached to the stream / has been deleted / ...
            for(var i = 0; i < tppSelect.options.length; i++)
            {
                if(tppSelect.options[i].value == tppSelect.value)
                {
                    tppSelect.value = tppPreselection;
                    break;
                }
            }
            tppPreselection = null;
        }
        
        tppSelect.options[0].text = phoneModelVal;
        tppSelect.disabled = false;
    }
}

// end ajax

var phoneBrandVal = 'Phone brand';
var phoneModelVal = 'Model';
var phoneModelsLoadingVal = 'Loading...';
function PopulateManufactories(list, targetid) {

        var sel = document.getElementById(targetid);
        sel.options.length = list.length + 1;
        sel.options[0] = new Option(phoneBrandVal, '', true, false);
        
        for (var i=0;i<list.length;i++) {
            var ix = i+1;
            sel.options[ix] = new Option(list[i].name,list[i].id, false, false);
        }
    }
    
function PopulateManufactoriesSelected(list, targetid, selected_value) {

        var sel = document.getElementById(targetid);
        sel.options.length = list.length + 1;
        sel.options[0] = new Option(phoneBrandVal, '', true, false);
        
        for (var i=0;i<list.length;i++) {
            var ix = i+1;
            var selected = selected_value == list[i].id;
            sel.options[ix] = new Option(list[i].name,list[i].id, false, selected);
        }
    }
    
    
function PopulateProductsSelected(list, elm, targetid, selected_value)
{
    if(elm.selectedIndex==0)
    {
        var sel = document.getElementById(targetid);
        var optlen = sel.options.length;
       for(var jX=0;jX<optlen;jX++)
       {
            sel.options[1]=null;        
       }
    }
    if (elm.selectedIndex>0) 
    {
        var cmanu = list[elm.selectedIndex -1];
        var sel = document.getElementById(targetid);
        sel.options.length = cmanu.Tpp.length + 1;
        
        sel.options[0] = new Option(phoneModelVal, '', true, false);
        for (var i=0;i<cmanu.Tpp.length;i++) 
        {
            var ix = i+1;
            var selected = cmanu.Tpp[i].id == selected_value;
            sel.options[ix] = new Option(cmanu.Tpp[i].name,cmanu.Tpp[i].id, false, selected);
        }
    }
}    
    
function PopulateProducts(list,elm, targetid) 
{
    if(elm.selectedIndex==0)
    {
        var sel = document.getElementById(targetid);
        var optlen = sel.options.length;
       for(var jX=0;jX<optlen;jX++)
       {
            sel.options[1]=null;        
       }
    }
    if (elm.selectedIndex>0) 
    {
        var cmanu = list[elm.selectedIndex -1];
        var sel = document.getElementById(targetid);
        sel.options.length = cmanu.Tpp.length + 1;
        sel.options[0] = new Option(phoneModelVal, '', true, false);
        for (var i=0;i<cmanu.Tpp.length;i++) 
        {
            var ix = i+1;
            sel.options[ix] = new Option(cmanu.Tpp[i].name,cmanu.Tpp[i].id, false, false);
        }
    }
}
//************************** Component 607 Ends  ************************************  

//*************************** Search ***********************************************

function GNDoSearch(id, url) 
{
    var sf = document.getElementById(id);
    //var sf = document.getElementById('GNmasterdarchtextfield');
    var pam = '';
    
    if (sf && sf.value && sf.value != '') {
        pam = '?k='+sf.value;
    }
    window.location=url + pam;
}

function GNInvokeSearch(e, url)
{
    var charCode;
    if(e && e.which)
    {
        e = e;
        charCode = e.which;
    }
    else
    {
        e = event;
        charCode = e.keyCode;
    }
    
    if(charCode == 13)
    {
        if (e.srcElement) // Works for IE
        {
          GNDoSearch(e.srcElement.id, url);
        } 
        else 
        {
          GNDoSearch(e.target.id, url); // Works for Mozilla & family
        }
    	return false;
    }
    return true;   
}

//*************************** Search end *******************************************

//*************************** MOSS Administration scripts START

var CMAcurrentMenuElement = null;
var CMAdidOpen = false;

document.onclick = CMAMenuHandler;

function CMAMenuHandler(e) {
    if (!CMAdidOpen && CMAcurrentMenuElement) {
        var x = CMAcurrentMenuElement.childNodes[1];
        x.className = 'CMAeditMENUBODY';
    }
    CMAdidOpen = false;
}

function CMAShowHideAdminMenu() {
    var elm1 = document.getElementById('CMAnavigation');
    var elm2 = document.getElementById('CMAmossnavigation');
    if (elm1 && elm2) {
        var x = elm2.innerHTML;
        elm2.innerHTML = elm1.innerHTML;
        elm1.innerHTML = x;
    }
}

function CMASetFix() {
    var ff = document.getElementById('CMAadminevent');
    if (ff) {
        ff.value='toggleopen';
        document.forms[0].submit();
    }
}

function CMAToggleEditMode() {
    var ff = document.getElementById('CMAadminevent');
    if (ff) {
        ff.value='toggleedit';
        document.forms[0].submit();
    }
}

function CMASetContextDate() {
    var ff = document.getElementById('CMAadminevent');
    if (ff) {
        ff.value='setdate';
        document.forms[0].submit();
    }
}

function CMASetShopFakeUser() {
    var ff = document.getElementById('CMAadminevent');
    if (ff) {
        ff.value='setfakeshopuser';
        document.forms[0].submit();
    }
}

function CMAToggleMossMode() {
    var ff = document.getElementById('CMAadminevent');
    if (ff) {
        ff.value='togglemoss';
        document.forms[0].submit();
    }
}


function CMAShowMossMenu() {
    var d = document.getElementById('MOSSMENU');
    if ( d ) {
        d.className = 'CMAMOSSMENUON';
    }

}


var wasdelete = false;

function CMAToggleEditComponent(elm) {
    if (!wasdelete) {
        if (CMAcurrentMenuElement && CMAcurrentMenuElement != elm) {
            var x = CMAcurrentMenuElement.childNodes[1];
            x.className = 'CMAeditMENUBODY';
        }
        var menu = elm.childNodes[1];
        if (menu.className == 'CMAeditMENUBODY') {
            menu.className = 'CMAeditMENUBODYOPEN';
            CMAcurrentMenuElement = elm;
            CMAdidOpen = true;
        } else {
            menu.className = 'CMAeditMENUBODY';
            CMAcurrentMenuElement = null;
        }
    }
    wasdelete=false;
}

function CMADeleteAdminLink(compid) {
    if (confirm('This will delete the datalink for this component.')) 
    {
        var hid = document.getElementById('CMAdeletesmarturlid');
        if (hid) {
            hid.value = compid;
            document.forms[0].submit();
        }
    }
    wasdelete = true;
    return false;
}

function CMASmartURLDirectBind(compid, smartUrlType) {
    var componentHiddenField = document.getElementById('CMAdirectbindcompid');
    var smartUrlTypeHiddenField = document.getElementById('CMAdirectbindsmarturltype');
    
    if (componentHiddenField != null && smartUrlTypeHiddenField != null)
    {
        componentHiddenField.value = compid;
        smartUrlTypeHiddenField.value = smartUrlType;
        document.forms[0].submit();
    }
}

function CMASmartURLBindOther(value)
{
    if(value.indexOf("|") > -1)
    {
        var parts = value.split("|");
        CMASmartURLDirectBind(parts[0], parts[1]);
    }
    else
    {
        CMASmartURL(value);
    }
}

function CMAmenuitemover(elm) {
    var icon = elm.childNodes[0].childNodes[0].childNodes[0];
    icon.className = 'CMAeditMEUNITEMICONOVER';
    var text = elm.childNodes[0].childNodes[0].childNodes[1];
    text.className = 'CMAeditMEUNITEMNAMEOVER';

}

function CMAmenuitemout(elm) {
    var icon = elm.childNodes[0].childNodes[0].childNodes[0];
    icon.className = 'CMAeditMEUNITEMICON';
    var text = elm.childNodes[0].childNodes[0].childNodes[1];
    text.className = 'CMAeditMEUNITEMNAME';
}

function CMAmenuitemclick(elm, url) {
	var winobj = window.open(url ,'_blank','height=600,width=865,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
	winobj.moveTo(50, 50);
}

function CMARefresh() {
   location.reload(true);
}


function CMASmartURL(url) {
	var winobj = window.open(url ,'_blank','height=600,width=865,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
	winobj.moveTo(50, 50);
}


function CMAApplyDictionaryMenu() {
    var target = document.getElementById('dictionarymenucell');
    var source = document.getElementById('dictionarymenucontent');
    if (target && source) {
        target.innerHTML = source.innerHTML;
        source.innerHTML = "&nbsp;";
    }
}

function CMASiteMapAdmin(url) 
{
	var winobj = window.open(url ,'_blank','height=550,width=400,status=no,toolbar=no,menubar=no,location=no,resizable=0');
	winobj.moveTo(50, 50);
}

function CMAAdminOpenAdministration(url) {
	var winobj = window.open(url ,'_blank','height=550,width=800,status=no,toolbar=no,menubar=no,location=no,resizable=1');
	winobj.moveTo(50, 50);
}


//*************************** MOSS Administration scripts END
//************************** Component 104 Starts  ************************************  

function rememberSelection(id, path)
{
var checkBox = document.getElementById(id)
if(checkBox.checked)
    {

        Cookies.create('jabradefaultPath',path,200);
    }
else
    {
        Cookies.erase('jabradefaultPath');
    }
}

var Cookies = {
	init: function () 
	{
	   if (document.cookie) {
		    var allCookies = document.cookie.split('; ');
		    for(var i = 0; i < allCookies.length; i++) 
		    {
			    var cookiePair = allCookies[i].split('=');
			    this[cookiePair[0]] = cookiePair[1];
		    }
	    }
	},
	
	create: function (name, value, days) 
	{
	    var expires = "";
		if (days) 
		{
			var date = new Date();
			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
			var expires = "; expires=" + date.toGMTString();
		}
//		else 
//		{
//		    expires = "; expires=0";
//		}
		document.cookie = name + "=" + value + expires + "; path=/;";
		this[name] = value;
	},
	
	erase: function (name) 
	{
		this.create(name, '', -1);
		this[name] = undefined;
	},
	
	value: function (c_name)
	{
//	    debugger;
//	    alert('1');
        if (document.cookie.length>0)
        {
            c_start = document.cookie.indexOf(c_name + "=");
            if (c_start != -1)
            { 
                c_start = c_start + c_name.length + 1;
                c_end = document.cookie.indexOf(";", c_start);
                if (c_end == -1) 
                {
                    c_end = document.cookie.length;
                }
                var val = unescape(document.cookie.substring(c_start, c_end));
                return val;
            }
        }
        return "";
	}
};
Cookies.init();

function SelectManuAndProductFromCookie(manuselid, manucookiename, prodlist, prodselid, prodcookiename)
{   
    var manuselelm = document.getElementById(manuselid);
    var prodselelm = document.getElementById(prodselid);
    var manuval = Cookies.value(manucookiename);
    if(manuval != "")
    {
        manuselelm.value = manuval;
        var prodval = Cookies.value(prodcookiename);
        PopulateProducts(prodlist, manuselelm, prodselelm.id);
        prodselelm.value = prodval;
        return true;
    }
    return false;
}


//************************** Component 104 Ends  ************************************  

// Hello


//************************** Component 602 Starts  ************************************  
//var comparisonCounter = 0;

function GetLength(checkBox)
{
    var count = 0;
    for(x = 0; x < document.forms[0].elements[checkBox.name].length; x++)
    {
        if(document.forms[0].elements[checkBox.name][x].checked)
        {   
            count++;
        }
    }
    return count;
}

function CMACompare()
{
    document.forms[0].submit();
}

function CMACountCheck(checkBox, max)
{
//    debugger;
    comparisonCounter = GetLength(checkBox);
    if(checkBox.checked && comparisonCounter == (max + 1))
    {       
        checkBox.checked= false;
        return false ;
    }
    else if(checkBox.checked)
    {
        comparisonCounter++;
    }
    else if (!checkBox.checked)
    {
        comparisonCounter--;
    }
    return true;
}
//************************** Component 602 Ends  ************************************  

//************************** 906 Webform component start ****************************


function GNWebformSelect(formid) 
{
    var action = document.getElementById(formid + "_action");
    if (action) 
    {
        action.value = 'selectform';
        document.forms[0].submit();
    }
}

function GNWebformSubmit(formid) 
{
    if(GNIsValidForm())
    {
        var action = document.getElementById(formid + "_action");
        if (action) 
        {
            action.value = 'submitform';
            
            var aelm = document.getElementById("SUBMIT"+formid);
            if (aelm) {
                aelm.innerHTML = "Sending...";
            }
            
            document.forms[0].submit();
        }
    }
}

    var FieldValidation;
    var RequiredValidationMessage = 'Please fill in all required fields.';
    var GNEmailErrorMessage = 'Email format is wrong - please enter a correct email.';
    var GNPasswordErrorMessage = "The passwords don't mach.";
    
    function GNSetFieldValidation(validation,errormessage)
    {   
        eval("FieldValidation =" +validation);
        RequiredValidationMessage = errormessage;                 
    }
        
    function GNIsValidForm()
    {      
        if(FieldValidation != null)
        {
            for(var i = 0; i<FieldValidation.length; i++)
            {            
                if(!GNCheckRequired(FieldValidation[i].Name,FieldValidation[i].Value,FieldValidation[i].Type))
                  {
                    var elm = document.getElementById(FieldValidation[i].Name);
                    if (elm) {
                        elm.focus();
                    }
                     return false;
                  }                           
            }
        }       
        return true;
    }

    function GNCheckRequired(fieldName,value,vtype)
    {
        if (vtype == "Email") {
            if (!GNValidateEmailAddress(value)) {
                alert(GNEmailErrorMessage);
                return false;
            }
            return true;
        }   
        else if(vtype == "Password")
        {
            if(document.getElementById(fieldName).value !=
               document.getElementById(fieldName + '_confirm').value)
            {
                alert(GNPasswordErrorMessage);
                return false;
            }
            
            if(document.getElementById(fieldName).value == '')
            {
                alert(RequiredValidationMessage);
                return false;
            }
            
            return true;
        }
     
        if(value == null || value == "")
        {
            var elm = document.getElementById(fieldName);
            if (elm.type=='checkbox' && elm.checked) {
                return true;
            }
            
            if (elm.type=='select-one' && elm.selectedIndex > 0) {
                return true;
            }
            
            alert(RequiredValidationMessage);
            return false;
        }
       return true;    
    }
   
    function GNValidateEmailAddress(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
 		 return true					
    }
                
    
    function GNSetWebFormFieldValue(fieldid,value)
    {       
        if(FieldValidation == null)
        {
        return;
        }
        for(var i = 0;i<FieldValidation.length;i++)
        {               
            
            if(fieldid == FieldValidation[i].Name)
            { 
                FieldValidation[i].Value = value;        
            }                
        }        
    }
    
    function GNSetWebFormCheckBoxValue(checkBoxName)
    {
    var objCheckBox = document.forms[0].elements[checkBoxName];
    
    if(!objCheckBox)
    {
     return;
    }
        var countCheckBoxes = objCheckBox.length;
	    if(!countCheckBoxes)
	    {
	        if(objCheckBox.Checked)
	        {
	        GNSetWebFormFieldValue(checkBoxName,'1');
	        }
	        else
	        {
	        GNSetWebFormFieldValue(checkBoxName,'');	        
	        }
	        
	    }		
	    else
	    {	
		   for(var i = 0; i < countCheckBoxes; i++)
		    {
			    if(objCheckBox[i].checked)
			    {
			    GNSetWebFormFieldValue(checkBoxName,'1');
			    return;
			    }    
		    }
		    GNSetWebFormFieldValue(checkBoxName,"");
	    }
    }        


//************************** 906 Webform component end ****************************** 

//************************** Product Page IssuePopup start ****************************** 
var cX = -100; var cY = -100;
function UpdateCursorPosition(e)
{ 
    cX = e.pageX; 
    cY = e.pageY;
}

function UpdateCursorPositionDocAll(e)
{ 
    cX = event.clientX; 
    cY = event.clientY;
}

if(document.all) 
{ 
    document.onclick = UpdateCursorPositionDocAll; 
}
else 
{ 
    document.onclick = UpdateCursorPosition; 
}

function AssignPosition(d) 
{
    if(issueinfodivXpos.value == "0px" && issueinfodivYpos.value == "0px")
    {
        d.style.left = (cX+0) + "px";
        d.style.top = (cY+0) + "px";
    }
    else
    {
        d.style.left = issueinfodivXpos.value;
        d.style.top = issueinfodivYpos.value;
    }
    issueinfodivXpos.value = d.style.left;
    issueinfodivYpos.value = d.style.top;
}

function HideContent(d) 
{
    var div = document.getElementById(d);
    if(d.length < 1) 
    { 
        return; 
    }
    if(div != null)
    {
        div.style.display = "none";
    }
}

function ShowContent(d) 
{
    if(d.length < 1) 
    { 
        return; 
    }
    var div = document.getElementById(d);
    if(div != null)
    {
        AssignPosition(div);
        div.style.display = "block";
    }
}
//************************** Product Page IssuePopup end ****************************** 
//************************** Channel Selector ToggleDivs start ****************************** 
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}
//************************** Channel Selector ToggleDivs end ****************************** 


function GNFormSelectProductValue(elm) {
    var target = document.getElementById(elm.id + '_name');
    
    if (target != null) {
        if (elm.selectedIndex && elm.selectedIndex>0) {
                target.value = elm.options[elm.selectedIndex].text;
        } else {
            target.value = '';
        }
    }
}

//*********************************************** login box start *************************/

function logout()
{
    var logoutHiddenField = document.getElementById('inputGenLogoff');
    logoutHiddenField.value = 'true';
    document.forms[0].submit();
}

//*********************************************** login box end *************************/


//*********************************************** Wizard handlers start *****************/

function GNWizardSubmit(wizardid, index) {
    var next = document.getElementById(wizardid+'_next');
    if (next) {
        next.value = index;
        document.forms[0].submit();
    }
}

function GNWizardOpenNext(wizardid) {
    var current = document.getElementById(wizardid+'_current');
    var next = parseInt(current.value) + 1;
    var td = document.getElementById(wizardid+'_step'+next);

    if (td) {
        td.className = 'Selectable_ProgressBox';
        td.onclick = function() { GNWizardSubmit(wizardid, 'next'); };
    }

    var img = document.getElementById(wizardid+'_next_image');
    img.src = nextimage.src;
    
    td = document.getElementById(wizardid+'_next_td');
    td.onclick = function() { GNWizardSubmit(wizardid, 'next'); };
}

//*********************************************** Wizard handlers end   *****************/

//*********************************************** Hedaset Guide start   *****************/

function toggleGuidance(boxid)
{
    var box = document.getElementById(boxid);
    if(box.style.display == 'none' || box.style.display == '')
    {
        box.style.display = 'inline';
    }
    else
    {
        box.style.display = 'none';
    }
}

function Primary(name, id) 
{
    this.name = name;
    this.id = id;
    this.sub = new Array();
    this.index = 0;

    this.addChild = function (id, sname) 
    {
        this.sub[this.index] = new Object();
        this.sub[this.index].id = id;
        this.sub[this.index].name = sname;
        this.index++; 
    }

    this.addChildren = function (ids, snames) 
    {
        for (var ix=0;ix<ids.length;ix++)
        {
            this.sub[this.index] = new Object();
            this.sub[this.index].id = ids[ix];
            this.sub[this.index].name = snames[ix];
            this.index++;
        } 
    }
}

function toggleTab(module, section)
{
	var uls = document.getElementById(module).getElementsByTagName('ul');
   	var tabs = new Array();
    for (i=0;i<uls.length;i++)
        if (uls[i].className == 'tabs') tabs = uls[i].getElementsByTagName('li');
	var divs = document.getElementById(module).getElementsByTagName('div');
	var sections = new Array();
    for (i=0;i<divs.length;i++)
        if (divs[i].className == 'section') sections[sections.length++] = divs[i];

    if (tabs.length != sections.length) {
        alert('warning: your number of tabs ('+tabs.length+') differs from your number of sections ('+sections.length+')');
       return;
    }
}
function hsgTechnicalSpecs(url, width, height)
{
    var options = "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1";
    window.open(url, 'name', options + ',width=' + width + ',height=' + height);
}

function hsgPrintView(url, width, height)
{
    var options = "toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1";
    window.open(url, 'name', options + ',width=' + width + ',height=' + height);
}


function shopOrderReceipt(url, width, height) {
    var options = "toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1";
    window.open(url, 'name', options + ',width=' + width + ',height=' + height);
}

//*********************************************** Hedaset Guide end    *****************/

function shopOrderReceipt(url, width, height) {
    var options = "toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1";
    window.open(url, 'name', options + ',width=' + width + ',height=' + height);
}


function JabraToolClass() {
    this.ClientWidth = function() {
        return f_filterResults(
		            window.innerWidth ? window.innerWidth : 0,
		            document.documentElement ? document.documentElement.clientWidth : 0,
		            document.body ? document.body.clientWidth : 0
	            );
    };

    this.ClientHeight = function() {
        return f_filterResults(
		            window.innerHeight ? window.innerHeight : 0,
		            document.documentElement ? document.documentElement.clientHeight : 0,
		            document.body ? document.body.clientHeight : 0
	            );
    };

    this.ScrollLeft = function() {
        return f_filterResults(
		            window.pageXOffset ? window.pageXOffset : 0,
		            document.documentElement ? document.documentElement.scrollLeft : 0,
		            document.body ? document.body.scrollLeft : 0
	            );
    };

    this.ScrollTop = function() {
        return f_filterResults(
		            window.pageYOffset ? window.pageYOffset : 0,
		            document.documentElement ? document.documentElement.scrollTop : 0,
		            document.body ? document.body.scrollTop : 0
	            );
    };

    function f_filterResults(n_win, n_docel, n_body) {
        var n_result = n_win ? n_win : 0;
        if (n_docel && (!n_result || (n_result > n_docel)))
            n_result = n_docel;
        return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
    }


    this.ShowWait = function() {
        var elm = document.getElementById("pleasewait");
        if (elm != null) {
            elm.style.display = "block";
            elm.style.width = Number((this.ClientWidth() - 10)) + "px";
            elm.style.height = Number((Number(this.ClientHeight()) - 360)) + "px";
        }
        return true;
    }
}

var jabraTools = new JabraToolClass();


// ********************************************************************
// StringBuffer is a simple mechanism for effective handling of large
// javascript string concatanation.
// ********************************************************************
function StringBuffer() {
    this.buffer = [];
}

StringBuffer.prototype.append = function append(string) {
    this.buffer.push(string);
    return this;
};

StringBuffer.prototype.toString = function toString() {
    return this.buffer.join("");
};

var GN = new Object();
GN.fixedheader = 0;

GN.XmlBuilder = function(_root, _plain) {
    this.plain = _plain;
    if (arguments.length == 1) {
        this.plain = false;
    }

    this.root = _root;
    this.attributes = new Array();
    this.children = new Array();

    this.setAttr = function(name, value) {
        var obj = new Object();
        obj.name = name;
        obj.value = this.encodeString(value);
        this.attributes[this.attributes.length] = obj;
        return this;
    };

    this.addChild = function(name) {
        var child = new GN.XmlBuilder(name);
        this.children[this.children.length] = child;
        child.parent = this;
        return child;
    };

    this.body = function(content) {
        var child = new GN.XmlBuilder(this.encodeString(content), true);
        this.children[this.children.length] = child;
        child.parent = this;
        return child;
    };

    this.toString = function() {
        if (this.plain) {
            return this.root;
        }
        var sb = new StringBuffer();
        sb.append("<" + this.root);
        for (var i = 0; i < this.attributes.length; i++) {
            sb.append(" " + this.attributes[i].name + "='" + this.attributes[i].value + "'");
        }
        if (this.children.length > 0) {
            sb.append('>');
            for (var j = 0; j < this.children.length; j++) {
                sb.append(this.children[j].toString());
            }
            sb.append('</' + this.root + '>');
        } else {
            sb.append('/>');
        }
        return sb.toString();
    };

    this.encodeString = function(input) {
        try {
            return input.replace("&", "&amp;").replace("'", "&quot;");
        } catch (Error) {
            if (input) {
                return input;
            } else {
                return '';
            }
        }
    };
}

//************************************************************************************************************
// The GN root object provide comment generic platform facilities that can be used cross any other runction
//************************************************************************************************************

GN.ClientWidth = function() {
    return GN.f_filterResults(
	            window.innerWidth ? window.innerWidth : 0,
	            document.documentElement ? document.documentElement.clientWidth : 0,
	            document.body ? document.body.clientWidth : 0
            );
};

GN.ClientHeight = function() {
    return GN.f_filterResults(
	            window.innerHeight ? window.innerHeight : 0,
	            document.documentElement ? document.documentElement.clientHeight : 0,
	            document.body ? document.body.clientHeight : 0
            );
};

GN.ScrollLeft = function() {
    return GN.f_filterResults(
	            window.pageXOffset ? window.pageXOffset : 0,
	            document.documentElement ? document.documentElement.scrollLeft : 0,
	            document.body ? document.body.scrollLeft : 0
            );
};

GN.ScrollTop = function() {
    return GN.f_filterResults(
	            window.pageYOffset ? window.pageYOffset : 0,
	            document.documentElement ? document.documentElement.scrollTop : 0,
	            document.body ? document.body.scrollTop : 0
            );
};

GN.f_filterResults = function(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
};

GN.SizeListener = new Array();

GN.AddSizeListener = function(elementid) {
    if (arguments.length <= 1) {
        return;
    }
    var pos = GN.SizeListener.length; ;
    for (var i = 0; i < GN.SizeListener.length; i++) {
        if (GN.SizeListener[i].Id == elementid) {
            pos = i;
            break;
        }
    }
    var obj = new Object();
    obj.Id = elementid;
    obj.Values = new Array();
    for (var x = 1; x < arguments.length; x++) {
        obj.Values[x - 1] = arguments[x];
    }
    GN.SizeListener[pos] = obj;
    GN.SizeWorkplace(GN.fixedheader);
};


GN.SizeWorkplace = function(headerheight) {
    GN.fixedheader = headerheight;
    var workplace = document.getElementById("workplace");
    if (workplace) {
        workplace.style.width = GN.ClientWidth() + "px";
        workplace.style.height = GN.ClientHeight() + "px";
        var bd = document.getElementById("workplacebody");
        if (bd) {
            bd.style.width = GN.ClientWidth() + "px";
            bd.style.height = Number(GN.ClientHeight() - headerheight) + "px";
            var dc = document.getElementById("workplacebodydynamiccontent");
            if (dc) {
                dc.style.height = Number(GN.ClientHeight() - (headerheight + 14)) + "px";
            }
        }
        for (var x = 0; x < GN.SizeListener.length; x++) {
            GN.SizeElementHeight(GN.SizeListener[x]);
        }
    }
};

GN.ChildOfType = function(root, type) {
    var ret = new Array();

    var all = root.children;

    for (var i = 0; i < all.length; i++) {
        if (all[i].tagName.toUpperCase() == type.toString().toUpperCase()) {
            ret[ret.length] = all[i];
        }
    }
    return ret;
}

GN.SizeElementHeight = function(defi) {
    var outerElement = document.getElementById(defi.Id);
    if (!outerElement) {
        return;
    }
    var total = outerElement.offsetHeight;
    var fixed = 0;
    for (var i = 0; i < defi.Values.length; i++) {
        if (defi.Values[i] > 0) {
            fixed += defi.Values[i];
        }
    }
    var variable = total - fixed;
    var target = GN.ChildOfType(outerElement, 'div');

    for (var x = 0; x < target.length; x++) {
        var h = defi.Values[x];
        if (h <= 0) {
            target[x].style.height = "" + variable + "px";
        } else {
            //target[x].style.height = "" + h + "px";
        }
    }
};

GN.AddClass = function(element, name) {
    var current = element.className;
    var newvalue = '';
    var blank = '';
    var list = current.split(' ');
    for (var i = 0; i < list.length; i++) {
        if (list[i] != name) {
            newvalue += blank + list[i];
            blank = ' ';
        }
    }
    element.className = newvalue + blank + name;
};

GN.RemoveClass = function(element, name) {
    var current = element.className;
    var newvalue = '';
    var blank = '';
    var list = current.split(' ');
    for (var i = 0; i < list.length; i++) {
        if (list[i] != name) {
            newvalue += blank + list[i];
            blank = ' ';
        }
    }
    element.className = newvalue;
};

GN.ReplaceClass = function(element, from, to) {
    this.RemoveClass(element, from);
    this.AddClass(element, to);
};


GN.ShowHidePopup = function(element) {
    if (element.parentNode) {
        if (element.parentNode.tagName.toUpperCase() == 'DIV') {
            var x = element.parentNode.getElementsByTagName('div')[0];
            if (x.style.display == 'block') {
                x.style.display = 'none';
            } else {
                x.style.display = 'block';
            }
        } else {
            GN.ShowHidePopup(element.parentNode);
        }
    }
};

GN.ShowInnerPopup = function(element) {
    element.getElementsByTagName('div')[0].style.display = 'block';
};

GN.HideInnerPopup = function(element) {
    element.getElementsByTagName('div')[0].style.display = 'none';
};

GN.OverElement = function(element) {
    this.ReplaceClass(element, 'out', 'over');
};

GN.OutElement = function(element) {
    this.ReplaceClass(element, 'over', 'out');
};


// ******************************************
// Gnax is a specific ajax webpart handler
// that allow webpart on a page to be updated
// on an event.
// ******************************************
GN.Gnax = function(param, _callback) {
    var xmlhttp;
    var callback = _callback;

    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else
        if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            try {
                callback.Callback(xmlhttp.responseText);
            } catch (Error) {
                alert('Ajax call error: ' + Error.message);
            }
        }
    };

    this.Run = function() {

        var x = document.location.href;
        var qix = x.indexOf('?');
        if (qix >= 0) {
            x = x.substring(0, qix) + '.gnax' + x.substring(qix) + '&ts=' + new Date().getTime();
        } else {
            x = x + '.gnax' + '?ts=' + new Date().getTime();
        }

        xmlhttp.open('POST', x, true);
        xmlhttp.send(param);
    };
};

GN.GnaxControls = new Array();

GN.GnaxControls.AddListener = function(element, id, classname, componentid) {
    var obj = new Object();
    obj.element = element;
    obj.id = id;
    obj.classname = classname;
    obj.componentid = componentid;
    this.push(obj);
};

GN.GnaxControls.Callback = function(result) {
    var errpos = result.indexOf('<!--ERROR');
    if (errpos >= 0) {
        var errmess = result.substring(errpos + 10, result.length - (errpos + 13));
        alert(errmess);
    } else {
        if (!GN.GnaxControls.NextCallback || !GN.GnaxControls.NextCallback.Executer) {
            for (var i = 0; i < this.length; i++) {
                var cid = "<!--ID:" + this[i].id + "-->";
                var ix = result.indexOf(cid);
                this[i].element.innerHTML = result.substring(0, ix);
                result = result.substring(ix + cid.length);
            }
        }

        if (GN.GnaxControls.NextCallback) {
            GN.GnaxControls.NextCallback.Callback(result);
        }
    }
};


GN.Browser = new Object();
GN.Browser.IE_Less8 = function() {
    if (navigator.appName == "Microsoft Internet Explorer") {
        var ua = navigator.userAgent;
        var MSIEOffset = ua.indexOf("MSIE ");

        if (MSIEOffset == -1) {
            return false;
        } else {
            var ver = parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
            return ver < 8;
        }
    }
    return false;
};

// ***************************************************************
// Call Gnax method and update all Gnax registred webpart on page
// ***************************************************************
GN.GnaxControls.Run = function(command, param, callback) {
    GN.GnaxControls.NextCallback = callback;
    var doc = new GN.XmlBuilder("gnax");
    doc.addChild("command").setAttr('parameter', param).body(command);

    for (var i = 0; i < this.length; i++) {
        doc.addChild("webpart")
            .setAttr("classname", this[i].classname)
            .setAttr("componentid", this[i].componentid)
            .setAttr("id", this[i].id);

        var style = " style='width: " + this[i].element.offsetWidth + "px;height: " + this[i].element.offsetHeight + "px'";

        if (GN.Browser.IE_Less8()) {
            style = " style='left: -" + this[i].element.offsetWidth + "px;width: " + this[i].element.offsetWidth + "px;height: " + this[i].element.offsetHeight + "px'";
        }

        var demp = document.createElement("div");
        demp.className = "ajaxload";
        demp.innerHTML = "<div class='ajaxloadinner'" + style + "><div class='ajaxloadmessage'>&nbsp;</div></div>";

        this[i].element.insertBefore(demp, this[i].element.firstChild);

        //this[i].element.innerHTML = "<div class='ajaxload'><div class='ajaxloadinner'" + style + "><div class='ajaxloadmessage'>&nbsp;</div></div></div>" + this[i].element.innerHTML;
    }
    var ax = new GN.Gnax(doc.toString(), this);
    ax.Run();

};


// ***********************************************************
// Call Gnax method without updating webpart on page.
// ***********************************************************
GN.GnaxControls.Execute = function(command, param, callback) {
    GN.GnaxControls.NextCallback = callback;
    callback.Executer = true;
    var doc = new GN.XmlBuilder("gnax");
    doc.addChild("command").setAttr('parameter', param).body(command);
    var ax = new GN.Gnax(doc.toString(), this);
    ax.Run();
};


GN.Keyboard = new Object();
GN.Keyboard.Backspace = 8;
GN.Keyboard.Tab = 9;
GN.Keyboard.Enter = 13;
GN.Keyboard.Shift = 16;
GN.Keyboard.Ctrl = 17;
GN.Keyboard.Alt = 18;
GN.Keyboard.Caps = 20;
GN.Keyboard.Esc = 27;
GN.Keyboard.PgUp = 33;
GN.Keyboard.PgUp = 34;
GN.Keyboard.End = 35;
GN.Keyboard.Home = 36;
GN.Keyboard.Left = 37;
GN.Keyboard.Up = 38;
GN.Keyboard.Right = 39;
GN.Keyboard.Down = 40;
GN.Keyboard.Insert = 45;
GN.Keyboard.Delete = 46;
GN.Keyboard.F1 = 123;


GN.AutocompleteControls = new Array();

GN.AutocompleteControls.Get = function(_id) {
    for (var i = 0; i < this.length; i++) {
        if (this[i].id == _id) {
            return this[i];
        }
    }
    var nex = new GN.Autocomplete(_id);
    this[this.length] = nex;
    return nex;
};

GN.Autocomplete = function(_id) {
    this.id = _id;
    this.currentSearch = '';
    this.match = new Array();
    this.data = new Array();
    this.Callback = null;

    this.Match = function(val) {
        if (this.Callback && this.currentSearch != val) {
            for (var i = 0; i < this.data.length; i++) {
                this.data[i].selected = false;
            }

            this.match = new Array();

            if (val != '') {
                for (var x = 0; x < this.data.length; x++) {
                    if (this.Callback.Compare(this.data[x], val)) {
                        this.match[this.match.length] = this.data[x];
                    }
                }
            }
            this.currentSearch = val;
        };
        if (this.match.length == 1) {
            this.match[0].selected = true;
        }
    };

    this.UnselectElement = function(ix) {
        var elm = document.getElementById(this.id + "result" + ix);
        if (elm) {
            GN.RemoveClass(elm, "sel");
        }
    };

    this.SelectElement = function(ix) {
        var elm = document.getElementById(this.id + "result" + ix);
        if (elm) {
            GN.AddClass(elm, "sel");
        }
    };

    this.Next = function() {
        for (var i = 0; i < this.match.length - 1; i++) {
            if (this.match[i].selected) {
                this.match[i].selected = false;
                this.UnselectElement(i);
                this.match[i + 1].selected = true;
                this.SelectElement(i + 1);
                return;
            }
        }
        if (this.match.length > 0) {
            this.match[0].selected = true;
            this.SelectElement(0);
            if (this.match.length > 1) {
                this.match[this.match.length - 1].selected = false;
                this.UnselectElement(this.match.length - 1);
            }
        }
    };

    this.Prev = function() {
        for (var i = this.match.length - 1; i > 0; i--) {
            if (this.match[i].selected) {
                this.match[i].selected = false;
                this.UnselectElement(i);
                this.match[i - 1].selected = true;
                this.SelectElement(i - 1);
                return;
            }
        }
        if (this.match.length > 0) {
            this.match[0].selected = false;
            this.UnselectElement(0);
            if (this.match.length > 1) {
                this.match[this.match.length - 1].selected = true;
                this.SelectElement(this.match.length - 1);
            }
        }
    };

    this.Over = function(ix) {
        for (var i = 0; i < this.match.length; i++) {
            if (this.match[i].selected) {
                this.match[i].selected = false;
                this.UnselectElement(i);
                break;
            }
        }
        this.match[ix].selected = true;
        this.SelectElement(ix);
    };

    this.OnKey = function(element, e) {
        var unicode = e.keyCode ? e.keyCode : e.charCode;

        setTimeout("GN.AutocompleteControls.Get('" + this.id + "').Perform(" + unicode + ")", 0);

        if (unicode == GN.Keyboard.Enter || unicode == GN.Keyboard.Tab) {
            return false;
        }

        return true;
    };

    this.Select = function(index) {
        var res = document.getElementById(this.id + 'result');
        res.style.display = 'none';

        this.Callback.OnEnter(this.match[index]);
    };

    this.Validate = function() {
        if (this.Callback && this.Callback.Validate) {
            var selected = null;
            for (var i = 0; i < this.match.length; i++) {
                if (this.match[i].selected) {
                    selected = this.match[i];
                }
            }
            return this.Callback.Validate(selected);
        }
        return true;
    };

    this.Perform = function(code) {
        var element = document.getElementById(this.id);
        this.Match(element.value);

        switch (code) {
            case GN.Keyboard.Enter:
            case GN.Keyboard.Tab:
                for (var i = 0; i < this.match.length; i++) {
                    if (this.match[i].selected) {
                        this.Select(i);
                        return;
                    }
                }
                return;
            case GN.Keyboard.Up:
                this.Prev();
                return;
            case GN.Keyboard.Down:
                this.Next();
                return;
        }

        var res = document.getElementById(this.id + 'result');
        var sb = new StringBuffer();
        sb.append("<div>");
        if (typeof this.Callback.Translate == 'function') {
            if (this.match.length > 0) {
                var t1 = this.Callback.Translate('found', this.match.length);
                sb.append("<div class='found'>" + t1 + "</div>");
            } else {
                var t2 = this.Callback.Translate('noresult');
                sb.append("<div class='found'>" + t2 + "</div>");
            }
        } else {
            sb.append("<div class='found'>Found: " + this.match.length + "</div>");
        }
        sb.append("</div>");
        for (var z = 0; z < this.match.length; z++) {
            sb.append("<div>");
            sb.append("<div id='" + this.id + "result" + z + "' class='lin" + (this.match[z].selected ? " sel" : "") + "' ");
            sb.append("onclick=\"GN.AutocompleteControls.Get('" + this.id + "').Select(" + z + ");\" ");
            sb.append("onmouseover=\"GN.AutocompleteControls.Get('" + this.id + "').Over(" + z + ");\"");
            sb.append(">");
            sb.append(this.Callback.MergeElement(this.match[z]));
            sb.append("</div>");
            sb.append("</div>");
        }


        if (this.match.length > 0) {
            res.style.display = 'block';
        } else {
            res.style.display = 'none';
        }
        res.innerHTML = sb.toString();
    };
};



// ****************************************
// Shop specific scripts
// ****************************************
GN.Shop = new Object();
GN.Shop.addFavoritText = 'Add to favorit';
GN.Shop.removeFavoritText = 'Remove from favorit';

GN.Shop.ToggleFavorite = function(me, productid) {
    var callback = new Object();
    callback.Callback = function(result) {
        if (result == 'added') {
            me.setAttribute('class', 'iconFavSelected');
            me.setAttribute('className', 'iconFavSelected');
            me.title = GN.Shop.removeFavoritText;
            me.innerHTML = GN.Shop.removeFavoritText;
        } else
            if (result == 'removed') {
            me.setAttribute('class', 'iconFav');
            me.setAttribute('className', 'iconFav');
            me.title = GN.Shop.addFavoritText;
            me.innerHTML = GN.Shop.addFavoritText;
        }
    }
    GN.GnaxControls.Execute("Shop.ToggleFavorit", productid, callback);
};

GN.Shop.Cart = new Object();

GN.Shop.Cart.SetProduct = function(quantityfield, product) {
    if (!this.products) {
        this.products = new Array();
    }
    var found = null;
    for (var i = 0; i < this.products.length; i++) {
        if (this.products[i].productid == product) {
            found = this.products[i];
            break;
        }
    }
    if (!found) {
        found = new Object();
        found.productid = product;
    }
    found.quantity = quantityfield.value;
    this.products.push(found);
};

GN.Shop.Cart.Submit = function() {
    if (this.products && this.products.length > 0) {
        var sb = new StringBuffer();
        var comma = "";
        for (var i = 0; i < this.products.length; i++) {
            sb.append(comma + this.products[i].productid + ":" + this.products[i].quantity);
            comma = ",";
        }
        GN.GnaxControls.Run("Shop.UpdateCart", sb.toString(), this);
    }
};

GN.Shop.Cart.Callback = function() {
    this.products = null;
};


