// JavaScript Document

var VcAttributeValidator = {

			toValidate: [],

			addAttribute: function(options) {
				this.toValidate.push({
					'type' : options['type'],
					'formElementId' : options['formElementId'],
					'itemId' : options['itemId'],
					'itemName' : options['itemName'],
					'styleId' : options['styleId'],
					'styleName' : options['styleName'],
					'radioOptions' : options['radioOptions'] ? options['radioOptions'] : [],
					'isPkg' : options['isPkg'] ? options['isPkg'] : false,
					'isCrossSelling': options['isCrossSelling'] ? options['isCrossSelling'] : false,
					getAttributeName: function() {
						var attributeName = '';
						if(this != null) {
							if(this.isPkg || this.isCrossSelling) {
								attributeName = this.itemName+' - '+this.styleName;
							} else {
								attributeName = this.styleName;
							}
						}
						return attributeName;
					}			
				});		
			},

			validate: function(formName) {
				var vcErrorText = '';
				var vcForm = document.getElementById(formName);

				if(this.toValidate.length > 0) {
					for(var i = 0; i < this.toValidate.length;i++) {
						var vcFormAttribute = null;
						var crossSellingChecked = false;
						var attribute = this.toValidate[i];

						if(attribute.isCrossSelling) {
							vcCrossItem = document.getElementById('checkbox-attr-'+attribute.itemId);
							if(vcCrossItem != null) {
								if(vcCrossItem.checked) {
									crossSellingChecked = true;
								}
							}
						}				
						if(attribute.type == 'select' || attribute.type == 'text') {
							if(attribute.isCrossSelling) {
								if(crossSellingChecked) {
									var vcFormAttribute = document.getElementById(attribute.formElementId);
								}						
							} else {
								var vcFormAttribute = document.getElementById(attribute.formElementId);				
							}				
							if(vcFormAttribute != null) {
								if((attribute.type == 'select' && (vcFormAttribute.value == '' || vcFormAttribute.value == 0)) ||
								   (attribute.type == 'text' && vcFormAttribute.value == '')) { 
									vcErrorText += attribute.getAttributeName()+' is required.\n';
								}									
							}					
						} else if(attribute.type == 'radio') {
							if((attribute.isCrossSelling && crossSellingChecked) || !attribute.isCrossSelling) {									
								if(attribute.radioOptions.length > 0) {
									vcRadioChecked = false;
									for(var iRadio = 0; iRadio < attribute.radioOptions.length; iRadio++) {
										var vcRadioAttributeOption = document.getElementById(attribute.radioOptions[iRadio]);
										if(vcRadioAttributeOption != null) {
											if(vcRadioAttributeOption.checked) {
												vcRadioChecked = true;
											}
										}
									}
									if(!vcRadioChecked) {
										vcErrorText += attribute.getAttributeName()+' is required.\n';
									}						
								}
							}					
						}						
					}			
				}		

				if(vcErrorText != '') { 
					alert(vcErrorText); 
					return false; 
				} else if(vcForm != null) { 
					vcForm.submit(); 
				}
				return false;				
			}	
		}
		
								VcAttributeValidator.addAttribute({
									type: 'select', 
									formElementId: 'vcSelectAttribute-6-105', 
									itemId: '105', 
									itemName: 'Sclerotherapy of the Legs', 
									styleId: '6', 
									styleName: 'City/Date',
									isCrossSelling: false,
									isPkg: false
								});	