//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * @package Starweb Webshop System
 * @version See version-file
 * @copyright Copyright (c) 2000 - 2010, Ehandelslogik AB
 * 
 * @author Ehandelslogik AB, org.no 556696-9019  (Starweb)
 * Country: Sweden
 * Homepage: www.starweb.se
 * E-mail: support@starweb.se
 * 
 * License:
 * This program is not "free" software and restrictions apply!
 * This file as well as all other files containing the code to our software may ONLY be used and/or redistributed with written permission from us.
 * You'll find information regarding our conditions and pricing on our homepage. Contact us immediately if any of these conditions are not clear.
 */
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** Initialize: Public variables */
/** @var string - Get: Div name to hide/show */
var sDivName = 'cssBtnBuy';

/** @var string - Get: Location to article item */
var sLocationArtItem = GetChrStrStr(top.location.href, "sAction=", true);
if (!sLocationArtItem){alert("ERROR: sLocationArtItem is NOT set in ArtItem. Please contact support@starweb.se with this error message.");}

/** @var string - Get: Location to article list */
var sLocationArtList = location.pathname;
if (!sLocationArtList){alert("ERROR: sLocationArtList is NOT set in ArtList. Please contact support@starweb.se with this error message.");}



var sVat;
var bIsInclVat;
var sChrStop;
var sChrComma;
var sCartFrameName;
var sUrlBtnBuyPty = "";
var sUrlArtImg;
var sImgArtNameDefault;
var sArtModelIdSel = "";
var bIsViewCost;
var iCustRtlrNr;
var sCurrChr;
var fCurrWorthNr;
var iCurrDecNr;
var iDbId;
var sDbArtModelId;
var iDbArtVatNr;
var fDbWeightNr;
var fDbCostExclVatNr;
var fDbCostDiscountExclVatNr;
var fDbCostCustRtlrExclVatNr;
var sDbStockStatusTransl;
var sLangStockStatusIsEmpty;
var sUrlImgSoft_1;
var sImgFileName_1;
var iWdtNr_1;
var iHgtNr_1;
var bIsImgIsArtItemAutoZoom;
var bIsImgIsArtHighslide;
var sApp;
var iSetupShopSizeNr;
var iArtPrmTotalNr;
var iArtPrm_DataTotalNr;
var aArtPrm_DataUniqueIdItem;
var aImgArtPrmItem;






//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * Set Article Item Settings
 * @access public
 */
function SetArtItemSett(sVatSett, bIsInclVatSett, sChrStopSett, sChrCommaSett, sCartFrameNameSett, sArtNameSett,
   sUrlArtImgSett, sImgArtNameDefaultSett, bIsViewCostSett, iCustRtlrNrSett, sCurrChrSett, fCurrWorthNrSett, iCurrDecNrSett, iDbIdSett,
   sDbArtModelIdSett, iDbArtVatNrSett, fDbWeightNrSett, fDbCostExclVatNrSett, fDbCostDiscountExclVatNrSett, fDbCostCustRtlrExclVatNrSett,
   sDbStockStatusTranslSett, sLangStockStatusIsEmptySett, sUrlImgSoft_1Sett, sImgFileName_1Sett, iWdtNr_1Sett, iHgtNr_1Sett,
   bIsImgIsArtItemAutoZoomSett, bIsImgIsArtHighslideSett, sAppSett, iSetupShopSizeNrSett, iArtPrmTotalNrSett, iArtPrm_DataTotalNrSett)
{
   sVat                             = sVatSett;
   bIsInclVat                       = bIsInclVatSett;
   sChrStop                         = sChrStopSett;
   sChrComma                        = sChrCommaSett;
   sCartFrameName                   = sCartFrameNameSett;
   sArtName                         = sArtNameSett;
   sUrlArtImg                       = sUrlArtImgSett;
   sImgArtNameDefault               = sImgArtNameDefaultSett;
   bIsViewCost                      = bIsViewCostSett;
   iCustRtlrNr                      = iCustRtlrNrSett;
   sCurrChr                         = sCurrChrSett;
   fCurrWorthNr                     = fCurrWorthNrSett;
   iCurrDecNr                       = iCurrDecNrSett;
   iDbId                            = iDbIdSett;
   sDbArtModelId                    = sDbArtModelIdSett;
   iDbArtVatNr                      = iDbArtVatNrSett;
   fDbWeightNr                      = fDbWeightNrSett;
   fDbCostExclVatNr                 = fDbCostExclVatNrSett;
   fDbCostDiscountExclVatNr         = fDbCostDiscountExclVatNrSett;
   fDbCostCustRtlrExclVatNr         = fDbCostCustRtlrExclVatNrSett;
   sDbStockStatusTransl             = sDbStockStatusTranslSett;
   sLangStockStatusIsEmpty          = sLangStockStatusIsEmptySett;
   sUrlImgSoft_1                    = sUrlImgSoft_1Sett;
   sImgFileName_1                   = sImgFileName_1Sett;
   iWdtNr_1                         = iWdtNr_1Sett;
   iHgtNr_1                         = iHgtNr_1Sett;
   bIsImgIsArtItemAutoZoom          = bIsImgIsArtItemAutoZoomSett;
   bIsImgIsArtHighslide             = bIsImgIsArtHighslideSett;
   sApp                             = sAppSett;
   iSetupShopSizeNr                 = iSetupShopSizeNrSett;
   iArtPrmTotalNr                   = iArtPrmTotalNrSett;
   iArtPrm_DataTotalNr              = iArtPrm_DataTotalNrSett;
}






/**
 * Set Article Item Field Value List
 * @access public
 */
function SetArtItemFldValList()
{
   // Get: Is there article parameters?
   var frmArtItem = document.forms['frmArtItem'];
   var oArtPrm_0  = frmArtItem.elements['aItem[oArtPrm_0]']; // MUST BE FOUND BY NAME DUE TO LABEL IS IDENTIFIED BY ID!
   var sStockStatusSel, fArtWeightNrSel, fCostExclVatNrSel, fCostDiscountExclVatNrSel, fCostCustRtlrExclVatNrSel;
   var i, j, iUniqueIdRowNr;
   var sUniqueId            = "";
   var iArtQtyNr            = 1;
   var oArtQtyNrTxtBox      = document.getElementById("aItem[iArtQtyNr]");
   var sWarnMsg;
   
   
   
   switch (true)
   {
      // ARTICLE PARAMETER
      case ((oArtPrm_0 != "") && (oArtPrm_0 != undefined)):
         // Loop: Through all fields in array
         for (i=0, j=1; i<iArtPrmTotalNr; i++, j++)
         {
            // Get: Article parameter object
            var oArtPrmObj = frmArtItem["aItem[oArtPrm_"+ i +"]"]; // MUST BE FOUND BY NAME SINCE LABEL IS IDENTIFIED BY ID!
            
            
            /* Article parameter exists, set article parameter cost - Start */
            if (oArtPrmObj)
            {
               switch (true)
               {
                  // RADIO BUTTON
                  case (oArtPrmObj.type == "radio"):
                  case ((oArtPrmObj.type == undefined) && (oArtPrmObj.checked == undefined) && (oArtPrmObj.length > 0)): // Several radio buttons
                     // Check: If several radio buttons per parameter
                     if (oArtPrmObj.length > 0)
                     {
                        for (var k=0; k<oArtPrmObj.length; k++)
                        {
                           // Check: That value is checked
                           if (oArtPrmObj[k].checked)
                           {
                              sUniqueId += oArtPrmObj[k].value;
                              break;
                           }
                        }
                     }
                     // Check: Only ONE radio button per parameter
                     else if (oArtPrmObj.checked == true)
                     {sUniqueId += oArtPrmObj.value;}
                     break;
                     
                     
                  // SELECT LIST
                  default:
                     // Get: Selected article parameter id
                     if (oArtPrmObj.options)
                     {sUniqueId += oArtPrmObj.options[oArtPrmObj.selectedIndex].value;}
                     break;
               }
               
               
               // Set: Add value to total unique id string
               if (iArtPrmTotalNr != j)
               {sUniqueId += sChrStop;}
            }
            /* Article parameter exists, set article parameter cost - End */
         }
         
         
         if (sUniqueId)
         {
            // Loop: Through all fields in array
            for (iUniqueIdRowNr=0; iUniqueIdRowNr<iArtPrm_DataTotalNr; iUniqueIdRowNr++)
            {
               if (aArtPrm_DataUniqueIdItem[iUniqueIdRowNr][sUniqueId])
               {
                  sArtModelIdSel            = aArtPrm_DataUniqueIdItem[iUniqueIdRowNr][sUniqueId]["ModelId"];
                  sStockStatusSel           = aArtPrm_DataUniqueIdItem[iUniqueIdRowNr][sUniqueId]["sStockStatusTransl"];
                  fArtWeightNrSel           = aArtPrm_DataUniqueIdItem[iUniqueIdRowNr][sUniqueId]["WeightNr"];
                  fCostExclVatNrSel         = aArtPrm_DataUniqueIdItem[iUniqueIdRowNr][sUniqueId]["CostExclVatNr"];
                  fCostDiscountExclVatNrSel = aArtPrm_DataUniqueIdItem[iUniqueIdRowNr][sUniqueId]["CostDiscountExclVatNr"];
                  fCostCustRtlrExclVatNrSel = aArtPrm_DataUniqueIdItem[iUniqueIdRowNr][sUniqueId]["CostCustRtlrExclVatNr"];
                  //sImgArtPrmName            = aArtPrm_DataUniqueIdItem[iUniqueIdRowNr][sUniqueId]["Img"];

                  $.ajax({
                     url   : sBaseUrl +'/Shop/Page/pgAjaxLoad.php?sFunc=SetSelArtPrm',
                     data  : 'sSelArtPrm='+ sUniqueId
                  });

                  break;
               }
            }
         }
         break;
         
         
         
      // _NO_ ARTICLE PARAMETER
      default:
         sArtModelIdSel            = sDbArtModelId;
         sStockStatusSel           = sDbStockStatusTransl;
         fArtWeightNrSel           = fDbWeightNr;
         fCostExclVatNrSel         = fDbCostExclVatNr;
         fCostDiscountExclVatNrSel = fDbCostDiscountExclVatNr;
         fCostCustRtlrExclVatNrSel = fDbCostCustRtlrExclVatNr;
         break;
   }
   
   
   
   // Set: Model id, stock status, weight number, url to insert article in cart
   SetModelIdTxtBox(sArtModelIdSel);
   SetStockStatusTxtBox(sStockStatusSel);
   SetWeightNrTxtBox(fArtWeightNrSel);
   SetImgArtPrm(sUniqueId, iUniqueIdRowNr);
   
   
   
   // Set: Cost text boxes
   SetArtCostTxtBoxList(fCostExclVatNrSel, fCostDiscountExclVatNrSel, fCostCustRtlrExclVatNrSel);

}






/**
 * Set Article Cost Text Box List
 * @access private
 *
 * @param float fCostExclVatNrSel
 * @param float fCostDiscountExclVatNrSel
 * @param float fCostCustRtlrExclVatNrSel
 */
function SetArtCostTxtBoxList(fCostExclVatNrSel, fCostDiscountExclVatNrSel, fCostCustRtlrExclVatNrSel)
{
   if (bIsViewCost == true)
   {
      // Set: Cheapest price
      var fCostCheapestExclVatNr = "";
      switch (true)
      {
         // RETAILER
         case ((iCustRtlrNr > 0) && (fCostCustRtlrExclVatNrSel > 0)):
            fCostCheapestExclVatNr = fCostCustRtlrExclVatNrSel;
            break;
            
         // DISCOUNT
         case (fCostDiscountExclVatNrSel > 0):
            fCostCheapestExclVatNr = fCostDiscountExclVatNrSel;
            break;
            
         // COST
         case (fCostExclVatNrSel > 0):
            fCostCheapestExclVatNr = fCostExclVatNrSel;
            break;
      }
      
      
      switch (true)
      {
         // SET: Cost to both text boxes. If discounted cost OR retailer cost is set 
         case ((fCostDiscountExclVatNrSel > 0) && (fCostDiscountExclVatNrSel != fCostExclVatNrSel)):
         case ((fCostCustRtlrExclVatNrSel > 0) && (fCostCustRtlrExclVatNrSel != fCostExclVatNrSel)):
            SetArtCostExclVatNrTxtBox(fCostCheapestExclVatNr);
            SetArtCostDiscountExclVatNrTxtBox(fCostExclVatNrSel);
            break;
            
            
         // SET: Cost to both text boxes. If both prices are the same, hide discount price
         default:
            SetArtCostExclVatNrTxtBox(fCostCheapestExclVatNr);
            SetArtCostDiscountExclVatNrTxtBox(0.0);
            break;
      }
   }
}






/**
 * Set Article Cost Excl VAT Text Box
 * @access private
 *
 * @param float fArtCostExclVatNr
 */
function SetArtCostExclVatNrTxtBox(fArtCostExclVatNr)
{
   // Get: Settings
   var oArtCostExclVatNr    = document.getElementById("oArtCostExclVatNr");
   var bIsViewCostInclVatNr = ((sVat == 'InclVatNr') && (bIsInclVat == true)) ? true : false;
   
   
   if (oArtCostExclVatNr)
   {
      // Get: Cost incl/excl VAT
      switch (bIsViewCostInclVatNr)
      {
         // INCL VAT - Due to customer within EU
         case true:
            var sVatStr       = (iDbArtVatNr.length == 1) ? '1.0' + iDbArtVatNr : '1.' + iDbArtVatNr;
            fArtCostExclVatNr = GetRoundCostNr((fArtCostExclVatNr * sVatStr) / fCurrWorthNr);
            break;
            
            
         // EXCL VAT - Due to customer outside of EU
         default:
            fArtCostExclVatNr = GetRoundCostNr(fArtCostExclVatNr / fCurrWorthNr);
            break;
      }
      
      
      // Set: Article cost and currency char
      oArtCostExclVatNr.value = fArtCostExclVatNr + sCurrChr;

      // Check: If Klarna part payment is installed and should be shown
      if ($('#cssArtItemKlarnaPartPayCon').length)
      {
         var fUnformattedPurchaseAmountNr = fArtCostExclVatNr.replace(' ', '');
         fUnformattedPurchaseAmountNr = fUnformattedPurchaseAmountNr.replace(',', '.');
         fUnformattedPurchaseAmountNr = parseFloat(fUnformattedPurchaseAmountNr);
       
         $.get(sBaseUrl +'/Shop/Page/pgAjaxLoad.php', {sFunc: 'ArtItemKlarnaPartPay', fPurchaseAmountNr: fUnformattedPurchaseAmountNr}, function(sData) {  
            $('#cssArtItemKlarnaPartPayCon').replaceWith(sData);
         });
      }
   }
}






/**
 * Set Article Cost Discount Excl VAT Text Box
 * @access private
 *
 * @param float fArtCostDiscountExclVatNr
 */
function SetArtCostDiscountExclVatNrTxtBox(fArtCostDiscountExclVatNr)
{
   // Get: Setting
   var oArtCostDiscountExclVatNr = document.getElementById("oArtCostDiscountExclVatNr");
   
   
   // Check: If discount cost exists
   if (fArtCostDiscountExclVatNr && oArtCostDiscountExclVatNr)
   {
      // Get: Is cost incl VAT? (Depending on customer country)
      var bIsViewCostInclVatNr = ((sVat == 'InclVatNr') && (bIsInclVat == true)) ? true : false;
      
      
      // Get: Cost incl/excl VAT
      switch (bIsViewCostInclVatNr)
      {
         // INCL VAT - Due to customer within EU
         case true:
            var sVatStr = (iDbArtVatNr.length == 1) ? '1.0' + iDbArtVatNr : '1.' + iDbArtVatNr;
            fArtCostDiscountExclVatNr = GetRoundCostNr((fArtCostDiscountExclVatNr * sVatStr) / fCurrWorthNr);
            break;
            
            
         // EXCL VAT - Due to customer outside of EU
         default:
            fArtCostDiscountExclVatNr = GetRoundCostNr(fArtCostDiscountExclVatNr / fCurrWorthNr);
            break;
      }
      
   
      // Set: Cost to article discount cost and currency char
      oArtCostDiscountExclVatNr.value = fArtCostDiscountExclVatNr + sCurrChr;
   }
   else
   {
      // Set: Empty value in text box
      oArtCostDiscountExclVatNr.value = "";
   }
}






/**
 * Set Model Id Text Box
 * @access private
 *
 * @param string sArtModelId
 */
function SetModelIdTxtBox(sArtModelId)
{
   // Get: Setting
   var oArtModelId = document.getElementById("oArtModelId");
   
   
   if (sArtModelId && oArtModelId)
   {oArtModelId.value = sArtModelId;}
}






/**
 * Set Stock Status Text Box
 * @access private
 *
 * @param {array} sStockStatus
 */
function SetStockStatusTxtBox(sStockStatus)
{
   // Check: That stock status field exist
   if ($('#oArtStockStatus').length)
   {
      // Set: Stock value
      $('#oArtStockStatus').val(sStockStatus);
      
      // Hide: Stock label/text if stock value is empty
      if (!sStockStatus)
      {  $('#cssArtItemStockStatusTxt').css('visibility', 'hidden'); }
      else
      {
         $('#cssArtItemStockStatusTxt').css('visibility', 'visible');
         
         // Set: Hide or show buy button and quantity field
         if ($('#oArtStockStatus').val() == sLangStockStatusIsEmpty)
         {  
            DivToggle(sDivName, 0);
            DivToggle('cssArtItemArtQtyNrCon', 0);
         }
         else
         {
            DivToggle(sDivName, 1);
            DivToggle('cssArtItemArtQtyNrCon', 1);
         }
      }
   }
}






/**
 * Set Weight Number Text Box
 * @access private
 *
 * @param float fArtWeightNr
 */
function SetWeightNrTxtBox(fArtWeightNr)
{
   // Get: Settings
   var oArtWeightNr            = document.getElementById("oArtWeightNr");
   var sDivArtItemWeightNrName = "cssArtItemWeightNrTxt";
   
   
   if (fArtWeightNr && oArtWeightNr)
   {
      // Set: Hide weight number label
      DivToggle(sDivArtItemWeightNrName, 0);
      
      // Set: Weight to nothing
      oArtWeightNr.value = "";
      
      
      if (fArtWeightNr > 0)
      {
         // Set: Show weight number label
         DivToggle(sDivArtItemWeightNrName, 1);
         
         // Get: Weight number string
         if (fArtWeightNr < 1)
         {
            var sArtWeightNr  = (fArtWeightNr * 1000);
            sArtWeightNr     += ""; // Force string
            
            // Set: Max number of decimals
            sArtWeightNr = sArtWeightNr.substring(0, 7);
            
            sArtWeightNr += " gram";
         }
         else
         {sArtWeightNr = fArtWeightNr +" kg";}
         
         
         // Set: Textbox to value
         oArtWeightNr.value = sArtWeightNr;
      }
   }
}






/**
 * Set Image Article Parameter
 * @access private
 *
 * @param string sUniqueId
 * @param int iUniqueIdRowNr
 */
function SetImgArtPrm(sUniqueId, iUniqueIdRowNr)
{
   // Get: Settings
   //var oArtImg_1    = document.getElementById("oArtItemImg_1");
   var oArtImg_1    = document.getElementById("cssArtItemImg_1");
   var oArtDivImg_1 = document.getElementById("cssImg_1");
   

   
   if (oArtImg_1)
   {
      switch (true)
      {
         // GET: Selected article parameter image
         case ((sUniqueId != "") && (iUniqueIdRowNr != undefined) && (iSetupShopSizeNr > 2)):
            if (aImgArtPrmItem[iUniqueIdRowNr][sUniqueId] != "")
            {
               switch (true)
               {
                  // Check: That it's an SWF flash movie
                  case (aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["sUrlImgSoft"].indexOf(".swf") != -1):
                     // Get: Image html (oArtItemImg_1 must be present)
                     var sImgHtml = "<div id=\"oArtItemImg_1\"> </div>";
                     
                     // Get: SWF flash video html
                     var sSwfFlashVideoHtml = GetSwfFlashMovieHtml(
                        aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["sUrlImgSoft"],
                        aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iWdtNr"],
                        aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iHgtNr"]
                     );
                     var sHrefHtml = (bIsImgIsArtItemAutoZoom == true)
                        ? "<a id=\"aUrlArtItemImg_1\" onmouseover=\"ImgPopupAutoZoomShow(this,'Flash','"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["sUrlImgSoft"].replace(" ", "%20") +"','"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iOrgWdtNr"] +"','"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iOrgHgtNr"] +"')\" onmouseout=\"ImgPopupAutoZoomHide()\" class=\"highslide\" onclick=\"return hs.htmlExpand(this, {objectType:'swf', objectWidth:'"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iOrgWdtNr"] +"', objectHeight:'"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iOrgHgtNr"] +"', align:'center', allowSizeReduction:false})\" href=\""+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["sUrlImgSoft"] +"\">"
                        : "<a id=\"aUrlArtItemImg_1\" class=\"highslide\" onclick=\"return hs.htmlExpand(this, {objectType:'swf', objectWidth:'"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iOrgWdtNr"] +"', objectHeight:'"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iOrgHgtNr"] +"', align:'center', allowSizeReduction:false})\" href=\""+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["sUrlImgSoft"] +"\">";
                     
                     
                     var iRandNr = Math.random();
                     iRandNr     = Math.floor(iRandNr * 100);
                                         
                     var sImgTransparentHtml = "<div><div>"+ sHrefHtml;
                         sImgTransparentHtml +="<img id=\"cssImgTransparentNr_"+ iRandNr +"\" src=\""+ sBaseUrl +"/Shop/Image/Pixel.gif\" class=\"cssImgTransparent cssIeOpacity\" />";
                         sImgTransparentHtml +="<style type=\"text/css\">.cssImg #cssImgTransparentNr_"+ iRandNr +" {height:"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iHgtNr"] +"px; width:"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iWdtNr"] +"px;}";
                         sImgTransparentHtml +=".cssArtItemImgThumbGallery #cssImgTransparentNr_"+ iRandNr +" { height:"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iWdtNr"] +"px; width:"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iHgtNr"] +"px; background-color:red; display:block; z-index:2; position:absolute; margin:0px;}";        
                         sImgTransparentHtml +="</style><img class=\"cssMovieIcon\" src=\""+ sBaseUrl +"/Shop/Image/icon_movie_highslide.png\"/></a></div>"+ sSwfFlashVideoHtml +"</div>"+ sImgHtml +"</div>";
                     
                     
                     // View: Url and image
                     if (oArtDivImg_1)
                     {
                        // oArtDivImg_1.innerHTML = sHrefHtml + sSwfFlashVideoHtml + sImgHtml;
                        oArtDivImg_1.innerHTML = sImgTransparentHtml;
                     }
                     
                     break;
                     
                     
                     
                  // Check: That it's not the default image
                  case ((aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["sUrlImgSoft"].indexOf(sImgArtNameDefault) == -1)
                     && (aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["sUrlImgSoft"] != "")):
                     // Get: Image html
                     var sImgHtml = GetImgHtml(
                        aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["sUrlImgSoft"],
                        aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iWdtNr"],
                        aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iHgtNr"]
                     );
                     var sHrefHtml = (bIsImgIsArtItemAutoZoom == true)
                        ? "<a id=\"aUrlArtItemImg_1\" onmouseover=\"ImgPopupAutoZoomShow(this,'Img','"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["sUrlImgSoft"].replace(" ", "%20") +"','"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iOrgWdtNr"] +"','"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iOrgHgtNr"] +"')\" onmouseout=\"ImgPopupAutoZoomHide()\" class=\"highslide\" onclick=\"return hs.expand(this)\" href=\"\">"
                        : "<a id=\"aUrlArtItemImg_1\" class=\"highslide\" onclick=\"return hs.expand(this)\" href=\"\">";
                     
                     // View: Url and image
                     if (oArtDivImg_1)
                     {oArtDivImg_1.innerHTML = sHrefHtml + sImgHtml;}
                    
                     
                     // Set: Url
                     var oUrlArtItemImg_1 = document.getElementById("aUrlArtItemImg_1");
                     if (oUrlArtItemImg_1)
                     {oUrlArtItemImg_1.href = aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["sUrlImgSoft"];}
                     
                     
                     // Set: Image
                     oArtImg_1.src    = aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["sUrlImgSoft"];
                     
                     // Set: Width/height
                     oArtImg_1.width  = aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iWdtNr"];
                     oArtImg_1.height = aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iHgtNr"];
                     break;
                     
                     
                     
                  // Get: Image to first article image (default article image "-IngenBildVald-.jpg")
                  default:
                     // Get: Image html
                     var sImgHtml = GetImgHtml(
                        sUrlImgSoft_1,
                        iWdtNr_1,
                        iHgtNr_1
                     );
                     var sHrefHtml = (bIsImgIsArtItemAutoZoom == true)
                        ? "<a id=\"aUrlArtItemImg_1\" onmouseover=\"ImgPopupAutoZoomShow(this,'Img','"+ sUrlImgSoft_1.replace(" ", "%20") +"','"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iOrgWdtNr"] +"','"+ aImgArtPrmItem[iUniqueIdRowNr][sUniqueId]["iOrgHgtNr"] +"')\" onmouseout=\"ImgPopupAutoZoomHide()\" class=\"highslide\" onclick=\"return hs.expand(this)\" href=\"\">"
                        : "<a id=\"aUrlArtItemImg_1\" class=\"highslide\" onclick=\"return hs.expand(this)\" href=\"\">";

                     
                     // View: Url and image
                     if (oArtDivImg_1)
                     {oArtDivImg_1.innerHTML = sHrefHtml + sImgHtml;}


                     // Set: Url
                     var oUrlArtItemImg_1 = document.getElementById("aUrlArtItemImg_1");
                     if (oUrlArtItemImg_1)
                     {oUrlArtItemImg_1.href  = sUrlImgSoft_1;}


                     // Set: Image
                     oArtImg_1.src = sUrlImgSoft_1;
                     
                     // Set: Width/height
                     oArtImg_1.width  = iWdtNr_1;
                     oArtImg_1.height = iHgtNr_1;
                     break;
               }
            }
            else
            {
               // Set: Image to default article image "-IngenBildVald-.jpg"
               oArtImg_1.src = sUrlArtImg + sImgArtNameDefault;
               
               // Set: Width/height
               oArtImg_1.width  = iWdtNr_1;
               oArtImg_1.height = iHgtNr_1;
            }
            break;
      }
   }
}






/**
 * Get Image Html
 * @access private
 *
 * @param string $sUrlImgSoft
 * @param int $iWdtNr
 * @param int $iHgtNr
 * 
 * @return string
 */
function GetImgHtml(sUrlImgSoft, iWdtNr, iHgtNr)
{
   var sImgHtml;
   
   // Get: Image html
   sImgHtml  = "<img src=\""+ sUrlImgSoft +"\" id=\"oArtItemImg_1\""; // style=\"height:"+ iHgtNr +"px; width:"+ iWdtNr +"px;\"
   sImgHtml += " class=\"cssImgBorder oArtItemImg_1\" alt=\"\" /></a>";
   sImgHtml += " <style>.oArtItemImg_1 { height:"+ iHgtNr +"px; width:"+ iWdtNr +"px; }</style>";
   
   return sImgHtml;
}






/**
 * Get SWF Flash Movie Html
 * @access private
 *
 * @param string $sUrlImgSoft
 * @param int $iWdtNr
 * @param int $iHgtNr
 * 
 * @return string
 */
function GetSwfFlashMovieHtml(sUrlImgSoft, iWdtNr, iHgtNr)
{
   var sImgHtml;

   // Get: SWF flash movie html
   sImgHtml  = "<object id=\"cssSwf_1\" type=\"application/x-shockwave-flash\" data=\""+ sUrlImgSoft +"\" width=\""+ iWdtNr +"\" height=\""+ iHgtNr +"\">";
   sImgHtml += "<param value=\"opaque\" name=\"wmode\" />";
   sImgHtml += "<param value=\"\" name=\"flashvars\" />";
   sImgHtml += "<!--[if IE]>-->";
   sImgHtml += "<param name=\"movie\" value=\""+ sUrlImgSoft +"\" />";
   sImgHtml += "<!--<![endif]-->";
   sImgHtml += "</object>";
   
   return sImgHtml;
}






/**
 * Get Article Model Id Selected
 * @access public
 * 
 * @return string
 */
function GetArtModelIdSel()
{
   return sArtModelIdSel;
}






/**
 * Get Char String In String
 * @access public
 * 
 * Function was fetched from http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_strstr/
 * http://kevin.vanzonneveld.net
 * +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
 * +   bugfixed by: Onno Marsman
 *    example 1: GetChrStrStr('Kevin van Zonneveld', 'van');
 *    returns 1: 'van Zonneveld'
 *    example 2: GetChrStrStr('Kevin van Zonneveld', 'van', true);
 *    returns 2: 'Kevin '
 *
 * @param string haystack
 * @param string needle
 * @param boolean bool
 * 
 * @return string
 */
function GetChrStrStr(haystack, needle, bool)
{
    var pos = 0;
 
    haystack += '';
    pos       = haystack.indexOf(needle);
    
    if ( pos == -1 ){
        return haystack;//return false;
    } else{
        if ( bool ){
            return haystack.substr(0, pos);
        } else{
            return haystack.slice(pos);
        }
    }
}






/**
 * Get an article item property.
 * 
 * @param string sPropName
 * @return int|string|array
 */
function getArtItemProp(sPropName)
{
   var mProp = null;
   
   switch (sPropName)
   {
      case 'sModelId':
         mProp = sArtModelIdSel;
         break;
      case 'iArtQtyNr':
         var sArtQtyNr = $.trim($('#aItem\\[iArtQtyNr\\]').val());
         mProp = sArtQtyNr.match(/^\d+$/) ? parseInt(sArtQtyNr) : 1;          
         break;
      case 'aArtCustomVals':
         
         var aArtCustomVals = [];

         // Get: Editable custom fields
         $('textarea[name^="aArtItemCustomFldEditable"]').each(function()
         {  
            // Check: That value is not empty (don't add if so)
            if ($.trim($(this).val()) != '') 
            {  
               // Check: That the input name is in the correct format and extract part of it (the custom field ID).
               var aMatches = $(this).attr('name').match(/aArtItemCustomFldEditable\[(\d+)\]$/);
               if (aMatches)
               {  
                  var sVal = $.trim($(this).val());
                  
                  // Replace: ,-chars with .-chars if it's a numeric value 
                  if (sVal.match(/\d,\d/))
                  {  sVal = sVal.replace(',', '.'); }
                  
                  aArtCustomVals[parseInt(aMatches[1])] = sVal;
               }
            }
         });

         // Get: Possible book format choice
         if ($('#sElibEbookFormat').length && $('#iElibEbookFormatsArtCustomFld_Id').length())
         {
            // Add: As custom field val
            var iArtCustomFld_Id = parseInt($('#iElibEbookFormatsArtCustomFld_Id').val());
            aArtCustomVals[iArtCustomFld_Id] = $('#sElibEbookFormat').val();
         }

         if (aArtCustomVals.length)
         {  mProp = aArtCustomVals; }
         
         break;      
   }

   return mProp;
}

