// devel
//var shopBase = 'http://schmetterlingshop/shop/';

// ext test
//var shopBase = 'http://schmetterlingshop.test.orwonet.de/shop/';

// produktiv
var shopBase = 'http://shop.schmetterling.pixelnet.de/shop/';

    var partneridName='partnerId';
    var partneridValue='';

    function Werteliste (querystring) {
     if (querystring == '') return;
     var wertestring = querystring.slice(1);
     var paare = wertestring.split("&");
     var paar, name, wert;
     for (var i = 0; i < paare.length; i++) {
       paar = paare[i].split("=");
       name = paar[0];
       wert = paar[1];
       name = unescape(name).replace("+", " ");
       wert = unescape(wert).replace("+", " ");
       this[name] = wert;
     }
    }

    var liste = new Werteliste(location.search);

    if(partneridValue==''){
      if(liste.partnerId){
         partneridValue=liste.partnerId;
      }
    }
    //alert('partnerId='+partneridValue+'\nid='+liste.id);
    
    function trySetPartnerId(){
      if(partneridValue!=''){
        setPartnerId();
      }
    }
    
    function setPartnerId(){
//     var liste = new Werteliste(location.search);
    // 1. alle links behandeln, die keine javascript befehle im href enthalten
     var linkLaenge = document.getElementsByTagName('a').length;
     for(var i = 0;i<linkLaenge;i++){
       var tmp = document.getElementsByTagName('a')[i];
       var res =tmp.href.search(/javascript.+/);
       if (res==-1){
          var linkObject=document.getElementsByTagName('a')[i];
          var newPartnerid = build_partnerid_from_string(linkObject.href);
          if(newPartnerid!=''){
            linkObject.href+=newPartnerid;
          }
       	}
  	 }
   }
   function build_partnerid_from_string(string){
    var newPartnerid = '';
    var connector = '&';
    if(string.search(/\?/)==-1){
       connector = '?';
    }
    if(string.search(/partnerId=/)==-1){
       newPartnerid=connector + partneridName+'='+partneridValue;
    }
    return newPartnerid;
   }

  function set_partnerid_and_change_location(string){
    var new_href = string+build_partnerid_from_string(string);
//    alert('setting href to: '+new_href);
    location.href = new_href; 
  }

function new_setUrlIFrame() {

  var url = window.location.href;

  // id wird geholt aus Werteliste, siehe oben
  var id = liste.id;

  var pid = partneridName+'='+partneridValue;
  //alert('partnerid ready:'+pid);
  
  if (id == "preisliste") { 
    var servlet='viewPriceList.do?style=screen&';
    document.getElementById("iframe_shop").src = shopBase+servlet+pid;
    //alert(document.getElementById("iframe_shop").src);
	}
  else if (id == "login") { 
    var servlet='viewLoginForm.do?';
    document.getElementById("iframe_shop").src = shopBase+servlet+pid;
    //alert(document.getElementById("iframe_shop").src);
	}  
  else if (id == "onlineorder") { 
    var servlet='viewUploadForm.do?';
    document.getElementById("iframe_shop").src = shopBase+servlet+'orderingType=imageordering&'+pid;
    //alert(document.getElementById("iframe_shop").src);
	}  
 else if (id == "uploadcal") { 
    var servlet='viewUploadForm.do?';
    document.getElementById("iframe_shop").src = shopBase+servlet+'orderingType=calendarordering&'+pid;
   //alert(document.getElementById("iframe_shop").src);
	}
	else if (id == "uploadactivex") { 
    var servlet='viewUploadForm.do?type=activex&';
    document.getElementById("iframe_shop").src = shopBase+servlet+pid;
    //alert(document.getElementById("iframe_shop").src);
	}	
}

//Unterscheidung zwischen Test und Prod - Umgebung
//Prod - http://backoffice.orwonet.de/cgi-bin/SchmetterlingInstaller.pl?partnerId=
//Test - http://webdev.orwonet.de/cgi-bin/SchmetterlingInstaller.pl?partnerId=
 
  function SetDownloadUrl() {
   
  var url = window.location.href;
 // alert(url);
  
  if (url.indexOf('typodev') > 0 ) {
  //if (partneridValue != '') {
//     window.location.href="http://webdev.orwonet.de/cgi-bin/SchmetterlingInstaller.pl?partnerId="+partneridValue;  
     document.getElementById('download_link').href="http://webdev.orwonet.de/cgi-bin/SchmetterlingInstaller.pl?partnerId="+partneridValue;
     document.getElementById('manual_download_link').href="http://webdev.orwonet.de/cgi-bin/SchmetterlingInstaller.pl?partnerId="+partneridValue;
     document.getElementById('download_explain').style.display='block';
  }    
  else {
     document.getElementById('download_link').href="http://backoffice.orwonet.de/cgi-bin/SchmetterlingInstaller.pl?partnerId="+partneridValue;
     document.getElementById('manual_download_link').href="http://backoffice.orwonet.de/cgi-bin/SchmetterlingInstaller.pl?partnerId="+partneridValue;
     document.getElementById('download_explain').style.display='block';        
  }
  
   //else alert('Fehler beim Weitergeben der PartnerId!');  
     return true;
    }
    
  
