var contador=1;
/*
function carrito(store, catalog, category, lang, defaultItem, quick, userType){
	if(validarCarrito()){
	
		// Create a form and add it to the document body
		var f = document.createElement("form");
		document.body.appendChild(f);
		f.method = "POST"
		f.action="OrderItemAdd";
				
		var storeId = document.createElement("input");
		storeId.type = "hidden";
		f.appendChild(storeId);
		
		storeId.name ="storeId";
		storeId.value=store;
		
		var catalogId = document.createElement("input");
		catalogId.type = "hidden";
		f.appendChild(catalogId);
		
		catalogId.name ="catalogId";
		catalogId.value=catalog;
		
		var categoryId = document.createElement("input");
		categoryId.type = "hidden";
		f.appendChild(categoryId);
		
		categoryId.name ="categoryId";
		categoryId.value=category;
		
		
		
		var mpCategoryId = document.createElement("input");
		mpCategoryId.type = "hidden";
		f.appendChild(mpCategoryId);
		
		mpCategoryId.name ="mpCategoryId";
		mpCategoryId.value =document.mp.mpCategoryId.value;
		
		var mpCatalogId = document.createElement("input");
		mpCatalogId.type = "hidden";
		f.appendChild(mpCatalogId);
		
		mpCatalogId.name ="mpCatalogId";
		mpCatalogId.value=document.mp.mpCatalogId.value;
		
		
		
		var langId = document.createElement("input");
		langId.type = "hidden";
		f.appendChild(langId);
		
		langId.name ="langId";
		langId.value=lang;

		var errorViewName = document.createElement("input");
		errorViewName.type = "hidden";
		f.appendChild(errorViewName);
		
		errorViewName.name ="errorViewName";
		if(userType == 'R'){			
			errorViewName.value="QuickCheckoutProfile";
		}else{
			errorViewName.value="LogonForm";
		}		
		
		var shouldCachePage = document.createElement("input");
		shouldCachePage.type = "hidden";
		f.appendChild(shouldCachePage);
		
		shouldCachePage.name ="shouldCachePage";
		shouldCachePage.value="false";

		if(quick){
			var quickPurchase = document.createElement("input");
			quickPurchase.type = "hidden";
			f.appendChild(quickPurchase);

			quickPurchase.name ="quickPurchase";
			quickPurchase.value="true";
		}

		if(document.promotionCodes != null){
			for(i=0; i<document.promotionCodes.length; i++){
				if(document.promotionCodes[i].checked){
					var calCodeId = document.createElement("input");
					calCodeId.type = "hidden";
					f.appendChild(calCodeId);

					calCodeId.name ="calCodeId";
					calCodeId.value=document.promotionCodes[i].value;
				}
			}
		}
						
		// catentry and quantity
		for(i=0; i<contador-1; i++){
			switch(i){
				case 0:
					var cantidad ='';
					
					for(x=0; x<document.sel_atributos_1.cantidad.options.length; x++){
						if(document.sel_atributos_1.cantidad.options[x].selected){
							cantidad = document.sel_atributos_1.cantidad.options[x].value;
						}
					}
					
					var l_col = document.sel_atributos_1.colores.options.length;
					var l_ta1 = document.sel_atributos_1.talla1.options.length;
					var l_ta2 = document.sel_atributos_1.talla2.options.length;
					
					if (l_col > 1 || l_ta1 > 1 || l_ta2 > 1) {
						var catEntryId ='';
						
						if (l_col > 1 ) { 
							for(x=0; x<document.sel_atributos_1.colores.options.length; x++){
								if(document.sel_atributos_1.colores.options[x].selected){
									catEntryId = document.sel_atributos_1.colores.options[x].value;
								}
							}
						} else if (l_ta1 > 1) {
							for(x=0; x<document.sel_atributos_1.talla1.options.length; x++){
								if(document.sel_atributos_1.talla1.options[x].selected){
									catEntryId = document.sel_atributos_1.talla1.options[x].value;
								}
							}
						} else {
							for(x=0; x<document.sel_atributos_1.talla2.options.length; x++){
								if(document.sel_atributos_1.talla2.options[x].selected){
									catEntryId = document.sel_atributos_1.talla2.options[x].value;
								}
							}
						}
						
						if(catEntryId != '' && cantidad != ''){
							var catEntry = document.createElement("input");
							catEntry.type = "hidden";
							f.appendChild(catEntry);

							catEntry.name ="catEntryId_"+i;
							catEntry.value=catEntryId;
							
							var quantity = document.createElement("input");
							quantity.type = "hidden";
							f.appendChild(quantity);
									
							quantity.name ="quantity_"+i;
							quantity.value=cantidad;
						}
					}else{
							var catEntryId = document.createElement("input");
							catEntryId.type = "hidden";
							f.appendChild(catEntryId);
									
							catEntryId.name ="catEntryId_"+i;
							catEntryId.value=defaultItem;
							
							var quantity = document.createElement("input");
							quantity.type = "hidden";
							f.appendChild(quantity);
									
							quantity.name ="quantity_"+i;
							quantity.value=cantidad;

					}
					break;
				case 1:
					var catEntryId ='';
					var cantidad ='';
					
					for(x=0; x<document.sel_atributos_2.cantidad.options.length; x++){
						if(document.sel_atributos_2.cantidad.options[x].selected){
							cantidad = document.sel_atributos_2.cantidad.options[x].value;
						}
					}
					
					var l_col = document.sel_atributos_2.colores.options.length;
					var l_ta1 = document.sel_atributos_2.talla1.options.length;
					var l_ta2 = document.sel_atributos_2.talla2.options.length;
						
						
					if (l_col > 1 ) { 
						for(x=0; x<document.sel_atributos_2.colores.options.length; x++){
							if(document.sel_atributos_2.colores.options[x].selected){
								catEntryId = document.sel_atributos_2.colores.options[x].value;
							}
						}
					} else if (l_ta1 > 1) {
						for(x=0; x<document.sel_atributos_2.talla1.options.length; x++){
							if(document.sel_atributos_2.talla1.options[x].selected){
								catEntryId = document.sel_atributos_2.talla1.options[x].value;
							}
						}
					} else {
						for(x=0; x<document.sel_atributos_2.talla2.options.length; x++){
							if(document.sel_atributos_2.talla2.options[x].selected){
								catEntryId = document.sel_atributos_2.talla2.options[x].value;
							}
						}
					}
					
					
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
				case 2:
					var catEntryId ='';
					var cantidad ='';
					
					for(x=0; x<document.sel_atributos_3.cantidad.options.length; x++){
						if(document.sel_atributos_3.cantidad.options[x].selected){
							cantidad = document.sel_atributos_3.cantidad.options[x].value;
						}
					}
					
					var l_col = document.sel_atributos_3.colores.options.length;
					var l_ta1 = document.sel_atributos_3.talla1.options.length;
					var l_ta2 = document.sel_atributos_3.talla2.options.length;
					
					if (l_col > 1 ) { 
						for(x=0; x<document.sel_atributos_3.colores.options.length; x++){
							if(document.sel_atributos_3.colores.options[x].selected){
								catEntryId = document.sel_atributos_3.colores.options[x].value;
							}
						}
					} else if (l_ta1 > 1) {
						for(x=0; x<document.sel_atributos_3.talla1.options.length; x++){
							if(document.sel_atributos_3.talla1.options[x].selected){
								catEntryId = document.sel_atributos_3.talla1.options[x].value;
							}
						}
					} else {
						for(x=0; x<document.sel_atributos_3.talla2.options.length; x++){
							if(document.sel_atributos_3.talla2.options[x].selected){
								catEntryId = document.sel_atributos_3.talla2.options[x].value;
							}
						}
					}
					
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
				case 3:
					var catEntryId ='';
					var cantidad ='';
					
					for(x=0; x<document.sel_atributos_4.cantidad.options.length; x++){
						if(document.sel_atributos_4.cantidad.options[x].selected){
							cantidad = document.sel_atributos_4.cantidad.options[x].value;
						}
					}
					
					var l_col = document.sel_atributos_4.colores.options.length;
					var l_ta1 = document.sel_atributos_4.talla1.options.length;
					var l_ta2 = document.sel_atributos_4.talla2.options.length;
					
					if (l_col > 1 ) { 
						for(x=0; x<document.sel_atributos_4.colores.options.length; x++){
							if(document.sel_atributos_4.colores.options[x].selected){
								catEntryId = document.sel_atributos_4.colores.options[x].value;
							}
						}
					} else if (l_ta1 > 1) {
						for(x=0; x<document.sel_atributos_4.talla1.options.length; x++){
							if(document.sel_atributos_4.talla1.options[x].selected){
								catEntryId = document.sel_atributos_4.talla1.options[x].value;
							}
						}
					} else {
						for(x=0; x<document.sel_atributos_4.talla2.options.length; x++){
							if(document.sel_atributos_4.talla2.options[x].selected){
								catEntryId = document.sel_atributos_4.talla2.options[x].value;
							}
						}
					}
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
				case 4:
					var catEntryId ='';
					var cantidad ='';
					
					for(x=0; x<document.sel_atributos_5.cantidad.options.length; x++){
						if(document.sel_atributos_5.cantidad.options[x].selected){
							cantidad = document.sel_atributos_5.cantidad.options[x].value;
						}
					}
					
					var l_col = document.sel_atributos_5.colores.options.length;
					var l_ta1 = document.sel_atributos_5.talla1.options.length;
					var l_ta2 = document.sel_atributos_5.talla2.options.length;
					
					if (l_col > 1 ) { 
						for(x=0; x<document.sel_atributos_5.colores.options.length; x++){
							if(document.sel_atributos_5.colores.options[x].selected){
								catEntryId = document.sel_atributos_5.colores.options[x].value;
							}
						}
					} else if (l_ta1 > 1) {
						for(x=0; x<document.sel_atributos_5.talla1.options.length; x++){
							if(document.sel_atributos_5.talla1.options[x].selected){
								catEntryId = document.sel_atributos_5.talla1.options[x].value;
							}
						}
					} else {
						for(x=0; x<document.sel_atributos_5.talla2.options.length; x++){
							if(document.sel_atributos_5.talla2.options[x].selected){
								catEntryId = document.sel_atributos_5.talla2.options[x].value;
							}
						}
					}
					
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
			}		

		}
		
		// URL
		var URL = document.createElement("input");
		URL.type = "hidden";
		f.appendChild(URL);
		URL.name ="URL";
		if(quick){
			//URL.value="OrderCalculate?URL=OrderItemDisplay?URL=QuickProfileValidationCmd?URL=QuickCheckOutProcessOrderCmd?URL=PHQuickCheckoutOrderSumaryView";
			URL.value="QuickProfileValidationCmd?URL=QuickCheckOutProcessOrderCmd?URL=OrderCalculate?URL=PHQuickCheckoutOrderSumaryView";
			// quick checkout flag
			var validateMOPD = document.createElement("input");
			validateMOPD.type = "hidden";
			f.appendChild(validateMOPD);
			validateMOPD.name ="validateMOPD";
			validateMOPD.value="false";
			// quick checkout flag
			var quickPurchase = document.createElement("input");
			quickPurchase.type = "hidden";
			f.appendChild(quickPurchase);
			quickPurchase.name ="quickPurchase";
			quickPurchase.value="true";
			//updatePrices
			var updatePrices = document.createElement("input");
			updatePrices.type = "hidden";
			updatePrices.name ="updatePrices";
			updatePrices.value="1";
			f.appendChild(updatePrices);
			//errorView
			var errorView = document.createElement("input");
			errorView.type = "hidden";
			errorView.name ="errorView";
			errorView.value="PHQuickCheckoutOrderSumaryView";
			f.appendChild(errorView);
			//quickCheckout
			var quickCheckout = document.createElement("input");
			quickCheckout.type  = "hidden";
			quickCheckout.name ="quickCheckout";
			quickCheckout.value="true";
			f.appendChild(quickCheckout);
		}else{
			// set url to calculete adjustments first and then redirect to the 
			// shopping cart
			URL.value="OrderCalculate?URL=OrderItemDisplay";
		}
		// orderId="."
		//Sets the current order to the last pending order
		var orderId = document.createElement("input");
		orderId.type = "hidden";
		f.appendChild(orderId);
		orderId.name ="orderId";
		orderId.value=".";
		
		// calculationUsageId="-1".
		var calculationUsageId = document.createElement("input");
		calculationUsageId.type = "hidden";
		f.appendChild(calculationUsageId);		
		calculationUsageId.name ="calculationUsageId";
		calculationUsageId.value="-1";
				
		// keepAutoAddedOrderItemsBeforeCalculate = "false". 
		// Remove all orderItems added by a promotion before a new calculation. 
		var keepOrderItems = document.createElement("input");
		keepOrderItems.type= "hidden";
		f.appendChild(keepOrderItems);
		keepOrderItems.name = "keepAutoAddedOrderItemsBeforeCalculate";
		keepOrderItems.value = "false";		

		// ------------------------
		// Merge all pending orders
		// ------------------------
			
//		var msg = "";
//		for(i=0; i<f.elements.length; i++){
//			msg = msg + " " + f.elements[i].name+ " :: " +f.elements[i].value;
//		}
//		alert(msg);
		f.submit();
	}
}
*/



function crearForma(store, catalog, category, lang, defaultItem, quick, userType){
	var f;
	if(validarCarrito()){
		// Create a form and add it to the document body
		f = document.createElement("form");
		document.body.appendChild(f);
		f.method = "POST"
		f.action="agregarArticulo";
				
		var storeId = document.createElement("input");
		storeId.type = "hidden";
		f.appendChild(storeId);
		storeId.name ="storeId";
		storeId.value=store;
		
		var catalogId = document.createElement("input");
		catalogId.type = "hidden";
		f.appendChild(catalogId);
		catalogId.name ="catalogId";
		catalogId.value=catalog;
		
		var categoryId = document.createElement("input");
		categoryId.type = "hidden";
		f.appendChild(categoryId);
		categoryId.name ="categoryId";
		categoryId.value=category;
		
		
		
		var mpCategoryId = document.createElement("input");
		mpCategoryId.type = "hidden";
		f.appendChild(mpCategoryId);
		mpCategoryId.name ="mpCategoryId";
		mpCategoryId.value =document.mp.mpCategoryId.value;
		
		var mpCatalogId = document.createElement("input");
		mpCatalogId.type = "hidden";
		f.appendChild(mpCatalogId);
		mpCatalogId.name ="mpCatalogId";
		mpCatalogId.value=document.mp.mpCatalogId.value;
		
				
		var langId = document.createElement("input");
		langId.type = "hidden";
		f.appendChild(langId);
		langId.name ="langId";
		langId.value=lang;

/*		var errorViewName = document.createElement("input");
		errorViewName.type = "hidden";
		f.appendChild(errorViewName);
		
		errorViewName.name ="errorViewName";
		if(userType == 'R'){			
			errorViewName.value="QuickCheckoutProfile";
		}else{
			errorViewName.value="LogonForm";
		}		*/
		
		var shouldCachePage = document.createElement("input");
		shouldCachePage.type = "hidden";
		f.appendChild(shouldCachePage);		
		shouldCachePage.name ="shouldCachePage";
		shouldCachePage.value="false";


		if(document.promotionCodes != null){
			for(i=0; i<document.promotionCodes.length; i++){
				if(document.promotionCodes[i].checked){
					var calCodeId = document.createElement("input");
					calCodeId.type = "hidden";
					f.appendChild(calCodeId);

					calCodeId.name ="calCodeId";
					calCodeId.value=document.promotionCodes[i].value;
				}
			}
		}
						
		// catentry and quantity
		for(i=0; i<contador-1; i++){
			switch(i){
				case 0:
					var cantidad ='';
					
					for(x=0; x<document.sel_atributos_1.cantidad.options.length; x++){
						if(document.sel_atributos_1.cantidad.options[x].selected){
							cantidad = document.sel_atributos_1.cantidad.options[x].value;
						}
					}
					
					var l_col = document.sel_atributos_1.colores.options.length;
					var l_ta1 = document.sel_atributos_1.talla1.options.length;
					var l_ta2 = document.sel_atributos_1.talla2.options.length;
					
					if (l_col > 1 || l_ta1 > 1 || l_ta2 > 1) {
						var catEntryId ='';
						
						if (l_col > 1 ) { 
							for(x=0; x<document.sel_atributos_1.colores.options.length; x++){
								if(document.sel_atributos_1.colores.options[x].selected){
									catEntryId = document.sel_atributos_1.colores.options[x].value;
								}
							}
						} else if (l_ta1 > 1) {
							for(x=0; x<document.sel_atributos_1.talla1.options.length; x++){
								if(document.sel_atributos_1.talla1.options[x].selected){
									catEntryId = document.sel_atributos_1.talla1.options[x].value;
								}
							}
						} else {
							for(x=0; x<document.sel_atributos_1.talla2.options.length; x++){
								if(document.sel_atributos_1.talla2.options[x].selected){
									catEntryId = document.sel_atributos_1.talla2.options[x].value;
								}
							}
						}
						
						if(catEntryId != '' && cantidad != ''){
							var catEntry = document.createElement("input");
							catEntry.type = "hidden";
							f.appendChild(catEntry);

							catEntry.name ="catEntryId_"+i;
							catEntry.value=catEntryId;
							
							var quantity = document.createElement("input");
							quantity.type = "hidden";
							f.appendChild(quantity);
									
							quantity.name ="quantity_"+i;
							quantity.value=cantidad;
						}
					}else{
							var catEntryId = document.createElement("input");
							catEntryId.type = "hidden";
							f.appendChild(catEntryId);
									
							catEntryId.name ="catEntryId_"+i;
							catEntryId.value=defaultItem;
							
							var quantity = document.createElement("input");
							quantity.type = "hidden";
							f.appendChild(quantity);
									
							quantity.name ="quantity_"+i;
							quantity.value=cantidad;

					}
					break;
				case 1:
					var catEntryId ='';
					var cantidad ='';
					
					for(x=0; x<document.sel_atributos_2.cantidad.options.length; x++){
						if(document.sel_atributos_2.cantidad.options[x].selected){
							cantidad = document.sel_atributos_2.cantidad.options[x].value;
						}
					}
					
					var l_col = document.sel_atributos_2.colores.options.length;
					var l_ta1 = document.sel_atributos_2.talla1.options.length;
					var l_ta2 = document.sel_atributos_2.talla2.options.length;
						
						
					if (l_col > 1 ) { 
						for(x=0; x<document.sel_atributos_2.colores.options.length; x++){
							if(document.sel_atributos_2.colores.options[x].selected){
								catEntryId = document.sel_atributos_2.colores.options[x].value;
							}
						}
					} else if (l_ta1 > 1) {
						for(x=0; x<document.sel_atributos_2.talla1.options.length; x++){
							if(document.sel_atributos_2.talla1.options[x].selected){
								catEntryId = document.sel_atributos_2.talla1.options[x].value;
							}
						}
					} else {
						for(x=0; x<document.sel_atributos_2.talla2.options.length; x++){
							if(document.sel_atributos_2.talla2.options[x].selected){
								catEntryId = document.sel_atributos_2.talla2.options[x].value;
							}
						}
					}
					
					
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
				case 2:
					var catEntryId ='';
					var cantidad ='';
					
					for(x=0; x<document.sel_atributos_3.cantidad.options.length; x++){
						if(document.sel_atributos_3.cantidad.options[x].selected){
							cantidad = document.sel_atributos_3.cantidad.options[x].value;
						}
					}
					
					var l_col = document.sel_atributos_3.colores.options.length;
					var l_ta1 = document.sel_atributos_3.talla1.options.length;
					var l_ta2 = document.sel_atributos_3.talla2.options.length;
					
					if (l_col > 1 ) { 
						for(x=0; x<document.sel_atributos_3.colores.options.length; x++){
							if(document.sel_atributos_3.colores.options[x].selected){
								catEntryId = document.sel_atributos_3.colores.options[x].value;
							}
						}
					} else if (l_ta1 > 1) {
						for(x=0; x<document.sel_atributos_3.talla1.options.length; x++){
							if(document.sel_atributos_3.talla1.options[x].selected){
								catEntryId = document.sel_atributos_3.talla1.options[x].value;
							}
						}
					} else {
						for(x=0; x<document.sel_atributos_3.talla2.options.length; x++){
							if(document.sel_atributos_3.talla2.options[x].selected){
								catEntryId = document.sel_atributos_3.talla2.options[x].value;
							}
						}
					}
					
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
				case 3:
					var catEntryId ='';
					var cantidad ='';
					
					for(x=0; x<document.sel_atributos_4.cantidad.options.length; x++){
						if(document.sel_atributos_4.cantidad.options[x].selected){
							cantidad = document.sel_atributos_4.cantidad.options[x].value;
						}
					}
					
					var l_col = document.sel_atributos_4.colores.options.length;
					var l_ta1 = document.sel_atributos_4.talla1.options.length;
					var l_ta2 = document.sel_atributos_4.talla2.options.length;
					
					if (l_col > 1 ) { 
						for(x=0; x<document.sel_atributos_4.colores.options.length; x++){
							if(document.sel_atributos_4.colores.options[x].selected){
								catEntryId = document.sel_atributos_4.colores.options[x].value;
							}
						}
					} else if (l_ta1 > 1) {
						for(x=0; x<document.sel_atributos_4.talla1.options.length; x++){
							if(document.sel_atributos_4.talla1.options[x].selected){
								catEntryId = document.sel_atributos_4.talla1.options[x].value;
							}
						}
					} else {
						for(x=0; x<document.sel_atributos_4.talla2.options.length; x++){
							if(document.sel_atributos_4.talla2.options[x].selected){
								catEntryId = document.sel_atributos_4.talla2.options[x].value;
							}
						}
					}
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
				case 4:
					var catEntryId ='';
					var cantidad ='';
					
					for(x=0; x<document.sel_atributos_5.cantidad.options.length; x++){
						if(document.sel_atributos_5.cantidad.options[x].selected){
							cantidad = document.sel_atributos_5.cantidad.options[x].value;
						}
					}
					
					var l_col = document.sel_atributos_5.colores.options.length;
					var l_ta1 = document.sel_atributos_5.talla1.options.length;
					var l_ta2 = document.sel_atributos_5.talla2.options.length;
					
					if (l_col > 1 ) { 
						for(x=0; x<document.sel_atributos_5.colores.options.length; x++){
							if(document.sel_atributos_5.colores.options[x].selected){
								catEntryId = document.sel_atributos_5.colores.options[x].value;
							}
						}
					} else if (l_ta1 > 1) {
						for(x=0; x<document.sel_atributos_5.talla1.options.length; x++){
							if(document.sel_atributos_5.talla1.options[x].selected){
								catEntryId = document.sel_atributos_5.talla1.options[x].value;
							}
						}
					} else {
						for(x=0; x<document.sel_atributos_5.talla2.options.length; x++){
							if(document.sel_atributos_5.talla2.options[x].selected){
								catEntryId = document.sel_atributos_5.talla2.options[x].value;
							}
						}
					}
					
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
			}		

		}
		
		// URL
		var URL = document.createElement("input");
		URL.type = "hidden";
		f.appendChild(URL);
		URL.name ="URL";
		if(quick){
			//URL.value="OrderCalculate?URL=OrderItemDisplay?URL=QuickProfileValidationCmd?URL=QuickCheckOutProcessOrderCmd?URL=PHQuickCheckoutOrderSumaryView";
			URL.value="QuickProfileValidationCmd?URL=QuickCheckOutProcessOrderCmd?URL=OrderCalculate?URL=PHQuickCheckoutOrderSumaryView";
			// quick checkout flag
			var validateMOPD = document.createElement("input");
			validateMOPD.type = "hidden";
			f.appendChild(validateMOPD);
			validateMOPD.name ="validateMOPD";
			validateMOPD.value="false";
			// quick checkout flag
			var quickPurchase = document.createElement("input");
			quickPurchase.type = "hidden";
			f.appendChild(quickPurchase);
			quickPurchase.name ="quickPurchase";
			quickPurchase.value="true";
			//updatePrices
			var updatePrices = document.createElement("input");
			updatePrices.type = "hidden";
			updatePrices.name ="updatePrices";
			updatePrices.value="1";
			f.appendChild(updatePrices);
			//errorView
			var errorView = document.createElement("input");
			errorView.type = "hidden";
			errorView.name ="errorView";
			errorView.value="PHQuickCheckoutOrderSumaryView";
			f.appendChild(errorView);
			//quickCheckout
			var quickCheckout = document.createElement("input");
			quickCheckout.type  = "hidden";
			quickCheckout.name ="quickCheckout";
			quickCheckout.value="true";
			f.appendChild(quickCheckout);
		}else{
			// set url to calculete adjustments first and then redirect to the 
			// shopping cart
			//URL.value="OrderCalculate?URL=OrderItemDisplay?";
			//URL.value="OrderCalculate?URL=consultarBolsaDeCompra";
			URL.value="consultarBolsaDeCompra?URL=bolsaComprasPopupView";
		}
		// orderId="."
		//Sets the current order to the last pending order
		var orderId = document.createElement("input");
		orderId.type = "hidden";
		f.appendChild(orderId);
		orderId.name ="orderId";
		orderId.value=".";
		
		// calculationUsageId="-1".
		var calculationUsageId = document.createElement("input");
		calculationUsageId.type = "hidden";
		f.appendChild(calculationUsageId);		
		calculationUsageId.name ="calculationUsageId";
		calculationUsageId.value="-1";
				
		// keepAutoAddedOrderItemsBeforeCalculate = "false". 
		// Remove all orderItems added by a promotion before a new calculation. 
		var keepOrderItems = document.createElement("input");
		keepOrderItems.type= "hidden";
		f.appendChild(keepOrderItems);
		keepOrderItems.name = "keepAutoAddedOrderItemsBeforeCalculate";
		keepOrderItems.value = "false";		

		// ------------------------
		// Merge all pending orders
		// ------------------------
			
//		var msg = "";
//		for(i=0; i<f.elements.length; i++){
//			msg = msg + " " + f.elements[i].name+ " :: " +f.elements[i].value;
//		}
//		alert(msg);
		//f.submit();
	}
	return f;
}

function listaDeseos(store, catalog, category, lang, defaultItem,MPCatalogId,MPCategoryId){
	if(validarWish()){
	
		// Create a form
		var f = document.createElement("form");
		
		// Add it to the document body
		document.body.appendChild(f);
		
		f.method = "POST"
		f.action="InterestItemAdd";
		
		var URL = document.createElement("input");
		URL.type = "hidden";
		f.appendChild(URL);
		
		URL.name ="URL";
		URL.value="InterestItemDisplay";
		
		var storeId = document.createElement("input");
		storeId.type = "hidden";
		f.appendChild(storeId);
		
		storeId.name ="storeId";
		storeId.value=store;
		
		var catalogId = document.createElement("input");
		catalogId.type = "hidden";
		f.appendChild(catalogId);
		
		catalogId.name ="catalogId";
		catalogId.value=catalog;
		
		var categoryId = document.createElement("input");
		categoryId.type = "hidden";
		f.appendChild(categoryId);
		
		categoryId.name ="categoryId";
		categoryId.value=category;
		
		var langId = document.createElement("input");
		langId.type = "hidden";
		f.appendChild(langId);
		
		langId.name ="langId";
		langId.value=lang;

		var errorViewName = document.createElement("input");
		errorViewName.type = "hidden";
		f.appendChild(errorViewName);
		
		errorViewName.name ="errorViewName";
		errorViewName.value="ProductDisplayErrorView";
				
		var calculationUsageId = document.createElement("input");
		calculationUsageId.type = "hidden";
		f.appendChild(calculationUsageId);
		
		calculationUsageId.name ="calculationUsageId";
		calculationUsageId.value="-1";
				
		var shouldCachePage = document.createElement("input");
		shouldCachePage.type = "hidden";
		f.appendChild(shouldCachePage);
		
		shouldCachePage.name ="shouldCachePage";
		shouldCachePage.value="false";
		
		var listId = document.createElement("input");
		listId.type = "hidden";
		f.appendChild(listId);
		
		listId.name ="listId";
		listId.value=".";
		
		var mpCatalogId = document.createElement("input");
		mpCatalogId.type = "hidden";
		f.appendChild(mpCatalogId);
		
		mpCatalogId.name ="mpCatalogId";
		mpCatalogId.value=MPCatalogId;
		
		
		var mpCategoryId = document.createElement("input");
		mpCategoryId.type = "hidden";
		f.appendChild(mpCategoryId);
		
		mpCategoryId.name ="mpCategoryId";
		mpCategoryId.value=MPCategoryId;						

		for(i=0; i<contador-1; i++){
			switch(i){
				case 0:
					var cantidad ='';
					for(x=0; x<document.sel_atributos_1.cantidad.options.length; x++){
						if(! document.sel_atributos_1.cantidad.options[x].selected){
							cantidad = 1;
						}
					}
					if(document.sel_atributos_1.colores.options.length > 1){
						var catEntryId ='';
						for(x=0; x<document.sel_atributos_1.colores.options.length; x++){
							if(document.sel_atributos_1.colores.options[x].selected){
								catEntryId = document.sel_atributos_1.colores.options[x].value;
							}
						}
						if(catEntryId != '' && cantidad != ''){
							var catEntry = document.createElement("input");
							catEntry.type = "hidden";
							f.appendChild(catEntry);

							catEntry.name ="catEntryId_"+i;
							catEntry.value=catEntryId;
							
							var quantity = document.createElement("input");
							quantity.type = "hidden";
							f.appendChild(quantity);
									
							quantity.name ="quantity_"+i;
							quantity.value=cantidad;
						}
					}else{
							var catEntryId = document.createElement("input");
							catEntryId.type = "hidden";
							f.appendChild(catEntryId);
									
							catEntryId.name ="catEntryId_"+i;
							catEntryId.value=defaultItem;
							
							var quantity = document.createElement("input");
							quantity.type = "hidden";
							f.appendChild(quantity);
									
							quantity.name ="quantity_"+i;
							quantity.value=cantidad;

					}
					break;
				case 1:
					var catEntryId ='';
					var cantidad ='';
					for(x=0; x<document.sel_atributos_2.colores.options.length; x++){
						if(document.sel_atributos_2.colores.options[x].selected){
							catEntryId = document.sel_atributos_2.colores.options[x].value;
						}
					}
					for(x=0; x<document.sel_atributos_2.cantidad.options.length; x++){
						if(document.sel_atributos_2.cantidad.options[x].selected){
							cantidad = document.sel_atributos_2.cantidad.options[x].value;
						}
					}
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
				case 2:
					var catEntryId ='';
					var cantidad ='';
					for(x=0; x<document.sel_atributos_3.colores.options.length; x++){
						if(document.sel_atributos_3.colores.options[x].selected){
							catEntryId = document.sel_atributos_3.colores.options[x].value;
						}
					}
					for(x=0; x<document.sel_atributos_3.cantidad.options.length; x++){
						if(document.sel_atributos_3.cantidad.options[x].selected){
							cantidad = document.sel_atributos_3.cantidad.options[x].value;
						}
					}
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
				case 3:
					var catEntryId ='';
					var cantidad ='';
					for(x=0; x<document.sel_atributos_4.colores.options.length; x++){
						if(document.sel_atributos_4.colores.options[x].selected){
							catEntryId = document.sel_atributos_4.colores.options[x].value;
						}
					}
					for(x=0; x<document.sel_atributos_4.cantidad.options.length; x++){
						if(document.sel_atributos_4.cantidad.options[x].selected){
							cantidad = document.sel_atributos_4.cantidad.options[x].value;
						}
					}
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
				case 4:
					var catEntryId ='';
					var cantidad ='';
					for(x=0; x<document.sel_atributos_5.colores.options.length; x++){
						if(document.sel_atributos_5.colores.options[x].selected){
							catEntryId = document.sel_atributos_5.colores.options[x].value;
						}
					}
					for(x=0; x<document.sel_atributos_5.cantidad.options.length; x++){
						if(document.sel_atributos_5.cantidad.options[x].selected){
							cantidad = document.sel_atributos_5.cantidad.options[x].value;
						}
					}
					if(catEntryId != '' && cantidad != ''){
						var catEntry = document.createElement("input");
						catEntry.type = "hidden";
						f.appendChild(catEntry);

						catEntry.name ="catEntryId_"+i;
						catEntry.value=catEntryId;

						var quantity = document.createElement("input");
						quantity.type = "hidden";
						f.appendChild(quantity);

						quantity.name ="quantity_"+i;
						quantity.value=cantidad;
					}
					break;
			}		

		}
		
/****** Imprimir los elementos del form para saber que se esta enviando.*********************
	for(i=0; i<f.elements.length; i++){
		alert("Nombre: "+f.elements[i].name+"   Valor: "+f.elements[i].value);
	}
********************************************************************************************/

		f.submit();
	}
}


function validarCarrito(){
	for(i=0; i<contador-1; i++){
		var forma = null;
		switch(i){
		//CAMBIO: EVALUA LA OPCION SELECCIONADA EN VEZ DE SOLO EL  VALOR
			case 0:				
				if(document.sel_atributos_1.cantidad.value==0){
					alert('Por favor selecciona una cantidad para el 1er Producto');
					return false;
				}
				if(document.sel_atributos_1.colores.options.length>1){
					if(document.sel_atributos_1.colores.options[0].selected){
						alert('Por favor selecciona un color para el 1er Producto');
						return false;
					}
				}
				if(document.sel_atributos_1.talla1.options.length>1){
					if(document.sel_atributos_1.talla1.options[0].selected){
						alert('Por favor selecciona una talla1 para el 1er Producto');
						return false;
					}
				}
				if(document.sel_atributos_1.talla2.options.length>1){
					if(document.sel_atributos_1.talla2.options[0].selected){
						alert('Por favor selecciona una talla2 para el 1er Producto');
						return false;
					}
				}

				break;
			case 1:
				if(document.sel_atributos_2.cantidad.value==0){
					alert('Por favor selecciona una cantidad para el 2o Producto');
					return false;
				}
				if(document.sel_atributos_2.colores.options.length>1){
					if(document.sel_atributos_2.colores.options[0].selected){
						alert('Por favor selecciona un color para el 2o Producto');
						return false;
					}
				}
				if(document.sel_atributos_2.talla1.options.length>1){
					if(document.sel_atributos_2.talla1.options[0].selected){
						alert('Por favor selecciona una talla1 para el 2o Producto');
						return false;
					}
				}
				if(document.sel_atributos_2.talla2.options.length>1){
					if(document.sel_atributos_2.talla2.options[0].selected){
						alert('Por favor selecciona una talla2 para el 2o Producto');
						return false;
					}
				}

				break;
			case 2:
				if(document.sel_atributos_3.cantidad.value==0){
					alert('Por favor selecciona una cantidad para el 3er Producto');
					return false;
				}
				if(document.sel_atributos_3.colores.options.length>1){
					if(document.sel_atributos_3.colores.options[0].selected){
						alert('Por favor selecciona un color para el 3er Producto');
						return false;
					}
				}
				if(document.sel_atributos_3.talla1.options.length>1){
					if(document.sel_atributos_3.talla1.options[0].selected){
						alert('Por favor selecciona una talla1 para el 3er Producto');
						return false;
					}
				}
				if(document.sel_atributos_3.talla2.options.length>1){
					if(document.sel_atributos_3.talla2.options[0].selected){
						alert('Por favor selecciona una talla2 para el 3er Producto');
						return false;
					}
				}

				break;
			case 3:
				if(document.sel_atributos_4.cantidad.value==0){
					alert('Por favor selecciona una cantidad para el 4o Producto');
					return false;
				}
				if(document.sel_atributos_4.colores.options.length>1){
					if(document.sel_atributos_4.colores.options[0].selected){
						alert('Por favor selecciona un color para el 4o Producto');
						return false;
					}
				}
				if(document.sel_atributos_4.talla1.options.length>1){
					if(document.sel_atributos_4.talla1.options[0].selected){
						alert('Por favor selecciona una talla1 para el 4o Producto');
						return false;
					}
				}
				if(document.sel_atributos_4.talla2.options.length>1){
					if(document.sel_atributos_4.talla2.options[0].selected){
						alert('Por favor selecciona una talla2 para el 4o Producto');
						return false;
					}
				}

				break;
			case 4:
				if(document.sel_atributos_5.cantidad.value==0){
					alert('Por favor selecciona una cantidad para el 5o Producto');
					return false;
				}
				if(document.sel_atributos_5.colores.options.length>1){
					if(document.sel_atributos_5.colores.options[0].selected){
						alert('Por favor selecciona un color para el 5o Producto');
						return false;
					}
				}
				if(document.sel_atributos_5.talla1.options.length>1){
					if(document.sel_atributos_5.talla1.options[0].selected){
						alert('Por favor selecciona una talla1 para el 5o Producto');
						return false;
					}
				}
				if(document.sel_atributos_5.talla2.options.length>1){
					if(document.sel_atributos_5.talla2.options[0].selected){
						alert('Por favor selecciona una talla2 para el 5o Producto');
						return false;
					}
				}

				break;
		}
	}
	return true;
}

function validarWish(){
	for(i=0; i<contador-1; i++){
		var forma = null;
		switch(i){
			case 0:
				if(document.sel_atributos_1.colores.options.length>1){
					if(document.sel_atributos_1.colores.options[0].selected){
						alert('Por favor selecciona un color para el 1er Producto');
						return false;
					}
				}
				if(document.sel_atributos_1.talla1.options.length>1){
					if(document.sel_atributos_1.talla1.options[0].selected){
						alert('Por favor selecciona una talla1 para el 1er Producto');
						return false;
					}
				}
				if(document.sel_atributos_1.talla2.options.length>1){
					if(document.sel_atributos_1.talla2.options[0].selected){
						alert('Por favor selecciona una talla2 para el 1er Producto');
						return false;
					}
				}

				break;
			case 1:
				if(document.sel_atributos_2.colores.options.length>1){
					if(document.sel_atributos_2.colores.options[0].selected){
						alert('Por favor selecciona un color para el 2o Producto');
						return false;
					}
				}
				if(document.sel_atributos_2.talla1.options.length>1){
					if(document.sel_atributos_2.talla1.options[0].selected){
						alert('Por favor selecciona una talla1 para el 2o Producto');
						return false;
					}
				}
				if(document.sel_atributos_2.talla2.options.length>1){
					if(document.sel_atributos_2.talla2.options[0].selected){
						alert('Por favor selecciona una talla2 para el 2o Producto');
						return false;
					}
				}

				break;
			case 2:
				if(document.sel_atributos_3.colores.options.length>1){
					if(document.sel_atributos_3.colores.options[0].selected){
						alert('Por favor selecciona un color para el 3er Producto');
						return false;
					}
				}
				if(document.sel_atributos_3.talla1.options.length>1){
					if(document.sel_atributos_3.talla1.options[0].selected){
						alert('Por favor selecciona una talla1 para el 3er Producto');
						return false;
					}
				}
				if(document.sel_atributos_3.talla2.options.length>1){
					if(document.sel_atributos_3.talla2.options[0].selected){
						alert('Por favor selecciona una talla2 para el 3er Producto');
						return false;
					}
				}

				break;
			case 3:
				if(document.sel_atributos_4.colores.options.length>1){
					if(document.sel_atributos_4.colores.options[0].selected){
						alert('Por favor selecciona un color para el 4o Producto');
						return false;
					}
				}
				if(document.sel_atributos_4.talla1.options.length>1){
					if(document.sel_atributos_4.talla1.options[0].selected){
						alert('Por favor selecciona una talla1 para el 4o Producto');
						return false;
					}
				}
				if(document.sel_atributos_4.talla2.options.length>1){
					if(document.sel_atributos_4.talla2.options[0].selected){
						alert('Por favor selecciona una talla2 para el 4o Producto');
						return false;
					}
				}

				break;
			case 4:
				if(document.sel_atributos_5.colores.options.length>1){
					if(document.sel_atributos_5.colores.options[0].selected){
						alert('Por favor selecciona un color para el 5o Producto');
						return false;
					}
				}
				if(document.sel_atributos_5.talla1.options.length>1){
					if(document.sel_atributos_5.talla1.options[0].selected){
						alert('Por favor selecciona una talla1 para el 5o Producto');
						return false;
					}
				}
				if(document.sel_atributos_5.talla2.options.length>1){
					if(document.sel_atributos_5.talla2.options[0].selected){
						alert('Por favor selecciona una talla2 para el 5o Producto');
						return false;
					}
				}

				break;
		}
	}
	return true;
}


function agregar(){

	switch(contador){
		case 1:
			if(validarCarrito()){
				contador++;
				poblar(document.sel_atributos_1.colores,document.sel_atributos_1.talla1,document.sel_atributos_1.talla2,combo_colores,combo_talla1, combo_talla2, stock_colores, stock_talla1, stock_talla2, document.sel_atributos_1.cantidad);
			}
			break;
		case 2:
			if(validarCarrito()){
				contador++;
				poblar(document.sel_atributos_2.colores,document.sel_atributos_2.talla1,document.sel_atributos_2.talla2,combo_colores,combo_talla1, combo_talla2, stock_colores, stock_talla1, stock_talla2, document.sel_atributos_2.cantidad); 
			}
			break;
		case 3:
			if(validarCarrito()){
				contador++;
				poblar(document.sel_atributos_3.colores,document.sel_atributos_3.talla1,document.sel_atributos_3.talla2,combo_colores,combo_talla1, combo_talla2, stock_colores, stock_talla1, stock_talla2, document.sel_atributos_3.cantidad); 
			}
			break;
		case 4:
			if(validarCarrito()){
				contador++;
				poblar(document.sel_atributos_4.colores,document.sel_atributos_4.talla1,document.sel_atributos_4.talla2,combo_colores,combo_talla1, combo_talla2, stock_colores, stock_talla1, stock_talla2, document.sel_atributos_4.cantidad); 
			}
			break;
		case 5:
			if(validarCarrito()){
				contador++;
				poblar(document.sel_atributos_5.colores,document.sel_atributos_5.talla1,document.sel_atributos_5.talla2,combo_colores,combo_talla1, combo_talla2, stock_colores, stock_talla1, stock_talla2, document.sel_atributos_5.cantidad); 
			}
			break;

	}
}

function borrar(){

	switch(contador){
		case 3:
			contador--;
			tamanio = document.sel_atributos_2.colores.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_2.colores.options[x] = null;
			tamanio = document.sel_atributos_2.talla1.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_2.talla1.options[x] = null;
			tamanio = document.sel_atributos_2.talla2.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_2.talla2.options[x] = null;

			document.sel_atributos_2.cantidad.style.display = "none";
			document.sel_atributos_2.colores.style.display = "none";
			document.sel_atributos_2.talla1.style.display = "none";
			document.sel_atributos_2.talla2.style.display = "none";
			document.getElementById('borrarImg').style.display = "none";
			
			
			break;
		case 4:
			contador--;
			tamanio = document.sel_atributos_3.colores.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_3.colores.options[x] = null;
			tamanio = document.sel_atributos_3.talla1.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_3.talla1.options[x] = null;
			tamanio = document.sel_atributos_3.talla2.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_3.talla2.options[x] = null;

			document.sel_atributos_3.cantidad.style.display = "none";
			document.sel_atributos_3.colores.style.display = "none";
			document.sel_atributos_3.talla1.style.display = "none";
			document.sel_atributos_3.talla2.style.display = "none";
			
			break;
		case 5:
			contador--;
			tamanio = document.sel_atributos_4.colores.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_4.colores.options[x] = null;
			tamanio = document.sel_atributos_4.talla1.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_4.talla1.options[x] = null;
			tamanio = document.sel_atributos_4.talla2.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_4.talla2.options[x] = null;

			document.sel_atributos_4.cantidad.style.display = "none";
			document.sel_atributos_4.colores.style.display = "none";
			document.sel_atributos_4.talla1.style.display = "none";
			document.sel_atributos_4.talla2.style.display = "none";
			
			break;
		case 6:
			contador--;
			tamanio = document.sel_atributos_5.colores.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_5.colores.options[x] = null;
			tamanio = document.sel_atributos_5.talla1.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_5.talla1.options[x] = null;
			tamanio = document.sel_atributos_5.talla2.options.length-1;
			for(x=tamanio; x>0; x--)
				document.sel_atributos_5.talla2.options[x] = null;

			document.sel_atributos_5.cantidad.style.display = "none";
			document.sel_atributos_5.colores.style.display = "none";
			document.sel_atributos_5.talla1.style.display = "none";
			document.sel_atributos_5.talla2.style.display = "none";
			document.getElementById('agregarImg').style.display = "";
			
			break;

	}
}

function existeSel(element,select){
	var res = false;

	for(y=0; y<select.options.length; y++){
		if(select.options[y].text == element){
			res=true;
			break;
		}
	}
	
	return res;
}

function existeArray(element,array){
	var res = false;
	for(y=0; y<array.length; y++){
		if(array[y] == element){
			res=true;
			break;
		}
	}
	
	return res;
}

function ordena(arreglo, base){
	var resultado = new Array();
	var contador=0;
	for(i=0; i<base.length; i++){
		for(j=0; j<arreglo.length; j++){
			if(base[i] == arreglo[j] && !existeArray(arreglo[j], resultado)){
				resultado[contador] = arreglo[j];
				contador++;
			}
		}
	}
	return resultado;
}


function poblar(sel_att_curr, sel_att1, sel_att2, dist_att_curr, dist_att1,
 dist_att2, stock_att_curr, stock_att1, stock_att2, cantidad_combo){
 
 	if( sel_att_curr.options[0].selected ){
		for(x=1; x<sel_att_curr.options.length; x++)
			sel_att_curr.options[x] = null;
		for(x=1; x<sel_att1.options.length; x++)
			sel_att1.options[x] = null;
		for(x=1; x<sel_att2.options.length; x++)
			sel_att2.options[x] = null;

		for(x=0; x<dist_att_curr.length; x++)
			sel_att_curr.options[x+1] = new Option(dist_att_curr[x],dist_att_curr[x]);
		for(x=0; x<dist_att1.length; x++)
			sel_att1.options[x+1] = new Option(dist_att1[x],dist_att1[x]);
		for(x=0; x<dist_att2.length; x++)
			sel_att2.options[x+1] = new Option(dist_att2[x],dist_att2[x]);

		sel_att_curr.options[0].selected = true;	
		sel_att1.options[0].selected = true;
		sel_att2.options[0].selected = true;
	}else{

		var sel_att_curr_old = null;
		var sel_att1_old = null;
		var sel_att2_old = null;
		var tamanio = 0;
			
		for(x=0; x<sel_att_curr.options.length; x++) {
			if(sel_att_curr.options[x].selected) {
				sel_att_curr_old = sel_att_curr.options[x].text;
			}
		}
		
		if(sel_att1.options.length > 1){
			tamanio = sel_att1.options.length-1;
			for(x=tamanio; x>0; x--){
				if(sel_att1.options[x].selected){
					sel_att1_old = sel_att1.options[x].text;
				}
				sel_att1.options[x] = null;
			}
		}
			
		if(sel_att2.options.length > 1){
			tamanio = sel_att2.options.length-1;
			for(x=tamanio; x>0; x--){
				if(sel_att2.options[x].selected)
					sel_att2_old = sel_att2.options[x].text;
				sel_att2.options[x] = null;
			}
		}
			
			for(x=0; x<stock_att_curr.length; x++){
				if(stock_att_curr[x] == sel_att_curr_old){
					if(sel_att1_old == null){
						if(sel_att2_old == null){
							if(stock_att1.length > 0){
								if(!existeSel(stock_att1[x],sel_att1)){
									var idx = sel_att1.options.length;
									sel_att1.options[idx] = new Option(stock_att1[x],prodIds[x]);
									if(sel_att1.options[idx].text == sel_att1_old)
										sel_att1.options[idx].selected = true;
								}
							}
							if(stock_att2.length > 0){
								if(!existeSel(stock_att2[x],sel_att2)){
									var idx = sel_att2.options.length;
									sel_att2.options[idx] = new Option(stock_att2[x],prodIds[x]);
									if(sel_att2.options[idx].text == sel_att2_old)
										sel_att2.options[idx].selected = true;
								}
							} 
							
							if ((stock_att1.length < 1) &&  (stock_att2.length < 1)) {
									sel_att_curr.options[x+1] = new Option(stock_att_curr[x],prodIds[x]);						
									sel_att_curr.options[x+1].selected = true;
							}
							
						}else{
							if(stock_att2[x] == sel_att2_old){
								if(stock_att1.length > 0){
									if(!existeSel(stock_att1[x],sel_att1)){
										var idx = sel_att1.options.length;
										sel_att1.options[idx] = new Option(stock_att1[x],prodIds[x]);
										if(sel_att1.options[idx].text == sel_att1_old)
											sel_att1.options[idx].selected = true
									}
								}
								if(stock_att2.length > 0){
									if(!existeSel(stock_att2[x],sel_att2)){
										var idx = sel_att2.options.length;
										sel_att2.options[idx] = new Option(stock_att2[x],prodIds[x]);
										if(sel_att2.options[idx].text == sel_att2_old)
											sel_att2.options[idx].selected = true;
									}
								}
							}
						}
					}else{
						if(stock_att1[x]== sel_att1_old){
							if(sel_att2_old == null){			
								if(stock_att1.length > 0) {
									if(!existeSel(stock_att1[x],sel_att1)){
										var idx = sel_att1.options.length;
										sel_att1.options[idx] = new Option(stock_att1[x],prodIds[x]);
										if(sel_att1.options[idx].text == sel_att1_old)
											sel_att1.options[idx].selected = true
									}
								}
								if(stock_att2.length > 0) {
									if(!existeSel(stock_att2[x],sel_att2)){
										var idx = sel_att2.options.length;
										sel_att2.options[idx] = new Option(stock_att2[x],prodIds[x]);
										if(sel_att2.options[idx].text == sel_att2_old)
											sel_att2.options[idx].selected = true;
									}
								}
							}else{
								if(stock_att2[x]== sel_att2_old){
									if(stock_att1.length > 0){
										if(!existeSel(stock_att1[x],sel_att1)){
											var idx = sel_att1.options.length;
											sel_att1.options[idx] = new Option(stock_att1[x],prodIds[x]);
											if(sel_att1.options[idx].text == sel_att1_old)
												sel_att1.options[idx].selected = true
										}
									}
									if(stock_att2.length > 0){
										if(!existeSel(stock_att2[x],sel_att2)){
											var idx = sel_att2.options.length;
											sel_att2.options[idx] = new Option(stock_att2[x],prodIds[x]);
											if(sel_att2.options[idx].text == sel_att2_old)
												sel_att2.options[idx].selected = true;
										}
									}
								}
							}
						}
					}				
				}
			}
	}
	
	var display_agregar =0;
	
	if(sel_att_curr.options.length > 1){
		sel_att_curr.style.display = "";
	}else{
		sel_att_curr.style.display = "none";
		display_agregar++;
	}
	
	if(sel_att1.options.length > 1){
		sel_att1.style.display = "";
	}else{
		sel_att1.style.display = "none";
		display_agregar++;		
	}
	
	               
	if(sel_att2.options.length > 1){
		sel_att2.style.display = "";
	}else{
		sel_att2.style.display = "none";
		display_agregar++;
	}
	
	if(display_agregar==3){
		document.getElementById('agregarImg').style.display = "none";
		document.getElementById('borrarImg').style.display = "none";
	}else{
		if(contador<=5){
			document.getElementById('agregarImg').style.display = "";
		}else{
			document.getElementById('agregarImg').style.display = "none";
		}
		
		if(contador>=3){
			document.getElementById('borrarImg').style.display = "";
		}else{
			document.getElementById('borrarImg').style.display = "none";
		}
	}
	
	cantidad_combo.style.display="";
	document.getElementById('div_cantidad_'+(contador-1)).style.display = "";

}
