window.onbeforeunload  = function() {
    setTimeout('checkUserStatus(0)', 1000);
}

function buildURLRewriteTitle(strIn) {
	return strIn.toLowerCase().replace(/&#?\w+;/g, '').replace(/[^\w ]/g, '').replace(/ /g, '-');
}

/*
 * positionItem()
 * --------------
 *
 * 20100409 JJW Written to centre an item on the page and show it 100px from client top
 */
function positionItem(item) {
	var i = $('#' + item);
	i.css('top', ((($(window).height() - i.height())/2) - 32 + $(window).scrollTop()) + 'px');
	i.css('left', ((($(window).width() - i.width())/2) + $(window).scrollLeft()) + 'px');
	
	$('object').css('visibility', 'hidden');
}

function closePositionedItem() {
	$('object').css('visibility', 'visible');
}

function submitAccountPayments() {
    var radlist = document.getElementsByName("radios").length;
    var radArr = '';
	var count = 0;
    
	for (i = 0; i < radlist; i++) {
        if (document.getElementsByName("radios")[i].checked) {
             userArr = document.getElementsByName("radios")[i].value;
             count ++;
        }
    }
    
    if (count > 0) {
        document.forms['settings'].submit();
    } else {
		dialogOpen('#pop_up_1');
    }
}

function closeAccountMsg1(valIn) {
	dialogClose('#pop_up_1');
}

function checkKeyQuestions() {
    var keyid = document.getElementById("keyid").value;
    var q_1 = document.getElementById("f_key_q_1").value;
    var q_2 = document.getElementById("f_key_q_2").value;
    var eObj = document.getElementById("error_1");
    eObj.innerHTML = '';
    eObj.style.display = 'none';
        
    var error_code = 0;
    var data_1 = '';
    
    if (keyid > 0) {
        var poststr = 'callback=true&keyid=' + keyid.toString() + '&q1=' + encodeURIComponent(q_1) + '&q2=' + encodeURIComponent(q_2);
		ajaxpack.postAjaxRequest('checkKeyQuestions.asp', poststr, function t() { 
		     if(ajaxIsReady()) { 
		         if(ajaxpack.ajaxobj.responseText.length > 0) {
		            if (ajaxpack.ajaxobj.responseText == 'passed') {
		                document.getElementById("questions").value = 1;
		                document.forms['form_exec'].submit();
		            }
		            if (ajaxpack.ajaxobj.responseText == 'failed') {
		                error_code = 3;
		            }
		            if(ajaxpack.ajaxobj.responseText == 'error') {
		                error_code = 2;
		            }
		         }
		         else {
		            error_code = 2;
		         }
		         
                 if (error_code == 3) {
                    data_1 = '<strong>Error: </strong>You failed to answer the security questions correctly. Please try again or if you continue to experience problems please contact us directly.<br/>';
                    eObj.innerHTML = data_1;
                    eObj.style.display = 'block';
                 }
                 else if (error_code == 2) { 
                    data_1 = '<strong>Error: </strong>There was an unexpected error while attempting to process your key details.<br/><br/>Please refresh your browser and try again or if the problem persists please contact us directly.<br/>';
                    eObj.innerHTML = data_1;
                    eObj.style.display = 'block';
                 }
		         
		     }
		}, 'html');   
    }
    else {
        error_code = 1;
    }

    if (error_code > 0) {
        data_1 = '<strong>Error: </strong>There was an unexpected error while attempting to process your key details.<br/><br/>Please refresh your browser and try again or if the problem persists please contact us directly.<br/>';
        eObj.innerHTML = data_1;
        eObj.style.display = 'block';
    }

}

function checkAccessKey() {
	var keyResponse = document.getElementById("iscorrectkey");
	var key1 = document.getElementById('f_key1').value;
	var key2 = document.getElementById('f_key2').value;
	var key3 = document.getElementById('f_key3').value;
	var key4 = document.getElementById('f_key4').value;
	
	var accessKey = key1 + key2 + key3 + key4;
	
	if (accessKey.length > 0) {
		if (accessKey.length == 16 && key1.length == 4 && key2.length == 4 && key3.length == 4 && key4.length == 4) {
			var regexp = /[\da-f]{16}/gi;
			if (regexp.test(accessKey)) {
				keyResponse.innerHTML = 'Key correct  <img src="/layout/default/vaultkeyvalid.gif" alt="Key correct" />';
			} else {
				keyResponse.innerHTML = 'Incorrect key format <img src="/layout/default/vaultkeyinvalid.gif" alt="Incorrect key format" />';
			}
		} else {
			keyResponse.innerHTML = 'Incorrect key format <img src="/layout/default/vaultkeyinvalid.gif" alt="Incorrect key format" />';
		}
	}
}

function returnAccountHome() {
    document.location = document.getElementById("accounthome").value;
}

function deleteAccountConfirm() {
    document.getElementById("message_id_2").value = '';
	dialogOpen('#pop_up_2');
}

function closeAccountDelete(valIn) {
    switch(valIn) {
        case 1:
            document.getElementById("message_id_2").value = '';
			dialogClose('#pop_up_2');
            break;
        case 2:
            document.forms['settings'].submit();
            break;
        default:
            break;
    }
}

function closePopup38() {
	dialogClose('#pop_up_1');
}

function showPopup38() {
	dialogOpen('#pop_up_1');
}

function getAPIKeys(formid) {
    var fullpostcode = document.getElementById("f_post_code").value;
	var theform;
	if (formid == 1) theform = document.getElementById('form_registration');
	if (formid == 2) theform = document.getElementById('settings');
    
    if (fullpostcode.length > 0) {
        //var poststr = usePointFromPostcode(fullpostcode, showPointLatLng, item, formid);
		geocodeAddress(fullpostcode + ', UK', theform);
    } else {
        theform.submit();
    }
}

function checkUserStatus(inVar) {
	var uidelement = document.getElementById("logedin_user");
    var uid = 0;
	
	if (uidelement) uid = uidelement.value;
    
    if (uid > 0) {
        var poststr = 'callback=true&uid=' + uid.toString() + '&stat=' + inVar.toString();
		ajaxpack.postAjaxRequest('updateUserStatus.asp', poststr, function t() { 
		     if(ajaxIsReady()) { 
		        //if(ajaxpack.ajaxobj.responseText == 'success') {
                    //Do nothing
		        //}
		        //setTimeout('checkNewMessages()', 300);
		     }
		}, 'html');
    }
}

function sendUpdatePhotos() {
    var isCoverid = '', todelete = '', fullarray = '';
    var data_1 = '', data_2 = '', data_3 = '';
    var count = 0, count2 = 0;
    
    var photolength = document.getElementsByName("photo_check").length;
    
    for (i = 0; i < photolength; i++) {
        if (document.getElementsByName("photo_radio")[i].checked) {
            isCoverid = document.getElementsByName("photo_radio")[i].value;
        }
        if (document.getElementsByName("photo_check")[i].checked) {
            if (count2 > 0) todelete = todelete + ",";
            todelete = todelete + document.getElementsByName("photo_check")[i].value;
            count2++;
        }
        if (count > 0) fullarray = fullarray + ",";
        fullarray = fullarray + document.getElementsByName("photo_check")[i].value;
        count++;
    }
    
    document.getElementById("photoarray").value = fullarray;
    document.getElementById("deletearray").value = todelete;
    document.getElementById("iscover").value = isCoverid;
    
    document.forms['form_editalbum'].submit();
}

function deleteAlbum(aid) {
    if (aid > 0) {
        if(confirm("Delete this album and all associated photos?\n\nAre you sure?")) {
            data_1 = 'Album_List_';
            data_1 = data_1 + aid.toString();
            
            var poststr = 'callback=true&aid=' + aid.toString();
		    ajaxpack.postAjaxRequest('deleteMemberAlbum.asp', poststr, function t() { 
		         if(ajaxIsReady()) { 
		            if(ajaxpack.ajaxobj.responseText == 'success') {
                       document.getElementById(data_1).style.display = 'none';
		            }
		        }
		    }, 'html');
        }
    }
}

// 20100316 JJW Changed cookie handling to use jQuery cookie library
function setCookie(name, value) {
	$.cookie(name, value, {path: '/'});
}

function SubmitListingFilter(pid, tid, sid, order, cid)
{
    if(pid > 0)
    {
        var psize, purl;
        psize = document.getElementById("number_select").value;
        
        //Set cookie
        setCookie("PageFilter", psize);
        
        switch(tid)
        {
            case 1:
                //document.location.href = 'newsListing.asp?taxonomyid=' + pid.toString() + '&categoryid=' + cid + '&onsearch=1&pageno=0&pagesize=' + psize + '';
				//20100316 JJW Use cid as parentid with parent and taxonomy appended 107/blah/blah
                document.location.href = '/advice/' + pid.toString() + '/' + cid + '/pageno=0/pagesize=' + psize + '/onsearch=1/';
                break;
            case 2:
                document.location.href = 'search.asp?id=' + pid.toString() + '&onsearch=1&pageno=0&pagesize=' + psize + '';
                break;
            case 3:
                document.location.href = 'search_adv.asp?id=' + pid.toString() + '&onsearch=1&pageno=0&pagesize=' + psize + '';
                break;
            case 4:
                document.location.href = 'news.asp?taxonomyid=' + pid.toString() + '&onsearch=1&pageno=0&pagesize=' + psize + '';
                break;
            case 5:
                var listType, advid, grpid;
                listType = document.getElementById("typeid").value;
                advid = document.getElementById("advanced").value;
                grpid = document.getElementById("groupid").value;
                if (listType == 4)
                {
                    document.location.href = 'l_friends.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&typeid=' + listType.toString() + '&specorder=' + order + '&pagesize=' + psize + '&advanced=' + advid + '&groupid=' + grpid + '&t=1&start=0';
                }
                else
                {
                    document.location.href = 'l_friends.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&typeid=' + listType.toString() + '&specorder=' + order + '&pagesize=' + psize + '&advanced=' + advid + '&t=1&start=0';
                }
                break;
            case 6:
                var listType;
                listType = document.getElementById("typeid").value;
                document.location.href = 'l_msg.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&typeid=' + listType.toString() + '&specorder=' + order + '&pagesize=' + psize + '&mstatus=' + cid + '&t=1&start=0';
                break;
            case 7:
                var listType;
                listType = document.getElementById("typeid").value;
                document.location.href = 'l_msg.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&typeid=' + listType.toString() + '&specorder=' + order + '&pagesize=' + psize + '&t=1&start=0';
                break;
            case 8:
                var listType, profId;
                listType = document.getElementById("typeid").value;
                profId = document.getElementById("profileid").value;
                //document.location.href = 'l_gallery.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&typeid=' + listType.toString() + '&profileid=' + profId.toString() + '&specorder=' + order + '&pagesize=' + psize + '&t=1&start=0';
				if (cid == '5') {
					albumId = document.getElementById("albumid").value;
					albumName = buildURLRewriteTitle(document.getElementById("albumtitle").value);
					document.location.href = '/lifebox/photos/' + albumId.toString() + '/' + albumName + '?start=0&pagesize=' + psize.toString();
				} else {
					document.location.href = '/lifebox/photos?start=0&pagesize=' + psize.toString();
				}
				//l_gallery.asp?id=57&sid=8&typeid=5&profileid=44&pagesize=12&albumid=40&start=1
                break;
            case 9:
                var advid, profId;
                advid = document.getElementById("advanced").value;
                profId = document.getElementById("profileid").value;
                document.location.href = 'profile.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&profileid=' + profId.toString() + '&specorder=' + order + '&pagesize=' + psize + '&advanced=' + advid + '&t=1&start=0&view=friends';
                break;
            case 10:
                var listType, profId;
                listType = document.getElementById("typeid").value;
                profId = document.getElementById("profileid").value;
                document.location.href = 'profile.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&profileid=' + profId.toString() + '&specorder=' + order + '&typeid=' + listType.toString() + '&pagesize=' + psize + '&t=1&start=0&view=albums';
                break;
            case 11:
                var listType, advid, grpid;
                listType = document.getElementById("typeid").value;
                advid = document.getElementById("advanced").value;
                grpid = document.getElementById("groupid").value;
                document.location.href = 'a_users.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&typeid=' + listType.toString() + '&specorder=' + order + '&pagesize=' + psize + '&advanced=' + advid + '&t=1&start=0';
                break;
            case 12:
                var listType;
                listType = document.getElementById("typeid").value;
                document.location.href = 'a_msg.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&typeid=' + listType.toString() + '&specorder=' + order + '&pagesize=' + psize + '&mstatus=' + cid + '&t=1&start=0';
                break;
            case 13:
                var listType;
                listType = document.getElementById("typeid").value;
                document.location.href = 'a_msg.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&typeid=' + listType.toString() + '&specorder=' + order + '&pagesize=' + psize + '&t=1&start=0';
                break;
            case 14:
                var listType, subjectid;
                listType = document.getElementById("typeid").value;
                subjectid = document.getElementById("subjectid").value;
                document.location.href = 'a_msg.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&typeid=' + listType.toString() + '&subjectid=' + subjectid.toString() + '&specorder=' + order + '&pagesize=' + psize + '&t=1&start=0';
                break;
            case 15:
                var taskId, typeId, profId;
                taskId = document.getElementById("taskid").value;
                typeId = document.getElementById("typeid").value;
                profId = document.getElementById("profileid").value;
                document.location.href = 'v_gallery.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&typeid=' + typeId.toString() + '&profileid=' + profId.toString() + '&taskid=' + taskId.toString() + '&specorder=' + order + '&pagesize=' + psize + '&t=1&start=0';
                break;
            case 16:
                var taskId, typeId, profId;
                taskId = document.getElementById("taskid").value;
                typeId = document.getElementById("typeid").value;
                profId = document.getElementById("profileid").value;
                document.location.href = 'vault.asp?id=' + pid.toString() + '&sid=' + sid.toString() + '&profileid=' + profId.toString() + '&specorder=' + order + '&typeid=' + typeId.toString() + '&taskid=' + taskId.toString() + '&pagesize=' + psize + '&t=1&start=0&view=albums';
                break;
            default:
                break;
        }
    }
}

function showFullList(listid, labelid)
{
    var data_1, data_2, data_3;
    data_1 = listid.toString();
    data_2 = labelid.toString();
    data_3 = '';

    if (document.getElementById(data_1).style.display == 'block')
    {
        document.getElementById(data_1).style.display = 'none'
        data_3 = 'Show all';
        document.getElementById(data_2).innerHTML = data_3;
    }
    else
    {
        document.getElementById(data_1).style.display = 'block'
        data_3 = 'Hide older';
        document.getElementById(data_2).innerHTML = data_3;
    }
    
}

function reSetCaptcha() {
    var d = new Date();
    document.getElementById('captchaImageImage').innerHTML = '<img src="aspcaptcha.asp?s='+ d.getMilliseconds() +'" alt="This Is CAPTCHA Image" width="86" height="21" />';
}

// 20091109 JJW
// New utility functions dealing with a text field (input or textarea)
// taking focus and losing focus.
function fieldFocus(fieldId, defaultValue) {
	var field = document.getElementById(fieldId);
	if (field.value == defaultValue) field.value = '';
}

function fieldBlur(fieldId, defaultValue) {
	var field = document.getElementById(fieldId);
	if (field.value == '') field.value = defaultValue;
}

function CreateComment() {
    var dataid = document.getElementById("dataid").value;
    var typeid = document.getElementById("typeid").value
    var userid = document.getElementById("userid").value;
    var viewertypeid = 3;
    var cObj = document.getElementById("comment-message").value;
    
    if (typeid == 4) {
        viewertypeid = document.getElementById("viewertypeid").value;
    }
    
    if (cObj != "Write a new comment..." && cObj.length > 0) {
        
        try {
            document.getElementById("options_btn").style.display = 'none';
            document.getElementById("options_btn_busy").style.display = 'block';
        } catch(e) {
            //No action
        }

        try {
            /*var poststr = 'callback=true&strin=' + encodeURIComponent(cObj);
		    ajaxpack.postAjaxRequest('striptags.aspx', poststr, function t() { 
		        if(ajaxIsReady()) {
		            cObj = ajaxpack.ajaxobj.responseText;*/
		            
		            var poststr = 'callback=true&dataid=' + dataid.toString() + '&typeid=' + typeid.toString() + '&userid=' + userid.toString() + '&param=' + encodeURIComponent(cObj) + '&viewertypeid=' + viewertypeid.toString();
		            ajaxpack.postAjaxRequest('createComment.asp', poststr, function t() {
		                if(ajaxIsReady()) {
		                    if(ajaxpack.ajaxobj.responseText.length > 0) {
		                        var cArea = document.getElementById("user-comments");
		                        var data_1 = cArea.innerHTML;
		                        var data_2 = ajaxpack.ajaxobj.responseText;
		                        data_2 = data_2.toString() + data_1.toString();
		                        cArea.innerHTML = data_2;
		                        document.getElementById("comment-message").value = '';
            		            
		                        try {
                                    document.getElementById("options_btn_busy").style.display = 'none';
                                    document.getElementById("options_btn").style.display = 'block';
                                } catch(e) {
                                    //No action
                                }
		                    }
		                }
		            }, 'html');
		            /*
		        }
		    }, 'html');*/
        } catch(e) {
            //Do nothing
        }
    }
	return false;
}

function deleteComment(dataid, commentid, typeid) {
    if(confirm("Delete this comment.\n\nAre you sure?")) {
        var poststr = 'callback=true&dataid=' + dataid.toString() + '&commentid=' + commentid.toString() + '&typeid=' + typeid.toString();
        ajaxpack.postAjaxRequest('deleteComment.asp', poststr, function t() { 
		   if(ajaxIsReady())  { 
               if(ajaxpack.ajaxobj.responseText == "success") {
		            var row_1 = 'comment_row_';
                    row_1 = row_1 + commentid.toString();
                    document.getElementById(row_1).style.display = 'none';
		        }
		    }
	    }, 'html');       
	}
}

function saveEditComment(pid, cid, tid) {
    var tObj = document.getElementById("comment_edit_text").value;
    var eObj = document.getElementById("edit_comment_input");
    var userid = document.getElementById("logedin_user").value;
    
    eObj.InnerHTML = '<img src="/images/loader.gif" alt="" title=""/>';
    
    var poststr = 'callback=true&dataid=' + pid.toString() + '&cid=' + cid.toString() + '&userid=' + userid.toString() + '&typeid=' + tid.toString() + '&param=' + encodeURIComponent(tObj.toString()) + '&update=1';
    ajaxpack.postAjaxRequest('createComment.asp', poststr, function t() { 
		if(ajaxIsReady()) { 
		    if(ajaxpack.ajaxobj.responseText.length > 0) {
                var cell_1 = 'comment_row_';
                cell_1 = cell_1 + cid.toString();
                var pObj = document.getElementById(cell_1);
                
                pObj.innerHTML = ajaxpack.ajaxobj.responseText;
		    }
		}
    }, 'html');
}

function editComment(dataid, commentid, typeid) {
    var cell_1 = 'comment_data_';
    cell_1 = cell_1 + commentid.toString();
    var pObj = document.getElementById(cell_1);
    var oText = pObj.innerHTML.replace("<p>", "").replace("</p>", "").replace("<br />", "\n");
	if (!document.getElementById('comment_edit_text')) {
		var data_1 = '<div><textarea class="comment_edit" name="comment_edit_text" id="comment_edit_text">'+ oText + '</textarea><br/>';
		data_1 += '<span id="edit_comment_input"><a href="#" onclick="saveEditComment(' + dataid + ', ' + commentid + ', ' + typeid + '); return false;">Update</a></span>';
		data_1 += '<br/></div>';
		pObj.innerHTML = data_1;
		document.getElementById('comment_edit_' + commentid).innerHTML = '';
	}
}

var state = 'none'; 

function movepic(img_name,img_src) {
    document[img_name].src = img_src;
}

function showhide(layer_ref, btn_ref) { 
    if (state == '') { 
        state = 'none';
        movepic("" + btn_ref + "",'images/plus.gif');
    } else { 
        state = '';
        movepic("" + btn_ref + "",'images/minus.gif');
    }

    if (document.all) {
        eval( "document.all." + layer_ref + ".style.display = state"); 
    } 

    if (document.layers) { 
        document.layers[layer_ref].display = state; 
    } 

    if (document.getElementById &&!document.all) { 
        hza = document.getElementById(layer_ref); 
        hza.style.display = state; 
    }   
}

function showhideLarge(layer_ref, btn_ref) { 
    if (state == '') {
        state = 'none';
        movepic("" + btn_ref + "",'images/open.gif');
    } else {
        state = '';
        movepic("" + btn_ref + "",'images/close.gif');
    }
	
    if (document.all) {
        eval( "document.all." + layer_ref + ".style.display = state");
    }
	
    if (document.layers) {
        document.layers[layer_ref].display = state;
    }
	
    if (document.getElementById &&!document.all) {
        hza = document.getElementById(layer_ref);
        hza.style.display = state;
    }
}

function inArray(arr, val) {
	var i;
	for (i=0; i < arr.length; i++) {
		if (arr[i] === val) {
			return true;
		}
	}
	return false;
}

function removeFromArray(arr, val) {
	for(i=0;i<arr.length;i++){
		if(val==arr[i]) arr.splice(i, 1);
	}
}

function resetSearchForm() {
    document.location = "search.asp?reset=true";
}

function advancedSearchSubmit() {
    document.forms['form_adv'].submit();
    
}

function FormatNumber(amount) {
	var i = parseFloat(amount.value);
	if(isNaN(i)) i = 0.00;

	var minus = '';
	if(i < 0) i = 0;
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) s += '.00';
	if(s.indexOf('.') == (s.length - 2)) s += '0';
	s = minus + s;
	if(s == 0) {
        amount.value = '';
	} else {
        amount.value = s;
    }
}

function FormatNumberMB(amount) {
	FormatNumber(amount);
}

function FormatNumberDays(amount) {
	var i = parseFloat(amount.value);
	if(isNaN(i)) i = 0.00;

	var minus = '';
	if(i < 0) i = 0;
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) s += '.00';
	if(s.indexOf('.') == (s.length - 2)) s += '0';
	s = minus + s;
	if(s == 0) {
        amount.value = '';
	} else {
        var sArray = s.split(".");
        var result = sArray[0];
        amount.value = result;
    }
}

function isEmail(email) {
	var emailPattern = /^([a-zA-Z0-9_\.\+-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
    return emailPattern.test(email);
}

// 20091104 JJW
// Toggle checkbox function
function toggleCheckbox(id) {
	document.getElementById(id).checked = !document.getElementById(id).checked;
	return false;
}

// expands or shrinks a section of the taxonomy listing
function toggleTaxonomySection(partial, id, expandText, shrinkText) {
	var section = document.getElementById('TaxonomySection' + partial + id);
	var anchor = document.getElementById('TaxonomyExpand' + partial + id);
	var item = document.getElementById('TaxonomyItem' + partial + id);
	
	if (section.className == 'TaxonomySection' + partial) {
		section.className = 'TaxonomySectionExpanded' + partial;
		anchor.innerHTML = shrinkText;
		item.className = 'TaxonomyItemWithChildrenExpanded' + partial;
	} else {
		section.className = 'TaxonomySection' + partial;
		anchor.innerHTML = expandText;
		item.className = 'TaxonomyItemWithChildren' + partial;
	}
	
	return false;
}

// sets checkboxes to value passed in within a specific section
function setTaxonomySection(id, setting) {
	var items = document.getElementById(id).getElementsByTagName('input');
	
	for (var i = 0; i < items.length; ++i) {
		if (items[i].type == 'checkbox') {
			items[i].checked = setting;
		}
	}
}

// swaps an element's class between 2 specified classes
function toggleElement(id, startClass, endClass) {
	var section = document.getElementById(id);
	
	if (section.className == startClass)
		section.className = endClass
	else
		section.className = startClass;
		
	return false;
}

/******************************************
 * glossaryRollover routines                 *
 ******************************************/
//returns the position of any element on the screen
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function showGlossary(id, ele) {
	var pos = findPos(ele);
	document.getElementById(id).style.left = (pos[0]+50) + 'px';
	document.getElementById(id).style.top = (pos[1]-200) + 'px';
	document.getElementById(id).style.display='block';
}

function hideGlossary(id) {
	document.getElementById(id).style.display='none';
}

/******************************************
 * ajaxpack ajax routines                 *
 ******************************************/
//Basic Ajax Routine- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated: Jan 15th, 06'
function createAjaxObj() {
	var httprequest=false;
	// if Mozilla, Safari etc
	if (window.XMLHttpRequest) {
		httprequest=new XMLHttpRequest()
		if (httprequest.overrideMimeType)
			httprequest.overrideMimeType('text/xml');
	// if IE
	} else if (window.ActiveXObject) { 
		try {
			httprequest=new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) {
			try{
				httprequest=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	return httprequest;
}

var ajaxpack=new Object();
ajaxpack.basedomain="http://"+window.location.hostname;
ajaxpack.ajaxobj=createAjaxObj();
ajaxpack.filetype="txt";
ajaxpack.addrandomnumber=1; //Set to 1 or 0. See documentation.

ajaxpack.getAjaxRequest=function(url, parameters, callbackfunc, filetype) {
	ajaxpack.ajaxobj=createAjaxObj(); //recreate ajax object to defeat cache problem in IE
	if (ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
		var parameters=parameters+"&ajaxcachebust="+new Date().getTime();

	if (this.ajaxobj) {
		this.filetype=filetype;
		this.ajaxobj.onreadystatechange=callbackfunc;
		this.ajaxobj.open('GET', url+"?"+parameters, true);
		this.ajaxobj.send(null);
	}
}

ajaxpack.postAjaxRequest=function(url, parameters, callbackfunc, filetype) {
	ajaxpack.ajaxobj=createAjaxObj(); //recreate ajax object to defeat cache problem in IE

	if (this.ajaxobj) {
		this.filetype=filetype;
		this.ajaxobj.onreadystatechange = callbackfunc;
		this.ajaxobj.open('POST', url, true);
		this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.ajaxobj.setRequestHeader("Content-length", parameters.length);
		this.ajaxobj.setRequestHeader("Connection", "close");
		this.ajaxobj.send(parameters);
	}
}

function ajaxIsReady() {
	return (ajaxpack.ajaxobj.readyState == 4 && ajaxpack.ajaxobj.status==200 || window.location.href.indexOf("http")==-1);
} 
