
//////////////////////////////////////////////////////////
// build array of highlight ID's
var arrSectionIds = new Array()
arrSectionIds[0] = new highlightPair ("Case_Study" , "case_studies" )
arrSectionIds[1] = new highlightPair ("Research" , "research" )
arrSectionIds[2] = new highlightPair ("Creative" , "creative_gallery" )
arrSectionIds[3] = new highlightPair ("Integrated_Marketing" , "integrated_marketing" )
arrSectionIds[4] = new highlightPair ("Event" , "editorial_events" )
arrSectionIds[5] = new highlightPair ("Media_Briefing" , "newsletter" )
arrSectionIds[6] = new highlightPair ("Creative_Use_Of_Media" , "creative_media_use" )
arrSectionIds[7] = new highlightPair ("Home" , "home" )
arrSectionIds[8] = new highlightPair ("About_the_NMA" , "about_the_nma" )
arrSectionIds[9] = new highlightPair ("Breaking_Ads" , "breaking_ads" )
arrSectionIds[10] = new highlightPair ("Facts_and_figures" , "facts_and_figures" )
arrSectionIds[11] = new highlightPair ("Newsletter" , "newsletter" )
arrSectionIds[12] = new highlightPair ("Training_and_events" , "training_and_events" )
arrSectionIds[13] = new highlightPair ("Feedback" , "feedback" )
arrSectionIds[14] = new highlightPair ("Register" , "register" )
arrSectionIds[15] = new highlightPair ("Search" , "search" )
arrSectionIds[16] = new highlightPair ("Sitemap" , "sitemap" )
arrSectionIds[17] = new highlightPair ("Contact_Us" , "contactus" )
arrSectionIds[18] = new highlightPair ("Legal" , "legal" )
arrSectionIds[19] = new highlightPair ("Have_You_Seen" , "have_you_seen" )
arrSectionIds[20] = new highlightPair ("Why_Newspapers" , "why_newspapers" )
arrSectionIds[21] = new highlightPair ("Links" , "links" )
arrSectionIds[22] = new highlightPair ("Download" , "down_loads" )
arrSectionIds[23] = new highlightPair ("HarnessingEditorial" , "harnessing_editorial" )
arrSectionIds[24] = new highlightPair ("OnlineNews" , "onlinenews" )
arrSectionIds[25] = new highlightPair ("Creative_Benchmarking" , "creativebenchmarking" )

var strCurrentSection = ""
var strSectionId = "Home";


function highlightPair (strUrlId , strPageId)
{
  this.strUrlId = strUrlId
  this.strPageId = strPageId
}

//////////////////////////////////////////////////////////
// innitiated on page load
function setUp()
{
  highlightSection()
}

//////////////////////////////////////////////////////////
// drives highlight state
function highlightSection()
{
  if (document.getElementById)
  {
    var intPos = 0
    var strSection = strSectionId
    strSection = strSection.toLowerCase()
    for (var i=0;i<arrSectionIds.length;i++)
    {
//      alert (arrSectionIds[i].strUrlId + " : " + strSection)
      if (arrSectionIds[i].strUrlId.toLowerCase() ==  strSection)
      {
		if (document.getElementById(arrSectionIds[i].strPageId))
		{
	    var strOldImgName = new String (document.getElementById(arrSectionIds[i].strPageId).src);
	    var strNewImgName = strOldImgName.substring( 0, strOldImgName.lastIndexOf("_")+1) + "2.gif";
	    document.getElementById(arrSectionIds[i].strPageId).src = strNewImgName;
	    strCurrentSection = arrSectionIds[i].strPageId;
	    }
      }
    }
  }
}


//////////////////////////////////////////////////////////
// drives Rollovers in navigation elements
// objLeftNavItem = reference to navigation item
// strAction = announces action, (on | off)
function navigationRollover(objLeftNavItem , strAction)
{
  var strTargetGif = "0.gif"
  if (strAction == "on")
  {
    strTargetGif = "1.gif?new"
  }

  if ((objLeftNavItem.firstChild.id == strCurrentSection) && (strAction == "off"))
  {
    strTargetGif = "2.gif?new"
  }
  var strOldImgName = new String (objLeftNavItem.firstChild.src)
  var strNewImgName = strOldImgName.substring( 0, strOldImgName.lastIndexOf("_")+1) + strTargetGif
  objLeftNavItem.firstChild.src = strNewImgName
}


//////////////////////////////////////////////////////////
  // drives Rollovers in body elements
  // objBodyItem = reference to body item
  // strAction = announces action, (on | off)
  function bodyRollover(objBodyItem , strAction)
  {
	  var strTargetGif = "off.gif"
	  if (strAction == "on")
	  {
	    strTargetGif = "on.gif"
	  }
	  var strOldImgName = new String (objBodyItem.firstChild.src)
	  var strNewImgName = strOldImgName.substring( 0, strOldImgName.lastIndexOf("_")+1) + strTargetGif
	  objBodyItem.firstChild.src = strNewImgName
  }

//////////////////////////////////////////////////////////
  // drives Rollovers in form button elements
  function mouse_over(oSrc)
  {
  if((oSrc.src.indexOf("_on") != -1)||(oSrc.src.indexOf("_off") == -1))
   return(false);
  oSrc.src = oSrc.src.substring(0, oSrc.src.indexOf("_off")) + "_on" +
       oSrc.src.substring(oSrc.src.lastIndexOf("."), oSrc.src.length);
  }

 function mouse_out(oSrc)
  {
  if((oSrc.src.indexOf("_off") != -1)||(oSrc.src.indexOf("_on") == -1))
   return(false);
  oSrc.src = oSrc.src.substring(0, oSrc.src.indexOf("_on")) + "_off" +
       oSrc.src.substring(oSrc.src.lastIndexOf("."), oSrc.src.length);
  }


//////////////////////////////////////////////////////////
// tests browser for print functionality - prints appropriate result
function buildPrintButton()
{
  var strHTML = ""
  if (window.print)
  {
    strHTML = '<a href="javascript:window.print()">Print this page</a>'
  }
  else
  {
    strHTML = "Use your browser's print button to print this page"
  }
  document.write(strHTML)
}

//////////////////////////////////////////////////////////
// auto checks checkboxes when 'driving' checkbox is checkd
// strGroupId = ids group to be checked
function gallerySearchGroup(strGroupId, boxClicked) {
	if (document.getElementsByTagName) {
		objCheckBoxCollection = document.getElementsByTagName("input");
		for (var i=0;i<objCheckBoxCollection.length;i++) {
			if (objCheckBoxCollection[i].type == "checkbox" && objCheckBoxCollection[i].id == strGroupId) {
				if (boxClicked.checked) objCheckBoxCollection[i].checked = true;
				else objCheckBoxCollection[i].checked = false;
			}
		}
	}
}
//////////////////////////////////////////////////////////
// auto checks checkboxes when 'driving' checkbox is checkd
// strGroupId = ids group to be checked
function gallerySearchGroupByName(strGroupId, boxClicked) {
	if (document.getElementsByTagName) {
		objCheckBoxCollection = document.getElementsByTagName("input");
		for (var i=0;i<objCheckBoxCollection.length;i++) {
			if (objCheckBoxCollection[i].type == "checkbox" && objCheckBoxCollection[i].name == strGroupId) {
				if (boxClicked.checked) objCheckBoxCollection[i].checked = true;
				else objCheckBoxCollection[i].checked = false;
			}
		}
	}
}

//////////////////////////////////////////////////////////
// When an "all" is clicked, all the items are marked as checked
// strGroupId = ids group to be checked
function gallerySearchGroupAllClick(strGroupId, boxClicked) {
	if (document.getElementsByTagName) {
		objCheckBoxCollection = document.getElementsByTagName("input");
		for (var i=0;i<objCheckBoxCollection.length;i++) {
			if (objCheckBoxCollection[i].type == "checkbox" && objCheckBoxCollection[i].name == strGroupId) {
				if (boxClicked.checked) objCheckBoxCollection[i].checked = true;
				else  objCheckBoxCollection[i].checked = false;
			}
		}
	}
}

//////////////////////////////////////////////////////////
// When an "item" is clicked, the "all" is unchecked if any of the items are unchecked
// strGroupId = ids group to be checked
function gallerySearchGroupItemClick(strGroupId, boxClicked) {
	if (document.getElementsByTagName) {
		objCheckBoxCollection = document.getElementsByTagName("input");
		var itemIsUnchecked = false;
		var allBox = null;
		for (var i=0;i<objCheckBoxCollection.length;i++) {
			if (objCheckBoxCollection[i].type == "checkbox" && objCheckBoxCollection[i].name == strGroupId) {
				if( objCheckBoxCollection[i].value == -1 ) {
					allBox = objCheckBoxCollection[i];
				} else if( objCheckBoxCollection[i].checked == false ) {
					itemIsUnchecked = true;
				}
			}
		}
		if( allBox != null ) {
			if( itemIsUnchecked ) {
				allBox.checked = false;
			} else {
				allBox.checked = true;
			}
		}
	}
}

// form validation
//////////////////////////////////////////////////////////
// simple check for empty input on keyword form - creative advanced search
// objForm = form
// returns (true | false)
function validateKeyword(objForm)
{
  var blnIsValid
  if (objForm.keyword.value == "")
  {
    blnIsValid = false
    alert ("Please enter at least one keyword")
  }
  else
  {
    blnIsValid = true
  }
  objForm.action.value="keyword";
  return (blnIsValid)
}

// form validation
//////////////////////////////////////////////////////////
// simple check for empty input on keyword when searching same results
// objForm = form
// returns (true | false)
function validateSearchTheseResults(objForm)
{
  var blnIsValid
  if (objForm.searchTheseResults.value == "")
  {
    blnIsValid = false
    alert ("Please enter at least one keyword")
  }
  else
  {
    blnIsValid = true
  }
  objForm.action.value="keyword";
  return (blnIsValid)
}

//////////////////////////////////////////////////////////
// simple check for empty input on keyword form - creative advanced search
// objForm = form
// returns (true | false)
function validateAdvertiser(objForm)
{
  var blnIsValid
  if ( objForm.selectedAdvertisers.selectedIndex == 0 )
  {
    blnIsValid = false
    alert ("Please select an advertiser")
  }
  else
  {
    blnIsValid = true
  }
  return (blnIsValid)
}

//////////////////////////////////////////////////////////
// validation for checkboxes on Creative Search page (author: J Packer)
function validateCreativeCheckboxes(objForm) {
	for (var i=0;i<objForm.elements.length;i++) {
		if ( objForm.elements[i].type == "checkbox") {
			if ( objForm.elements[i].checked == true ) return true;
		}
	}
	alert ("Please select at least one criteria for your search");
	return false;
}

//////////////////////////////////////////////////////////
// simple check for empty input on criteria form
// objForm = form
// returns (true | false)
function validateCriteria(objForm)
{
  var blnIsValid
  var blnAtLeastOneChecked = false
  for (var i=0;i<objForm.length;i++)
  {
    if ( objForm[i].type == "checkbox" && objForm[i].name == "selectedCategories" )
    {
      if ( objForm[i].checked == true )
      {
        blnAtLeastOneChecked = true
      }
    }
  }
  if (blnAtLeastOneChecked)
  {
    blnIsValid = true
  }
  else
  {
    blnIsValid = false
    alert ("Please select at least one catagory")
  }
  return (blnIsValid)
}

//////////////////////////////////////////////////////////
// simple check for empty input on newspaper form
// objForm = form
// returns (true | false)
function validateNewspapers(objForm)
{
  var blnIsValid
  var blnAtLeastOneChecked = false
  for (var i=0;i<objForm.length;i++)
  {
    if ( objForm[i].type == "checkbox" && objForm[i].name == "selectedNewspapers" )
    {
      if ( objForm[i].checked == true )
      {
        blnAtLeastOneChecked = true
      }
    }
  }
  if (blnAtLeastOneChecked)
  {
    blnIsValid = true
  }
  else
  {
    blnIsValid = false
    alert ("Please select at least one Newspaper")
  }
  return (blnIsValid)
}

//////////////////////////////////////////////////////////
// simple check for null dropdown - cuom_advancedserach.stm
// objForm = form
// returns (true | false)
function validateNewspaper(objForm)
{
  var blnIsValid
  if ( objForm.newspaper.selectedIndex == 0 )
  {
    blnIsValid = false
    alert ("Please select a newspaper")
  }
  else
  {
    blnIsValid = true
  }
  objForm.action.value="newspaper";
  return (blnIsValid)
}

//////////////////////////////////////////////////////////
// simple check for null dropdown - creative_advancedsearch_results.stm
// objForm = form
// returns (true | false)
function validateCreativeSearch(objForm)
{

  var blnIsValid = false
  if ( objForm.selectedCategories.selectedIndex != 0 )
  {
    blnIsValid = true
  }
  var blnAtLeastOneChecked = false
  for (var i=0;i<objForm.length;i++)
  {
    if ( objForm[i].type == "checkbox" && objForm[i].name == "category" )
    {
      if ( objForm[i].checked == true )
      {
        blnAtLeastOneChecked = true
      }
    }
  }
  if (blnAtLeastOneChecked)
  {
    blnIsValid = true
  }
  if (!blnIsValid)
  {
    alert ("Please select at least one catagory")
  }
  return (blnIsValid)
}

//////////////////////////////////////////////////////////
// validates email
// objForm = form
// returns (true | false)
function validateEmail(objForm)
{
  var blnIsValid = true
  if (objForm.email.value == "")
  {
    blnIsValid = false
    alert ("Please enter your email address")
  }
  else
  {
    var strEmail = objForm.email.value
    if ( (strEmail.indexOf("@") == -1) || (strEmail.indexOf(".") == -1) )
    {
        blnIsValid = false
        alert ("Please enter a valid email address")
    }
  }
  return (blnIsValid)
}

//////////////////////////////////////////////////////////
// validates registration
// objForm = form
// returns (true | false)
function validateRegistration(objForm)
{
  var blnIsValid = true
  var strMsg = ""
  // email
  if (objForm.email.value == "")
  {
    blnIsValid = false
    strMsg += "your email address" + "\n"
  }
  else
  {
    var strEmail = objForm.email.value
    if ( (strEmail.indexOf("@") == -1) || (strEmail.indexOf(".") == -1) )
    {
        blnIsValid = false
        strMsg += "a valid email address" + "\n"
    }
  }
  //  BZ-5443 - only email address is to be mandatory
  
  // first name
  //if (objForm.firstname.value == "")
  //{
  //  blnIsValid = false
  //  strMsg += "your first name" + "\n"
  //}

  // last name
  //if (objForm.surname.value == "")
  //{
  //  blnIsValid = false
  //  strMsg += "your last name" + "\n"
  //}

  // company
  //if (objForm.companyname.value == "")
  //{
  //  blnIsValid = false
  //  strMsg += "your company name" + "\n"
  //} else if (objForm.companyname.value.length < 3) {
  //  blnIsValid = false
  //  strMsg += "a company name with at least 3 characters" + "\n"
  
  //}

  // company type
  //if (objForm.answers[0].selectedIndex == 0)
  //{
  //  blnIsValid = false
  //  strMsg += "the type of company" + "\n"
  //}

  // company role
  //if (objForm.answers[1].selectedIndex == 0)
  //{
  //  blnIsValid = false
  //  strMsg += "your role in your company" + "\n"
  //}
  
  

  // type of email

  if (strMsg != "")
  {
    strMsg = "Please enter: " + "\n\n" + strMsg
    alert (strMsg)
  }



  return (blnIsValid)
}

//////////////////////////////////////////////////////////
// validation from creative search landing page - form1
function validateGallery1(objForm)
{
  if (objForm.selectedCategories.selectedIndex == 0)
  {
    alert ("Please select at least one product")
    return false
  }
  else
  {
    return true
  }
}

//////////////////////////////////////////////////////////
// validation from creative search landing page - form2
function validateGallery2(objForm)
{
  if (objForm.selectedBestUseOf.selectedIndex == 0)
  {
    alert ("Please select at least one catagory")
    return false
  }
  else
  {
  return true
}
}

/////////////////////////////////////////////////////////////
// open window for annas search results image
function popUpAnnas(objLink)
{
  	URL = objLink.href
  	//alert(URL)
	this.window.name = "home";
	popupWin = window.open(URL, "ANNA", 'resizable=yes,scrollbars=yes,menubar=yes,location=yes,toolbar=yes,status=yes,width=650,height=500')
    popupWin.focus()
}

/////////////////////////////////////////////////////////////
// open window for enlarginf image
function popUpImage(objLink)
{
  URL = objLink.href
  alert (URL)
	this.window.name = "home";
	popupWin = window.open(URL, "popupimage", 'resizable=no,scrollbars=yes,menubar=no,location=no,toolbar=no,status=no,width=400,height=240')
  popupWin.focus()
}

function boxChecked(theCheckbox) {
	var numBoxes = eval("document.forms[1]." + theCheckbox.name + ".length;")
	if (theCheckbox.checked) {
		for (i=1;i<numBoxes;i++) {
			eval("document.forms[1]." + theCheckbox.name + "[i].checked = true");
		}
	}
	else {
		for (i=1;i<numBoxes;i++) {
			eval("document.forms[1]." + theCheckbox.name + "[i].checked = false");
		}
	}
}
// To clear value from text field
function clearText(theTextbox) {
	if (theTextbox.value == "SEARCH") {
		theTextbox.value="";
	}
}

// To add SEARCH to text field if it is blank
function searchText(theTextbox) {
	if (theTextbox.value == "") {
		theTextbox.value="SEARCH";
	}
}

// script for date on homepage header
var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var time = new Date();
var month = months[time.getMonth()];
var day = days[time.getDay()];
var date = time.getDate();
var year = time.getYear();
if (year < 2000) year = year + 1900;

// press releases window
function pressRelease(loc) {
	prWindow = window.open(loc, "pr_Window", "height=500,width=675,top=20,left=20,scrollbars=no,resizable=yes,status=yes,toolbar=no,menubar=no");
	if (window.focus) {setTimeout('prWindow.focus()',0)};
}

function imageWin(loc,w,h)
{
	var showScroll = "no";
	var screenH = screen.availHeight;
	var screenW = screen.availWidth;
	if (h > screenH - 100 || w > screenW - 100) showScroll = "yes";
	imageWindow = window.open( "/nma/static/imageWin.html?loc=" + loc + "&w=" + w + "&h=" + h, "image_Window", "height=300,width=300,top=20,left=20,scrollbars=" + showScroll + ",resizable=yes,status=yes,toolbar=no,menubar=no");
	if (window.focus) {setTimeout('imageWindow.focus()',0)};
}

// script for Add to Favorites link
var isMac = false;
if (navigator.platform.indexOf("Mac") != -1) { isMac = true; }

function addToFavorites() {
	if (isMac) { alert("Sorry, your browser does not support this function."); }
	else { window.external.AddFavorite('http://www.nmauk.co.uk','Newspaper Marketing Agency'); }
}
