﻿var lightboxcloselink;

function SetModal() {
    //Wenn das Layer bereits vorhanden ist, dann nicht erneut anzeigen.
    if (document.getElementById('divModal'))
        return;
    
    var modal = document.createElement('div');
    modal.setAttribute('id', 'divModal');
    modal.setAttribute('class', 'modal');
    modal.innerHTML = '&nbsp;';
    document.body.appendChild(modal);

    //IE 8 hat ein schwarzes Flackern, wenn es direkt per CSS gesetzt wird.
    setTimeout("document.getElementById('divModal').style.backgroundColor = '#000000';", 100);
}

function RemoveModal() {
    if (document.getElementById('divModal'))
        document.body.removeChild(document.getElementById('divModal'));
}

function collapsePanelBar(panelBarID, panelItemValue) {
    var panelBar = $find(panelBarID);
    var item = panelBar._findItemByValue(panelItemValue);

    if (item) {
        item.collapse();
    }
}
function xmlRequest(url, myMethod, postdata, parameter) {

    if (!myMethod) myMethod = 'GET';
    if (!parameter) parameter = '';

    if (postdata == undefined) postdata = null;

    xmlhttpReturnParam = parameter;

    //Objekt initiieren
    try {
        xmlhttp = new XMLHttpRequest();
    } catch (error) {
        try {
            xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
        } catch (error) {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    //Handler setzen, damit der downloadstatus überwacht wird
    xmlhttp.onreadystatechange = handleHttpState;

    //Anfrage starten
    // 	alert(myMethod + postdata);
    xmlhttp.open(myMethod, url);
    if (myMethod == "POST") {
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
    }
    xmlhttp.send(postdata);
}

function handleHttpState() {
    if (xmlhttp.readyState == 4) {
        if (xmlhttp.status == 200) {
           
        }
    }
}


var addresses = new Array();

//Springt zu der angegbenen addresse
function setAddress(func_street , func_postal, func_city, func_country, func_alternativePostal, func_zoom) {
    geocoder = new GClientGeocoder();

    if(func_zoom == 0) {
        func_zoom = 13;
    }

    var address = "";

    if (func_street != "") {
        address += func_street + ", ";
    }

    if (func_postal != "") {
        address += func_postal + ", ";
    }

    if (func_city != "") {
        address += func_city + ", ";
    }

    if (func_country != "") {
        address += func_country;
    }

    geocoder.getLocations(address,
        function(response) {
            if (response != null) {
                if (response.Status.code == 602 || response.Status.code == 500)
                     return;

                var place = response.Placemark[0];
                var lat = place.Point.coordinates[1];
                var longi = place.Point.coordinates[0];
                var point = new GLatLng(lat, longi);
                var country = place.AddressDetails.CountryNameCode;

                //Wenn keine alternative angegeben ist machen wir nichts
                if (func_alternativePostal.toString().length == 0) {
                    map.setCenter(point, func_zoom);
                } else {
                    //Ist eine Alternative angegeben prüfen wir das Land
                    //Stimmt das land überein springen wir an den Punkt
                    if (country == func_country.toString().toUpperCase()) {
                        map.setCenter(point, func_zoom);
                    } else {
                        //Stimmt das land nicht, gehen wir zur alternative
                    setAddress('', func_alternativePostal, '', func_country, '', 6);
                    }
                }
            }
        }
    );
}

//Springt zu der angegbenen addresse
function getCoordinates(func_street, func_postal, func_city, func_country) {
    geocoder = new GClientGeocoder();

    var address = "";

    if (func_street != "") {
        address += func_street + ", ";
    }

    if (func_postal != "") {
        address += func_postal + ", ";
    }

    if (func_city != "") {
        address += func_city + ", ";
    }

    if (func_country != "") {
        address += func_country;
    }

    var data = new Array();
    data["street"] = func_street;
    data["postal"] = func_postal;
    data["city"] = func_city;
    data["country"] = func_country;

    addresses[address] = data;

    geocoder.getLocations(
        address,
        function(response) {

            if (response != null) {
                if (response.Status.code == 602 || response.Status.code == 500)
                    return;

                var place = response.Placemark[0];
                var lat = place.Point.coordinates[1];
                var longi = place.Point.coordinates[0];
                var point = new GLatLng(lat, longi)
                var accuracy = place.AddressDetails.Accuracy;
                var func_street = addresses[address]["street"];
                var func_postal = addresses[address]["postal"];
                var func_city = addresses[address]["city"];
                var country = place.AddressDetails.Country.CountryNameCode;

                xmlRequest("/Handler/GeoHandler.ashx?lat=" + encodeURIComponent(lat) + "&long=" + encodeURIComponent(longi) + "&street=" + encodeURIComponent(func_street) + "&postal=" + encodeURIComponent(func_postal) + "&city=" + encodeURIComponent(func_city) + "&country=" + encodeURIComponent(country) + "&accuracy=" + encodeURIComponent(accuracy), null, null, null);
            }
        }
    );
}

//Springt zu den angegebenen Coordinaten
function moveToCoords(lati, longi) {
    //Neuen GPoint erstellen
    var point = new GLatLng(lati, longi);

    map.setCenter(point, 13);
}

//Springt zum angegebenen land
function setCountry(country) {
    geocoder = new GClientGeocoder();

    geocoder.getLocations(country,
        function(response) {

    if (response != null) {
                if (response.Status.code == 602 || response.Status.code == 500)
                    return;
            
                var place = response.Placemark[0];
                var point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0])

                map.setCenter(point, 5);
            }
        }
    );
    }

    function addCoordinateToMap(lati, longi, html, number) {
        var point = new GLatLng(lati, longi);
        var icon = new GIcon(G_DEFAULT_ICON);

        icon.iconSize = new GSize(30, 54);
        icon.shadowSize = new GSize(55, 54);
        //alert(icon.iconAnchor);
        icon.iconAnchor = new GPoint(15, 54);

        icon.image = "http://" + window.location.host + "/Handler/IGFileHandler.ashx?file=" + number + "&t=5";
        //alert(icon.image);
        
        var marker = new GMarker(point, { icon: icon });

        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindow(html);
            var point = marker.getLatLng();
        }
        );

        map.addOverlay(marker);
    }

    function panToCoords(lati, longi) {

        if ((lati == undefined || lati == "" || lati == 0) && (longi == undefined || longi == "" || longi == 0))
            return;
    
        var point = new GLatLng(lati, longi);

        map.panTo(point);
    }


    var toolTipImg;
    var toolTipData;

    function WaitLoadTip(url, ag, artist, title, number, size, copyr) {
        toolTipImg = new Image();
        toolTipImg.src = url;
             
        toolTipData = new Object();
        toolTipData['ag'] = ag;
        toolTipData['artist'] = artist;
        toolTipData['title'] = title;
        toolTipData['number'] = number;
        toolTipData['size'] = size;
        toolTipData['copyr'] = copyr;

        //alert(toolTipImg.width);

        ShowTip();
        
        
        //alert('1' + img.complete);

        //img.onload = function() { alert(img.complete); Tip('<img src=&quot;' + img.url + '&quot; />', BORDERCOLOR, '#000000'); };
        //img.onerror = function() { alert('error'); };
        //alert(img.complete); Tip('<img src=\"" + largeImage + "\" />', BORDERCOLOR, '#000000');
    }

    function WaitUnTip() {
        toolTipImg = null;
        UnTip();
    }

    function ShowTip() {
        if (toolTipImg == null)
            return;
            
            //alert(toolTipImg.complete);         
        if (toolTipImg.complete) {
            
        
            var html = '<div style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#545353; font-weight:normal;">';
            
            html += '<img src="' + toolTipImg.src + '" />';
            html += '<div style="margin: 5px;">';
                    
            if (toolTipData['ag'])
                html += '<span class="">' + toolTipData['ag'] + '</span><br />';
                      
            if (toolTipData['title'])
                html += '<span class="italic">' + toolTipData['title'] + '</span><br />';
           
            if (toolTipData['artist'])
                html += '<span class="">' + toolTipData['artist'] + '</span><br />';
                
            if (toolTipData['number'])
                html += '<br /><span class="bold">' + toolTipData['number'] + '</span><br />';
                
            if (toolTipData['size'])
                html += '<span class="">' + toolTipData['size'] + '</span><br />';
        
            if (toolTipData['copyr'])
                html += '<div class="" style="padding-top: 20px;">' + toolTipData['copyr'] + '</div>';
        
        
            html += '</div></div>';
        
            Tip(html, BORDERCOLOR, '#000000', WIDTH, toolTipImg.width);
        }
        else {
            window.setTimeout("ShowTip();", 250);
        }
    }

    function __rinit() {
        // für den IE
        if (document.attachEvent) document.attachEvent("onselectstart", function() { return false; });

        document.onkeyup =
	function() {
	    if (window.getSelection) {
	        var sel = window.getSelection();
	        sel.removeAllRanges();
	    }
	};

        document.onkeydown =
	function() {
	    if (window.getSelection) {
	        var sel = window.getSelection();
	        sel.removeAllRanges();
	    }
	};

        document.onmousemove =
	function() {
	    if (window.getSelection) {
	        var sel = window.getSelection();
	        sel.removeAllRanges();
	    }
	};
}


function writeToLayer(id, content) {
    if (document.getElementById) {
        document.getElementById(id).innerHTML = content;
    } else if (document.layers) {
        document.layers[id].document.write(content);
    } else if (document.all) {
        document.all[id].innerHTML = content;
    }
}

function addTracking(type, productNumber) {
    var pl = new SOAPClientParameters();
    pl.add("type", type);
    pl.add("productNumber", productNumber);
    
    
    var result = SOAPClient.invoke("/Services/DeDeProcureService.asmx", "CreateNewTrackingObject", pl, false);




    return result;
}

function openwindow(url, w, h, title, scrollbars, resizable) {
    openw = window.open(url, title, "toolbar=no,directories=no,menubar=no,location=no,status=yes,resizable=" + resizable + ",scrollbars=" + scrollbars + ",width=" + w + ",height=" + h);

    if (openw != null) {
        if (openw.opener == null) {
            openw.opener = self;
        }
    }

    //Fenster zentrieren
    posX = (screen.availWidth / 2) - w / 2;
    posY = (screen.availHeight / 2) - h / 2;
    openw.moveTo(posX, posY);

    return false;
}

    /**
     * Add a circle to the global variable "map". This function won't work for circles that encompass
     * the North or South Pole. Also, there is a slight distortion in the upper-left, upper-right,
     * lower-left, and lower-right sections of the circle that worsens as it gets larger and/or closer
     * to a pole.
     * @param lat Latitude in degrees
     * @param lng Longitude in degrees
     * @param radius Radius of the circle in statute miles
     * @param {String} strokeColor Color of the circle outline in HTML hex style, e.g. "#FF0000"
     * @param strokeWidth Width of the circle outline in pixels
     * @param strokeOpacity Opacity of the circle outline between 0.0 and 1.0
     * @param {String} fillColor Color of the inside of the circle in HTML hex style, e.g. "#FF0000"
     * @param fillOpacity Opacity of the inside of the circle between 0.0 and 1.0
     */
function drawCircle(lat, lng, radius, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity) {
      radius = radius * 0.62137119;
      var d2r = Math.PI/180;
      var r2d = 180/Math.PI;
      var Clat = radius * 0.014483;  // Convert statute miles into degrees latitude
      var Clng = Clat/Math.cos(lat*d2r); 
      var Cpoints = []; 
      for (var i=0; i < 33; i++) { 
        var theta = Math.PI * (i/16);
        Cy = lat + (Clat * Math.sin(theta));
        Cx = lng + (Clng * Math.cos(theta));
        var P = new GLatLng(Cy, Cx);
        Cpoints.push(P);
      }
      var polygon = new GPolygon(Cpoints, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity);
      //alert(polygon);
      map.addOverlay(polygon);
  }

  function CheckIsEu(countryCode) {
      /*
      * Da der Webservice zulange braucht prüfen wir es direkt
      *
      var pl = new SOAPClientParameters();
      pl.add("countryCode", countryCode);

      var result = SOAPClient.invoke("/Services/IGWebService.asmx", "IsEu", pl, false);

      return result;*/
        
      var languages = new  Object();
      languages["AL"] = 1;
      languages["AT"] = 1;
      languages["AZ"] = 1;
      languages["BA"] = 1;
      languages["BE"] = 1;
      languages["BG"] = 1;
      languages["BY"] = 1;
      languages["CH"] = 1;
      languages["CY"] = 1;
      languages["CZ"] = 1;
      languages["DE"] = 1;
      languages["DK"] = 1;
      languages["EE"] = 1;
      languages["ES"] = 1;
      languages["FI"] = 1;
      languages["FR"] = 1;
      languages["GB"] = 1;
      languages["GR"] = 1;
      languages["HR"] = 1;
      languages["HU"] = 1;
      languages["IE"] = 1;
      languages["IS"] = 1;
      languages["IT"] = 1;
      languages["LI"] = 1;
      languages["LT"] = 1;
      languages["LU"] = 1;
      languages["LV"] = 1;
      languages["MD"] = 1;
      languages["ME"] = 1;
      languages["MK"] = 1;
      languages["MT"] = 1;
      languages["NL"] = 1;
      languages["NO"] = 1;
      languages["PL"] = 1;
      languages["PT"] = 1;
      languages["RO"] = 1;
      languages["RS"] = 1;
      languages["RU"] = 1;
      languages["SE"] = 1;
      languages["SI"] = 1;
      languages["SK"] = 1;
      languages["TR"] = 1;
      languages["UA"] = 1;
      languages["XZ"] = 1;

      return countryCode.toUpperCase() in languages;
  }

  function CheckProductAlreadyInCart(productNumber) {
      var pl = new SOAPClientParameters();
      pl.add("productNumber", productNumber);

      var result = SOAPClient.invoke("/Services/IGWebService.asmx", "CheckProductAlreadyInCart", pl, false);

      return result;
  }


  if (typeof jQuery != 'undefined') {
      (function($) {
          var imgList = [];
          $.extend({
              preload: function(imgArr, option) {
                  var setting = $.extend({
                      init: function(loaded, total) { },
                      loaded: function(img, loaded, total) { },
                      loaded_all: function(loaded, total) { }
                  }, option);
                  var total = imgArr.length;
                  var loaded = 0;

                  setting.init(0, total);

                  for (var i in imgArr) {
                      imgList.push($("<img />")
					    .attr("src", imgArr[i])
					    .load(function() {
					        loaded++;
					        setting.loaded(this, loaded, total);
					        if (loaded == total) {
					            setting.loaded_all(loaded, total);
					        }
					    })
				    );
                  }
              }
          });
      })(jQuery);

      function setNextSlideshow(div_id, images, links, index, animationDur, displayDur) {
          var html = '&#65279;'; //non width text

          if (links[index]) {
              html += '<a href="' + links[index] + '">';
          }

          html += '<img src="' + images[index] + '"/>';

          if (links[index]) {
              html += '</a>';
          }

          var nextIndex = index + 1;

          if (nextIndex >= images.length)
              nextIndex = 0;

          $('#' + div_id).html(html);
          $('#' + div_id).fadeIn(animationDur, function() {
              setTimeout(function() {
                  $('#' + div_id).fadeOut(animationDur, function() {
                      setNextSlideshow(div_id, images, links, nextIndex, animationDur, displayDur);
                  });
              }, displayDur);
          });
      }
  }


  function RadComboBox_showImageOnSelectedItemChanging(sender, eventArgs) {
      var input = sender.get_inputDomElement();

      var imageUrl = eventArgs.get_item().get_imageUrl();

      if (imageUrl)
          input.style.background = "url(" + imageUrl + ") no-repeat 3px 5px";

      input.style.paddingLeft = "15px";
  }



  function RadComboBox_showFirstItemImage(sender) {
      var input = sender.get_inputDomElement();

      var imageUrl = sender.get_items().getItem(sender.get_selectedIndex()).get_imageUrl();
      
      if (imageUrl)
          input.style.background = "url(" + imageUrl + ") no-repeat 3px 5px";
        
      input.style.paddingLeft = "15px";
  }

  function cancelEvents(e) {
      if (!e) var e = window.event;
      e.cancelBubble = true;
      if (e.stopPropagation) e.stopPropagation();
  }

  function drawCircleFunc() {
  }
