var modelIDs = new Array();
var models = new Object();
var sizes = new Array();
var modelImages = new Object();
var current_modelID = 0;
var current_size = '';

function showModel(modelID){
  // Aktuellen Button normalisieren
  var el = document.getElementById("model_" + current_modelID);
  if(el) el.className = 'normalmodellink'

  // Neuen Button hervorheben
  var el = document.getElementById("model_" + modelID);
  if(el) el.className = 'selectedmodellink';

  current_modelID = modelID;

  // Suche Beschreibung
  var model = models['model' + modelID];
  if(model){
    // Beschreibung setzen
    var el = document.getElementById("modeldescription");
    if(el){
      el.innerHTML = model['modelDescription'];
    }
  }

  activateImage()
}

function showSize(size){
  // Aktuellen Button normalisieren
  var el = document.getElementById("size_" + current_size);
  if(el) el.className = 'normalsizelink'

  // Neuen Button hervorheben
  var el = document.getElementById("size_" + size);
  if(el) el.className = 'selectedsizelink';

  current_size = size;

  activateImage()
}

function registerModel(modelID, modelName, modelDescription){
  var model = new Object();
  model['modelID'] = modelID;
  model['modelName'] = modelName;
  model['modelDescription'] = modelDescription;
  models['model' + modelID] = model;
  modelIDs.push(modelID);
}

function registerSize(size){
  sizes.push(size);
}

function activateImage(){
  var s = current_modelID + '_' + current_size;
	var s2 = '';
  var id = modelImages[s];

  if(id){
    s = '/getjpgimage.php?type=modelphotosmall&id=' + id;
    s2 = '/getjpgimage.php?type=modelphotobig&id=' + id;
  }
  else{
    s = '/productinfo/NoImage.PNG';
    s2 = s;
  }

  var el = document.getElementById("modelimage");
  if(el) el.src = s;
  var el = document.getElementById("zoomimagelink");
  if(el) el.href = s2;

}

function registerModelImage(modelID, size, imageID){
  var s = modelID + '_' + size;
  modelImages[s] = imageID;
}

function hideProduct(){
  var el = document.getElementById("productinfocontent");
  if(el) el.innerHTML = "";
}


function showProduct(prod){

	var xmlHttp = null;
  // Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
  if (typeof XMLHttpRequest != 'undefined') {
      xmlHttp = new XMLHttpRequest();
  }
  if (!xmlHttp) {
      // Internet Explorer 6 und älter
      try {
          xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) {
          try {
              xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e) {
              xmlHttp  = null;
          }
      }
  }
  if (xmlHttp) {
      xmlHttp.open('GET', '/productinfo/getproductinfo.php?id=' + prod, true);
      xmlHttp.onreadystatechange = function () {
          if (xmlHttp.readyState == 4) {
             setProductInfoContent(xmlHttp.responseText);
          }
      };
      xmlHttp.send(null);
  }
}

function clearObjects(){
  modelIDs = new Array();
  models = new Object();
  sizes = new Array();
  modelImages = new Object();
}


function registerReceivedProductInfo(){
  var el = document.getElementById("registerproductinfo");
  if(el){
    eval(el.value);
  }
}

function setProductInfoContent(s){
  var el = document.getElementById("productinfocontent");
  if(el) el.innerHTML = s;
  clearObjects();
  registerReceivedProductInfo();
  initProductInfo();
}

function initProductInfo(){
  // Model aktivieren
	var model = current_modelID;
  if(!models['model' + model]){
    model = modelIDs[0];
  }
  showModel(model);

  // Größe aktivieren
	var size = current_size;
  var el = document.getElementById("size_" + size);
  if(!el){
   size = sizes[0];
  }
  showSize(size);

}

function showproductinfopopup(id){
  var url="/productinfo/getproductinfofull.php?id=" + id;
	win = window.open(url, "shirtfriendsproductinfo", "width=900,height=400,dependent=yes,location=no,menubar=no,status=no,toolbar=no,resizable=yes,scrollbars=yes");
  win.focus();
}

function gotoproductinfoanchor(){
  window.location.hash = '#';
  window.location.hash = '#productinfoanchor';
}