jQuery.noConflict();
jQuery(document).ready(function() {
  /*///////////////////////////////////////////////////////////////////////////////*/
  /*                                                     CONTACT FORM & VALIDATION */
  /*///////////////////////////////////////////////////////////////////////////////*/
  checkability();
  function checkability(){
    if(jQuery('#Text_Or_Image_To_Be_Printed_field').val() == ''){
      jQuery('.cart_btn').attr('id', 'disabledbutton').attr('disabled', true);    
    }
    else{
      jQuery('.cart_btn').removeAttr('id', 'disabledbutton').removeAttr('disabled');
    }
  };

  jQuery('#Text_Or_Image_To_Be_Printed_field').keyup(function(){
    checkability();
  })

  jQuery('.cart_btn').click(function() {
    // VARIABLES
    var formid = jQuery('.addtocart_form'),
        validated = true,
        counter = 0,
        error = jQuery('.validateresponse').fadeIn(500);

    // CHECK QUANTITIES
    var minorder = parseInt(jQuery('#minorder').text());
    var maxorder = parseInt(jQuery('#maxorder').text());
    if (jQuery('.inputboxquantity').val() >= minorder && jQuery('.inputboxquantity').val() <= maxorder) {
      // Do nothing
    }
    else {
      jQuery('.inputboxquantity').css({'border-style' : 'dashed'});
      validated = false;      
      jQuery(error).text('Please check your order quantity the minimum quantity is ' + minorder).append('. The maximum quantity is ' + maxorder); 
	  return false;
    }

    // TEXT OR IMAGE TO BE PRINTED VALIDATION
    jQuery('#Text_Or_Image_To_Be_Printed_field', formid).each(function(){
      if (jQuery(this).val().length == 0){
        jQuery(this).css({'border-color' : '#A31018'});
        jQuery(error).text('Please select some Text or an image to be printed');
	  return false;
      }
      else {        
        jQuery(this).css({'border-color' : ''})
      }
    });

    // CHOOSE YOUR CLIPART VALIDATION
    if (jQuery('input[name="Clipart"]').size() > 0 && !jQuery('input[name="Clipart"]').is(':checked')){
      jQuery('input[name="Clipart"]').addClass('borderalert');  
      validated = false;
      jQuery(error).text('Please select some clipart!');      
	  return false;
    }
    else {
      jQuery('input[name="Font_Style"]').removeClass('borderalert');      
    };  
    
    // PRINT COLOUR VALIDATION
    if (jQuery('input[name="Choose_Your_Print_Colour"]').size() > 0 && !jQuery('input[name="Choose_Your_Print_Colour"]').is(':checked')){
      jQuery('input[name="Choose_Your_Print_Colour"]').addClass('borderalert');  
      validated = false;
      jQuery(error).text('Please select a print colour!');  
	  return false;    
    }
    else {
      jQuery('input[name="Choose_Your_Print_Colour"]').removeClass('borderalert');      
    };

    // CHOOSE YOUR LEATHER COLOUR VALIDATION
    if (jQuery('input[name="Choose_Your_Leather_Colour"]').size() > 0 && !jQuery('input[name="Choose_Your_Leather_Colour"]').is(':checked')){
      jQuery('input[name="Choose_Your_Leather_Colour"]').addClass('borderalert');  
      validated = false;
      jQuery(error).text('Please select a leather colour!'); 
	  return false;
    }
    else {
      jQuery('input[name="Choose_Your_Leather_Colour"]').removeClass('borderalert');      
    };

    // CHOOSE YOUR COLOUR VALIDATION
    if (jQuery('input[name="Choose_Your_Colour"]').size() > 0 && !jQuery('input[name="Choose_Your_Colour"]').is(':checked')){
      jQuery('input[name="Choose_Your_Colour"]').addClass('borderalert');  
      validated = false;
      jQuery(error).text('Please select a colour!');      
	  return false;
    }
    else {
      jQuery('input[name="Choose_Your_Leather_Colour"]').removeClass('borderalert');      
    };

    // CHOOSE YOUR FONT STYLE VALIDATION
    if (jQuery('input[name="Font_Style"]').size() > 0 && !jQuery('input[name="Font_Style"]').is(':checked')){
      jQuery('input[name="Font_Style"]').addClass('borderalert');  
      validated = false;
      jQuery(error).text('Please select a font style!');
	  return false;   
    }
    else {
      jQuery('input[name="Font_Style"]').removeClass('borderalert');      
    };


    // SUCCESS FUNCTION
  });
});
