﻿/*** UpdateProgress ************************************************************/
function positionVertical(id) {
	var o = document.getElementById(id);
	if (o) {
		if (navigator.appName == 'Microsoft Internet Explorer') {
			o.style.top = (document.documentElement.scrollTop + (document.documentElement.offsetHeight / 2) - 50) + 'px';
		} else if (navigator.appName == 'Netscape') {
			o.style.top = (window.pageYOffset + (window.innerHeight / 2) - 50) + 'px';
		}
	} else {
		alert(id + " unbekannte id");
	}
}

/*** Utilities *****************************************************************/
function upload(obj) {
	__doPostBack(obj.name, '');
}

/*** Menue Steuerung ***********************************************************/
var menue_wait = new Object();
function menue_show(arg) {
	menue_hide_exec();
	menue_wait[arg] = false;
	document.getElementById(arg).style.display = 'block';
}

function menue_hide(arg) {
	menue_wait[arg] = true;
	setTimeout(menue_hide_exec, 250);
}

function menue_hide_exec() {
	for (n in menue_wait)
		if (menue_wait[n]) document.getElementById(n).style.display = 'none';
}

/*** allgemeiner Error-Callback für asynchrone Aufrufe *************************/
function onCallbackError(error, userContext, methodName) { //{{{
	if (error.get_exceptionType() == "System.Threading.ThreadAbortException") {
		Ext.Msg.alert("Fehler ", error.get_message() + "<br>in " + methodName + "<br><br>" + error.get_stackTrace());
	} else {
		Ext.Msg.alert("Fehler ", error.get_message() + "<br>in " + methodName + "<br><br>" + error.get_stackTrace());
	}
} //}}} onCallbackError


/*** Scrollbalken entfernen/wiederherstellen und bei IE die selects aus-/einblenden ***/
function showScrollBars(show) {
	var ovrflw = show ? 'auto' : 'hidden';
	Ext.getBody().setStyle('overflow', ovrflw);
	if (Ext.isIE6 || Ext.isIE7) {
		var htm = document.getElementsByTagName('HTML')[0];
		if (htm) {
			htm.style.overflow = ovrflw;
		}
		var selects = document.getElementsByTagName('select');
		var vsblty = show ? 'visible' : 'hidden';
		for (i = 0; i < selects.length; i++) {
			selects[i].style.visibility = vsblty;
		}
	}
}

/*########################################################################*/
/*### Ein-/Ausklappen der Resizeboxen ####################################*/
/*########################################################################*/
function ResizeBox_Resize(a_close) {
	var id = a_close.id.replace(/aclose/, '');
	var div_label = document.getElementById(id + 'div_label');
	var div_content = document.getElementById(id + 'div_content');
	var img_icon = document.getElementById(id + 'img_icon');
	var span_text = document.getElementById(id + 'span_text');
	
	/*-- HiddenFields --*/
	var isOpen = document.getElementById(id + 'isOpen');
	var minIcon = document.getElementById(id + 'minIcon');
	var maxIcon = document.getElementById(id + 'maxIcon');
	var openText = document.getElementById(id + 'openText');
	var closeText = document.getElementById(id + 'closeText');
	var labelCSS = document.getElementById(id + 'labelCSS');
	var activeLabelCSS = document.getElementById(id + 'activeLabelCSS');

	if (isOpen.value == '1') {
		img_icon.src = maxIcon.value;
		span_text.innerHTML = openText.value;
		div_content.style.display = 'none';
		isOpen.value = '0';
		var className = "ResizeBox_Label";
		if (null != labelCSS && "string" == typeof labelCSS.value && 0 < labelCSS.value.length) {
			className += " " + labelCSS.value;
		}
		div_label.className = className;
	} else {
		img_icon.src = minIcon.value;
		span_text.innerHTML = closeText.value;
		div_content.style.display = 'block';
		isOpen.value = '1';
		var className = "ResizeBox_Label";
		if (null != activeLabelCSS && "string" == typeof activeLabelCSS.value && 0 < activeLabelCSS.value.length) {
			className += " " + activeLabelCSS.value;
		} else if (null != labelCSS && "string" == typeof labelCSS.value && 0 < labelCSS.value.length) {
			className += " " + labelCSS.value;
		}
		div_label.className = className;

	}
}

/*** ein-/ausklappen der ResizeBoxEvent ****************************************/
function ResizeBoxEvent_Resize(a_close) {
	var id = a_close.id.replace(/aclose/, '');
	var div_label = document.getElementById(id + 'div_label');
	var div_content = document.getElementById(id + 'div_content');
	
	/*-- HiddenFields --*/
	var isOpen = document.getElementById(id + 'isOpen');
	var labelCSS = document.getElementById(id + 'labelCSS');
	var activeLabelCSS = document.getElementById(id + 'activeLabelCSS');

	if (isOpen.value == '1') {
		div_content.style.display = 'none';
		isOpen.value = '0';
		var className = "ResizeBox_Label";
		if (null != labelCSS && "string" == typeof labelCSS.value && 0 < labelCSS.value.length) {
			className += " " + labelCSS.value;
		}
		div_label.className = className;
	} else {
		
		div_content.style.display = 'block';
		isOpen.value = '1';
		var className = "ResizeBox_Label";
		if (null != activeLabelCSS && "string" == typeof activeLabelCSS.value && 0 < activeLabelCSS.value.length) {
			className += " " + activeLabelCSS.value;
		} else if (null != labelCSS && "string" == typeof labelCSS.value && 0 < labelCSS.value.length) {
			className += " " + labelCSS.value;
		}
		div_label.className = className;

	}
}



/*########################################################################*/
/*### Arrays in Strings verpacken (App_Code\SAS_App_Code.cs:StrElement) ##*/
/*########################################################################*/
var __sep = ':';

String.prototype.asElement = function() {
	return this.length.toString() + __sep + this;
}

String.prototype.appendElement = function(e) {
	return this + e;
}

String.prototype.locateElement = function(n) {
	var b = 0, e;
	while (n > 0) {
		e = this.indexOf(__sep, b);
		if (e > 0) {
			b = e + parseInt(this.substring(b, e)) + 1;
			--n;
		} else {
			b = n = -1;
		}
	}
	return b;
}

String.prototype.countElements = function() {
	var b = 0, c = 0, e = 0, l = this.length;
	while (b < l) {
		e = this.indexOf(__sep, b);
		b = (e > 0) ? e + parseInt(this.substring(b, e)) + 1 : l;
		++c;
	}
	return c;
}

String.prototype.getElement = function(n) {
	var b = this.locateElement(n);
	var e = this.indexOf(__sep, b);
	return this.substring(e + 1, e + 1 + parseInt(this.substring(b, e)));
}

String.prototype.headElements = function(n) {
	return this.substring(0, this.locateElement(n + 1));
}

String.prototype.tailElements = function(n) {
	return this.substring(this.locateElement(n), this.length);
}

String.prototype.setElement = function(e, i) {
	return this.headElements(i - 1) + e + this.tailElements(i + 1);
}

/*** FreeCall/KontaktBox ein-/ausklappen ************************************/
function toggleKontaktView() {
	var d = document.getElementById('KontaktDaten');
	var i = document.getElementById('KontaktStatus');
	if (d.style.display == 'block') {
		d.style.display = 'none';
		i.src = '/Sites/SAS/gfx/kontaktbox-knopf-oeffnen.png';
	} else {
		d.style.display = 'block';
		i.src = '/Sites/SAS/gfx/kontaktbox-knopf-schliessen.png';
	}
}

/*** Merkzettel-Liste *******************************************************/
function hidePanel() {
	var pan = document.getElementById("div_addColumnPanel");
	pan.style.visibility = "hidden";
}

function showPanel() {
	var pan = document.getElementById("div_addColumnPanel");
	pan.style.visibility = "visible";
}



/*########################################################################*/
/*### Client-Server-Kommunikation (obsolet) ##############################*/
/*########################################################################*/
var __seqId = 0;
var __pageTitle = null;
var __ring = {
	data: new Array(16),
	rpos: 0,
	wpos: 0,
	clear: function() {
		for (var i = this.data.length; i > 0; ) this.data[--i] = null;
		this.rpos = this.wpos = 0;
	},
	write: function(message) {
		if (this.data[this.wpos] != null) {
			return false;
		} else {
			this.data[this.wpos] = message;
			this.wpos = (this.wpos + 1) % this.data.length;
			return true;
		}
	},
	read: function() {
		var res = this.data[this.rpos];
		if (res != null) {
			this.rpos = (this.rpos + 1) % this.data.length;
		}
		return res;
	},
	canWrite: function() {
		return this.data[this.wpos] == null;
	}
}

function __recv(elements) {
	while (elements.countElements() > 1) {
		var page = elements.getElement(0);
		if (page == __pageTitle.getElement(0)) {
			var x = elements.getElement(1);
			eval(x);
		}
		elements = elements.tail(2);
	}
}

function __error(exception) {
	alert(exception._message);
}

function __send(message) {
	if (__pageTitle != null) {
		__seqId++;
		SAS.ClientMessage(__pageTitle.asElement() + __seqId.toString().asElement() + message.asElement(), __recv, __error);
	}
}

function __sendRing() {
	var messages = "";
	for (var text = __ring.read(); text != null; text = __ring.read()) {
		messages += text.asElement();
	}
	__send(messages);
}

function __pageLoad(pageTitle) {
	if (__pageTitle != null) {
	}
	__pageTitle = pageTitle;
	__ring.clear();
	var s = "load(" + pageTitle + ")";
	__send(s.asElement());
}

function __pageUnload(pageTitle) {
	if (pageTitle == __pageTitle) __pageTitle = null;
	var s = "unload(" + pageTitle + ")";
	var b = __ring.write(s);
	__sendRing();
	if (!b) __send(s.asElement());
}

function printMe(url){
    newWin = window.open(url,"Printversion","width=560,height=600,status=no,scrollbars=yes,resizable=yes");
    newWin.focus();
}

/*** Catalog.aspx: Objekte ein/ausklappen **********************************/
function toggleObjectView(divId, img) {
	var o = document.getElementById(divId);
	if (o.style.display == 'none') {
		o.style.display = 'block';
		img.src = '/Sites/SAS/gfx/pfeil_runter_dom.gif';
	} else {
		o.style.display = 'none';
		img.src = '/Sites/SAS/gfx/pfeil_rechts_dom.gif';
	}
}

/*** unload *****************************************************************/
function __leavePage() {
	if (SAS && "function" == typeof SAS.leavePage) {
		SAS.leavePage();
	}
}

function setPageReload(id) {
	if(document.getElementById(id).checked == true) {
		window.setTimeout('location.reload()', 900000);
	}
}



/*########################################################################*/
/*### PopUpWindow ########################################################*/
/*########################################################################*/
var pwSpot = null;

function openPopWindow(url, width, height) {
	var popwin = Ext.get('popup_window');
	var popdiv = Ext.get('popup_outer');
	var ptable = Ext.get('popup_table');
	if (null != popwin && null != popdiv && null != ptable) {
		showScrollBars(false);
		popwin.setStyle('width', width + 'px');
		popwin.setStyle('height', height + 'px');
		popwin.dom.src = url;
		popdiv.setStyle('width', width + 'px');
		popdiv.setStyle('display', 'block');
		ptable.setStyle('visibility', 'visible');
		if (null == pwSpot) {
			pwSpot = new Ext.ux.Spotlight({
				easing: 'easeOut',
				duration: 0.3,
				animate: false
			});
		}
		pwSpot.show(popdiv);
	}
}

function closePopWindow() {
	var popdiv = Ext.get('popup_outer');
	var ptable = Ext.get('popup_table');
	if (null != popdiv && null != ptable && null != pwSpot) {
		popdiv.setStyle('display', 'none');
		ptable.setStyle('visibility', 'hidden');
		pwSpot.hide();
		showScrollBars(true);
	}
}



/*########################################################################*/
/*### ProspektPopUp ######################################################*/
/*########################################################################*/
var ppu_intervalID;
var ppu_timeoutID;
var ppu_yOffset;
var ppu_width;
var ppu_height;

function ppu_getPopUp() {
	return document.getElementById('div_ProspektPopUp');
}

function ppu_displayPopUp() {
	var body = document.getElementsByTagName('body')[0];
	var popup = ppu_getPopUp();
	var width = body.clientWidth;
	var height = body.clientHeight;
	popup.style.top = (height - ppu_yOffset) + 'px';
	popup.style.left = (width - ppu_width) + 'px';
}

function ppu_moveProspektPopUp() {
	if (ppu_yOffset < ppu_height) {
		ppu_yOffset += 4;
		if (ppu_yOffset > ppu_height) ppu_yOffset = ppu_height;
		ppu_displayPopUp();
	} else {
		clearInterval(ppu_intervalID);
	}
}

function ppu_delayedInitPopUp() {
	clearTimeout(ppu_timeoutID);
	var popup = ppu_getPopUp();
	popup.style.display = 'block';
	ppu_height = popup.offsetHeight;
	ppu_width = popup.offsetWidth;
	ppu_yOffset = 0;

	ppu_intervalID = setInterval(ppu_moveProspektPopUp, 40);
	//ppu_timeoutID = setTimeout(ppu_donePopUp, 10000);
	window.onresize = ppu_displayPopUp;
}

function ppu_initPopUp() {
	ppu_timeoutID = setTimeout(ppu_delayedInitPopUp, 2000);
}

function ppu_donePopUp() {
	//clearTimeout(ppu_timeoutID);
	ppu_getPopUp().style.display = 'none';
}



/*########################################################################*/
/*### VIP-Shuttle-Reinfahr-Teaser ########################################*/
/*########################################################################*/
var vip_intervalId;
var vip_t0;
var vip_s = 771; // Breite des Bildes
var vip_t = 2.0;
var vip_v0 = vip_s * 2.0 / vip_t;
var vip_a = vip_v0 / vip_t;

function vip_initialize() {
	var jetzt = new Date();
	vip_t0 = 0;
	vip_intervalId = setInterval("vip_intervalCallback()", 2000);
}

function vip_intervalCallback() {
	var jetzt = new Date();
	if (vip_t0 == 0) {
		clearInterval(vip_intervalId);
		vip_t0 = jetzt.getTime();
		vip_intervalId = setInterval("vip_intervalCallback()", 20);
	} else {
		var t = (jetzt.getTime() - vip_t0) / 1000;
		var length;
		if (t < vip_t) {
			length = vip_v0 * t - 0.5 * vip_a * t * t;
		} else {
			length = vip_s;
			clearInterval(vip_intervalId);
		}
		var vip_png = document.getElementById('vip_png');
		var right = "" + Math.floor(length - vip_s) + "px";
		vip_png.style['right'] = right;
	}
}

//var vip_anim_object;
//var img_obj;

//function vip_intervalCallback2(pos, smobj) {
//	img_obj.style['right'] = pos + 'px';
//}

//function vip_completeCallback(smobj) {

//}

//function vip_initialize2() {
//	img_obj = document.getElementById('vip_png');
//	if (img_obj) {
//		vip_anim_object = new SmoothMovement(-1542, 0);
//		vip_anim_object.animate(40, vip_intervalCallback2, vip_completeCallback);
//	}
//}


/*########################################################################*/
/*### Ein-/Ausklappen der KlappBoxen #####################################*/
/*########################################################################*/
function KlappBox_Resize(a_close) {
	var id = a_close.id.replace(/aclose/, '');
	var div_show = document.getElementById(id + 'div_show');
	var div_hide = document.getElementById(id + 'div_hide');
	var div_content = document.getElementById(id + 'div_content');
	var minimized = document.getElementById(id + 'minimized');
	if (div_show && div_hide && div_content && minimized) {
		if (div_content.style.display != 'none') {
			minimized.value = '1';
			div_content.style.display = 'none';
			div_show.style.display = 'none';
			div_hide.style.display = 'block';
		} else {
			minimized.value = '0';
			div_content.style.display = 'block';
			div_show.style.display = 'block';
			div_hide.style.display = 'none';
		}
	} else {
		/*** Felder nicht definiert ***/
	}
}



/*########################################################################*/
/*### SocialBookmarks ####################################################*/
/*########################################################################*/

function socialBookmarks_Toggle(obj) {
	var mb = document.getElementById('more_bookmarks');
	if (mb) {
		if (mb.style['visibility'] == 'hidden') {
			mb.style['visibility'] = 'visible';
			obj.style['border-bottom'] = '1px solid White';
			obj.style.backgroundImage = 'url(/Sites/SAS/gfx/btn_down_Arrow.png)';
		} else {
			mb.style['visibility'] = 'hidden';
			obj.style['border-bottom'] = obj.style['border-top'];
			obj.style.backgroundImage = 'url(/Sites/SAS/gfx/btn_TabSeach_Arrow.png)';
		}
	}
	if (obj.blur) {
		obj.blur();
	}
}



/*########################################################################*/
/*### StartPage: rotierende Gesichter der SAS-Mitarbeiter ################*/
/*########################################################################*/

var __freecall_PictureWidth = 50;

function rotatingFacesInit() {
	setInterval("rotateFaces()", 10000);
}

function rotateFaces() {
	var d = Ext.get(document.getElementById('freecall-content-faces-line'));
	if (d) {
		var s = d.getStyle('left');
		if ('string' === typeof s) {
			var l = parseInt(s.replace(/px/, ''), 10);
			var w = d.getWidth();
			if (w + l <= __freecall_PictureWidth) {
				d.applyStyles('left: 0');
				l = 0;
			}
			d.animate({ left: { to: (l - __freecall_PictureWidth) } }, 0.33, null, 'easeOut', 'motion');
		}
	}
}

