var timer;
var actualFlyoutId = -1;

var huhu = "Peavey was here";
var dummypic400 = "/images/dummy_256x550.jpg";
var dummypic400b = "/images/dummy_550x550.jpg";

function showFlyout(id)
{
	if(actualFlyoutId != -1)
	{
		cancelHideFlyout();
		hideFlyout(actualFlyoutId);
	}
  	var elmnt = document.getElementById("flyout_" + id);

  	elmnt.style.display = "";

  	actualFlyoutId = id;
}

function hideFlyout(id)
{
	var elmnt = document.getElementById("flyout_" + id);
	elmnt.style.display = "none";
}

function startHideFlyout(id)
{
	timer = setTimeout(function(){hideFlyout(id)},250);
}

function cancelHideFlyout()
{
	clearTimeout(timer);
}

function getRawPageWidth () {
  if (window.innerWidth) {
    return window.innerWidth;
  } else if (document.body && document.body.offsetWidth) {
    return document.body.offsetWidth;
  } else {
    return 2000;
  }
}

function getRawPageHeight () {
  if (window.innerHeight) {
    return window.innerHeight+200;
  } else if (document.body && document.body.offsetHeight) {
    return document.body.offsetHeight+200;
  } else {
    return 1024;
  }
}


function correctLoaderHeight()
{
	loader = document.getElementById("rcLoader");
	loader.style.display = "block";
	loader.style.height = getRawPageHeight();
	loader.style.width = getRawPageWidth();
}

function getPageHeight()
{
	highestElement = document.getElementById("rcFrame");
	return highestElement.offsetHeight;
}

function showLoader()
{
	loader = document.getElementById("rcLoader");
	loader.style.height = getPageHeight();
	loader.style.display = "block";
}

function hideLoader()
{
	loader = document.getElementById("rcLoader");
	loader.style.display = "none";
}

function showExtSearch(obj)
{
	o = document.getElementById("extSearch");
	p = document.getElementById("bestellen");

	if(obj.checked == true)
	{
		o.style.display = "";
		//get(extSearchEnable,"dummy");
	}
	else
	{
		o.style.display = "none";
		//get(extSearchDisable,"dummy");
	}

}

function showShippingAddress(obj)
{
	o = document.getElementById("shippingAddress");
	if(obj.checked == true)
	{
		o.style.display = "";
	}
	else
	{
		o.style.display = "none";
	}

}

function showGreetingCard(obj)
{
	o = document.getElementById("greetingCard");
	if(obj.checked == true)
	{
		o.style.display = "";
	}
	else
	{
		o.style.display = "none";
	}

}

function gotoPage(obj)
{
	self.location.href = obj.options[obj.selectedIndex].value;
}

function showPaymentMethod(obj)
{

	var index = obj.elements['data[payment][pym_type]'].selectedIndex;

	var	method = obj.elements['data[payment][pym_type]'].options[index].value;

	o = document.getElementById("rcCredit");
	p = document.getElementById("rcDebit");

	if(method == "credit")
	{
		o.style.display = "";
	}
	else
	{
		o.style.display = "none";
	}

	if(method == "debit")
	{
		p.style.display = "";
	}
	else
	{
		p.style.display = "none";
	}

}

function gotoUrl(url)
{
	self.location.href = url;
}

function getUrlByExtSearch(obj)
{
	retrieveURL(obj, extSearchConvert, "dummy2");
}

function retrieveURL(obj, url, output)
{
	http_request = false;
	if (window.XMLHttpRequest)
	{
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
		{
			http_request.overrideMimeType('text/html');
		}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
			   http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{

			}
		}
	}

	if (!http_request)
	{
		alert('Cannot create XMLHTTP instance');
		return false;
	}

	var len = obj.elements.length;

	var post = new Array();


	for (var i = 0; i < len; i++)
	{
		e = obj.elements[i];
		post.push(e.name+"="+e.value);
	}

	params = post.join("&");
	warp_element = output;
	http_request.onreadystatechange = handleExtSearch;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", params.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(params);
}

function handleExtSearch()
{
	if(http_request)
	{
	    if (http_request.readyState == 4)
	    {
	        if (http_request.status == 200)
	        {
	   			gotoUrl(http_request.responseText);
	        }
	        else
	        {
	            alert('Der Inhalt konnte nicht geladen werden.');
	        }
	    }
	}

}

function addToBasket(id)
{
	get(syshost+'Produkte/Warenkorb/'+id+'.htm', 'rcCart');
}

function deleteFromBasket(id)
{
	document.getElementById('count_'+id).value = 0;
	document.forms['rcBasket'].submit();
}

function addBonusToBasket(id)
{
	get(syshost+'Produkte/Bonus/'+id+'.htm', 'rcCart');
}

function addToNotepad(id)
{
	get(syshost+'Produkte/Merkzettel/'+id+'.htm', 'dummy');
}

function directOrder()
{
	//id = prompt("Bitte geben Sie die Artikel- Nr des Produktes ein, das sie bestellen möchten:");
	id = document.getElementById("directOrderInput").value;
	if(id)
	{
		get(syshost+'Produkte/Direktbestellung/'+id+'.htm', 'rcCart');
	}

}

function refresh()
{
	self.location.href = this.location.href;
}

function rate(id)
{
	rating=window.open(syshost + 'Produkte/Bewerten/'+ id +'.htm','rating','directories=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,width=500,height=800,left=200,top=200');
	rating.focus();
}

function recommend(id)
{
	rating=window.open(syshost + 'Produkte/Empfehlen/'+ id +'.htm','recommend','directories=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,width=500,height=800,innerwidth=662,innerheight=473,left=200,top=200');
	rating.focus();
}