function addLoadEvent(func)
{
	var oldonload = window.onload;
  	if (typeof window.onload != 'function')
	{
    	window.onload = func;
  	}
	else
	{
    	window.onload = function()
		{
      		oldonload();
      		func();
    	}
  	}
}


function HasClassName(objElement, strClass)
{
   if ( objElement.className )
   {
      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
      {
         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper ) { return true; }
      }

	}
   // if we got here then the class name is not there
   return false;
}


function AddClassName(objElement, strClass, blnMayAlreadyExist)
{
   // if there is a class
   if ( objElement.className )
   {
      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // if the new class name may already exist in list
      if ( blnMayAlreadyExist )
      {
         // get uppercase class for comparison purposes
         var strClassUpper = strClass.toUpperCase();

         // find all instances and remove them
         for ( var i = 0; i < arrList.length; i++ )
         {
            // if class found
            if ( arrList[i].toUpperCase() == strClassUpper )
            {
               // remove array item
               arrList.splice(i, 1);
               // decrement loop counter as we have adjusted the array's contents
               i--;
            }

		  }

		}

      // add the new class to end of list
      arrList[arrList.length] = strClass;

      // add the new class to beginning of list
      //arrList.splice(0, 0, strClass);
      
      // assign modified class name attribute
      objElement.className = arrList.join(' ');

   }
   // if there was no class
   else
   {
      // assign modified class name attribute      
      objElement.className = strClass;
    }

}



function RemoveClassName(objElement, strClass)
{
   // if there is a class
   if ( objElement.className )
   {
      // the classes are just a space separated list, so first get the list
      var arrList = objElement.className.split(' ');

      // get uppercase class for comparison purposes
      var strClassUpper = strClass.toUpperCase();

      // find all instances and remove them
      for ( var i = 0; i < arrList.length; i++ )
      {
         // if class found
         if ( arrList[i].toUpperCase() == strClassUpper )
         {
            // remove array item
            arrList.splice(i, 1);

            // decrement loop counter as we have adjusted the array's contents
            i--;

          }

      }

      // assign modified class name attribute
      objElement.className = arrList.join(' ');

   }
}



function prepareInputsForHints()
{

	var getspans,i;
 	getspans = document.getElementsByTagName('span');
 	for(i in getspans)
  	{
  		if(/information/.test(getspans[i].className))
   		{
			getspans[i].className = "popup";
   		}
  	}
	

	
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)
	{
		if (inputs[i].parentNode.getElementsByTagName("span")[0])
		{
		
					
			inputs[i].onfocus = function () { this.parentNode.getElementsByTagName("span")[0].style.display = "inline"; }
			inputs[i].onblur = function () { this.parentNode.getElementsByTagName("span")[0].style.display = "none"; }
		}
	}


	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++)
	{
		if (selects[k].parentNode.getElementsByTagName("span")[0])
		{
			selects[k].onfocus = function () { this.parentNode.getElementsByTagName("span")[0].style.display = "inline"; }
			selects[k].onblur = function () { this.parentNode.getElementsByTagName("span")[0].style.display = "none"; }
		}
	}
	
	document.getElementById("warning").className = "hidden";
}
addLoadEvent(prepareInputsForHints);



function prepareOthers()
{
	var formdls = document.getElementsByTagName('dl');
	for(var x=1; x<formdls.length; x++)
	{
		if (document.getElementById("showother"+[x]))
		{
			if (document.getElementById("showother"+[x]).value !== "show")
			{
				//document.getElementById("other"+[x]).innerHTML = "TEST";
				
				var getotherdts,i;
				//getotherdts = document.getElementsByTagName('dt');
				getotherdts = document.getElementById("other"+[x]).getElementsByTagName('dt');
				for(i in getotherdts)
				{
					if(/other/.test(getotherdts[i].className))
					{
						RemoveClassName(getotherdts[i], 'other')
						AddClassName(getotherdts[i], 'hidden', '')
					}
				}
				
				var getotherdds,i;
				//getotherdds = document.getElementsByTagName('dd');
				getotherdds = document.getElementById("other"+[x]).getElementsByTagName('dd');
				for(i in getotherdds)
				{
					if(/other/.test(getotherdds[i].className))
					{
						RemoveClassName(getotherdds[i], 'other')
						AddClassName(getotherdds[i], 'hidden', '')
					}
				}
			
				
			}
		}
	}
}
addLoadEvent(prepareOthers);


function showhidden(controlvalue,panel1,value1,panel2,value2)
{
	if (controlvalue == value1)
	{
		var gethiddendts,i;
		gethiddendts = document.getElementById(panel1).getElementsByTagName("dt");
		for(i in gethiddendts)
		{
			RemoveClassName(gethiddendts[i], 'hidden')
			AddClassName(gethiddendts[i], 'other', '')
		}
		
		var gethiddendds,i;
		gethiddendds = document.getElementById(panel1).getElementsByTagName("dd");
		for(i in gethiddendds)
		{	
			RemoveClassName(gethiddendds[i], 'hidden')
			AddClassName(gethiddendds[i], 'other', '')
		}
		
		document.getElementById("show"+panel1).value = "show";
	}
	else
	{
		var gethiddendts,i;
		gethiddendts = document.getElementById(panel1).getElementsByTagName("dt");
		for(i in gethiddendts)
		{
			RemoveClassName(gethiddendts[i], 'other')
			AddClassName(gethiddendts[i], 'hidden', '')
		}
		
		var gethiddendds,i;
		gethiddendds = document.getElementById(panel1).getElementsByTagName("dd");
		for(i in gethiddendds)
		{
			RemoveClassName(gethiddendds[i], 'other')
			AddClassName(gethiddendds[i], 'hidden', '')
		}
		
		document.getElementById("show"+panel1).value = "noshow";
	}
	
	if (panel2 != "" && value2 != "")
	{
		if (controlvalue == value2)
		{
			var gethiddendts,i;
			gethiddendts = document.getElementById(panel2).getElementsByTagName("dt");
			for(i in gethiddendts)
			{
				RemoveClassName(gethiddendts[i], 'hidden')
				AddClassName(gethiddendts[i], 'other', '')
			}
				
			var gethiddendds,i;
			gethiddendds = document.getElementById(panel2).getElementsByTagName("dd");
			for(i in gethiddendds)
			{	
				RemoveClassName(gethiddendds[i], 'hidden')
				AddClassName(gethiddendds[i], 'other', '')
			}
				
			document.getElementById("show"+panel2).value = "show";	
		}
		else
		{
			var gethiddendts,i;
			gethiddendts = document.getElementById(panel2).getElementsByTagName("dt");
			for(i in gethiddendts)
			{
				RemoveClassName(gethiddendts[i], 'other')
				AddClassName(gethiddendts[i], 'hidden', '')
			}
			
			var gethiddendds,i;
			gethiddendds = document.getElementById(panel2).getElementsByTagName("dd");
			for(i in gethiddendds)
			{
				RemoveClassName(gethiddendds[i], 'other')
				AddClassName(gethiddendds[i], 'hidden', '')
			}
			
			document.getElementById("show"+panel2).value = "noshow";
		}
	}
}



function showloadingmessage()
{
	document.getElementById("warning").className = "";
	document.getElementById("warning").innerHTML = "<div id=\"processing\"><p>Processing your details, please wait...</p><p class=\"center\"><img src=\"/reeds/assets/templates/reed/img/loading.gif\" alt=\"\"/></p></div>";	
}