/***********************************************
* 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";});

	/*set hover class for anything*/
	$('form.cmxform input.send').hover(function() {$(this).addClass('inputhover');}, function() {$(this).removeClass('inputhover');});
		
});


function popUp(URL) {
window.open(URL, "popup_id", "width=780,height=550,left=50,top=50,scrollbars=yes,menubar=yes, resizable=no,location=no,toolbar=no");
}


/***********************************************
* Safe email links
***********************************************/

function hideEmail() {
	var s1 = "info";
			var s2 = "@";
			var s3 = "getthegoods.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 MultiOptionChecked(oField) {
	var iCount = 0;

	for (var i=0; i<oField.length;i++) {
		if ( oField[i].checked ) {
			iCount++;
		}
	}

	if ( iCount == 0 ) {
		return false;
	}

	return true;
}

function ValidateForm(f){

	with(f){

		if (isEmpty(FullName.value)) {alert("Please enter your Name");FullName.focus();return false;}
		if (isEmpty(Address1.value)) {alert("Please enter your Address");Address1.focus();return false;}
		if (isEmpty(Email.value)) {alert("Please enter your Email Address");Email.focus();return false;}
		if (!isEmail(Email.value) ) {alert("Please enter a valid Email Address."); Email.focus();return false;}
		//if ( !MultiOptionChecked(HaveChildren) ) {alert("Please select whether or not you have children."); return false;}
		if ( !MultiOptionChecked(AnyPHI) ) {alert("Please select whether or not you have private health insurance."); return false;}

		if ( AnyPHI[0].checked ) {
			if (isEmpty(WhichPHI.value)) {alert("Please select who you are currently insured with");WhichPHI.focus();return false;}
			if (isEmpty(CoverType.value)) {alert("Please select what your private health insurance currently covers you for");Address1.focus();return false;}
		}

		if (isEmpty(RegNo1.value)) {alert("Please enter your Sunday Mail City Bay Fun Run Event Registration Number");RegNo1.focus();return false;}
		if (isEmpty(RegNo2.value)) {alert("2009 Tour Down Under Registration Number");RegNo2.focus();return false;}

		if (TermsConditions.checked == false){alert("In order to continue you must have read and accepted the Terms & Conditions.");return false;}
	}
	return true;
 }

