// Mac IE Float fix
// <!--
function fixmacie(classname){  
	/* I'm assuming the containers are div */  
	var divs=document.getElementsByTagName("DIV"); 

	/* Loop through all the div's */  
	for(var d=0; d < divs.length;d++){ 
		/* Compare class names and insert clearing div*/ 
		(divs[d].className==classname)?divs[d].innerHTML+= "<div class='cb'> </div>":""; 
	} 
} 

function init(){ 
	/* Check if the browser is IE5 Mac */  
	if( navigator.appVersion.indexOf('Mac')!=-1 && document.all){ 
		/* Pass the class name of the container to fixmacie */  
		fixmacie("floatcontainer"); 
	} 
}
// !-->
// End of Mac IE Float fix

// ----------------------------------------------------------------

// 'external' to '_blank' target fix
// <!--
function externalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") &&
        anchor.getAttribute("rel") == "external")
      anchor.target = "_blank";
    }
}
// -->
// End of 'external' to '_blank' target fix

// ----------------------------------------------------------------

// IE Background png fix
// <!--
function alphaBackgrounds(){
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
	for (i=0; i<document.all.length; i++){
		var bg = document.all[i].currentStyle.backgroundImage;
		if (itsAllGood && bg){
			if (bg.match(/\.png/i) != null){
				var mypng = bg.substring(5,bg.length-2);
				document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='image')";
				document.all[i].style.backgroundImage = "url(/images/interface/blank.gif)";
			}
		}
	}
}
// -->
// End of IE Background png fix

// ----------------------------------------------------------------


// walsall menu
function checkState(path,link){  
	var listItem = document.getElementsByTagName("A");

	/* Loop through all the li's */  
	for(var li=0; li < listItem.length;li++){ 
		/* Compare class names and insert clearing div*/ 
		var thisA = listItem[li];

		if(path == thisA.href || link == thisA.href){
			// Dont change style for left-column research module or press-centre module
			if(thisA.href.indexOf('/text_size/larger') == -1 || (thisA.href.indexOf('/text_size/larger') >= 0 && thisA.id != 'text-plus_logo')){
				if(thisA.href.indexOf('/text_size/smaller') == -1 || (thisA.href.indexOf('/text_size/smaller') >= 0 && thisA.id != 'text-minus_logo')){
					thisA.style.display = 'block';
					thisA.style.background = '#DD0909 url(/images/interface/nav_minus.gif) no-repeat left center';
					thisA.style.fontWeight = 'bold';
					thisA.style.color = '#FFFFFF';
					thisA.style.marginLeft = '-16px';
					thisA.style.paddingLeft = '18px';
				}
			}
		}
	} 
}


// Fire all events onload
function multipleOnload(){
	init();
	externalLinks();
	// Fix for pc ie transparent bg's
	if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
		alphaBackgrounds();
	}
}
function getCssElement(changeSize)
{
   //alert('scott');
	var dis = '';
	if(document.styleSheets[0].rules)
	{
      	rules = document.styleSheets[0].rules
      	//alert("ie " + rules.length);	
	}
    else if(document.styleSheets[0].cssRules)
    {
		rules = document.styleSheets[0].cssRules
      	//alert("mz " + rules.length);
	}
	currentSize = getTextSize();
	//alert(changeSize);
	//alert('current '+currentSize);
   
    suc = 'FALSE';
   	if((changeSize == 'plus') && ((parseFloat(currentSize) +0.1) < 1.79 ))
   	{
    	size = makeFontBigger(currentSize);
    	suc = 'TRUE';
   	}
   	else if((changeSize == 'minus') && (currentSize > 0.3))
   	{
    	size = makeFontSmaller (currentSize)
    	suc = 'TRUE';
   	}
    else 
    	alert('Text Size is already at its limit');
     if(suc == 'TRUE')
     {		
     	bodyRule = rules[1].style.cssText.toLowerCase();
		//alert('body rule is '+bodyRule);
		if(currentSize == '1.0')
		  currentSize = '1';
		find = "font-size: " + currentSize + "em;";
		newSize = "font-size: " + size + "em;";
		//alert ('find is '+find);
		testing = bodyRule.replace(find, newSize);
		//alert('test '+testing);
		rules[1].style.cssText = testing;
		Set_Cookie( 'childrenInWasall', currentSize, 365, "/", "", "") 
      }
}

function getTextSize()
{
  var ts = document.getElementById('textSize').value;
  return ts;	
}

function setTextSize(ts)
{
   document.getElementById('textSize').value = ts;
   //alert('dummy ' + ts);
}

function makeFontBigger (ts)
{
	bigger = parseFloat(ts) + 0.1;
	big = bigger.toFixed(1);
	//alert('b '+big);
	setTextSize(big);
	return big;
}

function makeFontSmaller (ts) {
  smaller = parseFloat(ts) - 0.1;
  small = smaller.toFixed(1);
  //alert('s '+small);
  setTextSize(small);
  return small;
}

function fontSizeCheck()
{
	if(Get_Cookie( 'childrenInWasall' ))
	{
	  size = Get_Cookie( 'childrenInWasall' )
	  //alert(size);
		if(document.styleSheets[0].rules)
		{
	      	rules = document.styleSheets[0].rules
	      	//alert("ie " + rules.length);	
		}
	    else if(document.styleSheets[0].cssRules)
	    {
			rules = document.styleSheets[0].cssRules
	      	//alert("mz " + rules.length);
		}
		currentSize = getTextSize();
		bodyRule = rules[1].style.cssText.toLowerCase();
		//alert('body rule is '+bodyRule);
		if(currentSize == '1.0')
		  currentSize = '1';
		find = "font-size: " + currentSize + "em;";
		newSize = "font-size: " + size + "em;";
		//alert ('find is '+find);
		testing = bodyRule.replace(find, newSize);
		//alert('test '+testing);
		rules[1].style.cssText = testing;
	}
}
function setFocus(elem)
{
   if(document.getElementById(elem))
      document.getElementById(elem).focus();	
}


function formCheck(formName)
{
 
	sub = true;
	required=document.getElementById('requiredList').value.split(':');
    for(x=0; x<required.length; x++)
    {
       	if(document.getElementById(required[x]).value == '')
       	{
       	   sub = false;
       	   setFocus(required[x]);
       	   alert(document.getElementById(required[x]).name +" is required");
       	   x = required.length;	
       	}
    }
    if(sub)
      document.forms[formName].submit();
    
}