
$(document).ready(function(){
						   
	var FormObj=$("#membersearchform");
	// Place ID's of all required fields here.
	var required = [ "shape", "heat",'group','finish','shape','code'];
	var labels = [ "shapelabel", "heatlabel",'grouplabel','finishlabel','shapelabel','codelabel'];
	
	var errornotice = FormObj.find("#cformerror");
	// The text to show up within a field when it is incorrect
	var emptyerror = "";
	var emailerror = "";

	$('#searchresults_submit').click(function(event){
		//Validate required fields
                bAllfull = false;
		for (i=0;i<required.length;i++) {
			var input = FormObj.find('#'+required[i]);
			var label = FormObj.find('#'+labels[i]); 
			if ((input.val() == "") || (input.val() == emptyerror)) {
				input.addClass("needsfilled");
				label.addClass("labelalert");
				input.val(emptyerror);
			} else {
				input.removeClass("needsfilled");
				label.removeClass("labelalert");

                                bAllfull = true;
			}
		}
                if (bAllfull)
                {
                    $("#membersearchform label").removeClass("labelalert");
                    $("#membersearchform input").removeClass("needsfilled");
                    FormObj.find(":input").removeClass("needsfilled");
                }
		//if any inputs on the page have the class 'needsfilled' the form will not submit
		if (FormObj.find(":input").hasClass("needsfilled")) {
                        errornotice.fadeIn(750);
			event.preventDefault();
                        return false;
		} else {
			errornotice.hide();
                        $("#search_loadingpanel").show();

                      //submit
                     //group
                     //code
                     //heat
                     //'record='+ FormObj.find('#record').val() + '&
                      var dataString = 'group=' + FormObj.find('#group').val() +  "&finish=" + FormObj.find('#finish').val() + '&code=' + FormObj.find('#code').val()
                                            + '&heat=' + FormObj.find('#heat').val()+ '&shape=' + FormObj.find('#shape').val() ;
                      //var dataString = 'heat=' + FormObj.find('#heat').val()  + '&shape=' + FormObj.find('#shape').val() ;
                      
                      //alert (dataString);return false; http://111.118.160.187/~inter
                      $.ajax({
                        type: "POST",
                        url: "http://www.interlloy.com.au/z-search-page/",
                        data: dataString,
                        success: function(html) {
                            $("#search_loadingpanel").hide();
                            $("#search_results").show();
                          //alert(html);
                          $('#search_results').html( html );
                          /*$('#message').html("<h2>Contact Form Submitted!</h2>")
                          .append("<p>We will be in touch soon.</p>")
                          .hide()
                          .fadeIn(1500, function() {
                            $('#message').append("<img id='checkmark' src='images/check.png' />");
                          });*/
                             if(!$.fontAvailable('LeagueGothicRegular') || $.browser.msie ) {
                                Cufon.replace('h1');
                                Cufon.replace('.email a');
                                Cufon.replace('.email div');
                            }
                        }
                      });
			event.preventDefault();
                        return false;
		}
	});
	
	// Clears any fields in the form when the user clicks on them
	FormObj.find(":input").focus(function(){		
	   if ($(this).hasClass("needsfilled") ) {
			$(this).val("");
			$(this).removeClass("needsfilled");
	   }
	});

        /*$(".rs_email_result").live('click', function(){
            //alert('asdf');
            //alert (dataString);return false; http://111.118.160.187/~inter
              var dataString = 'record='+ $(this).attr('id');
              $.ajax({
                type: "POST",
                url: "http://www.interlloy.com.au/mail-out/",
                data: dataString,
                success: function(html) {
                alert('The certificate has been sent to your nominated email address.');
                }
              });
              return false;
        }
        );*/


});	
