// JavaScript Document

function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}

function goHome(){
	self.location='/';
}


/*
// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];

  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);

  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

  return foundObj;
}



function change_content(id,content){
	var obj = findObj(id);
	//var obj = document.getElementById(id);
	//if (obj == undefined ) return false;
	obj.innerHTML = content;
}

function add2watchlist(id,typ){
	findObj('shopaction').location = '/shopping/watchlist_add.php?id='+id+'&type='+typ;
	//document.getElementById(id).location = '/shopping/watchlist_add.php?id='+id+'&type='+typ;
}

*/

function expand_pv(){
/*
	Produktvergleich - Vergleiche ausklappen
	
	$('#txt_pv .catlist').animate({
		"height": "toggle", "opacity": "toggle"
	}, "fast");
	
	if($('#txt_pv .catlist').css('display') == 'none') $('#txt_pv .catlist').fadeIn('fast', function(){ $(this).css("display","block")});
	else $('#txt_pv .catlist').fadeOut('fast', function(){ $(this).css("display","none")});;
*/
	if($('#txt_pv .catlist').css('display') == 'none') $('#txt_pv .catlist').slideDown('fast',function(){});
	else $('#txt_pv .catlist').slideUp('fast',function(){});
	
}

function watchlist(pid,typ,a,page){
	
	//$('#num_watchlist').load('http://www.preisonaut.de/shopping/handler_watchlist.php?id='+pid+'&amp;typ='+typ+'&amp;a='+a);
	$.get('/shopping/handler_watchlist.php', { 'id':pid, 'typ':typ, 'a':a }, function(data) {
		
		$('#num_watchlist').html(data);
		
	});
	
	if(page == 'wl'){
		
		setTimeout('location.reload()',500);
		
	} else {
		
		if(a=='add') $('#watchitem'+pid).html('<a href="javascript:watchlist(\''+pid+'\',\''+typ+'\',\'remove\')"><img src="/images/icons/merkliste-entfernen.gif" width="16" height="16" alt="" class="icon" />Aus Merkliste löschen</a>');
		
		else $('#watchitem'+pid).html('<a href="javascript:watchlist(\''+pid+'\',\''+typ+'\',\'add\')"><img src="/images/icons/merkliste-adden.gif" width="16" height="16" alt="" class="icon" />Auf die Merkliste</a>');
		
	}
	
}


// Funktion wird direkt in der Merkliste benötigt - lädt die Seite neu
function watchlist_remove(id,typ){
	
	$.get('/shopping/handler_watchlist.php', { 'id':id, 'typ':typ, 'a':'remove' }, function(data) {
		
		if(data != ''){
			
			location.reload();
		
		} else {
			
			jAlert('Es ist ein Fehler aufgetreten, versuchen Sie es bitte noch einmal','Fehler');
			
		}
	});
}

function comparelist(cid,pid,action,sid,sname){
	
	$.get('/shopping/handler_comparelist.php', { 'pid':pid, 'cid':cid, 'a':action, 'sname':sid }, function(data) {
	  if(data == 'full') {
		  jAlert('Aus Gründen der Übersicht können nur 3 Produkte gleichzeitig innerhalb einer Kategorie verglichen werden!\n\nUm ein neues Produkt hinzuzufügen, löschen Sie bitte zuerst ein Produkt dieser Kategorie aus dem Vergleich.');
	  } else {
	  	$('#menuCompareListContent').html(data);
		if(action == 'add') $('#compareitem'+pid).html('<img src="/images/icons/produktvergleich-entfernen.jpg" width="20" height="20" alt="" class="icon"/><a href="javascript:comparelist(\''+cid+'\',\''+pid+'\',\'remove\',\''+sid+'\',\''+sname+'\')" class="inlist">Aus Vergleich löschen</a>');
		else $('#compareitem'+pid).html('<img src="/images/icons/produktvergleich-icon.jpg" width="20" height="20" alt="" class="icon"/><a href="javascript:comparelist(\''+cid+'\',\''+pid+'\',\'add\',\''+sid+'\',\''+sname+'\')">Produkt vergleichen</a>');
		//$('#compareitem'+pid).addClass('text-grau');
	  }
	});
}

// Funktion wird direkt im Vergleich benötigt - lädt die Seite neu
function comparelist_remove(cid,pid){
	
	$.get('/shopping/handler_comparelist.php', { 'pid':pid, 'cid':cid, 'a':'remove' }, function(data) {
		
		if(data.match(/^Fehler/)){
			
			jAlert(data,'Fehler');
		
		} else if(data == ''){
			
			jAlert('Es ist ein Fehler aufgetreten, versuchen Sie es bitte noch einmal','Fehler');
			
		} else {
			
			location.reload();
			
		}
	});
	
}




var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height) {

  if(left == 1) left = (screen.width/2) - width/2;
  if(top == 1) top = (screen.height/2) - height/2;

  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  if(popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'')){
	  	popUpWin.focus();
  } else {
		jAlert('Diese Seite wird in einem PopUp Fenster angezeigt.\nDeaktivieren Sie bitte Ihren PopUp Blocker.','Fehler');  
  }
}

function openWin(URLStr){
	var popw = $(window).width()-10;
	var poph = $(window).height()-20;
	if(popw <= 0) popw = 1010;
	if(poph <= 0) poph = 700;
	window.open(URLStr,'_blank','width='+popw+',height='+poph+',toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
	return false;
}


// autofill
var options, a;
jQuery(function(){
  options = { serviceUrl:'/shopping/auto-complete.php', minChars:2, width:372 }; // Von Become
  //options = { serviceUrl:'/shopping/autofill.php', minChars:2, width:372 }; // Eigene DB
  a = $('#iqry').autocomplete(options);
});

// Tooltip
this.tooltip = function(){	
		
		xOffset = 10;
		yOffset = 20;	
		
	$(".tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";								  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$(".tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};




// Highligting und Klicken der Offers
$(document).ready(function() {
	
	tooltip();
	
	// Preisomaut Logo href
	$("#preisonaut_logo").click(function(){
		self.location = 'http://www.preisonaut.de';
	});
	
	// inititialen Suchfeldinhalt definieren
	var init_searchphrase = 'Suchbegriff';
	
	// inititialen Suchfeldinhalt setzen
	if($("#iqry").val() == '') $("#iqry").val(init_searchphrase);
	
	// Keywordstatistik aktivieren

	$("#iqry").change(function(){
		$("#init_kw").val('1');
	});
	
	$("#iqry").focus(function(){
		if($(this).val() == init_searchphrase) $(this).val("");
	});
	
	$("#iqry").blur(function(){
		if($(this).val() == "") $(this).val(init_searchphrase);
	});
	
	$("#formSearch").submit(function(){
		if( $("#iqry").val().length < 3 || $("#iqry").val() == init_searchphrase ) {
			//alert('Geben Sie bitte einen Suchbegriff mit mindestens 3 Zeichen ein!');
			jAlert('Geben Sie bitte einen Suchbegriff mit mindestens 3 Zeichen ein!', 'Preisonaut Produktsuche');
			return false;
		}
	});
	
	// Merkliste String ändern
	$("#txt_ws").text('Merkliste');
	
	// Versandkosten String ändern
	$(".vks").text('zzgl. Versand ');
	
	// Versandkostenfrei String ändern
	$(".vksf").text('kostenloser Versand');
	
	var aHover = 0;
	
	//$("a").hover(function(){ aHover = 1; } , function(){ aHover = 0; } );
	
	$("a").hover(function(){ aHover = 1; } , function(){ aHover = 0; } );
	$(".watchlistLink").hover(function(){ aHover = 1; } , function(){ aHover = 0; } );
	
	// Merkliste Text im Link
	$(".watchlist-str-del").text("Aus Merkliste löschen");
	$(".watchlist-str-add").text("Auf die Merkliste");
	
	// more soll funktionieren
	$('.jqOfferRow').find('a.more').click(function() {
	  showDesc($(this).attr("rel"),$(this).attr("rev")); return false;
	});	
	
	// Bei Mouseover die Blöcke färben
	$('.jqOfferRow').hover(function(){$(this).addClass('highlightForClick')} ,  function(){$(this).removeClass('highlightForClick')} );
	$('.jqOfferCol').hover(function(){$(this).addClass('product-canvas-hover')} ,  function(){$(this).removeClass('product-canvas-hover')} );
	
	// Button bei Mousover einrahmen
	$('a.jqShoplink img').hover(function(){$(this).addClass('rahmen')} ,  function(){$(this).removeClass('rahmen')} );
	$('.button').hover(function(){$(this).addClass('rahmen')} ,  function(){$(this).removeClass('rahmen')} );
	
	/*
	$('.jqOfferRow').mouseout(function() {
	  $(this).removeClass('highlightForClick');
	});
	*/
	
	
	$('.jqOfferRow').click(function() {
		
		var shoplink = $(this).find("a.jqShoplink");
		
		if( shoplink.length > 0 ){
			
			if(aHover == 0){
	
				if(shoplink.attr("target") == "_blank"){
				
					//window.open(shoplink.attr("href"));
					//return false;
					return openWin(shoplink.attr("href"));
				
				} else {
					
					self.location = (shoplink.attr("href"));
					return false;
				}
			}
		}
	});
	
	
	
	
	// Mehr Button
	
	// init
	//$('.button_more').html('<img src="/images/buttons/txt-more.gif" alt="" width="54" height="11" />');
	$('.button_more').html('...[mehr]');
	
	// funktion
	$('.button_more').click(function() {
		
		
		var mButton = $(this);
		var hidden_block = $(this).prev();
		
		aHover = 1;
		
		if(hidden_block.css("display") == "none"){
			
			//$(this).css("display","none");
			$(this).html('');
			
			$(hidden_block).animate({
				"height": "toggle", "opacity": "toggle"
			}, "fast");

			
			$(hidden_block).fadeIn('fast', function(){ 
				$(this).css("display","inline");
				//mButton.html('<img src="/images/buttons/txt-less.gif" alt="" width="54" height="11" />');
				mButton.html('...[weniger]');
				mButton.css("display","inline");
				aHover = 0;
			});

	
		} else {
			
			mButton.css("display","none");
			
			$(hidden_block).animate({
				"height": "toggle", "opacity": "toggle"
			}, "fast");	
			
			$(hidden_block).fadeOut('fast', function(){ 
				//mButton.html('<img src="/images/buttons/txt-more.gif" alt="" width="54" height="11" />');
				mButton.html('...[mehr]');
				mButton.css("display","inline");
				$('this').css("display","inline")
				aHover = 0;
			});
		
		}

	});	
	
	// Preishinweis
	$(".pricehintdiv").html('<a href="/hinweise/preishinweis.php" class="pricehint" rel="nofollow">Preis kann höher sein!</a>');
	$(".pricehintdiv").hover(function(){ aHover = 1; } , function(){ aHover = 0; } );
	
	// ZOOM IMAGE
	var zoom_optionsO = {
	    zoomWidth: 100,
	    zoomHeight: 100,
		showEffect: 'fadein',
		fadeinSpeed: 'middle',
		hideEffect: 'fadeout',
		fadeoutSpeed: 'slow',
		lens: false,
		preloadText: 'Lade...',
        //xOffset: 10,
        yOffset: -18
       //position: "top" //and MORE OPTIONS
	};
	
	var zoom_optionsP = {
		showEffect: 'fadein',
		fadeinSpeed: 'middle',
		hideEffect: 'fadeout',
		fadeoutSpeed: 'slow',
		yOffset: -50,
		lens: false,
		preloadText: 'Lade...'
	};


	$('.zoomImgO').jqzoom(zoom_optionsO);
	$('.zoomImgP').jqzoom(zoom_optionsP);
	
	
	/* Fancy box */
	$(".ratingform").fancybox({
		'width'				: '580',
		'height'			: '420',
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	
	$(".pricehint").fancybox({
		'width'				: '520',
		'height'			: '220',
		'autoScale'			: true,
		'showNavArrows'		: false,
		'hideOnContentClick': true,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'type'				: 'iframe'
	});
	
	$(".preiswecker").fancybox({
		'width'				: '580',
		'height'			: '380',
		'autoScale'			: true,
		'showNavArrows'		: false,
		'hideOnContentClick': true,
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'type'				: 'iframe'
	});
	
	
	/*  Filter  */
	$('#filterbox a.dim').click(function() {
		
		var n = $(this).next();
		
		if(n.css('display') == 'none'){
			n.show('fast');
			$(this).removeClass('divclosed').addClass('divopen');
			$(this).attr('title','Filter einklappen');
		} else {
			n.hide('fast');
			$(this).removeClass('divopen').addClass('divclosed');
			$(this).attr('title','Filter ausklappen');			
		}
		
	});
	
	$('#filterbox .block-wrap a.mehrFilter').click(function() {
		
		var n = $(this).prev();
		var mb = $(this);
		
		if(n.css('display') == 'none'){
			n.show('fast',function(){mb.text('weniger anzeigen')});
		} else {
			n.hide('fast',function(){mb.text('mahr anzeigen')});
			//$(this).text('mehr anzeigen');			
		}
		
	});

	
	// Weihnachten - Tage runterzählen-Box
	/*
	var now = new Date();
	var feiertag = new Date("December 24," + now.getFullYear());
	
	var days2christmas = Math.ceil((feiertag.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
	
	if(days2christmas > 0){
		
		var strTag = days2christmas == 1 ? 'Tag' : 'Tage';
		//$('.dayscounter').html('Nur noch<br />' + days2christmas + ' ' + strTag + '!');
		$('.dayscounter').html( 'Nur noch ' + days2christmas + ' '+ strTag +'<br />bis Weihnachten!');
		
	} else if( days2christmas > -4){
		
		$('.dayscounter').html('Ich wünsche Ihnen<br />ein Frohes Fest!');
		$('.dayscounter').css("font-weight","bold");
		
	}
	*/
	
});




function showDesc(id1, id2){

	$('#'+id1).css('display','inline');
	$('#'+id2).css('display','none');
	return false;
}

