function $(id) {return document.getElementById(id);}

function showSearchBar() {
    var showsearch = new YAHOO.util.Anim('searchbar',{top:{to:0}},.3,YAHOO.util.Easing.easeOut);
    showsearch.animate();
}
function showImage(preview,el) {
    var loadNewImage = function() {
        el.style.cursor = 'progress';
        $('imagepreview').src = preview;
        $('imagepreview').onload = function() {
            fadein.animate();
            el.style.cursor = '';
        } 
    }
    var fadeout = new YAHOO.util.Anim('imagepreview',{opacity:{to:0}},.2,YAHOO.util.Easing.easeOut);
    var fadein = new YAHOO.util.Anim('imagepreview',{opacity:{to:1}},.2,YAHOO.util.Easing.easeOut);
    fadeout.onComplete.subscribe(loadNewImage);
    fadeout.animate();
}
function showhideDialog() {
	$('dialog').style.display!='block'?
	$('dialog').style.display='block':
	$('dialog').style.display='none';
}
function addCompanyToSavedList(companyId) {
    var loggedIn = OnlineDirectory.BusinessObjects.Ajax.BusinessAjaxHelper.AddCompanyToSaveList(companyId);
    if (!loggedIn.value) {
        alert('You must be logged in to use this feature.');
    } else {
        alert('This company has been saved to your contacts list.');    
    }
}
function addToFavourites() {
	var url=self.location.href;
	var title=document.title;
	if (window.sidebar) window.sidebar.addPanel(title,url,"");
	else if (window.opera && window.print) {
		var mbm=document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	}
	else if (document.all) window.external.AddFavorite(url,title);
}
function resizeMap() {
    if (!mapExpanded) {
        $('mapcontainer').className='expanded';
        $('map').className='expanded';
        $('mapresize').innerHTML='Small map';
        if ($('logo')!=null) {
            YAHOO.util.Event.on('logo','click',resizeMap);
            $('logo').alt='View details';
            $('logo').title='View details';
            $('logo').style.cursor='pointer';
        }
        if ($('images')!=null) {$('images').style.display='none';}
        if ($('contact')!=null) {$('contact').style.display='none';}
        $('details').style.display='none';
        $('maphelp').style.display='block';
        GUnload();
        loadMap();
        map.addControl(new GOverviewMapControl());
        mapExpanded=true;
    } else {
        $('mapcontainer').className='';
        $('map').className='';
        $('mapresize').innerHTML='Large map';
        if ($('logo')!=null) {
            YAHOO.util.Event.removeListener('logo');
            $('logo').alt='';
            $('logo').title='';
            $('logo').style.cursor='';
        }
        if ($('images')!=null) {$('images').style.display='block';}
        if ($('contact')!=null) {$('contact').style.display='';}
        $('maphelp').style.display='';
        $('details').style.display='';
        GUnload();
        loadMap();
        mapExpanded=false;
    }
}
function validChars(e,el) {
	var key;
	var keychar;
	if (window.event) key = window.event.keyCode;
	else if (e) key = e.which;
	else return true;
	keychar = String.fromCharCode(key);
	if ((key==32) || (key==0) || (key==8) || (key==9) || (key==27) || (key==13)) return true;
	if (keychar.match(/[0-9a-zA-Z\+\-\&]/)) return true;
	else return false;
}
