// JavaScript Document
function validations(oform)
{
		var msg="";
		var msg1="Please enter the following mandatory fields:\n";

		if(oform.b_name.value=="")
		{
			msg += "Name\n";
		}
		else if(trim(oform.b_name.value))
		{
			msg += "Correct name\n";
		}
		if(oform.b_company.value=="")
		{
			msg += "Company\n";
		}
		else if(trim(oform.b_company.value))
		{
			msg += "Correct company\n";
		}
		if(oform.b_telephone.value=="")
		{
			msg += "Telephone\n";
		}
		else if(trim(oform.b_telephone.value))
		{
			msg += "Correct telephone\n";
		}
		if(oform.b_email.value=="")
		{
			msg += "Email\n";
		}	
		else if(!validateEmails(oform.b_email.value))
		{
		msg += "Correct email\n";
		}
		
		if(msg != "")
		{
			msg1 +=msg;
			alert(msg1);
			return false;
		}
		else
		{
			return true;
		}

}

function wine_form_validations(oform)
{
		var msg="";
		var msg1="Please enter the following mandatory fields:\n";

		if(oform.wine_title.value=="")
		{
			msg += "Title\n";
		}
	  	else if(trim(oform.wine_title.value))
		{
			msg += "Correct Title\n";
		}
		if(oform.wine_fullname.value=="")
		{
			msg += "Full name\n";
		}
		
		else if(trim(oform.wine_fullname.value))
		{
			msg += "Correct Full name\n";
		}
		if(oform.wine_company.value=="")
		{
			msg += "Company\n";
		}
		
		else if(trim(oform.wine_company.value))
		{
			msg += "Correct Company\n";
		}
		if(oform.wine_address.value=="")
		{
			msg += "Address\n";
		}
		
		if(oform.wine_radio[0].checked==false && oform.wine_radio[1].checked==false)
		{
		   msg += "1. Are you responsible for ordering cleaning services in your company? \n";
		}
		if(oform.wine_cleaners[0].checked==false && oform.wine_cleaners[1].checked==false)
		{
		   msg += "2. Do you use private cleaners for your office cleaning? \n";
		}
		if(oform.wine_services[0].checked==false && oform.wine_services[1].checked==false)
		{
		   msg += "3. Do you use services of a commercial cleaning company? \n";
		}
		if(oform.b_cleaners.value=="")
		{
		   msg += "4. How many cleaners do clean your office premises? \n";
		}
		else if(isNaN(oform.b_cleaners.value))
		{
			
		   msg += "4. How many cleaners do clean your office premises?(Please Enter Number only) \n";
		}
		if(oform.b_day.value=="")
		{
		   msg += "5. How many days per week? \n";
		}
		else if(isNaN(oform.b_day.value))
		{
		   msg += "5. How many days per week?(Please Enter Number only) \n";
		}
		if(oform.b_time.value=="")
		{
		   msg += "6. How many hours per time? \n";
		}
		if(oform.b_happy.value=="")
		{
		   msg += "7. Are you happy with they service? \n";
		}
		else if(isNaN(oform.b_happy.value))
		{
		   msg += "7. Are you happy with they service?(Please Enter Number only) \n";
		}
		else if(oform.b_happy.value > 10)
		{
			  msg += "7. Are you happy with they service? (0 – poor service to 10 – excellent) \n";
		}
		if(oform.b_janitorial[0].checked==false && oform.b_janitorial[1].checked==false)
		{
		   msg += "8. Does your company order janitorial supplies? \n";
		}
		if(oform.b_supplies[0].checked==false && oform.b_supplies[1].checked==false)
		{
		   msg += "9. Are you responsible for purchasing janitorial supplies? \n";
		}
		if(oform.b_freeest[0].checked==false && oform.b_freeest[1].checked==false)
		{
		   msg += "10. Would you like us to give you a free estimate no ties attached? \n";
		}
		if(oform.b_corder[0].checked==false && oform.b_corder[1].checked==false)
		{
		   msg += "11. Does your company order janitorial supplies? \n";
		}
		if(oform.b_offices[0].checked==false && oform.b_offices[1].checked==false)
		{
		   msg += "12. Do you have more offices in Greater London? \n";
		}
		if(oform.b_residential[0].checked==false && oform.b_residential[1].checked==false)
		{
		   msg += "13. Would you like to get a free estimate for your residential house cleaning?\n";
		}
		
		if(oform.b_residential[0].checked==true)
		{
			    if(oform.wine_resaddress.value=="")
				{
					msg += "Residential address\n";
				}
				
				else if(trim(oform.wine_resaddress.value))
				{
					msg += "Correct residential address\n";
				}
			    if(oform.wine_phone.value=="")
				{
					msg += "Phone number\n";
				}
				
				else if(trim(oform.wine_phone.value))
				{
					msg += "Correct phone number\n";
				}
			   if(oform.wine_email.value=="")
				{
					msg += "Email\n";
				}	
				else if(!validateEmails(oform.wine_email.value))
				{
				msg += "Correct email\n";
				}
				if(oform.wine_typeofwork.value=="")
				{
					msg += "Type of work\n";
				}	
				else if(trim(oform.wine_typeofwork.value))
				{
				msg += "Correct Type of work\n";
				}
				if(oform.wine_contact.value=="")
				{
					msg += "When can we contact you?\n";
				}	
				else if(trim(oform.wine_contact.value))
				{
				msg += "Correct When can we contact you?\n";
				}
						
		}
								
		if(msg != "")
		{
			msg1 +=msg;
			alert(msg1);
			return false;
		}
		else
		{
			return true;
		}

}


function check_validations(oform)
{
	var msg="";
	var msg1="Please enter the following mandatory fields:\n";

	if(oform.quote_name.value=="")
	{
		msg += "Name\n";
	}
	else if(trim(oform.quote_name.value))
	{
		msg += "Correct name\n";
	}
	if(oform.quote_company.value=="")
	{
		msg += "Company\n";
	}
	else if(trim(oform.quote_company.value))
	{
		msg += "Correct company\n";
	}
	if(oform.quote_address.value=="")
	{
		msg += "Address\n";
	}
	else if(trim(oform.quote_address.value))
	{
		msg += "Correct address\n";
	}
	if(oform.quote_telephone.value=="")
	{
		msg += "Telephone\n";
	}
	else if(trim(oform.quote_telephone.value))
	{
		msg += "Correct telephone\n";
	}
	if(!validateEmails(oform.quote_email.value))
	{
		msg += "Valid email\n";
	}
	
	if(oform.quote_required_services.value=="")
	{
		msg += "Required services\n";
	}
	else if(trim(oform.quote_required_services.value))
	{
		msg += "Correct required services\n";
	}
	
	if(oform.quote_contact_mode.value=="")
	{
		msg += "When we can contact you?\n";
	}
	else if(trim(oform.quote_contact_mode.value))
	{
		msg += "Correct 'When we can contact you?'\n";
	}
	
	if(msg != "")
	{
		msg1 +=msg;
		alert(msg1);
		return false;
	}
	else
	{
		return true;
	}
}


function contact_form_validations(oform)
{
		var msg="";
		var msg1="Please enter the following mandatory fields:\n";

		if(oform.contact_name.value=="")
		{
			msg += "Name\n";
		}
		else if(trim(oform.contact_name.value))
		{
			msg += "Correct name\n";
		}
		if(oform.contact_company.value=="")
		{
			msg += "Company\n";
		}
		else if(trim(oform.contact_company.value))
		{
			msg += "Correct Company\n";
		}
		if(oform.contact_telephone.value=="")
		{
			msg += "Telephone\n";
		}
		else if(trim(oform.contact_telephone.value))
		{
			msg += "Correct Telephone\n";
		}
		if(!validateEmails(oform.contact_email.value))
		{
			msg += "Correct email\n";
		}
		
		if(msg != "")
		{
			msg1 +=msg;
			alert(msg1);
			return false;
		}
		else
		{
			return true;
		}
	
}

function quotation_form(oform)
{
		var msg="";
		var msg1="Please enter the following mandatory fields:\n";

		if(oform.quotation_name.value=="")
		{
			msg += "Name\n";
		}
		else if(trim(oform.quotation_name.value))
		{
			msg += "Correct name\n";
		}
		if(oform.quotation_company_name.value=="")
		{
			msg += "Company\n";
		}
		else if(trim(oform.quotation_company_name.value))
		{
			msg += "Correct company\n";
		}
		if(oform.quotation_address.value=="")
		{
			msg += "Address\n";
		}
		else if(trim(oform.quotation_address.value))
		{
			msg += "Correct address\n";
		}
		if(oform.quotation_phone_no.value=="")
		{
			msg += "Phone no.\n";
		}
		else if(trim(oform.quotation_phone_no.value))
		{
			msg += "Correct phone no.\n";
		}
		if(!validateEmails(oform.quotation_email.value))
		{
			msg += "Valid email\n";
		}
		
		if(oform.quotation_type_work.value=="")
		{
			msg += "Type of work\n";
		}
		else if(trim(oform.quotation_type_work.value))
		{
			msg += "Correct type of work\n";
		}
		
		if(oform.quotation_contact.value=="")
		{
			msg += "When can we contact you?\n";
		}
		else if(trim(oform.quotation_contact.value))
		{
			msg += "Correct when can we contact you?\n";
		}
		
		
		if(oform.quotation_find.value=="")
		{
			msg += "How did you find out about us?\n";
		}
		else if(trim(oform.quotation_find.value))
		{
			msg += "Correct how did you find out about us?.\n";
		}
		
		
		if(oform.quotation_comments.value=="")
		{
			msg += "Additional Comments.\n";
		}
		else if(trim(oform.quotation_comments.value))
		{
			msg += "Correct additional comments.\n";
		}
		
		
		if(msg != "")
		{
			msg1 +=msg;
			alert(msg1);
			return false;
		}
		else
		{
			return true;
		}
	
}

function trim(par)
{
	var y = par.length;
	var ret = '';
	var ex=0;
	var bl=0;
	for (i=0;i<y;i++)
	{
		if (par.charAt(i) == ' ')
			bl = bl+1
		else
		{
			ret=ret+par.charAt(i);
			ex = ex+1
		}
	}
	if (bl==y)
		return true;
	else 
		return false;
	
}
function validateEmails(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}
