/********************************************************************************
* Project:       phpCurema (http://phpcurema.neflexis.ch, info@neflexis.ch)     *
* Copyright:     2006 - 2007 neflexis GmbH (www.neflexis.ch)                    *
* Author:        Emanuel Zuber (emanuel.zuber@neflexis.ch)                      *
********************************************************************************/



/*** get city from zip ***/
function insert_city_from_zip() {
	var zip = $F('zip');
	
	if(zip.length == 4) {
		new Ajax.Request(	'custom/ajax_handler.php?action=get_zip&zip=' + zip,
							{asynchronous: true, onComplete: insert_city}
							);
	}
	else {
		$('city').value = '';
	}
}
function insert_city(request) {
	$('city').value = request.responseText;
}


function save_home_boxes() {
	new Ajax.Request('ajax_handler.php?action=set_home_boxes',{asynchronous:true, method:'post',postBody:Sortable.serialize("boxes")});
}



function search_select(search_engine) {
	if (search_engine == 'yahoo') {
		$('search_form').action='http://ch.search.yahoo.com/search';
		new Ajax.Request('ajax_handler.php?action=set_web_search&web_search=yahoo',{asynchronous:true, method:'get'});
	}
	else if (search_engine == 'live') {
		$('search_form').action='http://search.live.com/results.aspx';
		new Ajax.Request('ajax_handler.php?action=set_web_search&web_search=live',{asynchronous:true, method:'get'});
	}
	else if (search_engine == 'searchch') {
		$('search_form').action='http://www.search.ch/search.html';
		new Ajax.Request('ajax_handler.php?action=set_web_search&web_search=live',{asynchronous:true, method:'get'});
	}
	else {
		$('search_form').action='http://www.google.ch/search';
		new Ajax.Request('ajax_handler.php?action=set_web_search&web_search=google',{asynchronous:true, method:'get'});
	}

	$('href-search-google').style.background = 'transparent';
	$('href-search-yahoo').style.background = 'transparent';
	$('href-search-live').style.background = 'transparent';
	$('href-search-searchch').style.background = 'transparent';
	$('href-search-' + search_engine).style.background = 'url(custom/template/img/bg_search_tab.gif) no-repeat;';
	$('search_input').focus();
}







function CrossFadeSlideshow(slideshow, timeout) {
	this.slides = [];
	this.timeout = timeout;
	this.current = 0;
	
	var items = $(slideshow).getElementsByTagName('div');
	
	for (var i=0; i<items.length; i++) {
		if (Element.hasClassName(items[i], 'slide')) {
			this.slides.push(items[i]);
		}
	}
	
	for (var i=0; i<this.slides.length; i++) {
		this.slides[i].style.zIndex = this.slides.length - i;
	}

	Element.show(slideshow);
	setTimeout((function(){this.next();}).bind(this), this.timeout + 350);
}

CrossFadeSlideshow.prototype = {
	next: function() {
		for (var i=0; i<this.slides.length -1; i++) {
			var slide = this.slides[(this.current + i) % this.slides.length];
			slide.style.zIndex = this.slides.length - i;
		}

		Effect.Fade(this.slides[this.current], {
			afterFinish: function(effect) {
				effect.element.style.zIndex = 0;
				Element.show(effect.element);
				Element.setOpacity(effect.element, 1);
			}
		});
    
		this.current = (this.current + 1) % this.slides.length;
		setTimeout((function(){this.next();}).bind(this), this.timeout + 350);
	}
}


function confirm_order(text) {
	var answer = confirm (text)
	if (answer) {
		document.getElementById('cart-form').submit();
	}
	
	/*
	else {
		alert ("Darn. Well, keep trying then.")
	}
	*/
}















