//validation for contact us page
   function validate(){
        
        var name = $("#name").val();
        var company = $("#company").val();
        var address = $(".address").val();
        var country = $("#country").val();
        var phone = $("#phone").val();
        var ext = $("#ext").val();
        var mobile = $("#mobile").val();
        var email = $("#email").val();
        var subject = $("#subject").val();
        var message = $(".message").val();
          
        if(name =="" || name == null){
            $("#errorMsg").html("Please Enter your Name..");
            $("#errorMsg").show();
            return false;
        }
        if(company =="" || company == null){
            $("#errorMsg").html("Please Enter Company Name..");
            $("#errorMsg").show();
            return false;
        }
        if(country =="" || country == null){
            $("#errorMsg").html("Please Slect Country..");
            $("#errorMsg").show();
            return false;
        }
        if(phone =="" || phone == null){
            $("#errorMsg").html("Please Enter Phone Number..");
            $("#errorMsg").show();
            return false;
        }else if(phneValid(phone) == false){
             $("#errorMsg").html("Enter Only Numbers..");
             $("#errorMsg").show();
             $("#phone").focus();
             $("#phone").val("");
              return false;
        }
        if(ext !=""){
         if(phneValid(ext) == false){
             $("#errorMsg").html("Enter Only Numbers..");
             $("#errorMsg").show();
             $("#ext").val("");
             $("#ext").focus();
             return false;
         }
        } 
        if(mobile !=""){
            if(phneValid(mobile) == false){
             $("#errorMsg").html("Enter Only Numbers..");
             $("#errorMsg").show();
             $("#mobile").focus();
             $("#mobile").val("");
              return false;
          }
        }
        if(email =="" || email == null){
            $("#errorMsg").html("Please Enter Email ID..");
            $("#errorMsg").show();
            return false;
        }else{
        if (echeck(email)==false){
             $("#errorMsg").html("Enter a valid E-Mail ID..");
             $("#errorMsg").show();
             $("#email").focus();
             $("#email").val("");
                    
    		return false
    	} }
        if(subject =="" || subject == null){
            $("#errorMsg").html("Please Enter Subject..");
            $("#errorMsg").show();
            return false;
        }
        if(message =="" || message == null){
            $("#errorMsg").html("Please Enter your Message..");
            $("#errorMsg").show();
           
            return false;
        }
        document.getElementById('button').readonly= true;
        document.getElementById('button').value="Sending Mail";
        
   }    

   //function for validating email field
   function echeck(email){  
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
    return emailPattern.test(email);  
}  
   function phneValid(str) {
      return /^ *[0-9]+ *$/.test(str);
      }
   //function for clearing the error message
   function clearErrMsg(){
    var fldId = "#errorMsg";
    $(fldId).empty();
    
   }
 
   
   //function for validating the quote request
   function validateQuote(){
    
    var email = $("#email").val();
    var fname = $("#fname").val();
    var phone = $("#phone").val();
    var addr = $("#addr1").val();
    var city = $("#city").val();
    var pin = $("#postcode").val();
    var country = $("#country").val();
    var comment = $("#comment").val();
    
     if(email =="" || email == null){
            $("#errorMsg").html("The Email field cannot be empty");
            $("#errorMsg").show();
            return false;
        }else{
        if (echeck(email)==false){
             $("#errorMsg").html("Enter a valid e-mail ID");
             $("#errorMsg").show();
             $("#email").focus();
             $("#email").val("");
                    
    		return false
    	} }
        if(fname =="" || fname == null){
            $("#errorMsg").html("The first name field cannot be empty");
            $("#errorMsg").show();
            return false;
        }
        if(phone =="" || phone == null){
            $("#errorMsg").html("The phone field cannot be empty");
            $("#errorMsg").show();
            return false;
        }else if(phneValid(phone) == false){
             $("#errorMsg").html("Enter a valid phone number");
             $("#errorMsg").show();
             $("#phone").focus();
             $("#phone").val("");
              return false;
            }
                
        if(addr =="" || addr == null){
            $("#errorMsg").html("The address field cannot be empty");
            $("#errorMsg").show();
            return false;
        }
        if(city =="" || city == null){
            $("#errorMsg").html("The city field cannot be empty");
            $("#errorMsg").show();
            return false;
        }
        if(pin =="" || pin == null){
            $("#errorMsg").html("The postcode field cannot be empty");
            $("#errorMsg").show();
            return false;
        }else if(phneValid(pin) == false){
             $("#errorMsg").html("Enter a valid phone number");
             $("#errorMsg").show();
             $("#pin").focus();
             $("#pin").val("");
              return false;
            }
        if(country =="" || country == null){
            $("#errorMsg").html("The country field cannot be empty");
            $("#errorMsg").show();
            return false;
        }
         if(comment =="" || comment == null){
            $("#errorMsg").html("The comment field cannot be empty");
            $("#errorMsg").show();
            return false;
        }
 }
 
 //validation for request call page
 function validateCall(){
    var name = $("#name").val();
    var phone = $("#phone").val();
    var company = $("#company").val();
    if(name == null || name == ""){
        $("#error").html("Please enter a name");
        $("#error").show();
        return false;
    }
     if(phone == null || phone == ""){
        $("#error").html("Please enter a phone number");
        $("#error").show();
        return false;
    }
    else if(phneValid(phone) == false){
             $("#error").html("Enter a valid phone number");
             $("#error").show();
             $("#phone").focus();
             $("#phone").val("");
              return false;
            }
    if(company == null || company == ""){
        $("#error").html("Please enter a company name");
        $("#error").show();
        return false;
    }
 }
 
 //to send a query from the index page using jquery ajax
 function sendQuery(){
        var name = $("#name").val();
        var company = $("#company").val();
        var mobile = $("#mobile").val();
        var email = $("#email").val();
        var comment = $("#comment").val();
        if(name == "" || name == null){
             $("#mail").show();
             $("#errorMsg").show();
             $("#errorMsg").html("Please enter your name");
             return false;
        }
        if(company == "" || company == null){
             $("#mail").show();
             $("#errorMsg").show();
             $("#errorMsg").html("Please enter company name");
             return false;
        }
        if(mobile == "" || mobile == null){
             $("#mail").show();
             $("#errorMsg").show();
             $("#errorMsg").html("Please enter mobile number");
             return false;
        }else if(phneValid(mobile) == false){
             $("#errorMsg").html("Enter a valid mobile number");
             $("#errorMsg").show();
             $("#mobile").focus();
             $("#mobile").val("");
              return false;
            }
        if(email == "" || email == null){
             $("#mail").show();
             $("#errorMsg").show();
             $("#errorMsg").html("Please enter email address");
             return false;
        }else if (echeck(email)==false){
             $("#errorMsg").html("Enter a valid e-mail ID");
             $("#errorMsg").show();
             $("#email").focus();
             $("#email").val("");
                    
    		return false
    	} 
        if(comment == "" || comment == null){
             $("#mail").show();
             $("#errorMsg").show();
             $("#errorMsg").html("Please enter your comments");
             return false;
        }
        
        $.ajax({
		type:"POST",	   
        url:"sendQuery.php",
        data:"name="+name+"&company="+company+"&mobile="+mobile+"&email="+email+"&comment="+comment,
		success:function(html){
		    if(html == 1){
		      $("#errorMsg").show();
              $("#errorMsg").html("Enquiery Successfully Sent");
		    }
            else  if(html == 0){
		      $("#errorMsg").show();
              $("#errorMsg").html("Enquiery failed");
		    }
		}			 
			 });
  
 } 
 function category(category,id){
        $('#result').empty();
        var loader = "<div id='loader' style='text-align: center; margin-top: 10px; '><img src='images/pleasewait.gif' alt='please wait...' /></div>";
        $('#products_left_div2').html(loader);        
        var titleDiv = "products_left2";
          $('#products_left_div2').show(); 
                $.ajax({
        		type:"POST",	   
                url:"categoryQuery.php",
                data:"category="+category+"&mid="+id,
        		success:function(html){
                $('#products_left2').html(category);
                var val = "<div id='catRes' style='color: #000;float: left;font-family: Verdana,Arial,Helvetica,sans-serif;font-size: 16px; height: auto; margin: 0 0 10px; padding: 7px 0 0 20px; width: 100%;'>"+html+"</div>"
                $('#products_left_div2').html(val); 
                $("#prodLink").empty(); 
          }
					 
    });    
 } 
 
 function subcategory(category,mid,table,cTblName){
    var loader = "<div id='loader' style='text-align: center; margin-top: 10px; '><img src='images/pleasewait.gif' alt='please wait...' /></div>";
    $('#products_left_div2').html(loader);
     $.ajax({
		type:"POST",	   
        url:"subcategory.php",
        data:"category="+category+"&mid="+mid+"&table="+table+"&cTblName="+cTblName,
		success:function(html){
        $('#products_left_div2').empty();
         $('#result').html(html);
         var appendField ="<div id=\""+table+"\" class = \"newDiv\"><img src=\"images/small_arrow.png\"/>&nbsp;<a href= \"javascript: void(0);\" style=\"color:#FFFFFF;\" onclick = \"subcategoryLink('"+category+"',"+mid+",'"+table+"');\">"+category+"</a></div>";
         if($("#prodLink").html() == "" || $("#prodLink").html()== null){
         //alert("from navigation sub");   
			$("#prodLink").append(appendField);
			
           }
       else{
            if($('#'+table).html() == "" || $('#'+table).html() == null){
			//alert("from navigation sub2");
			$("#prodLink").append(appendField);
            }
			else{
			//alert("from navigation sub3");
			$("#prodLink").empty();
			
			$("#prodLink").append(appendField);
			}
                        
          }
       }
					 
	 });  
 }
 
 //function for making the sabcategories as a chain of links
 function subcategoryLink(category,mid,table){
    var loader = "<div id='loader' style='text-align: center; margin-top: 10px; '><img src='images/pleasewait.gif' alt='please wait...' /></div>";
    $('#products_left_div2').html(loader);
     $.ajax({
		type:"POST",	   
        url:"subcategory.php",
        data:"category="+category+"&mid="+mid+"&table="+table,
		success:function(html){
        $('#products_left_div2').empty();
         $('#result').html(html);
          var appendField ="<div id=\""+table+"\" class = \"newDiv\"><img src=\"images/small_arrow.png\"/>&nbsp;<a href= \"javascript: void(0);\" style=\"color:#FFFFFF;\" onclick = \"subcategoryLink('"+category+"',"+mid+",'"+table+"');\">"+category+"</a></div>";
         if($("#prodLink").html() == "" || $("#prodLink").html() == null){
            alert("from navigation1");
			$("#prodLink").append(appendField);
           }
       else{
            if($('#'+table).html() == "" || $('#'+table).html() == null){
            //$("#prodLink").val('');
			alert("from navigation2");
			$("#prodLink").append(appendField);
            }
                        
          }
          }
					 
			 });  
 } 
 function fieldValue(c){
        $.ajax({
		type:"POST",	   
        url:"fieldValue.php",
        data:"cName="+c,
		success:function(html){
        $('#products_left2').html(c);
        
        $('#products_left_div2').hide(); 
         $('#result').html(html); 
            }
					 
			 });    
    
 }
 //to toggle the divs in the product sub category page
$(document).ready(function(){//
  $("#specification").click(function(){
      $("#product_sub_contents").show();           
      $("#product_sub_contents2").hide();
      $("#product_sub_contents3").hide(); 
      $("#product_sub_jquery").hide();      
  
  });
  $("#gallery").click(function(){
      $("#product_sub_contents2").show();
      $("#product_sub_jquery").show(); 
      $("#product_sub_contents").hide();
      $("#product_sub_contents3").hide();      
  
  });
  $("#ebrouchure").click(function(){
      $("#product_sub_contents3").show();
      $("#product_sub_contents").hide();
      $("#product_sub_contents2").hide(); 
      $("#product_sub_jquery").hide();      
  
  });
 
});
//to select the machine range with respect to the roduct selected in the request a brochure page
function selRange(){
    var selected = $("#selProd").val();
    if(selected != ""){
        $.ajax({
            type : "POST",
            url  : "selectRange.php",
            data : "id="+selected,
            success :function(result){
                $("#selOpt").html(result);
            }
        })
    }
    else
    {   var result = "<select class='style333' name = 'range'><option value=''>SELECT</option></select>";
        $("#selOpt").html(result);
    }
}

