function selectRezept(id, rezeptname) {
  var imgarray = dojo.query('#rezept img.img');
  //var selectarray = $$('#rezeptS option');
  for (i=0;i<imgarray.length;i=i+1) {
    imgarray[i].className="img";
    //if(selectarray[i].value == id) {
    //  selectarray[i].selected="selected";
    //}
  }                
  document.getElementById('i'+id).className='img brd';
  document.getElementById('rezeptS').value= id;
  document.getElementById('rezeptName').innerHTML=rezeptname;
}

var st1;
var st2;
var thetop=-1;
var flagdivvisible=0;
var oMyDiv;
var boxMyDiv;

var st1ID;
var st2ID;
var thetopID=-1;
var flagdivvisibleID=0;

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);
   dojo.xhrGet({
	url: url,
	load: function(response, ioArgs) {
		writeContentDoc(response,DocTargetId);		
	},
	handleAs: 'text'
   });
}

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(dojo.byId('divbasketpopup').style.left.indexOf('px')>=0){
    suffix="px";
  }

  var vp = dijit.getViewport();
  var xPosition = vp.w/2 - 140 + vp.l;
  var yPosition = vp.h/2 - 74 + vp.t;


  dojo.byId('divbasketpopup').style.left=Math.floor((screen.availWidth-280)/2)+suffix;
  //dojo.byId('divbasketpopup').style.left=273+suffix;
  dojo.byId('divbasketpopup').style.top=Math.floor(screen.availHeight/2-148)+getop()+suffix;
  thetop=getop();

  dojo.marginBox(dojo.byId('divbasketpopup'), {l:xPosition , t:yPosition });
}

function appendProductURL(formular){
  var urlstr = "";
  var productParams = new Array('ChangeObjectID','ProductID','Quantity','RecipeID');
  for(var i=0;i<productParams.length;i++){
    urlstr += "&"+productParams[i]+"="+eval("formular."+productParams[i]+".value");  
  }
  return urlstr;
}

function divpopup(url,formular){
  closedivpopupID();
  if(dojo.byId('rezeptS').value=='0') {
	rezeptpopup();
  } else { 
	if(dojo.byId('Quantity').value =='') dojo.byId('Quantity').value=1;
	url+=appendProductURL(formular);
	writeContent(url,'divbasketpopup','writeContentDoc');  
	if(st1){clearTimeout(st1)};
	centerDiv();
	dojo.byId('divbasketpopup').style.visibility='visible';
	flagdivvisible=1;
	st1=setTimeout("flagdivvisible=0;dojo.byId('divbasketpopup').style.visibility='hidden'",7000);
	refreshlocation();
  }  
}

function closedivpopup(){
  dojo.byId('divbasketpopup').style.visibility='hidden';
  flagdivvisible=0;    
}

function rezeptpopup() {  
  centerDivID();
  dojo.byId('divrezeptpopup').style.visibility='visible';
  flagdivvisibleID=1;
  st1=setTimeout("flagdivvisibleID=0;dojo.byId('divrezeptpopup').style.visibility='hidden'",7000);
  refreshlocationID();

  var vp = dijit.getViewport();
  var xPosition = vp.w/2 - 140 + vp.l;
  var yPosition = vp.h/2 - 74 + vp.t;

  dojo.marginBox(dojo.byId('divrezeptpopup'), {l:xPosition , t:yPosition });
}

function refreshlocationID(){
    if(flagdivvisibleID && thetopID!=getop()){
      centerDivID('divrezeptpopup');
    }
    if(!flagdivvisibleID) {
      if(st2ID) clearTimeout(st2ID);
      return;
    }
    st2ID=setTimeout("refreshlocationID()",10);
}

function centerDivID(){
  var suffix="";
  if(dojo.byId('divrezeptpopup').style.left.indexOf('px')>=0){
    suffix="px";
  }
  dojo.byId('divrezeptpopup').style.left=Math.floor((screen.availWidth-280)/2)+suffix;
  dojo.byId('divrezeptpopup').style.top=Math.floor(screen.availHeight/2-58)+getop()+suffix;
  thetopID=getop();
}

function closedivpopupID(){
  dojo.byId('divrezeptpopup').style.visibility='hidden';
  flagdivvisibleID=0;    
}


