<?php
	//If user is not signed in redirect
	if(!$user->signed) redirect("?page=login");	
?>
<script>
$(document).ready(function() {
	
//form validation rules
	//add a custom method to check for zeros
	$.validator.addMethod("notEqual", function(value, element, param) {
  		return this.optional(element) || value != param;
	  }, "Please enter a number >0");
	// we need to have the validation plugin still validate hidden fields which we dynamically set with display:none propert
	 $.validator.setDefaults({
        ignore: []
    });

	
	var validator = $( "#geom" ).validate({
  		rules: {
			heated_width : {
				required: true,
				number: true,
				notEqual: 0,
                max: 1000
			},
  			heated_length : {
				required: true,
				number: true,
				notEqual: 0,
                max: 500
			},
    	 	base_thickness: {
     	 		required: true,
				number: true,
      		 	range: [1, 12]
    		},
			fin_type: {
     	 		required: true
    		},
			fin_width: {
     	 		required: true,
				number: true,
      		 	range: [0.1, 1.0]
    		},
			fin_height: {
     	 		required: true,
				number: true,
      		 	range: [0.5, 6.0]
    		},
			tim_thickness: {
     	 		required: true,
				number: true,
				range: [0, 1500]
    		},
			channel_roughness: {
     	 		required: true,
				number: true,
				min: 0
    		},
			channel_width: {
     	 		required: true,
				number: true,
				min: 0
    		},
			heated_thickness: {
     	 		required: true,
				number: true,
				min: 0
    		}
			
		},
		messages: {
			//we will turn some messages off (the hidden fields)
			channel_width: "",
			channel_roughness: "",
			heated_thickness: ""
			
		}
	});
	
	
	//configure fin options based on user inputs
	var fin_type =  $("#fin_type option:selected").val();
	var fin_width = $('#fin_width');
	var fin_width_p = $('#fin_width_p');
	var fin_options_p = $('#fin_options_p');
	
	
	if( typeof fin_type == 'undefined' ) {
		fin_width.val("0.1");
		fin_width.removeAttr('readonly');
		fin_width_p.toggle(true);
		fin_options_p.toggle(false);
	} else if ( fin_type === "0" ) {fin_width_p.toggle(true);fin_options_p.toggle(false);fin_width.removeAttr('readonly');} 
	else {
				fin_width.attr('readonly','readonly');
				fin_width_p.toggle(false);
				
				//hide 40 FPI (Copper) option if fin_type != 1 (straight fin Wolverine)
				if ( fin_type !== "1" ) {
					$("#fin_options option[value=3]").attr('disabled','disabled')
				} else {
				
					$("#fin_options option[value=3]").removeAttr('disabled');

				}
				
				fin_options_p.toggle(true);
				
	}
	
	//change fin width options when fin_type changes
	$("#fin_type").change(function() {
		
		fin_type = $("option:selected", this).val();
		
		if( typeof fin_type == 'undefined' ) {
			fin_width.val("0.1");
			fin_width.removeAttr('readonly');
			fin_width_p.toggle(true);
		} else if ( fin_type === "0" ) {fin_width_p.toggle(true);fin_options_p.toggle(false);fin_width.removeAttr('readonly');} 
		else {
				fin_width.attr('readonly','readonly');
				fin_width_p.toggle(false);
				
				//hide 40 FPI (Copper) option if fin_type != 1 (straight fin Wolverine)
				if ( fin_type !== "1" ) {
					$("#fin_options option[value=3]").attr('disabled','disabled');
				} else {
				
					$("#fin_options option[value=3]").removeAttr('disabled');

				}
				fin_options_p.toggle(true);
				
				
		}
		
		$( "#geom" ).validate().resetForm();
		
		
	});
	<?php if($_SESSION['sim_data']['geom']['hasinput'] === true) { 
	?> $( "#geom" ).valid(); <?php } else { $_SESSION['sim_data']['geom']['hasinput'] = true; }?>
	
	
	
	
	
});







</script>

<form id="geom" action="#" enctype="application/x-www-form-urlencoded" class="sim-form">  
<div class="subcontent" id="geom">
    			<h3>GEOMETRY</h3>
    			<hr  class="breaklightblue" />
                <div class="leftcol">
                	
                		<h4>Cold plate</h4>
						<p><label for="heated_width" class="formLabel">Width [Xc] </label>
                       		<input type="text" id="heated_width" name="heated_width" size="5"/> (mm)
                             <label for="heated_width" class="error" generated="true"></label>
                    	</p>
                		<p><label for="heated_length" class="formLabel">Length [Yc] </label>
                       	   <input type="text" id="heated_length" name="heated_length" size="5"/> (mm)
                           <label for="heated_length" class="error" generated="true"></label>
                    	</p>
                        <p><label for="base_thickness" class="formLabel">Base Thickness [Zc]</label>
                	   	   <input type="text" name="base_thickness" size="5"/> (mm)
                           <label for="base_thickness" class="error" generated="true"></label>
          				</p>
                	
                	
                    <br />
                
                		<h4>MDT<sup>®</sup> Geometry</h4>
                         <p><label class="formLabel" style="vertical-align:top;">Type</label>
      						<select name="fin_type" id="fin_type" size="4" style="display:inline-block; height:auto; padding-top:5px; padding-bottom:5px; width:150px;">
                    			<option value="0" selected="selected">Straight Fin (User Defined)</option>
                    			<option value="1">Straight Fin (WLV)</option>
                                <option value="2">In-Line Pin Fin (WLV)</option>
                                <option value="3">Staggered Pin Fin (WLV)</option>
                			</select>
                             <label for="fin_type" class="error" generated="true"></label>
                        </p>
                        <p id="fin_options_p"><label class="formLabel" style="vertical-align:top;">Fin Options</label>
      						<select name="fin_options" id="fin_options" size="1" style="display:inline-block; height:auto; padding-top:5px; padding-bottom:5px; width:150px;">
                    			<option value="1" selected="selected">12 FPI (Copper)</option>
                    			<option value="2">25 FPI (Copper)</option>
                                <option value="3">40 FPI (Copper)</option>
                                <option value="4">12 FPI (Aluminium)</option>
                                <option value="5">25 FPI (Aluminium)</option>
                			</select>
                             <label for="fin_options_p" class="error" generated="true"></label>
                        </p>
                        
                        <p id="fin_width_p"><label class="formLabel">Fin Width</label>
      						<input type="text" id="fin_width" name="fin_width" size="5" value = "0.1"/> (mm)
                             <label for="fin_width" class="error" generated="true"></label>
                        </p>
                        <p><label class="formLabel">Fin Height</label>
      						<input type="text" name="fin_height" size="5"/> (mm)
                             <label for="fin_height" class="error" generated="true"></label>
                        </p>
                        <p><label class="formLabel">Tim Thickness*</label>
      						<input type="text" name="tim_thickness" size="5" value="0"/> (microns)
                            <label for="tim_thickness" class="error" generated="true"></label>
                        </p>
                        <p>
                           <input type="hidden" name="channel_roughness" size="5" value="0" />
                           <label for="channel_roughness" class="error" generated="true"></label>
                           <input type="hidden" name="channel_width" id="channel_width" size="5" value="0"/>
                           <label for="channel_width" class="error" generated="true"></label>
                           <input type="hidden" name="heated_thickness" size="5" value = "0"/>
                           <label for="heated_thickness" class="error" generated="true"></label>
                        </p>
                
                </div><!-- End .leftcol -->
                <div class = "rightcol">
                	<img alt="Cold Plate Geometry" src="assets/images/geometry.png" width="300" style="margin-top:0px;"/>
                    <p class="notes"><b>Special Notes:</b></p>
                    <ul class="notes">
                         <li><b>Cold Plate Length [Yc] must be <= 500 mm</b></li>
                    	 <li><b>Cold Plate Thickness [Zc] must be between 1-12 mm</b></li>
                         <li><b>Heat Source is uniformly distributed across top of cold plate surface</b></li>
                         <li><b>MDT Fin Height must be between 0.5 - 6.0 mm</b></li>
                         <li><b>MDT Fin Width must be between 0.1 - 1.0 mm</b></li>
                         <li><b>Fin width = Channel width</b></li>
                         <li><b>TIM thickness must be between 0 - 1500 microns.</b></li>
                         <li><b style="color:#C00;">*Zero TIM thickness => No TIM</b></li>
                    </ul>
                   	 <p style="float:right;">
                    	<input onclick="window.location.href='?page=instr';" type="button"  value="BACK" style="width: 
                        	120px; height: 70px; -webkit-appearance: none; background-color:#00457c; font-weight:bold; 
                            font-size:18px; color:#adafb2; margin-top:0px; margin-bottom:5px; margin-right:10px; display
                            : inline;" /> 
                    	<input onclick="window.location.href='?page=bdry';" type="button"  value="NEXT" style="width: 
                    		120px; height: 70px; -webkit-appearance: none; background-color:#00457c; font-weight:bold; 
                            font-size:18px; color:#adafb2; margin-top:0px; margin-bottom:5px; display:inline;" />
                    </p>    
                </div><!-- End .rightcol -->
            </div><!-- end .subcontent-->
</form>          