
var curProductName = '';
var curBackKitGroupId = '';
var curBackAltKitGroupId = '';
var hasConfiguration = false;
var hasEngraving = false;
var hasOptions = false;
var hasSendInMine = true;
var hasBuyNew= true;
var hasPartsOnly = false;
var isNewItem = false;
var isPartsOnlyItem = false;
var curPaintPrice = 0;
var curSendInMinePrice = 0;
var curBaseConfigPrice = 0;
var curHardwareOptionsPrice = 0;
var curExtrasPrice = 0;
var curWarrantyPrice = 0;
var curGiftWrappingPrice = 0;
var backRandomizer = new Array(5);
var curRandomizer = 0;

Event.observe(window, "load", setupDS, false);

function updateGiftWrapping(itemToChange){
	
	//alert(itemToChange);
	//alert($('dsGW' + itemToChange));
	
	var newColor = '';
	var itemSelect = $('dsGW' + itemToChange + 'Select');
	var curItemSelected = null;
	
	if (itemSelect != null && itemSelect.options[itemSelect.selectedIndex] != null){
		curItemSelected = itemSelect.options[itemSelect.selectedIndex];
		newColor = curItemSelected.text;
	}
	
	if (newColor.indexOf('(') > 0)
		newColor = newColor.substring(0, newColor.indexOf('('));
	
	if ($('dsGW' + itemToChange) != null)
		changeBGImage($('dsGW' + itemToChange), "../images/designStudio/gift_wrapping/" + itemToChange + "/" + getImgName(newColor) + ".png");
	
	if(itemToChange == 'paper'){
		if (curItemSelected.title != null && curItemSelected.title != '') curGiftWrappingPrice = curItemSelected.title; 
		else curGiftWrappingPrice = 0;
		updateGiftWrappingRibbon();
	}
	//
	//updateModelPrices();		
	updatePurchasePrices();
}

function updateGiftWrappingRibbon() {
	if (curGiftWrappingPrice == 0){
		if($('dsGWhribbonSelect') != null) {
			$('dsGWhribbonSelect').disabled = true;
			for (var i=0;i<$('dsGWhribbonSelect').options.length;i++) {
				$('dsGWhribbonSelect').options[i].selected = $('dsGWhribbonSelect').options[i].defaultSelected;
			}	
			updateGiftWrapping('hribbon');
		}
		if($('dsGWvribbonSelect') != null) {
			$('dsGWvribbonSelect').disabled = true;
			for (var i=0;i<$('dsGWvribbonSelect').options.length;i++) {
				$('dsGWvribbonSelect').options[i].selected = $('dsGWvribbonSelect').options[i].defaultSelected;
			}	
			updateGiftWrapping('vribbon');
		}
		if($('dsGWCardText') != null) {
			$('dsGWCardText').value = "";
			$('dsGWCardText').disabled = true;
		}
		
		
	} else {
		if($('dsGWhribbonSelect') != null) $('dsGWhribbonSelect').disabled = false;
		if($('dsGWvribbonSelect') != null) $('dsGWvribbonSelect').disabled = false;
		if($('dsGWCardText') != null) $('dsGWCardText').disabled = false;		
		
	}
		
}

function updateWarrantyPrice (newWarrantyPrice) {
	if (newWarrantyPrice == null  || newWarrantyPrice == ''){
		newWarrantyPrice = 0;
	}
	
	curWarrantyPrice = newWarrantyPrice;
	
	updateModelPrices();	
}



function buyProduct(isNew, isPartsOnly) {
    isNewItem = isNew;
	isPartsOnlyItem = isPartsOnly;
	if (!isPartsOnly){
		var installKitChecks = $('cwDSPOStep1').getElementsByTagName ('input')
		
		
		for (var i=0;i<installKitChecks.length;i=i+1) {
		
			if (installKitChecks[i] != null ){
				installKitChecks[i].checked = false;
			}
		
		}
			
	}
	
    nextStep('design');
}


function partsOnlyAddToCart() {
	
	curBaseConfigPrice = 0;
	var kitgroupId = $('productTypeKitGroupId').innerHTML;
	var typesSelectBox = $('Kit' + kitgroupId );
	var i;
	for (i=0;i<typesSelectBox.length;i=i+1) 
	{
		if (typesSelectBox.options[i] != null && getImgName(typesSelectBox.options[i].text) == 'parts_only'){
			typesSelectBox.selectedIndex = i;
		}
	}
	var pricesSelectBox = $('Kit' + kitgroupId + 'Prices');
	pricesSelectBox.selectedIndex = typesSelectBox.selectedIndex;
	
	
	var aspdnsfBox = document.getElementsByName('KitGroupID_' + kitgroupId);
	if (aspdnsfBox[0].selectedIndex != null)
		aspdnsfBox[0].selectedIndex = typesSelectBox.selectedIndex;
	
	
	
	var extrasCheckboxes = getElementsByClass('cwDSExtraControllers',$('cwDSLowerHiddenInfo'),'input');	
	
	
		
	for (i=0;i<extrasCheckboxes.length;i=i+1) {
	
		if (extrasCheckboxes[i] != null ){
			extrasCheckboxes[i].checked = false;
		}
	
	}

	var hardwareOptions = $('dsOptions').getElementsByTagName("input"); 
	
	var curOptKitGroupId, curOptGroup, m;
	
	for (l=0;l<hardwareOptions.length;l=l+1){
		hardwareOptions[l].checked = false;
	
	}
	if($('cartExtraDipslay') != null) $('cartExtraDipslay').checked=true;
	//if($('cwCustomWarranty') != null)
	//	$('cwCustomWarranty').checked = true;
	var noPartsOnlyStuff = getElementsByClass('nopartsonly',$('cwDSLowerHiddenInfo'),'select');
    for (i=0;i<noPartsOnlyStuff.length;i=i+1) {
	
		$('curItemColorShowing').innerHTML = 'none';
		var curPOKitGroupId = noPartsOnlyStuff[i].id;
		
		curPOKitGroupId = curPOKitGroupId.replace('Kit', '');
		
		$('curItemKitId').innerHTML = curPOKitGroupId;
		updateItemColor('none', curPOKitGroupId);
		acceptItemColor(true);
		$('dsPartsOnlyDesc').style.display = 'block';
		
	
	
    }	
	nextStep('config');
}



function sendInMineAddToCart() {
	
	curBaseConfigPrice = 0;
	var kitgroupId = $('productTypeKitGroupId').innerHTML;
	var typesSelectBox = $('Kit' + kitgroupId );
	var i;
	for (i=0;i<typesSelectBox.length;i=i+1) 
	{
		if (typesSelectBox.options[i] != null && getImgName(typesSelectBox.options[i].text) == 'colorization'){
			typesSelectBox.selectedIndex = i;
		}
	}
	var pricesSelectBox = $('Kit' + kitgroupId + 'Prices');
	pricesSelectBox.selectedIndex = typesSelectBox.selectedIndex;
	
	
	var aspdnsfBox = document.getElementsByName('KitGroupID_' + kitgroupId);
	if (aspdnsfBox[0].selectedIndex != null)
		aspdnsfBox[0].selectedIndex = typesSelectBox.selectedIndex;
	
	
	
	var extrasCheckboxes = getElementsByClass('cwDSExtraControllers',$('cwDSLowerHiddenInfo'),'input');	
	
	
		
	for (i=0;i<extrasCheckboxes.length;i=i+1) {
	
		if (extrasCheckboxes[i] != null ){
			extrasCheckboxes[i].checked = false;
		}
	
	}

	var hardwareOptions = $('dsOptions').getElementsByTagName("input"); 
	
	var curOptKitGroupId, curOptGroup, m;
	
	for (l=0;l<hardwareOptions.length;l=l+1){
		hardwareOptions[l].checked = false;
	
	}
	
	if($('cwCustomWarranty') != null)
		$('cwCustomWarranty').checked = true;
	
	/*
	var curOptKitGroupId, curOptGroup, m;
	for (l=0;l<hardwareOptions.length;l=l+1){
		
		if (!Element.hasClassName(hardwareOptions[l], 'dsOptOptionModel' + kitItemId)){
			curOptKitGroupId = hardwareOptions[l].id;
			
			curOptKitGroupId = curOptKitGroupId.replace("dsOptOptionKitGroup","");
			
			
			curOptGroup = document.getElementsByName('KitGroupID_' + curOptKitGroupId);
			
			for (m=0;m<curOptGroup.length;m=m+1){
				
				if(m==0)
					curOptGroup[m].checked = true;
				else
					curOptGroup[m].checked = false;
				
			}
		}		
		
		
	}
	*/
	
	
	
	//showEngraving();


	nextStep('config');
}

function nextStep(lastStep){
    $('dsDisplayImages').style.display = 'none';
    $('dsRightMenu').style.display = 'none';
    $('dsEngraving').style.display = 'none';
    $('dsEngControls').style.display = 'none';
    $('dsWallMatching').style.display = 'none';
    $('dsModelSelection').style.display = 'none';
    //$('dsOptions').style.display = 'none';
    $('dsColorization').style.display = 'none';
    $('dsPartsOnlyDesc').style.display = 'none';
    $('dsRandomDesign').style.display = 'none';
    $('dsColorizationRapidReturn').style.display = 'none';
	$('dsEmailFormWrapper').style.visibility = 'hidden';
	//|| lastStep == 'engrave'
	// 
	
	//alert(lastStep);
	if (hasConfiguration && (lastStep == 'design' ) && isNewItem) {
        showModelSelection();
	} else if ((lastStep == 'design') && isPartsOnlyItem) {
		showPartsOnly();
	} else if ((lastStep == 'design') && !isNewItem) {
		if ($('rapidReturnWrapper') != null) 
        	$('dsColorizationRapidReturn').style.display = 'block';
		else
        	$('dsColorization').style.display = 'block';
		
		
	} else if (hasEngraving && (lastStep == 'design' || lastStep == 'config')) {
		showEngraving(); 
		//yesEngrave();
		
		
	} else if (hasOptions && isNewItem && lastStep!= 'options')  {showOptions();
	} else callUpdate();
    

}

function showPartsOnly(){
	var noPartsOnlyStuff = getElementsByClass('nopartsonly',$('cwDSLowerHiddenInfo'),'select');
	if (noPartsOnlyStuff == ''){
		$('dsPartsOnlyDesc').style.display = 'block';
	} else {
		for (i=0;i<noPartsOnlyStuff.length;i=i+1) {
		
			if (noPartsOnlyStuff[i] != null){
				if(noPartsOnlyStuff[i].options[noPartsOnlyStuff[i].selectedIndex].innerHTML.toLowerCase() != 'chrome' && noPartsOnlyStuff[i].options[noPartsOnlyStuff[i].selectedIndex].innerHTML.toLowerCase() != 'none'){
					if (confirm('Frame is only available with "Send In Mine".  Continue without frame?')) {
						
						$('curItemColorShowing').innerHTML = 'chrome';
						var curPOKitGroupId = noPartsOnlyStuff[i].id;
						
						curPOKitGroupId = curPOKitGroupId.replace('Kit', '');
						
						$('curItemKitId').innerHTML = curPOKitGroupId;
						updateItemColor('chrome', curPOKitGroupId);
						acceptItemColor(true);
						$('dsPartsOnlyDesc').style.display = 'block';
						
					} else {
						goBackToDS('dsPartsOnlyDesc');
					}
				} else {
					
						$('dsPartsOnlyDesc').style.display = 'block';
				}
			}
		
		}	
	}
}


function showModelSelection() {
	if(hasWallMatching()) {
		$('dsWallMatching').style.display = 'block';
		var wallMatchingWarranty = getElementsByClass('dsWallMatchingDefWar',$('dsWallMatching'),'input');
		if (wallMatchingWarranty[0] != null ) wallMatchingWarranty[0].checked = true;	
		
		$('dsWMDisDetailsBrand').innerHTML = $('wallMatchingText1').value;
		$('dsWMDisDetailsDesc').innerHTML = $('wallMatchingText2').value;
		$('dsWMDisDetailsCode').innerHTML = $('wallMatchingText3').value;
		
		
	} else	{
		$('dsModelSelection').style.display = 'block';
		var modelSelectWarranty = getElementsByClass('dsModelSelectDefWar',$('dsModelSelection'),'input');
		if (modelSelectWarranty[0] != null ) modelSelectWarranty[0].checked = true;
	}
	
	updateModelPrices();

}

function updatePurchasePrices() {
	$('dsSendInMinePrice').innerHTML = '$' + (parseFloat(curPaintPrice) + parseFloat(curSendInMinePrice) + parseFloat(curGiftWrappingPrice));
	$('dsBuyNewPrice').innerHTML = '$' + (parseFloat(curPaintPrice) + parseFloat(curBaseConfigPrice) + parseFloat(curExtrasPrice) + parseFloat(curGiftWrappingPrice));
	if($('dsPartsOnlyPrice') != null) {
		$('dsPartsOnlyPrice').innerHTML = '$' + (parseFloat(curPaintPrice) + parseFloat(curGiftWrappingPrice));
	}
}

function updateModelPrices() {
	var modelPriceDivs = getElementsByClass('dsModelPrice',$('dsModelSelection'),'div');
	var modelOrgPriceDivs = getElementsByClass('dsModelOrgPrice',$('dsModelSelection'),'div');
	
    for (i=0;i<modelPriceDivs.length;i=i+1) {
	
        if (modelPriceDivs[i] != null && modelPriceDivs[i].innerHTML != null){
        	if (modelOrgPriceDivs[i] != null && modelOrgPriceDivs[i].innerHTML != null){
	        	modelPriceDivs[i].innerHTML = '$' + (parseFloat(modelOrgPriceDivs[i].innerHTML) + parseFloat(curPaintPrice) + parseFloat(curExtrasPrice) + parseFloat(curWarrantyPrice) + parseFloat(curGiftWrappingPrice));
			}
        }
	
    }
	
}

function hasWallMatching() {
	var paintedItemSelectBoxes = getElementsByClass('cwDSPaintedItem',$('cwDSLowerHiddenInfo'),'select');
    for (i=0;i<paintedItemSelectBoxes.length;i=i+1) {
        if (paintedItemSelectBoxes[i] != null && paintedItemSelectBoxes[i].innerHTML != null && paintedItemSelectBoxes[i].selectedIndex != null && paintedItemSelectBoxes[i].options[paintedItemSelectBoxes[i].selectedIndex] != null){
			if (getImgName(paintedItemSelectBoxes[i].options[paintedItemSelectBoxes[i].selectedIndex].text) == 'wall_matching')	return true;					
        }
    }
	return false;
}

function showOptions() {
    
    
	var optionDivs = getElementsByClass('dsOptOption', $('dsOptionsList'), 'div');
	var optionName = '';
	var iconDiv = null;
    for (optDivCounter=0;optDivCounter<optionDivs.length;optDivCounter=optDivCounter+1) 
	{
	
	    optionName = optionDivs[optDivCounter].title;
	    optionName = getImgName(optionName);
	    optionDivs[optDivCounter].style.backgroundImage = "url(../images/designStudio/options/subheads/" + optionName + ".gif)";
		
	    
	    iconDiv = getElementsByClass('dsOptIcon', optionDivs[optDivCounter], 'div');
	    
	    
        for (iconCounter=0;iconCounter<iconDiv.length;iconCounter=iconCounter+1) 
	    {
	        iconDiv[iconCounter].style.backgroundImage = "url(../images/designStudio/options/Icons/" + optionName + ".jpg)";
	    }
	    
	    /*
		kitGroupID = optionDivs[j].id.substring(9);
		if (optionDivs[j].title == 'back'){
		    curBackKitGroupId = kitGroupID;
		    optionDivs[j].title = '';
		}
		namesSelectBox = $('Kit' + kitGroupID );
		colorSelected = namesSelectBox.options[namesSelectBox.selectedIndex];
		imageName = getImgName(colorSelected.text);
		updateItemColor(imageName, kitGroupID);
		*/
		
		
	}
	
	
    var baseContinuePrice = parseFloat(curBaseConfigPrice) + parseFloat(curPaintPrice) + parseFloat(curExtrasPrice);
	addHardwareOptionsClickEvents();
	$('dsOptContinue').innerHTML = "$" + baseContinuePrice;
    $('dsOptions').style.display='block';
}


function addHardwareOptionsClickEvents(){
    var stringSummaryUL = "<ul>";
    var hoInputs = $('dsOptionsList').getElementsByTagName('input');
    var kitGroupId = "";
	for (i=0;i<hoInputs.length;i=i+1) 
	{
		//hoInputs[i].addEventListener('change',hoSelected,false);  //todo fix in IE7
		//attachThisEvent(hoInputs[i], 'change', hoSelected);
		
		if (!Element.hasClassName(hoInputs[i], 'cwOptNotSelectedModelInput')){
			attachThisEvent(hoInputs[i], 'keydown', hoSelected);
			attachThisEvent(hoInputs[i], 'click', hoSelected);
			
			
			kitGroupId = hoInputs[i].name;
			
			kitGroupId = kitGroupId.replace('KitGroupID_', '');
		
			if (kitGroupId.indexOf('_') > 0)
				kitGroupId = kitGroupId.substring(0, (kitGroupId.indexOf('_')));
				
				
			if(hoInputs[i].type == 'checkbox' && !hoInputs[i].checked){
				stringSummaryUL += "<li id='dsOptListItem" + kitGroupId + "' class='notChecked'>" + $('dsOpt' + hoInputs[i].value + 'Name').innerHTML + "</li>";
			} else if (hoInputs[i].checked){
				stringSummaryUL += "<li id='dsOptListItem" + kitGroupId + "' >" + $('dsOpt' + hoInputs[i].value + 'Name').innerHTML + "</li>";
			}
			
		
		}
	}
    /*var hoSelects = $('dsOptionsList').getElementsByTagName('select');
	for (i=0;i<hoSelects.length;i=i+1) 
	{
		hoSelects[i].addEventListener('change',hoSelected,false);
        stringSummaryUL += "<li>" + $('dsOpt' + hoSelects[i].value + 'Name').innerHTML + "</li>";
	}*/
    stringSummaryUL  += "</ul>";
	$('dsOptionsSummary').innerHTML = stringSummaryUL;
}

function hoSelected(theEvent){
	
	
	
	if (typeof theEvent == "undefined"){
		theEvent = window.event;
	}
	var optionSelected = null;
	theEvent.target? optionSelected=theEvent.target : optionSelected=theEvent.srcElement; 
	var kitGroupID = optionSelected.name;
	kitGroupID = kitGroupID.replace('KitGroupID_', '');
	
	if (kitGroupID.indexOf('_') > 0){
	    kitGroupID = kitGroupID.substring(0, (kitGroupID.indexOf('_')));
	}
	
	
	
    
    
	var itemValue = optionSelected.value;
	/*itemValue = itemValue.replace('KitGroupID_', '');
	
	if (itemValue.indexOf('_') > 0){
	    itemValue = itemValue.substring(0, (itemValue.indexOf('_')));
	}*/
	
	
	$('dsOptListItem' + kitGroupID).innerHTML = $('dsOpt' + itemValue + 'Name').innerHTML ;
	$('dsOptListItem' + kitGroupID).style.display = 'list-item';
	
	
	
	if(optionSelected.type == 'radio') {
		var radioForm = optionSelected.form;
		var radioGroup = document.getElementsByName('KitGroupID_' + kitGroupID);
		
		
		//var radioGroup = radioForm.getInputs('radio', ('KitGroupID_' + kitGroupID));
		
        for (j=0;j<radioGroup.length;j=j+1) 
        {
            if (radioGroup[j].defaultChecked){
                curHardwareOptionsPrice -= parseFloat($('dsOpt' + radioGroup[j].value + 'Price').innerHTML);
                radioGroup[j].defaultChecked = false;
            }
        }
		
	}
	
	
	if (optionSelected.type == 'radio'){
	    optionSelected.defaultChecked = true;
	    curHardwareOptionsPrice += parseFloat($('dsOpt' + itemValue + 'Price').innerHTML);
	} else if(optionSelected.type == 'checkbox' && !optionSelected.checked){
	    $('dsOptListItem' + kitGroupID).style.display = 'none';
	    curHardwareOptionsPrice -= parseFloat($('dsOpt' + itemValue + 'Price').innerHTML);
	} else {
	    curHardwareOptionsPrice += parseFloat($('dsOpt' + itemValue + 'Price').innerHTML);
	}
    
	
    var baseContinuePrice = parseFloat(curBaseConfigPrice) + parseFloat(curPaintPrice) + parseFloat(curExtrasPrice) + parseFloat(curHardwareOptionsPrice);
	$('dsOptContinue').innerHTML = "$" + baseContinuePrice;
	
}

function selectModel(kitItemId, kitGroupId){
    var typesSelectBox = $('Kit' + kitGroupId );
    for (i=0;i<typesSelectBox.length;i=i+1) 
    {
        if (typesSelectBox.options[i] != null && typesSelectBox.options[i].value == kitItemId){
	        typesSelectBox.selectedIndex = i;
        }
    }
    var pricesSelectBox = $('Kit' + kitGroupId + 'Prices');
    pricesSelectBox.selectedIndex = typesSelectBox.selectedIndex;
    
	var aspdnsfBox = document.getElementsByName('KitGroupID_' + kitGroupId);
	if (aspdnsfBox[0].selectedIndex != null)
		aspdnsfBox[0].selectedIndex = typesSelectBox.selectedIndex;
    
	
	
	var hardwareOptions = getElementsByClass(('dsOptOptionModel' + kitItemId), null, 'div');
	var l = 0;
	
	for (l=0;l<hardwareOptions.length;l=l+1){
		
		hardwareOptions[l].style.display = 'block';
		
		
	}
	
	
	hardwareOptions = getElementsByClass('dsMultiModelOption', null, 'div');
	var curOptKitGroupId, curOptGroup, m;
	for (l=0;l<hardwareOptions.length;l=l+1){
		
		if (!Element.hasClassName(hardwareOptions[l], 'dsOptOptionModel' + kitItemId)){
			curOptKitGroupId = hardwareOptions[l].id;
			
			curOptKitGroupId = curOptKitGroupId.replace("dsOptOptionKitGroup","");
			
			
			curOptGroup = document.getElementsByName('KitGroupID_' + curOptKitGroupId);
			
			for (m=0;m<curOptGroup.length;m=m+1){
				
				if(m==0)
					curOptGroup[m].checked = true;
				else
					curOptGroup[m].checked = false;
				
			}
		}		
		
		
	}
	
    curBaseConfigPrice = pricesSelectBox.options[pricesSelectBox.selectedIndex].text;
    nextStep('config');
        
}




function showEngraving(){
	//new Effect.Appear('dsEngraving');
    $('dsEngraving').style.display = 'block';
    $('dsEngControls').style.display = 'block';    
		
    var namesSelectBox = $('Kit' + curBackKitGroupId );
	var colorSelected = namesSelectBox.options[namesSelectBox.selectedIndex];
    var imageName = getImgName(colorSelected.text);	if (imageName == 'chrome') {
		$('dsEngraveingTitle').style.backgroundImage = "url(../images/designStudio/engraving/diamond.gif)";
	}
	$('dsEngDisplayWrapper').className = '';
	$('dsEngDisplayWrapper').addClassName(imageName);
	$('dsEngDisplayWrapper').addClassName(curProductName);
	changeBGImage($('dsEngraveingMain'), "../products/" + curProductName + "/eng" + curBackKitGroupId + "/" + imageName + ".png");
	
	
	
    var namesSelectBoxAlt = $('Kit' + curBackAltKitGroupId );
	if (namesSelectBoxAlt != null) {
		var colorSelectedAlt = namesSelectBoxAlt.options[namesSelectBoxAlt.selectedIndex];
		var imageNameAlt = getImgName(colorSelectedAlt.text);
		if(imageNameAlt == 'same_as_main') imageNameAlt = imageName;
		changeBGImage($('dsEngravingAltBG'), "../products/" + curProductName + "/eng" + curBackAltKitGroupId + "/" + imageNameAlt + ".png");
	}
	//todo check for chrome and change BG images in engraving area
	
	if(isIE6cw == null || !isIE6cw)  changeBGImage($('dsEngControls'), "../images/designStudio/engraving/window.png");
}

function yesEngrave() {
    $('dsEngShadeOutBG').style.background = 'none';
    //$('dsEngSplash').style.display = 'none';
    //$('dsEngLeftControls').style.display = 'block';
    //$('dsEngCenterControls').style.display = 'block';
    //$('dsEngRightControls').style.display = 'block';
}

function updateEngraving(changedTextbox){
	$(changedTextbox.id + 'Display').innerHTML = changedTextbox.value;
	
	/*
	$('dsEngTopLineDisplay').innerHTML = $('dsEngTopLine').value;
	$('dsEngBottomLineDisplay').innerHTML = $('dsEngBottomLine').value;
	*/
}


function resetEngraveForm() {
    $('dsEngTopLine').value = 'Type Your Message Here...';
    $('dsEngBottomLine').value = '...And Here.  50 Character Per Line.';
    $('dsEngTopLineDisplay').innerHTML = '';
    $('dsEngBottomLineDisplay').innerHTML = '';
}


function callUpdate() {
	var kitGroupID, namesSelectBox, colorSelected, imageName, aspdnsfBox, pricesSelectBox, items;
	items = getElementsByClass('dsBGDisplays', null, null);
	for (j=0;j<items.length;j=j+1){
		kitGroupID = items[j].id.substring(9);
		namesSelectBox = $('Kit' + kitGroupID );
		pricesSelectBox = $('Kit' + kitGroupID + 'Prices' );
		aspdnsfBox = document.getElementsByName('KitGroupID_' + kitGroupID);
		
		
		if (aspdnsfBox[0].selectedIndex != null)
			aspdnsfBox[0].selectedIndex = namesSelectBox.selectedIndex;

	}
	$('dsLowerSection').style.display = 'none';
	$('dsDetailsHeader').style.display = 'none';
	$('dsMainHeader').style.display = 'none';
	$('designStudio').style.display = 'none';
	$('cwAddingToCart').style.display = 'block';
	
	
	if($('CartRecID') != null && $('CartRecID').value == 0){
		$('dsForm').submit();
		setTimeout("sendAddToCart();",250);
	} else {
		$('dsForm').target = "_top";
		$('dsForm').submit();
	}
}

function createCustomColor() {

}

function deleteCustomColor() {
    if(confirm('are you sure you want to delete this color?')){
    
    }
}

function applyCustomColor() {

}


function goBackToDS(fromDiv) {
    //new Effect.Fade(fromDiv);
	if (fromDiv == 'dsEngraving') $('dsEngControls').style.display = 'none';
    $(fromDiv).style.display = 'none';
	//new Effect.Appear('dsDisplayImages');
    $('dsRandomDesign').style.display = 'block';
    $('dsDisplayImages').style.display = 'block';
	//new Effect.Appear('dsRightMenu');
    $('dsRightMenu').style.display = 'block';
	
}

function openCustomColor() {

	//new Effect.Appear('dsCCBorder');
    $('dsCCBorder').style.display = 'block';
    //new Effect.Fade('dsDisplayImages');
    $('dsDisplayImages').style.display = 'none';
    //new Effect.Fade('dsItemSelected');
    $('dsItemSelected').style.display = 'none';
    //new Effect.Fade('dsRightMenu');
    $('dsRightMenu').style.display = 'none';



}


function closeCCWindow () {
    hideItemSelected();
    goBackToDS('dsCCBorder');
}

function saveEngraving() {
	var engNameHolder = "";
	var engLineFinalBoxes = null;
	clearEngraving();
	if ($('hiddenEngraving1') != null) {
		$('hiddenEngraving1').value = $('dsEngTopLine').value;
		engNameHolder = $('hiddenEngraving1').name;
		engNameHolder = engNameHolder.substring(0, engNameHolder.indexOf('custom'));
		engLineFinalBoxes = document.getElementsByName(engNameHolder);
		if (engLineFinalBoxes[0] != null) engLineFinalBoxes[0].value = $('dsEngTopLine').value;
	}
	if ($('hiddenEngraving2') != null) {
		$('hiddenEngraving2').value = $('dsEngBottomLine').value;
		engNameHolder = $('hiddenEngraving2').name;
		engNameHolder = engNameHolder.substring(0, engNameHolder.indexOf('custom'));
		engLineFinalBoxes = document.getElementsByName(engNameHolder);
		if (engLineFinalBoxes[0] != null) engLineFinalBoxes[0].value = $('dsEngBottomLine').value;
	}
	if ($('selectEngravingCheckbox') != null && ($('dsEngTopLine').value != '' || $('dsEngBottomLine').value != '')) $('selectEngravingCheckbox').checked = true;
	callUpdate();
}

function skipEngraving() {
	var engNameHolder = "";
	var engLineFinalBoxes = null;
	if ($('hiddenEngraving1') != null){ 
		$('hiddenEngraving1').value = "";
		engNameHolder = $('hiddenEngraving1').name;
		engNameHolder = engNameHolder.substring(0, engNameHolder.indexOf('custom'));
		engLineFinalBoxes = document.getElementsByName(engNameHolder);
		if (engLineFinalBoxes[0] != null) engLineFinalBoxes[0].value = "";
	}
	if ($('hiddenEngraving2') != null) {
		$('hiddenEngraving2').value = "";	
		engNameHolder = $('hiddenEngraving2').name;
		engNameHolder = engNameHolder.substring(0, engNameHolder.indexOf('custom'));
		engLineFinalBoxes = document.getElementsByName(engNameHolder);
		if (engLineFinalBoxes[0] != null) engLineFinalBoxes[0].value = "";
	}
	if ($('selectEngravingCheckbox') != null) $('selectEngravingCheckbox').checked = false;
    callUpdate();
}

function clearEngraving() {
	if ($('dsEngTopLine').value == 'Type Your Message Here...') $('dsEngTopLine').value = "";
	if ($('dsEngBottomLine').value == '...30 Characters Per Line.') $('dsEngBottomLine').value = "";
}


function setupEngraving(){
	
	var engNameHolder1 = "";
	var engLineFinalBoxes1 = null;
	var engNameHolder2 = "";
	var engLineFinalBoxes2 = null;
	
	if ($('hiddenEngraving1') != null && $('hiddenEngraving2') != null) {
		
		engNameHolder1 = $('hiddenEngraving1').name;
		engNameHolder1 = engNameHolder1.substring(0, engNameHolder1.indexOf('custom'));
		engLineFinalBoxes1 = document.getElementsByName(engNameHolder1);
	
		engNameHolder2 = $('hiddenEngraving2').name;
		engNameHolder2 = engNameHolder2.substring(0, engNameHolder2.indexOf('custom'));
		engLineFinalBoxes2 = document.getElementsByName(engNameHolder2);
		
		if (engLineFinalBoxes1[0] != null && engLineFinalBoxes2[0] != null && (engLineFinalBoxes1[0].value != '' || engLineFinalBoxes2[0].value != '')){
			$('dsEngTopLine').value = engLineFinalBoxes1[0].value;
			$('hiddenEngraving1').value = $('dsEngTopLine').value;
			$('dsEngBottomLine').value = engLineFinalBoxes2[0].value;
			$('hiddenEngraving2').value = $('dsEngBottomLine').value;
		}
	}	
}


function sendAddToCart() {
	var myIFrame = top.myIFrame;
	var myProductId  = myIFrame.document.getElementById('ProductID');
	var myVariantId  = myIFrame.document.getElementById('VariantID');
	if (myProductId != null && myVariantId != null){
		var addToCartForm = myIFrame.document.getElementById('AddToCartForm_' + myProductId.value + "_" + myVariantId.value);
		addToCartForm.target = "_top";
		addToCartForm.submit();
	} else 
		setTimeout("sendAddToCart();",250);
	
}




function addRemoves(){
	//var items = getElementsByClass('dsItem', $('designStudio'), 'div');
	var items = getElementsByClass('dsRemoveButton', null, null);
	for (i=0;i<items.length;i=i+1) 
	{
		//items[i].addEventListener('click',removeItem,false);  //todo, fix in IE fails currently
		attachThisEvent(items[i], 'click', removeItem);
	}
	items = getElementsByClass('dsBGDisplays', null, null);
	var kitGroupID, namesSelectBox, colorSelected, imageName, aspdnsfBox, pricesSelectBox;
	for (j=0;j<items.length;j=j+1) 
	{
		kitGroupID = items[j].id.substring(9);
		if (items[j].title == 'back'){
		    curBackKitGroupId = kitGroupID;
		    items[j].title = '';
		}
		if (items[j].title == 'backAlt'){
		    curBackAltKitGroupId = kitGroupID;
		    items[j].title = '';
		}
		
		
		namesSelectBox = $('Kit' + kitGroupID );
		pricesSelectBox = $('Kit' + kitGroupID + 'Prices' );
		aspdnsfBox = document.getElementsByName('KitGroupID_' + kitGroupID);
		if (aspdnsfBox[0] != null && aspdnsfBox[0].selectedIndex != null){
			namesSelectBox.selectedIndex = aspdnsfBox[0].selectedIndex;
			pricesSelectBox.selectedIndex = aspdnsfBox[0].selectedIndex;
		}
		colorSelected = namesSelectBox.options[namesSelectBox.selectedIndex];
		imageName = getImgName(colorSelected.text);
		updateItemColor(imageName, kitGroupID);
		
		updateItemPrice(kitGroupID);
		
	
	
	}
	
	/*
	items.each(function(item){
		Event.observe(item, 'click', function(event){ );
	});*/
}




function preselectColors(colorParams){
	
	//var colorParams = " " + document.location;
	
	
	
	if (colorParams.indexOf('?') > 0)
		colorParams = colorParams.substring(colorParams.indexOf('?') + 1);
	else
		colorParams = '';
	
	
	
	
	if(colorParams == null || colorParams == '') return false;
	
	
	
	
	while (colorParams!='')
	{
		if (colorParams.indexOf('=') < 0) colorParams = '';
		else {
			kitGroupId = colorParams.substring(0, colorParams.indexOf('=') );
			if(IsNumeric(kitGroupId)){
				
				colorParams = colorParams.substring(colorParams.indexOf('=') + 1);
				kitGroupColor = colorParams.substring(0, colorParams.indexOf('&') );
				colorParams = colorParams.substring(colorParams.indexOf('&') + 1);
				if(kitGroupColor == '') kitGroupColor = colorParams;
				
				$('curItemColorShowing').innerHTML = kitGroupColor;
		
				$('curItemKitId').innerHTML = kitGroupId;
				
				updateItemColor(kitGroupColor, kitGroupId);
				
				
				acceptItemColor(true);
				//colorParams = '';
			} else {
				colorParams = '';
			}
		}
		
	}
	
	
	
	/*
	itemPrice = itemPrice.substring(0, itemPrice.indexOf('.'));
theleft = ;
theright = str.lastIndexOf("&");
return(str.substring(theleft, theright));
	
	
	
	//var items = getElementsByClass('dsItem', $('designStudio'), 'div');
	var items = getElementsByClass('dsRemoveButton', null, null);
	for (i=0;i<items.length;i=i+1) 
	{
		//items[i].addEventListener('click',removeItem,false);  //todo, fix in IE fails currently
		attachThisEvent(items[i], 'click', removeItem);
	}
	items = getElementsByClass('dsBGDisplays', null, null);
	var kitGroupID, namesSelectBox, colorSelected, imageName, aspdnsfBox, pricesSelectBox;
	for (j=0;j<items.length;j=j+1) 
	{
		kitGroupID = items[j].id.substring(9);
		if (items[j].title == 'back'){
		    curBackKitGroupId = kitGroupID;
		    items[j].title = '';
		}
		
		
		namesSelectBox = $('Kit' + kitGroupID );
		pricesSelectBox = $('Kit' + kitGroupID + 'Prices' );
		aspdnsfBox = document.getElementsByName('KitGroupID_' + kitGroupID);
		if (aspdnsfBox[0] != null && aspdnsfBox[0].selectedIndex != null){
			namesSelectBox.selectedIndex = aspdnsfBox[0].selectedIndex;
			pricesSelectBox.selectedIndex = aspdnsfBox[0].selectedIndex;
		}
		colorSelected = namesSelectBox.options[namesSelectBox.selectedIndex];
		imageName = getImgName(colorSelected.text);
		updateItemColor(imageName, kitGroupID);
		
		updateItemPrice(kitGroupID);
		
	
	
	}*/
	
}


function updateItemPrice(kitGroupId){
	
	
	var pricesSelectBox = $('Kit' + kitGroupId + 'Prices');
	var itemPrice = pricesSelectBox.options[pricesSelectBox.selectedIndex].text;
	if (itemPrice.indexOf('.') > 0)
	itemPrice = itemPrice.substring(0, itemPrice.indexOf('.'));
	
	if(parseFloat(itemPrice) > 0){
		
		$('dsItem' + kitGroupId + 'Price').innerHTML = '$' + itemPrice;
		curPaintPrice = parseFloat(curPaintPrice) + parseFloat(itemPrice);
		
		if (!Element.hasClassName($('dsItem' + kitGroupId), "dsMain")){
			$('dsItem' + kitGroupId).addClassName("dsRemove");
			$('dsItem' + kitGroupId).removeClassName("dsAdd");
		}
	}
	
	
	updatePurchasePrices();
	
	
	
	
}


function setupDS(){
	
	if ($('unfProductName') == null) return false;
	
    curProductName = getImgName($('unfProductName').innerHTML);
	
    $('dsDisplayImages').className = curProductName;
    addRemoves();
	preselectColors(" " + document.location);
	var docLocation = " " + document.location;
	
	if(docLocation.lastIndexOf('cartrecid') > 0) $('dsSendDesign').style.display = 'none';
	
	$('dsSaveConfig').innerHTML = docLocation;
	$('dsSaveConfig').href = docLocation;
	$('dsEmailUrl').value = docLocation.strip();
	$('dsEmailUrlEnd').value = docLocation.substring(docLocation.lastIndexOf('/') + 1);
    
	var kitgroupId = $('productStepsKitGroupId').innerHTML;
    var stepsSelectBox = $('Kit' + kitgroupId );
    for (i=0;i<stepsSelectBox.length;i=i+1) 
    {
	    if (stepsSelectBox.options[i] != null && getImgName(stepsSelectBox.options[i].text) == 'configuration'){
		    hasConfiguration = true;
	    }
	    if (stepsSelectBox.options[i] != null && getImgName(stepsSelectBox.options[i].text) == 'engraving'){
		    hasEngraving = true;
	    }
	    if (stepsSelectBox.options[i] != null && getImgName(stepsSelectBox.options[i].text) == 'options'){
		    hasOptions = true;
	    }
    }
	
	kitgroupId = $('productTypeKitGroupId').innerHTML;
    stepsSelectBox = $('Kit' + kitgroupId );
	var curKitItemID = 0;
    for (i=0;i<stepsSelectBox.length;i=i+1) 
    {
		if (stepsSelectBox.options[i] != null && stepsSelectBox.options[i].value != null){
			curKitItemID = stepsSelectBox.options[i].value;
			if ($('dsConfigHeaderImg' + curKitItemID) != null){
				$('dsConfigHeaderImg' + curKitItemID).src = '../products/' + curProductName + '/configuration/' + curKitItemID + '.png';
				
			}
			
		}
		
	//$('dsMainHeader').style.backgroundImage = "url()";
	
	
		
    }
	
	
	
	
	
	
	
	if(hasBuyNew) {
		$('dsBuyNew').style.display = 'block';
		$('dsPurchaseTopSpacerBuyNew').style.display = 'none';
	} else $('dsBuyNew').style.display = 'none';
	
	if(hasSendInMine) {
		$('dsSendInMine').style.display = 'block';
		$('dsPurchaseTopSpacerSendInMine').style.display = 'none';
	} else $('dsSendInMine').style.display = 'none';
	
	
	if(hasPartsOnly)  {
		$('dsPartsOnly').style.display = 'block';
		$('dsPurchaseTopSpacerPartsOnly').style.display = 'none';
	} else {
		if($('dsPartsOnly') != null) $('dsPartsOnly').style.display = 'none';
	}
	
	$('dsPurchaseSpacer').style.display = 'none';
	$('dsPurchaseSpacer2').style.display = 'none';
	
	if(hasBuyNew && hasSendInMine && hasPartsOnly){
		$('dsPurchaseSpacer').style.display = 'block';
		$('dsPurchaseSpacer2').style.display = 'block';
	} else{ 
		if (hasPartsOnly && (hasBuyNew || hasSendInMine)) {
			$('dsPurchaseSpacer').style.display = 'block';
		}
		if (hasBuyNew && hasSendInMine) {
			$('dsPurchaseSpacer2').style.display = 'block';
		}
	}
	
	
	$('dsMainHeader').style.backgroundImage = "url('../products/" + curProductName + "/main_header.gif')";
	$('dsDetailsHeader').style.backgroundImage = "url('../products/" + curProductName + "/detail_header.gif')";
	
	
	$('cwPFPFrame').src = "../products/" + curProductName + "/features.html";
	
	setTimeout("setupProductFeatures();",250);
	
	
	
	/*
	var kitId = $('basePaintPriceKitGroup').innerHTML;
	var pricesSelectBox = $('Kit' + kitId + 'Prices');
	var itemPrice = pricesSelectBox.options[pricesSelectBox.selectedIndex].text;
	if (itemPrice.indexOf('.') > 0)
		itemPrice = itemPrice.substring(0, itemPrice.indexOf('.'));
	
	$('dsItem' + kitId + 'Price').innerHTML = '$' + itemPrice;
	
	curPaintPrice = parseFloat(itemPrice);
*/	
//$('dsDisplayImages').style.display = 'none';
	changeBGImage($('dsDisplayImages1'), "../products/" + curProductName + "/background.jpg");
	changeBGImage($('dsDisplayImages2'), "../products/" + curProductName + "/background.png");
	changeBGImage($('dsDisplayImages3'), "../products/" + curProductName + "/background.gif");
	changeBGImage($('dsDiaplayImagesTopMost'), "../products/" + curProductName + "/screen.png");

	
	
	
	
	
	var hardwareOptionExtras = $('cwDSLowerHiddenInfo').getElementsByTagName("input"); 
	
	var selectedHardwareOption, priceOfOption, m;
	
	for (m=0;m<hardwareOptionExtras.length;m=m+1){
		
		
		if(hardwareOptionExtras[m] != null && hardwareOptionExtras[m].type == 'checkbox'){
			if (hardwareOptionExtras[m].checked == true) {
					
					selectedHardwareOption =  document.getElementsByName(hardwareOptionExtras[m].name + 'CWDS');
					
					if (selectedHardwareOption[0] != null)
						selectedHardwareOption[0].checked = true;
					
					if(hardwareOptionExtras[m].id == null || hardwareOptionExtras[m].id == '')
						hardwareOptionExtras[m].checked = false;
					
					if (hardwareOptionExtras[m].title != null && hardwareOptionExtras[m].title != ''){
						priceOfOption = parseFloat(hardwareOptionExtras[m].title);
						if(!priceOfOption) priceOfOption = 0;
						
						curExtrasPrice = parseFloat(curExtrasPrice) + parseFloat(priceOfOption);
					}
		
				
			}
		}
	
	}
	
	
	
	
	
	//double check extra items to make sure only painted ones are added
	var extrasCheckboxes = getElementsByClass('cwDSExtraControllers',$('cwDSLowerHiddenInfo'),'input');	
	var curCheckboxId = "";
	var priceOfOption = 0;
	
	for (i=0;i<extrasCheckboxes.length;i=i+1) {
		if (extrasCheckboxes[i] != null ){
			curCheckboxId = extrasCheckboxes[i].id;
			curCheckboxId = curCheckboxId.replace('ExtraCont', '');
			if ($(curCheckboxId) != null) {
				if(getImgName($(curCheckboxId).options[$(curCheckboxId).selectedIndex].text) == 'none') {
					
					if (extrasCheckboxes[i].checked){
						priceOfOption = parseFloat(extrasCheckboxes[i].title);
						if(!priceOfOption) priceOfOption = 0;
						
						curExtrasPrice = parseFloat(curExtrasPrice) - parseFloat(priceOfOption);
					}
					
					extrasCheckboxes[i].checked = false;
					
				}
			}
		}
	}
	
	
	
	updatePurchasePrices();
	
	setupEngraving();
	
	
	
	
	//new Effect.Appear('dsDisplayImages',{duration:1});
		
		//new Ajax.Updater('dsLowerSection', 'http://webdev/products/ipod_video/lower.html');

}

function setupProductFeatures()  {
	var cwPFPFrame = top.cwPFPFrame;
	var featuresWrapper = null;
	
	if (cwPFPFrame != null) {
			
		featuresWrapper  = cwPFPFrame.document.getElementById('cwFeaturesWrapper');
		if (featuresWrapper != null) {
			$('cwPFPContent').innerHTML = featuresWrapper.innerHTML;
			if($('dsPFPPreloadLink') != null){
				var preloadColorFromPFP = " " + $('dsPFPPreloadLink').innerHTML;
				preselectColors(preloadColorFromPFP.unescapeHTML());
			}
		} else {
			setTimeout("setupProductFeatures();",250);
		}
	}
	

}

function removeItem(theEvent)  {//clicking red x to remove an item
	if (typeof theEvent == "undefined"){
		theEvent = window.event;
	}
	if (typeof theEvent.stopPropagation != "undefined"){
		theEvent.stopPropagation();
	} else {
		theEvent.cancelBubble = true;
	}
	var kitGroupID = "";
	theEvent.target? kitGroupID=theEvent.target.id : kitGroupID=theEvent.srcElement.id; 
	kitGroupID = kitGroupID.replace("dsRemove","");
	removeItemById(kitGroupID);
	removeItemFromSaveLink(kitGroupID);
}

function removeItemById(kitGroupID) {

	
	
	var itemPrice = $('dsItem' + kitGroupID + 'Price').innerHTML.substring(1);
	var sendInPrice, buyNewPrice, buyNewExtraPrice;
	buyNewExtraPrice = 0;
	itemPrice = itemPrice * 1;
	sendInPrice = $('dsSendInMinePrice').innerHTML.substring(1) * 1 ;
	buyNewPrice = $('dsBuyNewPrice').innerHTML.substring(1) * 1 ;
	
	
	
	if ($('Kit' + kitGroupID + 'ExtraCont') != null) {
		$('Kit' + kitGroupID + 'ExtraCont').checked = false;
		buyNewExtraPrice = parseFloat($('Kit' + kitGroupID + 'ExtraCont').title);
		if(!buyNewExtraPrice) buyNewExtraPrice = 0;
		
		curExtrasPrice = parseFloat(curExtrasPrice) - parseFloat(buyNewExtraPrice);
	}
	
	
	//$('dsSendInMinePrice').innerHTML = '$' + (parseFloat(sendInPrice) - parseFloat(itemPrice));
	//$('dsBuyNewPrice').innerHTML = '$' + (parseFloat(buyNewPrice) - parseFloat(itemPrice) - parseFloat(buyNewExtraPrice));
	//todo, replace above using global variables
	
	curPaintPrice = parseFloat(curPaintPrice) - parseFloat(itemPrice);
	
	updatePurchasePrices();
	
	$('dsItem' + kitGroupID + 'Price').innerHTML = "";
	
	
	
	namesSelectBox = $('Kit' + kitGroupID );
	resetSelectBox(namesSelectBox);
	pricesSelectBox = $('Kit' + kitGroupID  + 'Prices');
	resetSelectBox(pricesSelectBox);
	colorSelected = namesSelectBox.options[namesSelectBox.selectedIndex];
	imageName = getImgName(colorSelected.text);
	updateItemColor(imageName, kitGroupID, true);
	
	
	
	if(imageName == 'white_keys' || imageName == 'black_keys') {
		
		
		var lowestModelPrice = 100000;
		var curModelPrice = 0;
		var lowestModelDiv = null;
		
		
		updateModelPrices();
		
		
		
		
		
		var blackModelDivs = getElementsByClass('dsInvSizeblack_keys',$('cwDSMSBottom'),'div');
		for (i=0;i<blackModelDivs.length;i=i+1){
			blackModelDivs[i].style.display = 'block';
			lowestModelDiv = getElementsByClass('dsModelPrice',blackModelDivs[i],'div');
			if(lowestModelDiv[0] != null){
				curModelPrice = lowestModelDiv[0].innerHTML.substring(1) * 1;
				if (curModelPrice < lowestModelPrice) lowestModelPrice = curModelPrice;
				
			}
		}
		var whiteModelDivs = getElementsByClass('dsInvSizewhite_keys',$('cwDSMSBottom'),'div');
		for (i=0;i<whiteModelDivs.length;i=i+1){
			whiteModelDivs[i].style.display = 'block';
			lowestModelDiv = getElementsByClass('dsModelPrice',whiteModelDivs[i],'div');
			if(lowestModelDiv[0] != null){
				curModelPrice = lowestModelDiv[0].innerHTML.substring(1) * 1;
				if (curModelPrice < lowestModelPrice) lowestModelPrice = curModelPrice;
				
			}
		}
		
		
		
		
		
		$('dsBuyNewPrice').innerHTML = '$' + lowestModelPrice;
		
		
		
		
		
		
		
		
		/*
		
		var blackModelDivs = getElementsByClass('dsInvSizeblack_keys',$('cwDSMSBottom'),'div');
		for (i=0;i<blackModelDivs.length;i=i+1){
			blackModelDivs[i].style.display = 'none';
		}
		var whiteModelDivs = getElementsByClass('dsInvSizewhite_keys',$('cwDSMSBottom'),'div');
		
		
		
		
		
		
		
		
		for (i=0;i<whiteModelDivs.length;i=i+1){
			whiteModelDivs[i].style.display = 'block';
			
			
			
			
			lowestModelDiv = getElementsByClass('dsModelPrice',whiteModelDivs[i],'div');
			if(lowestModelDiv[0] != null){
				curModelPrice = lowestModelDiv[0].innerHTML.substring(1) * 1;
				if (curModelPrice < lowestModelPrice) lowestModelPrice = curModelPrice;
				
			}
		}
		
		
		
		
		*/
		
		
		
		
		
	}
	
	if (!Element.hasClassName($('dsItem' + kitGroupID), "dsMain")){
		$('dsItem' + kitGroupID).addClassName("dsAdd");
		$('dsItem' + kitGroupID).removeClassName("dsRemove");
	}
	
	
}
var iMapTimeOut = 0;
var iMapTimer;
function areaOut(kitId, title)  {
    $('dsImgMap').src = '/images/designStudio/blank.gif';
	$('dsItem' + kitId).style.color = '#CCC';
	//$('dsDisplay' + kitId).style.opacity = '1';
	clearTimeout(iMapTimer);

}

function areaOver(kitId, title)  {
   
    iMapTimeOut=100;
    iMapTimer = setTimeout("areaOverTimed("+ kitId +")", iMapTimeOut);
}
function areaOverTimed(kitId, title)  {
    
    
	//new Effect.Fade('dsImgMap',{duration:0.01, from:1, to:0.15});
	$('dsImgMap').src = '/products/' + curProductName + '/rollovers/' + kitId + '.png';
	$('dsItem' + kitId).style.color = '#0087C7';
	//new Effect.Appear('dsImgMap', { duration: 0.1 });
    setTimeout("$('dsImgMap').src = '/images/designStudio/blank.gif';", 300);
    /*background-color:#000;
    filter:alpha(opacity=20);
    -moz-opacity: 0.2;
    opacity: 0.2;
    */
}

function showItemSelected(kitId, title)  {//open item selected screen
	$('dsBlackKeys').style.display = "none" ;
	$('dsWhiteKeys').style.display = "none" ;
	$('dsOriginalChrome').style.display = "none" ;
	$('dsMatteScreen').style.display = "none" ;
	$('dsGlossScreen').style.display = "none" ;
	$('dsGold').style.display = "none" ;
	$('dsWallMatchingButton').style.display = "none" ;
	$('dsCustomColor').style.display = "none";
	$('dsLogoDesclaimer').style.display = "none" ;
	$('dsMatteScreenDesclaimer').style.display = "none" ;
	$('curItemKitId').innerHTML = kitId;
	var hasOtherOptions =  false;
	var hasSolidColors =  false;
	var hasMetalicColors = false;
	var hasMetalicColors = false;
	var hasPearlColors = false;
	
	
	
	
	
	
	
	var colorAnchors = $('colorSwatches').getElementsByTagName("a");// getElementsByClass('imgItemColors', , 'a');
	var colorListItems = $('colorSwatches').getElementsByTagName("li");// getElementsByClass('imgItemColors', , 'a');
	for (i=0;i<colorListItems.length;i=i+1) 
	{
		
		if (!Element.hasClassName(colorListItems[i], "colorTypeTitle")){
			colorListItems[i].style.display = "none";
		}
		
	}
	var namesSelectBox = $('Kit' + kitId);
	
	//document.("input")
	
	
	
	
	
	/*
	var itemColors = getElementsByClass('imgItemColors', null, 'img');
	for (i=0;i<itemColors.length;i=i+1) 
	{
		itemColors[i].style.display = "none";
	}
	var namesSelectBox = $('Kit' + kitId);
	*/
	
	
	
	
	
	for (i=0;i<namesSelectBox.length;i=i+1) 
	{
		
		
		
		
		
		
		
		
	    var itemColor = getImgName(namesSelectBox.options[i].text);
	    if (itemColor == 'chrome'){
			$('dsOriginalChrome').style.display = "block" ;
			attachThisEvent($('dsOriginalChrome'), 'click', swatchClick);
			attachThisEvent($('dsOriginalChrome'), 'mouseover', changeItemColor);
			attachThisEvent($('dsOriginalChrome'), 'mouseout', resetItemColor);
			hasOtherOptions = true;
		}
	    if (itemColor == 'gold'){
			$('dsGold').style.display = "block" ;
			attachThisEvent($('dsGold'), 'click', swatchClick);
			attachThisEvent($('dsGold'), 'mouseover', changeItemColor);
			attachThisEvent($('dsGold'), 'mouseout', resetItemColor);
			hasOtherOptions = true;
		}
	    if (itemColor == 'custom_color_brand'){// hiding always for now until custom color is ready
			$('dsCustomColor').style.display = "block";
			itemColor = 'custom_color';
			attachThisEvent($('dsCustomColor'), 'click', swatchClick);
			attachThisEvent($('dsCustomColor'), 'mouseover', changeItemColor);
			attachThisEvent($('dsCustomColor'), 'mouseout', resetItemColor);
			hasOtherOptions = true;
	    }
	    if (itemColor == 'black_keys'){
			$('dsBlackKeys').style.display = "block" ;
			attachThisEvent($('dsBlackKeys'), 'click', swatchClick);
			attachThisEvent($('dsBlackKeys'), 'mouseover', changeItemColor);
			attachThisEvent($('dsBlackKeys'), 'mouseout', resetItemColor);
			hasOtherOptions = true;
		}
	    if (itemColor == 'white_keys'){
			$('dsWhiteKeys').style.display = "block" ;
			attachThisEvent($('dsWhiteKeys'), 'click', swatchClick);
			attachThisEvent($('dsWhiteKeys'), 'mouseover', changeItemColor);
			attachThisEvent($('dsWhiteKeys'), 'mouseout', resetItemColor);
			hasOtherOptions = true;
		}
	    if (itemColor == 'wall_matching'){
			$('dsWallMatchingButton').style.display = "block" ;
			attachThisEvent($('dsWallMatchingButton'), 'click', swatchClick);
			attachThisEvent($('dsWallMatchingButton'), 'mouseover', changeItemColor);
			attachThisEvent($('dsWallMatchingButton'), 'mouseout', resetItemColor);
			hasOtherOptions = true;
		}
	    if (itemColor == 'gloss_screen'){
			$('dsGlossScreen').style.display = "block" ;
			attachThisEvent($('dsGlossScreen'), 'click', swatchClick);
			attachThisEvent($('dsGlossScreen'), 'mouseover', changeItemColor);
			attachThisEvent($('dsGlossScreen'), 'mouseout', resetItemColor);
			hasOtherOptions = true;
		}
	    if (itemColor == 'matte_screen'){
			$('dsMatteScreen').style.display = "block" ;
			attachThisEvent($('dsMatteScreen'), 'click', swatchClick);
			attachThisEvent($('dsMatteScreen'), 'mouseover', changeItemColor);
			attachThisEvent($('dsMatteScreen'), 'mouseout', resetItemColor);
			hasOtherOptions = true;
		}
	    if (itemColor == 'logodesclaimer'){
			$('dsLogoDesclaimer').style.display = "block" ;
		}		
	    if (itemColor == 'mattescreendesclaimer'){
			$('dsMatteScreenDesclaimer').style.display = "block" ;
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		var curItem = $('ics' + itemColor);
		if (curItem != null) {
			hasSolidColors = true;
		} else {
			curItem = $('icm' + itemColor);
					
			if (curItem != null) {
				hasMetalicColors = true;
			} else {
				
				curItem = $('icp' + itemColor);
				
				
				if (curItem != null) {
					hasPearlColors = true;
				}
				
			}
		}
		
		
		
		
		
		
		//var curItem = $('ic' + itemColor);
		if (curItem != null){
			curItem.style.display = "block";
			//curItem.addEventListener('click',updateItemColor,false);  //todo, fix in IE
			attachThisEvent(curItem, 'click', swatchClick);
			//curItem.addEventListener('mouseover',changeItemColor,false);  //todo, fix in IE
			attachThisEvent(curItem, 'mouseover', changeItemColor);
			//curItem.addEventListener('mouseout',resetItemColor,false);  //todo, fix in IE
			attachThisEvent(curItem, 'mouseout', resetItemColor);
		}
		
		
		
		
		
		
		
		
		
		
		
	}
	$('dsOtherOptions').style.display = "block";
	if (hasOtherOptions){
	     $('dsOtherOptions').style.visibility = "visible";
	} else {
	     $('dsOtherOptions').style.visibility = "hidden";
	}
	if (hasSolidColors){
	     $('icsSolidTitle').style.display = "block";
	} else {
	     $('icsSolidTitle').style.display = "none";
	}
	if (hasMetalicColors){
	     $('icmMetallicTitle').style.display = "block";
	} else {
	     $('icmMetallicTitle').style.display = "none";
	}
	
	if (hasPearlColors){
	     $('icpPearlTitle').style.display = "block";
	} else {
	     $('icpPearlTitle').style.display = "none";
	}
	
	var colorSelected = namesSelectBox.options[namesSelectBox.selectedIndex];
	var imageName = getImgName(colorSelected.text);
	$('curItemColorShowing').innerHTML = imageName;
	$('dsCurColor').style.backgroundImage = "url('../images/designStudio/MySelection/" + imageName + ".png')";
	//updateItemColor(imageName);
	//changeItemColor(imageName);
	
	
	$('isTitle').innerHTML = title;
	
	
	var pricesSelectBox = $('Kit' + kitId + 'Prices');
	var itemPrice = pricesSelectBox.options[pricesSelectBox.selectedIndex].text;
	if (itemPrice.indexOf('.') > 0)
		itemPrice = itemPrice.substring(0, itemPrice.indexOf('.'));
	
	if (itemPrice != '')
		$('isPrice').innerHTML = '$' +  parseFloat(itemPrice);
	else
		$('isPrice').innerHTML = '';
		
	$('dsItemSelected').style.display = 'block';
	//new Effect.Appear('dsItemSelected',{duration:.5});
}



function acceptItemColor(ignoreSaveConfig)  {//accept clicked in item selected screen
	var curColorShowing = getImgName($('curItemColorShowing').innerHTML);
	var baseKitGroupID = $('basePaintPriceKitGroup').innerHTML;
	$('wallMatchingPopIn').style.display = 'none';
	/*var baseSelectBox = $('Kit' + baseKitGroupID );
	var baseColor = '';
	if (baseSelectBox.options[baseSelectBox.selectedIndex] != null && baseSelectBox.options[baseSelectBox.selectedIndex].text != '')
		baseColor = getImgName(baseSelectBox.options[baseSelectBox.selectedIndex].text);
	*/
	
	var kitId = $('curItemKitId').innerHTML;
	var namesSelectBox = $('Kit' + kitId );
	var callRemoveWhenDone = false;
	
	
	if(curColorShowing == 'white_keys') {
		var blackModelDivs = getElementsByClass('dsInvSizeblack_keys',$('cwDSMSBottom'),'div');
		for (i=0;i<blackModelDivs.length;i=i+1){
			blackModelDivs[i].style.display = 'none';
		}
		var whiteModelDivs = getElementsByClass('dsInvSizewhite_keys',$('cwDSMSBottom'),'div');
		var lowestModelPrice = 100000;
		var curModelPrice = 0;
		var lowestModelDiv = null;
		
		
		updateModelPrices();
		
		
		for (i=0;i<whiteModelDivs.length;i=i+1){
			whiteModelDivs[i].style.display = 'block';
			lowestModelDiv = getElementsByClass('dsModelPrice',whiteModelDivs[i],'div');
			if(lowestModelDiv[0] != null){
				curModelPrice = lowestModelDiv[0].innerHTML.substring(1) * 1;
				if (curModelPrice < lowestModelPrice) lowestModelPrice = curModelPrice;
				
			}
		}
		$('dsBuyNewPrice').innerHTML = '$' + lowestModelPrice;
	}
	
	if(curColorShowing == 'black_keys') {
		var whiteModelDivs = getElementsByClass('dsInvSizewhite_keys',$('cwDSMSBottom'),'div');
		for (i=0;i<whiteModelDivs.length;i=i+1){
			whiteModelDivs[i].style.display = 'none';
		}
		var blackModelDivs = getElementsByClass('dsInvSizeblack_keys',$('cwDSMSBottom'),'div');
		var lowestModelPrice = 100000;
		var curModelPrice = 0;
		var lowestModelDiv = null;
		
		
		updateModelPrices();
		
		
		for (i=0;i<blackModelDivs.length;i=i+1){
			blackModelDivs[i].style.display = 'block';
			lowestModelDiv = getElementsByClass('dsModelPrice',blackModelDivs[i],'div');
			if(lowestModelDiv[0] != null){
				curModelPrice = lowestModelDiv[0].innerHTML.substring(1) * 1;
				if (curModelPrice < lowestModelPrice) lowestModelPrice = curModelPrice;
				
			}
		}
		
		$('dsBuyNewPrice').innerHTML = '$' + lowestModelPrice
		//alert();	
		//updateModelPrices();
		
	}
	if (sameAsMainColor(curColorShowing)){
		var foundSameAsMain = false;
		var iOfColor = 0;
		for (i=0;i<namesSelectBox.length;i=i+1) 
		{
			if (namesSelectBox.options[i] != null && getImgName(namesSelectBox.options[i].text) == 'same_as_main'){
				//namesSelectBox.selectedIndex = i;
				//foundSameAsMain = true;
				callRemoveWhenDone = true;
			}
			if (namesSelectBox.options[i] != null && getImgName(namesSelectBox.options[i].text) == curColorShowing){
				iOfColor = i;
			}
			
		}
		if (!foundSameAsMain) namesSelectBox.selectedIndex = iOfColor;
	} else {
		for (i=0;i<namesSelectBox.length;i=i+1) 
		{
			if (namesSelectBox.options[i] != null && getImgName(namesSelectBox.options[i].text) == curColorShowing){
				namesSelectBox.selectedIndex = i;
			}
		}
	}
	
	if (kitId == baseKitGroupID) {//The base Paint job was changes, check and update all same as options
		resetSameAsMineColors(kitId, curColorShowing);
	}
	
	if(curColorShowing != 'none') {
		var pricesSelectBox = $('Kit' + kitId + 'Prices');
		var oldItemPrice = 0;
		if (pricesSelectBox.options[pricesSelectBox.selectedIndex] != null && pricesSelectBox.options[pricesSelectBox.selectedIndex].text != '') 
			oldItemPrice = pricesSelectBox.options[pricesSelectBox.selectedIndex].text;
			
		pricesSelectBox.selectedIndex = namesSelectBox.selectedIndex;
		var itemPrice = pricesSelectBox.options[pricesSelectBox.selectedIndex].text;
		if (itemPrice.indexOf('.') > 0)
			itemPrice = itemPrice.substring(0, itemPrice.indexOf('.'));
			
		if (itemPrice == '' || itemPrice == null)
			itemPrice = 0;
			
		$('dsItem' + kitId + 'Price').innerHTML = '';
		if (itemPrice >= 0) $('dsItem' + kitId + 'Price').innerHTML = '$' + itemPrice;
		var sendInPrice, buyNewPrice, buyNewExtraPrice;
		itemPrice = itemPrice * 1;
		sendInPrice = $('dsSendInMinePrice').innerHTML.substring(1) * 1 ;
		buyNewPrice = $('dsBuyNewPrice').innerHTML.substring(1) * 1 ;
		buyNewExtraPrice = 0;
		
		if ($('Kit' + kitId + 'ExtraCont') != null) {
			if(!$('Kit' + kitId + 'ExtraCont').checked){
				$('Kit' + kitId + 'ExtraCont').checked = true;
				buyNewExtraPrice = parseFloat($('Kit' + kitId + 'ExtraCont').title);
				if (!buyNewExtraPrice) buyNewExtraPrice = 0;
				
				curExtrasPrice = parseFloat(curExtrasPrice) + parseFloat(buyNewExtraPrice);
			}
		}
		
		//$('dsSendInMinePrice').innerHTML = '$' + (sendInPrice + itemPrice - oldItemPrice);
		//$('dsBuyNewPrice').innerHTML = '$' + (buyNewPrice + itemPrice - oldItemPrice + buyNewExtraPrice);
		//todo, redo above using global prices
		
		curPaintPrice = parseFloat(curPaintPrice) + parseFloat(itemPrice) - parseFloat(oldItemPrice);
		
		updateModelPrices();
		
		if (!Element.hasClassName($('dsItem' + kitId), "dsMain")){
			$('dsItem' + kitId).addClassName("dsRemove");
			$('dsItem' + kitId).removeClassName("dsAdd");
		}
		
		if (callRemoveWhenDone) removeItemById(kitId);
		
	
	}	
	
	$('dsItemSelected').style.display = 'none';
	//new Effect.Fade('dsItemSelected');
	
	$('dsCancelItem').style.backgroundImage = 'url(../../images/designStudio/CancelAndAccept/cancel_disabled.gif)';
	
	
	$('dsAcceptItem').style.backgroundImage = 'url(../../images/designStudio/CancelAndAccept/apply_disabled.gif)';
		
	updatePurchasePrices();
	
	//if (ignoreSaveConfig == null || ignoreSaveConfig == false)
		//updateSaveConfig(kitId, curColorShowing);
	
}


function updateSaveConfig(kitId, curColorShowing) {
	var colorParams = " " + $('dsSaveConfig').href, baseURL = " ", colorToUpdate = " ", startOfCPs = " ", endOfCPs = " ";
	
	if (colorParams.indexOf('?') > 0) {
		baseURL = colorParams.substring(0, colorParams.indexOf('?') );
		colorParams = colorParams.substring(colorParams.indexOf('?') + 1);
	} else {
		baseURL = colorParams;
		colorParams = '';
	}
	
	//if(colorParams == null || colorParams == '') return false;
	
	if (colorParams.indexOf(kitId) < 0){
		if(colorParams != '') colorParams = colorParams + "&";
		colorParams = colorParams + kitId + '=' + curColorShowing;
	} else {
		startOfCPs = colorParams.substring(0, colorParams.indexOf(kitId));
		colorToUpdate = colorParams.substring(colorParams.indexOf(kitId));
		if (colorToUpdate.indexOf('&') > 0)
			endOfCPs = colorToUpdate.substring(colorToUpdate.indexOf('&'));
		else
			endOfCPs = " ";
			
		colorParams = startOfCPs + kitId + '=' + curColorShowing + endOfCPs;
		
	}
	
	colorParams = colorParams.replace(' ', '');
	
	$('dsSaveConfig').innerHTML = baseURL + '?' + colorParams;
	$('dsSaveConfig').href = baseURL + '?' + colorParams;
	$('dsEmailUrl').value = baseURL.strip() + '?' + colorParams.strip();
	$('dsEmailUrlEnd').value = baseURL.substring(baseURL.lastIndexOf('/') + 1) + '?' + colorParams;
}

function removeItemFromSaveLink(kitId) {
	var curSaveConfig = $('dsSaveConfig').href;
	var frontFinalSaveConfig = curSaveConfig.substring(0, curSaveConfig.indexOf('?'));
	var remainingSaveConfig = curSaveConfig.substring(curSaveConfig.indexOf('?') + 1);
	
	var frontfrontSaveConfig = remainingSaveConfig.substring(0, remainingSaveConfig.indexOf(kitId) - 1);
	var backfrontSaveConfig = remainingSaveConfig.substring(remainingSaveConfig.indexOf(kitId));
	
		
	
	
	if(backfrontSaveConfig.indexOf('&') > 0)
		backfrontSaveConfig = backfrontSaveConfig.substring(backfrontSaveConfig.indexOf('&') + 1);
	else
		backfrontSaveConfig = "";
		
			
		
	
	
	if(frontfrontSaveConfig == "") {
		if(backfrontSaveConfig == "") {
			remainingSaveConfig = "";
		} else {
			remainingSaveConfig = "?" + backfrontSaveConfig;
		}
	} else {
		if(backfrontSaveConfig == "") {
			remainingSaveConfig = "?" + frontfrontSaveConfig;
		} else {
			remainingSaveConfig = "?" + frontfrontSaveConfig + "&" + backfrontSaveConfig;
		}
	}
	
	//if (remainingSaveConfig != "") frontFinalSaveConfig = frontFinalSaveConfig.strip() + '?' + remainingSaveConfig.strip();
	
	
	
	$('dsSaveConfig').innerHTML = frontFinalSaveConfig + remainingSaveConfig;
	$('dsSaveConfig').href = frontFinalSaveConfig + remainingSaveConfig;
	$('dsEmailUrl').value = frontFinalSaveConfig.strip() + remainingSaveConfig.strip();
	$('dsEmailUrlEnd').value = frontFinalSaveConfig.substring(frontFinalSaveConfig.lastIndexOf('/') + 1) + remainingSaveConfig;
}


function hideItemSelected()  {//cancel clicked in item selected screen

	var kitId = $('curItemKitId').innerHTML;
	var namesSelectBox = $('Kit' + kitId );
	
    var colorSelected = namesSelectBox.options[namesSelectBox.selectedIndex];
    imageName = getImgName(colorSelected.text);
		
	updateItemColor(imageName, kitId);
	
	updateSaveConfig(kitId, imageName);
	//$('dsItemSelected').style.display = "none";
	
	
	$('wallMatchingPopIn').style.display = 'none'; 
	
	$('dsItemSelected').style.display = 'none';
	//new Effect.Fade('dsItemSelected');
	$('dsCancelItem').style.backgroundImage = 'url(../../images/designStudio/CancelAndAccept/cancel_disabled.gif)';
	
	
	$('dsAcceptItem').style.backgroundImage = 'url(../../images/designStudio/CancelAndAccept/apply_disabled.gif)';
}

function changeItemColor(newColor)  {// on mouseover of a swatch
	if (newColor == 'same_as_main') {
		/*var baseKitGroupID = $('basePaintPriceKitGroup').innerHTML;
		var baseSelectBox = $('Kit' + baseKitGroupID );
		if (baseSelectBox.options[baseSelectBox.selectedIndex] != null && baseSelectBox.options[baseSelectBox.selectedIndex].text != '')
			newColor = getImgName(baseSelectBox.options[baseSelectBox.selectedIndex].text);
		*/
		newColor = getSameAsMainColor();
	} 
	if (true) {
		var curItem = $('ics' + newColor);
		if (curItem == null){
			curItem = $('icm' + newColor);
		}
		if (curItem == null){
			curItem = $(this.id);
			if (this.id != null){
				if(this.id == 'dsOriginalChrome')
					newColor = 'chrome';
				else if(this.id == 'dsGold')
					newColor = 'gold';
				else if(this.id == 'dsCustomColor')
					newColor = 'custom_color';
				else if(this.id == 'dsWallMatchingButton')
					newColor = 'wall_matching';
				else if(this.id == 'dsMatteScreen')
					newColor = 'matte_screen';
				else if(this.id == 'dsGlossScreen')
					newColor = 'gloss_screen';
				else
					newColor = this.id.substring(3);	
			}
		}
	}
	$('dsCurColor').innerHTML = '';
	$('dsCurColor').style.backgroundImage = "url('../images/designStudio/MySelection/" + newColor + ".png')";
}

function swatchClick (newColor, kitId) {//on clicking a swatch
	
	if (kitId == null) kitId = $('curItemKitId').innerHTML;
	
	var curItem = $('ics' + newColor);
	if (curItem == null){
		curItem = $('icm' + newColor);
	}
	if (curItem == null){
		curItem = $('icp' + newColor);
	}
	if (curItem == null){
		curItem = $(this.id);
		if (this.id != null){
			if (this.id == 'dsOriginalChrome'){
				newColor = 'chrome';
			} else if (this.id == 'dsGold'){
				newColor = 'gold';
			} else if (this.id == 'dsWhiteKeys'){
				newColor = 'white_keys';
			} else if (this.id == 'dsBlackKeys'){
				newColor = 'black_keys';
			} else if (this.id == 'dsCustomColor'){
				newColor = 'custom_color';
			} else if (this.id == 'dsWallMatchingButton'){
				newColor = 'wall_matching';
			} else if (this.id == 'dsMatteScreen'){
				newColor = 'matte_screen';
			} else if (this.id == 'dsGlossScreen'){
				newColor = 'gloss_screen';
			} else {
				newColor = this.id.substring(3);
			}
		}
		else {  
	        if (newColor = 'same_as_main'){
	            $('dsDisplay' + kitId).style.backgroundImage = 'url()';
	        } else {
	            return false;	
	        }
		}
	}
	
	
	if(newColor == 'wall_matching') $('wallMatchingPopIn').style.display = 'block';

	
	updateItemColor(newColor, kitId, true);	
	
	$('dsCancelItem').style.backgroundImage = 'url(../../images/designStudio/CancelAndAccept/cancel.gif)';
	
	
	$('dsAcceptItem').style.backgroundImage = 'url(../../images/designStudio/CancelAndAccept/apply.gif)';

	
	//if (ignoreSaveConfig == null || ignoreSaveConfig == false)
		
	updateSaveConfig(kitId, newColor);
	
	//	
	//new Effect.Pulsate($('dsAcceptItem'),{duration:3,from:1.0,to:0.7});
}

function updateItemColor(newColor, kitId, fadeInNewColor)  {
	
	//new Effect.Appear('dsDisplayImagesBGReplace',{duration:.1});
	
	if (kitId == null) kitId = $('curItemKitId').innerHTML;
	
	var curItem = $('ics' + newColor);
	if (curItem == null){
		curItem = $('icm' + newColor);
		if (curItem == null){
			curItem = $('icp' + newColor);
			if (curItem == null){
			 
				curItem = $(this.id);
				if (this.id != null) newColor = this.id.substring(3);
				else {  
					if (newColor == 'same_as_main'){
						$('dsDisplay' + kitId).style.backgroundImage = 'url()';
					} else if (newColor == 'unpainted' || newColor == 'standard' || newColor == 'none' || newColor == 'chrome' || newColor == 'gold' || newColor == 'white_keys' || newColor == 'black_keys' || newColor == 'wall_matching' || newColor == 'matte_screen' || newColor == 'gloss_screen') {
						$('dsDisplay' + kitId).style.backgroundImage = 'url()';
					} else {
						return false;	
					}
				}
			}
		}
	}
	
	$('curItemColorShowing').innerHTML = newColor;
	//$('dsDisplayImagesBGReplace').style.backgroundImage = $('dsDisplay' + kitId).style.backgroundImage;
	//changeBGImage($('dsDisplayImagesSmall'),"../images/designStudio/" + curProductName + "/" + kitId + "/small/" + newColor + ".png");
	changeBGImage($('dsDisplay' + kitId),"../products/" + curProductName + "/" + kitId + "/" + newColor + ".png", fadeInNewColor);
	/*$('dsDisplayImagesSmall').style.backgroundImage = "url('../images/designStudio/" + curProductName + "/" + kitId + "/small/" + newColor + ".png')";
	$('dsDisplay' + kitId).style.backgroundImage = "url('../images/designStudio/" + curProductName + "/" + kitId + "/" + newColor + ".png')";
	*/
	var pricesSelectBox = $('Kit' + kitId + 'Prices');
	var namesSelectBox = $('Kit' + kitId);
	var hasSameAsMine = false;
	for (i=0;i<namesSelectBox.length;i=i+1) 
	{		
		if (namesSelectBox.options[i] != null && getImgName(namesSelectBox.options[i].text) == 'same_as_main') hasSameAsMine = true;
			
			
		if (namesSelectBox.options[i] != null && getImgName(namesSelectBox.options[i].text) == newColor){
	        var itemPrice = pricesSelectBox.options[i].text;
			if(itemPrice.indexOf('.') > 0)
	        	itemPrice = itemPrice.substring(0, itemPrice.indexOf('.'));
			if ( sameAsMainColor(newColor) && hasSameAsMine)
				$('isPrice').innerHTML = '$0';
			else if (itemPrice != '' )
				$('isPrice').innerHTML = '$' +  parseFloat(itemPrice);
			else
				$('isPrice').innerHTML = '';
		}
	}
	
	
	
	setTimeout('clearBGReplace(' + kitId + ');',1000);
	
	
}

function clearBGReplace(kitId){
	$('dsDisplayBG' + kitId).style.backgroundImage = $('dsDisplay' + kitId).style.backgroundImage;
	//new Effect.Fade('dsDisplayImagesSmall',{duration:10});
	//new Effect.Fade('dsDisplayImagesBGReplace',{duration:10});
    //$('dsDisplayImagesSmall').style.backgroundImage = '';
    //$('dsDisplayImagesBGReplace').style.backgroundImage = '';
}

function resetItemColor(newColor)  {
	/*var curItem = $('ic' + newColor);
	if (curItem == null){
		curItem = $(this.id);
		newColor = this.id.substring(2);	
	}*/
	newColor = $('curItemColorShowing').innerHTML;
	if (newColor == 'same_as_main') {
		/*var baseKitGroupID = $('basePaintPriceKitGroup').innerHTML;
		var baseSelectBox = $('Kit' + baseKitGroupID );
		if (baseSelectBox.options[baseSelectBox.selectedIndex] != null && baseSelectBox.options[baseSelectBox.selectedIndex].text != '')
			newColor = getImgName(baseSelectBox.options[baseSelectBox.selectedIndex].text);*/
		newColor = getSameAsMainColor();
	}
	$('dsCurColor').innerHTML = '';
	$('dsCurColor').style.backgroundImage = "url('../images/designStudio/MySelection/" + newColor + ".png')";
}

function getImgName(oldName){
    oldName = oldName.toLowerCase();
    oldName = oldName.strip();
	return oldName.replace(/ /g,'_');
}

function resetSelectBox(selBox) {
    for (var i=0;i<selBox.options.length;i++) {
        selBox.options[i].selected = selBox.options[i].defaultSelected;
    }
}

function mousedownRemoveItem(kitGroupId)  {// not sure when this fires
	//$('dsItemSelected').style.display = "block";
	/**/
	if (typeof event == "undefined"){
		event = window.event;
	}
	if (typeof event.stopPropagation != "undefined"){
		event.stopPropagation();
	} else {
		event.cancelBubble = true;
	}
	
	return true;
	
	//new Effect.SlideDown('dsItemSelected');
}

function sameAsMainColor (colorToCheck) {
	
	var baseColor = '';
	baseColor = getSameAsMainColor();
		
	if (baseColor == colorToCheck) return true;
	else return false;
}	

function getSameAsMainColor () {
	
	var baseKitGroupID = $('basePaintPriceKitGroup').innerHTML;
	var baseSelectBox = $('Kit' + baseKitGroupID );
	var baseColor = '';
	if (baseSelectBox.options[baseSelectBox.selectedIndex] != null && baseSelectBox.options[baseSelectBox.selectedIndex].text != '')
		baseColor = getImgName(baseSelectBox.options[baseSelectBox.selectedIndex].text);
		
	return baseColor;
	
}	

function resetSameAsMineColors (baseKitGroupID, baseColor) {//The base Paint job was changes, check and update all same as options


	var i = 0, curKitGroupId, j = 0, curSelectBox, curItemColor, pricesSelectBox, oldItemPrice;
	var paintedItems = getElementsByClass('cwDSPaintedItem',$('cwDSLowerHiddenInfo'),'select');
	
    for (i=0;i<paintedItems.length;i=i+1) {
		curSelectBox = paintedItems[i];
		curKitGroupId = curSelectBox.id;
		curKitGroupId = curKitGroupId.replace('Kit', '');
		if (curKitGroupId!= baseKitGroupID) {
			
			if (curSelectBox.options[curSelectBox.selectedIndex] != null && curSelectBox.options[curSelectBox.selectedIndex].text != '')
				curItemColor = getImgName(curSelectBox.options[curSelectBox.selectedIndex].text);
			
			
			if (curItemColor == baseColor) {
				if (curSelectBox.options[0] != null && getImgName(curSelectBox.options[0].text) == 'same_as_main'){
						
						removeItemById(curKitGroupId);
						removeItemFromSaveLink(curKitGroupId); 
						/*curSelectBox.selectedIndex = 0;
						pricesSelectBox = $('Kit' + curKitGroupId + 'Prices');
						pricesSelectBox.selectedIndex = 0;
						oldItemPrice = $('dsItem' + curKitGroupId + 'Price').innerHTML;
						oldItemPrice = oldItemPrice.replace('$', '');
						
						curPaintPrice = curPaintPrice - parseFloat(oldItemPrice);
						$('dsItem' + curKitGroupId + 'Price').innerHTML = '$0';
						updateItemPrice(curKitGroupId);*/
				}
				
			}	
		}
	}

}

function randomBack(){
	preselectColors(backRandomizer[curRandomizer]);
	/*if (curRandomizer == 0) 
	if (curRandomizer == 1) preselectColors(back2Randomizer);
	if (curRandomizer == 2) preselectColors(back3Randomizer);
	if (curRandomizer == 3) preselectColors(back4Randomizer);
	if (curRandomizer == 4) preselectColors(back5Randomizer);*/
	$('dsSaveConfig').href = backRandomizer[curRandomizer];
	$('dsSaveConfig').innerHTML = backRandomizer[curRandomizer];
	$('dsEmailUrl').value = backRandomizer[curRandomizer].strip();
	$('dsEmailUrlEnd').value = backRandomizer[curRandomizer].substring( backRandomizer[curRandomizer].lastIndexOf('/') + 1) ;
	curRandomizer = curRandomizer + 1;
}



function randomDesign() {
		
	
	backRandomizer[4] = backRandomizer[3];
	backRandomizer[3] = backRandomizer[2];
	backRandomizer[2] = backRandomizer[1];
	backRandomizer[1] = backRandomizer[0];
	backRandomizer[0] = $('dsSaveConfig').href;
	
	var i = 0, curSelectBox, curKitGroupId, newRandomColor;
	var paintedItems = getElementsByClass('cwDSPaintedItem',$('cwDSLowerHiddenInfo'),'select');
    for (i=0;i<paintedItems.length;i=i+1) {
		curSelectBox = paintedItems[i];
		curKitGroupId = curSelectBox.id;
		curKitGroupId = curKitGroupId.replace('Kit', '');
		//if (curSelectBox.options[curSelectBox.selectedIndex] != null && curSelectBox.options[curSelectBox.selectedIndex].text != '')
		//	curItemColor = getImgName(curSelectBox.options[curSelectBox.selectedIndex].text);
		
		
		
		
		
		newRandomColor = getRandomColor(curSelectBox);
		
		
		
		
		
		$('curItemColorShowing').innerHTML = newRandomColor;
		$('curItemKitId').innerHTML = curKitGroupId;
		updateItemColor(newRandomColor, curKitGroupId, true);
		updateSaveConfig(curKitGroupId, newRandomColor)
		acceptItemColor(false);
	
				
		//var i = 
		
		
		
		
	}
	curRandomizer = 0;
}



function getRandomColor(curSelectBox) {
	var curBoxLength, newRandomColorNumber, newRandomColor;
	
	
	curBoxLength = curSelectBox.length;
		
	newRandomColorNumber = Math.round(curBoxLength*Math.random());
	
	if (curSelectBox[newRandomColorNumber] == null){
		return getRandomColor(curSelectBox);
	} else if (curSelectBox[newRandomColorNumber].text == null){
		return getRandomColor(curSelectBox);
	} else if (getImgName(curSelectBox[newRandomColorNumber].text)  == 'none'){
		return getRandomColor(curSelectBox);
	} else if (getImgName(curSelectBox[newRandomColorNumber].text)  == 'unpainted'){
		return getRandomColor(curSelectBox);
	} else if (getImgName(curSelectBox[newRandomColorNumber].text).substring(0, 6) == 'custom'){
		return getRandomColor(curSelectBox);
	} else {
		return getImgName(curSelectBox[newRandomColorNumber].text);
	}
	
	itemPrice = itemPrice.substring(0, itemPrice.indexOf('.'));
}


function openEmailForm() {
	$('dsEmailFormWrapper').style.visibility = 'visible';	
}
function closeEmailForm() {
	$('dsEmailFormWrapper').style.visibility = 'hidden';	
}
function sendEmailForm () {
	if($('dsEmailTo').value == '' || $('dsEmailTo').value == 'example@mail.com') {
		alert('Please enter the email address of the person you would like to send your design to.');	
		return false;
	}
	else $('cwdsSendEmail').disabled = true;
	
}


function toggleGiftWrapping() {
	
	
	if ($('giftWrappingPanel').style.display == 'none'){
		$('giftWrappingPanel').style.display = 'block';
		$('GiftWrappingWrapper').style.zIndex = '20';
	} else {
		$('giftWrappingPanel').style.display = 'none';
		$('GiftWrappingWrapper').style.zIndex = '5';
	}
	updateGiftWrappingRibbon();
	
}

function clearGiftWrapping() {
	
	if ($('dsGWpaperSelect') != null) {
		for (var i=0;i<$('dsGWpaperSelect').options.length;i++) {
			$('dsGWpaperSelect').options[i].selected = $('dsGWpaperSelect').options[i].defaultSelected;
		}	
		updateGiftWrapping('paper');
	}
	
	if ($('dsGWvribbonSelect') != null) {
		for (var i=0;i<$('dsGWvribbonSelect').options.length;i++) {
			$('dsGWvribbonSelect').options[i].selected = $('dsGWvribbonSelect').options[i].defaultSelected;
		}	
		updateGiftWrapping('vribbon');
	}
	
	if ($('dsGWhribbonSelect') != null) {
		for (var i=0;i<$('dsGWhribbonSelect').options.length;i++) {
			$('dsGWhribbonSelect').options[i].selected = $('dsGWhribbonSelect').options[i].defaultSelected;
		}	
		updateGiftWrapping('hribbon');
	}
	
	if ($('dsGWCardText') != null) $('dsGWCardText').value = '';
	toggleGiftWrapping();
}

// JavaScript Item class

dsItem.prototype._name;
dsItem.prototype._state;
dsItem.prototype._attribute;
dsItem.prototype._attValue;



function dsItem(name) {
	this._name = name;
}




dsItem.prototype.getName = function() {
	return this._name;
}



function setSendDesignTo(sendDesingToAddress) {
	if(sendDesingToAddress == 'colorware'){
		if ($('dsEmailTo').value != 'sales@colorwarecustom.com') $('dsEngSaveFriend').value = $('dsEmailTo').value;
		$('dsEmailTo').value = 'sales@colorwarecustom.com';
	} else if (sendDesingToAddress == 'friend') {
		$('dsEmailTo').value = $('dsEngSaveFriend').value;
	}
		
		
		
		
}


    function dsStaticOverview(){ 
		$('dsLowerSection').className = '';
		Element.addClassName($('dsLowerSection'), "showOverview");
		//$('dsLowerSection').addClassName("showOverview");
	}
   function dsStaticConfig(){
		$('dsLowerSection').className = '';
		Element.addClassName($('dsLowerSection'), "showConfig");
		//$('dsLowerSection').addClassName("showConfig");
		
   }
   function dsStaticProcess(){
		$('dsLowerSection').className = '';
		$('dsLowerSection').addClassName("showProcess");
   }
   function dsStaticGallery(){
		$('dsLowerSection').className = '';
		$('dsLowerSection').addClassName("showGallery");
   }
   function dsStaticShipping(){
		$('dsLowerSection').className = '';
		$('dsLowerSection').addClassName("showShipping");
   }
   function dsStaticSupport(){
		$('dsLowerSection').className = '';
		$('dsLowerSection').addClassName("showSupport");
   }
   
   
   
   
   function toggleRapidReturn () {
		if ($('rapidReturnPanel').style.display == 'none'){
			$('rapidReturnPanel').style.display = 'block';
			$('rapidReturnWrapper').style.zIndex = '20';
		}else{
			$('rapidReturnPanel').style.display = 'none';
			$('rapidReturnWrapper').style.zIndex = '5';
		}
		//$('rrQualify').style.display = 'none';
		
   }
   function hideRapidReturn () {
		Effect.SlideDown('rapidReturnPanel', {delay: .1, duration: 2});
		
		
	//setTimeout("$('rrQualify').style.display = 'block';",2500);
		
   }