$(document).ready(function(){

	// $("body#productinfoBody input:image").css("border","1px solid red");
	
	$("body#productinfoBody input:image").bind("click", 
		function() { 
			if ( $("select option:selected").text() == "select size" ) {
				
				/* size not select, cancel */
				alert('Please select a size'); 
				return false; 
			}
		}
	);


	/* for the popup window in the spec buttons */
	$("a.popupbutton").each(function(i) {
		var linkstring = $(this).attr("href"); // 'http://www.warmnsafe.com/size_chart_liner.htm';
		var clickstring = "window.open(\'" + linkstring + "\',\'POPUPWIN\',\'toolbar=no,location=no, directories=no, status=yes,menubar=no, resizable=yes, scrollbars=yes, top=50, left=50, width=600,height=900\')";
	
		$(this).attr("href","javascript:void(0)");
		
				$( this ).bind (
				"click",
				function(){
					window.open(linkstring,'POPUPWIN','toolbar=no,location=no, directories=no, status=yes,menubar=no, resizable=yes, scrollbars=yes, top=50, left=50, width=600,height=900');
				}
				);
	});

	$("a.popupbuttonlong").each(function(i) {
		var linkstring = $(this).attr("href"); // 'http://www.warmnsafe.com/size_chart_liner.htm';
		var clickstring = "window.open(\'" + linkstring + "\',\'POPUPWIN\',\'toolbar=no,location=no, directories=no, status=yes,menubar=no, resizable=yes, scrollbars=yes, top=50, left=50, width=600,height=900\')";
	
		$(this).attr("href","javascript:void(0)");
		
				$( this ).bind (
				"click",
				function(){
					window.open(linkstring,'POPUPWIN','toolbar=no,location=no, directories=no, status=yes,menubar=no, resizable=yes, scrollbars=yes, top=50, left=50, width=600,height=900');
				}
				);
	});

	
	/* for the category listing page: check that size is selected*/
	$("form[name='cart_quantity']").each(
		function(i) {
			var elementid = $(this).attr("id");
			if ( elementid.substr(0,9) == "orderform" ) {
				
					$(this).submit(function(){
						
							var numElem = $(this).children().length;
							for ( var j=0; j < numElem; j++ ) {
								if ( $(this).children().get(j).tagName == "SELECT" || $(this).children().get(j).tagName == "select" ){
									var selectbox = $(this).children().get(j);
									if (selectbox.options[selectbox.selectedIndex].innerHTML == "select size" ) {
										alert("Please select size");
										return false;
									} else {
										return true;	
									}
								}
							}


						});
								
			}
		}
		
	)
										 
	
	
	

 });

