
// Hide Extra info when js enabled - Show Extra info when js disabled
fonLoad=function() {

	var extra = document.getElementById("extraInfo");
	var hidelnk  = document.getElementById("hideLink");
	var showlnk  = document.getElementById("showLink");

	extra.style.display="none";
	hidelnk.style.display="inline";
	showlnk.style.display="inline";
}


// Show Extra info
function showExtra() {

	var extra = document.getElementById("extraInfo");
	var lnk  = document.getElementById("showLink");
	
	if( extra.style.display == "block" )
	{
		extra.style.display="none"; //hides div
		lnk.innerHTML = "more&gt"; //change link text
	}
	else
	{
		extra.style.display="block";
		lnk.innerHTML = "";
	}		
	
	return false;
	
}


// Destination form navigation
function goDestination() {
  
  if (document.destinationNavigation.destURL.value != '') {
     window.location = document.destinationNavigation.destURL.value;
  } else {
    return false;
  }
	
}


// 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 */

/* changeImage function modified to work with the open/close images on the schedule page */
function changeImage(row,s,sched)
{
	var h = (s==1)?"r":"";
	var row_src = (parseInt(sched)>=1)?'r'+sched:row;

	if(document.images) document.images[row].src = eval(h + row_src + ".src");
}
/* Popup used in video 4:3 and popup slideshow */
function openPhotoWin(f,t){
	return openWindow(f, t, 'no', 'no', 'no', 'no', 568, 520, 'no', 'no', 'no');
}
/* Popup used in video 16:9 */
function openPhotoWin169(f,t){
	return openWindow(f, t, 'no', 'no', 'no', 'no', 568, 420, 'no', 'no', 'no');
}
/* Popup used in Brochure Order Form */
function openWinBrochure(f,t){
	return openWindow(f, t, 'no', 'no', 'yes', 'no', 492, 520, 'no', 'no', 'no');
}
/* Popup Travel Info Emquiry */
function openWinEnquiry(f,t){
	return openWindow(f, t, 'no', 'no', 'no', 'no', 475, 520, 'no', 'no', 'no');
}
/* 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);
}


// Flash Player 8 Detect
var url_file = '';
var MM_FlashPlayerVersion = 8;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	    for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
	    }
		var MM_FlashPlayerInstalled = MM_PluginVersion >= MM_FlashPlayerVersion;
	}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<scr' + 'ipt language=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashPlayerInstalled = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_FlashPlayerVersion)))\n');
	document.write('</scr' + 'ipt\> \n');
}

// Hook for Internet Explorer. the ActiveX player raises events
// that need to be handled via vbscript. calls the eqivalent JS function
// that does the work. you need 1 of these functions per swf instance on the page.
function writeVBHandler(id)
{
	 var s = '';
	
	if (navigator.appName && 
	  navigator.appName.indexOf("Microsoft") != -1 &&
	  navigator.userAgent.indexOf("Windows") != -1 && 
	  navigator.userAgent.indexOf("Windows 3.1") == -1) 
	{	 
	  s += '<SCRIPT LANGUAGE=VBScript\> \n';
	  s += 'on error resume next \n';
	  s += 'sub '+id+'_FSCommand(ByVal command, ByVal args)\n';
	  s += ' call '+id+'_DoFSCommand(command,args)\n';
	  s += 'end sub\n';
	  s += '</SCRIPT\> \n';	  	
	}
	return s;
}


// Validates the contact enquiry form
function checkContactForm(contact) {

  if (contact.givenName.value == "") {
    alert("Please enter your given name.");
    contact.givenName.focus();
    return false;
  }
  if (contact.familyName.value == "") {
    alert("Please enter your family name.");
    contact.familyName.focus();
    return false;
  }  
  
 if ( (contact.email.value == "" || contact.email.value == "Email Address") && (contact.phone.value == "" || contact.phone.value == "Phone Number") ) {
    alert("Please enter a preferred contact.")
    contact.email.focus();
    return false;
    
  } else if (contact.email.value != "Email Address" && contact.email.value != "") {
    if (!checkEmail(contact.email.value)) {
      contact.email.focus();
      return false;
    } 
  }
  if (contact.enquiryDetail.value == "") {
    alert("Please enter the details of your enquiry.");
    contact.enquiryDetail.focus();
    return false;
 }
 
 if (contact.emailMe.checked && contact.email.value == "") {
    alert("Please enter your email address.")
    contact.email.focus();
    return false;
    
 } else if (contact.email.value != "Email Address" && contact.email.value != "") {
    if (!checkEmail(contact.email.value)) {
     contact.email.focus();
     return false;
    } 
  }    

}


// Validates the contact enquiry form
function checkOperatorContactForm(contact) {

  if (contact.givenName.value == "") {
    alert("Please enter your given name.");
    contact.givenName.focus();
    return false;
  }
  if (contact.familyName.value == "") {
    alert("Please enter your family name.");
    contact.familyName.focus();
    return false;
  }  
  
 if (contact.email.value == "" && contact.phone.value == "") {
    alert("Please enter a preferred contact.")
    contact.email.focus();
    return false;
    
  } else {
    if (!checkEmail(contact.email.value)) {
      contact.email.focus();
      return false;
    } 
  }
  if (contact.enquiryDetail.value == "") {
    alert("Please enter the details of your enquiry.");
    contact.enquiryDetail.focus();
    return false;
  }
      
 if (contact.emailMe.checked && contact.email.value == "") {
    alert("Please enter your email address.")
    contact.email.focus();
    return false;
    
 } else {
    if (!checkEmail(contact.email.value)) {
     contact.email.focus();
     return false;
    } 
  }
  
  return true;

}


// Validates the brochure order form
function checkBrochureForm(brochure) {

  if (brochure.givenName.value == "") {
    alert("Please enter your given name.");
    brochure.givenName.focus();
    return false;
  }
  if (brochure.familyName.value == "") {
    alert("Please enter your family name.");
    brochure.familyName.focus();
    return false;
  }  
  if (brochure.postalAddress.value == "") {
    alert("Please enter your postal address.");
    brochure.postalAddress.focus();
    return false;
  }
  if (brochure.suburb.value == "") {
    alert("Please enter your suburb.");
    brochure.suburb.focus();
    return false;
  }
  if (brochure.state.value == "") {
    alert("Please select your state.");
    return false;
  }
  if (brochure.postcode.value == "") {
    alert("Please enter your postcode.");
    brochure.postcode.focus();
    return false;
  }
  
 if (brochure.eNewsletter.checked && brochure.email.value == "") {
    alert("Please enter your email.")
    brochure.email.focus();
    return false;
    
 } else {
    if (!checkEmail(brochure.email.value)) {
     brochure.email.focus();
     return false;
    } 
  }

}


// Validates the feedback questionnaire form
function checkFeedbackForm(feedback) {
  
  var notChecked = new String("");
  
  for (i=1; i<=6; i++) {
    
    checked = false;
    for (j=0; j < feedback['q'+i].length; j++) {
      if (feedback['q'+i][j].checked) {
        checked = true;
      }
    }
    if (checked == false) {
      notChecked = notChecked + i + ",";
    }
    
  }
  
  if (notChecked != "") {
    alert("Please provide your answer for Question(s): " + notChecked.substring(0, notChecked.length-1));
    return false;
  }
  
  return true;
  
}


// function to validate email addresses
function checkEmail(theEmail)  {

  var foundAt = 0;
  var foundPeriod = 0;
  var checktheEmail = true;
  var errorString = ""
  for( i = 0; i < theEmail.length; i++ ) {
    if(theEmail.charAt(i) != '@') {
      foundAt++;
    } else {
      break;
    }
  }
  for( i = 0; i < theEmail.length; i++ ) {
    if(theEmail.charAt(i) != '.') {
      foundPeriod++;
    } else {
      break;
    }
  }
  if(theEmail.length == 0) {
    checktheEmail = true;
  } else if(theEmail.length == foundAt) {
    errorString += "Your email address does not contain the '@' symbol. Please make sure your email address is correct so we can contact you.";
    checktheEmail = false;
  } else if(foundAt == 0 || theEmail.charAt(foundAt - 1) == ' ') {
    errorString += "Your email address does not contain a name before the '@' symbol. Please make sure your email address is correct so we can contact you.";
    checktheEmail = false;
  } else if((theEmail.charAt(foundAt + 1) == ' ' || theEmail.charAt(foundAt + 1) == '.') || foundAt + 1 == theEmail.length) {
    errorString += "Your email address contains no details after after the '@' symbol. Please make sure your email address is correct so we can contact you.";
    checktheEmail = false;
  } else if(theEmail.length == foundPeriod) {
    errorString += "Your email address does not contain the '.' symbol. Please make sure your email address is correct so we can contact you.";
    checktheEmail = false;
  } else if(theEmail.charAt(foundPeriod + 1) == ' ' || foundPeriod + 1 == theEmail.length) {
    errorString += "Your email address contains no details after the '.' symbol. Please make sure your email address is correct so we can contact you.";
    checktheEmail = false;
  }
  if(checktheEmail == false) {
    alert(errorString);
  }
    return checktheEmail;
}



// 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');
}




// function to track HBX links
function doLink(custom4)  {
  //_hbSet('c4',custom4);
  //_hbSet('gp','LAST');
  //_hbSet('gn','Lead To Operator');
  //_hbSend();
}

// function to track HBX links to custom metrics
function trackHBXMetric(custom4,custom3)  {
  //if (custom4 != '') {
    //_hbSet('c4',custom4);
  //}
  //if (custom3 != '') {
    //_hbSet('c3',custom3);
  //}
  //_hbSet('gp','LAST');
  //_hbSet('gn','Lead To Operator');
  //_hbSend();
}



// 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 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="travel_pack_nav">');
  	document.write('<p>');
  		document.write('Collect your<br />favourite holiday ideas...<br />');
  		if (loggedIn == 0) {
        document.write('<a href="/travel-pack/index.cfm">More</a> | <a href="/travel-pack/index.cfm?tpAction=signin">Login</a> | <a href="/travel-pack/index.cfm?tpAction=register">Sign-up</a>');
      } else {
        document.write('<a href="/travel-pack/index.cfm">View List</a>');
      }
  	document.write('</p>');
  	document.write('<div class="border">');
      document.write('<p>');
    		document.write('Your pack has <b><span id="travelPackItemCount" attr="' + itemCount + '">' + itemCount + ' item');
        if (itemCount != 1) {
          document.write('s');
        }
        document.write('</span></b><br />');
        document.write('<a href="' + bookmarkLink + '" target="tpWindow" onclick="return openWinSized(this.href, this.target, 200, 200);"><img src="/qldhols_06/fms/images/travel_pack/icon_travelpack_' + bodyClass + '.gif" width="21" height="16" border="0" alt="Add to Travel Pack icon"></a>&nbsp;');
    		document.write('<a href="' + bookmarkLink + '" target="tpWindow" onclick="return openWinSized(this.href, this.target, 200, 200);">Add to Travel Pack</a>');
    	document.write('</p>');
    document.write('</div>');
  document.write('</div>');
}

function writeTpBookmarkLink(bookMarkLink, bodyClass) {
  document.write('<a href="' + bookMarkLink + '" target="tpWindow" onclick="return openWinSized(this.href, this.target, 200, 200);" title="Add to Travel Pack"><img src="/qldhols_06/fms/images/global/buttons_icons/gr_travelpack_add_' + bodyClass + '.gif" alt="Add to Travel Pack" width="26" height="39" border="0" /></a>');
}

function writeTpBookmarkLinkProduct(bookMarkLink) {
  document.write('<li class="addTravelPack"><a href="' + bookMarkLink + '" target="tpWindow" onclick="return openWinSized(this.href, this.target, 200, 200);">Add to Travel Pack</a></cfoutput></li>');
}


function validateRegister(register) {

  if (register.firstname.value == "") {
    alert('Please enter your first name');  
    register.firstname.focus();
    return false;
  }
  if (register.surname.value == "") {
    alert('Please enter your surname');  
    register.surname.focus();
    return false;
  }
  
  if (register.country.value == "Australia" && register.address_state.value == "") {
    alert('Please select your state');  
    register.address_state.focus();
    return false;
  }
  if (register.country.value == "") {
    alert('Please select your country');  
    register.country.focus();
    return false;
  }
  
  if (register.email.value == "") {
    alert('Please enter your email');  
    register.email.focus();
    return false;
  }
  if (!checkEmail(register.email.value)) {
    register.email.focus();
    return false;
  } 
  if (register.password.value == "") {
    alert('Please enter a password for your travel pack log-in');  
    register.password.focus();
    return false;
  }
  
  return true;
}

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 validateSignIn(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 validatePasswordReminder(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) {
  
  if (send.friendName.value == '') {
    alert("Please enter your friend's name");  
    send.friendName.focus();
    return false;
  }
  
  if (send.friendEmail.value == '') {
    alert('Please enter your friend\'s email address');  
    send.friendEmail.focus();
    return false;
  }
  if (!checkEmail(send.friendEmail.value)) {
    send.friendEmail.focus();
    return false;
  } 

  if (send.ownName.value == '') {
    alert('Please enter your name');  
    send.ownName.focus();
    return false;
  }
  if (send.ownEmail.value == '') {
    alert('Please enter your email address');  
    send.ownEmail.focus();
    return false;
  }
  if (!checkEmail(send.ownEmail.value)) {
    send.ownEmail.focus();
    return false;
  } 
  
  if (send.subject.value == '') {
    alert('Please enter the subject for your email');  
    send.subject.focus();
    return false;
  }

  return true;
}

function validateAddFolder(folder) {
	
	if (folder.newFolderName.value == '') 	{
		alert('Please enter the name of the new folder to create');	
		folder.newFolderName.focus();
		return false;
	}
	
	return true;
}

function validateRemoveFolder(folder) {

	var somethingChecked = false;	
	for (var i=0; i<folder.removeFolderUUIDs.length; i++) 	{
		somethingChecked = somethingChecked || folder.removeFolderUUIDs[i].checked;
	}
	
	if (!somethingChecked) 	{
		alert('Please click in the checkbox next to at least one folder you wish to remove');
		return false;
	}
	
	return true;
}

function validateNotes(notes) {
	if (notes.note.value == '') 	{
		alert('Please enter the note you would like to add');	
		notes.note.focus();
		return false;
	}
	return true;
}
