// Netscrape 4
if (document.layers) {var NN4 = true;}
// var NN4 = (document.layers) ? true : false

// IE
if (document.all) {var IE = true;}
// var IE = (document.all) ? true : false

// DOM
if (document.getElementById && !document.all) {var DOM = true;}
// var DOM = (document.getElementById && !document.all) ? true : false

function getElement(id){
	
		if(NN4) {
			path = document.layers[id]
		} else if(IE) {
			path = document.all[id]
		} else {
			path = document.getElementById(id)
		} 
		//return the path to the css layer depending upon the browser type
		return path; 
}

function MGC_swapImgRestore() { //v3.0
	var i,x,a=document.MGC_sr; 
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MGC_winOpenChildCentered(sURL,sWinName,sFeatures,nChildWidth,nChildHeight){
	// simply omit the top and left attributes from sFeatures to open the child window
	// centered on it's parent
	var nParentLeft = 0, nParentTop = 0; // default parent position
	var nParentHeight = 480, nParentWidth = 640; // default parent window size
	var bAppendTop = 1, bAppendLeft = 1, bAppendWidth = 1, bAppendHeight = 1;
	
	if (! sWinName || sWinName.length < 1){
		sWinName = "popup";			
	}
	
	if (! nChildWidth || nChildWidth < 1){
		nChildWidth = 300;			
	}
	if (! nChildHeight || nChildWidth < 1){
		nChildHeight = 200;			
	}
	if (! sFeatures || sFeatures.length < 1){
		sFeatures = "toolbar=0,resizable=1,scrollbars=1,directories=0,status=0,menubar=0";			
	}
	if (sFeatures.indexOf("top=") >= 0){
		bAppendTop = 0;
	}
	if (sFeatures.indexOf("left=") >= 0){
		bAppendLeft = 0;
	}
	if (sFeatures.indexOf("width=") >= 0){
		bAppendWidth = 0;
	}
	if (sFeatures.indexOf("height=") >= 0){
		bAppendHeight = 0;
	}
	
	// lowest common denominator
	if (window.innerWidth && window.innerHeight){ 
		nParentWidth = window.innerWidth; 
		nParentHeight = window.innerHeight; 
	} 
	// more accurate - IE5-
	if (document.body.clientWidth && document.body.clientHeight){ 
		nParentWidth = document.body.clientWidth; 
		nParentHeight = document.body.clientHeight; 
	} 
	// even more accurate - IE 6, Firefox with our doctype
	if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight){
		nParentWidth = document.documentElement.clientWidth; 
		nParentHeight = document.documentElement.clientHeight; 
	}
	
	if (window.screenX && window.screenY){
		nParentTop = window.screenY;
		nParentLeft = window.screenX;
	}

	if (window.screenLeft && window.screenTop){
		nParentTop = window.screenTop;
		nParentLeft = window.screenLeft;
	}
	
	var nParentCenterX =  Math.floor((nParentWidth / 2) + nParentLeft);
	var nParentCenterY =  Math.floor((nParentHeight / 2) + nParentTop);
	
	var nChildLeft = nParentCenterX - (nChildWidth / 2);
	var nChildTop = nParentCenterY - (nChildHeight / 2);
	
	if (bAppendWidth){
		sFeatures = sFeatures + ",width=" + nChildWidth;
	}
	if (bAppendHeight){
		sFeatures = sFeatures + ",height=" + nChildHeight;
	}
	if (bAppendTop){
		sFeatures = sFeatures + ",top=" + nChildTop;
	}
	if (bAppendLeft){
		sFeatures = sFeatures + ",left=" + nChildLeft;
	}
	
	winChild = MGC_winOpen(sURL,sWinName,sFeatures);
	//winChild.focus();

	//return winChild;
}


function MGC_winOpen(url, name, features) { 
	winChild = window.open(url, name, features);
	winChild.focus();
	return winChild;
}

function MGC_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MGC_p) d.MGC_p=new Array();
	var i,j=d.MGC_p.length,a=MGC_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("##")!=0){ d.MGC_p[j]=new Image; d.MGC_p[j++].src=a[i];}}
}

function MGC_findObj(n, d) { //v4.0
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MGC_findObj(n,d.layers[i].document);


	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MGC_swapImage() { //v3.0
	var i,j=0,x,a=MGC_swapImage.arguments; document.MGC_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MGC_findObj(a[i]))!=null){document.MGC_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function dropdownRedirect(whichform,whichfield){
	if (arguments.length > 0){
		if (arguments.length > 1){
			dropdown = document.forms[whichform].elements[whichfield];
		} else {
			dropdown = document.forms[whichform].elements["gotoURL"];
		}
	} else {
		dropdown = document.forms["navdropdown"].elements["gotoURL"];
	}
	
	var URL = dropdown.options[dropdown.selectedIndex].value;
	window.location.href = URL;
	return true;
}


function dynMenuArrow( bHideArrow )
{
	if( document.all.subitemselected )
	{
		if( bHideArrow )
			document.all.subitemselected.style.backgroundImage = 'url(/images/ui/white1x1.gif)';
		else
			document.all.subitemselected.style.backgroundImage = 'url(/images/ui/arrow.gif)';
	}		
}


function showHide(id,dispMode)
{
	 var elementObj = getElement(id); 
	 if (elementObj.style.display){
		 elementObj = elementObj.style;
	 }
	 if (elementObj.display){
		 if (dispMode){
			 elementObj.display = dispMode; 
		 } else {
			 if (elementObj.display == "none")
				{ 
					elementObj.display = "block"; 
				} 
			 else 
				{ 
					elementObj.display = "none"; 
				}
		 }
	 }
}

function hideSubmit(objForm, sButton, sMessage){
  // default message if one isn't passed in
  var message='Please wait...';
  
  // if a message was passed in, use it
  if(sMessage != undefined){
   message=sMessage;
  }
  
  // check for the given button in objForm
  if(objForm[sButton] != undefined) {
   // change the button's message/text
   objForm[sButton].value=message;
   // disable the button
   objForm[sButton].disabled=true;
  }
 }
 
function disableSubmit(thisForm){
	if (window.greySubmit){
		greySubmit(thisForm);
	}
	return true;
} 
 
 // Rollover  v2.0.1
// documentation: http://www.dithered.com/javascript/rollover/index.html
// license: http://creativecommons.org/licenses/by/1.0/
// code by Chris Nott (chris[at]dithered[dot]com)


function isDefined(property) {
  return (typeof property != 'undefined');
}

var rolloverInitialized = false;
function rolloverInit() {
   if (!rolloverInitialized && isDefined(document.images)) {
      
      // get all images (including all <input type="image">s)
      // use getElementsByTagName() if supported
      var images = new Array();
      if (isDefined(document.getElementsByTagName)) {
         images = document.getElementsByTagName('img');
         var inputs = document.getElementsByTagName('input');
         for (var i = 0; i < inputs.length; i++) {
            if (inputs[i].type == 'image') {
               images[images.length] = inputs[i];
            }
         }
      }
      
      // otherwise, use document.images and document.forms collections
      // remove if not supporting IE4, Opera 4-5
      else {
         images = document.images;
         inputs = new Array();
         for (var formIndex = 0; formIndex < document.forms.length; formIndex++) {
            for (var elementIndex = 0; elementIndex < document.forms.elements.length; elementIndex++) {
               if (isDefined(document.forms.elements[i].src)) {
                  inputs[inputs.length] = document.forms.elements[i];
               }
            }
         }
      }
      
      // get all images with '_off.' in src value
      for (var i = 0; i < images.length; i++) {
         if (images[i].src.indexOf('_off.') != -1) {
            var image = images[i];
            
            // store the off state filename in a property of the image object
            image.offImage = new Image();
            image.offImage.src = image.src;
            
            // store the on state filename in a property of the image object
            // (also preloads the on state image)
            image.onImage = new Image();
            image.onImage.imageElement = image;
            
            // add onmouseover and onmouseout event handlers once the on state image has loaded
            // Safari's onload is screwed up for off-screen images; temporary fix
            if (navigator.userAgent.toLowerCase().indexOf('safari') != - 1) {
               image.onmouseover = function() {
                  this.src = this.onImage.src;
               };
               image.onmouseout = function() {
                  this.src = this.offImage.src;
               };
            }
            else {
               image.onImage.onload = function() {
                  this.imageElement.onmouseover = function() {
                     this.src = this.onImage.src;
                  };
                  this.imageElement.onmouseout = function() {
                     this.src = this.offImage.src;
                  };
               };
            }
            
            // set src of on state image after defining onload event handler
            // so cached images (that load instantly in IE) will trigger onload
            image.onImage.src = image.src.replace(/_off\./, '_on.');
         }
      }
   }
   rolloverInitialized = true;
}

// call rolloverInit when document finishes loading
//if (isDefined(window.addEventListener)) {
//   window.addEventListener('load', rolloverInit, false);
//}
//else if (isDefined(window.attachEvent)) {
//   window.attachEvent('onload', rolloverInit);
//}

function validateSearch(frmObj){
	if(frmObj.query.value.length == 0 || frmObj.query.value == 'search'){
		alert('You must enter text to search for.');
		frmObj.query.focus();
		return false;
	}else{
		return true;
	}
}

// added 10/7/05 KPK - PADS user groups functionality  //REVISED BY MDW TO USE JQUERY 2/18/08
function showView(contentElementID){
	jQuery("div",jQuery('#right')).hide();
	jQuery("#"+contentElementID).show();
	jQuery("li",jQuery('#meeting')).removeClass("active");
	jQuery("li",jQuery('#group')).removeClass("active");
	jQuery('#'+contentElementID+'_nav').addClass('active');
}

jQuery(document).ready(function(){
	jQuery(".usergroupnav a").click(function(){
		var thisid = jQuery(this).parent("li").attr("id");
		var thisidpass = thisid.split("_nav")[0];
		showView(thisidpass);
	});
	jQuery(".usergroupnav:first").trigger("click");
});

// added 1/31/07 KPK - show/hide functionality - give the anchor a class="view-button" and the VERY NEXT div class="view-more". name your image myButton-show (off state) and myButton-hide.gif
jQuery(document).ready(function(){
	jQuery(".view-button").click(function(){
		var $my_wrapper = jQuery(this).parents("div:first");
		var $my_toggleobj = $my_wrapper.find("div.view-more")
		if(!$my_toggleobj[0]){
			$my_toggleobj = $my_wrapper.next("div.view-more")
		}
		var $my_togglelink = jQuery(this);
		if($my_togglelink.hasClass("toggled")){
			$my_togglelink.removeClass("toggled").attr("title", "Show");
			$my_toggleobj.hide();
		}else{
			$my_togglelink.addClass("toggled").attr("title", "Hide");
			$my_toggleobj.show();
		}
		return false;
	});
});
function toggleVisibility(rootobj){
/*	my_wrapper = rootobj.parentNode
	my_toggleobj = null;
	my_togglelink = rootobj;
	for (var i=0; i < my_wrapper.childNodes.length; i++){
		if (my_wrapper.childNodes[i].className == 'view-more' || my_wrapper.childNodes[i].className == 'view-more toggled'){
			my_toggleobj = my_wrapper.childNodes[i];
			break;
		}
	}
	my_toggleimg = rootobj.getElementsByTagName('IMG');
	my_toggleimg = my_toggleimg[0];
	if (my_togglelink.className == "view-button toggled") {
		my_toggleobj.style.display = "none";
		my_togglelink.setAttribute("title", "Show");
		my_togglelink.className = "view-button";
		if(my_toggleimg) {
			my_toggleimg.src = my_toggleimg.src.replace(/-hide\./, '-show.');
		}
	} else {
		my_toggleobj.style.display = "block";
		my_togglelink.setAttribute("title", "Hide");
		my_togglelink.className = "view-button toggled";
		if(my_toggleimg) {
			my_toggleimg.src = my_toggleimg.src.replace(/-show\./, '-hide.');
		}
	}*/
}

function prepareHideShow(){
	/*my_links = document.getElementsByTagName("A");
	for (var i=0; i < my_links.length; i++){	
		if (my_links[i].className == "view-button" || my_links[i].className == "view-button toggled"){
			my_links[i].onclick = function(){
				toggleVisibility(this);
				return false;
			}
		}	
	}*/
}

function init(){
	rolloverInit();
	//prepareHideShow();
}


jQuery(document).ready(function(){




//ACCORDIONS - ADDED BY MDW 2/28/2008

	jQuery("div.accordioncontainer").each(function(){
	
		var $thisAcc = jQuery(this);

		jQuery("div.accordion",$thisAcc).hide();														//hide the accordion divs
		jQuery("h4",$thisAcc).css({														//set the css for thee headers for the form on the left
			color: '#666',
			background: 'url(/mentor/images/navs/bg-toggle.gif) 0 50%'
		});
		jQuery("h4",$thisAcc).each(function(){												//for each header for the form on the left
			jQuery(this).click(function(){													//bind a toggle function
	
				if(jQuery(this).next("div.accordion").css("display")!=="block"){

					jQuery("div.accordion:visible",$thisAcc).hide("blind",{}, "normal")
					jQuery("h4",$thisAcc).css({														//set the css for thee headers for the form on the left
						color: '#666',
						background: 'url(/mentor/images/navs/bg-toggle.gif) 0 50%'
					});
					jQuery("h4",$thisAcc).removeClass("toggled");					
					
					jQuery(this).addClass("toggled").css({															//on first click set the css to active state
						color: '#111',
						background: 'url(/mentor/images/navs/bg-toggle-active.gif) 0 50%'
					}).next("div.accordion").show("blind",{}, "normal");
				
				}

			});
		});

		if(jQuery("h4.default",$thisAcc).length===0){
			jQuery("h4:first",$thisAcc).trigger("click");
		}else{
			jQuery("h4.default:first",$thisAcc).trigger("click");
		}	

	})
	
//ACCORDIONS2 - without styling - ADDED BY MDW 7/23/2008

	jQuery("div.nsaccordioncontainer").each(function(){
	
		var $thisAcc = jQuery(this);

		jQuery("div.accordion",$thisAcc).hide();														//hide the accordion divs
		jQuery("h4",$thisAcc).each(function(){												//for each header for the form on the left
			jQuery(this).click(function(){													//bind a toggle function
	
				if(jQuery(this).next("div.accordion").css("display")!=="block"){

					jQuery("div.accordion:visible",$thisAcc).hide("blind",{}, "normal");
					jQuery("h4",$thisAcc).removeClass("toggled");					
					jQuery(this).addClass("toggled").next("div.accordion").show("blind",{}, "normal");
				
				}

			});
		});

		if(jQuery("h4.default",$thisAcc).length===0){
			jQuery("h4:first",$thisAcc).trigger("click");
		}else{
			jQuery("h4.default:first",$thisAcc).trigger("click");
		}	

	})
//ANIMATED FORM BUTTONS - ADDED BY MDW 2/28/2008

	var $buttons = jQuery(".aniformbutton");
	$buttons.each(function(){
		jQuery(this).hover(function(){
			jQuery(this).animate({
				paddingLeft: '20px',
				marginRight: '5px'
			},200)
		},function(){
			jQuery(this).animate({
				paddingLeft: '10px',
				marginRight: 0
			},200)
		})
	});
	
//TABBER REPLACEMENTS - ADDED BY MDW 3/4/2008

	var $tabber = jQuery("div.tabber");
	
	$tabber.each(function(){

		var $currentTabber = jQuery(this);
		$currentTabber.removeClass("tabber").addClass("tabberlive");
	
		var $tabberNav = jQuery('<ul class="tabbernav"></ul>').prependTo($currentTabber);
	
		jQuery("div.tabbertab",$currentTabber).hide();
	
		jQuery("div.tabbertab",$currentTabber).each(function(index){
			var h2length = jQuery("h2",jQuery(this)).length;
			var h3length = jQuery("h3",jQuery(this)).length;
			var tabtext;
			if((h2length===0)&&(h3length===0)){
				tabtext=index+1;
			}else if(h2length>0){
				tabtext = jQuery("h2:first",jQuery(this)).text()
				jQuery("h2:first",jQuery(this)).hide();
			}else{
				tabtext = jQuery("h3:first",jQuery(this)).text()
				jQuery("h3:first",jQuery(this)).hide();
			}
			jQuery('<li><a href="#" title="' + tabtext + '">' + tabtext + '</a></li>').appendTo($tabberNav);
			jQuery(this).attr("title",tabtext)
		})
				
		jQuery("ul.tabbernav li a",$currentTabber).click(function(){
			jQuery("div.tabbertab",$currentTabber).hide();
			jQuery("ul.tabbernav li",$currentTabber).removeClass("tabberactive");
			jQuery(this).parent("li").addClass("tabberactive");
			jQuery("div.tabbertab[title='"+ jQuery(this).attr("title") + "']",$currentTabber).show();
			jQuery(this).trigger("blur");
			return false;
		})
		
		var defaultTab = jQuery("div.tabbertab",$currentTabber).index(jQuery("div.tabbertab.defaultTab",$currentTabber)[0])

		if(defaultTab!==-1){
			jQuery("ul.tabbernav li:eq(" + defaultTab + ") a:first",$currentTabber).trigger("click");
		}else{
			jQuery("ul.tabbernav li:first a:first",$currentTabber).trigger("click");
		}
		
	
	})

//ANIMATED TABS REPLACES MOOTABS - ADDED BY MDW 3/4/2008

	var $anitabs = jQuery("div.anitabs");
	
	$anitabs.each(function(){
		jQuery("ul",jQuery(this)).tabs();	
	});
	
//Abstract Togglers - ADDED BY MDW 3/11/2008

	jQuery("a.abstracttoggler").next("div").hide();
	jQuery("a.abstracttoggler").toggle(function(){
		jQuery(this).next("div").animate({height: 'toggle'},"fast").end().removeClass("toggle-collapsed").addClass("toggle-expanded");
	},function(){
		jQuery(this).next("div").animate({height: 'toggle'},"fast").end().removeClass("toggle-expanded").addClass("toggle-collapsed");
	});


//SOLUTIONS EXPO - ADDED BY MDW 3/12/2008


	jQuery("a.toggleworkshops").click(function(){
		var thisID = jQuery(this).attr("id");
		thisID = thisID.split("toggle")[1];
		var triggerID = 'toggle'+thisID;
		var workshopID = 'workshops'+thisID;
		var showhidevalues = (jQuery(this).attr("rel")).split("|")
		var showValue = showhidevalues[0];
		var hideValue = showhidevalues[1];
		toggleWorkshops(triggerID,workshopID,showValue,hideValue);
		return false;
	});
	jQuery(".showabsr").toggle(function(){
		jQuery(this).addClass("on").parent().children(".abstract-content").show();
		return false;
	},function(){
		jQuery(this).removeClass("on").parent().children(".abstract-content").hide();
		return false;
	})
	conflictUpdateEvent();
	
//FORM VALIDATION - ADDED BY MDW 3/13/2008

	jQuery("form.mentorvalidate").each(function(){
		var validID=jQuery(this).attr("id");
		MENTOR.validate({
			formId:validID,
			emailClass: 'validateemail',
			phoneClass: 'validatephone',
			numericClass: 'validatenumeric'
		});
	});

	jQuery("select",jQuery("form.mentorvalidate")).each(function(){																//iterate through all select fields
		if(jQuery.trim(jQuery("option:selected",jQuery(this)).text())=='Other (please specify):') {				//if the last option is selected
			jQuery('#' + jQuery(this).attr('name') + '_other').addClass("showingoption").removeClass("hidingoption").show();	//add the showingoption class to the span around the text field
		}else{
			jQuery('#' + jQuery(this).attr('name') + '_other').removeClass("showingoption").addClass("hidingoption").hide();  //if it is not selected add teh hidingoption class
		}
		jQuery(this).change(function(){															//attach a change listener
			if(jQuery.trim(jQuery("option:selected",jQuery(this)).text())=='Other (please specify):') {			//if the last option is selected
				jQuery('#' + jQuery(this).attr('name') + '_other').addClass("showingoption").removeClass("hidingoption").show();  //show the span with the text field in it
			}else{
				jQuery('#' + jQuery(this).attr('name') + '_other').removeClass("showingoption").addClass("hidingoption").hide()	//if not seletected, hide the text field
				.find("span.error").remove();
			}
		});
	});
	
	jQuery("input.checkboxother",jQuery("form.mentorvalidate")).each(function(){
		var $newCheck = jQuery('<p><input type="checkbox" class="createdcheckother removeonsubmit" /> <label class="checkbox">Other</label></p>').insertBefore(jQuery(this).prev("label"))
		var $currentBlock = jQuery(this).parents("li");
		$thisothertext = jQuery(this);
		jQuery(this).prev("label").hide().end().hide();
		jQuery("input.createdcheckother",$currentBlock).click(function(){
			if(jQuery(this).attr("checked")==true){
				jQuery(".checkboxother",$currentBlock).show().prev("label").show();
			}else{
				jQuery(".checkboxother",$currentBlock).hide().val('').addClass("removeonsubmit").prev("label").hide();
			}
		});				
	});	
	
//VID
	var vid="";
	var pageurl = window.location + '';
	if(pageurl.indexOf("&vid=")!=-1){
		vid=pageurl.split("&vid=")[1];
		vid=vid.split("&")[0];
	}	
	if(pageurl.indexOf("?vid=")!=-1){
		vid=pageurl.split("?vid=")[1];
		vid=vid.split("&")[0];
	}	
	if(vid!=""){
		var vidused="yes";
		var $prefilling = jQuery('<div class="loading"> <strong>Populating Form</strong></div>');
		$prefilling.insertBefore(jQuery('#contactFields'));
		jQuery.ajax({
			type: "GET",
			url: "/apps/forms/ajax_userdata.cfm",
			dataType: "script",
			data: {vid:vid},
			success: function(){
				if(typeof userData != "undefined"){
					
					jQuery('<div id="viderrors" class="error"><ul></ul></div>').insertBefore(jQuery('.form-container'))
	
					var $viderrors = jQuery(userData.error_message)
					
					jQuery("#viderrors ul").append($viderrors);
					
					jQuery("form.mentorvalidate").each(function(){
						var $thisform = jQuery(this);
						var checkboxnames=[];
						jQuery(":checkbox,:radio",$thisform).each(function(){
							var thisname = jQuery(this).attr("name")
							if(thisname!=''){
								if(jQuery.inArray(thisname, checkboxnames)==-1){
									checkboxnames.push(thisname)
									var $thisInput = jQuery('[name='+thisname+']');
									if(userData[thisname]){
										var checkvals = userData[thisname].split(",")
										$thisInput.not(".checkboxother").val(checkvals);
									}
								}
							}
						})
						jQuery("select[type='select-multiple']",$thisform).each(function(){
							var userdatakey = (jQuery(this).attr("id")).split("id_")
							if(userdatakey.length>1){
								if(userData[userdatakey[1]]){
									var checkvals = userData[userdatakey[1]].split(",")
									jQuery(this).val(checkvals);
								}
							}
						});
						jQuery("select[type='select-one'],textarea,:text",$thisform).not(".checkboxother").each(function(){
							var userdatakey = (jQuery(this).attr("id")).split("id_")
							if(userdatakey.length>1){
								if(userData[userdatakey[1]]){
									jQuery(this).val(userData[userdatakey[1]])
									if(userData[userdatakey[1]]!=''){
										if(jQuery(this).parent("span").hasClass("other")){
											var relelsel = (jQuery(this).attr("id")).split("_other")
											relelsel.pop()
											relselel = relelsel.join("_other")
											jQuery("#"+relselel).trigger("change")
										}
									}
								}
							}
						});
					})

					
					
					/*for(var key in userData){																//iterate through all the items in the userdata array		
						var $thisInput = jQuery('#id_'+key);
						if($thisInput.length==0){
							$thisInput = jQuery('[name='+key+']');
						}
						if($thisInput[0]){																		//if there is a field
							if(($thisInput.attr('type') != 'hidden')&&($thisInput.attr('type') != 'submit')){
								if($thisInput.attr('type') == 'checkbox' || $thisInput.attr('type') == 'radio'){//if it is a checkbox or radio button
									var checkvals = userData[key].split(",")
									$thisInput.val(checkvals);
								}else{																			//if is a text field
									$thisInput.val(userData[key]); 												//set the value to the value of the item in the array
								}
							}							
						}
					}*/
				$prefilling.remove();
				}
			},
			error: function(){
				$prefilling.remove();
			}
		});
		
	}
//REMEMBER ME - ADDED BY MDW 3/27/2008

	

	if(document.getElementById("rememberMe")){
		
		
		if((readCookie("REMEMBER") == "yes")&&(vidused!="yes")&&(readCookie("userID")!=null)){																	//if userdata has value from the page header
		
			var $prefilling = jQuery('<div class="loading"><strong>Populating Form</strong></div>')
			$prefilling.insertBefore(jQuery('.form-container'));
			jQuery.ajax({
				type: "GET",
				url: "/apps/forms/ajax_userdata.cfm",
				dataType: "script",
				data: {userID:readCookie("userID")},
				success: function(){
					if(typeof userData != "undefined"){
						var fname = userData.fname || '';													//fname either equals the value from userdata array or blank
						var lname = userData.lname || '';													//lname either equals the value from userdata array or blank
							
						if(fname!=''){
							jQuery('<p id="welcomeElement"></p>')														//create dom element of welcome paragraph
							.text('Welcome back, ' + fname + ' ' + lname)											//add the welcome text including first name and lastname
							.insertBefore(jQuery('.form-container'));														//insert the new element after the contact fields
							
						}
						jQuery('<p id="notMeElement">(<a id="notMeLink"" href="#"></a>)</p>')	//create the not me links
						.insertAfter("#welcomeElement");														//put them after the welomce paragraph
						jQuery("#notMeLink")																			//select the not me link
						.text("Click here if you aren't " + fname + " " + lname)								//add text to the link
						.click(function(){																		//and a click listener
							eraseCookie("REMEMBER")
							eraseCookie("userID")
							clearUserData();																	//clear contact fields with function
							showContactForm();																	//show the contact fields
						});
						jQuery("form.mentorvalidate").each(function(){
							var $thisform = jQuery(this);
							var checkboxnames=[];
							jQuery(":checkbox,:radio",$thisform).each(function(){
								var thisname = jQuery(this).attr("name")
								if(thisname!=''){
									if(jQuery.inArray(thisname, checkboxnames)==-1 && userData[thisname]){
										checkboxnames.push(thisname)
										var $thisInput = jQuery('[name='+thisname+']');
										var checkvals = userData[thisname].split(",")
										$thisInput.not(".checkboxother").val(checkvals);
									}
								}
							})
							jQuery("select[type='select-multiple']",$thisform).each(function(){
								var userdatakey = (jQuery(this).attr("id")).split("id_")
								if(userdatakey.length>1){
									if(userData[userdatakey[1]]){
										var checkvals = userData[userdatakey[1]].split(",")
										jQuery(this).val(checkvals);
									}
								}
							});
							jQuery("select[type='select-one'],textarea,:text",$thisform).not(".checkboxother").each(function(){
								var userdatakey = (jQuery(this).attr("id")).split("id_")
								if(userdatakey.length>1){
									if(userData[userdatakey[1]]){
										jQuery(this).val(userData[userdatakey[1]])
										if(userData[userdatakey[1]]){
											if(userData[userdatakey[1]]!=''){
												if(jQuery(this).parent("span").hasClass("other")){
													var relelsel = (jQuery(this).attr("id")).split("_other")
													relelsel.pop()
													relselel = relelsel.join("_other")
													jQuery("#"+relselel).trigger("change")
												}
											}
										}
									}
								}
							});
						})
/*						for(var key in userData){																//iterate through all the items in the userdata array		
							var $thisInput = jQuery('#id_'+key);
							if($thisInput.length==0){
								$thisInput = jQuery('[name='+key+']');
							}
							if($thisInput[0]){
								if(($thisInput.attr('type') != 'hidden')&&($thisInput.attr('type') != 'submit')){
									if($thisInput.attr('type') == 'checkbox' || $thisInput.attr('type') == 'radio'){//if it is a checkbox or radio button
										var checkvals = userData[key].split(",")
										$thisInput.val(checkvals);
									}else{																			//if is a text field
										$thisInput.val(userData[key]); 												//set the value to the value of the item in the array
									}
								}									
							}
						}*/
					}
					$prefilling.remove();
				},
				error: function(){
					$prefilling.remove();
				}
			});
/*			jQuery.getJSON("/apps/forms/ajax_userdata.cfm",{userID:readCookie("userID")},function(data){
				$.each(data.userData, function(i,key){
					var $thisInput = jQuery('#id_'+key);														//store the jquery object in a variable for each field
					if($thisInput[0]){																		//if there is a field
						if($thisInput.attr('type') == 'checkbox' || $thisInput.attr('type') == 'radio'){//if it is a checkbox or radio button
							$thisSet = jQuery('#id_'+key);													//the field to set is stored		
							$thisSet.each(function(){													//iterate  through all the items
								if(jQuery(this).val() == key){										//if the items value is the same as in the array
									$(this).attr("checked","true");										//mark itchecked
								}
							});
							
						}else{																			//if is a text field
							$thisInput.val(key); 												//set the value to the value of the item in the array
						}
						
					}
        		});
			});*/
			//$('#contactFields').hide();																//hide the contact fields
/*			for(var key in userData){																//iterate through all the items in the userdata array		
				var $thisInput = $('#id_'+key);														//store the jquery object in a variable for each field
				if($thisInput){																		//if there is a field
					if($thisInput.attr('type') == 'checkbox' || $thisInput.attr('type') == 'radio'){//if it is a checkbox or radio button
						$thisSet = $('#id_'+key);													//the field to set is stored		
						$thisSet.each(function(){													//iterate  through all the items
							if($(this).val() == userData[key]){										//if the items value is the same as in the array
								$(this).attr("checked","true");										//mark itchecked
							}
						});
						
					}else{																			//if is a text field
						$thisInput.val(userData[key]); 												//set the value to the value of the item in the array
					}
					
				}
			}*/
		}

	}
	function clearUserData(){																	//function to clear all contact fields
		$('#contactFields input').val("");														//clear the value of all inputs
		$('#contactFields select').each(function(){	
			this.selectedIndex = 0;																//make all select boxes have the first option selected
		});
	}

	function showContactForm(){																	//function to show contact fields
		//$('#contactFields').show();																//show the contact fields
		$('#welcomeElement').fadeOut("slow");													//fade the welcome message out
		$('p#notMeElement').hide();																//hide the links
	}

//POPUPS - ADDED BY MDW 3/27/2008

	jQuery("a.popup").each(function(){													//for each link with class popup
		jQuery(this).click(function(){													//attach a click function that opens a popup window
			var passedWidth
			var passedHeight
			if((jQuery(this).is("[rel]")) && (jQuery(this).attr("rel").split('|').length===2)){
				passedWidth = jQuery(this).attr("rel").split('|')[0]
				passedHeight = jQuery(this).attr("rel").split('|')[1]
			}else{
				passedWidth=920
				passedHeight=720
			}
			var w = window.open(jQuery(this).attr("href"),"popup","width=" + passedWidth + ",height=" + passedHeight + ",resizable=yes,toolbar=no,menubar=no,location=yes,scrollbars=yes");
			w.focus();
			return false;
		});
	});

//Lightbox - ADDED BY MDW 6/10/2008

	jQuery("a[rel='lightbox']").lightBox({
		imageLoading:'/mentor/images/lightbox/lightbox-ico-loading.gif',
		imageBtnPrev:'/mentor/images/lightbox/lightbox-btn-prev.gif',
		imageBtnNext:'/mentor/images/lightbox/lightbox-btn-next.gif',
		imageBtnClose:'/mentor/images/lightbox/lightbox-btn-close.gif',
		imageBlank:'/mentor/images/lightbox/lightbox-blank.gif'
	})

/*	jQuery("a[rel='lightbox'").each(function(){													//for each link with class popup
		jQuery(this).click(function(){													//attach a click function that opens a popup window
			var passedWidth
			var passedHeight
			if((jQuery(this).is("[rel]")) && (jQuery(this).attr("rel").split('|').length===2)){
				passedWidth = jQuery(this).attr("rel").split('|')[0]
				passedHeight = jQuery(this).attr("rel").split('|')[1]
			}else{
				passedWidth=800
				passedHeight=600
			}
			var w = window.open(jQuery(this).attr("href"),"popup","width=" + passedWidth + ",height=" + passedHeight + ",resizable=yes,toolbar=no,menubar=no,location=yes,scrollbars=yes");
			w.focus();
			return false;
		});
	});*/



//PAYMENT FORM INTERACTIONS - ADDED BY MDW 4/9/2008
	

	jQuery("div.radioShowHide").each(function(){
		var $thisRSH=jQuery(this);
		jQuery(".radiopanel",$thisRSH).hide();
		jQuery(".radiotrigger",$thisRSH).each(function(i){
			jQuery(this).click(function(){
				jQuery(".radiopanel",$thisRSH).hide();
				jQuery("label.required",$thisRSH).removeClass("required").addClass("reqhidden");
				var $showpanel = jQuery("div.radiopanel:eq(" + (i) + ")",$thisRSH);
				$showpanel.show();
				jQuery("label.reqhidden",$showpanel).removeClass("reqhidden").addClass("required");
			});
			if(jQuery(this).is(":checked")){
				jQuery(".radiopanel",$thisRSH).hide();
				jQuery("label.required",$thisRSH).removeClass("required").addClass("reqhidden");
				var $showpanel = jQuery("div.radiopanel:eq(" + (i) + ")",$thisRSH);
				$showpanel.show();
				jQuery("label.reqhidden",$showpanel).removeClass("reqhidden").addClass("required");
			}
		});
		if(jQuery(".radiotrigger:checked",$thisRSH).length<1){
			jQuery(".radiotrigger:first",$thisRSH).trigger("click");
		}
	});
	
//auto fill billing on training - added by MDW 6/30/2008
	jQuery("#id_sameascontact").click(function(){
		if(jQuery(this).attr("checked")==true){
			jQuery("#id_billing_address1").val(jQuery("#id_address1").val());
			jQuery("#id_billing_municipality").val(jQuery("#id_municipality").val());
			jQuery("#id_billing_state").val(jQuery("#id_state").val());
			jQuery("#id_billing_postalcode").val(jQuery("#id_postal_code").val());
			jQuery("#id_billing_country").val(jQuery("#id_country").val());
		}
	})

//tooltips - added by MDW 6/30/2008

	jQuery(".tooltip").tooltip({
		track: false,
		showURL: false
	});

	jQuery("input#337").click(function(){
		if(jQuery(this).attr("checked")==true){
			jQuery("#interest_area_other").show();
		}else{
			jQuery("#interest_area_other").hide();
		}
	})
	
	//divrotator
	jQuery("div.divrotator").each(function(){
	 	var $rotator = jQuery(this);
	 	var randomnumber=Math.floor(Math.random()*jQuery("div",$rotator).length);
	  	jQuery("div:eq("+randomnumber+")",$rotator).show();
	})
})
var conflictUpdateEvent = function(){
	if(jQuery("form[name='event2Form']").attr("id")=='scheduleSessionForm'){
		jQuery("input[name='mentor_event']").each(function(){
			var conflictsearch = jQuery(this).attr("conflicts");
			if(conflictsearch){
				var arPotentialConflicts = conflictsearch.split(',');
				var other = new Object();
				var arConflicts = new Array();
				var rowID =  (jQuery(this).attr("id")).replace('check','');
				if(jQuery(this).is(":checked")){
					setRowHighlight(rowID,true);
					for(var i=0;i<arPotentialConflicts.length;i++){
						other = jQuery('#check'+arPotentialConflicts[i]);
						if(other.is(":checked")){
							arConflicts.push(other[0]);
						}
					}
				}else{
					setRowHighlight(rowID,false);
				}
				setRowWarning(rowID,arConflicts);
			}
		})
	}
}

function setRowWarning(warnID,arConflicts){
	var warn = jQuery('#warn'+warnID);
	var bSetToOn = (arConflicts.length == 0 ? false : true);
	if(bSetToOn){
		var html = warn.attr("title");
		html+="<ul>";
		for(var i=0;i<arConflicts.length;i++){
			html+='<li>' + arConflicts[i].title + '</li>';
		}
		html+="</ul>";
		warn.html(html);
		warn[0].style.display = '';
	}else{
		warn[0].style.display = 'none';
	}
}

function setRowHighlight(rowID,bSetToOn){
	var row = jQuery('#sessionRow'+rowID);
	if(bSetToOn){
		row.addClass('checked');
	}else{
		row.removeClass('checked');
	}
}
var toggleWorkshops = function(triggerID,workshopID,showValue,hideValue){
	var $elTrigger = jQuery("#"+triggerID);
	var $elWorkshops = jQuery("#"+workshopID);
	if($elTrigger.html() == hideValue){
		$elTrigger.html(showValue);
		$elTrigger.addClass('show');
		$elWorkshops.fadeOut("slow");
	}else{
		$elTrigger.html(hideValue);
		$elTrigger.removeClass('show');
		$elWorkshops.fadeIn("slow");
	}
}
function submitTo(location){
	var frm = document.forms["event2Form"];
	if(typeof(frm) != 'undefined'){
		if(location.length > 0){
			frm.forwardTo.value = location;
		}
		if(frm.id == 'confirmForm'){
			confirmPreSubmitEvent(frm);
		}
		frm.submit();
	}
}

function confirmPreSubmitEvent(frm){
	var items = '';
	for (var i=0; i<frm.length; i++) {
		if(frm[i].name.substring(0,12) == 'mentor_event' && frm[i].checked){
			items += ','+frm[i].value;
		}
	}
	items = items.substring(1,items.length);//remove the initial comma
	frm.mentor_event.value = items;
}

var createCookie = function(name,value,days){
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}else{
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
};
var readCookie = function(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
};
var eraseCookie = function(name){
	createCookie(name,"",-1);
};

//commonspot js that we will want to replace
function FormatWindowParams(windowparams)
{
	if( windowparams.indexOf(":loc=") != -1 || windowparams.indexOf(":ww=") != -1 || windowparams.indexOf(":hh=") != -1 || 
	    windowparams.indexOf(":left=") != -1 || windowparams.indexOf(":top=") != -1 )
	{
		windowparams = substringReplace(windowparams,':left=',',left=');
		windowparams = substringReplace(windowparams,'left=','left=');
		windowparams = substringReplace(windowparams,':ww=',',width=');
		windowparams = substringReplace(windowparams,'ww=','width=');		
		windowparams = substringReplace(windowparams,':hh=',',height=');
		windowparams = substringReplace(windowparams,'hh=','height=');
		windowparams = substringReplace(windowparams,':loc=',',location=');
		windowparams = substringReplace(windowparams,'loc=','location=');
		windowparams = substringReplace(windowparams,':dir=',',directories=');
		windowparams = substringReplace(windowparams,'dir=','directories=');
		windowparams = substringReplace(windowparams,':tb=',',toolbar=');
		windowparams = substringReplace(windowparams,'tb=','toolbar=');
		windowparams = substringReplace(windowparams,':stat=',',status=');
		windowparams = substringReplace(windowparams,':mb=',',menubar=');
		windowparams = substringReplace(windowparams,':sb=',',scrollbars=');
		windowparams = substringReplace(windowparams,':rs=',',resizable=');
	}
	return windowparams;
}
function substringReplace(source,pattern,replacement)
{
	var pos = 0;
	var target="";
	while ((pos = source.indexOf(pattern)) != (-1))
	{
		target = target + source.substring(0,pos) + replacement;
		source = source.substring(pos+pattern.length);
		pos = source.indexOf(pattern);
	}
	return (target + source);
}
function HandleLink(parentID,link,displaylink) 
{
	// links are in one of the following formats:
	// 		cpe_60_0,CP___PAGEID=100
	// 		CPNEWWIN:WindowName^params@CP___
	// 			CPNEWWIN:child^top=110:left=130:ww=140:hh=150:tb=1:loc=1:dir=0:stat=1:mb=1:sb=1:rs=1@CP___PAGEID=3811,Adv-Search-2.cfm,1
	// displaylink is the server relative URL or fully qualified URL
		var windowname = "";
		var windowparams = "";

		// "CPNEWWIN:" & NewWindowName & "^" & params & "@" & linkStruct.LinkURL; 
		pos = link.indexOf("CPNEWWIN:");
		if (pos != -1)
		{
			pos1 = link.indexOf ("^");
			windowname = link.substring (pos+9, pos1);
			pos2 = link.indexOf ("@");
			windowparams = link.substring (pos1 + 1, pos2);
			link = link.substring (pos2 + 1, link.length);
		}
		
		if( displaylink && displaylink != "" )
		{		
			if (windowname == "")
				window.location = displaylink;
			else
			{
				windowparams = FormatWindowParams(windowparams);
				window.open (displaylink, windowname, windowparams);
			}
		}
		else
		{
			targetLink = link;

			if (link.indexOf ("CP___") != -1)
			{

				httpPos = -1;
				commaPos = link.indexOf(",");
				if (commaPos != -1)
				{
					targetUrl = link.substr(commaPos + 1);
					if (targetUrl.indexOf("://") != -1 || targetUrl.indexOf("/") == 0)
					{
							httpPos = commaPos + 1;
					}		
				}

				
				if (httpPos != -1)
				{
					targetLink = link.substr(httpPos);

					commaPos = targetLink.indexOf(",");
					if (commaPos != -1)
						targetLink = targetLink.substr(0, commaPos);
				}
				else
					targetLink = jsDlgLoader + "?url=/commonspot/utilities/handle-link.cfm&thelink=" + link;
				
				if (windowname == "")
					window.location = targetLink;
				else
				{
					windowparams = FormatWindowParams(windowparams);
					window.open (targetLink, windowname, windowparams);
				}
			}
			else
			{
				//commaPos = link.indexOf(",");
				//if (commaPos != -1)
				//link = link.substr(0, commaPos);

				if (windowname == "")
					window.location = link;
				else
				{
					windowparams = FormatWindowParams(windowparams);
					window.open (link, windowname, windowparams);
				}
			}
		}

}

//function for pads layout other resources - MDW 6/10/2008
function expandList(){
	if (!document.getElementById) return false;
	list_header = document.getElementById("foldheader");
	list_expand = document.getElementById("foldinglist"); 
	if (list_header.className != "expanded"){
		list_expand.style.display ="block";
		list_header.className = "expanded";
	} else {
		list_expand.style.display ="none";
		list_header.className = "collapsed";
	}
}

