function setCookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}
	
function FIND(item) {
  if (document.all) return(document.all[item]);
  if (document.getElementById) return(document.getElementById(item));
  return(false);
}

var st1;
var st2;
var thetop=-1;
var flagdivvisible=0;
var oMyDiv;
var boxMyDiv;

function formatPrice(value){
  var num = new NumberFormat(value);
  num.setSeparators(true,'.',',');
  return num.toFormatted()+' '+('&euro;');
}

function writeContentDoc(Doc, TargetId) {
   if(!oMyDiv) oMyDiv=document.createElement("div");
   oMyDiv.innerHTML=Doc;
   var oInsertTarget=document.getElementById(TargetId);
   oInsertTarget.innerHTML=oMyDiv.innerHTML;
}

function writeContentBox(Doc, TargetId) {
   if(!boxMyDiv) boxMyDiv=document.createElement("div");
   boxMyDiv.innerHTML=Doc;
   var oInsertTarget=document.getElementById(TargetId);
   oInsertTarget.innerHTML=boxMyDiv.innerHTML;
}

function writeContent(url, DocTargetId, writeFunc) {
    makeHttpRequest("GET",WebServerScriptUrlSSL+url+'&rand='+Math.floor(Math.random()*1000000),'', false, writeFunc, DocTargetId);
}

function getop(){
  if (navigator.appName == "Netscape") {
    return window.pageYOffset;
  }
  else {
    return (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;
  }
}

function refreshlocation(){
    if(flagdivvisible && thetop!=getop()){
      centerDiv();
    }
    if(!flagdivvisible) {
      if(st2) clearTimeout(st2);
      return;
    }
    st2=setTimeout("refreshlocation()",10);
}

function centerDiv(){
  var suffix="";
  if(FIND('divbasketpopup').style.left.indexOf('px')>=0){
    suffix="px";
  }
  FIND('divbasketpopup').style.left=Math.floor((screen.availWidth-280)/2)+suffix;
  FIND('divbasketpopup').style.top=Math.floor(screen.availHeight/2-148)+getop()+suffix;
  thetop=getop();
}

function appendProductURL(formular){
  var urlstr = "";
  var productParams = new Array('ChangeObjectID','ProductID','Quantity');
  for(var i=0;i<productParams.length;i++){
    urlstr += "&"+productParams[i]+"="+eval("formular."+productParams[i]+".value");  
  }
  return urlstr;
}

function divpopup(url,formular){
  url+=appendProductURL(formular);
  writeContent(url,'divbasketpopup','writeContentDoc');  
  if(st1){clearTimeout(st1)};
  centerDiv();
  FIND('divbasketpopup').style.visibility='visible';
  flagdivvisible=1;
  st1=setTimeout("flagdivvisible=0;FIND('divbasketpopup').style.visibility='hidden'",7000);
  refreshlocation();
}

function closedivpopup(){
  FIND('divbasketpopup').style.visibility='hidden';
  flagdivvisible=0;    
}

function getOffset(what, offsettype) {
    var totaloffset = (offsettype == 'left') ? what.offsetLeft : what.offsetTop;
    var parentEl = what.offsetParent;
    while(parentEl != null) {
        totaloffset = (offsettype == 'left') ? totaloffset + parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl = parentEl.offsetParent;
    }
    return totaloffset;    
}

//slide teaser functions
function toLeft(SlideNo) {
  tpos-=1;
  cpos-=545;
  
  myFx.scrollTo(cpos, 0); 
  if(cpos > 545) $('to-left').style.display='block'; 
  if(cpos == 0) $('to-left').style.display='none';
  if(cpos < 545 * (SlideNo -1)) $('to-right').style.display='block';
  
  hideInfo(tpos);
}
function toRight(SlideNo) {
  tpos+=1;
  cpos+=545;
  
  myFx.scrollTo(cpos, 0);
  $('to-left').style.display='block';
  if(cpos == 545 * (SlideNo -1)) $('to-right').style.display='none';
  
  hideInfo(tpos);
}
function hideInfo(tpos) {
  //var div = $('i'+tpos).setStyles({
	//	display:'block',
	//	opacity: 0
	//});
	//new Fx.Style(div, 'opacity', {duration: 1000} ).start(1);

  $('i'+tpos).style.display='block';
  if($('i'+(tpos-1))) $('i'+(tpos-1)).style.display='none';
  if($('i'+(tpos+1)))$('i'+(tpos+1)).style.display='none';
}


