function ZoomPicture(PictureID, Language, Width, Height) {

	if ((Width/Height > 4/3 && Width > window.screen.availWidth - 35) || (Width/Height < 4/3 && Height > window.screen.availHeight - 150)) {

		NewWindowWidth = window.screen.availWidth - 20;

		NewWindowHeight = window.screen.availHeight - 150;

	} else {

		NewWindowWidth = Width + 50;

		NewWindowHeight = Height + 80;

	}

	NewWindowFeatures = "top=20,left=10,width="+NewWindowWidth+",height="+NewWindowHeight+",location=0,directories=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1";

	var PictureZoom = window.open("/generalpurpose/zoompicture.php?PictureID=" + PictureID + "&Language=" + Language, "PictureZoom", NewWindowFeatures);

	PictureZoom.focus();
}

function SwapImage(ImageName, ImageFileName) {

	document.images[ImageName].src = ImageFileName;

}

function OpenURLInNewWindow(URL) {

	if (URL) {

		NewWindowWidth = (window.screen.availWidth - 20);
		NewWindowHeight = (window.screen.availHeight - 150);

		NewWindowFeatures = "top=20,left=10,width="+NewWindowWidth+",height="+NewWindowHeight+",location=1,directories=0,menubar=1,toolbar=1,status=1,scrollbars=1,resizable=1";

		var NewWindow = window.open("/index/referer.php?URL="+URL+"&S=", "PreviewWindow", NewWindowFeatures);

		NewWindow.focus();
	}
}

function OpenURLInNewWindowSized(URL, NewWindowWidth, NewWindowHeight) {

	if (URL) {

		//NewWindowWidth = (window.screen.availWidth - 20);
		//NewWindowHeight = (window.screen.availHeight - 150);

		NewWindowFeatures = "top=20,left=10,width="+NewWindowWidth+",height="+NewWindowHeight+",location=1,directories=0,menubar=1,toolbar=1,status=1,scrollbars=1,resizable=1";

		var NewWindow = window.open("/index/referer.php?URL="+URL+"&S=", "PreviewWindow", NewWindowFeatures);

		NewWindow.focus();
	}
}

function RoundToDecimal(ValueToRound, NoOfDecimal) {

	ValueToRound = Math.round(ValueToRound*Math.pow(10,2))/Math.pow(10,2);
	ValueToRoundString = "" + ValueToRound;
	CommaPos = ValueToRoundString.length - ValueToRoundString.indexOf(".");
	if (CommaPos == 2) {
		ValueToRoundString += "0";
	} else {
		if (CommaPos == ValueToRoundString.length + 1) {
			ValueToRoundString += ".00";
		}
	}
	return ValueToRoundString;
}



var marked_row = new Array;

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;

    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 5. Sets the new color...
	newColor = thePointerColor;
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
                theCells[c].style.backgroundColor = newColor;
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

/**************************/
function onFeatureChangeHandler(target, bChangePrice) {
	if (bChangePrice == undefined) {
		bChangePrice = true;
	}
    var select = target;
    var featureLevel = parseInt(select.name.split("_")[1]);
    
    var featureValue;
    var versionList = allVersions;
    for (var i = 0; i <= featureLevel; i++) {
      featureValue = getValueForLevel(i);
      
      if (!versionList[featureValue]) {
        return;
      }
      versionList = versionList[featureValue];
    }

    if (versionList['RegularPrice']) {
    	if (bChangePrice) {
    		setPrice(versionList);
    	}
      activeArticleVersionID = versionList['ArticleVersionID'];      
      if ($('#selected-set-version-id').length) {
    	  $('#selected-set-version-id')[0].value = activeArticleVersionID;
      }
      
    }
    else {
      setDataForLevel(versionList, featureLevel + 1);
    }
  }
  
  function getValueForLevel(level) {
    var el = document.getElementById('featureLevel_' + level);
    return (el.value?el.value:el.firstChild.data)
  }
  
  function setDataForLevel(data, level) {
    var target = document.getElementById('featureLevel_' + level)
    if (!target) {
      return false;
    }
    
    if (target.nodeName.toLowerCase() == 'select') {
      var oldSelectedValue = target.value;

      target.innerHTML = "";
      for (i in data) {
        option = document.createElement('option');
        option.value = i;
        option.appendChild(document.createTextNode(i));
        target.appendChild(option);
      }
      onFeatureChangeHandler(target);
    }
    
  }
  
  function setPrice(PriceObj) {

    if (PriceObj['SpecialPrice']) {
      var thePriceParts = RoundToDecimal(PriceObj['RegularPrice']).split("\.");
      var intPart = thePriceParts[0];
      var decPart = thePriceParts[1];
      var regularPrice = '<span class="strikethrough">'+intPart + ','
        + '<sup>' + decPart + '</sup></span>';
        
        
      var thePriceParts = RoundToDecimal(PriceObj['SpecialPrice']).split("\.");
      var intPart = thePriceParts[0];
      var decPart = thePriceParts[1];
      var specialPrice = intPart + ','
        + '<sup>' + decPart + '</sup>';
        
        
    }
    else {
      var thePriceParts = RoundToDecimal(PriceObj['RegularPrice']).split("\.");
      var intPart = thePriceParts[0];
      var decPart = thePriceParts[1];
      var regularPrice = intPart + ','
        + '<sup>' + decPart + '</sup>';
        //+ '<span class="currencySymbol">' + PriceObj['CurrencySymbolShort'] + '</span></span>';
      var specialPrice = "";
    }
    // hide old article version description
    disDiv = document.getElementById('VersionDescription' + activeArticleVersionID);
    if (disDiv != "undefined" && disDiv != null) {
       disDiv.style.display = 'none';
    }
    // show article version description
    disDiv = document.getElementById('VersionDescription' + PriceObj['ArticleVersionID']);
    if (disDiv != "undefined" && disDiv != null) {
       disDiv.style.display = 'block';
    }

    var priceField = document.getElementById('value');
    if (specialPrice != '') {
  	   priceField.innerHTML = specialPrice;// + '<br />' + regularPrice;
    }
    else { 
 	   priceField.innerHTML = regularPrice;
    }
  }
  

  
  

var sliderOpen = null;
showContactForm = function(ident) {	
	
	var myParent = $(ident);
	
	if (myParent.css('right') < '0') {
       myParent._status = 'closed';
	}
	else {
		myParent._status = 'open';
	}
	
	if (myParent._status == 'closed' && sliderOpen == null) {
		myParent.animate({right: '0px'});
		myParent.css('z-index', '400');
		sliderOpen = ident;
	}
	else if (myParent._status == 'open' && sliderOpen == ident) {		
		myParent.animate({right: '-540px'});		
		$("input[type='text']", myParent).attr("value", "");
		$("textarea", myParent).attr('value', '');
		$("div.error-msg", myParent).remove();
		$("div.info-msg", myParent).remove();
		$("div.standard-msg", myParent).remove();
		myParent.css('z-index', '300');
		sliderOpen = null;
	}
}

showSetVersionInfo = function (event) {
   var hoverDiv = $('.set-hover', this.parentNode);
   if (hoverDiv) {
      hoverDiv.show();
   }
}

hideSetVersionInfo = function (event) {
   var hoverDiv = $('.set-hover', this.parentNode);
   if (hoverDiv) {
      hoverDiv.hide();
   }
}

sendSetForm = function() {	
    var url = jscriptSetUrl;
    if (url.match(/\?/)) {
      url += '&';
    }
    else {
      url += '?';
    }
    url += 'SetStartVersionId=' + activeArticleVersionID
      + '&AddToCartQuantity=' + $('#amountSelector')[0].value
      + '&SetId=' + this.id;
    location.href = url;
}


$().ready(function() {
   $('#search-field-text').focus(function() {
	   if (this.startValue == undefined) {
		   this.startValue = this.value;
	   }
	   this.value = '';
	   $(this).css('text-align', 'left');
   });
   $('#search-field-text').blur(function() {
	   if (this.value != '') {
		   return;
	   }
	   if (this.startValue != undefined) {
		   this.value= this.startValue;
	   }	   
	   $(this).css('text-align', 'center');
   });
   
   $('#brand-selection').change(function() {
	   window.location.href=this.value;
   });
   
   $('#contact-form .slider').click(function() {showContactForm('#contact-form');});
   $('#recommend-form .slider').click(function() {showContactForm('#recommend-form');});
   
   $('.set-picture').mouseover(showSetVersionInfo);
   $('.set-picture').mouseleave(hideSetVersionInfo);
   $('.set-version').click(sendSetForm);
   $('.set-hover').mouseover(showSetVersionInfo);
   $('.set-hover').mouseleave(hideSetVersionInfo);
}		
);

