
function setoptions()
{
    var ptmp = location.pathname.replace('/speakers/find/','');
    var ptmp = ptmp.replace('/speakers/find','');
    var path = ptmp.split('/');

    if(path.length==0)
    {
        var selected_topic = 'all.topics';
        var selected_loc = 'all.locations';
    }
    else if (path.length == 1)
    {
        var selected_topic = path[0];
    }
    else
    {
        var selected_topic = path[0];
        var selected_loc = path[1];
    }


    $('spkrtopic').options[0] = new Option('-- All Topics --','all.topics');
    $('spkrtopic').selectedIndex=0;

    for(i=0;i<topics.length;i++)
    {
            $('spkrtopic').options[i] = new Option(topics_dsp[i],topics[i]);
            if( $('spkrtopic').options[i].value == selected_topic )
                $('spkrtopic').selectedIndex=i;

    }

    for(i=0;i<locs.length;i++)
    {
        try {
            $('spkrloc').options[i] = new Option(locs_dsp[i],locs[i]);
            if( $('spkrloc').options[i].value == selected_loc )
                $('spkrloc').selectedIndex=i;
        }catch(e) {}
    }

    var selected_bio = path[1];

    $('spkrbio').selectedIndex=0;

    for(i=0;i<bios.length;i++)
    {
        try {
            $('spkrbio').options[i] = new Option(bios_dsp[i],bios[i]);
            if( $('spkrbio').options[i].value == selected_bio )
                $('spkrbio').selectedIndex=i;
        }catch(e) {}
    }

$('spkrloc').onchange=run_query;
$('spkrtopic').onchange=run_query;
$('spkrbio').onchange=get_bio;

}

function get_bio()
{
    var path = '/speakers/bio/'+$('spkrbio').value;
    location.href=path;

}

function run_query()
{


var topic= $('spkrtopic').value;
if(topic == '' ) {
    topic='all.topics';
}
var loc= $('spkrloc').value;

var path = '/speakers/find/'+topic+'/'+loc;

location.href=path;

}

Event.observe(window,'load',setoptions)

spk_req = new Object();
spk_req.run = function(e) {

    var event = e ? e : window.event;
    var target = event.target ? event.target : event.srcElement;
    var fd = $('formDialog');
    fd.style.display='none';
    fd.style.backgroundColor='#cccccc';
    fd.style.zIndex='1000';
    fd.style.backgroundColor='#cccccc';
    $('body').appendChild(fd);
    Position.absolutize(fd);
    placeForm();
    var url = '/speakers/request-speaker';
    new Ajax.Updater('formDialogInner', url, { method: 'get',
                                               afterFinish: new Effect.Appear(fd) } );
    $('spknm').innerHTML=target.id.replace('-',' ');
    return false;

}


function closeFormDialog()
{
    new Effect.Fade('formDialog',{afterFinish:function() { $('formDialogInner').innerHTML='';}} )
}


function submit_srf()
{
   $('Name').style.backgroundColor='#ffffff';
   $('Company').style.backgroundColor='#ffffff';
   $('Telephone').style.backgroundColor='#ffffff';
   $('Email').style.backgroundColor='#ffffff';

    var error_count = 0;
    if( $('Name').value == '' )
    {
        $('Name').style.backgroundColor='#ffcccc';
        error_count +=1;
    }
    if( $('Company').value == '' )
    {
        $('Company').style.backgroundColor='#ffcccc';
        error_count +=1;
    }
    if( $('Telephone').value == '' )
    {
        $('Telephone').style.backgroundColor='#ffcccc';
        error_count +=1;
    }
    if( $('Email').value == '' )
    {
        $('Email').style.backgroundColor='#ffcccc';
        error_count +=1;
    }
    if(error_count > 0)
    {
        alert('Errors on form.');
        return false;

    }



    $('RequestedSpeaker').value = $('spknm').innerHTML;
    new Ajax.Updater('formDialogInner','/speakers/request-speaker',{method:'post',parameters: $('speakerform').serialize(true) } )
    return false;


}

function set_contact_form_links()
{

    var srl = document.getElementsByClassName('contactspeaker');
    for(i=0; i< srl.length; i++)
        srl[i].onclick = spk_req.run;

}

function placeForm()
{
    var Geometry = {};
    
    if(window.screenLeft)
    {
        Geometry.getWindowX = function() { return window.screenLeft; };
        Geometry.getWindowY = function() { return window.screenTop; };
    }
    else if (window.screenX)
    {
        Geometry.getWindowX = function() { return window.screenX; };
        Geometry.getWindowY = function() { return window.screenY; };
    }
    
    if(window.innerWidth)
    {  // All but IE
        Geometry.getViewPortWidth = function() { return window.innerWidth; };
        Geometry.getViewPortHeight = function() { return window.innerHeight; };
        Geometry.getHorizontalScroll = function() { return window.pageXOffset };
        Geometry.getVerticalScroll = function() { return window.pageYOffset };
    }
    else if(document.documentElement && document.documentElement.clientWidth)
    {
        // IE6 when there is a doctype
        Geometry.getViewPortWidth = function() { return document.documentElement.clientWidth; };
        Geometry.getViewPortHeight = function() { return document.documentElement.clientHeight; };
        Geometry.getHorizontalScroll = function() { return document.documentElement.scrollLeft; };
        Geometry.getVerticalScroll = function() { return  document.documentElement.scrollTop;};
    }
    else if(document.body.clientWidth)
    {
        // IE4, IE5, IE6 Without a doctype
        Geometry.getViewPortWidth = function() { return document.body.clientWidth; };
        Geometry.getViewPortHeight = function() { return document.body.clientHeight; };
        Geometry.getHorizontalScroll = function() { return document.body.scrollLeft; };
        Geometry.getVerticalScroll = function() { return  document.body.scrollTop;};
    }

    var c = ((Geometry.getViewPortWidth() + Geometry.getHorizontalScroll() )/2)-200;
    var t = (Geometry.getViewPortHeight()/2)+Geometry.getVerticalScroll()-200;
    if(c <= 254.0)
        c=254.0;

    var fd = $('formDialog');
    fd.style.top=t+'px';
    fd.style.left=c+'px';
    fd.style.zIndex=1000;



}



Event.observe(window,'load',set_contact_form_links)
Event.observe(window,'resize',placeForm)



