/* Scope definieren
 *
 */
	ip = {};

/* Helper Funktionen
 *
 */
	ip.pageLoaded = false;
	
	ip.get = function(id) {
		return document.getElementById(id);
	}
	
	ip.helper = {
		loadUrl : function(url) {
			document.location.href = url;
		},
		
		getLeft : function(l) {
			if (l.offsetParent) return (l.offsetLeft + this.getLeft(l.offsetParent));
			else return (l.offsetLeft);
		},
			
		getTop : function(l) {
			if (l.offsetParent) return (l.offsetTop + this.getTop(l.offsetParent));
			else return (l.offsetTop);
		},
		
		scrollbarVisible : function() {
			var bodyEl = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ? window.document.documentElement : window.document.body || null;
			if(window.innerWidth) {
				if (window.opera)
					return (window.outerWidth - bodyEl.scrollWidth)>10;
				else
					return window.scrollbars.visible;
			} else {
				return (bodyEl.clientWidth < bodyEl.offsetWidth);
			}
		},
		
		stopEvent : function(e) {
			if(!e) e = window.event;
			if(typeof e != 'undefined' && e != null) {
				if(typeof e.stopPropagation == 'function') e.stopPropagation();
				else e.cancelBubble = true;
			}
		},
		
		inArray : function(v,a) {
			for(var i=0;i<a.length;i++) {
				if(a[i] == v) return true;
			}
			return false;
		}
	}
	
/* Service-Navigation
 *
 */
	ip.serviceNavigation = {
		showMore : function(obj,e) {
			if(!e) e = window.event;
			if(typeof e.stopPropagation == 'function') e.stopPropagation();
			else e.cancelBubble = true;
			
			var popup = ip.get('divServiceNavigationPopupMoreContainer');
			var l = ip.helper.getLeft(obj);
			var w = obj.offsetWidth;
			var pw = popup.getElementsByTagName('div')[0].offsetWidth;
			var bodyEl = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ? window.document.documentElement : window.document.body || null;
			
			bodyEl.onmouseover = function() {
				ip.get('divServiceNavigationPopupMoreContainer').style.visibility = 'hidden';
				this.onmouseover = null;
			}
			popup.onmouseover = function(e) {
				if(!e) e = window.event;
				if(typeof e.stopPropagation == 'function') e.stopPropagation();
				else e.cancelBubble = true;
			}
			popup.style.top = '25px';
			popup.style.left = ((l+w)-pw)+'px';
			popup.style.visibility = 'visible';
		}
	}

/* Tab-Funktionen
 *
 */
	ip.tab = {
		highlight : function(obj) {
			if(obj.className.indexOf('Active') < 0) {
				obj.className = 'headerTabContainerHover';
			}
		},
	
		unhighlight : function(obj) {
			if(obj.className.indexOf('Active') < 0) {
				obj.className = 'headerTabContainer';
			}
		}
	}

/* Basic-Search-Form
 *
 */
	ip.basicSearch = {
		onFocusInput : function(obj) {
			if(obj.value == obj.defaultValue) obj.value = '';
		},
	
		onBlurInput : function(obj) {
			if(obj.value == '') obj.value = obj.defaultValue;
		},
	
		onSubmitForm : function(obj) {
			return (obj.search.value != '' && obj.search.value != 'Bilder-Suche');
		},
		
		doSubmit : function(f) {
			if(typeof f == 'undefined') f = document.forms.frmBasicSearch;
			if(this.onSubmitForm(f)) {
				f.submit();
			}
		},
		
		toggleKeyword : function(obj) {
			var v = document.forms.frmBasicSearch.search;
			v.value = v.value.replace('Bilder-Suche','');
			
			if(obj.checked) {
				v.value += (v.value == '' ? '' : ' ') + obj.value;
			} else {
				var re1 = new RegExp('[ ]?'+obj.value);
				v.value=v.value.replace(re1,'');
				
				// Wenn jetzt an erster Stelle ein Space ist, entfernen
				var re2 = new RegExp('^ ');
				v.value=v.value.replace(re2,'');
			}
		}
	}
	
/* Extended-Search-Form
 *
 */
	ip.extendedSearch = {
		interval : null,
		
		show : function() {
			var obj = ip.get('divExtendedSearchContainer');
			var ow = obj.offsetWidth;
			obj.style.marginLeft = (-1*ow)+'px';
			obj.style.visibility = 'visible';
			clearInterval(this.interval);
			this.interval = setInterval(this.slideIn,5);
		},
		
		slideIn : function(obj) {
			var obj = ip.get('divExtendedSearchContainer');
			var ml = parseInt(obj.style.marginLeft);
			if(ml < -1) {
				obj.style.marginLeft = Math.round((ml/2))+'px';
			} else {
				clearInterval(ip.extendedSearch.interval);
				obj.style.marginLeft = '0px';
			}
		},
		
		hide : function() {
			var obj = ip.get('divExtendedSearchContainer');
			var ow = obj.offsetWidth;
			obj.style.marginLeft = '0px';
			clearInterval(this.interval);
			this.interval = setInterval(this.slideOut,5);
		},
		
		slideOut : function() {
			var obj = ip.get('divExtendedSearchContainer');
			var ow = parseInt(obj.offsetWidth);
			var ml = parseInt(obj.style.marginLeft);
			if(Math.abs(ml) < ow) {
				obj.style.marginLeft = Math.round(ml-((ow-Math.abs(ml))/2))+'px';
			} else {
				clearInterval(ip.extendedSearch.interval);
				obj.style.marginLeft = (-1*ow)+'px';
			}
		},
		
		setFormat : function(field,obj) {
			var f = document.forms.frmExtendedSearch;
			
			// Toggle Format
			if(f[field].value == 1) {
				f[field].value = 0;
				obj.parentNode.style.backgroundColor = 'transparent';
				obj.parentNode.style.border = '1px solid transparent';
			} else {
				f[field].value = 1;
				obj.parentNode.style.backgroundColor = '#FFFFFF';
				obj.parentNode.style.border = '1px solid orange';
			}
		},
		
		onSubmitForm : function(obj) {
			return true;
			//return (obj.search.value != '' && obj.search.value != obj.search.defaultValue);
		},
		
		doSubmit : function() {
			if(this.onSubmitForm(document.forms.frmExtendedSearch)) {
				document.forms.frmExtendedSearch.submit();
			}
		},
		
		reset : function() {
			var f = document.forms.frmExtendedSearch;
			f.search.value = '';
			f.size.selectedIndex = 0;
			f.pgname.value = '';
			f.s_ck.checked = false;
			f.s_cg.checked = false;
			f.s_cw.checked = false;
			f.s_cy.checked = false;
			f.s_co.checked = false;
			f.s_cr.checked = false;
			f.s_cm.checked = false;
			f.s_cb.checked = false;
			f.s_cc.checked = false;
			f.s_ce.checked = false;
			
			f.s_fp.value = 0;
			f.s_fl.value = 0;
			f.s_fs.value = 0;
			
			ip.get('td_s_fp').style.backgroundColor = 'transparent';
			ip.get('td_s_fp').style.border = '1px solid transparent';
			ip.get('td_s_fl').style.backgroundColor = 'transparent';
			ip.get('td_s_fl').style.border = '1px solid transparent';
			ip.get('td_s_fs').style.backgroundColor = 'transparent';
			ip.get('td_s_fs').style.border = '1px solid transparent';
			
			f.s_mr.checked = false;
			f.s_pr.checked = false;
			f.s_edt.checked = false;
			f.s_baw.checked = false;
			f.s_hr.checked = false;
			f.s_new.checked = false;
			f.s_serie.checked = false;
		},
		
		toggleActiveStatus : function(obj) {
			var v = (obj.checked) ? 1 : 0;
			document.location.href = document.location.href.replace(/s_active=[0,1]/,'s_active='+v);
		}
	}

/* Cookie-Funktionen
 *
 */
	ip.cookie = {
		read : function(n,standard) {
			a = document.cookie;
			res = (typeof standard != 'undefined') ? standard : '';
			while(a != '') {
				while(a.substr(0,1) == ' ') {a = a.substr(1,a.length);}
				cookiename = a.substring(0,a.indexOf('='));
				if(a.indexOf(';') != -1) {
					cookiewert = a.substring(a.indexOf('=')+1,a.indexOf(';'));
				} else {
					cookiewert = a.substr(a.indexOf('=')+1,a.length);
				}
				if(n == cookiename) {
					res = cookiewert;
				}
				i = a.indexOf(';')+1;
				if(i == 0) {
					i = a.length;
				}
				a = a.substring(i,a.length);
			}
			return(res)
		},
		
		write : function(n,w) {
			var a = new Date();
			a = new Date(a.getTime() +1000*60*60*24*365);
			document.cookie = n+'='+w+'; domain='+window.location.host+'; expires='+a.toGMTString()+';';
		}
	}
	
/* Register
 *
 */
	ip.register = {
		checkVAT : function(obj) {
			var v = obj.value;
			var tr = ip.get('trVAT');
			if(ip.helper.inArray(v,arrVATCountries)) {
				tr.style.display = '';
			} else {
				tr.style.display = 'none';
			}
		}
	}
	
/* Confirm-Box
 *
 */
	ip.confirmYes = function() {
		ip.confirmHide();
	}
	
	ip.confirmNo = function() {
		ip.confirmHide();
	}
	
	ip.confirmHide = function() {
		ip.get('divConfirm').style.display = 'none';
	}
	
	ip.confirmShow = function() {
		ip.get('divConfirm').style.display = '';
	}
	
/*
 *
 */
	ip.account = {
		delCC : function(id) {
			ip.get('divConfirmText').innerHTML = 'Wollen Sie diese gespeicherte Kreditkarte wirklich l&ouml;schen?';
			ip.confirmCCDelId = id;
			ip.confirmYes = function() {
				document.location.href = '/account.php?action=changepayment&delCC='+ip.confirmCCDelId;
			}
			ip.confirmShow();
		}
	}
	
/* ImageList-Funktionen
 * ist in File imageList.js ausgelagert
 */
	
/* Projectbox-Funktionen
 * ist in File projectbox.js ausgelagert
 */

/* Navigation
 * ist in File navigation.js ausgelagert
 */
 
  	ip.popup = function(URL) {
		day = new Date();
		id = day.getTime();
		window.open(URL,'win'+id, 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=660,height=700,left=50,top=10');
	}
	
	