/*

	*********************************************************
	*                                                       *
	*  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          *
	*                                                       *
	*********************************************************
	
*/

xpos = 100; ypos = 100;

//
// keyboard
//
function chkKeyTyp(e) {		
	var code = '';
	if (dd_ie) {code = event.keyCode;} 
	else if (!dd_ie && !e) {document.onkeypress=chkKeyTyp;}
	else if (!dd_ie && e) {code = e.which;}	
	code = (!code) ? 0 : code;
	return code;
}

// 
// url encoding
// 
function ioEscape(str) {
	var newstr = escape(str);
	newstr = newstr.replace("+", "%2B");
	newstr = newstr.replace("/", "%2F"); 	
	return newstr;
}

//
// show artdetails
//
showArtMoreStatus = new Object();
function showArtMoreInfo(id) {
	if (!showArtMoreStatus[id]) {
		showArtMoreStatus[id] = true;
		new Effect.BlindDown(id, { duration: 0.5, afterFinish: function() {	
				Element.show(id);
			} }  
		);				
	} else {
		showArtMoreStatus[id] = false;	
		new Effect.BlindUp(id, { duration: 0.5, afterFinish: function() {	
				Element.hide(id);
			} }  
		);	
	}
}

//
// ajax connection
//
var xmlHttp = false;
function initAjax() {
	xmlHttp = false;	
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	   xmlHttp = new XMLHttpRequest();
	   if (xmlHttp.overrideMimeType) {
	       xmlHttp.overrideMimeType('text/xml');
	   }
	} else if (window.ActiveXObject) { // IE
	   try {
	       xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	   } catch (e) {
	       try {
	       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	       } catch (e) {}
	   }
	}
	return xmlHttp;
}

//
// ajax (prepare and return xml struct)
//
function getXMLStruct(req) {		
	xmlModel = null;
	if (document.implementation && document.implementation.createDocument) {
		xmlModel = req.responseXML;
	} else {			
		  // special - only for IE! grrr... IE sucks...
		  if (!document.getElementById('_dataContainerXML')) {
			var dummy = document.createElement('div');
			dummy.setAttribute('id','_dataContainerXML');
			document.body.appendChild(dummy);
		} else if (document.getElementById('_dataContainerXML').childNodes.length) {
			var last = document.getElementById('_dataContainerXML').lastChild;
			dummy = document.getElementById('_dataContainerXML').removeChild(last);				
		}
		var ioXMLAppend = document.createElement('xml');
		ioXMLAppend.setAttribute('innerHTML',req.responseText);
		ioXMLAppend.setAttribute('id','_dataAjaxXML');
		document.getElementById('_dataContainerXML').appendChild(ioXMLAppend);
		document.getElementById('_dataAjaxXML').innerHTML = req.responseText;
		xmlModel = document.getElementById('_dataAjaxXML');	
	}	
	return xmlModel;
}

//
// get xml value
//
function getXMLValue(xmlModel,tagName,xmlPos) {	
	var returnData = "";
	var objData = xmlModel.getElementsByTagName(tagName)[xmlPos];
	if (objData.firstChild) {
		returnData = objData.firstChild.nodeValue;
	}
	return returnData;
}
function evalXMLCount(xmlModel,tagName) {	
	var xmlTree = "";
	xmlTree = xmlModel.getElementsByTagName(tagName);
	return xmlTree.length;
}

//
// box action (radio or checkbox)
//
function getBoxAction(boxid, boxtyp) {
	if (!boxtyp) {boxtyp = "check";}
	var chk = false;
	if ((o=searchObj(boxid))!=null) {
		if (!o.disabled) {
			switch (boxtyp) {		
				case "radio" : 
					chk = true;
					break;
				default : 
					chk = (o.checked) ? false : true;
					break;
			}
			o.checked = chk;
		}
	}	
}

//
// select or deselect all checkboxes (form)
//
function checkAllFormBoxes(frm, box) {
	var obj,dfe = eval("document."+frm+".elements.length");	
	for (i=0; i < dfe; i++) {		
		obj =  eval("document."+frm+".elements["+i+"]");
		if (obj.type == 'checkbox') {obj.checked = box.checked;}		
	}	
}

//
// select or deselect all checkboxes (same id)
//
function checkAllBoxes(boxid, boxcou, boxacter) {
	var boxchk = boxacter.checked;
	for (i=0; i < boxcou; i++) {
		if (d.getElementById(boxid+''+i) != null) {
		 d.getElementById(boxid+''+i).checked = boxchk;	
		}			
	}
}

//
// send all selected boxes
//
function sendAllBoxes(boxid, boxcou, sel, frm, boxact) {			
	var i = 0, objcou = 0; sendchk = false;		
	var selact = d.getElementById(sel).selectedIndex;
	var selarg = d.getElementById(sel).options[selact].value;
	if (selarg!=0) {
		var posarr = selarg.split("@");
		while (i < boxcou) {
			if (d.getElementById(boxid+''+i) != null) {
			 if (d.getElementById(boxid+''+i).checked) {
			  objcou++; sendchk = true;
			 }	
			} 
			i++;
		}
	}
	if (sendchk) {
		checkAskArr(boxcou);
		asknow = unescape(repNewline(d.arrask[posarr[1]]));
		if((askcheck=confirm(asknow)) == true) {
			var sendform = eval("d."+frm);
			sendform.submit(); return false;
		} else {
			if ((bact = searchObj(boxact)) != null) {
				bact.checked = (!bact.checked) ? true : false;
			}
			for (i=0;i<boxcou;i++) {
				if (d.getElementById(boxid+''+i) != null) {
				 if (d.getElementById(boxid+''+i).checked) {
		 		   d.getElementById(boxid+''+i).checked = false;
				 }	
				} 
			}
		}
	}
}

//
// form info
//
function setInfoStatus(err, msg) {
	if (err) {			
		if ((m=searchObj(d.valinfo))!=null) {
			m.className = "x1rt"; m.innerHTML = unescape(msg);
		} else {alert(unescape(msg));} 		
	} else {	
		if ((m=searchObj(d.valinfo))!=null) {
			m.className = "x1gr"; m.innerHTML = unescape(msg);
		}		
	}	
}

//
// control textarea
//
function textCounter(area, show, limit) {
	anzahl = area.value.length;
	stand = parseInt(limit-anzahl);
	if (stand < 0) {stand = 0;}
	d.getElementById(show).value = stand;
	if (anzahl>limit) {
		area_limit = area.value.substring(area.value, limit);
		area.value = area_limit;
	}
}

//
// 
//
function doCLnk(lnk, box, what, frm, pos) {	
	d.getbox = false;	
	getBoxAction(box,'checkbox');
	var doform = eval("d."+frm);
	doform.values.value = d.arrlnk[lnk];	
	if (what == "ask") {
		confirmActionForm(frm, pos);
		if (d.getbox) {getBoxAction(box,'checkbox');}
	} else {
		doform.submit(); return false;
	}
}

//
// confirm - go on link (simple)
//
function confAction(ask, qry) {
	var asknow = repNewline(ask);
	if((askcheck=confirm(asknow))==true) {top.location.replace(d.weburl+d.glourl+"?"+qry);}	
}

//
// confirm - go on link (without value)
// 
function confirmAction(pos, qry) {
	checkAskArr(pos);
	var asknow = repNewline(d.arrask[pos]);
	if((askcheck=confirm(asknow))==true) {top.location.replace(d.weburl+d.glourl+"?"+qry);}	
}

//
// confirm - go on link (with value)
//
function confirmActionValue(val, pos, qry) {
	checkAskArr(pos);
	asknow = repNewline(d.arrask[pos])+repNewline(val);
	if((askcheck=confirm(asknow))==true) {top.location.replace(d.weburl+"?"+qry);}	
}

//
// confirm - go on form
//
function confirmActionForm(frm, pos) {
	checkAskArr(pos);
	asknow = repNewline(d.arrask[pos]);
	askcheck = confirm(asknow);
	if(askcheck == true) {
		var sendform = eval("d."+frm);
		sendform.submit(); return false;
	} else {
		d.getbox = true;
	}
}

//
// form validate (include: fieldcolor, style)
//
function formColorStyle(obj, rgb) {
	obj.style.backgroundColor = rgb;
	return;
}
function formCheckingStyle() {
	d.errview = d.errview+1;
	//d.fld.value = d.errview;
	if (d.ftyp == 's') {
		fsi = d.fld.options[d.fld.selectedIndex].value;
		if (fsi.NaN) {
			if (fsi != "") {
				formColorStyle(d.fld, ""); clearInterval(d.errcount);	
			}
		} else if (fsi != 0) {
			formColorStyle(d.fld, ""); clearInterval(d.errcount);		
		}
	} else if (d.ftyp == 'e') {
		if (d.fld.value.match(/^[\w]{1}[漩周|\w\.\-_]*@[\w]{1}[漩周|\w\-_\.]*\.[\w]{2,6}$/i)) {
			formColorStyle(d.fld, ""); clearInterval(d.errcount);				
		}
	} else if (d.ftyp == 'n') {
		if (d.fld.value.length > 0) {
			if (!isNaN(d.fld.value)) {
				formColorStyle(d.fld, ""); clearInterval(d.errcount);	
			}				
		}
	} else if (d.ftyp == 't') {
		if (d.fld.value.length > 0) {	
			formColorStyle(d.fld, ""); clearInterval(d.errcount);
		}
	}
	if (d.errview > 40) {
		formColorStyle(d.fld, ""); clearInterval(d.errcount);		
	}
}
function formErrorStyle(fld, ftyp) {
	try {
		d.fld = fld; d.ftyp = ftyp;
		formColorStyle(d.fld, "#CCFFFF"); //CCFFCC
		d.errview = 0; 
		d.errcount = setInterval("formCheckingStyle()", 100);
	} catch (e) {}
	finally {return;}
}
function formValidate() {

	var i,j=-1,o,a=formValidate.arguments;
	var errmy=true,errbs=false,msg='',otyp='';
	
	d.otyp_bs_rem = "nein";
	var o = null;
	
	if (a.length>0) {
		for(i=0;i<a.length;i+=2) {
			j++;		
			if ((o=searchObj(a[i]))!=null) {		
				if (!o.disabled) {

					otyp=a[i+1];
					if (otyp!='ba' && otyp!='bs') {formColorStyle(o, "");}
					
					if (otyp=='e') {	
						
						if (!o.value) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else if (o.value && !o.value.match(/^[\w]{1}[漩周|\w\.\-_]*@[\w]{1}[漩周|\w\-_\.]*\.[\w]{2,6}$/i)){
							errmy = true; msg = d.valmsg[j+1]; i=a.length;
						} else if (o.value && o.value.match(/^[\w]{1}[漩周|\w\.\-_]*@[\w]{1}[漩周|\w\-_\.]*\.[\w]{2,6}$/i)){
							j++;
						} else {errmy = false;}
								
					} else if (otyp=='t') {
					
						if (!o.value) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else {errmy = false;}		
														
					} else if (otyp=='n') {
					
						if (!o.value || isNaN(o.value)) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else {errmy = false;}					
					
					} else if (otyp=='s') {
						
						var osv = o.options[o.selectedIndex].value;
						
						if (!o.options[o.selectedIndex]) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else if (osv.NaN) {
							if (osv == "") {
								errmy = true; msg = d.valmsg[j]; i=a.length;
							}			
						} else if (osv <= 0) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else {errmy = false;}	
						
					} else if (otyp=='ba') {
					
						if (o.length) {
							tmperrmy = false;
							for (p=0;p<o.length;p++) {
								if (!o[p].checked) {
									tmperrmy = true;
									break;
								}
							}
							if (tmperrmy) {
								errmy = true; msg = d.valmsg[j]; i=a.length;
							}
						} else if (!o.length && !o.checked) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else if (!o.length) {errmy = false;}	
					
					} else if (otyp=='bs') {
				
						d.otyp_bs_rem = "ja";
						
						if (o.length) {
							tmperrmy = true;
							for (p=0;p<o.length;p++) {
								if (o[p].checked) {
									o[p].checked = true;
									tmperrmy = false;
									break;
								}
							}
							if (tmperrmy) {
								errmy = true; msg = d.valmsg[j]; i=a.length;
							}
						} else if (!o.length && !o.checked) {
							errmy = true; msg = d.valmsg[j]; i=a.length;
						} else if (!o.length) {errmy = false;}						
						
						/*		
						if (!errbs && o.checked) {
							o.checked = true;					
							errmy = false; errbs=true;
						} else if (!errbs && !o.checked) {
							errmy = true; msg = d.valmsg[j]; j--;
						}
						*/
						 		
					}
					if (errmy) {break;}
				}
			}
		}		
	} else {
		errmy=false;
	}
	
	if (errmy) {			
		if ((m=searchObj(d.valinfo))!=null) {
			m.className = "error"; 
			try {m.innerHTML = unescape(decodeURI(msg));} catch(e) {m.innerHTML = unescape(msg);}			
		} else {
			try {alert(unescape(decodeURI(msg)));} catch(e) {alert(unescape(msg));}
		} 		
		if (otyp!='ba' && otyp!='bs') {
			o.focus(); formErrorStyle(o, otyp); 
		}		
		return false;		
	} else {	
		if ((m=searchObj(d.valinfo))!=null) {
			m.className = "done"; 
			try {m.innerHTML = unescape(decodeURI(d.saveinfo));} catch(e) {m.innerHTML = unescape(d.saveinfo);}			
		}		
		return true;
	}
}

//
// scroll
//
function ioPageScroll(){
	var yScroll = 0, xScroll = 0;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}	
	if (self.pageXOffset) {
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollLeft){	 // Explorer 6 Strict
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		xScroll = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

//
// newest infolayer (wem 30.11.06)
//
objHide = null;
function showAutoLayer(text, width, snickers, top, left) {	

	if (!top) top = 0;
	if (!left) left = 0;
	if (!width) width = 100;
	if (!snickers) snickers = -1;
	
	var infoID = 'gloInfoLayer';	
	if (!document.getElementById(infoID)) createInfoLayer();
	
	/*var objStyle = Element.readAttribute(infoID, 'style');	
	if (objStyle.indexOf("opacity")!=-1) { Element.hide(infoID); }*/
	
	Element.setStyle(infoID, { left: (xpos+left+10)+'px', top: (ypos+top+10)+'px', width: (width+2)+'px' } );	
	Element.update(infoID, unescape(text));		
	Element.show(infoID);
	
	if (snickers > -1) { 
		if (objHide == null) { objHide = setTimeout("hideAutoLayer();", snickers); }
	}
	
}

function hideAutoLayer() {

	var infoID = 'gloInfoLayer';
	
	if (objHide != null) { 
		clearTimeout(objHide); objHide = null; 
		//new Effect.Fade(infoID, { from: 0.9, to: 0.0, duration: 0.25, afterFinish: function() { Element.hide(infoID); } } );
	}
	
	Element.hide(infoID);
	Element.setStyle(infoID, { left: '-2000px', top: '-2000px', width: '10px' } );	
	
}


//
// any eventlistener

ioEventListener = Class.create();

ioEventListener.prototype = {

  initialize: function(list) {
    this.list = list;
    Event.observe(document, 'keypress', this.onKeyPress.bindAsEventListener(this));
    Event.observe(document, 'mousemove', this.onMouseMove.bindAsEventListener(this));
  },

  // Arbitrary functions to respond to events
  onKeyPress: function(event) {
    var code = event.keyCode;
    if(code == Event.KEY_TAB) {	/*alert('Tab key was pressed');*/ }
  },
  onMouseMove: function(event) {
	xpos = Event.pointerX(event);
	ypos = Event.pointerY(event);
  }

}

myEventListener = new ioEventListener();





//
// fsm (modal-js)
//
function getBlockDisplay() {
	var block = "block";
	try {block = d.getElementById("popTR").style.display;} catch(e){}	
	try {block = d.getElementById("MB_display").style.display;} catch(e){}
	//alert(block);
	return block;
}

function modalOnSelect(act) {
	var grids = document.getElementById("fsmModalForm").getElementsByTagName("tr");		
	for (var i=0; i<grids.length; i++){
		if (grids[i].getAttribute("row") == "fsmgrid") {	
			grids[i].style.display = (act == "hide") ? "none" : getBlockDisplay();
		}	
	}
	
}	
function modalChangeFsm(hid,arr){
	modalOnSelect("show");		
	for (i=0; i<arr["fsm_hea_id"].length; i++){
		if(arr["fsm_hea_id"][i] == hid){
			document.getElementById("fsmModalRow"+arr["fsm_hea_id"][i]).style.display = getBlockDisplay();
		} else {
			document.getElementById("fsmModalRow"+arr["fsm_hea_id"][i]).style.display = "none";
		}
	}		
}		

function modalCloseFsm(id,img,rel,cou) {
	if (rel && cou <= 0) {
		document.location.reload(true);	
	} else if (!rel) {
		try { document.getElementById("fsm_plu_"+id).src = img; } catch(e) {}
	}
	Modalbox.hide();
}

// eof