// JavaScript Document

///////////////////////////////////////
// Toggles visibility via diplay style.
    function toggle_visibility(id,imgEl) {
       var e = document.getElementById(id);
	   var eImage = document.getElementById(imgEl);
	   
       if(e.style.display == 'block')
          {
		  e.style.display = 'none';	  
		  eImage.src = '/resources/dojoroot/dijit/themes/tundra/images/treeExpand_plus.gif';
		  }
       else
	   	{
          e.style.display = 'block';
		  eImage.src = '/resources/dojoroot/dijit/themes/tundra/images/treeExpand_minus.gif';
		}
    }

///////////////////////////////////////////////////
// Used in the forms to disable unavailable options
	
	function disable_functionality(elem) {
		var x = document.getElementById(elem);
		if(x.style.display == 'block')
		x.style.display = 'none';
		document.contactform.BulletinAreas.disabled = true;
		
		}
		
	function enable_functionality(elem) {
		var x = document.getElementById(elem);
		if(document.contactform.BulletinAreas.checked == true)
		x.style.display = 'block';
		document.contactform.BulletinAreas.disabled = false;
		}
		
////////////////////////////////////////////////////
// Used in the search to pull the entered field value of search into the form action href

function doSearch( ) {
 form = document.forms.sitesearch;
 if( form.Search.value != "") {
  window.location.href = "/sitesearch/search.action?query=" + form.Search.value;
 }
}

////////////////////////////////////////////////////
// CONTACT FORM VALIDATION

function validateForm() 
{
 var okSoFar=true
 with (document.contactform)
 {
  var foundAt = required_email.value.indexOf("@",0)
  if (required_prefix.value=="" && okSoFar)
  {
    okSoFar=false
    alert("A salutation other than NONE is required.")
    required_prefix.focus()
  }
  if (required_first.value=="" && okSoFar)
  {
    okSoFar=false
    alert("A first name is required.")
    required_first.focus()
  }
  if (required_last.value=="" && okSoFar)
  {
    okSoFar=false
    alert("A last name is required.")
    required_last.focus()
  }
  if (required_address.value=="" && okSoFar)
  {
    okSoFar=false
    alert("An address is required.")
    required_address.focus()
  }
  if (required_city.value=="" && okSoFar)
  {
    okSoFar=false
    alert("A city is required.")
    required_city.focus()
  }
 
  if (required_pcode5.value=="" && okSoFar)
  {
    okSoFar=false
    alert("A postcode is required.")
    required_pcode5.focus()
  }
  if (foundAt < 1 && okSoFar)
  {
    okSoFar = false
    alert ("Please enter a valid email address.")
    required_email.focus()
  }
  if (required_subject.value=="" && okSoFar)
  {
    okSoFar=false
    alert("Please enter the subject.")
    required_subject.focus()
  }
  if (required_message.value=="" && okSoFar)
  {
    okSoFar=false
    alert("Please enter the details for your message.")
    required_message.focus()
  }
  if (okSoFar==true)  submit();
 }
}
////////////////////////////////////////////////////
// GENERIC ALERT SCRIPT
function alertMe(msg)
{
alert(msg);
}

////////////////////////////////////////////////////
// CHECK FOR A COOKIE
function loggedincheck ( cookie_name1, cookie_name2 )
{

  var results1 = document.cookie.match ( '(^|;) ?' + cookie_name1 + '=([^;]*)(;|$)' );
  var results2 = document.cookie.match ( '(^|;) ?' + cookie_name2 + '=([^;]*)(;|$)' );

  if ( results1 || results2 )
    {
		document.write("<ul><li><a href='/about/index.html' title='About DDS'>About</a></li><li><a href='/contact/index.html' title='Contact DDS'>Contact</a></li><li><a href='/careers/index.html' title='Careers at DDS'>Careers</a></li><li id='select'><select name='country selector' id='countryselector' onchange=\"JumpMenu('parent',this,0)\"><option value='' selected='selected'>Choose site - UK</option><option value='http://www.donovandata.com/'>Choose site - US</option><option value='http://www.ddscanada.com/'>Choose site - CA</option><option value='http://www.dds.de/'>Choose site - DE</option><option value='http://www.dds.ie/'>Choose site - IE</option><option value='http://www.dds.fr'>Choose site - FR</option></select></li></ul><ul id='loggedin'><li id='loggedinleft'><a href='/secure/logout.action'>Logout</a></li><li><a href='/secure/openpage.action?pageType=my-dds&key=My-DDS-5DD0D3'>Return to My DDS</a></li></ul>");
		isHomepage();
	}
  else
   document.write("<ul><li><a href='/about/index.html' title='About DDS'>About</a></li><li><a href='/contact/index.html' title='Contact DDS'>Contact</a></li><li><a href='/careers/index.html' title='Careers at DDS'>Careers</a></li><li><a href='/secure/openpage.action?pageType=my-dds&amp;key=My-DDS-5DD0D3'>Login</a></li><li><select name='country selector' id='countryselector' onchange=\"JumpMenu('parent',this,0)\"><option value='' selected='selected'>Choose site - UK</option><option value='http://www.donovandata.com/'>Choose site - US</option><option value='http://www.ddscanada.com/'>Choose site - CA</option><option value='http://www.dds.de/'>Choose site - DE</option><option value='http://www.dds.ie/'>Choose site - IE</option><option value='http://www.dds.fr'>Choose site - FR</option></select></li></ul>");
}
////////////////////////////////////////////////////
// JUMP MENU
function JumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
}

////////////////////////////////////////////////////
// GENERIC FIELD VALIDATION AND ERROR MESSAGE
function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}

////////////////////////////////////////////////////
// Format date acording to browser locale settings
function formatDate( date_str ) { d = dojo.date.stamp.fromISOString(date_str);
document.write( dojo.date.locale.format(d, {selector: "date", formatLength: "short"} ) );
}

////////////////////////////////////////////////////
// Get url path, compare to index.html, if matched redirect to mydds, else nothing
function isHomepage() {
	var thisDomain = (window.location.protocol + "//" + window.location.host );
	if(window.location.href == thisDomain + '/index.html' || window.location.href == thisDomain + '/')
	  { 
	  window.location = thisDomain + "/mydds"
	  }
}

////////////////////////////////////////////////////
// Clear persistent login cookie from logout page
/*function blankOutCookie() {
	expireDate = new Date();
	y1 = expireDate.getYear();

	if (y1 < 200)
	{
	y1 = y1 + 1900;
	}
	expireDate.setYear(y1);
	e1 = ";expires=" + expireDate.toGMTString();
	
	path=";path=/";
	document.cookie = "DDSPersistentLoginCookie=" + e1 + path;
	
	path = ";path=/sitesearch";
	document.cookie = "JSESSIONID=" + e1 + path;
	
	path = ";path=/secure";
	document.cookie = "JSESSIONID=" + e1 + path;
	
	path = ";path=/login";
	document.cookie = "JSESSIONID=" + e1 + path;

}*/