var openedFAQ = 9999;



function createXmlHttpRequestObject(){ // create an xmlhttprequestobject
	var xmlHttp; // save reference on XMLHttpRequest
	try { xmlHttp = new XMLHttpRequest(); // try to create an XMLHttpRequest Object
	} catch(e) { // try to create an XMLHttpRequest Object for Internet Explorer 6 an earlier
		var xmlHttpVersion = new Array("MSXML2.XMLHTTP.6.0",
									   "MSXML2.XMLHTTP.5.0",
									   "MSXML2.XMLHTTP.4.0",
									   "MSXML2.XMLHTTP.3.0",
									   "MSXML2.XMLHTTP",
									   "Microsoft.XMLHTTP");
		
		for (var i=0; i<xmlHttpVersion.length && !xmlHttp; i++){ // try id's 
			try {
				xmlHttp = new ActiveXObject(xmlHttpVersion[i]); // try to create an XMLHttpRequest Object for IE
			} catch (e) {  } //ignore errors
		}
	}
	
	if(!xmlHttp) alert("error creating the xmlhttprequest object"); // error if not possible to create XMLHttpRequest Object
	else return xmlHttp; // function will returns the Object if created 
}

function submitFormKey(ev, formName) { // catch the enterkey
	if(!ev) ev = window.event; 
	if(ev.keyCode == 13) return true;
}


function passwordAuditor(userPasswordField){ // check strongness of userpassword

	var userPassword = $(userPasswordField).value;
	var passwordAuditorVA = $('passwordAuditor');

	var hardRegex = new RegExp("^(?=.{10,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g")
	var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).*$", "g");
	var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
	
	passwordAuditorVA.className = (userPassword == '') ? 'elHide' : 'elShow';
	
	if(hardRegex.test(userPassword)) passwordAuditorVA.setStyle('background-position', '0 -210px');
	else if(strongRegex.test(userPassword)) passwordAuditorVA.setStyle('background-position', '0 -140px');
	else if(mediumRegex.test(userPassword)) passwordAuditorVA.setStyle('background-position', '0 -70px');
	else passwordAuditorVA.setStyle('background-position', '0 0');	

}



function showFlash(action){
	
	switch(action){
	
		case 'show': 
			
			var requiredMajorVersion = 8;
			var requiredMinorVersion = 0;
			var requiredRevision = 0;
			var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
		
			if(hasReqestedVersion) { (function(){ $('flashContent').innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="502" height="292" id="frame_b" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="' + heavyweight_image_storage + 'elements/flash/frame_b.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="' + heavyweight_image_storage + 'elements/flash/frame_b.swf" quality="high" bgcolor="#ffffff" width="502" height="292" name="frame_b" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>'; }).delay(400); }
			else { $('flashContent').className = 'elHide'; (function(){ $('oFrame2Img').src = heavyweight_image_storage + 'elements/images/ostendis_grafik.jpg'; }).delay(500);  }
			break;
		
		case 'remove': $('flashContent').innerHTML = '';
	}
			
}

function iconGallery(e, eid){

	if(!e) e = window.event; // register event for ie6 and later
	$(eid).set('morph', {duration: 500});
	$(eid +'d').set('morph', {duration: 400 });

	if(e.type == 'mouseover') { 

		$(eid).morph({'opacity': [1, 0.2], 'opacity': [0.2, 1]}); 
		$(eid +'d').morph({'opacity': [0, 1]});
	
	} else { 
		
		$(eid).morph({'opacity': [1, 0.6]}); 
		$(eid +'d').morph({'opacity': [1, 0]});

	}

}

function accordion(duration){

	var accordion = new Accordion($$('.toggler'),$$('.accordionContent'), {
		duration: duration,
		show: -1,
		height: true,
		onActive: function(toggler) { },
		onBackground: function(toggler) { },
		alwaysHide: 1
	});
	
}

function getRef(ref){

	var pointTo = '';
	for(var i = 0, y = ref.length; i <= y; i++) pointTo = pointTo + ref.charAt(ref.length-i);
	location.href = '\u006D\u0061\u0069\u006C\u0074\u006F\u003A' + pointTo;
	
}

function randomAppPic() {
	
	var ran = Math.floor(Math.random()*3);
	var picArray = new Array();
	
	picArray[0] = new Object();
	picArray[0]['path'] = heavyweight_image_storage+ 'elements/images/oobran_0.jpg';
	picArray[0]['link'] = globalDomain +'?sy=oah&sh=27b72cc84b731e86e2ee281b8fe4312ca4b55fc96884b2ff4cba1c5b25b74820';
	picArray[1] = new Object();
	picArray[1]['path'] = heavyweight_image_storage + 'elements/images/oobran_1.jpg';
	picArray[1]['link'] = globalDomain +'?sy=oah&sh=c726fa95c2a714ee3c5d00c7b7ee6256505e4d53091086709099e153651571b7';
	picArray[2] = new Object();
	picArray[2]['path'] = heavyweight_image_storage + 'elements/images/oobran_2.jpg';
	picArray[2]['link'] = globalDomain +'?sy=oah&sh=b769487c015b0bbfe91a10e04783744806abfb328b0a55315602c115463f350e';
	
	document.getElementById('sbAppPic').innerHTML = '<a href="'+ picArray[ran]['link'] +'" target="_blank"><img src="'+ picArray[ran]['path'] +'" /></a><a href="'+ picArray[ran]['link'] +'" target="_blank">Bewerbung &ouml;ffnen</a>';

}

function createXmlHttpRequestObject(){ // create an xmlhttprequestobject
	var xmlHttp; // save reference on XMLHttpRequest
	try { xmlHttp = new XMLHttpRequest(); // try to create an XMLHttpRequest Object
	} catch(e) { // try to create an XMLHttpRequest Object for Internet Explorer 6 an earlier
		var xmlHttpVersion = new Array("MSXML2.XMLHTTP.6.0",
									   "MSXML2.XMLHTTP.5.0",
									   "MSXML2.XMLHTTP.4.0",
									   "MSXML2.XMLHTTP.3.0",
									   "MSXML2.XMLHTTP",
									   "Microsoft.XMLHTTP");
		
		for (var i=0; i<xmlHttpVersion.length && !xmlHttp; i++){ // try id's 
			try {
				xmlHttp = new ActiveXObject(xmlHttpVersion[i]); // try to create an XMLHttpRequest Object for IE
			} catch (e) {  } //ignore errors
		}
	}
	
	if(!xmlHttp) alert("error creating the xmlhttprequest object"); // error if not possible to create XMLHttpRequest Object
	else return xmlHttp; // function will returns the Object if created 
}


function slideShowCalculate(amApp, amMonth){
	
	
	if(amApp > 600 || amApp <= 0) $('appAmount').setStyle('border', '1px solid #FF0000'); else $('appAmount').setStyle('border', '1px solid #6A89BA');
	if(amMonth > 24 || amApp <= 0) $('monthAmount').setStyle('border', '1px solid #FF0000'); else $('monthAmount').setStyle('border', '1px solid #6A89BA');
	if(amApp <= 600 && amMonth <= 24 && amApp > 0 && amMonth > 0) {
	
		xmlHttp = createXmlHttpRequestObject();
	
		if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
			
			xmlHttp.open('POST', 'modules/calcAjax.php', true);
			xmlHttp.onreadystatechange = function(){ if(xmlHttp.readyState == 4 && xmlHttp.status == 200) displayCalcs(); }
			xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");  
			xmlHttp.send('appAmount=' + amApp + '&monthAmount=' + amMonth); 
	
		}
		
	}

}
	
function displayCalcs(){

	$('calculator').className = 'elHide';
	$('calculatorResult').className = 'elShow';
	$('calculatorResult').innerHTML = xmlHttp.responseText;

}

function displayNewCalc(){

	$('calculator').className = 'elShow';
	$('calculatorResult').className = 'elHide';
	
}


function showSlideShowTip(tipId, type){ $(tipId).className = (type == 'show') ? 'elShow img_' + tipId : 'elHide'; }

function countChars(charsAmount, element){
	
	var maxSigns = charsAmount; 
	var commentLeft = maxSigns - $(element).value.length;	
	if(commentLeft <= 0) $(element).value = $(element).value.substring(0, maxSigns);

}

function opwToolTip(){
     $$('.toolTip').each(function(element,index) {  
         var content = element.get('title').split('::');  
         element.store('tip:title', content[0]);  
         element.store('tip:text', content[1]);  
    });  

	var opwTip = new Tips('.toolTip',{    
        hideDelay: 50,  
        showDelay: 50	
	});
	
	
	opwTip.addEvents({
		'show': function(tip){ $$('.tip').morph({duration: 800, 'opacity': [0, 1]}) },				 
		'hide': function(tip){ $$('.tip').morph({duration: 800, 'opacity': [1, 0]}) }
	});
	
}

function addCloseOnEscape(instanceName){
	document.onkeydown = function(e){
		if(navigator.appName=="Microsoft Internet Explorer"){
			if(event.keyCode == 27){ self[instanceName].close(); document.onkeydown = ''; }	
			document.getElementById('chatBotBox').style.visibility = 'visible';
		} else{
				if(e.which == 27){ self[instanceName].close(); document.onkeydown = ''; }	
				document.getElementById('chatBotBox').style.visibility = 'visible';
			}
	}
}

function showAppPreviews(){

	var content = new Element('div').setProperties({'id': 'appPreview_div'});
	//content.innerHTML = content.nodeValue = '<div class="appPreview_topLeft"><a href="https://secure.ostendis.ch/oob/?sy=oah&sh=b769487c015b0bbfe91a10e04783744806abfb328b0a55315602c115463f350e" target="_blank"><img src="elements/images/appPreview/1_dark.png" onmouseover="this.src=\'elements/images/appPreview/1.png\';" onmouseout="this.src=\'elements/images/appPreview/1_dark.png\';" /></a></div><div class="appPreview_topCenter"><a href="https://secure.ostendis.ch/oob/?sy=oah&sh=c726fa95c2a714ee3c5d00c7b7ee6256505e4d53091086709099e153651571b7" target="_blank"><img src="elements/images/appPreview/2_dark.png" onmouseover="this.src=\'elements/images/appPreview/2.png\';" onmouseout="this.src=\'elements/images/appPreview/2_dark.png\';" /></a></div><div class="appPreview_topRight"><a href="https://secure.ostendis.ch/oob/?sy=oah&sh=27b72cc84b731e86e2ee281b8fe4312ca4b55fc96884b2ff4cba1c5b25b74820" target="_blank"><img src="elements/images/appPreview/3_dark.png" onmouseover="this.src=\'elements/images/appPreview/3.png\';" onmouseout="this.src=\'elements/images/appPreview/3_dark.png\';" /></a></div><img src="elements/icons/ico_close.png" class="appPreview_closeButton" onclick="moopromptInstance.close();" onmouseover="this.src=\'elements/icons/ico_close_hover.png\';" onmouseout="this.src=\'elements/icons/ico_close.png\';" /><div class="appPreview_bottomLeft"><a href="https://secure.ostendis.ch/oob/?sy=oah&sh=10e3df375bdf3b936c804e520455669668d0af11261c81efa8cd3f719a20fc2d" target="_blank"><img src="elements/images/appPreview/4_dark.png" onmouseover="this.src=\'elements/images/appPreview/4.png\';" onmouseout="this.src=\'elements/images/appPreview/4_dark.png\';" /></a></div><div class="appPreview_bottomCenter"><a href="https://secure.ostendis.ch/oob/?sy=oah&sh=da178396ae06e4d749142a4c6242d5d9da62b855418ff61895c9eee32629cea9" target="_blank"><img src="elements/images/appPreview/5_dark.png" onmouseover="this.src=\'elements/images/appPreview/5.png\';" onmouseout="this.src=\'elements/images/appPreview/5_dark.png\';" /></a></div><div class="appPreview_bottomRight"><a href="https://secure.ostendis.ch/oob/?sy=oah&sh=10afa7145a4a057323c739badc1387c0f38d2c70469e1e59f3ac90ccd4de16ee" target="_blank"><img src="elements/images/appPreview/6_dark.png" onmouseover="this.src=\'elements/images/appPreview/6.png\';" onmouseout="this.src=\'elements/images/appPreview/6_dark.png\';" /></a></div><div style="border: 1px solid red; float: left; width: 500px; margin-top: 20px;"><img src="elements/images/appPreview/1.png" class="preloadImg" /><img src="elements/images/appPreview/2.png" class="preloadImg" /><img src="elements/images/appPreview/3.png" class="preloadImg" /><img src="elements/images/appPreview/4.png" class="preloadImg" /><img src="elements/images/appPreview/5.png" class="preloadImg" /><img src="elements/images/appPreview/6.png" class="preloadImg" /></div>'; 
	
	content.innerHTML = content.nodeValue = ''
	+'<div class="appPreview_topLeft">'
	+'	<a href="https://secure.ostendis.ch/oob/?sy=oah&sh=b769487c015b0bbfe91a10e04783744806abfb328b0a55315602c115463f350e" target="_blank">'
	+'		<img src="elements/images/appPreview/1_dark.jpg" onmouseover="this.src=\'elements/images/appPreview/1.jpg\';" onmouseout="this.src=\'elements/images/appPreview/1_dark.jpg\';" />'
	+'	</a>'
	+'</div>'
	
	+'<div class="appPreview_topCenter">'
	+'	<a href="https://secure.ostendis.ch/oob/?sy=oah&sh=c726fa95c2a714ee3c5d00c7b7ee6256505e4d53091086709099e153651571b7" target="_blank">'
	+'		<img src="elements/images/appPreview/2_dark.jpg" onmouseover="this.src=\'elements/images/appPreview/2.jpg\';" onmouseout="this.src=\'elements/images/appPreview/2_dark.jpg\';" />'
	+'	</a>'
	+'</div>'
	
	+'<div class="appPreview_topRight">'
	+'	<a href="https://secure.ostendis.ch/oob/?sy=oah&sh=27b72cc84b731e86e2ee281b8fe4312ca4b55fc96884b2ff4cba1c5b25b74820" target="_blank">'
	+'		<img src="elements/images/appPreview/3_dark.jpg" onmouseover="this.src=\'elements/images/appPreview/3.jpg\';" onmouseout="this.src=\'elements/images/appPreview/3_dark.jpg\';" />'
	+'	</a>'
	+'</div>'
	
	+'<img src="elements/icons/ico_close.png" class="appPreview_closeButton" onclick="moopromptInstance.close();" onmouseover="this.src=\'elements/icons/ico_close_hover.png\';" onmouseout="this.src=\'elements/icons/ico_close.png\';" />'
	
	+'<div class="appPreview_bottomLeft">'
	+'	<a href="https://secure.ostendis.ch/oob/?sy=oah&sh=10e3df375bdf3b936c804e520455669668d0af11261c81efa8cd3f719a20fc2d" target="_blank">'
	+'		<img src="elements/images/appPreview/4_dark.jpg" onmouseover="this.src=\'elements/images/appPreview/4.jpg\';" onmouseout="this.src=\'elements/images/appPreview/4_dark.jpg\';" />'
	+'	</a>'
	+'</div>'
	
	+'<div class="appPreview_bottomCenter">'
	+'	<a href="https://secure.ostendis.ch/oob/?sy=oah&sh=da178396ae06e4d749142a4c6242d5d9da62b855418ff61895c9eee32629cea9" target="_blank">'
	+'		<img src="elements/images/appPreview/5_dark.jpg" onmouseover="this.src=\'elements/images/appPreview/5.jpg\';" onmouseout="this.src=\'elements/images/appPreview/5_dark.jpg\';" />'
	+'	</a>'
	+'</div>'
	
	+'<div class="appPreview_bottomRight">'
	+'	<a href="https://secure.ostendis.ch/oob/?sy=oah&sh=10afa7145a4a057323c739badc1387c0f38d2c70469e1e59f3ac90ccd4de16ee" target="_blank">'
	+'		<img src="elements/images/appPreview/6_dark.jpg" onmouseover="this.src=\'elements/images/appPreview/6.jpg\';" onmouseout="this.src=\'elements/images/appPreview/6_dark.jpg\';" />'
	+'	</a>'
	+'</div>'; 
	
	divClose = new Element('div').setProperties({ 'class': 'popDialog pdClose', 'id': 'mpClose', 'style': 'width: 99%; margin-left: 0px;' });
		
	moopromptInstance = new MooPrompt('noOverlay','', content, {
		
		buttons: 1,
		overlay: false,
		width: 1020,
		height: 428,
		button1: divClose,
		horizontal: 'center',
		vertical: 'absoluteTop',
		effect:'fade',
		onButton1: function() { }
	
	});

	addCloseOnEscape('moopromptInstance');
	
}

function showScreenshot(picName){
	try{ self['moopromptInstanceScreenshot'].close(); } catch(e){ }
	document.getElementById('chatBotBox').style.visibility = 'hidden';

	switch(picName){
		case "template.jpg": picWidth = 924; picHeight = 457; break;
		case "advisor.jpg":  picWidth = 394; picHeight = 667; break;
		
		case "lap.jpg":  picWidth = 835; picHeight = 820; break;
		case "appcheck.jpg":  picWidth = 846; picHeight = 634; break;
		
		case "appsend.jpg":  picWidth = 924; picHeight = 693; break;
		case "mail.jpg":  picWidth = 924; picHeight = 733; break;
		case "application.jpg":  picWidth = 924; picHeight = 679; break;
		
		case "functions/template_1_big.jpg":  picWidth = 703; picHeight = 633; break;
		case "functions/template_2_big.jpg":  picWidth = 703; picHeight = 620; break;
		case "functions/template_3_big.jpg":  picWidth = 703; picHeight = 620; break;
		
		case "functions/application_1_big.jpg":  picWidth = 836; picHeight = 510; break;
		case "functions/application_2_big.jpg":  picWidth = 836; picHeight = 510; break;
		
		case "functions/app_activities_big.jpg":  picWidth = 824; picHeight = 692; break;
		
		case "functions/rav_big.jpg":  picWidth = 938; picHeight = 412; break;
	}
	
	var content = new Element('div').setProperties({'id': 'showScreenshot', 'style': 'margin-top: 0px;'});
	content.innerHTML = content.nodeValue = '<img src="elements/images/screenshots/' + picName + '" style="float: left;" />'; 
	
	divCloseTopRight = new Element('div').setProperties({'class': 'formCloseButton', 'id': 'formCloseButton' });
		
	moopromptInstanceScreenshot = new MooPrompt('showScreenshotClass','', content, {
		
		buttons: 1,
		overlay: true,
		width: picWidth,
		height: picHeight,
		button1: divCloseTopRight,
		horizontal: 'center',
		vertical: 'middle',
		effect:'grow',
		onButton1: function() { try { document.getElementById('chatBotBox').style.visibility = 'visible'; } catch(e){ } }
	
	});
	
	addCloseOnEscape('moopromptInstanceScreenshot');
	
}

function openAnswer(id){
	var openOrClosed = document.getElementById(id).style.display;
	
	if(openOrClosed == 'none'){
		document.getElementById(id).style.display = 'block';
		if(openedFAQ != 9999 && openedFAQ != id) document.getElementById(openedFAQ).style.display = 'none';
		openedFAQ = id;
	} else document.getElementById(id).style.display = 'none';
}

function showOstendisVideo(){
	var content = new Element('div').setProperties({'id': 'showScreenshot', 'style': 'margin-top: 0px;'});
	content.innerHTML = content.nodeValue = '<embed style="float: left;" src="http://c.brightcove.com/services/viewer/federated_f9/1569844385?isVid=1&publisherID=687883056" bgcolor="#FFFFFF" flashVars="playerID=30897834001&domain=embed&autoStart=true&@videoPlayer=ref:90807152602985305_auridiaGmbH_de" base="http://admin.brightcove.com" name="flashObj" width="490" height="326" seamlesstabbing="false" type="application/x-shockwave-flash" allowFullScreen="true" swLiveConnect="true" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"a></embed>'; 
	
	divCloseTopRight = new Element('div').setProperties({'class': 'formCloseButton', 'id': 'formCloseButton', 'style': 'margin-top: 3px;' });
		
	moopromptInstanceVideo = new MooPrompt('showScreenshotClass','', content, {
		
		buttons: 1,
		overlay: true,
		width: 515,
		height: 327,
		button1: divCloseTopRight,
		horizontal: 'center',
		vertical: 'middle',
		effect:'grow',
		onButton1: function() { }
	
	});
	
	addCloseOnEscape('moopromptInstanceVideo');
	
}

var globalVisibleValue = 10;
var min = 1;
var max = 5;
var globalTestimonial = Math.floor(Math.random() * (max - min + 1)) + min;
var InvisibleInterval;
var VisibleInterval;

function setInvisible(){
	if(globalVisibleValue < 0){
		clearInterval(InvisibleInterval);
		$('testimonial').src = "../elements/images/testimonials/testimonial_" + globalTestimonial + ".jpg";
		setVisible();
		VisibleInterval = window.setInterval("setVisible();", 65);
	} else {
		$('testimonial').style.opacity = globalVisibleValue/10;
		$('testimonial').style.filter = 'alpha(opacity=' + globalVisibleValue*10 + ')';
		globalVisibleValue--;
	}
}

function setVisible(){
	if(globalVisibleValue > 10){
		$("testimonial_next").onclick = function() { showTestimonal('next'); };
		$("testimonial_back").onclick = function() { showTestimonal('back'); };
		clearInterval(VisibleInterval);
	} else {
		$('testimonial').style.opacity = globalVisibleValue/10;
		$('testimonial').style.filter = 'alpha(opacity=' + globalVisibleValue*10 + ')';
		globalVisibleValue++;
	}
}

function showTestimonal(nextOrBack){
	$("testimonial_next").onclick = function() { };
	$("testimonial_back").onclick = function() { };
		
	if(nextOrBack == "next"){
		setInvisible();
		if(globalTestimonial < 5) globalTestimonial++;
		else globalTestimonial = 1;
		
		InvisibleInterval = window.setInterval("setInvisible();", 65);
	} else{
		setInvisible();
		if(globalTestimonial > 1) globalTestimonial--;
		else globalTestimonial = 5;
		
		InvisibleInterval = window.setInterval("setInvisible();", 65);
	}
	
}