/*

	*********************************************************
	*                                                       *
	*  Besten Dank fuer Ihr Interesse am JS-Code!           *
	*  Best thanks for reading the JS code!                 *
	*                                                       *
	*  ___________________________________________________  *
	*                                                       *
	*  Haben Sie Fragen zu dieser Webseite, bitte           *
	*  kontaktieren Sie uns: contact@io-market.com          *
	*  If you have any questions about this website         *
	*  please contact: contact@io-market.com                *
	*                                                       *
	*  ___________________________________________________  *
	*                                                       *
	*  All rights reserved! io-market AG - 11/2006          *
	*                                                       *
	*********************************************************
	
*/

// history back?
if (ret = iomGetCookie('HISTORYCTRL')) {
	iomClearCookie('HISTORYCTRL');
	top.location.href = d.weburl+d.glourl+unescape(ret);
}

//
// onerror
//
var showError = true;
function stopJSError(msg, file, row) { 
	var error = "Fehler: "+msg+" / Zeile:"+row;
	try {if(window.location.search != ""){tmp=window.location.search;error+="&s="+escape(tmp.substr(1));}}catch(e){}	
	try {if(d.formlnk!=""){error+="&f="+escape(d.formlnk);}}catch(e){}	
	//try {var xmlHttpMail = initAjax();if(xmlHttpMail){xmlHttpMail.open('GET',"/ajax.cfm?pop=jserror&q="+error+"&rand="+Math.random(),true);xmlHttpMail.send(null);}}catch(e){}
	//try {d.getElementById("jsError").innerHTML="JavaScript-Fehler: "+msg;if(showError){showError = false;setTimeout("showJSError()", 2000);}}catch(e){}
	//try {iomSetCookie('PAGEREFRESH', 'yes');}catch(e){}
	return true;
}

function showJSError() {	
	showError = true;
	d.getElementById("jsError").innerHTML = "";
}

if (Prototype.Browser.IE) window.onerror=stopJSError;	

/////////////////////////
function workProtector() {
	return true;
}
/////////////////////////

//
// initialize global variables
//
w = window; d = document; mon = screen; var isit = new String(d.location);

if (!document.glourl) {
	url_protocol = window.location.protocol;
	url_host = window.location.host;
	url_path = window.location.pathname;	
	document.glourl = url_protocol+"//"+url_host+url_path;
}

if (mon) {mon_w = mon.width;mon_h = mon.height; if(navigator.appName.indexOf("Microsoft")!=-1){mon_aw = mon.availWidth;mon_ah = mon.availHeight;} else {mon_aw = mon.availWidth;mon_ah = parseInt(mon.availHeight-100);}} else {mon_w = 750;mon_h = 500;mon_aw = 700;mon_ah = 450;}

xpos = 100; ypos = 100;

var dd_u = "undefined";
dd_ie = (navigator.appVersion.indexOf("MSIE")!=-1);
op = !!(window.opera && document.getElementById); // opera?

function browserDetect() {
	this.n = navigator.userAgent.toLowerCase();
	this.db = (document.compatMode && document.compatMode.toLowerCase() != "backcompat")?
		document.documentElement
		: (document.body || null);
	this.op = !!(window.opera && document.getElementById);
	this.op6 = !!(this.op && !(this.db && this.db.innerHTML));
	if (this.op && !this.op6) document.onmousedown = new Function('e',
		'if (((e = e || window.event).target || e.srcElement).tagName == "IMAGE") return false;');
	this.ie = !!(this.n.indexOf("msie") >= 0 && document.all && this.db && !this.op);
	this.iemac = !!(this.ie && this.n.indexOf("mac") >= 0);
	this.ie4 = !!(this.ie && this.ie && !document.getElementById);
	this.ie501 = !!(!this.ie && !this.db && this.n.indexOf('msie 5.01') >= 0);
	this.ie55 = !!(!this.ie && !this.db && this.n.indexOf('msie 5.5') >= 0);
	this.ie6 = !!(this.ie && this.n.indexOf('msie 6') >= 0);
	this.ie7 = !!(this.ie && this.n.indexOf('msie 7') >= 0);
	this.n4 = !!(document.layers && typeof document.classes != dd_u);
	this.n6 = !!(typeof window.getComputedStyle != dd_u && typeof document.createRange != dd_u);
	this.w3c = !!(!this.op && !this.ie && !this.n6 && document.getElementById);
	this.ce = !!(document.captureEvents && document.releaseEvents);
}
// browser detect
dd = new browserDetect();

//
// round
//
function roundValue(x, n) {
	if (n < 1 || n > 14) return false;
	var e = Math.pow(10, n);
	var k = (Math.round(x * e) / e).toString();
	if (k.indexOf('.') == -1) k += '.';
	k += e.toString().substring(1);
	return k.substring(0, k.indexOf('.') + n+1);
}

//
// set price format
//
function ioPriceFormat(p, d) {
	return roundValue(roundValue((p/5), d)*5, d)
}

//
// decrypt mailadress
//
function iomCrypMailto(s) 
{
 var n = 0, r = "";
 var c = unescape(s);
 for(var i=0; i < c.length; i++) 
 { 
  n = c.charCodeAt(i); 
  if (n >= 8364) {n = 128;}
  r += String.fromCharCode(n-(5));
 }
 return r;
}
// open decrypted mail
function iomGetMailto(s) 
{
 location.href = iomCrypMailto(s);
}

//
// cookie management
//
function iomClearCookie(cookieName) {
	var now = new Date();
	yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
	iomSetCookie(cookieName, 'cookieValue', yesterday);
}
function iomSetCookie(cookieName, cookieValue, expires, path, domain, secure) {
	document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}
function iomGetCookie(cookieName) {
	var cookieValue = '';
	var posName = document.cookie.indexOf(escape(cookieName) + '=');
	if (posName != -1) {
		var posValue = posName + (escape(cookieName) + '=').length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
		else cookieValue = unescape(document.cookie.substring(posValue));
	}
	return (cookieValue);
}

//
// prepare text
//
function repNewline(txt) {
	try {newtxt = decodeURI(txt);} catch(e) {newtxt = txt;}
	if (newtxt.indexOf('\\n')!=-1) {	
		do {newtxt = newtxt.replace('\\n','\n');} 
		while(newtxt.indexOf('\\n')!=-1);	
	} else if (newtxt.indexOf('\r')!=-1) {	
		do {newtxt = newtxt.replace('\r','');} 
		while(newtxt.indexOf('\r')!=-1);	
	} else if (newtxt.indexOf('%0D')!=-1) {	
		do {newtxt = newtxt.replace('%0D','');} 
		while(newtxt.indexOf('%0D')!=-1);					
	} else if (newtxt.indexOf('%5Cn')!=-1) {	
		do {newtxt = newtxt.replace('%5Cn','\n');} 
		while(newtxt.indexOf('%5Cn')!=-1);
	} else if (newtxt.indexOf('<br>')!=-1) {	
		do {newtxt = newtxt.replace('<br>','\n');} 
		while(newtxt.indexOf('<br>')!=-1);	
	} else if (newtxt.indexOf('<br />')!=-1) {	
		do {newtxt = newtxt.replace('<br />','\n');} 
		while(newtxt.indexOf('<br />')!=-1);	
	}		
	return unescape(newtxt);
}

function repFormline(txt) {
	try {newtxt = decodeURI(txt);} catch(e) {newtxt = txt;}
	if (newtxt.indexOf('<')!=-1) {	
		do {newtxt = newtxt.replace('<','&lt;');} 
		while(newtxt.indexOf('<')!=-1);
	}	
	if (newtxt.indexOf('>')!=-1) {	
		do {newtxt = newtxt.replace('>','&gt;');} 
		while(newtxt.indexOf('>')!=-1);
	}		
	if (newtxt.indexOf('\n')!=-1) {	
		do {newtxt = newtxt.replace('\n','<br />');} 
		while(newtxt.indexOf('\n')!=-1);
	}
	return unescape(newtxt);
}

// 
// check ask array
//
function checkAskArr(arr) {
	if (!d.arrask) {
		d.arrask = new Array();
		for (i=0;i<=arr;i++) {d.arrask[i] = "Are you sure?\n";}
	}
}

//
// open new browser window (not popup)
//
function openBrowser(qry, url) {
	var wurl = (qry!="") ? url+".cfm?"+qry : url+".cfm";
	d.winBrowser = window.open(wurl);
	if (d.winBrowser) {d.winBrowser.window.focus();}
}

//
// open popup window
//
function openPopUp(qry, url, nam, ww, wh, res, bar, stt, sec, too) {
	if (!res) {res = "yes";}
	if (!bar) {bar = "yes";}
	if (!stt) {stt = "no";}	
	if (!too) {too = "no";}	
	if (ww > mon_w) {ww = mon_w;}
	if (wh > mon_h) {wh = mon_h;}
	var loc = "PopUpWindow";
	var wargs = "width="+ww+",height="+wh+",scrollbars="+bar+",resizable="+res+",status="+stt+",location="+loc+",toolbar="+too;
	var wurl = (qry!="") ? url+".cfm?"+qry : url+".cfm";
	winPop = window.open(wurl,"PoP"+nam,wargs);
	checkPopUp();
}

//
// check popup blocker
//
function checkPopUp() {
	if (winPop) {
		winPop.window.focus();
	} else {
		var popblockmsg = "PopUp-Blocker? Please disable it and reload this site!";
		alert(popblockmsg);
	}	
}

//
// ask/goto logout
//
function gloLogOut(msg, qry) { // logout
	var asknow = repNewline(msg);
	var logoutchk = confirm(asknow);
	if (logoutchk != false) {top.location.replace(d.weburl+d.glourl+"?"+qry);}
}

//
// preload images
//
function preloadImg() {
	if(d.images){ if(!d.das_p) d.das_p=new Array();
	var i,j=d.das_p.length,a=preloadImg.arguments; for(i=0; i<a.length; i++)	
	if (a[i].indexOf("#")!=0){ d.das_p[j]=new Image; d.das_p[j++].src=d.locimg+"/"+a[i];}}
}

//
// change image
//
function changeImg() {	
	var i,j=0,x,a=changeImg.arguments; d.das_sr=new Array; for(i=0;i<a.length;i++)
	if ((x=searchObj(a[i]))!=null){d.das_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=d.locimg+"/"+a[i+1];}
}

//
// resotre image ('rechange')
//
function restoreImg() {
	var i,x,a=document.das_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//
// serach object (id or name)
//
function searchObj(n, d) {
	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=searchObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

//
// get coord of a object (return x:y)
//
function getCoordXY(iom) {
	if (document.layers) { return iom; }
	var io={ x:0 ,y:0 };
	do {io.x+=parseInt(iom.offsetLeft); io.y+=parseInt(iom.offsetTop); iom=iom.offsetParent;} 
	while (iom);
	return io;
}

//
// set window status
//
function changeStatus(qry) {
	if (qry) { w.defaultStatus=document.url+"?"+qry; }
	else { w.defaultStatus=""; }
}

//
// gourl now (func-cadaver? 29.11.06)
//
function goURLnow(qry) {
	if (qry) {top.location.replace(d.weburl+"?"+qry);} else {top.location.replace(d.glourl);}
}

//
// go any url
//
function goUrl() {
	var u = goUrl.arguments;
	for (i=0;i<(u.length-1);i+=2) {
	var url=u[i],qry=u[i+1],hir=u[i+2];
	  if (!hir) {location.replace(url+"?"+qry);} 
	  else if (hir=="top") {top.location.replace(url+"?"+qry);}
	  else if (hir=="blank") {window.open(url+"?"+qry);}}
}

//
// create info layer
//
function createInfoLayer(id) {
	var objInfoLayer = document.createElement('div');
	if (!id) objId = 'gloInfoLayer';
	objInfoLayer.setAttribute('id', objId);
	objInfoLayer.style.display = 'none';
	objInfoLayer.style.position = 'absolute';
	objInfoLayer.style.top = '-2000px';
	objInfoLayer.style.left = '-2000px';	
	//if (!id) document.body.appendChild(objInfoLayer);	
	document.body.appendChild(objInfoLayer);	
	return;
}

//
// blur all links (nice effect)
//
function blurAllLinks() {	
	allLinks = document.getElementsByTagName('a');
	for(var i=0; i<allLinks.length; i++){
		iLink = allLinks[i];
		var actFocus = String(iLink.getAttribute('onfocus'));
		if (actFocus == 'null') iLink.onfocus = new Function("if(this.blur)this.blur()");
	}	
	return;
}

// init lightbox
function initLightbox() { myLightbox = new Lightbox(); }

//
// png goes transparency (simply the best^^ IE6)
//
if (dd.ie && !dd.ie7) {window.onload = function(){window.png = new PNGTransparency();window.png.create();}}
function PNGTransparency(){this.create = PNGTransparency_create;}
function PNGTransparency_create(){
	var i, img, oldsrc;
	var imgs = document.getElementsByTagName('img');
	for ( i=0; i < imgs.length; i++ ){
		img = imgs[i];
		if (img.src.indexOf('.png') != -1){
			oldsrc = img.src;
			img.src = d.imgurl+'/ai_ph.gif';
			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + oldsrc + "', sizingMethod='scale')";
		}
	}
}

//
// init protector
//
function initWhileLoadOld() {	
	var fileLoadingImage = document.weburl+"/img/loading.gif";
	var objBody = document.getElementsByTagName("body").item(0);		
	var objProtector = document.createElement("div");
	objProtector.setAttribute('id','protector');
	objProtector.style.display = 'none';
	objBody.appendChild(objProtector);	
	var objBar = document.createElement("div");
	objBar.setAttribute('id','barcontainer');
	objBar.style.display = 'none';
	objBody.appendChild(objBar);
	var objBarLoader = document.createElement("div");
	objBarLoader.setAttribute('id','barloader');
	objBar.appendChild(objBarLoader);	
	Element.setInnerHTML("barloader", "load - please wait...");	
}

function protectWhileLoadOld() {	
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}	
	var arrayPageSize = getPageSize();		
	Element.setHeight('protector', arrayPageSize[1]);		
	Element.show('protector');
	var arrayPageScroll = ioPageScroll();	
	Element.setStyle('barcontainer', {'top':((arrayPageSize[3]/2)+arrayPageScroll[1]-30)+'px'});
	Element.show('barcontainer');
}


function initWhileLoad() {	
	
	var layProtector = new Element("div");
	layProtector.setAttribute('id','protectorOverlay');	
	layProtector.setStyle({'position':'absolute', 'width':'100%', 'height':'100%', 'left':'0pt', 'top':'0pt', 'backgroundColor':'#000', 'zIndex':'4999'})
	layProtector.setOpacity(.4);
		
	var boxProtector = new Element("div");
	boxProtector.setAttribute('id','protectorBox');		
	boxProtector.setStyle({'position':'absolute', 'left':'50%', 'top':'100px', 'marginLeft':'-100px', 'width':'200px', 'backgroundColor':'#FFF', 'padding':'10px', 'color':'#999', 'textAlign':'center', 'zIndex':'5000'})	
	boxProtector.addClassName('rounded');
	
	var waitText = 'please wait...';
	if (!Prototype.Browser.IE) {		
		boxProtector.insert(new Element("p").insert(new Element('img', {'src':document.weburl+'/img/loading.gif', 'border':'0', 'width':'22', 'height':'22'} )));
	} else {
		waitText = 'load - please wait...';
	}
	boxProtector.insert(new Element("p").update(waitText));	
	
	layProtector.hide();
	boxProtector.hide();

	document.getElementsByTagName("body").item(0).insert(layProtector);
	document.getElementsByTagName("body").item(0).insert(boxProtector);
	
}

function protectWhileLoad() {	

	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}	
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = ioPageScroll();	
	
	if (arrayPageScroll[0]<=0) {
		$('protectorOverlay').setStyle({'height':arrayPageSize[1]+'px', 'width':'100%'}).show();		
		$('protectorBox').setStyle({'top':((arrayPageSize[3]/2)+arrayPageScroll[1]-100)+'px'}).show();	
	} else {
		$('protectorOverlay').setStyle({'height':arrayPageSize[1]+'px', 'width':(arrayPageSize[0]+arrayPageScroll[0]-16)+'px'}).show();		
		$('protectorBox').setStyle({'top':((arrayPageSize[3]/2)+arrayPageScroll[1]-100)+'px', 'left':((arrayPageSize[2]/2)+arrayPageScroll[0])+'px'}).show();	
	}
	
	window.onscroll = function (e) {
  		var arrayPageSize = getPageSize();	
		var arrayPageScroll = ioPageScroll();
		$('protectorBox').setStyle({'top':((arrayPageSize[3]/2)+arrayPageScroll[1]-100)+'px'})
	}
	
}


//
// remove 'index.cfm' in hyperlinks
//
function removeIndexLinks() {	
	links = d.getElementsByTagName('a');
	for(i=0;i<links.length;i++){
		var ilink = links[i];
		var actHref = String(ilink.getAttribute('href'));
		if (actHref.indexOf("/index.cfm") != -1) {
			var newHref = actHref.replace(/index.cfm/g, "");
			ilink.setAttribute('href', newHref);
		}
		if (actHref.indexOf("/undefined?") != -1) {
			var newHref = actHref.replace(/undefined/g, "");
			ilink.setAttribute('href', newHref);
		}
	}	
	forms = d.getElementsByTagName('form');
	for(i=0;i<forms.length;i++){
		var iform = forms[i];
		var actForm = String(iform.getAttribute('action'));
		if (actForm.indexOf("/index.cfm") != -1) {
			var newForm = actForm.replace(/index.cfm/g, "");
			iform.setAttribute('action', newForm);
		}		
	}			
	return;
}

//
// init onload 
//
var block = "block";
var none = "none";

function initSiteOnLoad() {	

	// init lightbox
	initLightbox()	
	
	// create infolayer
	createInfoLayer();
	
	// init protector
	initWhileLoad();
	
	// blur all links
	// blurAllLinks();	
	
	// remove index.cfm
	removeIndexLinks();	
	
	// start eventlistener
	//mouseEventInit();
	//mouseEventClick();
	
}

// start onLoad page
Event.observe(window, 'load', initSiteOnLoad, false);

// script is loaded...
document.pageloaded = true;
// eof