showOffers=function(ASIN,offerPage,condition,targetId){
	var url="/aaws/offers.php";
	new Ajax.Updater(
		$(targetId), url,{
			method: 'get',
			onBegin:showOffersBegin(targetId),
			onComplete:showOffersCompleted(targetId),
			evalScripts:true,
			parameters: {
				offerPage: offerPage,
				ASIN:ASIN,
				condition:condition
			}
			
		}
	);
}
showOffersBegin=function(targetId){
	$(targetId).insert( { top: '<div class="waiting">Please wait...</div>'} );
	new Effect.BlindDown(targetId);
}

showOffersCompleted=function(targetId){
	new Effect.Highlight(targetId,{delay:2.0});
}

hideCloseable=function(event) {
		var element = Event.findElement(event, 'div.closeable');
		//$(element).Hide();
		Effect.BlindUp(element);
}

switchView=function(elem1,elem2){
	$(elem1, elem2).invoke('toggle');  
	/*
	new Effect.Parallel(
		[new Effect.Fade(elem1, {sync: true}),
		new Effect.Appear(elem2, {sync: true})],{duration: 0});
	*/
}
	
itemDetail_changeProductImage = function(nid,nsrc,nheight,nwidth){
	var pic = $(nid);
	pic.src=nsrc;
	if ((nheight>0 && nwidth>0)){
		x = pic.up('div.item_Image');
		y = pic.up('div.item_ImageWrapper');
		pic.height=nheight;
		pic.width=nwidth;
		
		
		x.height=nheight;
		x.width=nwidth;
		Element.setStyle(pic, {width:nwidth+'px',height:nheight+'px'});
		Element.setStyle(x, {width:nwidth+'px',height:nheight+'px'});
	}
	new Effect.Highlight(y);
}
		
cart_modifyItemQuantity=function(formRef,sQuantity){
	quantity  = parseInt(sQuantity);
	if (isNaN(quantity)){
		return false;
	}		
	
	$(formRef).CartItemQuantity.value  = quantity;
	$(formRef).submit();	
}
	
changeBrowseNode=function(elem,targetId){
	var url="/aaws/browse.php";
	new Ajax.Updater(
		targetId, url,{
			
			method: 'get',
			parameters: {
				node: $F(elem)
			}
		}
	);
}

addToBasket=function(pid){
	var url="/aaws/addToMinibasket.php";
	new Ajax.Updater(
		'minibasket_wrapper', url,{
			method: 'get',
			parameters: {
				OfferListingId: pid
			}
			
		}
	);
	return false;
}

addToBasket=function(pid,but){
	var url="/aaws/addToMinibasket.php";
	new Ajax.Updater(
		'minibasket_wrapper', url,{
			method: 'get',
			onBegin:addToBasketStart(but),
			onComplete:addToBasketFinished(but),
			parameters: {
				OfferListingId: pid
			}
			
		}
	);
}

addToBasketStart=function(but){
	
}

addToBasketFinished=function(but){
	x = $(but).up('div.contentBox');
	
	new Effect.Parallel(
		[
			new Effect.Highlight(x, {sync: true}),
			new Effect.Highlight('minibasket_wrapper', {sync: true})
		],{duration: 1});
}

updateBasket=function(ciid,quantity){
	var url="/aaws/request/cart_modify.php";
	new Ajax.Updater(
		'minibasket_wrapper', url,{
			method: 'get',
			onComplete:updateBasketFinished,
			parameters: {
				CartItemId: ciid,
				CartItemQuantity: quantity
			}
		}
	);
}

loadBitlyScript=function(link,title){
	target='http://api.bit.ly/shorten?version=2.0.1&longUrl='+link+'&login=amanav&apiKey=R_65a902cd8fbd57a8b0a265619dfd1342';
	new Ajax.Request('/proxy.php', {
			method:'get',
			 onSuccess: function(transport) {
				var data= transport.responseText.evalJSON();
				for (var r in data.results) {
						result = data.results[r];
						result['longUrl'] = r;
					break;
				}
				shortUrl = result['shortUrl'];
				window.open('http://twitter.com/home?status='+title+'%20-%20'+shortUrl);
			},
			parameters: {
				target:target
			}
		}
	);
}
loadBitlyScriptFinished=function(transport,title){
	var data= transport.responseText.evalJSON();
	for (var r in data.results) {
			result = data.results[r];
			result['longUrl'] = r;
		break;
	}
	shortUrl = result['shortUrl'];
	alert(shortUrl);//window.open('http://twitter.com/home?status='+title+'%20-%20'+shortUrl);
}
loadBitlyScriptFailed=function(req,exception) {
		alert("The request had a fatal exception thrown.\n\n" +
        exception);
        alert("exception.description:"+exception.description);
        alert("exception.message"+exception.message);
        return true;

}
updateBasketFinished=function(){
	new Effect.Highlight('minibasket_wrapper');
}

removeFromHistory=function(asin){
	deleteCookie('history['+asin+']','/',null);
	setVisible('historyItem_'+asin,false);
}

readMetaTag=function(tagName){
	var meta = $$('meta[name="'+tagName+'"]');
	var metaContent="";
	if (Object.isArray(meta)){
		var fo= metaContent=meta.first();
		metaContent=fo.content;
	}
	else if(isElement(meta)){
		metaContent=meta.content;
	}
	return metaContent;
}

bookmark=function(item) {
  link=encodeURIComponent(location.href);
  title=encodeURIComponent(document.title);
  keywords = encodeURIComponent(readMetaTag('keywords'));
  description = encodeURIComponent(readMetaTag('description'));
  switch(item) {
    case 'wong':
      window.open('http://www.mister-wong.de/index.php?action=addurl&bm_url='+link+'&bm_description='+title+"&bm_comment="+description); break;
    case 'del':
      window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+link+'&title='+title,'delicious', 'toolbar=no,width=550,height=550'); break;
    case 'google':
      window.open('http://www.google.com/bookmarks/mark?op=add&hl=de&bkmk='+link+'&title='+title+'&labels='+keywords+'&annotation='+description); break;
    case 'webnews':
      window.open('http://www.webnews.de/einstellen?url='+link+'&title='+title); break;
    case 'linkarena':
      window.open('http://linkarena.com/bookmarks/addlink/?url='+link+'&title='+title+'&desc='+description+'&tags='+keywords); break;
    case 'oneview':
      window.open('http://beta.oneview.de:80/quickadd/neu/addBookmark.jsf?URL='+link+'&title='+title); break;
    case 'furl':
      window.open('http://www.furl.net/storeIt.jsp?u='+link+'&t='+title); break;
    case 'yahoo':
      window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?u='+link+'&t='+title); break;
    case 'yigg':
      window.open('http://yigg.de/neu?exturl='+link+'&exttitle='+title); break;
	case 'twitter':
		loadBitlyScript(link,title);break;
    case 'facebook':
	  u=location.href;
	  t=document.title;
	  window.open('http://www.facebook.com/sharer.php?u='+link+'&t='+title,'sharer','toolbar=0,status=0,width=626,height=436');
  }
}

function getChildrensHeights(obj)
{
	if(!obj.firstChild) return 0;
	if(!obj.tagName.match(/div/i)) return 0;
	var height = 0;
	tmp = obj;
	obj = obj.firstChild;
	do height += getChildrensHeights(obj);
	while(obj = obj.nextSibling);
	//if(height == 0) height = tmp.offsetHeight;
	if(height == 0) height = tmp.offsetHeight;
	return height;
}

setVisible=function(ele, show){
	if (show){
		$(ele).show();
	}
	else{
		$(ele).hide();
	}
}

function popUp(url,title, w,h) {
	var option="width="+w+",height="+h+",scrollbars=no,menubar=no,toolbar=no,location=no,resizable=no";
	ok = window.open(url,title,option);
	return (! ok);
}

clearText=function(thefield){
	thefield.value = "";
}
activateField=function(textField,thefield){
	if (textField.value==""){
		$(thefield).disabled="disabled";
	}
	else{
		$(thefield).disabled=false;
	}
}

/* Tabs */

/*-----------------------------------------------------------
    Toggles element's display value
    Input: any number of element id's
    Output: none 
    ---------------------------------------------------------*/
function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'inline';
        else
            d.style.display = 'none';
    }
}
/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(num,numelems,opennum,animate) {
    if ($('tabContent'+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = 'tabHeader'+i;
                var h = $(temph);
                if (!h){
                    var h = $('tabHeaderActive');
                    h.id = temph;
                }
                var tempc = 'tabContent'+i;
                var c = $(tempc);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
                        Effect.toggle(tempc,'blind',{duration:0.5, queue:{scope:'menus', limit: 3}});
                    else
                        toggleDisp(tempc);
                }
            }
        }
        var h = $('tabHeader'+num);
        if (h)
            h.id = 'tabHeaderActive';
        h.blur();
        var c = $('tabContent'+num);
        c.style.marginTop = '2px';
        if (animate || typeof animate == 'undefined'){
            Effect.toggle('tabContent'+num,'blind',{duration:0.5, queue:{scope:'menus', position:'end', limit: 3}});
        }else{
            toggleDisp('tabContent'+num);
        }
    }
}


/**
* Sets a Cookie with the given name and value.
*
* name Name of the cookie
* value Value of the cookie
* [expires] Expiration date of the cookie (default: end of current session)
* [path] Path where the cookie is valid (default: path of calling document)
* [domain] Domain where the cookie is valid
* (default: domain of calling document)
* [secure] Boolean value indicating if the cookie transmission requires a
* secure transmission
*/
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
 
/**
* Gets the value of the specified cookie.
*
* name Name of the desired cookie.
*
* Returns a string containing value of specified cookie,
* or null if cookie does not exist.
*/
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
 
/**
* Deletes the specified cookie.
*
* name name of the cookie
* [path] path of the cookie (must be same as path used to create cookie)
* [domain] domain of the cookie (must be same as domain used to create cookie)
*/
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}