$(document).ready(function() 
{
	$('a.poplight[href^=#]').click(function() {
	    var popID = $(this).attr('rel'); //Get Popup Name
	    var popURL = $(this).attr('href'); //Get Popup href to define size

	    //Pull Query & Variables from href URL
	    var query= popURL.split('?');
	    var dim= query[1].split('&');
	    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

	    //Fade in the Popup and add close button
	    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="img/close.png" class="btn_close" title="Close Window" alt="Close" /></a>');

	    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
	    var popMargTop = ($('#' + popID).height() + 80) / 2;
	    var popMargLeft = ($('#' + popID).width() + 80) / 2;

	    // Apply Margin to Popup
	    $('#' + popID).css({
		'margin-top' : -popMargTop,
		'margin-left' : -popMargLeft
	    });

	    //Fade in Background
	    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
	    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

	    return false;
	});

	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
	    $('#fade , .popup_block').fadeOut(function() {
		$('#fade, a.close').remove();  //fade them both out
	    });
	    return false;
	});
	
	$(".modal").click(function(e) { e.preventDefault(); $("fieldset#account_menu").toggle(); });   
	$("fieldset#account_menu").mouseup(function() { return false; });
	$(document).mouseup(function(e) { if($(e.target).parent("a.modal").length==0) { $("fieldset#account_menu").hide(); } });		    

});

// Show contact information below footer 
function showContactInfo() { $("#contact_information").animate({"height": "toggle"}, { duration: 1000 }); }


// Contact form validation
function checkEnquiryForm()
{
   name = document.getElementById("name").value;
   email = document.getElementById("email").value;
   phone = document.getElementById("phone").value;
   enquiry = document.getElementById("enquiry").value;
   
   if(name == "" || name == " " || name == "  " || name == "   " || name == "    " || name == "     " || name == "      " || name == "       ") { hideContactErrors(); document.getElementById("nameError").style.display = "inline"; document.getElementById("name").select(); document.getElementById("name").focus(); return false; }
   if(email == "") { hideContactErrors(); document.getElementById("emailError").style.display = "inline"; document.getElementById("email").select(); document.getElementById("email").focus(); return false; }    	
   if(email != "") { hideContactErrors(); var emailpattern = /^.+@.+\..{2,3}$/; if(!emailpattern.test(email)) { document.getElementById("emailError").style.display = "inline"; document.getElementById("email").select(); document.getElementById("email").focus(); return false; } }    
   if(phone == "" || phone == " " || phone == "  " || phone == "   " || phone == "    " || phone == "     " || phone == "      " || phone == "       ") { hideContactErrors(); document.getElementById("phoneError").style.display = "inline"; document.getElementById("phone").select(); document.getElementById("phone").focus(); return false; }
   if(enquiry == "" || enquiry == " " || enquiry == "  " || enquiry == "   " || enquiry == "    " || enquiry == "     " || enquiry == "      " || enquiry == "       ") { hideContactErrors(); document.getElementById("enquiryError").style.display = "inline"; document.getElementById("enquiry").select(); document.getElementById("enquiry").focus(); return false; }
   
   return true;

}


function closeDIV(div) { document.getElementById(div).style.display = "none"; }



function hideContactErrors()
{
   document.getElementById("nameError").style.display = "none";
   document.getElementById("emailError").style.display = "none";
   document.getElementById("phoneError").style.display = "none";
   document.getElementById("enquiryError").style.display = "none";
}



// Footer tabs - who, what, where
$(document).ready(function() 
{
  $(".tab_content").hide();
  $("ul.tabs li:first").addClass("active").show();
  $(".tab_content:first").show(); 
  $("ul.tabs li").click(function() { $("ul.tabs li").removeClass("active");
  $(this).addClass("active"); 
  $(".tab_content").hide();
  var activeTab = $(this).find("a").attr("href");
  $(activeTab).fadeIn();
  return false;
  $('#tabs').tabs();
});
});


$(document).ready(function() 
{
  $(".tab_contents").hide();
  $("ul.tabs2 li:first").addClass("active").show();
  $(".tab_contents:first").show(); 
  $("ul.tabs2 li").click(function() { $("ul.tabs2 li").removeClass("active");
  $(this).addClass("active"); 
  $(".tab_contents").hide();
  var activeTab = $(this).find("a").attr("href");
  $(activeTab).fadeIn();
  return false;
  $('#tabs2').tabs();
});
});

$(document).ready(function() 
{
  $(".tab_info").hide();
  $("ul.tabs3 li:first").addClass("active").show();
  $(".tab_info:first").show(); 
  $("ul.tabs3 li").click(function() { $("ul.tabs3 li").removeClass("active");
  $(this).addClass("active"); 
  $(".tab_info").hide();
  var activeTab = $(this).find("a").attr("href");
  $(activeTab).fadeIn();
  return false;
  $('#tabs3').tabs();
});
});

$(document).ready(function() 
{
  $(".tabs_info").hide();
  $("ul.tabs4 li:first").addClass("active").show();
  $(".tabs_info:first").show(); 
  $("ul.tabs4 li").click(function() { $("ul.tabs4 li").removeClass("active");
  $(this).addClass("active"); 
  $(".tabs_info").hide();
  var activeTab = $(this).find("a").attr("href");
  $(activeTab).fadeIn();
  return false;
  $('#tabs4').tabs();
});
});



// Quotation form
function checkQuoteForm()
{
	postcode = document.getElementById("postcode").value;
	package = document.getElementById("package").selectedIndex;
	value = document.getElementById("value").selectedIndex;

	if(postcode == "" || postcode == " " || postcode == "  " || postcode == "   " || postcode == "    " || postcode == "     " || postcode == "      ") { hideQuoteErrors(); document.getElementById("postcodeError").style.display = "inline"; document.getElementById("postcode").select(); document.getElementById("postcode").focus(); return false; }
	if(package == "") { hideQuoteErrors(); document.getElementById("packageError").style.display = "inline"; return false; }
	if(value == "") { hideQuoteErrors(); document.getElementById("valueError").style.display = "inline"; return false; }
	
	return true;
}

function hideQuoteErrors()
{
	document.getElementById("postcodeError").style.display = "none";
	document.getElementById("packageError").style.display = "none";
	document.getElementById("valueError").style.display = "none";
}


// Login form 
function checkLogin()
{
	user = document.getElementById("user").value;
	pass = document.getElementById("pass").value;
	
	if(user == "" || user == " " || user == "  " || user == "   " || user == "    " || user == "     " || user == "      ") { hideLoginErrors(); document.getElementById("userError").style.display = "inline"; document.getElementById("user").select(); document.getElementById("user").focus(); return false; }
	if(pass == "" || pass == " " || pass == "  " || pass == "   " || pass == "    " || pass == "     " || pass == "      ") { hideLoginErrors(); document.getElementById("passError").style.display = "inline"; document.getElementById("pass").select(); document.getElementById("pass").focus(); return false; }
	
	return true;
}

function hideLoginErrors()
{
	document.getElementById("userError").style.display = "none";
	document.getElementById("passError").style.display = "none"; 
}


// Register form
function checkRegister()
{
	registername = document.getElementById("registername").value;
	registeremail = document.getElementById("registeremail").value;
	registeruser = document.getElementById("registeruser").value;
	registerpass = document.getElementById("registerpass").value;
	registerpass2 = document.getElementById("registerpass2").value;
	
	if(registername == "" || registername == " " || registername == "  " || registername == "   " || registername == "    " || registername == "     " || registername == "      ") { hideRegisterErrors(); document.getElementById("registernameError").style.display = "inline"; document.getElementById("registername").select(); document.getElementById("registername").focus(); return false; }
        if(registeremail == "") { hideRegisterErrors(); document.getElementById("registeremailError").style.display = "inline"; document.getElementById("registeremail").select(); document.getElementById("registeremail").focus(); return false; }    	
        if(registeremail != "") { hideRegisterErrors(); var emailpattern = /^.+@.+\..{2,3}$/; if(!emailpattern.test(registeremail)) { document.getElementById("registeremailError").style.display = "inline"; document.getElementById("registeremail").select(); document.getElementById("registeremail").focus(); return false; } }    
	if(registeruser == "" || registeruser == " " || registeruser == "  " || registeruser == "   " || registeruser == "    " || registeruser == "     " || registeruser == "      ") { hideRegisterErrors(); document.getElementById("registeruserError").style.display = "inline"; document.getElementById("registeruser").select(); document.getElementById("registeruser").focus(); return false; }
	if(registerpass == "" || registerpass == " " || registerpass == "  " || registerpass == "   " || registerpass == "    " || registerpass == "     " || registerpass == "      ") { hideRegisterErrors(); document.getElementById("registerpassError").style.display = "inline"; document.getElementById("registerpass").select(); document.getElementById("registerpass").focus(); return false; }
	if(registerpass2 == "" || registerpass2 == " " || registerpass2 == "  " || registerpass2 == "   " || registerpass2 == "    " || registerpass2 == "     " || registerpass2 == "      ") { hideRegisterErrors(); document.getElementById("registerpass2Error").style.display = "inline"; document.getElementById("registerpass2").select(); document.getElementById("registerpass2").focus(); return false; }
	
	return true;
}

function hideRegisterErrors()
{
	document.getElementById("registernameError").style.display = "none";
	document.getElementById("registeremailError").style.display = "none";
	document.getElementById("registeruserError").style.display = "none";
	document.getElementById("registerpassError").style.display = "none";
	document.getElementById("registerpass2Error").style.display = "none";
}


// Main contact form
function checkMainContact()
{
	yourname = document.getElementById("yourname").value;
	youremail = document.getElementById("youremail").value;
	yourphone = document.getElementById("yourphone").value;
	yourenquiry = document.getElementById("yourenquiry").value;

	if(yourname == "" || yourname == " " || yourname == "  " || yourname == "   " || yourname == "    " || yourname == "     " || yourname == "      " || yourname == "       ") { hideMainContactErrors(); document.getElementById("yournameError").style.display = "inline"; document.getElementById("yourname").select(); document.getElementById("yourname").focus(); return false; }
	if(youremail == "") { hideMainContactErrors(); document.getElementById("youremailError").style.display = "inline"; document.getElementById("youremail").select(); document.getElementById("youremail").focus(); return false; }    	
	if(youremail != "") { hideMainContactErrors(); var emailpattern = /^.+@.+\..{2,3}$/; if(!emailpattern.test(youremail)) { document.getElementById("youremailError").style.display = "inline"; document.getElementById("youremail").select(); document.getElementById("youremail").focus(); return false; } }    
	if(yourphone == "" || yourphone == " " || yourphone == "  " || yourphone == "   " || yourphone == "    " || yourphone == "     " || yourphone == "      " || yourphone == "       ") { hideMainContactErrors(); document.getElementById("yourphoneError").style.display = "inline"; document.getElementById("yourphone").select(); document.getElementById("yourphone").focus(); return false; }
	if(yourenquiry == "" || yourenquiry == " " || yourenquiry == "  " || yourenquiry == "   " || yourenquiry == "    " || yourenquiry == "     " || yourenquiry == "      " || yourenquiry == "       ") { hideMainContactErrors(); document.getElementById("yourenquiryError").style.display = "inline"; document.getElementById("yourenquiry").select(); document.getElementById("yourenquiry").focus(); return false; }

	return true;
}

function hideMainContactErrors()
{
	document.getElementById("yournameError").style.display = "none";
	document.getElementById("youremailError").style.display = "none";
	document.getElementById("yourphoneError").style.display = "none";
	document.getElementById("yourenquiryError").style.display = "none";
}


// Forgotten password validation
function checkForgotPass()
{
	forgotemail = document.getElementById("forgotemail").value;
	
	if(forgotemail == "") { hideForgotErrors(); document.getElementById("forgotemailError").style.display = "inline"; document.getElementById("forgotemail").select(); document.getElementById("forgotemail").focus(); return false; }    	
	if(forgotemail != "") { hideForgotErrors(); var emailpattern = /^.+@.+\..{2,3}$/; if(!emailpattern.test(forgotemail)) { document.getElementById("forgotemailError").style.display = "inline"; document.getElementById("forgotemail").select(); document.getElementById("forgotemail").focus(); return false; } }    
	
	return true;
}

function hideForgotErrors() { document.getElementById("forgotemailError").style.display = "none"; }


function checkPassword()
{
    	password = document.getElementById("password").value;
    	confirmpassword = document.getElementById("confirmpassword").value;
		
	if(password == "" || password == " " || password == "  " || password == "   " || password == "    " || password == "     " || password == "      ") { alert("Please provide a password!"); document.getElementById("password").select(); document.getElementById("password").focus(); return false; }
	if(confirmpassword == "" || confirmpassword == " " || confirmpassword == "  " || confirmpassword == "   " || confirmpassword == "    " || confirmpassword == "     " || confirmpassword == "      ") { alert("Please confirm your password!"); document.getElementById("confirmpassword").select(); document.getElementById("confirmpassword").focus(); return false; }

	if(password != confirmpassword) { alert("The two passwords do not match"); return false; }

	return true;
}


// Link Exchange form validation
function checkLinkExchange()
{
   	linkname = document.getElementById("linkname").value;
   	linkemail = document.getElementById("linkemail").value;
   	linkweb = document.getElementById("linkweb").value;
   	linkcomments = document.getElementById("linkcomments").value;
   	
   	if(linkname == "" || linkname == " " || linkname == "  " || linkname == "   " || linkname == "    " || linkname == "     " || linkname == "      ") { hideLinkErrors(); document.getElementById("linknameError").style.display = "inline"; document.getElementById("linkname").select(); document.getElementById("linkname").focus(); return false; }   	
	if(linkemail == "") { hideLinkErrors(); document.getElementById("linkemailError").style.display = "inline"; document.getElementById("linkemail").select(); document.getElementById("linkemail").focus(); return false; }    	
	if(linkemail != "") { hideLinkErrors(); var emailpattern = /^.+@.+\..{2,3}$/; if(!emailpattern.test(linkemail)) { document.getElementById("linkemailError").style.display = "inline"; document.getElementById("linkemail").select(); document.getElementById("linkemail").focus(); return false; } }    
   	if(linkweb == "" || linkweb == " " || linkweb == "  " || linkweb == "http://www." || linkweb == "http://www. " || linkweb == "http://www.  " || linkweb == "http://www.   ") { hideLinkErrors(); document.getElementById("linkwebError").style.display = "inline"; document.getElementById("linkweb").select(); document.getElementById("linkweb").focus(); return false; }   	
   	if(linkcomments == "" || linkcomments == " " || linkcomments == "  " || linkcomments == "   " || linkcomments == "    " || linkcomments == "     " || linkcomments == "      ") { hideLinkErrors(); document.getElementById("linkcommentsError").style.display = "inline"; document.getElementById("linkcomments").select(); document.getElementById("linkcomments").focus(); return false; }   	
   	
	return true;   	
}

function hideLinkErrors()
{
	document.getElementById("linknameError").style.display = "none";
	document.getElementById("linkemailError").style.display = "none";
	document.getElementById("linkwebError").style.display = "none";
	document.getElementById("linkcommentsError").style.display = "none";
}


// Local page form
function checkLocal()
{
   	con_name = document.getElementById("con_name").value;
   	con_email = document.getElementById("con_email").value;
	con_heard = document.getElementById("con_heard").selectedIndex;
	con_enquiry = document.getElementById("con_enquiry").value;
	
	if(con_name == "" || con_name == " " || con_name == "  " || con_name == "   " || con_name == "     " || con_name == "     " || con_name == "      " || con_name == "       ") { alert("Please provide your name!"); document.getElementById("con_name").select(); document.getElementById("con_name").focus(); return false; }
	if(con_email == "") { alert("Please provide your email address!"); document.getElementById("con_email").select(); document.getElementById("con_email").focus(); return false; }    	
	if(con_email != "") { var emailpattern = /^.+@.+\..{2,3}$/; if(!emailpattern.test(con_email)) { alert("Please provide a valid email address!"); document.getElementById("con_email").select(); document.getElementById("con_email").focus(); return false; } }    
	if(con_heard == "") { alert("Where did you hear about us?"); return false; }    	
	if(con_enquiry == "" || con_enquiry == " " || con_enquiry == "  " || con_enquiry == "   " || con_enquiry == "     " || con_enquiry == "     " || con_enquiry == "      " || con_enquiry == "       ") { alert("Please enter your enquiry!"); document.getElementById("con_enquiry").select(); document.getElementById("con_enquiry").focus(); return false; }
	
	return true;
}


function showDIV(container) { document.getElementById(container).style.display = "block"; }
function hideDIV(container) { document.getElementById(container).style.display = "none"; }

