// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	
		el.style.display = 'block';
		
		
	} else {
				
		el.style.display = 'none';
		
		if (div_id != 'blanket'){
			el.style.width = 'auto';
		}//end if
	}//end if
}

function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}//end if
	
	var scrollTop = getScrollY();
	
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight + scrollTop;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight + scrollTop;
		} else {
			blanket_height = document.body.parentNode.scrollHeight + scrollTop;
		}//end if
	}//end if
	
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_top = scrollTop + 150;
	
	popUpDiv.style.top = popUpDiv_top + 'px';	
	
	var popup = document.getElementById(popUpDivVar)
	
	//Ajust the blanket size for a really large popup
	if (popup.style.display == "none"){
		popup.style.display="block";
		
		if ( (blanket_height) < (popup.offsetHeight + popUpDiv_top) ){
			
			blanket_height = popup.offsetHeight + popUpDiv_top + 100;
			blanket.style.height = blanket_height + 'px';
		}//end if
						
		popup.style.display="none";
	}//end if
}

function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}//end if
	
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}//end if
	}//end if
	
	var popUpDiv = document.getElementById(popUpDivVar);
	
		
		
	
	if (popUpDiv.style.display == "none") {
		popUpDiv.style.display = "block";
		
		popUpDiv.style.width = get_widest_element(popUpDiv) + 'px';//set width on the fly b/c IE sucks and "max-width:auto" does not work
		
		var popup_width = popUpDiv.clientWidth;
		window_width=window_width/2 - (popup_width/2);
		popUpDiv.style.left = window_width + 'px';
		popUpDiv.style.display = "none";				
	}//end if	
}

function popup(windowname) {	
	
	window_pos(windowname);
	blanket_size(windowname);	
	toggle('blanket');
	toggle(windowname);		
}




/*
 * Find scrollTop regardless of browser
 */
function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;    
  } else if( document.body && document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;    
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;    
  }//end if
  return scrOfY;
}


//Used to find the widest TABLE and/or DIV element in the popup.
//We use this width to set the width of the popup on the fly.
//We do it this way instead of (simply doing it in CSS) b/c IE sucks and there were browser issues.
function get_widest_element(el){

	var max_width = 0;
	
	var allTableElements = el.getElementsByTagName("table");
	
	for (var i = 0; i < allTableElements.length; i++) {
		
		if (allTableElements[i].offsetWidth > max_width){
			max_width = allTableElements[i].offsetWidth
			
			if (max_width > 900){//900 pixels MAX
				max_width = 900;
			}
			//alert(max_width);
		}//end if				
	}//end for
	
	var allDivElements = el.getElementsByTagName("div");
	
	for (var i = 0; i < allDivElements.length; i++) {
		
		if (allDivElements[i].offsetWidth > max_width && i != 0){//IE Fix. Skip first DIV
			max_width = allDivElements[i].offsetWidth

			if (max_width > 900){//900 pixels MAX
				max_width = 900;
			}
			//alert(max_width);
		}//end if				
	}//end for
	
	//400 pixels MIN
	if (max_width < 300){
		max_width = 300;
	}//end if
	
	return max_width;
}





/*
 * Used by:	Prescreen Question Templates
 * 			Demographic Question Templates
 * 			Employment Processes
 * 			Candidate Sources
 */
function setBucketList() {		
		
		var yui_bucket 		= document.getElementById("yui_bucket");
		var allSpanElements = yui_bucket.getElementsByTagName("span");
		
		var list = "";
		
		for (var i = 0; i < allSpanElements.length; i++) {
			list += allSpanElements[i].getAttribute("value") + ","
		}//end for	
		list = list.substring(0, list.length-1);
		document.forms[0].bucket_list.value = list;				
}




/*

function show_menu_dopdown(el){
	
	var t = el.getElementsByTagName("table");
	
	
	if (t[0].style.display != "block"){
		ShowEffect(t[0]);	
	}
	
	t[0].style.display = "block";
}

function ShowEffect(element){
       new Effect.Appear(element, 	{	duration:0.5, 
	   									from:0, 
										to:1.0, 
										afterFinish: function(){
														element.style.display = "block";
													}
									});
	   
}


function HideEffect(element){
       new Effect.Appear(element,	{	duration:0.5, 
	   									from:1.0, 
										to:0,
										delay: 1,
										afterFinish: function(){
														element.style.display = "none";
													}
									});
}



function hide_menu_dopdown(el){
	
	//var t = el.getElementsByTagName("table");
	//t[0].style.display = "none";

	if (el.style.display == "block"){
		//HideEffect(el);
		el.style.display = "none";
	}
	
}
*/