// JavaScript Document

function getOption() {
	
	if ($('#option_1').length > 0) {
		
		if ($('#option_1').val() == '') return;
		
		$('#option_2cont').html('');
		$('#option_1').attr('name', 'option_1');
		mainimage = mainproductimage;
		changeImage(false);
	
		$.getJSON(BASE_HREF+'_ajax/product_option.php', { products_id: $('#option_1').val() },
			function(json){
				if (json.count == '0') {
					$('#option_1').attr('name', 'products_id');
					$('#option_2cont').html('');
				} else {
					$('#option_2cont').html(json.html);
					$('#option_1').attr('name', 'option_1');
				}
				
				if (json.image != '') {
					mainimage = json.image;
					changeImage(false);
				}
			});
		
		return;
	}
	
}

function validateForm(submitontrue) {
		
	var labels = $('#productbuttons').find('label');
		
	var option1_count = $('#option_1').length;
	var option2_count = $('#option_2').length;
	
	if (option1_count > 0) {
		if ($('#option_1').val() != '') {
			
			if ($('#option_1')[0].options[$('#option_1').selectedIndex].attr('haschildren') == '1' && option2_count == 0) {
				return false;
			}
			
			if (option2_count == 1) {
				if ($('#option_2').val() != '') {
					if (submitontrue == 1) {
						$('#productform')[0].submit();
					} else
						return true;
				} else {
					
					var oos = /Out Of Stock/;
					if ($('#option_2').options[$('#option_2').selectedIndex].text.search(oos)) {
						alert("The size you've chosen is Out Of Stock.");
						return false;
					} else {
					
						alert('Please choose a size.');
						return false;
					
					}
				}
			} else {
				if (submitontrue == 1) {
					$('#productform').submit();
				} else
					return true;
			}
		} else {
			alert('Please choose a color.');
			return false;
		}
	} else {
		return true;
	}
	return false;
}
