function toggle(box) {
	boxes = new Array('1','2','3');
	showbox = document.getElementById('detail' + box);
	arrow = document.getElementById('indicator' + box);
	if (showbox.style.display=='') {
		showbox.style.display='none';
		arrow.src = 'http://my.techdata.ch/images/arrow_down.gif';
	}else{
		for (i=0;i<boxes.length;i++)
		{
			if(boxes[i] != box)
			{
				document.getElementById('detail' + boxes[i]).style.display='none';
				document.getElementById('indicator' + boxes[i]).src='http://my.techdata.ch/images/arrow_down.gif';
			}
		}
		showbox.style.display='';
		arrow.src='http://my.techdata.ch/images/arrow_up.gif';
	}
}

function mozilla() {
	try {
		if (isExplorer=='0') {
			var v = document.getElementsByTagName('select');
			var o;
			for (var i=0;i<v.length;i++) {
				o = v[i];
				if (o!=null) {
					if (o.className=='formcombo') {
						 o.className='formcombomoz';
					}
					if (o.className=='errorCombo') {
						 o.className='errorCombomoz';
					}
					if (o.className=='formcomborec') {
						 o.className='formcomborecmoz';
					}
					if (o.className=='formcombospec') {
						 o.className='formcombospecmoz';
					}
					if (o.className=='errorComborec') {
						 o.className='errorComborecmoz';
					}
					if (o.className=='errorCombospec') {
						 o.className='errorCombospecmoz';
					}
				}
			}
		}
	} catch (e) {}
}

function uml(aStr) {
	try {
		aStr = aStr.replace("ä", "&auml;");
		aStr = aStr.replace("ö", "&ouml;");
		aStr = aStr.replace("ü", "&uuml;");
		aStr = aStr.replace("Ä", "&Auml;");
		aStr = aStr.replace("Ö", "&Ouml;");
		aStr = aStr.replace("Ü", "&Uuml;");
		aStr = aStr.replace("ß", "&szlig;");
	} catch(e) {}
	return aStr;
}

function switchView(obj) {
	try {
		var v = document.getElementById(obj);
		if (v.style.display=='inline') {
			v.style.display='none';
		} else {
			v.style.display='inline';
		}
	} catch(e) {}
}

function trim(s) {
	return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}

function $(id) {
	return document.getElementById(id);
}

var ua = navigator.userAgent.toLowerCase();

Ext = {
	isStrict : (document.compatMode == "CSS1Compat"),
    isOpera : (ua.indexOf("opera") > -1),
	isSafari : (/webkit|khtml/).test(ua),
    isSafari3 : this.isSafari && ua.indexOf('webkit/5') != -1,
    isIE : !this.isOpera && ua.indexOf("msie") > -1,
    isIE7 : !this.isOpera && ua.indexOf("msie 7") > -1,
    isGecko : !this.isSafari && ua.indexOf("gecko") > -1,
    isWindows : (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1),
    isMac : (ua.indexOf("macintosh") != -1 || ua.indexOf("mac os x") != -1),
    isAir : (ua.indexOf("adobeair") != -1),
    isLinux : (ua.indexOf("linux") != -1),
	getViewHeight : function(full) {
		return full ? this.getDocumentHeight() : this.getViewportHeight();
    },
	getViewWidth : function(full) {
		return full ? this.getDocumentWidth() : this.getViewportWidth();
    },
    getDocumentHeight: function() {
		var scrollHeight = !this.isStrict ? document.body.scrollHeight : document.documentElement.scrollHeight;
        return Math.max(scrollHeight, this.getViewportHeight());
    },
    getDocumentWidth: function() {
        var scrollWidth = !this.isStrict ? document.body.scrollWidth : document.documentElement.scrollWidth;
		return Math.max(scrollWidth, this.getViewportWidth());
    },
    getViewportHeight: function(){
		if(this.isIE){
			return this.isStrict ? document.documentElement.clientHeight :document.body.clientHeight;
        } else {
            return self.innerHeight;
        }
    },
    getViewportWidth: function() {
		if(this.isIE){
            return this.isStrict ? document.documentElement.clientWidth : document.body.clientWidth;
        } else {
			return self.innerWidth;
        }
    },
	getScrollTop : function() {
		return !this.isStrict ? document.body.scrollTop : document.documentElement.scrollTop;
	}
};

Ext.apply = function(o, c, defaults){
    if(defaults){
        Ext.apply(o, defaults);
    }
    if(o && c && typeof c == 'object'){
        for(var p in c){
            o[p] = c[p];
        }
    }
    return o;
};

Ext.apply(Function.prototype, {
    createCallback : function(/*args...*/){
        var args = arguments;
        var method = this;
        return function() {
            return method.apply(window, args);
        };
    },
    createDelegate : function(obj, args, appendArgs){
        var method = this;
        return function() {
            var callArgs = args || arguments;
            if(appendArgs === true){
                callArgs = Array.prototype.slice.call(arguments, 0);
                callArgs = callArgs.concat(args);
            }else if(typeof appendArgs == "number"){
                callArgs = Array.prototype.slice.call(arguments, 0);
                var applyArgs = [appendArgs, 0].concat(args);
                Array.prototype.splice.apply(callArgs, applyArgs);
            }
            return method.apply(obj || window, callArgs);
        };
    },
    defer : function(millis, obj, args, appendArgs){
        var fn = this.createDelegate(obj, args, appendArgs);
        if(millis){
            return setTimeout(fn, millis);
        }
        fn();
        return 0;
    },
    createSequence : function(fcn, scope){
        if(typeof fcn != "function"){
            return this;
        }
        var method = this;
        return function() {
            var retval = method.apply(this || window, arguments);
            fcn.apply(scope || this || window, arguments);
            return retval;
        };
    },
    createInterceptor : function(fcn, scope){
        if(typeof fcn != "function"){
            return this;
        }
        var method = this;
        return function() {
            fcn.target = this;
            fcn.method = method;
            if(fcn.apply(scope || this || window, arguments) === false){
                return;
            }
            return method.apply(this || window, arguments);
        };
    }
});

var MsgBox = {
	windowObj : null,
	innerWindowObj : null,
	flexalert : function(title, message, fn, width) {
		if(!this.windowObj) {
			this.windowObj = new WindowBox('msgObj');
		}
		this.windowObj.closeBtnHandler(fn);
		this.windowObj.setNoBtnVisible(false);
		this.windowObj.setYesBtnVisible(false);
		this.windowObj.setCloseBtnVisible(true);
		this.windowObj.setNextBtnVisible(false);
		this.windowObj.show(title, message, width, 130);
	},
	alert : function(title, message, fn) {
		if(!this.windowObj) {
			this.windowObj = new WindowBox('msgObj');
		}
		this.windowObj.closeBtnHandler(fn);
		this.windowObj.setNoBtnVisible(false);
		this.windowObj.setYesBtnVisible(false);
		this.windowObj.setCloseBtnVisible(true);
		this.windowObj.setNextBtnVisible(false);
		this.windowObj.show(title, message, 350, 130);
	},
	alertNext : function(title, message, fn) {
		if(!this.windowObj) {
			this.windowObj = new WindowBox('msgObj');
		}
		this.windowObj.nextBtnHandler(fn);
		this.windowObj.setNoBtnVisible(false);
		this.windowObj.setYesBtnVisible(false);
		this.windowObj.setCloseBtnVisible(false);		
		this.windowObj.setNextBtnVisible(true);
		this.windowObj.show(title, message, 350, 130);
	},
	internalAlert : function(title, message, fn) {
		if(!this.innerWindowObj) {
			this.innerWindowObj = new WindowBox('innerMsgObj');
		}
		this.innerWindowObj.closeBtnHandler(fn);
		this.innerWindowObj.setNoBtnVisible(false);
		this.innerWindowObj.setYesBtnVisible(false);
		this.innerWindowObj.setCloseBtnVisible(true);
		this.innerWindowObj.setNextBtnVisible(false);
		this.innerWindowObj.show(title, message, 350, 140);
	},
	showPasswdChange : function(title, finishText) {
		if(!this.windowObj) {
			this.windowObj = new WindowBox('msgObj');
		}
		var message = '<p>Bitte vergeben Sie zunächst Ihr persönliches Passwort, mit dem Sie sich jederzeit wieder auf &quot;meinEBERLE&quot; anmelden können.<BR>&nbsp;</p><table border="0" cellspacing="0" cellpadding="0"><colgroup><col class="caption" /><col class="formfield" /></colgroup>' + 
		'<tr><td width="175">Passwort*</td><td width="170"><input id="passwd" name="passwd" class="formfield" type="password" value=""></td></tr><tr><td>Passwort bestätigen*</td><td><input id="passwdRepeat" name="passwdRepeat" class="formfield" type="password" value=""></td></tr></table>';
		this.windowObj.yesBtnHandler(function() {
			var pass1 = $('passwd');
			var pass2 = $('passwdRepeat');
			var r = 0;
			r = validate('empty', pass1.value, 'passwd', 'formfield');
			r += validate('empty', pass2.value, 'passwdRepeat', 'formfield');
			if(r == 0) {
				if(pass1.value != pass2.value) {
					r += 1;
					pass2.className = 'formfieldError';
				}
			}
			if(r > 0) {
				MsgBox.internalAlert('Hinweis','Bitte ergänzen/korrigieren Sie Ihre Angaben in den rot markierten Feldern.');
				return;
			}	
			var ajax = new AJAX();
			var params = 'passwd=' + pass1.value;
			ajax.callPage('/ajax/change_passwd.asp?' + params, function(respText) {
				if(trim(respText) == 'ok') {
					var msg = finishText ? finishText : '';
					MsgBox.internalAlert('Hinweis', msg);
					MsgBox.hide();
				}
			});
		});
		this.windowObj.setNoBtnVisible(false);
		this.windowObj.setYesBtnVisible(true);
		this.windowObj.setCloseBtnVisible(false);
		this.windowObj.setNextBtnVisible(false);
		this.windowObj.show(title, message, 350, 130);
	},
	confirm : function(message, fn) {
		if(!this.windowObj) {
			this.windowObj = new WindowBox('msgObj');
		}		
		this.windowObj.yesBtnHandler(fn);
		this.windowObj.setNoBtnVisible(true);
		this.windowObj.setYesBtnVisible(true);
		this.windowObj.setCloseBtnVisible(false);
		this.windowObj.setNextBtnVisible(false);
		this.windowObj.show('', message, 350, 110);
	},
	hide : function() {
		this.windowObj.hide();
	}
};
 
function WindowBox(id) {
	var topZindex = 20000;	
	var id = id;
    var obj;
	var mask;
    var iframe;
    var header;
	var contents;           
    var x, y;
    var left = 0, top = 0;
    var center = true; //show window with center align
    var storeLastPosition = true; //store last window position
    var firstShow = true; //check this if ceter==true and storeLastPosition, then center only first time
	var mouseMove, mouseUp;
	var yesBtnHandler;
	var yesBtnVisible;
	var noBtnHandler;
	var noBtnVisible;
	var closeBtnVisible;
	var closeBtnHandler;
	var nextBtnVisible;
	var nextBtnHandler;
		   
	return {
		$ : function(id) {
			return document.getElementById(id);
		},		
		setYesBtnVisible : function(visible) {
			yesBtnVisible = visible;
		},
		yesBtnHandler : function(fn) {
			yesBtnHandler = fn;
		},
		setNoBtnVisible : function(visible) {
			noBtnVisible = visible;
		},
		noBtnHandler : function(fn) {
			noBtnHandler = fn;
		},
		setCloseBtnVisible : function(visible) {
			closeBtnVisible = visible;
		},		
		closeBtnHandler : function(fn) {
			closeBtnHandler = fn;
		},
		setNextBtnVisible : function(visible) {
			nextBtnVisible = visible;
		},
		nextBtnHandler : function(fn) {
			nextBtnHandler = fn;
		},
		zIndex : function(value) {
			topZindex = value;
		},
		mouseDown : function(event) {
			if(!event) {
				event = window.event;
			}
			y = event.clientY;
			x = event.clientX;
			mouseMove = this.mouseMove.createDelegate(this);		
			this.addEvent(document, "mousemove", mouseMove);
			
			mouseUp = this.mouseUp.createDelegate(this);
			this.addEvent(document, "mouseup", mouseUp);
		},
		
		mouseUp : function (event) {
			if(!event) {
				event = window.event;
			}
			this.removeEvent(document, "mousemove", mouseMove);
			this.removeEvent(document, "mouseup", mouseUp);
		},
	            
		mouseMove : function(event) {
			if(!event) {
				event = window.event;
			}
			var el = this.getObj();
			el.style.left = (parseInt(el.style.left) - (parseInt(x) - parseInt(event.clientX))) + 'px';
			el.style.top = (parseInt(el.style.top) - (parseInt(y) - parseInt(event.clientY))) + 'px';				
					
			y = event.clientY;
			x = event.clientX;
			if (storeLastPosition) {
			    left = el.style.left;
			    top = el.style.top;
			}
			return false;
		},

	    addEvent : function(obj, evType, fn) {
			try {
				if (obj.addEventListener) {
	                obj.addEventListener(evType, fn, false);
	                return true;
	            } else if (obj.attachEvent){
	                var r = obj.attachEvent("on" + evType, fn);
	                return r;
	            } else {
	                return false;
	            }
	        } catch(e) {
	            this.LOG(e.description);				
	        }
	    },

	    removeEvent : function (obj, evType, fn, useCapture) {
	        try{
				if (obj.removeEventListener){
	                obj.removeEventListener(evType, fn, useCapture);
	                return true;
	            } else if (obj.detachEvent){
	                var r = obj.detachEvent("on" + evType, fn);
	                return r;
	            } else {
	                this.LOG("Handler could not be removed");
	            }
	        } catch(e) {
	            this.LOG(e.description);
	        }
	    },
	            
	    LOG : function(msg){
	        window.status = msg;
	    },
		
		show : function(title, message, width, height, xPos, yPos) {			
			this.showMask();
            var el = this.getObj(width, height);
			$(id + '_title').innerHTML = title ? title : '&nbsp;';			
			$(id + '_msg').innerHTML = message ? message : '&nbsp;';
			if($(id + '_yes_btn')) {
				$(id + '_yes_btn').style.display = yesBtnVisible ? 'inline' : 'none';
				$(id + '_yes_btn').onclick = yesBtnHandler ? yesBtnHandler : this.hide.createDelegate(this);
			}
			if($(id + '_no_btn')) {
				$(id + '_no_btn').onclick = noBtnHandler ? noBtnHandler : this.hide.createDelegate(this);
				$(id + '_no_btn').style.display = noBtnVisible ? 'inline' : 'none';
			}
			if($(id + '_close_btn')) {
				$(id + '_close_btn').onclick = closeBtnHandler ? closeBtnHandler : this.hide.createDelegate(this);
				$(id + '_close_btn').style.display = closeBtnVisible ? 'inline' : 'none';
			}
			if($(id + '_next_btn')) {
				$(id + '_next_btn').onclick = nextBtnHandler ? nextBtnHandler : this.hide.createDelegate(this);
				$(id + '_next_btn').style.display = nextBtnVisible ? 'inline' : 'none';
			}
            if (firstShow && center){
				if (xPos == null || yPos == null) {
					x = (Ext.getViewWidth(true) - width) / 2;
					y = ((Ext.getViewHeight(false) - height) / 2) + Ext.getScrollTop() ;
				}
                el.style.left = x + 'px';
                el.style.top = y + 'px';
                left = el.style.left;                          
                top = el.style.top;
            } else {
                el.style.left = left;
                el.style.top = top;             
            }			
			
			var c = this.getContents();
			var header = this.getHeader();		
			
            el.style.zIndex = topZindex;
            el.style.display = "block";			
			
            this.firstShow = false;
		},
		
		showMask : function() {
			if(!mask || !$(id + '_mask')) {
				mask = document.createElement('div');
				mask.id = id + '_mask';
				mask.style.position = 'absolute';
				mask.style.top = '0';
				mask.style.left = '0';
				mask.style.overflow = 'hidden';
				mask.style.zIndex = topZindex - 1;
				mask.style.zoom = '1';
				mask.style.backgroundColor = '#CCC';
				mask.style.filter = 'Alpha(opacity=50)';
				mask.style.opacity =  '0.5';
				mask.style.MozOpacity = '0.5';
				document.body.appendChild(mask);
			}
			mask.style.width = Ext.getViewWidth(true) + 'px';
			mask.style.height = Ext.getViewHeight(true) + 'px';
			mask.style.display = 'block';			
			if(Ext.isIE && !Ext.isIE7) {
				this.showHideCombos(false);
			}
			var obj = document.getElementById('flashDiagramDiv');
			if(obj) {
				obj.style.visibility = 'hidden';
			}
		},
		
		hideMask : function() {
			if(mask) {
				mask.style.display = 'none';
				if(Ext.isIE && !Ext.isIE7) {
					this.showHideCombos(true);
				}
			}
			var obj = document.getElementById('flashDiagramDiv');
			if(obj) {
				obj.style.visibility = 'visible';
			}
		},
		
        getIframe : function () {
            if (!iframe) {
				iframe = $(id + '_iframe');
			}
            return iframe;
        },
		
        getObj : function (width, height) {
            if (!obj) {
				obj = this.$(id);
				if(!obj) {
					var el = document.createElement('div');
					el.id = id;
					el.style.position = 'absolute';
					el.style.left = '0';
					el.style.top = '0';
					el.style.display = 'none';
					document.body.appendChild(el);					
					obj = this.$(id);
					obj.innerHTML = this.getInnerHTML(id, width, height);
				}
			}			
            return obj;
        },

        getHeader : function () {
            if (!header && this.$(id + '_header')) {				
				header = this.$(id + '_header');
				header.onmousedown = this.mouseDown.createDelegate(this);
				header.onmouseup = this.mouseUp.createDelegate(this);
				if(this.$(id + '_closer')) {
					this.$(id + '_closer').onclick = this.hide.createDelegate(this);
				}
			}
            return header;
        },
           
		getContents : function () {
		    if (!contents) {
				contents = this.$(id + '_cont');
			}
			return contents;
		},
		   
        syncIframe : function () {
             var _obj = this.getObj();
			 var c = this.getContents();
			 var header = this.getHeader();
        },
                      
        hide : function () {
            this.getObj().style.display = 'none';
			this.hideMask();			
        },
		
		showHideCombos : function(show) {
			var el = document.getElementsByTagName('select');			
			for(var i = 0, len = el.length; i < len; i++) {
				el[i].style.visibility = show ? 'visible' : 'hidden';				
			}
		},
		
		getHTML : function(id) {
			return '<div id="' + id + '" style="position:absolute;left:0;top:0;display:none;"></div>';
		},
		
		getInnerHTML : function(id, width, height) {
			if(!width) {
				width = 250;
			}
			return '<table id="' + id + '_cont" width="' + width + '" height="' + height + '" border="0" cellspacing="0" cellpadding="0" style="margin-bottom:12px;">' +
				'<tr>' + 
		            '<td width="5"><img src="/images/box_csides.gif" alt="" width="5" height="34" /></td>' +
		            '<td width="290" id="' + id + '_title" style="height:34px;line-height:34px;vertical-align:middle;font-size:14px;color:#333333;background:url(/images/box_ctop.gif) repeat-x top left;padding:0 12px;">&nbsp;</td>' +
		            '<td width="5"><img src="/images/box_csides.gif" alt="" width="5" height="34" /></td>' +
	            '</tr>' +
				'<tr>' +
					'<td bgcolor="#f8dede">&nbsp;</td>' +
					'<td class="boxcontent" bgcolor="#ffffff">' + 
						'<table border="0" cellspacing="0" cellpadding="0" id="simplebox">' +
							'<tr><td>' +
								'<table border="0" cellspacing="0" cellpadding="0" id="regtable">' +								
									'<tr><td td id="' + id + '_msg"></td></tr>' +
								'</table>' +
								'<table width="' + width + '" border="0" cellspacing="0" cellpadding="0" style="margin-bottom:12px;">' +
										'<tr>' +
											'<td align="left" style="padding-left:20px;"></td>' +
											'<td align="right">' +
											'<img id="' + id + '_yes_btn" src="/MLSupport/' + lngDir + '/button/btn_cok.gif" style="cursor:pointer" border="0">' + 
											'<img id="' + id + '_close_btn" src="/MLSupport/' + lngDir + '/button/btn_cclose.gif" style="cursor:pointer" border="0">' +
											'<img id="' + id + '_next_btn" src="/MLSupport/' + lngDir + '/button/btn_cnext.gif" style="cursor:pointer" border="0"></td>' +
										'</tr>' +
								'</table>' +				
							'</td></tr>' +
						'</table>' +
					'</td>' +
					'<td bgcolor="#f8dede">&nbsp;</td>' +
				'</tr>' +
				'<tr>' +
					'<td style="background:url(/images/box_cbottom.gif) repeat-x top left;" colspan="3"><img src="/images/spacer.gif" alt="" width="1" height="6" /></td>'
				'</tr>' +
			'</table>';						
		}
	}
}