adlib.defaults.strings.template.openDelimiter="{";
adlib.defaults.strings.template.closeDelimiter="}";
// Pop-up functions

var currentPopId=null;
function showPopup(elem){
	elem=$(elem).toggleOn().center();
	currentPopId=elem.id;
	var backers=$('popup-backing','ie-pop-fix','pop-clicker').applyStyle({display:'block',width:DOM.getDocumentWidth()-10,height:DOM.getDocumentHeight()});
};
function showPopup1(elem){
  alert("showPopup1: "+elem);
	delem=top.document.getElementById(elem);
  alert("showPopup1: 1 ");
	delem.toggleOn();
	DOM.doStyleEvent('css',delem,'display');
  alert("showPopup1: 2 ");
	delem.center();
  alert("showPopup1: 3 ");
	currentPopId=delem.id;
  alert("showPopup1: 4 ");
	var backers=$('popup-backing','ie-pop-fix','pop-clicker').applyStyle({display:'block',width:DOM.getDocumentWidth()-10,height:DOM.getDocumentHeight()});
};


function closePopup(){
	$(currentPopId,'popup-backing','ie-pop-fix','pop-clicker').toggleOff();
};


function checkEmail(str){
	var emailPattern=function(){
		var al="a-zA-Z";
		var an=al+"0-9";
		var dm=an+"\\-";
		var ch=dm+"_\\+";
		var ent=ch+"\\.";
		var a=new RegExp("^["+an+"]["+ent+"]*["+an+"]@(["+an+"]["+ent+"]*["+ch+"]\\.)?["+dm+"]{2,63}\\.["+al+"]{2,10}$");
		return a	
	}();
	return ((isValidText(str))&&(emailPattern.test(str)));

};

// fm = form name
// cn = counter field name
// fn = field name 1 (contact field name)
// fn = field name 2 (title field name)
// pid = id for point of insertion (link <tr>)
// targ = the link that is clicked
function addGroupFields(fm,cn,fn1,fn2,pid,targ){
	var fm=document[fm];
	var num=fm[cn].value.toInt();
	var obj={
		fieldName:fn1+'_'+num,
		fieldLabel:'Leader:',
		onchange:'document.forms.group_form.hosts_changed.value=1;',
		fieldName1:fn2+'_'+num,
		fieldLabel1:'Leadership Position (optional):',
		onchange1:'document.forms.group_form.title_changed.value=1;'
	};
	var obj2={
		fieldName:fn2+'_'+num,
		fieldLabel:'Leadership Position (optional):',
		onchange:'document.forms.group_form.title_changed.value=1;'
	};
	addFieldRowGroup($(targ).$anc('table'),obj,pid,0);
	//addFieldRowGroup2($(targ).$anc('table'),obj2,pid,0);
	new AutoSuggest(top.document.getElementById(fn1+'_'+num),friends);
	num++;
	fm[cn].value=num;
	return false;
};

function addEventField(fm,cn,fn,pid,targ,size){
	var fm=document[fm];
	var num=parseInt(fm[cn].value);
	var obj={
		fieldName:fn+'_'+num,
		fieldLabel:''
	};
	addFieldRow($(targ).$anc('table'),obj,pid,size);
	new AutoSuggest(top.document.getElementById(fn+'_'+num),friends);
	num++;
	fm[cn].value=num;
	return false
}

// el = element to insert into
// o = template object
// pid = id of node to insert before
function addFieldRow(el,o,pid,size){
	var stxt=" ";
	if (size > 0)
	    stxt=" size="+size+" ";
	var row='<tr>'+_NL+'<th><label for="{fieldName}">{fieldLabel}</label></th>'+_NL;
	row+='<td>'+_NL
	    +'<input type="text" class="textfield" name="{fieldName}" id="{fieldName}"'+stxt+'/>'+_NL
	    +'<input type="hidden" name="{fieldName}_id" id="{fieldName}_id">'+_NL+'</td>'+_NL+'</tr>';
	var cont=row.template(o);
	el.insertContent(cont,true,'#'+pid);
};

// el = element to insert into
// o = template object
// pid = id of node to insert before
function addFieldRowGroup(el,o,pid,size){
	var stxt=" ";
	if (size > 0)
	    stxt=" size="+size+" ";
	var row='<tr>'+_NL+'<th style="text-align: right;"><label for="{fieldName}">{fieldLabel}</label></th>'+_NL;
	row+='<td style="width:210px;"><input type="text" class="textfield" name="{fieldName}" id="{fieldName}" style="width:175px;"'+stxt+'/>'+_NL
	    +'<input type="hidden" name="{fieldName}_id" id="{fieldName}_id" onChange="{onchange}">'
	    +_NL+'</td>'+_NL;
	row+='<th style="width:210px; text-align: right; padding-right: 10px;"><label for="{fieldName1}">{fieldLabel1}</label></th>'+_NL;
	row+='<td style="width:210px;">'+_NL
	    +'<input type="text" style="width:175px;" name="{fieldName1}" id="{fieldName1}"'+stxt+'/>'+_NL
	    +'<input type="hidden" name="{fieldName1}_id" id="{fieldName1}_id" onChange="{onchange1}">'
	    +_NL+'</td>'+_NL+'</tr>';
	var cont=row.template(o);
	el.insertContent(cont,true,'#'+pid);
};
function addFieldRowGroup2(el,o,pid,size){
	var stxt=" ";
	if (size > 0)
	    stxt=" size="+size+" ";
	var row='<th><label for="{fieldName}">{fieldLabel}</label></th>'+_NL;
	row+='<td>--'+_NL
	    +'<input type="text" class="textfield" name="{fieldName}" id="{fieldName}"'+stxt+'/>'+_NL
	    +'<input type="hidden" name="{fieldName}_id" id="{fieldName}_id" onChange="{onchange}">'
	    +_NL+'--</td>'+_NL+'</tr>';
	var cont=row.template(o);
	el.insertContent(cont,true,'#'+pid);
};


/************************************* AIM functions**************************/
var AIMWindowOpened=typeof window.AIMWindowOpened=="undefined"?false:window.AIMWindowOpened;
var AIMWin=null;
var AIMWindowUrl="aim.html";
var AIMTimer=null;
var AIMisAnimating=false;
var AIMrestartAfterAnimation=false;
function openAim(){
	var l=DOM.getWindowX();
	var w=DOM.getDocumentWidth()+30;
	var s=screen.width;
	var left=l+w;
	if(left+545>s){
		left=s-545;
	}
	AIMWin=window.open(AIMWindowUrl,'AIMWindow','width=540,height=400,location=no,scrollbars=yes,menubar=no,toolbar=no,resizeable=yes,status=yes,top=0,left='+left);
	// if popup blockers didn't stop us, toggle the link off and set a var to track that it is there
	if(AIMWin){
		$('chat').toggleOff();
		AIMWindowOpened=true;
	}
};
function closeAim(){
	AIMWin=null;
	AIMWindowOpened=false;
	$('chat').toggleOn();	
};
function AIMNewMessage(){
	if(AIMTimer==null){
		$('chatUpdate').toggleOn().animate({opacity:[0,100]});
	}
	else if(AIMisAnimating){
		AIMrestartAfterAnimation=true;
	}
	else{
		clearTimeout(AIMTimer);
	}
	startAIMTimer(this);
};
function startAIMTimer(el){
	AIMTimer=setTimeout(function(){
		AIMisAnimating=true;
		$('chatUpdate').animate({
			opacity:[100,0],
			callback:function(el){
				AIMisAnimating=false;
				el.toggleOff(); 
				AIMTimer=null;
				if(AIMrestartAfterAnimation){
					AIMrestartAfterAnimation=false;
					AIMNewMessage();
				}
			}
		})},10000);	
};
Events.inQ('DOMLoad',function(){if(AIMWindowOpened){$('chat').toggleOff();}});


Events.add('hoverFixOver','mouseover',function(e,el){
	el.addClass('hover');
});

Events.add('hoverFixOut','mouseout',function(e,el){
	el.removeClass('hover');
});

if(adlib.browser.ie&&adlib.browser.v<7){
	Behaviors.addToDOMLoad(new Behavior({
		css:'.hoverFix',
		events:{
			hoverFixOver:true,
			hoverFixOut:true
		}
	}));
}

