// Force checkbox selection
function check_it(obj)
{
if (obj.id == 'appointment' && obj.checked) {
document.getElementById('info').checked = false;
}
else if (obj.id == 'info' && obj.checked) {
document.getElementById('appointment').checked = false;
}

}

////////// FORM VALIDATION FUNCTIONS ///////////////////

// check for empty field
function isEmpty(s) {
   if (s==null || s=='' || s=='select') {
          return true;
   }else{
          return false;
   }
}

// set acceptable characters
function isEmail(strValue) {
   regexp = /^([^$@\\ ]+)@((([^$@\\ \.]+)\.)+)([A-Za-z0-9]+)$/
  
   if (isEmpty(strValue)) {
       return false;
	   }
	   return regexp.test(strValue);
}
// check Contact Us form
function checkFormCU() {

		if(isEmpty(document.forms[0].name.value)){
		   alert("Please provide your First Name");
		   document.forms[0].name.style.backgroundColor='#FFF0D2';
		   return false;
		}
	
		if(!isEmail(document.forms[0].email.value)){
		   alert("Please fill in your Email Address correctly");
		   document.forms[0].email.style.backgroundColor='#FFF0D2';
		   return false;
		}
		
		if(isEmpty(document.forms[0].area.value)){
		   alert("Please choose an Area of Interest");
		   document.forms[0].area.style.backgroundColor='#FFF0D2';
		   return false;
		}
		
		if(isEmpty(document.forms[0].msg.value)){
		   alert("How can we help you?");
		   document.forms[0].msg.style.backgroundColor='#FFF0D2';
		   document.forms[0].msg.focus();
		   return false;
		}
			document.forms[0].submit();
		}

// check Connection form
function checkFormC() {

		if(isEmpty(document.forms[0].name.value)){
		   alert("Please provide your First Name");
		   document.forms[0].name.style.backgroundColor='#FFF0D2';
		   return false;
		}
	
		if(!isEmail(document.forms[0].email.value)){
		   alert("Please fill in your Email Address correctly");
		   document.forms[0].email.style.backgroundColor='#FFF0D2';
		   return false;
		}
		
		if(isEmpty(document.forms[0].vehicle.value)){
		   alert("Please Specify Your Vehicle Type");
		   document.forms[0].vehicle.style.backgroundColor='#FFF0D2';
		   return false;
		}
		
		if(isEmpty(document.forms[0].msg.value)){
		   alert("How can we help you?");
		   document.forms[0].msg.style.backgroundColor='#FFF0D2';
		   document.forms[0].msg.focus();
		   return false;
		}
			document.forms[0].submit();
		}
		
////////// END FORM VALIDATION FUNCTIONC ///////////////////


//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#popupBG").css({
			"opacity": "0.7"
		});
		$("#popupBG").fadeIn("slow");
		$("#popupContainer").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#popupBG").fadeOut("slow");
		$("#popupContainer").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContainer").height();
	var popupWidth = $("#popupContainer").width();
	//centering
	$("#popupContainer").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#popupBG").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#popupBG").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

