quote='"';
popup='popup';
empty='';
wopts = 'location=no,toolbar=no,status=no,menubar=no,resizable=yes,width=260,left=200,top=200,scrollbars=yes,height=';
wopts2 = 'location=no,toolbar=no,status=no,menubar=no,resizable=yes,width=500,left=100,top=100,scrollbars=yes,height=';
ropts = 'location=no,toolbar=no,status=no,menubar=no,resizable=yes,width=260,left=200,top=200,scrollbars=no,height=';
purl = '/prop.htm?t';

if( !window.XMLHttpRequest ) XMLHttpRequest = function(){
	try{ return new ActiveXObject("MSXML3.XMLHTTP") }catch(e){}
	try{ return new ActiveXObject("MSXML2.XMLHTTP.3.0") }catch(e){}
	try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
	try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
	alert('Your browser does not support XMLHTTP');
	return null;
}

function cancelEvent(e) {
	if (e && e.stopPropagation) e.stopPropagation(); else event.cancelBubble=true;
}

function newcpt() {
	window.open(empty,popup,wopts+360).focus();
}

function edit(e,id) {
	if (id)	{
		window.open('/prop.aspx?'+id,popup,wopts+360).focus();
		cancelEvent(e);
	}
}

function imgchg(id) {window.open('/images.aspx?i='+id,popup,wopts2+400).focus();}

function do_http(url) {
	var xmlHttp = new XMLHttpRequest();
	if (xmlHttp!=null) {
		xmlHttp.open('GET', url,false);
		xmlHttp.send(null);
		if (xmlHttp.reponseText!=null) alert(xmlHttp.responseText); else return true;
	}
}

function del(bt,pk,id) {
	if (confirm('Are you sure?')) {
		if (do_http('/del.aspx?table='+bt+'&'+pk+'='+id)) {
			if ((window.location.pathname+'?').indexOf('/'+id+'?')>-1 && document.referrer) window.location.replace(document.referrer);
			else window.location.replace(window.location.href);
		}
	}
}

function rate(me,id,r) {
	if (do_http('/rate.aspx?ID='+id+'&Rating='+r)) me.parentNode.style.backgroundImage='url(/Images/'+r+'star.png)';
}

function approve(me,id) {
	do_http('/approve.aspx?ID='+id+'&Approved='+(me.checked?1:0));
}

var voted = '';
function vote(id) {
	if (do_http('/vote.aspx?ID='+id+voted)) window.location.replace(window.location.href);
}

function len(t,n) {
	if (t.value.length>n) t.value=t.value.substr(0,n); //Maximum length is n
}

function key(e) {
	return (e.which||e.keyCode) != 60; //Don't allow <
}

function ifont(me) {
	me = me.parentNode.currentStyle;
	return me.fontStyle + ' ' + me.fontWeight + ' ' + me.fontSize + ' ' + me.fontFamily;
}

function checkForm(me) {
	var f;
	if (me.TandCs && !me.TandCs.checked) {alert('You must accept the Terms & Conditions'); return false;}
	for (var i=0; f=me[i]; i++) if (f.title.substr(0,1)=='*' && (f.value==null || f.value=='')) {alert('Please complete '+f.title.substr(1)); return false;}
}

var dragObject,dragHeader,xStart,dropLast;

function dinit(root) {
	if (root==null) {
		root=document;
		document.onmousedown=drag;
		document.onselectstart=function(e) {return !dragObject;};
		document.ondragstart=function(e) {return !dragObject;};
		document.onmouseup=dstop;
//		document.body.style.cursor='default';
	}
	var divs = root.getElementsByTagName('div'), tds=root.getElementsByTagName('td');
	for (var i=0; n=divs[i]; i++) if (n.id && n.className.substr(0,9)=='Item Move') {
		n.onmousemove=function(e) {dropon(e,this); return false;};
		if (document.images.sizer && n.title.indexOf('Styler')<0) n.onmouseover=function(e) {if (!dragObject) this.appendChild(document.images.sizer); cancelEvent(e);}
	}
	for (var i=0; n=tds[i]; i++) if (n.id) n.onmousemove=function(e) {dropon(e,this);};

	var tas = root.getElementsByTagName('textarea');
	for (var i=0;i<tas.length;i++) resize(tas[i]); // loop through all textareas sizing them
}

function dstop(e) {
	xStart = null;
	document.onmousemove = null;
	if (dragObject) {
		dragObject.className=dragObject.className.replace(' drag','');
		dragObject=null;
		dropLast=null;
		document.body.style.cursor='default';
	}
}

function drag(e) {
	var target = e ? e.target : window.event.srcElement;
	if (target==document.images.sizer) {xStart = (e ? e.clientX : window.event.clientX)-target.parentNode.offsetWidth; document.onmousemove = sizerMove;}
	if (target.nodeName=='IMG' || target.nodeName=='SPAN') target=target.parentNode;
	if (target.className.substr(0,9)!='Item Move') return true;
    dragObject = target;
	dragHeader = document.getElementById(target.id+'h');
	target.className += ' drag';
	document.body.style.cursor=xStart ? 'w-resize' : 'move';
	return false;
}

function dropon(e,me) {
	if (xStart) return;
	if (!dragObject || dragObject==me || dropLast==me) {cancelEvent(e); return;}
	if (me.parentNode.title.split(':')[0]==dragObject.parentNode.title.split(':')[0]) {
		dropLast=me;
		if (me.previousSibling==dragObject) me.parentNode.insertBefore(dragObject,me.nextSibling);
		else me.parentNode.insertBefore(dragObject,me);
		var myHeader = document.getElementById(me.id+'h');
		if (me.nodeName=='TD' && myHeader && dragHeader) {
			if (myHeader.previousSibling==dragHeader) myHeader.parentNode.insertBefore(dragHeader,myHeader.nextSibling);
			else myHeader.parentNode.insertBefore(dragHeader,myHeader);
		}
		cancelEvent(e);
	}
	else if (dragObject!=me.lastChild && me.title.split(':')[0]==dragObject.parentNode.title.split(':')[0]) {
		dropLast=me;
		me.appendChild(dragObject);
		cancelEvent(e);
	}
}

function delcpt(me) {
	var hider = document.getElementById('x0');
	hider.appendChild(me);
	var myHeader = document.getElementById(me.id+'h');
	if (myHeader) hider.appendChild(myHeader);
}

function resize(me) {
	me.style.height='10px';
	me.style.height=me.scrollHeight+'px';
}

function sizerMove(e) {
	if (!dragObject || !xStart) return true;
	e = e ? e : window.event;
	var d = (e.clientX-xStart)*100 / dragObject.parentNode.clientWidth;
	if (d>=100) {
		dragObject.style.width = '';
		if (typeof dragObject.style.styleFloat != 'undefined') dragObject.style.styleFloat=''; else dragObject.style.cssFloat='';
		dragObject.style.clear='';
	} else {
		dragObject.style.width = d.toFixed(3) + '%';
		if (typeof dragObject.style.styleFloat != 'undefined') dragObject.style.styleFloat='left'; else dragObject.style.cssFloat='left';
		dragObject.style.clear='none';
	}
	return false;
}

function setInfo() {
	var info='', sep=String.fromCharCode(1), nl=String.fromCharCode(2);
	var divs = document.getElementsByTagName('div'), tds=document.getElementsByTagName('td');
	var bid = document.body.id;
	if (bid) info+=bid.substr(1)+sep+parentsId(document.getElementById('s'+bid.substr(1)))+sep+document.body.style.cssText.toLowerCase()+nl;
	for (var i=0; c=divs[i]; i++) if (c.id && c.className.substr(0,4)=='Item') {
		info+=c.id.substr(1)+sep+parentsId(c)+sep+c.style.cssText.toLowerCase();
		if (c.className.substr(0,9)=='Item Move') info+=sep+c.className.substr(10)+nl; else info+=nl;
	}
	for (var i=0; c=tds[i]; i++) if (c.id && c.className.substr(0,4)=='Item') {
		info+=c.id.substr(1)+sep+parentsId(c)+sep+c.style.cssText.toLowerCase();
		if (c.className.substr(0,9)=='Item Move') info+=sep+c.className.substr(10)+nl; else info+=nl;
	}
	document.getElementById('design_id').value = info;
}

function parentsId(n) {
	if (n) while (n=n.parentNode) if (n.id) return n.id.substr(1);
}

var tickers;
function setTickers() {
	tickers = document.getElementsByTagName('tt');
	if (tickers[0]) setInterval('tick()',300);
}

function tick() {
	var ticker;
	for(var i=0; ticker=tickers[i]; i++) {
		var x = ticker.offsetLeft;
		if (x+ticker.offsetWidth<0) x = ticker.parentNode.offsetWidth;
		ticker.style.left = (x-20)+'px';
	}
}

function clear_back() {document.cookie='_back=';}
function set_back() {document.cookie='_back='+escape(location.href);}

function setback() {
	var els = document.getElementsByTagName('a');
	for(var i=0; el=els[i]; i++) if (el.className=='setback') el.onclick=set_back;
}

function replaceCite(){
	var els = document.getElementsByTagName('cite');
	for(var i=0; el=els[i]; i++) replaceElement(el);
}

function replaceElement(el){
	var c = el.style.color || document.defaultView ? document.defaultView.getComputedStyle(el, null).color : el.currentStyle ? el.currentStyle.color : '#000001';
	if(c.indexOf('rgb') > -1) c = '#'+eval(c);
	else if(c.length == 4) c = '#'+c.charAt(1)+c.charAt(1)+c.charAt(2)+c.charAt(2)+c.charAt(3)+c.charAt(3);
	var sVars = 'txt='+escape(el.innerHTML).replace(/%B4/g,'%27')+'&amp;textcolor='+c+'&amp;w='+el.offsetWidth+'&amp;h='+el.offsetHeight;
	temp = el.innerHTML = '<object type="application/x-shockwave-flash" data="/flash/kinship.swf" style="width:'+el.offsetWidth+'px;height:'+el.offsetHeight+'px"><param name="movie" value="/flash/kinship.swf"/><param name="flashvars" value="'+sVars+'"/><param name="wmode" value="transparent"/>'+el.innerHTML+'</object>';
}

function Hex2(d){
	var d = parseInt(d);
	if (isNaN(d)) return '00'; else return '0123456789abcdef'.charAt(d>>4) + '0123456789abcdef'.charAt(d&15);
}

function rgb(r,g,b){
	return Hex2(r)+Hex2(g)+Hex2(b);
}

var tfixclose='';
function tfix(){
	if (tfixclose=='') {document.write('<table class="main">'); tfixclose='</table>';}
}

function tdfix(){
	if (tfixclose=='') {document.write('<table class="Item Move main">'); tfixclose='</table>';}
}

function flashfix(){
	var obj,objs = document.getElementsByTagName('object');
	for(var i=0;obj=objs[i];i++) obj.parentNode.innerHTML = obj.parentNode.innerHTML;
}

function getTickEmails(bAll) {
	var i, e='mailto:', tes=document.getElementsByName('tickEmail');
	for(i=0; i<50 && (te=tes[i]); i++) if (bAll || te.checked) e+=te.value+',';
	if (tes[i]) alert('Too many email addresses: only using first 50')
	return e;
}

function digits_only(e) {
	var c=e.which||e.keyCode;
	return c==8 || c==127 || (c>=48 && c<=57); //Only allow BS, DEL and digits
}

function chars_only(e) {
	var c=e.which||e.keyCode;
	return c==8 || c==127 || (c>=48 && c<=57) || (c>=97 && c<=122) || (c==45) || (c==46); //Only allow BS, DEL, digits and domain chars
}

function file_only(e) {
	var c=e.which||e.keyCode;
	return c==8 || c==127 || (c>=48 && c<=57) || (c>=97 && c<=122) || (c==45) || (c==95); //Only allow BS, DEL, digits and file chars
}

function domcheck(me) {
	var i = me.getElementsByTagName('img')[0];
	i.src = 'http://'+document.getElementsByName('DomainName')[0].value+'/Images/tick.gif';
}

function init() {
	if (window.location.search.indexOf('&_design=')>-1) dinit(); else {setback(); replaceCite(); setTickers(); shrinkImages(); linkWeb();findSearchDiv();}
	if (location.search.indexOf("_loginfail")>-1) alert("Username or Password not recognised");
}

function linkWeb() {
	//loop through div elements looking for ones with Item Description or Item About
	var div_list=document.getElementsByTagName('div');
	for(var i=0; check_div=div_list[i]; i++) if (check_div.className=='Item Description' || check_div.className=='Item About'){
		if (check_div.innerHTML.indexOf('<textarea')==-1) check_div.innerHTML=check_div.innerHTML.replace(/(http:\/\/\S+)/g, '<a href="$1">$1</a>').replace(/>(http:\/\/\S+)<\/a> \[([^\]]+)\]/g, '>$2</a>');			
		}

	var td_list=document.getElementsByTagName('td');
	for(var i=0; check_td=td_list[i]; i++) if (check_td.className=='Item Description' || check_td.className=='Item About'){
		if (check_td.innerHTML.indexOf('<textarea')==-1) check_td.innerHTML=check_td.innerHTML.replace(/(http:\/\/\S+)/g, '<a href="$1">$1</a>').replace(/>(http:\/\/\S+)<\/a> \[([^\]]+)\]/g, '>$2</a>');			
		}
}

function set_select(n,v,d) {
	var s = document.getElementsByName(n)[0];
	if (s) s.innerHTML=('<option>'+v.replace(/,/g,'</option><option>')+'</option>').replace('<option>'+d+'</option>','<option selected>'+d+'</option>');
}

function setImage(n) {
	var el=document.getElementsByName('Image')[0];
	if (!el) el=document.getElementsByName('Main_image')[0];
	if (el) {el.value=n; document.images['img_'+el.name].src=n;}
}

function shrinkImages() {
		var els=document.getElementsByTagName('img');
		for(var i=0; el=els[i]; i++) if ((p=el.parentNode).className=='Item Shrink' || (p=p.parentNode).className=='Item Shrink') {
			var n=100;
			while (n && p.scrollHeight>p.clientHeight) el.style.width=(n=n-2)+'%';
		}
}

function opts(a,c,n) {
document.write('<option value="">-</option>');
var add=true;
var cl=c.toLowerCase().replace(/,\s/g,',');
for (i in a) {
	var v = a[i].split('=');
	if (v.length<2) v[1]=v[0];
	if (v[1].toLowerCase()==cl) {document.write('<option value="'+v[1]+'"'+(n?' style="'+n+v[1]+'"':'')+' selected>'+v[0]+'</option>'); add=false;}
	else document.write('<option value="'+v[1]+'"'+(n?' style="'+n+v[1]+'"':'')+'>'+v[0]+'</option>');
	}
if (add && c) document.write('<option'+(n?' style="'+n+c+'"':'')+' selected>'+c+'</option>');
}

function Paginate(Total_items,PageSize,Start_item) {
	if (isNaN(Total_items) || isNaN(PageSize)) return;
	if (isNaN(Start_item)) Start_item=0;
	var end_item = Start_item + PageSize;
	if (end_item > Total_items) end_item = Total_items;
	var qs=window.location.search;
	if (qs=='') qs='?&_from='; else qs=qs.replace(/&_from=[0-9]*/,'')+'&_from=';
	document.write('Displaying '+(Start_item+1)+' to '+end_item +' of '+Total_items+' items ');

//create a back link
	if (Start_item>=PageSize) document.write('&lt;Back'.link(qs+(Start_item-PageSize))+' ');

//------------Added Section----------
var NumberOfPagesToDisplay=10
var ListSize =0;
var LastPage = Math.ceil(Total_items/PageSize)
var CurrentPage=0;

for (var i=1;i<=Math.ceil(Total_items/PageSize);i++ )//calculate current page, traverse through the pages until pagesize*currentpage=start item
{
	if ((i-1)*PageSize==Start_item) 
	{CurrentPage=i;}
}

//ListSize is the largest page number displayed on the screen
if (LastPage-CurrentPage>NumberOfPagesToDisplay-1) ListSize=CurrentPage+NumberOfPagesToDisplay-1;
else {ListSize=LastPage;}

//------------Added Section----------
//Also modified section below

//List pages
//Total_items/pageSize = total number of pages
	for (var i=CurrentPage; i<=ListSize; i++)
		if ((i-1)*PageSize==Start_item) document.write((i+' ').bold())
        else document.write(String(i).link(qs+(i-1)*PageSize)+' ');

//Create a next link, if the user is looking at the last page no next link should appear
	var LastPageStart = LastPage*PageSize-PageSize;
	if (Start_item<LastPageStart) document.write('Next&gt;'.link(qs+(Start_item+PageSize)));
}


function findSearchDiv(){
var divs = document.getElementsByTagName('div');
for (var i=0; n=divs[i]; i++) if (n.className.substr(0,16)=='Item searchOuter') n.onmousedown=displayFilters;

}

function displayFilters(){
var divs = document.getElementsByTagName('div');
for (var i=0; n=divs[i]; i++) if (n.className.substr(0,16)=='Item searchOuter')  n.style.height=105+'px';
for (var i=0; n=divs[i]; i++) if (n.className.substr(0,16)=='Item searchInner') {

n.style.display='block';
n.style.position='absolute';
n.style.top=0+'px'; 
n.style.left=0+'px';
n.style.backgroundImage='url(/Images/1811/header_search_dropdown_lower_portion.jpg)';
n.style.backgroundRepeat='no-repeat';
n.style.height=105+'px';
n.style.width=720+'px';
}

}