/**
 *
 * @access public
 * @return void
 **/

var Info = new function() {
	var userAgent = navigator.userAgent.toLowerCase();
	var b = {};
	b.isIE      = userAgent.indexOf("msie") != -1;
	b.isIE7     = b.isIE && (typeof window.XMLHttpRequest != "undefined");
	b.isIEpre7  = b.isIE && !b.isIE7;
	b.isSafari  = userAgent.indexOf("safari") != - 1;
	b.isMozilla = userAgent.indexOf("gecko") != -1 && b.isSafari == false;
	b.isFirefox = b.isMozilla == true && userAgent.indexOf("firefox") != -1;
	b.isOpera   = typeof window.opera != "undefined"; // || userAgent.indexOf("opera") != -1;
	this.browser = b;
	this.os = {
		isLinux: (navigator.platform.indexOf("Linux") == 0),
		isMac:   (navigator.platform.indexOf("Mac") == 0),
		isWin:   (navigator.platform.indexOf("Win") == 0)
	}
}

function checkAjaxSupport(){
	var succ = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		succ = true;
	} else if (window.ActiveXObject) { // IE
	     succ = true;
	}
	
	// IF IE 5.0
	if(isIE50()) succ = false;
	
	return succ;
}

function isIE50(){
	return navigator.appVersion.match(/MSIE 5.0/);
}
function isIE55(){
	return navigator.appVersion.match(/MSIE 5.5/);
}


function checkFooterPos(){
	if(!Info.browser.isIEpre7){
		
	
	var _head_height = $('main_head').offsetHeight;
	var _cont_height = $('container').offsetHeight
	var _content_height =$('content').offsetHeight

	var _window_height = (isIE() ? document.body.clientHeight-2 : window.innerHeight)
	var _height = _window_height
	
	//$('debug_txt').value = _height;
	$('container').style.height = (_height>document.cont_height ? _height : document.cont_height)+"px";
	
	
	// FILLER
	$('filler').style.height = _window_height-_content_height-_head_height-20+"px"
	}
}


function isIE(){
	return navigator.appVersion.match(/MSIE/);
}

function openGalleryImage(_key, _event){
	if(arguments[2]){
		loadGalleryThumbs(_event, arguments[2])
	}
	var _url = "/modules/gallery/show_detail.php";
	var _param = "key="+_key+"&event_id="+_event;
	openPopup(_url, _param, 420,367, "hideGalleryLoader()");
	
}



function hideGalleryLoader(){
	$('gallery_detail_loader').style.display = "none"; 
}
function loadGalleryThumbs(_event_id, _page){
	
	
	
	
	document._current_page = _page
	if(arguments[2]){
		document._total_pages = arguments[2]
	}
	//$('gallery_images').innerHTML = "";
	var url = "/modules/gallery/show_thumbs.php"; 
	var _param = "id="+_event_id+"&page="+_page;
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:_param,
			onComplete:function(elem){
				markGalleryPage(_page)
				$('gallery_images').innerHTML = elem.responseText;
				checkFooterPos();
			}
	});
	
	
	// NEXT 
	$('gallery_next_top').style.display = ((_page+1)<=document._total_pages) ? "block" : "none";
	$('gallery_next_bottom').style.display = ((_page+1)<=document._total_pages) ? "block" : "none";
	$('gallery_next_deact_top').style.display = ((_page+1)<=document._total_pages) ? "none" : "block";
	$('gallery_next_deact_bottom').style.display = ((_page+1)<=document._total_pages) ? "none" : "block";
	
	// PREV 
	$('gallery_prev_top').style.display = ((_page-1)>=1) ? "block" : "none";
	$('gallery_prev_bottom').style.display = ((_page-1)>=1) ? "block" : "none";
	$('gallery_prev_deact_top').style.display = ((_page-1)>=1) ? "none" : "block";
	$('gallery_prev_deact_bottom').style.display = ((_page-1)>=1) ? "none" : "block";
	var _ajax = checkAjaxSupport();	
	return !_ajax;
	
}

function markGalleryPage(_id){
	var _pages = document.getElementsByClassName("gallery_pages");
	for(var t=0; t<_pages.length; t++){
		var _cid = _pages[t].getAttribute("id");
		_pages[t].className = "gallery_pages";
		if( _cid==("page_"+_id+"_top") || _cid==("page_"+_id+"_bottom"))	{
			_pages[t].className = "gallery_pages act";
		}
		
	}
}

function loadGalleryNextPage(_event_id){
	var _next_page = document._current_page+1;
	return loadGalleryThumbs(_event_id, _next_page); 
}

function loadGalleryPrevPage(_event_id){
	var _prev_page = document._current_page-1;
	return loadGalleryThumbs(_event_id, _prev_page);
}


function showLightBox(_event_id){
	$('lightbox_js_alert').style.display = "none";
	$('lightbox').style.display = "block";
	var url = "/modules/gallery/show_lightbox.php"; 
	var _param = "event_id="+_event_id;
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:_param,
			onComplete:function(elem){
				$('lightbox').innerHTML = elem.responseText;
				new Effect.Highlight("lightbox")
			}
	});
}

function addToLightBox(_key, _event_id){
	var url = "/modules/gallery/add_to_lightbox.php"; 
	var _param = "key="+_key+"&event_id="+_event_id;
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:_param,
			onComplete:function(elem){
				showLightBox(_event_id);
				$('add_'+_key).style.display = "none";
				$('add_deact_'+_key).style.display = "block";
				
				//if($('add_lb_act')){
					$('add_lb_act').style.display = "none";
					$('add_lb_deact').style.display = "block";
				//}
				
			}
	});
}



function deleteFromLightBox(_key, _event_id){
	var url = "/modules/gallery/delete_from_lightbox.php";  
	var _param = "key="+_key+"&event_id="+_event_id;
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:_param,
			onComplete:function(elem){
				showLightBox(_event_id);
				$('add_'+_key).style.display = "block";
				$('add_deact_'+_key).style.display = "none";
			}
	});
}
function registerPromotionCode(update){
	if($('promotion_code')){
		var _param = $('promotion_code').value;
	}else{
		var _param = "";
	}
	var _url = "/modules/promotion/register_code.php";
	document.location.href = _url+"?code="+_param+"&update="+update
}

function closePopup(){
	var _prefix = "";
	if(arguments[0]==true){
		_prefix = "static_";
	}else{
		$('popup_content').innerHTML = "";
	}
	$(_prefix+'popup').style.display="none";
	$('deactivate').style.display="none";
}

function chooseVariation(_id, _v_id){

	// deact first
	var _e = document.getElementsByClassName("variation");
	for(t=0; t<_e.length; t++) _e[t].className = "variation deact";
	// activate
	$('variation_'+_v_id).className = "variation";
	//$('label_thumb').src = "/labels/"+_id+"/"+_v_id+"/thumb.png";
	$('v').value = _v_id;
	//closeChooseVariation();
	registerSession("v="+_v_id);
	generatePrev();
}

function registerSession(_param){
	var url = "/modules/ui/register_label_session.php";
	var quickEditReq = new Ajax.Request(url, {method:'get', parameters:_param,
			onComplete:function(elem){
				return true;
			}
	});
}


function openChooseVariation(){
	 Effect.BlindDown('choose_label_content', {duration:.5});
}
function closeChooseVariation(){
	 Effect.BlindUp('choose_label_content', {duration:.5});
}

function initLabelForm(){
	var _fields = document.label_input.getElementsByTagName("input");
	for(var o=0; o<_fields.length; o++){
		var _elem = _fields[o];
		_elem.onchange = generatePrev;
	}
	generatePrev()
}

function switchProductSelection(){
	var _url = "/modules/switch_product_selection.php";
	if(arguments[0]==true) _url +="?type=update";
	$('label_input').action = _url
	$('label_input').submit();
}

function generatePrev(){
	// RESET INPUT ELEMENTS
	$('label_warning').style.display = "none";
	$('submit_false').style.display = "block";
	$('submit_false_main').style.display = "block";
	$('submit_ok').style.display = "none";
	$('submit_ok_main').style.display = "none";
	$('label_indicator').className = "";
	//submit_ok_main
	_ie = document.getElementsByClassName("input_element");
	for(_e = 0; _e<_ie.length; _e++) _ie[_e].className = "input_element";
	
	
	$('label_indicator').style.display = "block";
	var param = Form.serialize("label_input");
	
	var url = "/modules/generate_preview.php";
	var _src = url+"?x="+Math.random()+"&"+(param);
	var oImage = new Image;
	//oImage.ipanel = ipanel;
	oImage.onload = function(){	
		$('label_preview').src = _src;
		$('label_indicator').style.display = "none";
		$('submit_false').style.display = "none";
		$('submit_false_main').style.display = "none";
		$('submit_ok').style.display = "block";
		$('submit_ok_main').style.display = "block";
		
	}
	oImage.onerror = function(){
		getPreviewError(param);
	}
	oImage.onabort = function(){ 
		$("label_indicator").style.display = "none"; 
	}
	//$("label_indicator").style.display = "none"; 
	oImage.src = _src;	 
	
}

function getPreviewError(param){
	$('label_indicator').style.display = "block"

	var url = "/modules/generate_preview.php";
	var quickEditReq = new Ajax.Request(url, {method:'get', parameters:param,
			onComplete:function(elem){
				//_resp = elem.responseText;
				var jsString = elem.responseText;
				var can_parse = jsString.match(/^\[.*\]$/);
				if(can_parse){
					var resp_array = eval(jsString);
					switch(resp_array[0]){
						case 'length':
							markFieldLengthError(resp_array[1]);
							break;
					}
				}else{
					//alert("========== FEHLER ========== \n"+(jsString));
				}
			}
	});
	var url = "/modules/generate_preview.php?debug=true";
	var _src = url+"&x="+Math.random()+"&"+(param);
	var oImage = new Image;
	//oImage.ipanel = ipanel;
	oImage.onload = function(){	
		$('label_preview').src = _src;
	}
	//$("label_indicator").style.display = "none"; 
	oImage.src = _src;	 
	
	
}

function markFieldLengthError(_elem){
	$('label_indicator').className = "error";
	new Effect.Appear("label_warning"); 
		for(_e = 0; _e<_elem.length; _e++){
			//alert(_elem[_e])
			$(_elem[_e]).className = "input_element error";
		}
}

function startImgUpload() {
	$('frame').innerHTML = "START";
	$('ui_image_error_content').innerHTML = "";
	$('ui_image_error').style.display ="none";

	$('static_popup_wait').style.display = "block";
	return true;
}

function completeImgUpload(response) {

	$('ui_image_wait').style.display = "none";
	$('frame').innerHTML = "START<hr />ENDE<br /><br />"+response;
	_resp = response.split("|");
		// javascript:editUIImage('3e80133d0eb7941e4baddfa9cf39ea07','1187004025')
	
	if(_resp[0]=="success"){
		closePopup(true)

		var _w = $('width_img').value;
		var _x = $('height_img').value;
		var _x = $('x_img').value;
		var _y = $('y_img').value;
		
		
		editUIImage(_resp[1], _resp[2], _w, _h,_x,_y);
		loadUIImages();
	}else{
		$('ui_image_error_content').innerHTML = _resp;
		new Effect.Appear('ui_image_error');
		$('static_popup_wait').style.display = "none";
	}

}

function registerUIImageSizes(_w, _h,_x,_y){
	document.i_w = _w;
	document.i_h = _h;
	document.i_x = _x;
	document.i_y = _y;
}
function loadUIImages(_session){
	//alert(arguments[1]);
	try{
	var _current_label = $('e').value
	// /tmp/2d156ced869472ec655c21b53722780d/images/1207576939/cropped_1207579019.jpg
	
	setUIImagesHeight(_session);
	 //$('uploaded_images').innerHTML = "Bitte installieren Sie Flash";
	var so = new SWFObject("/content/flash/ui_images_v1.swf", "ui_images_v1", "100%", "100%", "7");
	so.addParam("wmode","transparent");
	so.addVariable("session_id", _session);
	so.addVariable("current_label",_current_label);
	so.write("uploaded_images_flash");
	}catch(e){
		
	}
  
	
	
	
	/*
	_w = document.i_w;
	_h = document.i_h;
	_x = document.i_x;
	_y = document.i_y;
	
	var url = "/modules/ui/uploaded_images_list.php?t="+Math.random();
	var _param = "w="+_w+"&h="+_h+"&x="+_x+"&y="+_y;
	//alert(_param);
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:_param,
			onComplete:function(elem){
				_resp = elem.responseText;
				if(_resp){
					new Effect.Appear("uploaded_images");
					$('uploaded_images').innerHTML = _resp;
					new Effect.Highlight('uploaded_images');
				}
			}
	});

*/
	
	
	//$('uploaded_images').style.height=150+"px";

}

function setUIImagesHeight(_session){

	var url = "/modules/ui/get_uploaded_images_num.php?t="+Math.random();
	var _param = "session="+_session
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:_param,
			onComplete:function(elem){
				_resp = elem.responseText;
				_h = _resp*80+120
			
				$('uploaded_images_flash').style.height=_h+"px";
			}
	});
}

function deleteUIImage(sid, id){
	var _confirm = true;//confirm("Wollen Sie das Bild wirklich löschen?");
	if(_confirm){
		var param = "sid="+sid+"&id="+id;
		var url = "/modules/ui/delete_uploaded_image.php";
		var quickEditReq = new Ajax.Request(url, {method:'post', parameters:param,
				onComplete:function(elem){
					_resp = elem.responseText;
					new Effect.Fade("ui_elem_"+id, {duration:.5})
					$('image_1').value = "";
					generatePrev();
				}
		});
	}
}

function editUIImage(sid, id, _ts, _flashzoom){
	//alert("TS:"+_ts);
	
	var _debug = "SID: "+sid+"\n";
	_debug += "Id: "+id+"\n";
	_debug += "TS: "+_ts+"\n";

	
	var _e = $('e').value;
	var _v = $('v').value;
	var param = "_sid="+sid+"&id="+id+"&_ts="+_ts+"&_flashzoom="+_flashzoom; //+"&h="+_h+"&e="+_e+"&v="+_v;

	/*
	var url = "/modules/ui/build_cropper.php";
	openPopup(url, param, 910, 500, "initCropper("+_w+", "+_h+","+_x+", "+_y+")");
*/
	
	var url = "/content/flash/cropper_v2.html"
	openPopup(url, param, 600, 375, "initFlashCropper('"+sid+"','"+id+"','"+_ts+"','"+_flashzoom+"')")

}



function openUIUpload(){
	//$('ui_image_error').style.display = "none";
	//$('ui_image_error_content').innerHTML = "";
	openPopup(false, "", 300, 80, false, true);
	/*var so = new SWFObject("/content/flash/uploader_v2.swf", "uploader_v2", "300", "100", "9", "#ffffff");
			
			so.addParam("scale", "noscale");
			so.addParam("scale", "noscale");
			so.addVariable("session_id", "1f691d37a91815b23a7f4d85e37814ec");
			so.addParam("menu","false");
			/*so.addParam("wmode","transparent");
			so.addParam("scale","exactfit");
			so.write("flashcontent");*/
}

function chooseUIImage(_url){
	$('image_1').value = _url
	generatePrev()
	$('_copyright').style.display = "none";
	$('_copyright').innerHTML = "";
	// SET COPYRIGHT
	if(arguments[1]){
		var _copy = arguments[1];
		if(arguments[2]){
			_copy = '<a href="'+arguments[2]+'" target="_blank">'+_copy+'</a>';
		}
		$('_copyright').style.display = "block";
		$('_copyright').innerHTML = "Foto: &copy; "+_copy;
	}
	
	
	
	
	
}

function appearFade(_appear, _fade){
	// APPEAR
	for(a=0; a<_appear.length; a++){
		new Effect.BlindDown(_appear[a], { afterFinish:checkFooterPos});
	}
	// APPEAR
	for(f=0; f<_fade.length; f++){
		new Effect.BlindUp(_fade[f], { afterFinish:checkFooterPos});
	}
	
	$(_appear+"_btn").className = "act";
	$(_fade+"_btn").className = "";
	
}


/******** CROPPER *******/

function initFlashCropper(_session_id, _id, _img_ts, _flashzoom){

			$('flash_cropper').innerHTML = "";
	
	
			var so_cropper = new SWFObject("/content/flash/cropper_v2.swf", "_cropper", "600", "375", "8", "#ffffff");
		
			so_cropper.addVariable("_current_image", "/tmp/"+_session_id+"/images/"+_id+"/detail.jpg?t=");
			
			so_cropper.addVariable("_flashzoom",_flashzoom);
			if(_img_ts!=0){
				so_cropper.addVariable("_current_definition", "/tmp/"+_session_id+"/images/"+_id+"/def_"+_img_ts+".xml");
				//alert("LOAD:"+"/tmp/"+_session_id+"/images/"+_id+"/def_"+_img_ts+".xml");
				
			}else{
				so_cropper.addVariable("_current_definition", "/tmp/"+_session_id+"/images/"+_id+"/def.xml");
				//alert("LOAD:"+"/tmp/"+_session_id+"/images/"+_id+"/def.xml");
			}
			
			_scr = Url.encode(strReplace($('label_preview').src+"&hide_image=true", "&", "_AMP_"));
			_scr += "_AMP_time="+Math.random()*11;
			
			so_cropper.addVariable("_current_label",_scr)
		
			so_cropper.addVariable("_label_id", $('e').value)
			so_cropper.addVariable("_label_value", $('v').value)
			so_cropper.addVariable("_image_session", _session_id)
			so_cropper.addVariable("_image_id", _id)
			so_cropper.addParam("menu","false");
			so_cropper.addParam("wmode","window");
			so_cropper.addParam("scale","exactfit");
			
			so_cropper.write("flash_cropper");
			$('flash_cropper').style.zIndex = 9999;
}

function strReplace(s, r, w){
     return s.split(r).join(w);
}



function initCropper(_w,_h, _x, _y){
	
		$('prev_img').src = $('label_preview').src;
		// SET PREVIEW
		$('crop_preview').style.left = _x+"px";
		$('crop_preview').style.top = _y+"px";
	
	
	
	
		$('cropper').style.width = $('crop_image').width+"px";

		curCrop = new Cropper.ImgWithPreview(
					'crop_image',
					{
						minWidth: _w/5,
						minHeight: _h/5,
						ratioDim: { x: _w*5, y: _h*5 },
						displayOnInit: true,
						onEndCrop: onEndCrop,
						previewWrap: 'crop_preview',
						onloadCoords: document.coords
					}
			)
			$('imgCrop_crop_image').style.display = "block";

}
function onEndCrop( coords, dimensions ) {
	document.coords = coords;
	var _x1 = coords.x1;
	var _y1 = coords.y1;
	var _x2 = coords.x2;
	var _y2 = coords.y2;
	var _width = dimensions.width;
	var _height = dimensions.height;

	var _q = "_x1="+_x1+"&_y1="+_y1+"&_x2="+_x2+"&_y2="+_y2+"&_width="+_width+"&_height="+_height;
	if($('q')) $('q').value= _q;
}


function manipulateCropperImage(_id, _sid, _method, _val){
	var _src = $('prev_img').src;
	curCrop.remove(_id, _sid, _src);
	$('popup_wait').style.display = "block";
	var url = "/modules/ui/manipulate_image.php";
	//$('crop_image').style.display="hidden";
	_param = "id="+_id+"&sid="+_sid+"&method="+_method+"&value="+_val
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:_param,
			onComplete:function(elem){
				_resp = elem.responseText;
				_arr = _resp.split("|");
				
				changeCropperImage(_arr);

			}
	});

}




function changeCropperImage(_arr){
	_src = _arr[0];
	var oImage = new Image;
	oImage.src = _src;
	oImage.onload = function(){
		$('crop_image').src = _src;
		$('crop_image' ).width = _arr[1];
		$('crop_image' ).height = _arr[2];
		$('crop_image').style.visibility="visible";
		//new Effect.Appear("crop_image", {duration:.5});
		$('popup_wait').style.display = "none";
		initCropper(document.i_w,document.i_h, document.i_x, document.i_y);
	}
	oImage.onerror = function(){ $("popup_wait").style.display = "none"; }
	oImage.onabort = function(){ $("popup_wait").style.display = "none"; }


}

function updateCroppedImage(_sid, _id, _ts){
	var _iurl = "/tmp/"+_sid+"/images/"+_id+"/cropped_"+_ts+".jpg";
	$('image_1').value = _iurl;
	loadUIImages(_sid);
	closePopup();
	generatePrev()
	$('_copyright').innerHTML = "";
}

function cropImage(_id, _sid){
	var _param = "id="+_id+"&_sid="+_sid+"&"+$('q').value;
	var _url ="/modules/ui/crop_image.php";
	$('popup_wait').style.display = "block";
	var quickEditReq = new Ajax.Request(_url, {method:'post', parameters:_param,
			onComplete:function(elem){
				_resp = elem.responseText;
				//
				var _iurl = "/tmp/"+_sid+"/images/"+_id+"/cropped.jpg";
				$('image_1').value = _iurl;
				loadUIImages();
				closePopup();
				generatePrev()
				
			}
	});
}
/******** POPUP **************/


function openPopup(_url, _param, _w, _h){
	 var _pre = "";
	 if(arguments[5] == true) _pre = "static_";
	deactivateAll();
	// SHOW
	showPopup(_w, _h, _pre);
	// LOAD
	var _fnc = arguments[4];
	if(_url){
		var quickEditReq = new Ajax.Request(_url, {method:'post', parameters:_param,
				onComplete:function(elem){
					_resp = elem.responseText;
					$(_pre+'popup_content').innerHTML = _resp;	
					$(_pre+'popup_wait').style.display ="none";			
					if(_fnc) eval(_fnc);
					
				}
		});
	}else{
		$(_pre+'popup_wait').style.display ="none";
	}
}

function innerEdit(_url, _options){
	$(_options.wait_element).style.display = "block";
	var quickEditReq = new Ajax.Request(_url, {method:'post', parameters:'',
				onComplete:function(elem){
					_resp = elem.responseText;
					$(_options.element).innerHTML = _resp;	
					$(_options.wait_element).style.display = "none";
				}
		});
}
function innerSave(_url, _options){
	$(_options.wait_element).style.display = "block";
	var _form_values = Form.serialize(_options.form);
	var quickEditReq = new Ajax.Request(_url, {method:'post', parameters:_form_values,
				onComplete:function(elem){
					_resp = elem.responseText;
		
					$(_options.element).innerHTML = _resp;	
					$(_options.wait_element).style.display = "none";					
				}
		});
}
function deactivateAll(){

	var deact_all = $("deactivate");

	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
  	}
  
	deact_all.style.height = yScroll +"px";
	deact_all.style.display = "block";
	
}

function getPageScrollTop(){
	var yScrolltop;
	if (self.pageYOffset) {
		yScrolltop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScrolltop) 
	return yScrolltop;
}

function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}


function showPopup(_w, _h,  _pre){
	var _p = $(_pre+'popup');
	var _pc = $(_pre+'popup_content');
	
	
	_p.style.height = _h+"px"
	_p.style.width = _pc.style.width = _w+"px";

	if(_p.style.display != "block"){
	_p.style.marginLeft = -(_w/2)+"px";
	_p.style.marginTop = -(_h/2)+"px";
	
	_p.style.marginLeft="0px"; 
	_p.style.marginTop="0px";	
	var pagesize = getPageSize();
	var arrayPageScroll = getPageScrollTop();
	_p.style.marginLeft = -(_w/2)+"px";//((pagesize[0] )/2)-(_w/2)+"px";
	_p.style.marginTop = -(_h/2)+"px";//(arrayPageScroll[1] - ((pagesize[1])/2))-(_h/2)+"px";
	}
	_p.style.display = "block";
	
	/*
	/*$("big_image").style.width=w+"px";
	$("big_image").style.height=h+"px";
	// CENTER POS
	var add = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		add = window.pageYOffset; //document.body.scrollTop
	}
	$("big_image").style.marginLeft=-(w/2)+"px"; 
	$("big_image").style.marginTop=-((h/2)-add)+"px";	

	$("big_image").style.marginLeft="0px"; 
	$("big_image").style.marginTop="0px";	
	var pagesize = getPageSize();
	var arrayPageScroll = getPageScrollTop();
	$("big_image").style.width=w+"px";
	$("big_image").style.height=h+"px";
	$("big_image").style.left = ((pagesize[0] - 100)/2)-(w/2)+"px";
	$("big_image").style.top = (arrayPageScroll[1] + ((pagesize[1]-100)/2))-(h/2)+"px";
	$("deactivate").onclick = function(){ closePopup(); }
	*/
}


/******** CART **************/

function addToCart(_id){
	var _val = $('price_'+_id).value;
	var _param = "q="+_id+"&c="+_val;
	if(arguments[1]==true){
		var url = "/modules/ui/select_label.php";
		
		openPopup(url, _param, 500, 200);
	}else{
		
		var _url = "/modules/ui/add_to_cart.php?"+_param;
		document.location.href = _url;
	}
}
/*
function deleteCartItem(_item){
	new Effect.Fade('item_'+_item);
}*/
function deleteCartItem(_id){
	var _elem = $('price_'+_id);
	_elem.value = 0;
	var _c = _elem.value;
	var _url = "/modules/ui/delete_cart_item.php";
	var _param = "id="+_id;

	var quickEditReq = new Ajax.Request(_url, {method:'post', parameters:_param,
				onComplete:function(elem){
					
					_resp = elem.responseText;
					if(_resp){				
						_e = _resp.split("#");
						$('_p_price').innerHTML = _e[0];
						$('_p_shipping').innerHTML = _e[1];
						$('_p_total').innerHTML = _e[2];
						$('_p_vat').innerHTML = _e[3];
						if(_e[5] && $('_p_discount') ){
							$('_p_discount').innerHTML = _e[5];
							new Effect.Highlight('_p_discount');
						}
						new Effect.Highlight('_p_price');
						new Effect.Highlight('_p_shipping');
						new Effect.Highlight('_p_total');
						new Effect.Highlight('_p_vat');	
						new Effect.Shrink('item_'+_id, {afterUpdate:checkFooterPos, afterFinish:checkFooterPos});		
						if(_e[4]=="0") setCartToEmpty()
					}else{
						alert("Bitte geben Sie einen korrekten Wert ein");
					}
					
				}
		});
}

function setCartToEmpty(){
	$('cart_items').style.display = "none";
	$('no_items').style.display = "block";
}


function addToCartLabel(_param, _e){
	var _url = "/modules/ui/add_to_cart.php?"+_param;
	closePopup()
	document.location.href = _url;
}

function addToCartNewLabel(_p, _c){
	//Etiketten_Editor=Etikett_Gestalten:Produkt=4|14
	var _url = "/Etiketten_Editor=Produkt:"+_p+":"+_c
	document.location.href = _url;
//	alert("MUSS NOCH PROGRAMMIERT WERDEN");
}

function switchCartLabel(_id, _elem){
	var _val = _elem.value;
	if(_val){
		var _img = $('label_'+_id);
		var _param = "id="+_id+"&l="+_val;
		$('label_wait_'+_id).style.visibility = "visible";
		var _url = "/modules/ui/change_cart_label.php";
		var quickEditReq = new Ajax.Request(_url, {method:'post', parameters:_param,
				onComplete:function(elem){
					_resp = elem.responseText;
					/*oImage = new Image;
					oImage.src = _resp;
					oImage.onload = function(){
						alert('label_'+_id);
						$('label_'+_id).src = _resp;
						$('label_wait_'+_id).style.visibility = "hidden";
					}*/
					$('label_'+_id).src = _resp;
						$('label_wait_'+_id).style.visibility = "hidden";
					//oImage.onerror = function(){ alert("ERROR"); $('label_wait_'+_id).style.visibility = "hidden"; }
					//oImage.onabort = function(){ alert("ABORT"); $('label_wait_'+_id).style.visibility = "hidden"; }
				}
		});
	}else{
		alert("FEHLER");
	}
}
function updateCart(){
	
						new Effect.Highlight('_p_price');
						new Effect.Highlight('_p_shipping');
						new Effect.Highlight('_p_total');
						new Effect.Highlight('_p_vat');	
}

function updateCartItemCount(_id,_shipping,_vat){
	var _elem = $('price_'+_id);
	var _c = _elem.value;
	var _url = "/modules/ui/change_cart_item_count.php";
	var _param = "id="+_id+"&c="+_c;
	var quickEditReq = new Ajax.Request(_url, {method:'post', parameters:_param,
				onComplete:function(elem){
					_resp = elem.responseText;
					if(_resp){
							document.location.reload()
						_e = _resp.split("#");
						$('_p_price').innerHTML = _e[0];
						$('_p_shipping').innerHTML = _e[1];
						$('_p_total').innerHTML = _e[2];
						$('_p_vat').innerHTML = _e[3];
						if(_e[5] && $('_p_discount') ){
							$('_p_discount').innerHTML = _e[5];
							new Effect.Highlight('_p_discount');
						}
						new Effect.Highlight('_p_price');
						new Effect.Highlight('_p_shipping');
						new Effect.Highlight('_p_total');
						new Effect.Highlight('_p_vat');	
						$('can_order').style.display = _e[6] && _e[7] ? "block" : "none";
						$('can_not_order').style.display = _e[6] && _e[7] ? "none" : "block";
						//$('can_order_gvp').style.display = _e[7] ? "block" : "none";
						//$('can_order_gvp').style.display = _e[7] ? "none" : "block";
						if(!_e[4]) setCartToEmpty()
					}else{
						alert("Bitte geben Sie einen korrekten Wert ein");
					}
					
				}
				
				
		});
}
function updateCartGP(_id, _pack){
	var _url = "/modules/ui/change_cart_gvp.php";
	var _param = "id="+_id+"&pack="+_pack;

	var quickEditReq = new Ajax.Request(_url, {method:'post', parameters:_param,
				onComplete:function(elem){
					_resp = elem.responseText;
					if(_resp){
					
					document.location.reload()
						
					}else{
						alert("Bitte geben Sie einen korrekten Wert ein");
					}
					
				}
				
				
		});
}




/*
function addShippingAddress(){
	$('shipping_address_form').style.display = "none";
	new Effect.SlideDown('shipping_address_form',{duration:.5});
	$('add_sa_btn').style.display = "none";
	$('remove_sa_btn').style.display = "block";	
	$('has_shipping_address').value = 1;
}

function removeShippingAddress(){
	$('shipping_address_form').style.display = "none";
	//new Effect.SlideUp('shipping_address_form',{duration:.5});
	$('add_sa_btn').style.display = "block";
	$('remove_sa_btn').style.display = "none";	
	$('has_shipping_address').value = 0;
}
*/
function addShippingAddress(){
	$('form_shipping_address').style.display = "none";
	new Effect.SlideDown('form_shipping_address',{duration:.5}); 
	$('add_shipping').style.display = "none";
	$('remove_shipping').style.display = "block";	
	$('has_shipping_address').value = 1;
	//if($('shipping_id')) $('shipping_id').style.display = "none";
	
}

function addSavedShippingAddress(){
	var succ = false;
	if($('has_shipping_address').value == 0){
		addShippingAddress()
		succ = true;
	}else{
		succ = confirm("Wollen Sie Ihre vorhandene Lieferadresse überrschreiben?");	
	}	
	if(succ){	
	var val = $('shipping_id').value.split("|")
	$('s_ad_company').value 	= 	val[0]
	$('s_adg_id').selectedIndex 	= 	val[1]
	
	$('s_ad_title').value 		= 	val[2]
	$('s_ad_name').value 		= 	val[3]
	$('s_ad_firstname').value 	= 	val[4]
	$('s_ad_street').value 		= 	val[5]
	$('s_ad_zip').value 		= 	val[6]
	$('s_ad_city').value 		= 	val[7]
	//$('shipping_id').style.display = "none";
	}
	/*$('form_shipping_address').style.display = "none";
	new Effect.SlideDown('form_shipping_address',{duration:.5}); 
	$('add_shipping').style.display = "none";
	$('remove_shipping').style.display = "block";	
	$('has_shipping_address').value = 1;*/
	
}



function removeShippingAddress(){
	$('form_shipping_address').style.display = "block";
	new Effect.SlideUp('form_shipping_address',{duration:.5});
	$('add_shipping').style.display = "block";
	$('remove_shipping').style.display = "none";	
	$('has_shipping_address').value = 0;
	if($('shipping_id')){
		$('shipping_id').selectedIndex = 0
		$('shipping_id').style.display = "block";
	}
}



function initLabelAccordion(){
	
	var accordion;
	var accordionClicks;
	var accordionContents;
	
	
	accordionClicks = document.getElementsByClassName('accordion-click');
	accordionContents = document.getElementsByClassName('accordion-content');
	accordion = new fx.Accordion(accordionClicks, accordionContents);
	_elem = document.getElementsByClassName("accordion-content");
	for(var t=0; t<_elem.length; t++){
		_cn = _elem[t].className;
		if(_cn=="accordion-content act"){
			accordion.showThisHideOpen(accordionContents[t]);
			break;
		}
	}
	
	
	
}
/**
oImage.src = _src;
	oImage.onload = function(){
		$('crop_image').src = _src;
		$('crop_image' ).width = _arr[1];
		$('crop_image' ).height = _arr[2];
		$('crop_image').style.visibility="visible";
		//new Effect.Appear("crop_image", {duration:.5});
		$('popup_wait').style.display = "none";
		initCropper(document.i_w,document.i_h, document.i_x, document.i_y);
	}
	oImage.onerror = function(){ $("popup_wait").style.display = "none"; }
	oImage.onabort = function(){ $("popup_wait").style.display = "none"; }
**/

/**function selectLabel(_id){
	var _radio = document.label_form.e;
	var _c = 1;
	for(var _t=0; _t<_radio.length; _t++){
		_eid = _radio[_t].value;
		$("thumb_"+_eid).className = "thumbs";
		_radio[_t].checked = _radio[_t].value==_id
	}
	$("thumb_"+_id).className = "thumbs act";
	generatePrev();
}

function generatePrev(){
	$('img_wait').style.display = "block";
	var param = Form.serialize("label_form");
	var url = "/modules/generate_image.php";
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:param,
			onComplete:function(elem){
				_resp = elem.responseText;

				var oImage = new Image;
				oImage.onload = function(){
					$('b_img').src = _resp;
					$('img_wait').style.display = "none";
				}
				oImage.onerror = function(){ $("img_wait").style.display = "none"; }
				oImage.onabort = function(){ $("img_wait").style.display = "none"; }
				oImage.src = _resp;
			}
	});
}

function openPopupWindow(url){
	$('deactivate').style.display = "block";
	var _param = arguments[1] ? arguments[1] : "";
	var _runonload = arguments[2] ? arguments[2] : false;
	new Effect.Appear("popup", {duration:.5});
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:_param,
			onComplete:function(elem){
				_resp = elem.responseText;
				$('popup_content').innerHTML = _resp;
				if(_runonload){
					eval(_runonload+"()");
				}
			}
	});
}

function cosePopupWindow(){
	$('deactivate').style.display = "none";
	$('popup').style.display = "none";
	$('popup_content').innerHTML = "";
}

function startImgUpload() {
	return true;
}

function completeImgUpload(response) {
	if(response.match(/([0-9]{10}).jpg/)){
		loadUIList();
		cosePopupWindow();
	}else{
		alert("FEHLER");
	}
}


function loadUIList(){
	var url = "/modules/load_user_images.php";
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:"",
			onComplete:function(elem){
				_resp = elem.responseText;
				$('image_box').innerHTML = _resp;
				new Effect.Highlight('image_box');
			}
	});

}

function onEndCrop( coords, dimensions ) {
		$( 'crop_params' ).value = "id="+$( 'crop_id' ).value+"&x1="+coords.x1+"&y1="+coords.y1+"&x2="+coords.x2+"&y2="+coords.y2+"&width="+dimensions.width+"&height="+dimensions.height;
}

function initCropper(){
				new Cropper.ImgWithPreview(
					'testImage',
					{
						minWidth: 105,
						minHeight: 150,
						ratioDim: { x: 105, y: 150 },
						displayOnInit: true,
						onEndCrop: onEndCrop,
						previewWrap: 'previewArea'
					}
				) ;
}

function saveImageCrop(){
	var url = "/modules/crop_image.php";
	var _params = $( 'crop_params' ).value;
	var quickEditReq = new Ajax.Request(url, {method:'post', parameters:_params,
			onComplete:function(elem){
				_resp = elem.responseText;
				$('image_1').value = _resp;
				cosePopupWindow();
				loadUIList();
				selectLabel("e_2");

			}
	});
}

function setCroppedImage(id){
	$('image_1').value = id;
	selectLabel("e_2");
}*/