img_Perspective = '1';
flagtoExecuteQuickView = true;

_ieversion = 99;
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion>=8)
  _ieversion = 8;
 else if (ieversion>=7)
 _ieversion = 7;
 else if (ieversion>=6)
  _ieversion = 6;
 else if (ieversion>=5)
   _ieversion = 5;
}



function dropDownColorQuickView(itemID,idx,imgPath)
{
		img_value	= $(idx).value;
		img_value = img_value.split('|');
		img_ColorID	= img_value[0];
		img_price	= img_value[1];
		img_image	= img_value[4];
		
		if(img_value[2] == '' || img_value[2] == 0)
		 {
		 	img_priceOnSale	= '';
		 }
		 else
		 {
		 	img_priceOnSale	= '<span class="sale">'+''+img_value[2]+' '+'#xmlStruct.onSale#</span>';			 	
		 }
	
		priceSection = 'ItemPriceValue' + itemID;

		if (img_value != '')
		{		
			document.getElementById(priceSection).innerHTML = '$' +img_price +' '+img_priceOnSale;	
			imageContainer = 'ItemImage' + itemID;
			document.getElementById(imageContainer).src = imgPath + '/' + img_image;		
		}
		else
		{
			document.getElementById(priceSection).innerHTML = '';
			
		}
				
		getSizes(img_ColorID,itemID);

}


function getSizes(colorId,itemId)
{
	DWREngine._execute(_cfCatLevelsLocation, null, 'getSizesByColorItem',itemId,colorId,updateSelect_result);
}


function updateSelect_result(result)
{				
	_affect = 'sizeId-0';	
	_resultKeys = new Array('SKU_ID','SIZE_DESC');	
	dropDownSetRelation(result)
}


function QuickViewAddtoBag()
{
	alert('add to bag');
}

function showQuickViewAlert(obj)
{

	var path, targetAlert, cssClass, closeBText, itemid, colorid, date_published, flagid, registry_id;
	
    if(flagtoExecuteQuickView) {
    	flagtoExecuteQuickView = false;
		path = (!obj.path)?'':obj.path;
		targetAlert = (!obj.target)?'alertbox':obj.target;	
		cssClass = (!obj.cssClass)?'alertbox':obj.cssClass;
		closeBText = (!obj.closeBText)?'X':obj.closeBText;
		itemid = (!obj.itemid)?'':obj.itemid;
		colorid = (!obj.colorid)?'':obj.colorid;
		date_published = (!obj.date_published)?'':obj.date_published;
		registry_id = (obj.registry_id === undefined )?'':obj.registry_id;

		_callHasSpecialAction = 'resetBoxesNormalDropDownToObject('+colorid+')';
		 
		if($('generalFlagID'))
			flagid =  $('generalFlagID').value;
		else
			flagid = '';
			
		var args = {
				PATH: path
			,	DIVID: targetAlert
			,	CSSCLASS: cssClass
			,	CLOSEBUTTONTEXT: closeBText
			,	ITEMID: itemid
			,	COLORID: colorid
			,	DATE_PUBLISHED: date_published
			,	FLAGID: flagid
			,	REGISTRY_ID: registry_id
		};

		j$( ".quickViewButton" ).each(function () {
			if ( j$( this ).hasClass( "displayBlock" ) ) {
				j$( this ).removeClass( "displayBlock" ).addClass( "displayNone" );
			}
		});

		j$( ".alertboxQuickView" ).remove();
		
		j$.post(
				siteUrl + "/com/b2c/genericProxy.cfc?returnFormat=json&method=getQuickView"
			,	args
			,	callText_Result
			,	"json"
		);
		
	}	
	
}

function resetBoxesNormalDropDownToObject() {
	values = $('colorDropDown').value.split('@')[0].split('~');
	texts = $('colorDropDown').value.split('@')[1].split('~');
	SingleColortexts = $('colorDropDown').value.split('@')[2].split('~');
	selectedColorID = (arguments.length > 0)?arguments[0]:"";

	//$("color-0").options.length = 1;
	lasnN = 0;
	//for(x=1;x<values.length;x++) {
	//	try {
	//		colorID = values[x].split('|')[0];
	//		if (colorID == selectedColorID) { lasnN = x; }
	//	} catch(e) {}
	//	$("color-0").options[x] = new Option(SingleColortexts[x],values[x]);
	//}
	
	//if($('color-0').options.length == 2)
	//{
	//	$('color-0').style.display = 'none';
	//	if ( $("cololLabel" ) )
	//		$('colorLabel').style.display = 'none';

	//	Cval = $('color-0').options[1].value;
	//	Cval = Cval.split('|');
	//	Cval = Cval[0];


	//	if(Cval != 'NOCOLOR')
	//	{
	//		if ( $("singleColor" ) )
	//			$('singleColor').innerHTML = SingleColortexts[1];
	//		if ( $("cololLabel" ) )
	//			$('colorLabel').style.display = 'block';
	//	}
	//}
	
	if (lasnN == 0) { lasnN = $('color-0').options.length - 1; }
	$('color-0').options[lasnN].selected = true;
	eval( "selectedColor = " + j$( 'div[ id^=qv_colorSwatchImage ][ class*=selected ]' ).attr( 'rel' ) );
	
	colorID = selectedColor.color_id;
	imgPath = $('textImagePath').value;
	
	img_ColorID = colorID;
	
	_itemid = j$( "#itemID" ).val();
	
	dropDownColorActionsQuickView($('color-0').options[lasnN].value,imgPath, colorID, "qv_", '', 'main' );
	flagtoExecuteQuickView = true;
	
	//setAlternateViewThumbnails( "QuickView" );
}


function changeDropDownColorValue(lasnN,numImg,colorName, colorID, identifier, colorSelectName, imageType )
{
	//sets the identifier to the quickview one by default
	if( !identifier )
		identifier = "qv_";
	
	//sets the default name for the select list
	if( !colorSelectName )
		colorSelectName = 'color-0';
	
	//sets the name of the image that will be changed by default it will be main
	if( !imageType )
		imageType = "main";
	
	for(i=1;i<=numImg;i++)
	{
		j$( "#"+identifier+"colorSwatchImage" + i ).removeClass( "selected" );
	}

	j$( "#"+identifier+"colorSwatchImage" + lasnN ).addClass( "selected" );

	$(colorSelectName).options[lasnN].selected = true;
	
	imgPath = $('textImagePath').value;
	img_ColorID = colorID;

	if( j$('#'+identifier+'colorSwatchName').length > 0 )
		j$('#'+identifier+'colorSwatchName').html(colorName);
	
	dropDownColorActionsQuickView($(colorSelectName).options[lasnN].value,imgPath, colorID, identifier, colorSelectName, imageType );
    
    //$('colorSwatchName').innerHTML = colorName;
	
	//setAlternateViewThumbnails();
	

}

function changeMainQuickViewImages(imageSource){
	
	if($('productImageQV')){
		if(imageSource != ''){
			$('productImageQV').src = imageSource;
		}	
	}
}


function setAlternateViewThumbnails(){
	color = img_ColorID;
	psp = img_Perspective;

	while(color.indexOf('-') >= 0)
	{
		color = color.replace('-','_');
	}

 	if(color && psp && typeof window['qv_img_path_'+color] != "undefined"){
 		
 		if( eval('qv_img_'+color+'_count') < 4 ){
 			j$( '#qv_runwayPrev' ).hide();
 			j$( '#qv_runwayNext' ).hide();
 		}else{
 			j$( '#qv_runwayPrev' ).show();
 			j$( '#qv_runwayNext' ).show();
 		}
 		
 		var p = eval('qv_img_path_'+color);
		
		if (eval('qv_img_'+color+'_count') <= 1) {
			p1='no_image.jpg';
			if (document.getElementById('qv_img_img_1'))
				document.getElementById('qv_img_img_1').src = p+p1; 
			
			for(cpt = 1; cpt <= 9; cpt++){
				document.getElementById("qv_alternate_"+cpt).style.display = "none";
			}
		}else{
			for(cpt = 1; cpt <= eval('qv_img_'+color+'_count'); cpt++){
				eval('var p'+cpt+'= qv_img_img_'+cpt+'_'+color);
			}
	 		
	 		for(cpt = 1; cpt <= 9; cpt++){
				try{
					document.getElementById("qv_alternate_"+cpt).style.display = "block";
					eval('document.getElementById("qv_img_img_'+cpt+'").src = p+p'+cpt);
					j$('#qv_alternate_'+cpt+' a').attr("href","javascript:changeMainQuickViewImages('"+p+eval('qv_img_big_'+cpt+'_'+color)+"');");
				}catch(e){
					document.getElementById("qv_alternate_"+cpt).style.display = "none";
				}
			}
		}				
 	}
}



function dropDownColorActionsQuickView(img_value,imgPath, colorID, identifier, colorSelectName, imageType )
{
	//alert(img_value);
	img_value = img_value.split('|');
	img_ColorID	= colorID;
	img_price	= img_value[1];
	img_priceOnSale = img_value[2];
	img_memberPrice = img_value[7];
	
	eval("img_image = " + identifier + "productImages[ 'color_' + colorID + '_1' ][ '" + imageType + "' ][ 0 ];");
	
	if( imageType == "main" ){
		if(img_value[8]) convertPrice=img_value[8];
		if(img_value[9]) convertPriceONSale=img_value[9];
		if(img_value[10]) convertPriceMember=img_value[10];
	    
		if(img_value!='')
		{
			if(translate.showDollarAmountSaveOnSalePrice == 'true') {
				if(img_priceOnSale != '' && img_priceOnSale != '0.00'){	
					tempDiff = img_price - img_priceOnSale;
					priceDescription = ''
					priceDescription = ': <strike>' + img_price + '</strike>';
					priceDescription = priceDescription + ' | <span>' + img_priceOnSale + '</span> ' + translate.yousave + ' ' + tempDiff.toFixed(2) ;
				} else {
					priceDescription = ''
					priceDescription = img_price;
				}
			} else {	
				priceDescription = ''
				priceDescription = img_price;
				
				if(img_priceOnSale != '' && img_priceOnSale != '0.00'){
					priceDescription = priceDescription + ' | <span>' + translate.onSale + '</span> ' + img_priceOnSale;
				}
			}
			
			if(img_memberPrice && img_memberPrice != '' && img_memberPrice != '0.00'){
				priceDescription = priceDescription + '<br>' +  img_memberPrice;
			}
			if(img_value[8]) priceDescription=priceDescription+'<br> ( '+convertPrice;
			if(img_value[9]) priceDescription=priceDescription+' | '+convertPriceONSale;
			if(img_value[10]) priceDescription=priceDescription+' | '+convertPriceMember;
			if(img_value[8]) priceDescription=priceDescription+' )';
			
			if(imgPath){
				$("productImageQV").src = imgPath + '/' + img_image; 
			}	
			
			
			if($("isNewInd"))
			{
				if($("isNewInd").value == 'Y')
					priceDescription = priceDescription + ' | ' + translate.newLabel;;
			}
			
			if($("ItemPriceValueID"))
			{
				$("ItemPriceValueID").innerHTML =priceDescription;
			}	
			
			bypassImageZoomer = false;
			
			_itemid = j$( "#itemID" ).val();
			
			getSizesDetails(img_ColorID,_itemid);
			
		}
	}else{
		//We want to change the thumbnail (productSearchResults)
		if(imgPath){
			j$( "#" + identifier ).attr( "src", imgPath + '/' + img_image ); 
		}	
	}
}


function getSizesDetails(colorId,itemId)
	{
	
		if ($('productType').value != 'SINGLE_SKU')
			{
			if($('showOutOfStockInSizes').value == 'true')
			{
				showOutOfStockInSizes = 'all';
			}
			else
			{
				showOutOfStockInSizes = 'in';
			}
			
			DWREngine._execute(_cfCatLevelsLocation, null, 'getSizesByColorItem',itemId,colorId,$('actualCurLang').value,showOutOfStockInSizes,updateSelect_result);
		}	
		else
		{
			$('QuickViewAddcartProcessing').style.display = 'none';
			$('QuickViewAddcartButton').style.display = 'block';
		}
	}

	function CheckOutOfStock(sizeObj)
	{
		val = sizeObj.options[sizeObj.selectedIndex].text;
		val = val.toUpperCase();

		if(val.indexOf('OUT OF STOCK') >= 0)
		{
			showAlert({message:'Cannot select size that is OUT OF STOCK',closeBText:'x',cssClass:'alertboxSmall'});
			sizeObj.options[0].selected = true;
		}
		if($("ItemPriceValueID")&&sizeObj.options[sizeObj.selectedIndex].id!='')
		{
			img_value = sizeObj.options[sizeObj.selectedIndex].id.split('~');
			img_price	= img_value[0];
			img_priceOnSale = img_value[1].replace('ON SALE','');
			
			if(img_priceOnSale != ''){
				$("ItemPriceValueID").innerHTML = translate.productprice + ' ' + img_price + '<br/> ' + translate.productonSale + ' ' + img_priceOnSale;
			} else {
				$("ItemPriceValueID").innerHTML = translate.productprice + ' ' + img_price;
			}	
			
		} 

	}


	function updateSelect_result(result)
	{
		var sb = $("SizeSelectBox-0");
		if (sb){
			if ( sb.options.length == 0 || sb.options[ 0 ].value != "" )
				initialLength = 0;
			else
				initialLength = 1;
			
			// Clear the current drop down box value
			$("SizeSelectBox-0").options.length = initialLength;
	        // alert(result);
			// Build drop down box here.
			for ( i=0; i < result.length; i++ )
			{
				addToSizeDropDown = true;
	
				if (result[i].INSTOCK == 'false')
				{
					sizeTEXT = result[i].SIZE_DESC + ' (Out of Stock)';
	
					if($('showOutOfStockInSizes').value == 'false'){
						addToSizeDropDown = false;
					}
				}
				else
				{
					sizeTEXT = result[i].SIZE_DESC;
				}
	
	
	
				if(addToSizeDropDown)
				{
						optObj = new Option(sizeTEXT, result[i].SKU_ID, false);
						// Append the new option...
						sb.options[i+initialLength] = optObj;
	
						if(result.length == 1)
						{
							tempText = sb.options[initialLength].text;
	
							if (tempText.indexOf('Out of Stock') < 0)
								sb.selectedIndex = initialLength;
	
							if($('singleSize'))
							{
								sb.style.display = 'none';
								$('singleSize').style.display = 'block';
							}
						}
						else
						{
							if($('singleSize'))
							{
								if(sb.style.display == 'none')
								{
									sb.style.display = 'block';
									$('singleSize').style.display = 'none';
								}
								
							}
						}
						
						if(result[i].PRICE){
						sb.options[i+initialLength].id = result[i].PRICE + '~' + result[i].TEMPSALEPRICE;
						}else {
						sb.options[i+initialLength].id = '';	
						}
	
				}
				
			}
			
			if( $('QuickViewAddcartProcessing') )
				$('QuickViewAddcartProcessing').style.display = 'none';
			
			if( $('QuickViewAddcartButton') )
				$('QuickViewAddcartButton').style.display = 'block';
		}
	}

function resetBoxesToObject()
{
	_listMenus = new _ListMenu();
	_listMenus.init();
	_listMenus.openBoxEvent = 'click';
	_listMenus.maxHeight = 150;
	
	//color box
	values = $('colorDropDown').value.split('@')[0].split('~');
	texts = $('colorDropDown').value.split('@')[1].split('~');
	SingleColortexts = $('colorDropDown').value.split('@')[2].split('~');
	
	_listMenus.initJsDropDown();
	
	_listMenus.menuName = 'colorId-0';
	_listMenus.mainClass = 'menuDrop long swatchHeight adjustMargin';
	_listMenus.setDropDownSize('showAll');
	
	_listMenus.setMenuStructure();
	
	myMenu = _listMenus.setMenuObjects(values,texts);
	
	_listMenus.appendMenu($('lineItem_color_0'),myMenu);
	
	_listMenus.assignEvent("dropDownColorFromQuickView('colorId-"+_listMenus.currentObjectN+"')",_listMenus.currentObjectN);
	
	objEvent = getObjectEvent($('colorId-0_'+_listMenus.currentObjectN));
	_listMenus.setCurrentMenu(objEvent);
	currentMenu = _listMenus.getCurrentMenu();
	
	selectMenu($('colorId-0_1'));
	_affect = 'sizeID-0';
	
	
	
	//size box
	
	
	_listMenus.initJsDropDown();

	sizeValues = new Array();
	sizeValues[0] = '';
	
	sizeTexts = new Array();
	
	
	if($('actualCurLang').value == 'fre')
 		sizeTexts[0] = 'Taille';
 	else
		sizeTexts[0] = 'Size';
	
	
	
	_listMenus.menuName = 'sizeID-0';
	_listMenus.mainClass = ' menuDrop short adjustMargin';
	_listMenus.setDropDownSize('colapse');
	
	_listMenus.setMenuStructure();
	
	myMenu = _listMenus.setMenuObjects(sizeValues,sizeTexts);
	
	
	
	_listMenus.appendMenu($('lineItem_size_0'),myMenu);
	
	
	//qty box
	_listMenus.initJsDropDown();
	qtyValues = new Array();
	qtyValues[0] = '1';
	qtyValues[1] = '2';
	qtyValues[2] = '3';
	qtyValues[3] = '4';
	
	qtyTexts = new Array();
	qtyTexts[0] = '1';
	qtyTexts[1] = '2';
	qtyTexts[2] = '3';
	qtyTexts[3] = '4';
	
	
	_listMenus.menuName = 'qty-0';
	_listMenus.mainClass = ' menuDrop xshort adjustMargin';
	_listMenus.setDropDownSize('colapse');
	
	_listMenus.setMenuStructure();
	
	myMenu = _listMenus.setMenuObjects(qtyValues,qtyTexts);
	
	_listMenus.appendMenu($('lineItem_qty_0'),myMenu);
	
	objEvent = getObjectEvent($('qty-0_'+_listMenus.currentObjectN));
	_listMenus.setCurrentMenu(objEvent);
	currentMenu = _listMenus.getCurrentMenu();
	
	selectMenu($('qty-0_0'));
	
	
	$('menuBody_1').style.width= "90px";
	
}

function addSkusToFavorites(aForm)
{
	addToMyFavorites = true;
	checkForErros = validateStyle();
	addToMyFavorites = false;


	if(!checkForErros)
	{
		document.getElementById('skuCount').value=lineCount+1;

		aForm.action = j$( "#quickViewAddToFavoritesAction" ).val();
		aForm.submit();
    }
	else
	{
		ShowProductDetailsError(checkForErros);
	}
}
			
