function newsMods(UL)
{
	var TO,row=0,C;
	if(!(UL=$(UL)))
		C=(UL=$('bullMod_News')).up('div.bullModContainer');
	else
		C=UL.up('div.bullModContainer');
	this.setup=function()
	{
		if(C.getWidth()>400)
		{
			var self=this;
			var D=C.down('div.displayContainer'),L=C.childElements()[1];
			D.style.width=(C.getWidth()-247)+'px';
			L.style.cssFloat='right';
			L.style.width='220px';
//			L.down('ul').removeClassName('noListStyle');
			D.style.display='';
			C.addClassName('fullWidth');
			C.observe('mouseover',function(){self.stop();});
			C.observe('mouseout',function(){self.start();});
			$A(C.getElementsByClassName('border')).each(function(t){t.removeClassName('border')})
			$A(C.getElementsByTagName('li')).each(function(t){
				t.observe('mouseover',function(){self.display(this);});
			})
			this.display(L.down('li'));
			this.TO=setInterval(function(){self.display();},5000);
		}
		else
		{
			
			{
				Accordion_News=new accordion(UL.id,{onEvent : 'mouseover'});
				Accordion_News.activate(UL.down('.accordion_toggle'));
			}
		}
	}
	this.display=function(item)
	{
		L=C.childElements()[1];
		if(item)
		{
			var temp;
			for(var i=0,row=-1;row==-1 && (temp=L.getElementsByTagName('li')[i]);i++)
				if(temp==item)
					this.row=i;
		}
		else
			if(!(item=L.getElementsByTagName('li')[++this.row]))
				item=L.getElementsByTagName('li')[this.row=0];

		$A(item.up('ul').getElementsByTagName('li')).each(function(t){t.removeClassName('highlighted')});
		item.addClassName('highlighted');
		item.up('div.bullModContainer').down('div.displayContainer').innerHTML=item.down('div.fullView').innerHTML;
	}
	this.stop=function()
	{
		clearInterval(this.TO);
	}
	this.start=function()
	{
		var self=this;
		clearInterval(this.TO);
		this.TO=setInterval(function(){self.display();},5000);
	}
	if(C && $$('#bullMod_News li')) this.setup();
}

function imagesFade(c,s)
{
	var i=0;
	if(!s) s=5;
	if(!(c=$(c))) return;
	var img=(c.select('img'));
	if(!img[0]) return;
	c.style.position='relative';
	img.each(function(c){c.style.position='absolute';c.style.top='0px';c.style.left='0px';c.hide();});
	img[i].style.position='relative';
	img[i].style.display='';
	c.show();
	c.style.height=c.getHeight() + 'px';
	c.style.width=c.getWidth() + 'px';
	img[i].style.position='absolute';
	this.timeOut=setInterval(function(obj){return(function(){obj.n();});}(this), s*1000);
	addOnload(function(obj){return(function(){obj.cache();});}(this));
	this.cache=function()
	{
		var i=0;
		imgArray = new Array();
		img.each(function(o)
		{
			imgArray[i]=new Image();
			imgArray[i++].src=o.src;
		});
	}
	this.n=function()
	{
		var n=i+1;
		if(!img[n]) n=0;
		Effect.Fade(img[i]);
		Effect.Appear(img[n]);
		i=n;
	}
}

function fillContainer(container,content)
{

	if(container && content)
	{
		startHeight=container.getHeight();
//		startContent=content.getHeight();
		content.style.minHeight=(content.getHeight()-content.style.paddingTop-content.style.paddingBottom)+'px';
		if(startHeight!=container.getHeight())
			content.style.minHeight=(parseInt(content.style.minHeight)+(startHeight-container.getHeight()))+'px';
		for(var i=0;(startHeight==container.getHeight()) && i<500;i++)
			content.style.minHeight=(parseInt(content.style.minHeight)+1)+'px';
		content.style.minHeight=(parseInt(content.style.minHeight)-1)+'px';
	}
}


function calculatePaypal(paypalUsername,code,noShipping,This,currency)
{
	var items=[],C;
	var further='',url='',i=0;
	if(!This || !(C=$(This).up('.content')))
		if(!This || !(C=$(This).up('.module')))
			if(!(C=$('mainContent')))
			{
				alert('an error has occured, please contact your administrator');
			}
	C.getElementsBySelector('select').each(function(select){
		if(select.selectedIndex!=-1 && select.options[select.selectedIndex].text!='0')
		{
			var val=[]; //name, value
			var cost,o=select.options[select.selectedIndex];
			if((cost=o.value)=="" || cost==o.text)
				if((cost=select.options[0].value)=='' || cost==select.options[0].text)
					cost=select.name.substring(select.name.indexOf("$")+1).replace( /(^.+)(\w\d+\w)(.+$)/i,'$2'); //get cost from end of string
			cost=cost.replace( /(^.+\D)(\d+)(\D.+$)/i,'$2'); //get cost from anywhere in string
			if(isNaN(o.text))
			{
				val[0]=o.text;
				val[1]=cost;
				val[2]=1;
			}
			else
			{
				val[0]=select.name;
				val[1]=cost;
				val[2]=o.text;
			}
			items[items.length]=val;
		}
	});
	C.getElementsBySelector('input[type=checkbox]').each(function(select){
		if(select.checked)
		{
			var val=[]; //name, value
			val[0]=select.name;
			val[1]=select.value.replace( /(^.+\D)(\d+)(\D.+$)/i,'$2');;
			val[2]=1;
			items[items.length]=val;
		}
	});
	C.getElementsBySelector('input[type=text]').each(function(input){
		if(input.value!='')
		{
			if(further!='') further+='; ';
			further+=input.name+': '+input.value;
		}
	});
	for(i=0;i<items.length;i++)
		url+='&item_name_'+(i+1)+'='+escape(items[i][0])+'&amount_'+(i+1)+'='+items[i][1]+'&quantity_'+(i+1)+'='+items[i][2];
	window.open('https://www.paypal.com/cgi-bin/webscr?cmd=_cart&upload=1&business='+paypalUsername+url+'&custom='+escape(further)+'&no_shipping='+(noShipping?noShipping:0)+'&no_note=1&currency_code='+ ((_domainName.indexOf('eu.')==-1)?'AUD':'GBP')+'&lc=AU&notify_url=https%3A//'+ location.hostname + location.pathname +'%3Faction%3Dpaypalconfirm%26code%3D'+code+'%26paypalField%3D*default*%26increment%3Dfalse','remote', 'left=50,top=50,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,status=no,resizable=yes,height=780,width=800');
}

function findAddress(address) {
	if(!$('showGoogle').checked)
	{
		$('googleFound').hide();

		$('googleMap').style.visibility='hidden';
		return;
	}
	$('googleFound').show();
	if (geocoder) {
		geocoder.getLatLng(
        	address,
        	function(point) {
				if (!point) {
					$('googleFound').innerHTML='<div class="warning" style="width:164px;margin-left:0;margin-right:0;">Address not found in google.</div>';
					$('googleMap').hide();
            	} else {
					$('googleFound').innerHTML='<div class="success" style="width:164px;margin-left:0;margin-right:0;">Address found in google.<br><a href="javascript:showGoogleMap($(\'location\').value)">View Map</a></div>';
            	}});
    }
    if(map) showGoogleMap(address);
}
function showGoogleMap(address,target) 
{
	if(!target) target='googleMap';
	if($('showGoogle'))
	{
		if(!$('showGoogle').checked)
		{
			$('googleFound').hide();
			$(target).style.visibility='hidden';
//			$('googleMap').hide();
			return;
		}
		$('googleFound').show();
	}
	if (GBrowserIsCompatible()){
map=null;
		if(!map)
		{
	      map = new GMap2(document.getElementById(target));
	      map.addControl(new GSmallMapControl());
	      map.addControl(new GScaleControl());
	    }
		if (geocoder) {
			geocoder.getLatLng(
	        	address,
	        	function(point) {
					if (!point) {
						if($('showGoogle'))
						{
							$('googleFound').innerHTML='<div class="warning" style="width:164px;margin-left:0;margin-right:0;">Address not found in google.</div>';
							$('googleMap').hide();
						}
	            	} else {
	            		if($(target))
	            		{
							$(target).show();
							$(target).style.visibility='visible';
	              		}
	              		map.setCenter(point, 14);
	               		var marker = new GMarker(point);
	               		map.addOverlay(marker);
	            	}});
		    }
    }
}
function getSelectCount(select){
	var counter=0;
	for (var i = 0; i < select.options.length; i++)
	if (select.options[i].selected)
		counter++;
	return counter;
}
var logoutTimer=null;
function resetLogoutTimer(code,reset)
{
	if(window!=window.parent && window.parent.resetLogoutTimer)
	{
		window.parent.resetLogoutTimer(code,reset);
		return;
	}	
	if(logoutTimer && !reset)
	{
		if(logoutTimer) clearTimeout(logoutTimer)
		if(!confirm('You will be timed out of this site due to inactivity in 5 minutes, click OK to reset the timer.')){
			logoutTimer=null;	
			return;
		}
		new Ajax.Request('ocd.aspx', {method: 'post',postBody: 'action=main&code='+code,onSuccess: function(transport){
			if(transport.responseText.match('please enter your password')){
				newwin=window.open('', 'admin_remote', 'left=50,top=50,toolbar=no,location=no,directories=no,menubar=no,scrollbars=auto,status=no,resizable=no,height=200,width=400');
				newwin.document.write('<HTML><HEAD><TITLE>Login</TITLE><link rel="StyleSheet" href="/defaults/modules.css" type="text/css" media="screen"/><link rel="StyleSheet" href="/defaults/allsites.css" type="text/css" media="screen"/><script type="text/javascript" src="/library/prototype.js"></script><script type="text/javascript" src="/library/core.js"></script></HEAD>'+
					'<body style="padding:20px"><form onsubmit="ajaxSuccess(\'ocd.aspx\',\'action=verify&code='+code+'&password=\'+$(\'password\').value,\'post\',\'resetLogoutTimer\',function(){window.close();},function(){alert(\'An error has occurred, please try again.\');});return false;">'+
					'<div class="info">You have been logged out, please enter your password.</div><div class="blank"><b>Password</b><br><input type="password" name="password" id="password"> <input class="ButtonSmall" type="submit" name="B1" value="&gt;"></div></form></body></HTML>');
			   newwin.document.close();
			}
		}});
	}
	if(logoutTimer) clearTimeout(logoutTimer)
	logoutTimer=setTimeout('resetLogoutTimer("'+ code +'",0);',25*60*1000);//1500
}

function ajaxSuccess(url,postBody,method,successText,onSuccess,onFail)
{
	
	var success=0;
	new Ajax.Request(url, {
		method: method,
		postBody: postBody,
		onSuccess: function(transport) {
			var response=transport.responseText,not=0;
			if(response.charAt(0)=='!'){
				not=1;
				response=response.substring(1);
			}
			if ((response.match(successText) && !not) || (not && !response.match(successText)))
				onSuccess(transport);
			else
				onFail(transport);
		},
		onFailure: function(transport){
			onFail(transport);
		}
	});
}

function enableDDIndex(checked,code)
{
	if(checked)
	{
		$$('#photoIndexContainer div.handle').each(function(obj){
			Effect.Appear(obj);
		});
		Sortable.create($('photoIndexContainer'),{
			tag:'div',overlap:'horizontal',only:'photoBoard',scroll:window,onUpdate: function() {
				new Ajax.Request('ocd.aspx' , {
					method: 'post',postBody:getFormData('indexForm')
				});
			}//,handle:'handle'
		});
	}
	else
	{
		$$('#photoIndexContainer div.handle').each(function(obj){
			Effect.Fade(obj);
		});
		Sortable.destroy($('photoIndexContainer'))
	}
}

function loadDragDrop(sortables,code){

	$('menuDragDrop').value='on'
	sections = $$('.photoBContainer,.photoMenuItem');
	$$('.photoBContainer div.handle').each(function(obj){Effect.Appear(obj);})
	sortables.each(function(sort){Sortable.create(sort,{tag:'div',handle:'handle',containment: sections,only:'tableWrapper',overlap:'horizontal',scroll:window,onUpdate: function() {new Ajax.Request('ocd.aspx' , {method: 'post',postBody:getPhotoBoardCats()+'&code='+code});}});})
	$$('.photoBContainer div.catHandle').each(function(obj){Effect.Appear(obj);})
	Sortable.create('categoriesContainer',{tag:'div',handle:'catHandle',only:'photoBContainer',scroll:window,onUpdate: function() {new Ajax.Request('ocd.aspx' , {method: 'post',postBody:getPhotoBoardCats()+'&code='+code});}});
}
function disableDragDrop(sortables){
	$('menuDragDrop').value=''
//	$('categoriesContainer').removeClassName('dragDrop');
	$$('.photoBContainer div.catHandle').each(function(obj){Effect.Fade(obj);})
	$$('.photoBContainer div.handle').each(function(obj){Effect.Fade(obj);})
	for(var i=0;i<sortables.length;i++)
		Sortable.destroy(sortables[i]);
	Sortable.destroy('categoriesContainer');
}

function movePhotos(from,to,code)
{
	var j,forms=$(from).getElementsByTagName('form'),postString='action=photo_categories&ajaxcontent=on&code='+code+'&dragdrop=on&';
	for(j=0;j<forms.length;j++)
	{
		var form=forms[j];
//		$(form).down('#pBoard2').value=unescape(to.id.substring(11));
//		$(form).down('#pBoard').selectedIndex=0;
		$(form).elements[7].value=unescape(to.id.substring(11));//7
		$(form).elements[6].selectedIndex=0;//6
		postString+=getFormData(form.name) + '&';
		if(from.id.indexOf('catCon')==-1) from.remove();		
	}
	if(from.id.indexOf('catCon')!=-1) from.remove();		
	new Ajax.Request('ocd.aspx' , {method: 'post',postBody:postString});
	document.forms.photoIndex.sub_dir.value=$('photoboardName').innerHTML;
	if($(to).down('noOfPhotos'))
	{
		$(to).down('#noOfPhotos').innerHTML=$(to).down('#noOfPhotos').innerHTML*1+j;
		setTimeout('Effect.Shake($$("#carousel_photoB #'+to.id+'")[0].down(".noOfPhotosContainer"));',500);
	}
//	Effect.Shake(to.down('.noOfPhotosContainer'));
}

function getPhotoBoardCats()
{
	var cats = $$('#categoriesContainer .photoBContainer'),postString='action=photo_categories&ajaxcontent=on&resetIndex=on&dragdrop=on&';
	for(var i=0;i<cats.length;i++)
	{
		var cat=$(cats[i]);
		var forms=cat.getElementsByTagName('form');
		for(var j=0;j<forms.length;j++)
		{
			var form=$(forms[j]),id;
			id=unescape(cat.down('div.photoboardTitle').innerHTML);
			form.elements[1].value=id;
			if($F(select=form.elements[11])!=id)
				select.selectedIndex=0;
			postString+=getFormData(form.name) + '&';
		}
	}
//	alert(postString);
	return postString;
}

function getMenuItems() {
	var items = $$('#menuEditContainer li.menu')
	var returnString = '';
	var i=1;
	items.each(function(item) {
		returnString+='menuItemText_' + i + '=' + escape(item.down().value) + '&menuItem_' + i++ + '=' + escape(item.id) + '&';
	});
	return 'action=editMenuItems&'+returnString;
}

function toolTip(o,m,c,type)//newHook,newStem,newOffset)
{
	if(typeof(Tip)=='undefined')
	{
		if(type==3) //was a click 
			window.parent.document.location.href='ocd.aspx'
		else if(m.indexOf("<a")==-1)
			$(o).observe('click',function(){alert(c+'\n\n'+m.replace(/<br>/gi,"\n"))});
		return;
	}
	var newStem,newHook,newOffset,newCloseButton=false,newHideAfter=1,newShowOn='mousemove';
	if(type==3)
	{
		newCloseButton=true;
		newHideAfter=0;
		newShowOn='click'
		newStem='topRight';
		newHook={tip:'topRight',target:'bottomRight'};
		newOffset={x: 0, y: 0};
	}
	else if(!type || type==1)//0=to mouse 1=to object corner
	{
		newStem='topLeft';
		newHook=(type)?{tip:'topLeft',target:'bottomRight'}:{tip:'topLeft',mouse: true};
		newOffset={ x: 0, y: type?10:10 };
	}
	else if(type==2) //2=no stem beneith middle
	{
		newStem='';
		newHook={ tip: 'topMiddle', mouse: true }
		newOffset={ x: 0, y: 5 };
	}
	var ob=new Tip(o, m, {
	    title : c,
		style: 'protoblue',
		hideOthers: true,
		stem: newStem?newStem:'',
		fixed: true,
		hook: newHook,
		offset: newOffset,
		hideOn: false, // disable the normal hide event, because we only want to use the hideAfter option
		hideAfter: newHideAfter,
		closeButton: newCloseButton,
		showOn: newShowOn
	});
	return ob;
}

function printFriendlyName(field)
{
	var fields= new Array();fields["fname"]="first name";fields["lname"]="last name";fields["emailaddr"]="email address";
	fields["dob"]="date of birth";fields["dob_day"]="day of birth";fields["dob_month"]="month of birth";fields["dob_year"]="year of birth";fields["res_mobile"]="mobile number";fields["res_street"]="address";fields["password_check"]="password confirmation";
	fields["fyear"]="peer year";
	if(fields[field]) return fields[field];
	else return field;
}

function echeck(str) {
	var at="@",dot=".",lat=str.indexOf(at),lstr=str.length,ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1) return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
	return true;
}

function checkRequiredFields(fields)
{
	var message='',first;
	$$('input.example').each(function(item) {
	  if(item.disabled!=true && item.value!='')
		item.value='';
	});
	fields=fields.split('\t');
	fields=fields.concat('fname,lname,fyear,password,password_check,secretQuestion1,secretAnswer1,secretQuestion2,secretAnswer2,dob_day,dob_month,dob_year'.split(','));
	fields=$A(fields).uniq();
	for(var i=0;i<fields.length;i++)
	{ 
		var item=fields[i];
		if($(item) && (($F(item)=='') || (fields[i]=='emailaddr' && !echeck($F(item)))))
		{
			if(!first) first=item;
			$(item).addClassName('notMatch');
			$(item).onkeydown=function(){$(this).removeClassName('notMatch')}
			if(fields[i]=='emailaddr') message+='You have not entered a valid email address, please confirm\n';
			else message+='You have not entered a value for your ' + printFriendlyName(item)+'\n';
		}
	}
	if(message!='')
	{
		alert(message);
		Effect.ScrollTo($(first).up());
		return false;
	}
	else 
		return true;
}

function citySelect(me,target,prepend)
{
	if(!target) target='countriesContainer';
	if(!me)
		submitAjax(target,0,0,0,0,0,0,0,"/reference/php/citiesdropdownlist/index.php?prepend="+prepend)
	else if (me.name == (prepend+"country")) {
		submitAjax(target,0,0,0,0,0,0,0,"/reference/php/citiesdropdownlist/index.php?countries=" + encodeURIComponent(me.value)+"&prepend="+prepend)
	}
	else if (me.name == (prepend+"state")) {
		submitAjax(target,0,0,0,0,0,0,0,"/reference/php/citiesdropdownlist/index.php?countries=" + encodeURIComponent(document.getElementById(prepend+"country").value) + "&states=" + encodeURIComponent(me.value)+"&prepend="+prepend)
	}
}

function setupPBoard(name){
var hCarousel_pBoard=new UI.Carousel(name);
}

function displayNetworking(name)
{
	$$('#networkingContainer .networkingItem').each(function(item) {
	  if(!($(item).down('input').value=='' || $(item).down('input').className.indexOf(' example')!=-1) || item.down('input').name==name)
	  {
	  	item.style.display='';
		$(item).down('input').disabled=false;
//		if(item.down('input').name==name) $(item).down('input').focus();
	  }
	  else
	  {
	  	item.style.display='none';
		$(item).down('input').disabled=true;
	  }
	});
}

function resizeLW(width,height)
{
	var contents,container;
	if($('lightwindow_contents'))
	{
		contents=$('lightwindow_contents');
		container=$('lightwindow_container');
	}
	else
	{
		contents=window.parent.$('lightwindow_contents');
		container=window.parent.$('lightwindow_container');
	}
	
	contents.style.width=width+'px';
	contents.style.height=height+'px';
	container.style.width=(width*1+20)+'px';
	container.style.height=(height*1+87)+'px';
	container.style.left= -((width+20)/2)+'px';
	container.style.top= -((height+87)/2)+'px';
}


function placeAll(text)
{
	if(!$('PBall').checked)
	{
		alert('You can only change all values if you have the appropriate selection in Step 1');
		return;
	}
	Ins = document.getElementsByTagName('input');
	Sels = document.getElementsByTagName('select');
	for (i=0;i<Sels.length;i++)
	if(Sels[i].name.indexOf('moveTo')==0)
	{
		var found=0;
		opts=Sels[i].options;
		for(j=0;j<opts.length;j++)
		{
			if(opts[j].text==text)
			{
				found=1;
				Sels[i].selectedIndex=j;
			}
		}
		if(!found) Sels[i].selectedIndex=0;
	}
	for ( i = 0; i < Ins.length; i++ )
	if ( Ins[i].type == 'text' && Ins[i].name.indexOf('moveTo')==0)
	Ins[i].value=text;
}
function slideUpDown(name,dir)
{
	if(typeof(name)!='object') name=$(name);
	if(name.visible())
	{
		if(dir!='down') Effect.SlideUp(name, { duration: 0.5 });
	}
	else
	{
		if(dir!='up') Effect.SlideDown(name, { duration: 0.5 });
	}
}

function setTeamSelect(r,g,t)
{
	var im0=$('cbi_r'+r+'g'+g+'t0');
	var cb0=$('cb_r'+r+'g'+g+'t0');
	var im1=$('cbi_r'+r+'g'+g+'t1');
	var cb1=$('cb_r'+r+'g'+g+'t1');
	var im2=$('cbi_r'+r+'g'+g+'d');
	var cb2=$('cb_r'+r+'g'+g+'d');
	if(!t)
	{
		im0.className='CBticked';
		cb0.checked=true;
	}else{
		im0.className='CBunticked';
		cb0.checked=false;
	}
	if(t==1)
	{
		im1.className='CBticked';
		cb1.checked=true;
	}else{
		im1.className='CBunticked';
		cb1.checked=false;
	}
	if(t==2 && im2 && cb2)
	{
		im2.className='CBticked';
		cb2.checked=true;
	}else if(im2 && cb2){
		im2.className='CBunticked';
		cb2.checked=false;
	}
	tippingChange=1;	
}
 function AddSelectOption(selectObj, text, value, isSelected) 
{
	if(typeof(selectObj)=='string') selectObj=$(selectObj);
    if (selectObj != null && selectObj.options != null)
    {
        selectObj.options[selectObj.options.length] = 
            new Option(text, value, false, isSelected);
    }
}

function printYears(selectObj,start,negoffset,posoffset)
{
	selectObj=$(selectObj);
	if(start || negoffset)
	{
		end=(new Date()).getYear();
		if(end<1000)
			end+=1900;
		if(negoffset)
			start=end-negoffset;
		if(posoffset)
			end+=posoffset;
		for (;end>=start;end--)
		{
//			document.write('<option>'+end);
			AddSelectOption(selectObj, end,end, false);
		}
	}
	else
	{
		start=(new Date()).getYear();
		if(start<1000)
			start+=1900;
		end=start+posoffset;
		for (;end>=start;start++)
		{
//			document.write('<option>'+start);
			AddSelectOption(selectObj, start,start, false);
		}
	}

}
function printCountries()
{//
if(_domainName.indexOf('eu.')==-1)
{
	c = new Array('Afghanistan','Albania','Algeria','Andorra','Angola','Antarctica','Antigua and Barbuda','Argentina','Armenia','Australia','Austria','Azerbaijan','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bhutan','Bolivia','Bosnia and Herzegovina','Botswana','Brazil','Brunei','Bulgaria','Burkina Faso','Burma (Myanmar)','Burundi','Cambodia','Cameroon','Canada','Cape Verde','Cayman Islands','Central African Republic','Chad','Chile','China','Colombia','Comoros','Congo, Republic of','Costa Rica','Cote d\'Ivoire','Croatia','Cuba','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','Fiji','Finland','France','French Guiana','Gabon','Georgia','Germany','Ghana','Greece','Greenland (Kalaallit Nunaat)','Grenada','Guatemala','Guinea','Guinea-Bissau','Guyana','Haiti','Honduras','Hong Kong','Hungary','Iceland','India','Indonesia','Iran','Iraq','Ireland','Israel','Italy','Ivory Coast (Cote d\'Ivoire)','Jamaica','Japan','Jordan','Kazakstan','Kenya','Kiribati','Korea, North','Korea, South','Kuwait','Kyrgyzstan','Laos','Latvia','Lebanon','Lesotho','Liberia','Libya','Liechtenstein','Lithuania','Luxembourg','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Marshall Islands','Mauritania','Mauritius','Mexico','Micronesia','Moldova','Monaco','Mongolia','Morocco','Mozambique','Myanmar','Namibia','Nauru','Nepal','Netherlands','New Zealand','Nicaragua','Niger','Nigeria','Norway','Oman','Pakistan','Palau','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Poland','Portugal','Qatar','Romania','Russia','Rwanda','Sain','Saint Kitts and Nevis','Saint Lucia','Saint Vincent and the Grenadines','Samoa','San Marino','Sao Tome and Principe','Saudi Arabia','Senegal','Serbia and Montenegro','Seychelles','Sierra Leone','Singapore','Slovakia (Slovak Republic)','Slovenia','Solomon Islands','Somalia','South Africa','Spain','Sri Lanka','Sudan','Suriname','Swaziland','Sweden','Switzerland','Syria','Taiwan','Tajikistan','Tanzania','Thailand','The Bahamas','The Gambia','Timor-Leste','Togo','Tonga','Trinidad and Tobago','Tunisia','Turkey','Turkmenistan','Tuvalu','Uganda','Ukraine','United Arab Emirates','United Kingdom','United States of America','Uruguay','Uzbekistan','Vanuatu','Vatican City','Venezuela','Vietnam','Yemen','Zambia','Zimbabwe')
	t = new Array(9,31,60,75,127,189);
}
else
{
	c = new Array('Afghanistan','Albania','Algeria','American Samoa','Andorra','Angola','Anguilla','Antigua and Barbuda','Argentina','Armenia','Aruba','Australia','Austria','Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia and Herzegovina','Botswana','Brazil','Brunei Darussalam','Bulgaria','Burkina Faso','Burundi','Cambodia','Cameroon','Canada','Cape Verde','Cayman Islands','Central African Republic','Chad','Chile','China','Christmas Island','Colombia','Comoros','Congo','Congo, The Democratic Republic of the','Cook Islands','Costa Rica','Cote d\'Ivoire','Croatia','Cuba','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','Falkland Islands (Malvinas)','Faroe Islands','Fiji','Finland','France','French Guiana','French Polynesia','Gabon','Gambia','Georgia','Germany','Ghana','Gibraltar','Greece','Greenland','Grenada','Guadeloupe','Guam','Guatemala','Guernsey','Guinea','Guinea-Bissau','Guyana','Haiti','Holy See (Vatican City State)','Honduras','Hong Kong','Hungary','Iceland','India','Indonesia','Iran, Islamic Republic of','Iraq','Ireland','Isle of Man','Israel','Italy','Jamaica','Japan','Jersey','Jordan','Kazakhstan','Kenya','Kiribati','Korea, Democratic People\'s Republic of','Korea, Republic of','Kuwait','Kyrgyzstan','Lao People\'s Democratic Republic','Latvia','Lebanon','Lesotho','Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania','Luxembourg','Macao','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Marshall Islands','Martinique','Mauritania','Mauritius','Mayotte','Mexico','Micronesia, Federated States of','Moldova, Republic of','Monaco','Mongolia','Montenegro','Montserrat','Morocco','Mozambique','Myanmar','Namibia','Nepal','Netherlands','Netherlands Antilles','New Caledonia','New Zealand','Nicaragua','Niger','Nigeria','Niue','Norfolk Island','Norway','Oman','Pakistan','Palau','Palestinian Territory','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn','Poland','Portugal','Puerto Rico','Qatar','Reunion','Romania','Russian Federation','Rwanda','Saint Helena','Saint Kitts and Nevis','Saint Lucia','Saint Pierre and Miquelon','Saint Vincent and the Grenadines','Samoa','San Marino','Sao Tome and Principe','Saudi Arabia','Senegal','Serbia','Seychelles','Sierra Leone','Singapore','Slovakia','Slovenia','Solomon Islands','Somalia','South Africa','South Georgia and the South Sandwich Islands','Spain','Sri Lanka','Sudan','Suriname','Svalbard and Jan Mayen','Swaziland','Sweden','Switzerland','Syrian Arab Republic','Taiwan','Tajikistan','Tanzania, United Republic of','Thailand','Timor-Leste','Togo','Tonga','Trinidad and Tobago','Tunisia','Turkey','Turkmenistan','Turks and Caicos Islands','Tuvalu','Uganda','Ukraine','United Arab Emirates','United Kingdom','United States','Uruguay','Uzbekistan','Vanuatu','Venezuela','Vietnam','Virgin Islands, British','Virgin Islands, U.S.','Western Sahara','Yemen','Zambia','Zimbabwe');
}
	var i,ar=$A(arguments),showH=0,home=9;
	var selectObj=ar.shift();
	if((showH=(ar[0]=='Y' || ar[0]=='y')) || ar[0]=='N' || ar[0]=='n') i=1;
	else if((showH=(ar[1]=='Y' || ar[1]=='y')) || ar[1]=='N' || ar[1]=='n'){
		if((home=ar[0]).length>2) home=c.indexOf(ar[0]);
		i=2;}
	else i=(showH=0);
//If no arguements, print default pre-list//
	if(i==ar.length){ for(i=0;t[i];i++) if (t[i]!=home || showH) AddSelectOption(selectObj, c[t[i]], c[t[i]], false);}
	else for (i; i < ar.length; i++) AddSelectOption(selectObj, c[ar[i]], c[ar[i]], false);
	AddSelectOption(selectObj, '-----------------------------------', ' ', false);
	for(i=0;c[i];i++) if (i!=home || showH) AddSelectOption(selectObj, c[i], c[i], false);
}

var currentSelectID,printedDocWrite=0;
function loadContent(formName)
{
	if(Tips)Tips.hideAll();
	if($('mainContent'))
	{
		var postBody;
		if(document.forms[formName])
			postBody=getFormData(formName)+'&ajaxContent=on';
		else
			postBody=formName+'&ajaxContent=on';
		if($('listContainer') && postBody.indexOf('ajax=on')!=-1)
			targetDiv='listContainer';
		else
			targetDiv='mainContent';
		document.write = function(text){ if(_domainName=="proof.ptly.com" && (!printedDocWrite++)) alert(currentSelectID + ' - ' + text); };
		if($('contentOverlay') && targetDiv=='mainContent')
		{
			$('contentOverlay').up().style.position='relative';
			$('contentOverlay').style.zIndex=3000;
			Effect.Appear('contentOverlay',{from:0,to:0.7});
			$('contentLoading').style.zIndex=3001;
			Effect.Appear('contentLoading',{duration: 3});
		}
		if(document.forms[formName])
			new Ajax.Updater(targetDiv, 'ocd.aspx', {asynchronous:true,evalScripts:true,method:'post',postBody:postBody,afterFinish:function(){$('contentOverlay').up().style.position=''; }});
		else if(postBody.indexOf('?')!=-1)
			new Ajax.Updater(targetDiv, postBody, {asynchronous:true,evalScripts:true,afterFinish:function(){$('contentOverlay').up().style.position=''; }});
		else
			new Ajax.Updater(targetDiv, 'ocd.aspx?'+postBody, {asynchronous:true,evalScripts:true,afterFinish:function(){$('contentOverlay').up().style.position=''; }});
	}
	else if(document.forms[formName])
		document.forms[formName].submit();
	else if(formName.indexOf('?')!=-1)
		document.location.href=formName+'&ajaxContent=on';
	else
		document.location.href='ocd.aspx?'+formName+'&ajaxContent=on';
	return true;
}

function slideList(panel,mod,li,inc,dontTO)
{
	if(!inc) inc=1;
	for(var This=$('list_'+panel+'_'+mod+'_'+li);This && This.style.display=='none';This=$('list_'+panel+'_'+mod+'_'+(++li)));
	if(!This)
		var This=$('list_'+panel+'_'+mod+'_'+(li=0));
	var Next;
	if(!(Next=$('list_'+panel+'_'+mod+'_'+(li+=inc))))
	{
		if(inc==1) Next=$('list_'+panel+'_'+mod+'_'+(li=0));
		else for(Next=$('list_'+panel+'_'+mod+'_'+(li=0));$('list_'+panel+'_'+mod+'_'+(li*1+1));Next=$('list_'+panel+'_'+mod+'_'+(li++)));
	}
	if(!Next)
		return;
	if(inc>0)
	{
		var i;
		if((i=(Next.style.left.replace("px","")))>2 && i<300)
		{
			slideList(panel,mod,li,inc,dontTO);
			return;
		}
		Next.style.left='300px';
		Next.style.zIndex='2';
		Next.show();
		This.style.zIndex='1';
		Next.morph('left:2px');
//		Next.morph('left:8px',{duration: 3,transition:Effect.Transitions.spring});
		setTimeout('$("'+This.id+'").hide();',1000);
	}
	else
	{
		Next.style.zIndex='1';
		This.style.zIndex='2';
		Next.show();
		Next.style.left='2px';
		This.morph('left:300px');
//		This.morph('left:300px',{duration: 3,transition:Effect.Transitions.spring});
		setTimeout('$("'+This.id+'").hide();',3000);
	}
	if(!dontTO)
		window['l_'+mod]=setTimeout('slideList(0,\''+mod+'\','+li+');',5000);
	return;
}

function setupActiveSearch(code)
{
	new Ajax.Autocompleter
	(
		"autocomplete", "autocomplete_choices", "ocd.aspx",
		 {
		 	minChars: 3
		 	,parameters:'code='+code+'&action=autocomplete&search_exact=not'
		 	,afterUpdateElement : getSelectionId
		 	,indicator: 'autoSearchLoading'
	 });
}

function transMod(T,mod,s)
{
	var last=eval('l_'+mod),This='mod_'+last+'_'+mod,Next,type=T;
	if(!$(Next='mod_'+(++last)+'_'+mod))
		Next='mod_'+(last=1)+'_'+mod;
	$(This).absolutize();
	$(This).style.top='0px'
	if(!type) type=Math.floor(Math.random()*6)+1;
	switch(type)
	{
		case 1:
			Effect.Fade(This,{duration: 2});
			Effect.Appear(Next,{duration: 2,afterFinish: function() { resetMods(mod); }});
			break;
		case 2:
			Effect.Puff(This,{duration: 2});
			Effect.Appear(Next,{duration: 2,afterFinish: function() { resetMods(mod); }});
			break;
		case 3:
			Effect.DropOut(This,{duration: 2});
			Effect.BlindDown(Next,{duration: 2,afterFinish: function() { resetMods(mod); }});
			break;
		case 4:
			Effect.Shrink(This,{duration: 1.5});
			Effect.Grow(Next,{delay: 1,duration: 1.5,afterFinish: function() { resetMods(mod); }});
			break;
		case 5:
			Effect.SwitchOff(This,{duration: 2});
			Effect.BlindDown(Next,{duration: 2,delay: 1,afterFinish: function() { resetMods(mod); }});
			break;
		case 6:
			Effect.DropOut(This,{duration: 1.5});
			Effect.SlideDown(Next,{delay:1,duration: 3,transition:Effect.Transitions.Elastic,afterFinish: function() { $(Next).relativize();resetMods(mod); }});
			break;
	}
	window['l_'+mod]=last;
	setTimeout('transMod('+T+',"'+mod+'",'+s+')',(s||10)*1000);
}
// Elastic (adapted from "EaseOutElastic") divided by 2 to reduce overshoot
Effect.Transitions.Elastic = function(pos) {
    return -1*Math.pow(4,-8*pos) * Math.sin((pos*6-1)*(2*Math.PI)/2) + 1;
};
function resetMods(mod)
{
return;
	var p;
	for(var j=1;m=$('mod_'+j+'_'+mod);j++)
		with(m)
		{
			if(style.position=='absolute')
			{
				if(!p)p=$(m.parentNode);
//				style.left=(p.cumulativeOffset()[0]+2*1)+'px';
//				style.top=p.cumulativeOffset()[1]+'px';
			}
			else
			{
				style.left='0px';
				style.top='0px';
			}
		}
}
function getSelectionId(text, li)
{
	form=findObj('autoCompleteForm');
//alert(li.id);
	if(li.id)
	{
		form.ref_no.value=li.id;
		form['fname || lname || preferred name || flname || bus_institution || res_country'].value='';
	}
	form.submit();
}

var Editor =function()
{
	this.getHTML = function() {
		var oEditor = FCKeditorAPI.GetInstance('htmlmessage') ;
		return oEditor.GetXHTML();
	}
	this.focusEditor = function(text) {
	}
	this.setMode = function() {
	}
	this.config = function() {
		this.baseURL=null;
	}
	this.insertHTML = function(text) {
		var oEditor = FCKeditorAPI.GetInstance('htmlmessage') ;
		oEditor.InsertHtml(text);
	}
	this.setHTML = function(text) {
		var oEditor = FCKeditorAPI.GetInstance('htmlmessage') ;
		oEditor.SetHTML(text);
	}	
}
//editorconfig = function () {
//	this.baseURL=null;
//}
editor = new Editor;

function showImageAbove(imghref,height,modName)
{
	var img,txt;
	if(imghref)
	{
		(img=$('carousel_'+modName)).innerHTML='<div style="text-align:center"><img style="margin:auto" src="' + imghref + '" height='+height+'/></div>';
		img.style.visibility='';
		$('carouselText_'+modName).hide();
	}
	else
	{
		$('carousel_'+modName).style.visibility='hidden';
		$('carouselText_'+modName).show();
	
	}
}
function slideUL(name,start)
{
	if(!$(name))
	{
		alert('no list by name -' +name);
		return;
	}
	this.listNo=0;
	this.timeOut=null;
	this.c=$(name);
	this.rows=this.c.getElementsByTagName('li');
	if(this.c.style.position!='absolute')
		this.c.style.position='relative';
	for(var i=1;i<this.rows.length;i++)
		$(this.rows[i]).hide();
	this.setDim=function()
	{	
		this.c.style.width=this.c.getWidth()+'px';
		this.c.style.height=this.c.getHeight()+'px';
		this.c.style.overflow='hidden';
		this.y=$(this.rows[0]).positionedOffset()[0]+'px';
		this.x=this.rows[0].positionedOffset()[1]+'px';
		for(var i=0;i<this.rows.length;i++)
		{
			with($(this.rows[i]))
			{
				style.width=getWidth()+'px';
				style.height=getHeight()+'px';
				style.position='absolute';
				if(i!=0) hide();
			}
		}
	}
	this.i=function()
	{	
		var t=this.rows[this.listNo];
		this.listNo=(++this.listNo)%this.rows.length;
		var n=this.rows[this.listNo];
		n.style.left='300px';
		if(!this.y) this.setDim();
		n.style.top=this.y;
		n.style.zIndex='2';
		n.show();
		t.style.zIndex='1';
		n.morph('left:'+ this.x);
		t.fade({delay:.4});
	}
	this.d=function()
	{	
		var t=this.rows[this.listNo];
		if(--this.listNo<0) this.listNo=this.rows.length-1;
		var n=this.rows[this.listNo];
		n.style.zIndex='1';
		t.style.zIndex='2';
		if(!this.y) this.setDim();
		n.style.top=this.y;
		n.hide();
		n.style.left=this.x;
		t.morph('left:300px');
		n.appear();
	}
	this.p=function()
	{
		clearTimeout(this.timeOut)
	}
	this.s=function()
	{
		if(this.listNo<0 || this.listNo>this.rows.length)
			alert('error - no ' + this.listNo)
		if(this.rows.length==1)
			return;
		this.TO;
	} 
	this.TO=function()
	{
		this.timeOut=setInterval(function(obj){return(function(){obj.i();});}(this), 5000); //this uses closure apparently...
	}
	if(start)
		this.TO();
}

function imageOver(image,over)
{
	src=image.src;
	var last=src.substring(src.lastIndexOf('.'));
	if(over)
	{
		var first=src.substring(0,src.lastIndexOf('.'));
		image.src=first+'_over'+last;
	}
	else
	{
		var first=src.substring(0,src.lastIndexOf('_over'));
		image.src=first+last;
	}
}

if (typeof Effect == 'undefined')
	throw("accordion.js requires including script.aculo.us' effects.js library!");
 
var accordion = Class.create();
accordion.prototype = {
 
	//
	// Setup the Variables
	//
	showAccordion : null,
	currentAccordion : null,
	duration : null,
	effects : [],
	animating : false,
	 
	//
	// Initialize the accordions
	//
	initialize: function(container, options) {
		if (!$(container)) {
			throw(container+" doesn't exist!");
			return false;
		}
	
		this.options = Object.extend({
		resizeSpeed : 8,
		classNames : {
			toggle : 'accordion_toggle',
			toggleActive : 'accordion_toggle_active',
			content : 'accordion_content'
		},
		defaultSize : {
			height : null,
			width : null
		},
		direction : 'vertical',
		onEvent : 'click'
		}, options || {});
		 
	this.duration = ((11-this.options.resizeSpeed)*0.15);
 
	var accordions = $$('#'+container+' .'+this.options.classNames.toggle);
	accordions.each(function(accordion) {
		Event.observe(accordion, this.options.onEvent, this.activate.bind(this, accordion), false);
		if (this.options.onEvent == 'click') {
			accordion.onclick = function() {return false;};
		}
		if (this.options.onEvent == 'mouseover') { //if activates on mouseover, enable onclick override as well
			Event.observe(accordion, 'click', this.activate.bind(this, accordion), false);
		}
 
		if (this.options.direction == 'horizontal') {
			var options = {width: '0px', display:'none'};
		} else {
			var options = {height: '0px', display:'none'};
		}
		// options.merge({display: 'none'});
 
		this.currentAccordion = $(accordion.next(0)).setStyle(options);
	}.bind(this));
},
 
//
// Activate an accordion
//
	activate : function(accordion) {
		if (this.animating) {
			return false;
		}
 
		this.effects = [];
		this.currentAccordion = $(accordion.next(0));
		this.currentAccordion.setStyle({
			display: 'block'
		});
 
		this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive);
 
		if (this.options.direction == 'horizontal') {
			this.scaling = $H({
				scaleX: true,
				scaleY: false
			});
		} else {
			this.scaling = $H({
				scaleX: false,
				scaleY: true
			});
		}
		if (this.currentAccordion == this.showAccordion) {
			if (this.options.onEvent == 'mouseover')
				return;
			this.deactivate();
		} else {
			this._handleAccordion();
		}
	},
//
// Deactivate an active accordion
//
	deactivate : function() {
		var options = $H({
			duration: this.duration,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			queue: {
				position: 'end',
				scope: 'accordionAnimation'
			},
			scaleMode: {
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			},
			afterFinish: function() {
				this.showAccordion.setStyle({
				height: 'auto',
				display: 'none'
			});
			this.showAccordion = null;
			this.animating = false;
		}.bind(this)
	});
// options.merge(this.scaling);
 
	this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
 
	new Effect.Scale(this.showAccordion, 0, options.update(this.scaling).toObject());
},
 
//
// Handle the open/close actions of the accordion
//
_handleAccordion : function() {
	var options = $H({
		sync: true,
		scaleFrom: 0,
		scaleContent: false,
		transition: Effect.Transitions.sinoidal,
		scaleMode: {
			originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
			originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
		}
	});
	options.merge(this.scaling);
 
	this.effects.push(
		new Effect.Scale(this.currentAccordion, 100, options.update(this.scaling).toObject())
	);
 
	if (this.showAccordion) {
		this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
 
		options = $H({
			sync: true,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal
		});
		options.merge(this.scaling);
	 
		this.effects.push(
			new Effect.Scale(this.showAccordion, 0, options.update(this.scaling).toObject())
		);
	}
 
	new Effect.Parallel(this.effects, {
		duration: this.duration,
		queue: {
			position: 'end',
			scope: 'accordionAnimation'
		},
		beforeStart: function() {
			this.animating = true;
		}.bind(this),
		afterFinish: function() {
			if (this.showAccordion) {
				this.showAccordion.setStyle({
					display: 'none'
				});
			}
			$(this.currentAccordion).setStyle({
				height: 'auto'
			});
			this.showAccordion = this.currentAccordion;
			this.animating = false;
		}.bind(this)
	});
}
}
Event.observe(window, 'load', function(){window.isLoaded=true}, false);
