
// ***** Popup Windows ************************************************************************************** //

/* START JS Browser detect code */
var bow="n";
var bow1="n";

bName = navigator.appName;
bVer = parseInt(navigator.appVersion);

if (bName == "Netscape" && bVer >= 3)
{
	bow = "ok";
	bow1 = "ok";
}
else if (bName == "Microsoft Internet Explorer" && bVer > 3)
{
	bow = "ok";
	bow1="ok";
}
else if (bName == "Microsoft Internet Explorer" && bVer >=2)
{
	bow = "ok";
}

var IS_AOL=0;

if (navigator.userAgent)
{
	if (navigator.userAgent.indexOf("AOL") >=0)
	{
		IS_AOL=1;
		bow1="n";
	}
}
else
{
	bow="n"
	bow1="n";
}
/* END JS Browser detect code */

/* Popup Sized Window */
function openWinSized(f,t,w,h){
	return openWindow(f, t, 'no', 'no', 'yes', 'no', w, h, 'no', 'no', 'no');
}

/* general utility function that accepts parameters for url of filename (f),
target Window (t), 
menubar (m - yes/no), location (l - yes/no), 
scrollbars (s - yes/no), resizeable (r - yes/no), 
window width (w), window height (h). 
Default values are laid out in the function.
*/
function openWindow(f, t, m, l, s, r, w, h, st, tool, d)
{
	var fn_filename = "";
	var fn_target = "_blank";
	var fn_menubar = "yes";
	var fn_location = "yes";
	var fn_scrollbars = "yes";
	var fn_resizable = "yes";
	var fn_width = "600";
	var fn_height = "400";
	var fn_status = "yes";
	var fn_toolbar = "yes";
	var fn_directories = "yes";
	
	if (arguments.length > 0)
	{
		if (f != "" || f != null) fn_filename = f;
		if (t != "" || t != null) fn_target = t;
		if (m == "no") fn_menubar = m;
		if (l == "no") fn_location = l;
		if (s == "no") fn_scrollbars = s;
		if (r == "no") fn_resizable = r;
		if (w > 0) fn_width = w;
		if (h > 0) fn_height = h;
		if (st == "no") fn_status = st;
		if (tool == "no") fn_toolbar = tool;
		if (d == "no") fn_directories = d;
	}
	
	self.name="MainWin";
	
  if (bow!="ok") return (true);
	
	argumentString = 'menubar='+fn_menubar+',location='+fn_location+',scrollbars='+fn_scrollbars+',resizable='+fn_resizable+',width='+fn_width+',height='+fn_height+',status='+fn_status+',toolbar='+fn_toolbar+',directories='+fn_directories;
	
	remote =  window.open(fn_filename,fn_target,argumentString);

    if (remote == null) return true;

    if (bow1 =="ok") window.setTimeout('remote.focus()',1000);
	return (false);
}




// ***** TRACKING FUNCTIONS ************************************************************************************** //

// function to track SiteCatalyst Lead links
function trackSCLead(productID, leadType, leadEvent, brochureName) {
  var s=s_gi(s_account);
  
  s.products = ";" + productID;
  s.eVar18=brochureName;
  s.eVar17=leadType;
  
  if (leadEvent == 0) {
    s.events="event9";
    s.linkTrackEvents="event9"
  } else {
    s.events="event10";
    s.linkTrackEvents="event10"
  }
  
  s.linkTrackVars="eVar17,eVar18,products,events"
  s.tl(this,'o','Lead');
  
}

function trackSCDownload(downloadName) {
  var s=s_gi(s_account);
  s.linkTrackVars='eVar18,events';
  s.linkTrackEvents='event11';
  s.events='event11';
  s.eVar18=downloadName;
  s.tl(this,'d',downloadName);
}

function trackSCEvent(eventID) {
  var s=s_gi(s_account);
  s.events=eventID
  s.linkTrackVars="events"
  s.linkTrackEvents=eventID
  s.tl(true,'o','Login');
}

function trackSCPartnerRefer(partnerName) {
  var s=s_gi(s_account);
  s.events="event13"
  s.eVar20=partnerName;
  s.linkTrackVars="eVar20,events"
  s.linkTrackEvents="event13"
  s.tl(true,'o','Partner Referral');
}


// ***** EYE MAG ************************************************************************************** //

function openEyemag(projectnr, siteid, pagenumber) {

  var fileurl = 'http://www.eyemag.se/core/main.php?PROJECTNR=' + projectnr + '&SITEID=' + siteid + '&OPENPAGE=' + pagenumber;
  
  if (document.all) 
    var xMax = screen.width, yMax = screen.height-16; 
  else { 
    if (document.layers) 
      var xMax = window.outerWidth, yMax = window.outerHeight; 
    else var xMax = 1000, yMax=800; 
  }
  
  var w = xMax-10;
  var h = yMax-12;
  var pop = window.open(fileurl,'Eyemag','width='+w+',height='+h+', screenX=0,screenY=0,top=0,left=0,menubar=0,toolbar=0,status=no,resizable=no');
  
} 


// ***** TRAVEL PACK FUNCTIONS ************************************************************************************** //

function writeTPStatus(loggedIn, itemCount, bookmarkLink, bodyClass) {
  
  document.write('<div id="travelPack">');
  	document.write('<p>');
      
  		document.write('<strong>MY QUEENSLAND HOLIDAY</strong><br/>');
      
  		if (loggedIn == 0) {
        document.write('<a href="/travel-pack/index.cfm?tpAction=signin">Sign in</a> or <a href="/travel-pack/index.cfm?tpAction=register">Register</a>');
      }
      else
      {
    		document.write('<a href="/travel-pack/index.cfm">Your holiday has <span id="travelPackItemCount" attr="' + itemCount + '">' + itemCount + ' item');
        if (itemCount != 1) {
          document.write('s');
        }
        document.write('</a>');
    	}
      
    document.write('</p>');
  document.write('</div>');
}

function writeTpBookmarkLink(bookMarkLink, bodyClass, productLabel) {
  document.write('<a href="' + bookMarkLink + '" class="doTravelPack" title="' + productLabel + ' - Add to My Queensland Holiday"><img src="/fms/graphics/themes/common/button-labels/add-qld-holiday.png" alt="' + productLabel + ' - Add to My Queensland Holiday" border="0" class="button btnLong" /></a>');
}

function writeTpBookmarkLinkProduct(bookMarkLink, bodyClass, productLabel) {
  document.write('<a href="' + bookMarkLink + '" class="doTravelPack" title="' + productLabel + ' - Add to My Queensland Holiday"><img src="/fms/graphics/themes/common/button-labels/product-add-qld-holiday.png" alt="' + productLabel + ' - Add to My Queensland Holiday" border="0" class="button btnProduct" /></a>');
}


function validateTPRegister(register) {
  
  var formValid = true;
  
  var registerFormFields = $([])
   .add( $("#firstname") )
   .add( $("#surname") )
   .add( $("#country") )
   .add( $("#address_state") )
   .add( $("#email") )
   .add( $("#password") )
   .add( $("#subscribe") );
   
  registerFormFields.removeClass('ui-state-highlight');
  $(".formFieldHint").text("").removeClass('ui-state-highlight');
  
  // required: all
  if ( $("#firstname").val() == "") {
    //$("#firstname").addClass('ui-state-highlight');
    $("#firstname_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#surname").val() == "") {
    //$("#surname").addClass('ui-state-highlight');
    $("#surname_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  
  if ( $("#country").val() == "Australia" && $("#address_state").val() == "") {
    //$("#address_state").addClass('ui-state-highlight');
    $("#address_state_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ($("#country").val() == "") {
    //$("#country").addClass('ui-state-highlight');
    $("#country_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  
  // validate the email address
  if ( $("#email").val() != "" && !(validateEmail($("#email").val())) ) {
    //$("#email").addClass('ui-state-highlight');
    $("#email_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ($("#password").val() == "") {
    //$("#password").addClass('ui-state-highlight');
    $("#password_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  
  return formValid;
}

function changeTPCountry(stateObj) {
  var country = document.getElementById('country');
  
  if (stateObj.value != ""){
    country.selectedIndex = 1;
  } else {
    country.selectedIndex = 0;
  }
  
}

function checkTPCountry(countryObj) {
  var address_state = document.getElementById('address_state');
  
  if (countryObj.value == "Australia"){
    address_state.disabled = false;
  } else {
    address_state.selectedIndex = 0;
    address_state.disabled = true;
  }
  
}



function validateTPSignIn(signin) {
  if (signin.useremail.value == "") {
    alert('Please enter your email');  
    signin.useremail.focus();
    return false;
  }
  if (signin.password.value == "") {
    alert('Please enter your password');  
    signin.password.focus();
    return false;
  }
  return true;
}


function validateTPPasswordReminder(password) {
  if (password.useremail.value == "") {
    alert('Please enter your email');  
    password.useremail.focus();
    return false;
  }
  return true;
}


function getTPSelectedItems(tpForm) {
  
  var itemUUIDList = '';
  var itemUUIDElements = document.forms[tpForm];
  
	for (var i=0; i < itemUUIDElements.elements.length; i++) 	{
    if (itemUUIDElements.elements[i].checked) {
      itemUUIDList = itemUUIDList + itemUUIDElements.elements[i].value + ',';
    }
	}
	
  return itemUUIDList;
  
}

function getTPAllItems(tpForm) {
  
  var itemUUIDList = '';
  var itemUUIDElements = document.forms[tpForm];
  
	for (var i=0; i < itemUUIDElements.elements.length; i++) 	{
    itemUUIDList = itemUUIDList + itemUUIDElements.elements[i].value + ',';
	}
	
  return itemUUIDList;
  
}


function tpSelectAll(tpForm) {
  var itemUUIDElements = document.forms[tpForm];
	for (var i=0; i < itemUUIDElements.elements.length; i++) 	{
    itemUUIDElements.elements[i].checked = true;
	}
}
function tpSelectNone(tpForm) {
  var itemUUIDElements = document.forms[tpForm];
	for (var i=0; i < itemUUIDElements.elements.length; i++) 	{
    itemUUIDElements.elements[i].checked = false;
	}
}


function tpMoveItems(tpForm, folders) {
  
  var itemUUIDList = getTPSelectedItems(tpForm);
  if (itemUUIDList == '') {
    alert("Please select the items you'd like to move.");
    
  } else {
    for (i=0; i<folders.length; i++) {
      if (folders[i].selected) {
        folderUUID = folders[i].value;
      }
    }
    window.location = '/travel-pack/index.cfm?tpAction=itemMove&moveToFolderUUID=' + folderUUID + '&itemUUIDList=' + itemUUIDList +'&folderUUID=' + folderUUID;
    
  }
}

function tpMapItems(tpForm) {
  var itemUUIDList = getTPSelectedItems(tpForm);
  if (itemUUIDList == '') {
    var itemUUIDList = getTPAllItems(tpForm);
  }
  openWinSized('/travel-pack/travel-pack-window.cfm?tpAction=map&bodyClass=blue&itemUUIDList=' + itemUUIDList, this.target, 584, 600);
  
}

function tpDeleteItems(tpForm) {
  var itemUUIDList = getTPSelectedItems(tpForm);
  if (itemUUIDList == '') {
    alert("Please select the items you'd like to delete.");
  } else {
    window.location = '/travel-pack/index.cfm?tpAction=itemDelete&itemUUIDList=' + itemUUIDList;
  }
}

function tpEmailItems(tpForm) {
  var itemUUIDList = getTPSelectedItems(tpForm);
  if (itemUUIDList == '') {
    var itemUUIDList = getTPAllItems(tpForm);
  }
  openWinSized('/travel-pack/travel-pack-window.cfm?tpAction=email&itemUUIDList=' + itemUUIDList, this.target, 492, 600);
}

function tpPrintItems(tpForm) {
  var itemUUIDList = getTPSelectedItems(tpForm);
  if (itemUUIDList == '') {
    var itemUUIDList = getTPAllItems(tpForm);
  }
  openWinSized('/travel-pack/travel-pack-window.cfm?tpAction=print&bodyClass=white&itemUUIDList=' + itemUUIDList, this.target, 585, 600);
}

function closeTPWindow() {
  var openedFromURL = window.opener.location;
  window.opener.location = openedFromURL;
  setTimeout("window.close()", 3000);
}


function validateTPEmail(send) {
	
  var formValid = true;
  
  var emailFormFields = $([])
   .add( $("#friendName") )
   .add( $("#friendEmail") )
   .add( $("#ownName") )
   .add( $("#ownEmail") )
   .add( $("#subject") );
   
  emailFormFields.removeClass('ui-state-highlight');
  $(".formFieldHint").text("").removeClass('ui-state-highlight');
  
  if ( $("#friendName").val() == "") {
    $("#friendName_hint").text("Please enter your friend's name").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#friendEmail").val() == "") {
    $("#friendEmail_hint").text("Please enter your friend's email address").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#ownName").val() == "") {
    $("#ownName_hint").text("Please enter your own name").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#ownEmail").val() == "") {
    $("#ownEmail_hint").text("Please enter your own email address").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#subject").val() == "") {
    $("#subject_hint").text("Please enter a subject").addClass('ui-state-highlight');
    formValid = false;
  }
  
  if (formValid) {
    submitTPEmail();
  } else {
    alert("Please check that you have completed all equired fields marked with *.");
  }
	
	return false;
  
}


function validateAddFolder() {
	
  var formValid = true;
  
  var folderFormFields = $([])
   .add( $("#new_folder_name") );
   
  folderFormFields.removeClass('ui-state-highlight');
  $(".formFieldHint").text("").removeClass('ui-state-highlight');
  
  // required: folder name
  if ( $("#new_folder_name").val() == "") {
    $("#new_folder_name_hint").text("Please enter a name for your new folder").addClass('ui-state-highlight');
    formValid = false;
  }
  
  if (formValid) {
    submitTPFolder('add');
  } else {
    alert("Please check that you have completed all equired fields marked with *.");
  }
	
	return false;
}


function validateRemoveFolder() {
	
  var formValid = true;
  
  $(".remove_folder_hint").text("").removeClass('ui-state-highlight');
  
  // required: folder name
  if ( $('input[name=removeFolderUUIDs]:checked').length == 0 ) {
    $("#remove_folder_hint").text("Please click in the checkbox next to at least one folder you wish to remove").addClass('ui-state-highlight');
    formValid = false;
  }
  
  if (formValid) {
    submitTPFolder('remove');
  } else {
    alert("Please check that you have completed all equired fields marked with *.");
  }
	
	return false;
}


function validateNote(notes) {
	
  var formValid = true;
  
  $(".note_hint").text("").removeClass('ui-state-highlight');
  
  // required: folder name
  if ( $("#note").val == "" ) {
    $("#val_hint").text("Please enter the note you would like to add").addClass('ui-state-highlight');
    formValid = false;
  }
  
  if (formValid) {
    submitTPNote();
  } else {
    alert("Please check that you have completed all equired fields marked with *.");
  }
	
	return false;
}



// ***** VALIDATION FUNCTIONS ************************************************************************************** //

// function to validate email addresses
function validateEmail(theEmail) {
  
  var regExp = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
  
  if ( !( regExp.test( theEmail ) ) ) {
    return false;
  } else {
    return true;
  }
  
}


// function to clear the keyword field on search forms
function clearKeywordValue(keywordField)  {
  if (keywordField.value == "Enter a Keyword/s" || keywordField.value == "Search using keywords") {
    keywordField.value = "";
  }
}



function closeDialog(objectUUID) {
  $('#dialogWindow'+objectUUID).dialog('close');
}


function validateCompetitionEntry(extraJSValidateFields) {
  
  var formValid = true;
  var strFields = new String('');
  var arExtraFields = new Array();
  
  if (extraJSValidateFields != "") {
    strFields = new String(extraJSValidateFields);
    arExtraFields = strFields.split(",");
  }
  
  
  $(".formFieldHint").text("").removeClass('ui-state-highlight');
  
  // required
  if ( $("#title").val() == "") {
    $("#title_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#firstName").val() == "") {
    $("#firstName_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#surname").val() == "") {
    $("#surname_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#email").val() == "") {
    $("#email_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#confirm_email").val() == "") {
    $("#confirm_email_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#address_state").val() == "") {
    $("#address_state_hint").text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  
  if (arExtraFields.length > 0) {
    for (i=0; i<arExtraFields.length; i++) {
      
      if ($("#" + arExtraFields[i] ).is("input[type='checkbox']")) {
        if ( $("#"+arExtraFields[i]+":checked").length == 0 ) {
          $("#"+arExtraFields[i]+"_hint").text("required").addClass('ui-state-highlight');
          formValid = false;
        }
      } else {
        if ( $("#" + arExtraFields[i] ).val() == "") {
          $("#"+arExtraFields[i]+"_hint").text("required").addClass('ui-state-highlight');
          formValid = false;
        }
      }
    }
  }
  
  
  if (formValid) {
    return true;
  } else {
    alert("Please check that you have completed all required fields marked with *.");
  }
  
  return false;
  
}

function validateCompetitionRefer(requiredFriendsNumber) {
  
  var formValid = true;
  $(".formFieldHint").text("").removeClass('ui-state-highlight');
  
  if (requiredFriendsNumber > 0) {
    for (i=1; i<=requiredFriendsNumber; i++) {
      if ( $("#friendName" + i).val() == "") {
        $("#friendName" + i + "_hint").text("required").addClass('ui-state-highlight');
        formValid = false;
      }
      if ( $("#friendEmail" + i).val() == "") {
        $("#friendEmail" + i + "_hint").text("required").addClass('ui-state-highlight');
        formValid = false;
      } else if ( $("#friendEmail" + i).val() != "" && !(validateEmail($("#friendEmail" + i).val())) ) {
        $("#friendEmail" + i + "_hint").text("required").addClass('ui-state-highlight');
        formValid = false;
      }
    }
  }
  
  if (formValid) {
    return true;
  } else {
    alert("Please check that you have completed all required fields marked with *.");
  }
  
  return false;
  
}


function validateBrochureOrder(brochureUUID) {
  
  var formValid = true;
  
  var brochureFormFields = $([])
   .add( $("#title-"+brochureUUID) )
   .add( $("#first_name-"+brochureUUID) )
   .add( $("#surname-"+brochureUUID) )
   .add( $("#postal_address-"+brochureUUID) )
   .add( $("#postal_suburb-"+brochureUUID) )
   .add( $("#postal_state-"+brochureUUID) )
   .add( $("#postal_postcode-"+brochureUUID) )
   .add( $("#subsribe-"+brochureUUID) )
   .add( $("#email-"+brochureUUID) );
  
  brochureFormFields.removeClass('ui-state-highlight');
  $(".formFieldHint").text("").removeClass('ui-state-highlight');
  
  // required: first name, surname, (email or phone), enquiry, captcha
  if ( $("#first_name-"+brochureUUID).val() == "") {
    $("#first_name_hint-"+brochureUUID).text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#surname-"+brochureUUID).val() == "") {
    $("#surname_hint-"+brochureUUID).text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  
  if ( $("#postal_address-"+brochureUUID).val() == "" ) {
    $("#postal_address_hint-"+brochureUUID).text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#postal_suburb-"+brochureUUID).val() == "" ) {
    $("#postal_suburb_hint-"+brochureUUID).text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#postal_state-"+brochureUUID).val() == "" ) {
    $("#postal_state_hint-"+brochureUUID).text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#postal_postcode-"+brochureUUID).val() == "" ) {
    $("#postal_postcode_hint-"+brochureUUID).text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  
  // email required if subscribe option ticked
  if ( $("#email-"+brochureUUID).val() == "" && $("#subscribe-"+brochureUUID+":checked").length > 0 ) {
    $("#email_hint-"+brochureUUID).text("required").addClass('ui-state-highlight');
    formValid = false;
  } 
  // validate the email address
  else if ( $("#email-"+brochureUUID).val() != "" && !(validateEmail($("#email-"+brochureUUID).val())) ) {
    $("#email_hint-"+brochureUUID).text("required").addClass('ui-state-highlight');
    formValid = false;
  }
  
  if (formValid) {
    submitBrochureOrder(brochureUUID);
  } else {
    alert("Please check that you have completed all required fields marked with *.");
  }
  
  return false;
  
}


function validateProductEnquiry() {
  
  var formValid = true;
  var doNextEmailCheck = true;
  
  var productEnquiryFields = $([])
   .add( $("#first_name") )
   .add( $("#surname") )
   .add( $("#email") )
   .add( $("#phone") )
   .add( $("#enquiryDetail") )
   .add( $("#captchaUserInput") )
   .add( $("#subsribe") );
   
  productEnquiryFields.removeClass('ui-state-highlight');
  $(".formFieldHint").text("").removeClass('ui-state-highlight');

  // required: first name, surname, (email or phone), enquiry, captcha
  if ( $("#first_name").val() == "") {
    $("#first_name_hint").text("Please enter your first name").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#surname").val() == "") {
    $("#surname_hint").text("Please enter your surname").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#email").val() == "" && $("#phone").val() == "" ) {
    $("#email_hint").text("Please enter a preferred contact").addClass('ui-state-highlight');
    formValid = false;
    doNextEmailCheck = false;
  }
  if ( $("#enquiryDetail").val() == "" ) {
    $("#enquiry_hint").text("Please enter your enquiry").addClass('ui-state-highlight');
    formValid = false;
  }
  if ( $("#captchaUserInput").val() == "" ) {
    $("#captcha_hint").text("Please enter the security code").addClass('ui-state-highlight');
    formValid = false;
  }
  
  // validate the email address
  if ( $("#email").val() != "" && !(validateEmail($("#email").val())) ) {
    $("#email_hint").text("Please enter a valid email address").addClass('ui-state-highlight');
    formValid = false;
    doNextEmailCheck = false;
  }
  
  // check BCC and subscribe for email only if email is already not valid
  if (doNextEmailCheck) {
    // email required if BCC option ticked
    if ( $("#email").val() == "" &&  $("#emailMe:checked").length > 0   ) {
      $("#email_hint").text("Please enter an email address so we can send you a copy of this enquiry").addClass('ui-state-highlight');
      formValid = false;
    }
    // email required if subscribe option ticked
    if ( $("#email").val() == "" && $("#subscribe:checked").length > 0 ) {
      $("#email_hint").text("Please enter an email address to subscribe to the enewsletter").addClass('ui-state-highlight');
      formValid = false;
    }
  }
  
  return formValid;
  
}



// ***** AJAX FUNCTIONS ************************************************************************************** //


// brochure order submit and response functions
function submitBrochureOrder(brochureUUID) {
  var proxy = new ajaxProxy();
  proxy.setCallbackHandler(brochureOrderResponse);
  proxy.setForm('brochureOrderForm'+brochureUUID+'');
  proxy.setHTTPMethod('POST')
  proxy.sendBrochureOrder();
}

function brochureOrderResponse(result) {
  
  if (result.FORMVALID) {
    $('#brochureFormView'+result.BROCHUREUUID).hide();
    $('#confirmationView'+result.BROCHUREUUID).show();
    trackSCLead('', 'Brochure Order', 1, result.BROCHURELABEL);
    //setTimeout(" $('#dialogWindow'+result.BROCHUREUUID).dialog('close') ", 3000);
    
  } else { 
    alert("Please check that you have completed all equired fields marked with *.");
  }
  
}


// product enquiry submit and response functions
function submitProductContact() {
  var proxy = new ajaxProxy();
  proxy.setCallbackHandler(sendEnquiryResponse);
  proxy.setForm('enquiryForm');
  proxy.setHTTPMethod('POST')
  proxy.sendProductEnquiry();
}

function sendEnquiryResponse(result) {

  if (result.FORMVALID) {
    $('#enquiryFormView').hide();
    $('#confirmationView').show();
    trackSCLead(result.PRODUCTATDWID, "Product Enquiry Email", 1);
    
  } else {
    alert("not valid: " + result.INVALIDFIELDS);
    
  }
  
}


// tp add folder submit and response functions
function submitTPFolder(tpAction) {
  var proxy = new ajaxProxy();
  proxy.setCallbackHandler(submitTPFolderResponse);
  if (tpAction == "add") {
    proxy.setForm('tpAddFolderForm');
  } else {
    proxy.setForm('tpRemoveFolderForm');
  }
  proxy.setHTTPMethod('POST')
  proxy.tpFolder();
}

function submitTPFolderResponse(result) {
  
  if (result.FORMVALID) {
    $('#formView').hide();
    $('#confirmationView').show();
    $('#tpFolderList').html(result.HTMLUPDATE.HTMLLIST);
    $('#tpFolderSelect').html(result.HTMLUPDATE.HTMLSELECT);
    
  } else {
    alert("not valid: " + result.INVALIDFIELDS);
    
  }
  
}


// tp email submit and response functions
function submitTPEmail() {
  var proxy = new ajaxProxy();
  proxy.setCallbackHandler(submitTPEmailResponse);
  proxy.setForm('tpEmailForm');
  proxy.setHTTPMethod('POST')
  proxy.tpEmail();
}

function submitTPEmailResponse(result) {
  
  if (result.FORMVALID) {
    $('#formView').hide();
    $('#confirmationView').show();
    
  } else {
    alert("not valid: " + result.INVALIDFIELDS);
    
  }
  
}


// tp note submit and response functions
function submitTPNote() {
  var proxy = new ajaxProxy();
  proxy.setCallbackHandler(submitTPNoteResponse);
  proxy.setForm('tpNoteForm');
  proxy.setHTTPMethod('POST')
  proxy.tpNote();
}

function submitTPNoteResponse(result) {
  
  if (result.FORMVALID) {
    $('#formView').hide();
    $('#confirmationView').show();
    
  } else {
    alert("not valid: " + result.INVALIDFIELDS);
    
  }
  
}



// ***** DOCUMENT READY FUNCTIONS ************************************************************************************** //


var $loading = $('<img src="/fms/graphics/icons/loading.gif" alt="loading" class="loading">');


$(document).ready(function() {
  
  //tabs
  $("#interestingTabs").tabs({ cache: true });
  $("#socialMediaTabs").tabs({ cache: true });
  
  $("#tabs1").tabs({ cache: true,
    show: function(event, ui) {
      if (ui.panel.id == "tab-mapview") {
        resetMap();
      }
    }
  });
  
  $('.servicesLink').click(function() { // bind click event to link
    $("#tabs1").tabs('select', 1); // switch to second tab
    return false;
  });
  
  $('.mapviewLink').click(function() { // bind click event to link
    $("#tabs1").tabs('select', 3); // switch to second tab
    return false;
  });
  
  
  $('.productDepotsLink').click(function(event) {
		//prevent the default action for the click event
		event.preventDefault();
    
    $("#tabs1").tabs('select', 0); // switch to first tab

		//get the top offset of the target anchor
		var target_offset = $("#productSites").offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
    
    return false;
  });
  
  $('.productVenuesLink').click(function(event) {
		//prevent the default action for the click event
		event.preventDefault();
    
    $("#tabs1").tabs('select', 1); // switch to second tab

		//get the top offset of the target anchor
		var target_offset = $("#productVenues").offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 500);
    
    return false;
  });
  
  
  
  $("#tabs2").tabs({ 
    cache: true,
    show: function(event, ui) {
      if (ui.panel.id == "tab-mapview") {
        resetMap();
      }
    }
  });
  
  
  $('#productSlideshowImages').cycle({
    delay: 500,
    timeout: 4000,
    speed: 500,
    fit: 0,
    width: 210, 
    height: 158, 
    before: onBefore,
    pause: 1,
    prev: '#productSlideshowPrev',
    next: '#productSlideshowNext'
  });
  function onBefore() {
    $('#productSlideshowCaption').html(this.title);
  }
  
  $('#productSlideshowPause').click(function() {
    
    $('#productSlideshowImages').cycle('toggle');
    
    if ( $('#productSlideshowPauseImg').attr('alt') == 'Pause Photos' ) {      
      $('#productSlideshowPauseImg').attr('alt', 'Play Photos');
      $('#productSlideshowPauseImg').attr('src', '/fms/graphics/buttons/play.gif');
      
    } else {
      $('#productSlideshowPauseImg').attr('alt', 'Pause Photos');
      $('#productSlideshowPauseImg').attr('src', '/fms/graphics/buttons/pause.gif');
      
    }
    
  });
  
  
  $('.orderBrochureLink').each(function() {
    
    var $brochureDialog = $('<div id="dialogWindow'+$(this).attr('id')+'"></div>')
      .append($loading.clone());
      
    var $brochure = $(this).one('click', function() {
      $brochureDialog  
        .load( $brochure.attr('href') )
        .dialog({
          title: $brochure.attr('title'),
          width: 600,
          height: 550,
          modal: true,
          
          open: function() {
            $("#brochureOrderForm"+$(this).attr('id')+" #title").val("");
            $("#brochureOrderForm"+$(this).attr('id')+" #first_name").val("");
            $("#brochureOrderForm"+$(this).attr('id')+" #surname").val("");
            $("#brochureOrderForm"+$(this).attr('id')+" #postal_address").val("");
            $("#brochureOrderForm"+$(this).attr('id')+" #postal_suburb").val("");
            $("#brochureOrderForm"+$(this).attr('id')+" #postal_state").val("");
            $("#brochureOrderForm"+$(this).attr('id')+" #postal_postcode").val("");
            $("#brochureOrderForm"+$(this).attr('id')+" #subsribe").val("");
            $("#brochureOrderForm"+$(this).attr('id')+" #email").val("");
          },
          
          close: function() {
          }
          
        })
      ;
      
      $brochure.click(function() {
        $brochureDialog.dialog('open');
        return false;
      });
      
      return false;
      
    }); // end $brochure
    
  }); // end for each brochure links
  
  
  
  $('.doTravelPack').each(function() {
    
    var $travelPackDialog = $('<div id="travelPackDialogDiv"></div>')
      .append($loading.clone());
      
    var $travelPack = $(this).click(function() {
      $travelPackDialog
        .load( $travelPack.attr('href') )
        .dialog({
          title: $travelPack.attr('title'),
          width: 600,
          height: 500,
          modal: true,
    			show: 'blind',
    			hide: 'blind',
          buttons: {
            
            Ok: function() {
              $(this).dialog('close');
            }
            
          },
          close: function() {
          }
          
        })
      ;
      
      $travelPack.click(function() {
        $travelPackDialog.dialog('open');
        return false;
      });
    
      return false;
      
    }); // end $travelPack
    
  }); // end for each doTravelPack links
  
  $('.tpRegisterLink').click(function() { // bind click event to link
    $("#tabs1").tabs('select', 0); // switch to second tab
    return false;
  });
  $('.tpSigninLink').click(function() { // bind click event to link
    $("#tabs1").tabs('select', 1); // switch to second tab
    return false;
  });
  $('.tpPasswordLink').click(function() { // bind click event to link
    $("#tabs1").tabs('select', 2); // switch to second tab
    return false;
  });
  
  
    
  // product enquiry dialog window
  $("#contactFormPanel").dialog({
    autoOpen: false,
    height: 700,
    width: 600,
    modal: true,
    buttons: {
      
      'Send Enquiry': function() {
        validateProductEnquiry();
      },
      
      Cancel: function() {
        $(this).dialog('close');
      }
      
    },
    
    close: function() {
    }
    
  });
  
  $('.contactProduct').click(function() {
    $('#contactFormPanel').dialog('open');
    return false;
  });
  
  
  
});
