//init fancy box for contact page
$(document).ready(function() {
	//Activate FancyBox
	$("p#maplink a").fancybox({
		'hideOnContentClick': true
	});
	
});
		


function check_contact_form(theForm){


if (theForm.firstname.value == '') {
    alert("Please enter your first name.");
    theForm.firstname.focus();
    return false;
}

if (theForm.surname.value == '') {
    alert("Please enter your surname.");
    theForm.surname.focus();
    return false;
}

if (theForm.email.value == '') {
    alert("Please enter your e-mail address.");
    theForm.email.focus();
    return false;
}
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (filter.test(theForm.email.value) != true){
    theForm.email.focus();
    alert("Your e-mail address is not valid! Please try again.");
    return false;
}
       
if (theForm.telephone.value == '') {
    alert("Please enter your telephone number.");
    theForm.telephone.focus();
    return false;
}

if(theForm.message.value==""){
	alert("You have not entered a message.");
	theForm.message.focus();
	return false;
}

var message="<b>Website Enquiry</b> \n\n";
message+="<b>Lead generated:</b> The Serious Business Group (http://seriousgroup.co.uk) \n\n";
message+="<b>Name:</b> "+theForm.firstname.value+" "+theForm.surname.value+"\n";
message+="<b>Email:</b> "+theForm.email.value+"\n";
message+="<b>Telephone:</b> "+theForm.telephone.value+"\n";
message+="<b>Message:</b> "+theForm.message.value+"\n\n\n";

var email=theForm.email.value;
var name=theForm.firstname.value+" "+theForm.surname.value;
var subject=theForm.subject.value;
var type=theForm.type.value;

x=document.location.href;

//hardcode if a dowloaded version
if (x.substring(0,8)=="file:///") {
domain="http://sm.kelstongroup.com";
}else{


if (x.substring(0,7)=="http://") {
x=x.substring(7,x.length);
}
y=x.split("/");
var domain= "http://"+y[0];
}

//jquery ajax

$.ajax({
  type: "POST",
  url: domain+'/wp-content/themes/seriousgroup/js/ajax.php', // this is the real one.
  //url: domain+'/seriousgroup-wp/wp-content/themes/seriousgroup/js/ajax.php', // for localhost testing ONLY
  data:  { trigger: "contactrequest",message: message,name: name,email: email,subject: subject,type: type },
  success: function(msg){
     alert( msg );
   }
 });

theForm.firstname.value="";
theForm.surname.value="";
theForm.telephone.value="";
theForm.email.value="";
theForm.message.value="";

return false;

}

function check_subscribe_form(theForm){

if(theForm.subscribe_name.value=="" || theForm.subscribe_name.value=="Name"){
alert("Please enter your name.");
theForm.subscribe_name.focus();
return false;
}

var x = theForm.subscribe_email.value;
var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (filter.test(x) !=true){
alert("Please enter a valid email address.");
theForm.subscribe_email.focus();
return false;
}
var message="<b>Newsletter request</b> \n\n";
message+="<b>Lead generated:</b> The Serious Business Group (http://seriousgroup.co.uk) \n\n";
message+="<b>Name:</b> "+theForm.subscribe_name.value+"\n";
message+="<b>Email:</b> "+theForm.subscribe_email.value+"\n\n\n";

var email=theForm.subscribe_email.value;
var name=theForm.subscribe_name.value;
var subject=theForm.subject.value;
var type=theForm.type.value;

x=document.location.href;

//hardcode if a dowloaded version
if (x.substring(0,8)=="file:///") {
domain="http://seriousgroup.co.uk";
}else{
if (x.substring(0,7)=="http://") {
x=x.substring(7,x.length);
}
y=x.split("/");
var domain= "http://"+y[0];
}

//jquery ajax

$.ajax({
  type: "POST",
  url: domain+'/wp-content/themes/seriousgroup/js/ajax.php', // this is the real one.
  //url: domain+'/seriousgroup-wp/wp-content/themes/seriousgroup/js/ajax.php', // for localhost testing ONLY
  data:  { trigger: "contactrequest",message: message,name: name,email: email,subject: subject,type:type },
  success: function(msg){
     alert( msg );
   }
 });

theForm.subscribe_name.value="";
theForm.subscribe_email.value="";

return false;

}

function clearText(thefield){
if (thefield.defaultValue==thefield.value) {
thefield.value = "";
}
}

function replaceText(thefield){
if (thefield.value=="") {
thefield.value = thefield.defaultValue;
}
}

function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;

// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
}