/***********************************************
* jQuery functions execute
***********************************************/

$(document).ready(function() {                
              
	/*cmx form */
	if(jQuery.browser.mozilla) {
		$('form.cmxform').hide().find('label:not(.nocmx)').each(function(){
                          	var $labelContent = $(this).html();
                                       var $labelWidth = $(this).css('width');
                                       $(this).empty();
                                       $(this).append('<span style="display: block; width: '+$labelWidth+';">');
                                       $(this).prepend('</span>');
                                       $(this).css('display', '-moz-inline-box');
                                       $(this).find('span').html($labelContent);
                                       $('form.cmxform').show();
                                });
                };             


	/*external link*/
	$('a[@rel$="external"]').click(function(){this.target = "_blank";});
	$('ul#nav a#navservices').click(function(){window.location = 'services.asp?id=laser-dentistry';});
	
	/* Popup window - class="popup" rel="standardwindow" */
	var profiles = {standardwindow:{height:500,width:750,center:1,toolbar:0,menubar:1,scrollbars:1,resizable:0},smallwindow:{height:500,width:650,status:1,scrollbars:1,menubar:1,resizable:0,center:1}};
   $(function(){$(".popup").popupwindow(profiles);});

	/*set hover class for anything*/
	$('form.cmxform input.send').hover(function() {$(this).addClass('hover');}, function() {$(this).removeClass('hover');});
	/*dropdown fix*/
	$('ul#nav li').hover(function() {$(this).addClass('over');}, function() {$(this).removeClass('over');});
	$('body#services ul#nav ul').css('left','0');
			
	/*hide and show - with effect*/
	$('#map').hide();
	$('a.openmap').click(function() {$('#map').fadeIn('slow').animate({opacity: 1.0}); });
	$('a.closemap').click(function() {$('#map').fadeOut('slow').animate({opacity: 0});});
	$('#map').css('cursor', 'pointer').click(function() {$('#map').fadeOut('slow').animate({opacity: 0});});
	
});


/***********************************************
* Safe email links
***********************************************/

function hideEmail() {
	var s1 = "info";
			var s2 = "@";
			var s3 = "123dental.com.au";
			var s4 = "?Subject=Enquiry%20from%20" + s3;
			var s5 = s1 + s2 + s3;
			document.write("<a href=" + "mail" + "to:" + s1 + s2 + s3 + s4 + ">" + s5 + "</a>");
}

/***********************************************
* Form fields Validation Script
***********************************************/

function ValidateForm(f){

	with(f){
		var chkcount;
		if (isEmpty(_1_First_Name.value)) {alert("Please enter your First Name");_1_First_Name.focus();return false;}
		if (isEmpty(_2_SurName.value)) {alert("Please enter your Surname");_2_SurName.focus();return false;}
		if (isEmpty(_3_Phone.value)) {alert("Please enter your Phone");_3_Phone.focus();return false;}
		if (isEmpty(_4_Email_From.value)) {alert("Please enter your Email Address");_4_Email_From.focus();return false;}
		if ( !isEmail(_4_Email_From.value) ) {alert("Please enter a valid Email Address."); _4_Email_From.focus();return false;}
		if (isEmpty(_5_Address1.value)) {alert("Please enter your Address");_5_Address1.focus();return false;}
		if (isEmpty(_7_Postcode.value)) {alert("Please enter your Postcode");_7_Postcode.focus();return false;}
		if (_8_Medical_Condition_Changed[0].checked == false && _8_Medical_Condition_Changed[1].checked == false) {alert("Please answer to the medical condition question");return false;}
		// Check that at least one checkbox option was selected
			chkcount = 0;
			for (var i=0; i < _9_Appointment_Reasons.length; i++) {
				if ( _9_Appointment_Reasons[i].checked ) {
			  		chkcount += 1;
				}
			}
			if ( chkcount == 0 ) {
				alert("Please select at least one reason for your appointment");
				return false;
			}
		if (isEmpty(_10_Desired_Date.value)) {alert("Please enter your Desired Date");_10_Desired_Date.focus();return false;}
		if (isEmpty(_11_Desired_Time.value)) {alert("Please enter your Desired Time");_11_Desired_Time.focus();return false;}
		if (isEmpty(_12_Enquiries.value)) {alert("Please enter your Comments");_12_Enquiries.focus();return false;}
	}
	return true;
 }

