 
//trying to write a script that allows a radio buttons child questions to be hidden/shown.  It should show the .child div of the radio button if it's not already showing. OnbLur, HIDE the child DIV but ONLY hide it if the next click was onto another radio button within this particular Array (the array formed by a group of radios with same name). The reason why is becuz a user may have moved on to the next question and did not deselect the parent radio of the .child div. in that case, the .child div should remain viewable on the screen. right now, for temporary purposes, i just burned in a onClick=effect.blindUp event into all the other radios in the array; not ideal; Dont forget that onload, we need to reset radios correctly due to browser helper/cache issues.
 function toggleChildOfRadio(obj2,idOfThing2) { 
 	theChild=document.getElementById(idOfThing2);  
 	if (obj2.checked) {
		
		if (theChild.style.display=='none') {
         	Effect.BlindDown(theChild, {duration: 1.5}); 
         	new Effect.Highlight(theChild, {delay:1.5,duration: 3, startcolor:'#effbdb'}); 
			}
			
			
		}
		
		else
		{
		Effect.BlindUp(theChild, {duration: 1.5}); 
		}
 }
 
 //show error
function showError(thing) {
	Effect.Grow(thing, {duration:1.5, direction:'top-left'}); 
	//new Effect.Highlight(thing, {duration: 1, delay:1.5, startcolor:'#f2bdbd'});
 
}
 
 	//radio sets use this to allow the radio options without children to control the child of the option with the children
  function hideIfNotHidden(thebranch) { 
 	branch=document.getElementById(thebranch);  
 	 
		
	if (branch.style.display!='none') {
         Effect.BlindUp(branch); 
		}
		 
 	}
	
 


//wuffo scripts for UI started below. removed calendar stuff.

addEvent(window, 'load', initForm);

var highlight_array = new Array();
 function initForm(){
	checkPaypal();  
	initializeFocus();
}

function checkPaypal() {
	if(document.getElementById('merchant')) {
		document.getElementById('merchantMessage').innerHTML = 'Your order is being processed. Please wait while the page redirects to the merchant checkout.';
		document.getElementById('merchantButton').style.display = 'none';
		document.getElementById('merchant').submit();
	}
}
 

// for radio and checkboxes, they have to be cleared manually, so they are added to the
// global array highlight_array so we dont have to loop through the dom every time.
function initializeFocus(){
	fields = getElementsByClassName(document, "*", "field");
	for(i = 0; i < fields.length; i++) {
		if(fields[i].type == 'radio' || fields[i].type == 'checkbox' || fields[i].type == 'file') {
			fields[i].onclick = function(){clearSafariRadios(); addClassName(this.parentNode.parentNode, "focused", true)};
			fields[i].onfocus = function(){clearSafariRadios(); addClassName(this.parentNode.parentNode, "focused", true)};
			highlight_array.splice(highlight_array.length,0,fields[i]);
		}
		else {
			fields[i].onfocus = function(){clearSafariRadios();addClassName(this.parentNode.parentNode, "focused", true)};
			fields[i].onblur = function(){removeClassName(this.parentNode.parentNode, "focused")};
		}
	}
}

function clearSafariRadios() {
	for(var i = 0; i < highlight_array.length; i++) {
		if(highlight_array[i].parentNode) {
			removeClassName(highlight_array[i].parentNode.parentNode, 'focused');
		}
	}
}
 

/*--------------------------------------------------------------------------*/

//http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/
function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return (arrReturnElements)
}

//http://www.bigbold.com/snippets/posts/show/2630
function addClassName(objElement, strClass, blnMayAlreadyExist){
   if ( objElement.className ){
      var arrList = objElement.className.split(' ');
      if ( blnMayAlreadyExist ){
         var strClassUpper = strClass.toUpperCase();
         for ( var i = 0; i < arrList.length; i++ ){
            if ( arrList[i].toUpperCase() == strClassUpper ){
               arrList.splice(i, 1);
               i--;
             }
           }
      }
      arrList[arrList.length] = strClass;
      objElement.className = arrList.join(' ');
   }
   else{  
      objElement.className = strClass;
      }
}

//http://www.bigbold.com/snippets/posts/show/2630
function removeClassName(objElement, strClass){
   if ( objElement.className ){
      var arrList = objElement.className.split(' ');
      var strClassUpper = strClass.toUpperCase();
      for ( var i = 0; i < arrList.length; i++ ){
         if ( arrList[i].toUpperCase() == strClassUpper ){
            arrList.splice(i, 1);
            i--;
         }
      }
      objElement.className = arrList.join(' ');
   }
}

//http://ejohn.org/projects/flexible-javascript-events/
function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() { obj["e"+type+fn]( window.event ) };
    obj.attachEvent( "on"+type, obj[type+fn] );
  } 
  else{
    obj.addEventListener( type, fn, false );	
  }
} 

 

