/*由于大图绑定在href属性中，故一般而言，需使用a标签的href指向大图。仅支持png,gif,jpg,bmp四种格式的图片。用法是：目标.preview();
例如：<a href="xx.jpg">图片</a>
$("a").preview();就可以了
*/

function getScrollTop()
{
    var scrollTop=0;
    if(document.documentElement&&document.documentElement.scrollTop)
    {
        scrollTop=document.documentElement.scrollTop;
    }
    else if(document.body)
    {
        scrollTop=document.body.scrollTop;
    }
    return scrollTop;
}

(function($){
	$.fn.preview = function(){
		var xOffset = 10;
		var yOffset = 20;
		var w = function(){
			if($.browser.msie){
				return document.compatMode == "CSS1Compat"? document.documentElement.clientWidth :
						 document.body.clientWidth;
			}else{
				return self.innerWidth;
			}
		}
		
		var h = function(){
			if($.browser.msie){
				return document.compatMode == "CSS1Compat"? document.documentElement.clientHeight :
						 document.body.clientHeight;
			}else{
				return self.innerHeight;
			}
		}
		
		$(this).each(function(){
			$(this).hover(function(e){
				if(/.png$|.gif$|.jpg$|.bmp$/.test($(this).attr("src"))){
					$("body").append("<div id='preview'><div><img src='"+$(this).attr('src')+"' /><p>"+$(this).attr('title1')+"</p></div></div>");
				}else{
					$("body").append("<div id='preview'><div><p>"+$(this).attr('title1')+"</p></div></div>");
				}
				$("#preview").css({
					position:"absolute",
					padding:"4px",
					border:"1px solid #f3f3f3",
					backgroundColor:"#eeeeee",
					top:(e.pageY - yOffset) + "px",
					zIndex:10
				});
				$("#preview > div").css({
					padding:"5px",
					backgroundColor:"white",
					border:"1px solid #cccccc"
				});
				$("#preview > div > p").css({
					textAlign:"center",
					fontSize:"14px",
					padding:"0px 0 3px 0px",
					margin:"0"
				});
				if(e.pageX < w()/2){
					$("#preview").css({
						left:e.pageX + xOffset + "px"			  
					}).fadeIn("fast");
				}else{
					$("#preview").css("right",(w()-e.pageX + yOffset) + "px").fadeIn("fast");	
				}
			},function(){
				$("#preview").remove();
			}).mousemove(function(e){
				//$("#preview").css("top",(e.pageY - xOffset) + "px");
				//  document.getElementById("wert").innerHTML="Wert:"+"x: "+e.pageX+" y:"+e.pageY+" w:"+w()+" h"+h()+" xw:"+$("#preview").width()+" yh"+$("#preview").height();
				//if(e.pageY < h()/2){ 
					$("#preview").css("top",getScrollTop()+20+ "px");
				//}
				//else {
				//	$("#preview").css("top",(e.pageY - $("#preview").height()) + document.body.scrollTop+"px");
				//}
					
				if(e.pageX < w()/2){
					$("#preview").css("left",(e.pageX + yOffset) + "px").css("right","auto");
				}else{
					$("#preview").css("right",(w()-e.pageX + yOffset) + "px").css("left","auto");
				}
			});						  
		});
	};
})(jQuery);

function gan(element) {
 	if (typeof element == "string")
 		return document.getElementById(element);
 	else
 		return null;
} 

String.prototype.trim = function(){
          return this.replace(/(^\s*)|(\s*gan)/g, '');
}

function isIE(){
      return (document.all && window.ActiveXObject && !window.opera) ? true : false;
}
 
function cancelVorder(divId){
    gan(divId).style.display = 'none';
    gan("hinter_div").style.display = 'none';
 	document.body.style.overflow = '';
}

function popHinterDiv(){
   if (gan("hinter_div")) {
   	 gan("hinter_div").style.display = '';
   }
   else {
    var hinterDiv = document.createElement('div');
    document.body.appendChild(hinterDiv);
    hinterDiv.id = 'hinter_div';
    with(hinterDiv.style) {
     position = 'absolute';
     background = '#000000';
     left = '0px';
     top = '0px';
     var bodySize = getBodySize();
     //width = bodySize[0] + 'px'
     width = '100%'
      height = bodySize[1] + 'px';
     zIndex = 12;
     if (isIE()) {
      filter = "Alpha(Opacity=80)";
     } else {
      opacity = 0.8;
     }
    }
   }
    
  
}

function getBodySize(){
   var bodySize = [];
   with(document.documentElement) {
    bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
    bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
   }
   return bodySize;
}

function popVorderDiv(divName,divId){
   if (gan(divId)) {
  		gan(divId).style.display = '';
		gan(divId).style.top = getScrollTop()+'px';
		return;
   } else {
	   	var divName = document.createElement('div');
		divName.id = divId;
		document.body.appendChild(divName);
		var bs= getBodySize();
		with(divName.style){
			zIndex = 15;
 		display="block";
		position = 'absolute';
		width='100%';
		height=document.documentElement.clientHeight-36+'px';
		left = '0px';
		//top = (document.documentElement.clientHeight - 400)/2 + getScrollTop()+'px';
		top = getScrollTop()+18+'px';
		overflow='auto';
		}
		return divName;
	}
} 

function popVorderDivFlow() {
   popHinterDiv(); 
   popVorderDiv(); 
   // document.body.style.overflow = "hidden";    
}

 


function mouseCoords(ev) 
{ 
	if(ev.pageX || ev.pageY){ 
	return {x:ev.pageX, y:ev.pageY}; 
	} 
	return { 
		x:ev.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
		y:ev.clientY + document.body.scrollTop+document.documentElement.scrollTop 
	}; 
}

function dele(id,l) {
	var phpRequest = init();
	function init() {
		if (window.XMLHttpRequest)
			return new XMLHttpRequest();
		else if (window.ActiveXObject)
			return new ActiveXObject("Microsoft.XMLHTTP");
	}
 

	phpRequest.open("GET", "php/kauf.php?_ln="+encodeURI(l)+"&dele=" + encodeURI(id), false);
	phpRequest.send(null);

	if (phpRequest.readyState == 4 && phpRequest.status == 200) {
		var result = phpRequest.responseText;
		document.getElementById("bestellung").innerHTML =result; 
		
	}
}

function k1(){ 
	if(	document.getElementById('id_k1').checked==true) {
		document.getElementById('id_buegelkoerbe').checked='';
		document.getElementById('id_k_m_s_b').checked='';
		document.getElementById('id_schalen').checked='';
		document.getElementById('id_einkaufskoerbe').checked='';
		document.getElementById('id_fuellkoerbe').checked='';
		document.getElementById('id_flaschekoerbe').checked='';
		document.getElementById('id_pflanzenkoerbe').checked='';		
		document.getElementById('id_sonstige').checked='';
	}
}

function k2(){

	if(	document.getElementById('id_k2').checked==true) {
		document.getElementById('id_korbsets').checked='';
		document.getElementById('id_einzelkoerbe').checked='';
	}
}

function k3(){

	if(	document.getElementById('id_k3').checked==true) {
		document.getElementById('id_mit_stoff').checked='';
		document.getElementById('id_ohne_stoff').checked='';
	}
}

function alle_c(k){
	document.getElementById(k).checked='';
}

function ShowTip(a)
{
var event=a?a:window.event;
var mX = event.x ? event.x : event.pageX;
var my = event.y ? event.y : event.pageY;
document.getElementById("div_tip").style.display = 'block';
document.getElementById("div_tip").style.left=mX +10 ;
document.getElementById("div_tip").style.posTop=my + 10;
}

function HideTip(a)
{
	document.getElementById("div_tip").style.display = 'none';

}

function request(nr,ve,ti,l) { 
	var phpRequest = init();
	function init() {
		if (window.XMLHttpRequest)
			return new XMLHttpRequest();
		else if (window.ActiveXObject)
			return new ActiveXObject("Microsoft.XMLHTTP");
	}
 

	phpRequest.open("GET", "php/kauf.php?nr=" + encodeURI(nr)+'&ve='+ encodeURI(ve)+'&_ln='+encodeURI(l)+'&ti='+ encodeURI(ti), false);
	phpRequest.send(null);

	if (phpRequest.readyState == 4 && phpRequest.status == 200) {
		var result = phpRequest.responseText;
		//document.getElementById("bestellung").innerHTML =result; 
		
	}
	
	document.getElementById("akt").submit();
	//history.go(0);
	//$("a.preview").preview();	  

}

function au(nr,anzahl,l) {  
	var phpRequest = init(); 
	function init() {
		if (window.XMLHttpRequest)
			return new XMLHttpRequest();
		else if (window.ActiveXObject)
			return new ActiveXObject("Microsoft.XMLHTTP");
	}
 
	phpRequest.open("GET", "php/kauf.php?nr=" + encodeURI(nr)+'&anzahl='+ encodeURI(anzahl)+'&au=true'+'&_ln='+encodeURI(l), false);
	phpRequest.send(null);  
}
