var exposecount=0;

var expose = Array();

var joinedexposes;

var ImmoIDs;
var Immobilien;

var el;
var exCont;

var language=1;
var i=0;

var slink = self.location.toString();
var GET = new Object;
for(var i=0;i<=slink.length;i++){
    if(slink[i]=="?"){slink=slink.substring(i+1,(slink.length)); setvari();}
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
            
function setvari(){
    var zwa = Array();
    var uz = Array();
    var x=0, y=0;
                
    for(var i=0;i<=slink.length;i++){
        if(slink[i]=="&"){uz[x]=i; x++;}
    }

    for(i=0;i<=(uz.length-1);i++){
        zwa[i]=slink.substring(y,uz[i]); y=(uz[i]+1);
    }
    zwa[(zwa.length)]=slink.substring((uz[uz.length-1]+1),slink.length);
                    
    for(i=0;i<=(zwa.length-1);i++){
        for(y=0;y<=zwa[i].length;y++){
            if(zwa[i][y]=="="){
                GET[zwa[i].substring(0,y)]=zwa[i].substring(y+1,zwa[i].length);
            }
        }
    }
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function changeValue(id, type){
  var valueContainer;
  valueContainer = document.getElementById('expose'+id);

  el = document.getElementById('lang');
  language = el.innerHTML;
  if(language == ""){
    language = "1";
  }

  if(valueContainer){
    if(type==1){
      if(language==1){
        valueContainer.innerHTML = '<span onclick="exposeButton('+id+');"><img width="8" height="8" src="images/immobilien/exposebutton.jpg"/> Expose abwählen</span></span>';
      }else{
        valueContainer.innerHTML = '<span onclick="exposeButton('+id+');"><img width="8" height="8" src="images/immobilien/exposebutton.jpg"/> deselect fact sheet</span></span>';
      }
    }else{
      if(language==1){
        valueContainer.innerHTML = '<span onclick="exposeButton('+id+');"><img width="8" height="8" src="images/immobilien/exposebutton.jpg"/> Expose auswählen</span></span>';
      }else{
        valueContainer.innerHTML = '<span onclick="exposeButton('+id+');"><img width="8" height="8" src="images/immobilien/exposebutton.jpg"/> select fact sheet</span></span>';
      }
    }
  }
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
  }

  return null;
}

function makeSelections(){
  var Immobilien;
  Immobilien = GetCookie("ImmobilienID");
  ImmoIDs = Immobilien.split(",");
  for (var i = 0; i < ImmoIDs.length; i++) {
    addExpose(ImmoIDs[i]);
  }
}

function removeExpose(id){
  for(var i=0; i<expose.length; i++){
    if(expose[i]=id){
      expose.splice(i,1);
    }
  }
  exposecount--;
  joinedexposes = expose.join(",");
  document.cookie = "ImmobilienID="+joinedexposes;
  var idart = "";
  var idcat = "";
  if(navigator.appName == "Microsoft Internet Explorer"){
    if(gup("idart")){
      idart = "&idart="+gup("idart");
    }
    if(gup("idcat")){
      idcat = "&idcat="+gup("idcat");
    }
  }
  if(navigator.appName != "Microsoft Internet Explorer"){
    if(GET["idart"] != undefined){
      idart = "&idart="+GET["idart"];
    }
    if(GET["idcat"] != undefined){
      idcat = "&idcat="+GET["idcat"];
    }
  }
  URLPARAM = idcat+idart;
  
  el = document.getElementById('lang');
  language = el.innerHTML;
  if(language == ""){
    language = "1";
  }

  var exCont;

  exCont = document.getElementById('exposes');

  if(exposecount == 0){
    container = document.getElementById('exposecontainer');
    container.style.display = "none";
  }

  if(language=="1"){
    if(exposecount < 2){
      exCont.innerHTML = "<a href=\"front_content.php?anfordern=1&exposes="+joinedexposes+URLPARAM+"\">"+exposecount+" gewähltes Expose jetzt anfordern</a>";
    }else{
      exCont.innerHTML = "<a href=\"front_content.php?anfordern=1&exposes="+joinedexposes+URLPARAM+"\">"+exposecount+" gewählte Exposes jetzt anfordern</a>";
    }
  }else{
  // if(language=="2"){
    if(exposecount < 2){
      exCont.innerHTML = "<a href=\"front_content.php?anfordern=1&exposes="+joinedexposes+URLPARAM+"\">Order "+exposecount+" selected fact sheet</a>";
    }else{
      exCont.innerHTML = "<a href=\"front_content.php?anfordern=1&exposes="+joinedexposes+URLPARAM+"\">Order "+exposecount+" selected fact sheets</a>";
    }
  }

  changeValue(id,2);
}

function addExpose(id){
  exposecount++;
  expose.push(id);
  joinedexposes = expose.join(",");
  document.cookie = "ImmobilienID="+joinedexposes;
  var idart = "";
  var idcat = "";
  if(navigator.appName == "Microsoft Internet Explorer"){
    if(gup("idart")){
      idart = "&idart="+gup("idart");
    }
    if(gup("idcat")){
      idcat = "&idcat="+gup("idcat");
    }
  }
  if(navigator.appName != "Microsoft Internet Explorer"){
    if(GET["idart"] != undefined){
      idart = "&idart="+GET["idart"];
    }
    if(GET["idcat"] != undefined){
      idcat = "&idcat="+GET["idcat"];
    }
  }
  URLPARAM = idcat+idart;
  
  el = document.getElementById('lang');
  language = el.innerHTML;
  if(language == ""){
    language = "1";
  }

  var exCont;

  exCont = document.getElementById('exposes');

  if(language=="1"){
    if(exposecount < 2){
      exCont.innerHTML = "<a href=\"front_content.php?anfordern=1&exposes="+joinedexposes+URLPARAM+"\">"+exposecount+" gewähltes Expose jetzt anfordern</a>";
    }else{
      exCont.innerHTML = "<a href=\"front_content.php?anfordern=1&exposes="+joinedexposes+URLPARAM+"\">"+exposecount+" gewählte Exposes jetzt anfordern</a>";
    }
  }else{
  // if(language=="2"){
    if(exposecount < 2){
      exCont.innerHTML = "<a href=\"front_content.php?anfordern=1&exposes="+joinedexposes+URLPARAM+"\">Order "+exposecount+" selected fact sheet</a>";
    }else{
      exCont.innerHTML = "<a href=\"front_content.php?anfordern=1&exposes="+joinedexposes+URLPARAM+"\">Order "+exposecount+" selected fact sheets</a>";
    }
  }

  container = document.getElementById('exposecontainer');
  container.style.display = "";
  changeValue(id,1);
}

function exposeButton(id){
  var removed = 0;
  for(var i=0; i<expose.length; i++){
    if(expose[i]==id){
      removeExpose(id);
      removed = 1;
      // alert("Removed ID: "+id);
    }
  }
  if(removed == 0){
    addExpose(id);
    // alert("Added ID: "+id);
  }
}

function showPrint(id){
  var attribWithoutAll="location=no,menubar=no,toolbar=no,status=no";
  attribWithoutAll+=",resizable=no,scrollbars=no,width=800,height=600";

  subwindow=window.open("","printview",attribWithoutAll);

  titel = document.getElementById('printcontainer0_'+id).innerHTML
  beschreibung = document.getElementById('printcontainer1_'+id).innerHTML
  kaufpreis = document.getElementById('printcontainer2_'+id).innerHTML
  ort = document.getElementById('printcontainer3_'+id).innerHTML
  expnr = document.getElementById('printcontainer16_'+id).innerHTML

  subimage1 = document.getElementById('imagecontainer4_'+id).innerHTML
  subimage2 = document.getElementById('imagecontainer8_'+id).innerHTML
  subimage3 = document.getElementById('imagecontainer9_'+id).innerHTML
  subimage4 = document.getElementById('imagecontainer10_'+id).innerHTML

  var image1 = "", image2 = "", image3 = "", image4 = "";

  if(subimage1 != "") image1 = "<img src=\"images/immobilien/"+subimage1+"\" style=\"max-height: 270px; max-width:360px;\" />";
  if(subimage2 != "") image2 = "<img src=\"images/immobilien/"+subimage2+"\" style=\"max-height: 270px; max-width:360px;\" />";
  if(subimage3 != "") image3 = "<img src=\"images/immobilien/"+subimage3+"\" style=\"max-height: 270px; max-width:360px;\" />";
  if(subimage4 != "") image4 = "<img src=\"images/immobilien/"+subimage4+"\" style=\"max-height: 270px; max-width:360px;\" />";

  subwindow.document.open();
  subwindow.document.write("<html><head>");
  subwindow.document.write("<style type=\"text/css\">body{margin: 0; font-family: Verdana, Sans-Serif, Arial; font-size: 12px; color: #666;}</style>");
  subwindow.document.write("</head><body>");
  subwindow.document.write("<img src=\"images/immobilien/printhead.jpg\" /><br />");
  subwindow.document.write("<div style=\"margin-left: 40px;\">");
  subwindow.document.write("<span style=\"font-size:16px; font-family: Verdana, Sans-Serif, Arial; color: #666; font-weight: bold;\">"+titel+"</span><br /><br />");
  subwindow.document.write("<span style=\"font-size:12px; font-family: Verdana, Sans-Serif, Arial; color: #666\">"+beschreibung+"</span><br /><br />");
  subwindow.document.write("<span style=\"font-size:12px; font-family: Verdana, Sans-Serif, Arial; color: #666; font-weight: bold;\">Ort:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ort+"</i><br /><br /><br />");
  subwindow.document.write("<span style=\"font-size:12px; font-family: Verdana, Sans-Serif, Arial; color: #666; font-weight: bold;\">Exp.Nr:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+expnr+"</i><br /><br /><br />");
  subwindow.document.write("<span style=\"font-size:12px; font-family: Verdana, Sans-Serif, Arial; color: #666; font-weight: bold;\">Kaufpreis:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;€ "+kaufpreis+"<br /><br /><br />");
  subwindow.document.write("  <table border=\"0\">");
  subwindow.document.write("    <tr> <td>"+image1+"</td> <td>"+image2+"</td> </tr>");
  subwindow.document.write("    <tr> <td>"+image3+"</td> <td>"+image4+"</td> </tr>");
  subwindow.document.write("  </table>");
  subwindow.document.write("</div>");
  subwindow.document.write("</body>");
  subwindow.document.write("</html>");
  subwindow.document.close();

  subwindow.print();
}

function showPrintPrivate(id){
  var attribWithoutAll="location=no,menubar=no,toolbar=no,status=no";
  attribWithoutAll+=",resizable=no,scrollbars=no,width=800,height=600";

  titel = document.getElementById('printcontainer0_'+id).innerHTML
  beschreibung = document.getElementById('printcontainer1_'+id).innerHTML
  kaufpreis = document.getElementById('printcontainer2_'+id).innerHTML
  ort = document.getElementById('printcontainer3_'+id).innerHTML
  rendite = document.getElementById('printcontainer5_'+id).innerHTML
  faktor = document.getElementById('printcontainer6_'+id).innerHTML
  me = document.getElementById('printcontainer13_'+id).innerHTML
  expnr = document.getElementById('printcontainer16_'+id).innerHTML

  subwindow=window.open("","printview",attribWithoutAll);

  subwindow.document.open();
  subwindow.document.write("<html><head>");
  subwindow.document.write("<style type=\"text/css\">body{margin: 0; font-family: Verdana, Sans-Serif, Arial; font-size: 12px; color: #666;}</style>");
  subwindow.document.write("</head><body>");
  subwindow.document.write("<img src=\"images/immobilien/printhead.jpg\" /><br />");
  subwindow.document.write("<div style=\"margin-left: 40px;\">");
  subwindow.document.write("<span style=\"font-size:16px; font-family: Verdana, Sans-Serif, Arial; color: #666; font-weight: bold;\">"+titel+"</span><br /><br />");
  subwindow.document.write("<span style=\"font-size:12px; font-family: Verdana, Sans-Serif, Arial; color: #666\">"+beschreibung+"</span><br /><br />");
  // subwindow.document.write("<span style=\"font-size:12px; font-family: Verdana, Sans-Serif, Arial; color: #666; font-weight: bold;\">Ort:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ort+"</i><br /><br /><br />");

  subwindow.document.write("<span style=\"font-size:12px; font-family: Verdana, Sans-Serif, Arial; color: #666; font-weight: bold;\">Kaufpreis:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;€ "+kaufpreis+" Mio.<br /><br /><br />");
  subwindow.document.write("<span style=\"font-size:12px; font-family: Verdana, Sans-Serif, Arial; color: #666; font-weight: bold;\">ME p.a.:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;€ "+me+"<br /><br /><br />");
  subwindow.document.write("<span style=\"font-size:12px; font-family: Verdana, Sans-Serif, Arial; color: #666; font-weight: bold;\">Rendite:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+rendite+"<br /><br /><br />");
  subwindow.document.write("<span style=\"font-size:12px; font-family: Verdana, Sans-Serif, Arial; color: #666; font-weight: bold;\">Faktor:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+faktor+"<br /><br /><br />");
  subwindow.document.write("<span style=\"font-size:12px; font-family: Verdana, Sans-Serif, Arial; color: #666; font-weight: bold;\">Exp.Nr:</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+expnr+"</i><br /><br /><br />");
  subwindow.document.write("</div>");
  subwindow.document.write("</body>");
  subwindow.document.write("</html>");
  subwindow.document.close();

  subwindow.print();
}

function openImages(id){

  var attribWithoutAll="location=no,menubar=no,toolbar=no,status=no";
  attribWithoutAll+=",resizable=yes,scrollbars=yes,width=800,height=600";

  subwindow=window.open("","gallery",attribWithoutAll);

  subimage1 = document.getElementById('imagecontainer4_'+id).innerHTML
  subimage2 = document.getElementById('imagecontainer8_'+id).innerHTML
  subimage3 = document.getElementById('imagecontainer9_'+id).innerHTML
  subimage4 = document.getElementById('imagecontainer10_'+id).innerHTML

  image1 = "";
  image2 = "";
  image3 = "";
  image4 = "";

  firstimage = "<img id=\"greatImage\" width=800 height=600 style=\"max-width: 800px; max-height: 600px;\" src=\"images/immobilien/"+subimage1+"\" />";
  if(subimage1 != "") image1 = "<img onclick=\"greatImage.src=this.src\" src=\"images/immobilien/"+subimage1+"\" height=\"150\" width=\"200\" />";
  if(subimage2 != "") image2 = "<img onclick=\"greatImage.src=this.src\" src=\"images/immobilien/"+subimage2+"\" height=\"150\" width=\"200\" />";
  if(subimage3 != "") image3 = "<img onclick=\"greatImage.src=this.src\" src=\"images/immobilien/"+subimage3+"\" height=\"150\" width=\"200\" />";
  if(subimage4 != "") image4 = "<img onclick=\"greatImage.src=this.src\" src=\"images/immobilien/"+subimage4+"\" height=\"150\" width=\"200\" />";

  subwindow.document.open();
  subwindow.document.write("<html><head>");
  subwindow.document.write("</head><body>");
  subwindow.document.write(firstimage);
  //subwindow.document.write("<table>");
  //subwindow.document.write("  <tr>");
  //subwindow.document.write("     <td rowspan=4 width=\"600\" height=\"600\" align=\"center\" id=\"innerContent\" style=\"overflow: auto;\">"+firstimage+"</td>");
  //subwindow.document.write("     <td height=\"150\" width=\"200\" id=\"img1\">"+image1+"</td>");
  //subwindow.document.write("  </tr>");
  //subwindow.document.write("  <tr>");
  //subwindow.document.write("     <td height=\"150\" width=\"200\" id=\"img2\">"+image2+"</td>");
  //subwindow.document.write("  </tr>");
  //subwindow.document.write("  <tr>");
  //subwindow.document.write("     <td height=\"150\" width=\"200\" id=\"img3\">"+image3+"</td>");
  //subwindow.document.write("  </tr>");
  //subwindow.document.write("  <tr>");
  //subwindow.document.write("     <td height=\"150\" width=\"200\" id=\"img4\">"+image4+"</td>");
  //subwindow.document.write("  </tr>");
  //subwindow.document.write("</table>");
  subwindow.document.write("</body>");
  subwindow.document.write("</html>");
  subwindow.document.close();

}

