window.onload = counterPath;
window.onload = gdiv_size;

function counterPath()
{
	var ScreenW = screen.width;
	var ScreenH = screen.height;
	var ScreenD = screen.colorDepth;
	
	var thisurl = window.location.pathname;
	var path = thisurl.split("/");
	var num = path.length;
	var dateiname = path[(num-1)];

	var countbox = "sw=" + ScreenW + "&sh=" + ScreenH + "&sd=" + ScreenD + "&refuri=" + dateiname;
	var retcode = "lib/counter.php?" + countbox;
	document.getElementById('statscount').src = retcode;
}

function DisplayTab(tab_id,panel_id,vals)
{
	var panelElm = document.getElementById(panel_id);
	var tabElm = document.getElementById(tab_id);
	var tname = vals.split(",");
	var arr = new Array();
	
	for(z=0;z<tname.length;z++)
	{
		var checkname = tname[z];
		if(document.getElementById(checkname + "_tab"))
		{
			var newElement = arr.push(checkname);
		}
	}

	for(var x=0;x<arr.length;x++)
	{
		var tabid = arr[x] + "_tab";
		document.getElementById(tabid).className = '';
	}
	tabElm.className = 'current';

	for(var y=0;y<arr.length;y++)
	{
		var panid = arr[y] + "_panel";
		document.getElementById(panid).className = 'panel';
	}
	panelElm.className = 'current';
}

function toggleScollbar(stat)
{
	desObj = document.getElementsByTagName('html')[0];
	//desObj = document.body;
	desObj.style.overflow = (state == "hide") ? "hidden" : '';
}

function trim(dir,val)
{
	switch(dir)
	{
    	case "r": return val.replace(/\s+$/g,''); break;
      	case "l": return val.replace(/^\s+/g,''); break;
     	default: return val.replace(/(^\s+|\s+$)/g,'');
    }
}

function pwStrength(o)
{
	var x=6;
	var w=o.value;
	var v=trim('',w);
	if(!v.match(/[a-z]/)||!v.match(/[A-Z]/)) x-=2; //Gross+Kleinbuchstaben verwenden
  	if(v.length<6)                           x-=2; //mindestens 6 Zeichen eingeben
  	if(!v.match(/[^a-z\d]/i))                x-=1; //Sonderzeichen verwenden
  	if(!v.match(/[\d]/i))                    x-=1; //Zahlen verwenden
  
	var c="sign_green.png";
  	if(x<6) c="sign_yellow.png";
  	if(x<3) c="sign_red.png";
  	
	document.getElementById('pwIndikator').src="gfx/layout/" + c;
}

function refreshCaptcha()
{
	document.getElementById('cappic').src='random.php';
}

function selLiefcbox(v)
{
	if(v != "")
	{
		document.getElementById('cb2').checked = true;
	}
}

function abwl_div(v)
{
	if(v == true)
	{
		document.getElementById('abwl').style.visibility = 'visible';
		document.getElementById('abwl').style.position = 'static';
		document.getElementById('abwl').style.display = 'block';
	}
	else
	{
		document.getElementById('abwl').style.visibility = 'hidden';
		document.getElementById('abwl').style.position = 'absolute';
		document.getElementById('abwl').style.display = 'none';
	}
}

function show_div(id)
{
	if(document.getElementById(id).style.visibility =='hidden')
	{
		document.getElementById(id).style.visibility = 'visible';
		document.getElementById(id).style.position = 'static';
	}
	else
	{
		document.getElementById(id).style.visibility = 'hidden';
		document.getElementById(id).style.position = 'absolute';
	}
}

function show_btn(cbox,btn)
{
	if(document.getElementById(cbox).checked == true)
	{
		document.getElementById(btn).innerHTML = '<input type="image" src="gfx/button/btn_sendorder.png" border="0" alt="Auftrag abschicken" id="senden">';
		//document.getElementById(btn).style.visibility = 'visible';	
	}
	else
	{
		document.getElementById(btn).innerHTML = '<img src="gfx/button/btn_sendorder.png" title="Bitte die AGB akzeptieren" alt="Bitte die AGB akzeptieren" style="cursor:not-allowed" onClick="alert(\'Bitte die AGB akzeptieren\')">';
		//document.getElementById(btn).style.visibility = 'hidden';	
	}
}

function return_confirm(cont,page)
{
	if(confirm(cont))
	{
		document.location.href=page;
	}
	else
	{
		return "";
	}	
}

/* Popups */
function richtlinien()
{
	settings="width=500,height=500,top=50,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win=window.open('help/richtlinien.htm','BeitragsRichtlinien',settings);
	win.focus();
}

function showAGB()
{
	settings="width=650,height=500,top=50,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win=window.open('help/agb.php','AllgemeineGeschaeftsbedingungen',settings);
	win.focus();
}

function showWiderruf()
{
	settings="width=650,height=500,top=50,left=50,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win=window.open('help/widerruf.php','Widerrufsbelehrung',settings);
	win.focus();
}

function showPopup()
{
	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=" + sbv + ",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=" + rsv + "";
	win=window.open('popup.php?cmd=' + page,titel,settings);
	win.focus();
}

function showPopup_ext(page,w,h,sb,rs,titel)
{
	if(sb==1)
	{
		var sbv = "yes";	
	}
	else
	{
		var sbv = "no";	
	}
	if(rs==1)
	{
		var rsv = "yes";	
	}
	else
	{
		var rsv = "no";	
	}
	
	myleft=(screen.width)?(screen.width-w)/2:100;
	mytop=(screen.height)?(screen.height-h)/2:100;
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=" + sbv + ",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=" + rsv + "";
	win=window.open(page,titel,settings);
	win.focus();
}

function iFrameHoehe(id)
{
	var hoehe=document.getElementById(id).contentWindow.document.body.scrollHeight;
	document.getElementById(id).height=hoehe;
}

function ParentiFrameHoehe(id)
{
	var hoehe=parent.document.getElementById(id).contentWindow.document.body.scrollHeight;
	parent.document.getElementById(id).height=hoehe;
}

function replaceURI(url)
{
	location.replace(url);
}

function goto_page(page)
{
	document.location.href=page;
}

function add2Favs()
{
	var titel = "Zooversand.de - Heimtiernahrung und Zubehör"; 
	var url = "http://www.zooversand.de/shop/";
	
	if(window.sidebar) // Firefox
	{
		window.sidebar.addPanel(titel, url,"");
	}
	else if(window.external) // IE
	{
		window.external.AddFavorite(url,titel);
	}
	else
	{
		alert(unescape('Um diese Seite zu Ihren Favoriten hinzuzuf%FCgen,\ndr%FCcken Sie bitte die Tastenkombination\n\nSTRG und D'));
		//alert(unescape('zum Testen: %A9 %E4 %F6 %FC %C4 %D6 %DC %DF %40 '));
	}
}

function ShowMarke(cmd,shop,sbv,marken_id)
{
	//var marken_id = $F('marke');
	document.location.href=cmd + '_' + shop + '-' + marken_id + '-0-' + sbv + '.html';
}

function ShowBruch(shop)
{
	//var marken_id = $F('marke');
	document.location.href='bruch_' + shop + '.html';
}

function get_PageSize()
{
	var xScroll, yScroll;
			
	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if(document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
			
	var windowWidth, windowHeight;
			
	if (self.innerHeight)
	{	// all except Explorer
		if(document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth; 
		}
		else
		{
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if(document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
			
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{ 
		pageHeight = yScroll;
	}
		
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{	
		pageWidth = xScroll;		
	}
	else
	{
		pageWidth = windowWidth;
	}
	return [pageWidth,pageHeight];
}

function gdiv_size()
{
	if(document.getElementById('global_div'))
	{
		var arrayPageSize = get_PageSize();
		var h = arrayPageSize[1] + 'px';
		var w = arrayPageSize[0] + 'px';
		document.getElementById('global_div').style.width=w;
		document.getElementById('global_div').style.height=h;
	}
	else
	{
		return false;
	}
}


function doLytebox()
{
	var myLink = document.getElementById("myLink");
	myLytebox.start(myLink,false,false);
}

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 5,
		animation: "slow",
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});

$(document).ready(function()
{
	$('#snach').jSuggest({
		url: 'live_suche.php',
		type: 'GET',
		data: 'snach',
		autoChange: false,
 		loadingImg: 'gfx/layout/loader.gif',
 		opacity: 0.9,
 		loadingText: 'suchen...',
 		showFirst: 4
	});
	
	$("#verfeinern").click(function(){
		if ($("#searchContainer").is(":hidden"))
		{
			$("#searchContainer").slideDown("fast");
		}
		else
		{
			$("#searchContainer").slideUp("fast");
		}
		return false;
	}); 
	
	$("#btnMini").click(function(){
		$("#searchContainer").slideUp("fast");
		return false;
	});
	
	$("#selBox1").change(function(){
    	var id_hauptkategorie=$(this).children('option:selected').val();
        $("#selBox2").load("suche_aartbox.php",{value: id_hauptkategorie});
    });
	
	$(document).ready(function(){	
		$("#slider").easySlider({
			auto: true,
			continuous: true,
			numeric: true
		});
	});	
});

function art_suche()
{
	var snach = $F('snach');
	var opt = { method:'post',postBody:'aktion=art_suche&snach='+snach };
	
	new Ajax.Updater( {success:'artikel'},'live_suche2.php',opt);
}
