// This script file is used to validate registration form
jQuery.noConflict();

jQuery(document).ready(function(){
	
	jQuery('#enqform').submit(function(e) {

		enquiry();
		e.preventDefault();
		
	});
	
});

jQuery(document).ready(function(){
	
	jQuery('#contactform').submit(function(e) {

		contact();
		e.preventDefault();
		
	});
	
});


jQuery(document).ready(function(){
	
	jQuery('#quoteform').submit(function(e) {

		quote();
		e.preventDefault();
		
	});
	
});

function enquiry()
{
	hideshow1('loading',1);
	error(0);
	jQuery.ajax({
		type: "POST",
		url: "actSendEnquiry.php",
		data: jQuery('#enqform').serialize(),
		dataType: "json",
		success: function(msg){
			
			if(parseInt(msg.status)==1)
			{
				successmail(1,msg.txt);
			}
			else if(parseInt(msg.status)==0)
			{
				if(msg.txt == "Error! Sending email! Try again."){
					
					error(1,msg.txt);
					document.getElementById('refresh1').click();
					
				}else {
				
				error(1,msg.txt);
				
				}
			}
			
			hideshow1('loading',0);
		}
	});

}

function contact()
{
	hideshow1('loading',1);
	error(0);
	jQuery.ajax({
		type: "POST",
		url: "actContact.php",
		data: jQuery('#contactform').serialize(),
		dataType: "json",
		success: function(msg){
			
			if(parseInt(msg.status)==1)
			{
				successmail(1,msg.txt);
			}
			else if(parseInt(msg.status)==0)
			{
				if(msg.txt == "Error! Sending email! Try again."){
					
					error(1,msg.txt);
					document.getElementById('refresh1').click();
					
				}else {
				
				error(1,msg.txt);
				
				}
			}
			
			hideshow1('loading',0);
		}
	});

}


function quote()
{
	hideshow1('loadingquote',1);
	errorquote(0);
	jQuery.ajax({
		type: "POST",
		url: "actQuote.php",
		data: jQuery('#quoteform').serialize(),
		dataType: "json",
		success: function(msg){
			
			if(parseInt(msg.status)==1)
			{
				successmailquote(1,msg.txt);
			}
			else if(parseInt(msg.status)==0)
			{
				if(msg.txt == "Error! Sending email! Try again."){
					
					errorquote(1,msg.txt);
					document.getElementById('refresh').click();
					
				}else {
				
				errorquote(1,msg.txt);
				
				}
			}
			
			hideshow1('loadingquote',0);
		}
	});

}



function hideshow1(el,act)
{
	if(act) jQuery('#'+el).css('visibility','visible');
	else jQuery('#'+el).css('visibility','hidden');
}

function hideshow(el,act)
{
	if(act) jQuery('#'+el).css('display','block');
	else jQuery('#'+el).css('display','none');
}

function error(act,txt)
{
	hideshow('error',act);
	if(txt) jQuery('#error').html(txt);
}

function successmail(act,txt)
{
	hideshow('error',0);
	hideshow('successmail',act);
	if(txt) jQuery('#successmail').html(txt);
}

function errorquote(act,txt)
{
	hideshow('errorquote',act);
	if(txt) jQuery('#errorquote').html(txt);
}

function successmailquote(act,txt)
{
	hideshow('errorquote',0);
	hideshow('successmailquote',act);
	if(txt) jQuery('#successmailquote').html(txt);
}
