
$(document).ready(function()
{ 

var outofstock=false; 


if(jQuery.isFunction($(".enquiriesform").validate)){
// function exists, so we can now call it
$(".enquiriesform").validate({
    invalidHandler: function(form, validator) {
      var errors = validator.numberOfInvalids();
      if (errors) {
 /*       var message = errors == 1
          ? 'You missed 1 field. It has been highlighted'
          : 'You missed ' + errors + ' fields. They have been highlighted';
        $("div.error span").html(message); */

        $("div.error").show();
      } else {
        $("div.error").hide();
      }
    }
 });

}





/*
 $('#button1').click(function() {
	
      var submitFrom = true;
	  var form  = $('#enquiriesform1')


      $('.required').each( function () {
	
        //remove previosu star so taht dont append stars on second submit
            $('#enquiriesform1').parent().prev().html($('#enquiriesform1').parent().prev().html().replace(" * ",""));
       
        if($('#enquiriesform1').val()=="")
        {
        
         
          $(this).closest('td').prev().append(" * ");
          $(".error").show();
           submitFrom = false;
        }
       
       });
        return false;
    });   

*/


 if($('.color').length=='0')
 {
   //remove Color heading
   $('#colorhead').hide();

  $('.colorrow').each(function(index) {
	  $(this).hide();
  });
  
 }

$('.color').change(function(){

   $(this).parent().parent().children('.productCode').html($(this).val());
   var rownum = $(this).attr('rownum');
  	$('#row'+rownum).addClass($(this).val());


   if($('#'+$(this).val()).attr('special')=='special') {
		//chnage colour 
		$('#specialmsg').show();
		//$('#specialmsg').html("<span class='special' style='float:left;'> Green text denotes product is currently on special. </span>");
		$('#row'+rownum).addClass('special');
	} else {
		//$('#specialmsg').hide();
		$('#row'+rownum).removeClass('special');
	}

   if($('#'+$(this).val()).attr('outofstock')=='outofstock') {
	    //chnage colour 
		$('#outofstock_msg').show();
 		$('#row'+rownum).find('.product').hide();
		$('#row'+rownum).find('#outofstock').remove();
		$('#row'+rownum).find('.product').parent().append("<div id='outofstock' class='outofstock'> X </div>");

		//$('#'+$(this).val()).parent().addClass('outofstock');
		//$(this).append("<div id='select"+prodid+"'> X </div>");
	} else {
		//$('#specialmsg').hide();
		
		$('#row'+rownum).find('.product').show();
		$('#row'+rownum).find('#outofstock').remove();
	}

  //chage gst price
   $('#pricemgst_'+rownum).val($('#'+$(this).val()).attr('minugst'));
   //change minus gst price
   $('#pricegst_'+rownum).val($('#'+$(this).val()).attr('gst'));

   product_price = $('#'+$(this).val()).val() *1;
   $('#prodPrice_'+rownum).html('$'+(product_price.toFixed(2)));
   $('#price_'+rownum).val(product_price);

 });

$('input,textarea,select').blur();//stop all text fields focus
$('#company').focus();


$("#sub_menu_container ul li:last-child").addClass("last");

if(typeof $("#enquiriesform").validate == 'function') {
	$("#enquiriesform").validate();
}


$('.outofstock').each(function(index) {

   $(this).parent().parent().children('.productCode').html($(this).val());
   var rownum = $(this).attr('rownum');
  
  //   if($('#'+$(this).val()).attr('outofstock')=='outofstock')
   //{
	    //chnage colour 
		
		$('#outofstock_msg').show();
 		$(this).find('.product').hide();
		$(this).append("<div id='outofstock' class='outofstock'> X </div>");
		
		

		//$('#'+$(this).val()).parent().addClass('outofstock');
		//$(this).append("<div id='select"+prodid+"'> X </div>");

   //}
     outofstock=true; 
  });


$('.color').each(function(index) 
{
  //select price
  $(this).parent().parent().children('.productCode').html($(this).val());
  var rownum = $(this).attr('rownum');



	
	if($('#'+$(this).val()).attr('special')=='special') {
		$('#row'+rownum).addClass('special');
	}

	if($('#'+$(this).val()).attr('outofstock')=='outofstock') {
	    //chnage colour 
		
		$('#outofstock_msg').show();
 		$('#row'+rownum).find('.product').hide();
		if(!$('#row'+rownum).find('.product').parent().find('#outofstock'))
		$('#row'+rownum).find('.product').parent().append("<div id='outofstock' class='outofstock'> X </div>");
		 outofstock=true; 

	} else {
		$('#row'+rownum).find('#outofstock').remove();
		$('#row'+rownum).find('.product').show();
	}
   
  product_price = $('#'+$(this).val()).val() * 1;


  $('#prodPrice_'+rownum).html('$'+(product_price.toFixed(2)));
  $('#price_'+rownum).val(product_price);
   
  
});

$('.color').trigger('change');


//lopp through the class


 
 /* 
$(':button').addClass('ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only');
$(':submit').addClass('ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only');
$(':reset').addClass('ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only');
  $(':button').hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});
 $(':submit').hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});
  $(':reset').hover(function(){$(this).addClass('ui-state-hover');},function(){$(this).removeClass('ui-state-hover');});
*/

        $('#search').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/searchgo-ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/searchgo.png'});             }
        );
        $('#enqiries').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/enqiries-ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/enqiries.png'});             }
        );   
        
          $('#submit-ro').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/submit-ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/submit.png'});             }
        ); 
        
                  $('.continueshopping-ro').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/continueshopping-ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/continueshopping.png'});             }
        );   
        
                          $('.updateorder-ro').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/updateorder-ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/updateorder.png'});             }
        );  
        
                  $('.next-ro').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/next-ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/next.png'});             }
        );                           

                  $('.remove-ro').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/remove-ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/remove.png'});             }
        );  
        
                          $('.gallery-ro').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/gallery-button-ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/gallery-button.png'});             }
        );
        
                                  $('.artwork-ro').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/artwork-button-ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/artwork-button.png'});             }
        );
        
                                          $('.start-ro').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/start_shopping_ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/start_shopping.png'});             }
        );
        
                                          $('.bag-ro').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/addtobag-ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/addtobag.png'});             }
        );
        
         $('.submit-ro').hover(
            function(){ // Change the input image's source when we "roll on"
                $(this).attr({ src : 'assets/templates/paperpak/images/submit-ro.png'});
            },
            function(){ // Change the input image's source back to the default on "roll off"
                $(this).attr({ src : 'assets/templates/paperpak/images/submit.png'});             }
        );        
        

if(outofstock)
{
//show out of stock message
//$('#outofstock_msg').show();
	$('.color').trigger('change');
}

});

