
// 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(selectedDestination) {
  
  if (selectedDestination.url.value != '') {
     window.location = selectedDestination.url.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, 500, 'no', 'no', 'no');
}
/* Popup Sized Window */
function openWinSized(f,t,w,h){
	return openWindow(f, t, 'no', 'no', 'no', '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 HBX links
function doLink(custom4)  {
  _hbSet('c4',custom4);
  _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');
  
} 

