<!-- //
var ProdOpt1 = new Array();
var ProdOpt2 = new Array();
var ProdOptMix = new Array();


// select the clicked option
function SelectBox(prodOptNo,prodOptIDName,prodOptID,valueID,optionID,optionTempID,Text,PriceOrig,PriceAdjust,ListPrice) {
	//alert('prodOptIDName:'+prodOptIDName+' | prodOptID:'+prodOptID+' | valueID:'+valueID+' | optionID:'+optionID+' | optionTempID:'+optionTempID+' | Text:'+Text+' | PriceOrig:'+PriceOrig+' | PriceAdjust:'+PriceAdjust+' | ListPrice:'+ListPrice);

	var ProductOptions 	= document.getElementById('ProductOptions').value;
	var origProdOptID1 	= document.getElementById('ProdOptID1').value;
	var origProdOptID2 	= document.getElementById('ProdOptID2').value;
	var ProductOption1 	= document.getElementById('ProductOption1');
	var ProductOption2 	= document.getElementById('ProductOption2');
	var ItemPrice	 	= document.getElementById('Price');					// price that gets submitted to the shopping cart
	
	var ProductListPrice = document.getElementById('listprice');			// list price display
	var ProductPrice   	= document.getElementById('pricechange');			// unit price display
	var PriceChange    	= document.getElementById('diffchange');			// discount display
	var Discount		= document.getElementById('PriceMultiplier').value;	// discount level
	var ItemSavingsPerc	= document.getElementById('ItemSavingsPerc').value;	// the percent diff of list and sale price
	
	//alert(ItemPrice);
	//alert(PriceAdjust);
	//alert(Discount);
	//alert(ItemSavingsPerc);
	
	if (prodOptNo=="1") {
		// check if we even want to allow a click
		if (CheckCombi(prodOptID,origProdOptID2) != "0") {
			document.getElementById(prodOptIDName).value = parseFloat(prodOptID);
			document.getElementById(valueID).value=Text;
			document.getElementById(optionID).innerHTML=Text;
			document.getElementById(optionTempID).value=Text;
			
			
			if ((ProductOption2.innerHTML.length > 0) && (ProductOption2.innerHTML.search(/,/) == -1)) {
				ProductOption1.innerHTML=Text+",&nbsp;";
			} else {
				// calculate and display price and discount results
				ProductOption1.innerHTML=Text;
				
				//-> adjust listprice to match margin at any time
				if (PriceAdjust != 0) {
					// first we fix the discount to normal and calculate the list price based on adjusted unit price
					var CurrPrice = (parseFloat(PriceOrig) / parseFloat(Discount)) + parseFloat(PriceAdjust);
					
					// then we add the discount back on (discount on price AFTER adjustment - not BEFORE)
					CurrPrice = parseFloat(CurrPrice) * parseFloat(Discount);
					
					// now we print out the result
					ItemPrice.value = parseFloat(CurrPrice).toFixed(2);
					ProductPrice.innerHTML = "$" + parseFloat(CurrPrice).toFixed(2);
					
					//price / 1-discount = listprice (reverted)
					ProductListPrice.innerHTML = "<del>$" + ( CurrPrice / (1-ItemSavingsPerc) ).toFixed(2) + "</del>";
					
					// price savings in $
					var Sub = parseFloat(CurrPrice / (1-ItemSavingsPerc)) - parseFloat(CurrPrice);
					PriceChange.innerHTML = "$" + (Sub).toFixed(2) +"  (" + (ItemSavingsPerc*100).toFixed(1) + "%)" ;
					
				} else {
					ItemPrice.value = (parseFloat(PriceOrig)).toFixed(2);
					ProductPrice.innerHTML = "$" + (parseFloat(PriceOrig)).toFixed(2);
					ProductListPrice.innerHTML = "<del>$" + ( parseFloat(ListPrice) ).toFixed(2) + "</del>";
					
					var Sub = parseFloat(ListPrice) - parseFloat(PriceOrig);
					var Percent = (Sub/parseFloat(ListPrice))*100;
					PriceChange.innerHTML = "$" + (Sub).toFixed(2) +"  (" + (Percent).toFixed(1) + "%)" ;
					
				}
			}
			for (var i = 0; i < ProdOpt1.length; i++) {
				if (ProdOpt1[i] == prodOptID) {
					document.getElementById(ProdOpt1[i]).className = 'ProdOptActive';
				} else {
					if (document.getElementById(ProdOpt1[i]).className != 'ProdOptNotAvail') {
						document.getElementById(ProdOpt1[i]).className = 'ProdOptAvail';
					}
				}
			}
		}
	}
	
	// currently not used (if used it will need to be adjusted to option 1 level)
	if (prodOptNo=="2") {
		// check if we even want to allow a click
		if (CheckCombi(origProdOptID1,prodOptID) != "0") {
		
			document.getElementById('ItemPrice').value = parseFloat(PriceOrig)+parseFloat(PriceAdjust);
			document.getElementById(prodOptIDName).value = parseFloat(prodOptID);
			document.getElementById(valueID).value=Text;
			document.getElementById(optionID).innerHTML=Text;
			document.getElementById(optionTempID).value=Text;
			
			if ((ProductOption1.innerHTML.length > 0) && (ProductOption1.innerHTML.search(/,/) == -1)) {
				document.getElementById('ProductOption2').innerHTML=",&nbsp;"+Text;
			} else {
				document.getElementById('ProductOption2').innerHTML=Text;
				ProductOption1.innerHTML=Text;
				ProductPrice.innerHTML = "$" + parseFloat(PriceAdjust).toFixed(2);
				var Sub = parseFloat(ListPrice) - parseFloat(PriceAdjust);
				var Percent = (Sub/parseFloat(ListPrice))*100;
				PriceChange.innerHTML = "$" + Sub +"  (" + Percent + "%)" ;
			}
			for (var i = 0; i < ProdOpt2.length; i++) {
				if (ProdOpt2[i] == prodOptID) {
					document.getElementById(ProdOpt2[i]).className = 'ProdOptActive';
				} else {
					if (document.getElementById(ProdOpt2[i]).className != 'ProdOptNotAvail') {
						document.getElementById(ProdOpt2[i]).className = 'ProdOptAvail';
					}
				}
			}
		}
	}
	
	// enable or disable checkout button
	switch (ProductOptions) {
	case "11":
		if (document.getElementById('ProdOptID1').value != "" && document.getElementById('ProdOptID2').value != "") {
			document.getElementById('SubmitBtn').src='_assets/images/buttons/addtocart.gif';
			document.getElementById('SubmitBtn').enabled=true;
		} else {
			document.getElementById('SubmitBtn').src='_assets/images/buttons/addtocart_disabled.gif';
			document.getElementById('SubmitBtn').enabled=false;
		}
		break;    
	
	case "10":
		if (document.getElementById('ProdOptID1').value != "") {
			document.getElementById('SubmitBtn').src='_assets/images/buttons/addtocart.gif';
			document.getElementById('SubmitBtn').enabled=true;
		} else {
			document.getElementById('SubmitBtn').src='_assets/images/buttons/addtocart_disabled.gif';
			document.getElementById('SubmitBtn').enabled=false;
		}
		break;
		
	case "01":
		if (document.getElementById('ProdOptID2').value != "") {
			document.getElementById('SubmitBtn').src='_assets/images/buttons/addtocart.gif';
			document.getElementById('SubmitBtn').enabled=true;
		} else {
			document.getElementById('SubmitBtn').src='_assets/images/buttons/addtocart_disabled.gif';
			document.getElementById('SubmitBtn').enabled=false;
		}
		break;
	
	default:
		// do nothing
	}
}

// roll over function (OVER) | id1 = BoxID (actual ProdOptID) / id2 = LabelID (id of the element that is going to hold the option name) / txt = OptionName
function ShowPreView(prodOptNo,id1,id2,txt) {
	var prodOptBox			= document.getElementById(id1);
	var prodOptLabel		= document.getElementById(id2);
	var origProdOptID1 		= document.getElementById('ProdOptID1').value;
	var origProdOptID2 		= document.getElementById('ProdOptID2').value;
	
	// loop through all options and find the combi that does not exist - mark as not available
	if (prodOptNo=="1") {
		
		// check if we even want to allow a roll over
		if (CheckCombi(id1,origProdOptID2) != "0") {
			if (ProdOpt2.length > 0 ) { 
				for (var i = 0; i < ProdOpt2.length; i++) {
					//write option into label
					prodOptLabel.innerHTML=txt;
					
					//do rollover
					prodOptBox.className = 'ProdOptActive';
					
					//check if this combi is available
					if (CheckCombi(id1,ProdOpt2[i]) == "0") {
						document.getElementById(ProdOpt2[i]).className = 'ProdOptNotAvail';
					} else {
						if (document.getElementById(ProdOpt2[i]).className != 'ProdOptActive') {
							document.getElementById(ProdOpt2[i]).className = 'ProdOptAvail';
						}
					}
				}
			} else {
				//write option into label
				prodOptLabel.innerHTML=txt;
				
				//do rollover
				prodOptBox.className = 'ProdOptActive';
			}
		}
	}
	
	if (prodOptNo=="2") {
		// check if we even want to allow a roll over
		if (CheckCombi(origProdOptID1,id1) != "0") {
			if (ProdOpt1.length > 0 ) {
				for (var i = 0; i < ProdOpt1.length; i++) {
					//write option into label
					prodOptLabel.innerHTML=txt;
					
					//do rollover
					prodOptBox.className = 'ProdOptActive';
					
					if (CheckCombi(ProdOpt1[i],id1) == "0") {
						document.getElementById(ProdOpt1[i]).className = 'ProdOptNotAvail';
					} else {
						if (document.getElementById(ProdOpt1[i]).className != 'ProdOptActive') {
							document.getElementById(ProdOpt1[i]).className = 'ProdOptAvail';
						}
					}
				}
			} else {
				//write option into label
				prodOptLabel.innerHTML=txt;
				
				//do rollover
				prodOptBox.className = 'ProdOptActive';
			}
		}
	}

}

// rollover function (OUT) | id1 = BoxID / id2 = LabelID / id3 = ActiveOptionID 
function RestorePreView(prodOptNo,id1,id2,id3) {
	//alert(document.getElementById(id1).innerHTML+' - '+document.getElementById(id2).value);
	var prodOptBox		= document.getElementById(id1);
	var prodOptLabel	= document.getElementById(id2);
	var prodOptActive 	= document.getElementById(id3);
	var origProdOptID1  = document.getElementById('ProdOptID1').value;
	var origProdOptID2  = document.getElementById('ProdOptID2').value;
	
	prodOptLabel.innerHTML = prodOptActive.value;
	
	//only restore if we rollover an active or available option else ignore
	if (prodOptBox.className != 'ProdOptNotAvail') {
		
		//do rollout
		if (prodOptBox.innerHTML != prodOptActive.value) {
			prodOptBox.className = 'ProdOptAvail';
		}
		
		//restore the other options | if combi is not available mark as inactive
		if (prodOptNo=="1") {
			for (var i = 0; i < ProdOpt2.length; i++) {			
				if (document.getElementById(ProdOpt2[i]).innerHTML==document.getElementById('mySize22').value) {
					document.getElementById(ProdOpt2[i]).className = 'ProdOptActive';
				} else {
					document.getElementById(ProdOpt2[i]).className = 'ProdOptAvail';
				}
				
				if (CheckCombi(origProdOptID1,ProdOpt2[i]) == "0") {
					document.getElementById(ProdOpt2[i]).className = 'ProdOptNotAvail';
				}
			}
		}
		
		if (prodOptNo=="2") {
			for (var i = 0; i < ProdOpt1.length; i++) {
				if (document.getElementById(ProdOpt1[i]).innerHTML==document.getElementById('mySize21').value) {
					document.getElementById(ProdOpt1[i]).className = 'ProdOptActive';
				} else {
					document.getElementById(ProdOpt1[i]).className = 'ProdOptAvail';
				}
				
				if (CheckCombi(ProdOpt1[i],origProdOptID2) == "0") {
					document.getElementById(ProdOpt1[i]).className = 'ProdOptNotAvail';
				}
			}
		}
	}
}

// check product availability (MULTI OPTION ONLY)
function CheckCombi(id1,id2) {
	var ProdOptMixStr = ProdOptMix.toString();
	var Needle = id1+'.'+id2;
	
	if (ProdOptMixStr.search(Needle)==-1) {
		return "0";
	} else {
		return "1";
	}
}

// control error message popup | a=behaviour | txt=error message | obj=element to display msg |  offsetX=position X | offsetY=position Y
function ToggleErrorMsg(a,txt,obj,offsetX,offsetY) {
	var id1 = document.getElementById('Value1').value;
	var id2 = document.getElementById('Value2').value;
	var c 	= document.getElementById('ErrorMsgBox');
	var e 	= document.getElementById('ErrorMsgTxt');
	var objX = findPosX(document.getElementById(obj))+offsetX;
	var objY = findPosY(document.getElementById(obj))+offsetY;
	
	if (txt.length==0) {
		txt = document.getElementById('ErrorTxt').value;
	}
	
	// set error text message
	e.innerHTML = txt;
	
	//set behaviour
	if (a=='on') {
		c.style.left=objX+'px';
		c.style.top=objY+'px';
	}
	if (a=='off') {
		c.style.left='-250px';
		c.style.top='-50px';
	}
	if (a=='check') {
		if (id1 != "" && id2 != "") {
			// later we can build a custom error msg and use innerHtml to display custom msg
			c.style.left='-250px';
			c.style.top='-50px';
		} else {
			c.style.left=objX+'px';
			c.style.top=objY+'px';
		}
	}
}

// check product form before submitting
function CheckRequired() {
	//alert(document.getElementById('CartAction').value);
	var InventoryCount = document.getElementById('InventoryCount').value;
	var ProductOptions = document.getElementById('ProductOptions').value;
	var origProdOptID1 = document.getElementById('ProdOptID1').value;
	var origProdOptID2 = document.getElementById('ProdOptID2').value;
	
	if (InventoryCount > 0) {
		switch (ProductOptions) {
			case "11":
				if (origProdOptID1.length==0) {
				   ToggleErrorMsg('check','','SubmitBtn',80,-10);
				   return false;
				}
				if (origProdOptID2.length==0) {
				   ToggleErrorMsg('check','','SubmitBtn',80,-10);
				   return false;
				}
				break;
			
			case "10":
				if (origProdOptID1.length==0) {
				   ToggleErrorMsg('check','','SubmitBtn',80,-10);
				   return false;
				}
				break;
			
			case "01":
				if (origProdOptID2.length==0) {
				   ToggleErrorMsg('check','','SubmitBtn',80,-10);
				   return false;
				}
				break;
		}
	
	} else {
		ToggleErrorMsg('on','Item Sold Out','SubmitBtn',80,-10);
		return false;	
	}
	
	return true;
}

// position of element on screen
function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    //alert('X: '+curleft);
	return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    //alert('Y: '+curtop);
	return curtop;
}


// HELPER FUNCTIONS
function roundNumber(num, dec) {
	var result = Math.round( Math.round( num * Math.pow( 10, dec + 1 ) ) / Math.pow( 10, 1 ) ) / Math.pow(10,dec);
	return result;
}

// -->