function urlEncode (str) {
str = escape(str);
return str.replace(/[*+\/@]|%20/g,
function (s) {
switch (s) {
case "*": s = "%2A"; break;
case "+": s = "%2B"; break;
case "/": s = "%2F"; break;
case "@": s = "%40"; break;
case "%20": s = "+"; break;
}
return s;
}
);
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

function doRPC(url){
var xmlhttp;
if (window.XMLHttpRequest){
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  } else if (window.ActiveXObject){
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  } else {
  alert("Your browser does not support XMLHTTP!");
  }

xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}


function getMouseX(){
        x = document.getElementById('MouseX').value;
        return x;
}
function getMouseY(){
        y =  document.getElementById('MouseY').value
        return y;
}


function addLoadEvent2(func) {
   var oldonload = window.onload;
   if (typeof window.onload != 'function') {
       window.onload = func;
   }
   else {
       window.onload = function() {
           oldonload();
           func();
       }
   }
}

function findPosX(obj)
{
        obj = document.getElementById(obj);
        var curleft = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curleft += obj.offsetLeft
                        obj = obj.offsetParent;
                }
        }
        else if (obj.x)
                curleft += obj.x;
        return curleft;
}

function findPosY(obj)
{
                obj = document.getElementById(obj);
        var curtop = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curtop += obj.offsetTop
                        obj = obj.offsetParent;
                }
        }
        else if (obj.y)
                curtop += obj.y;
        return curtop;
}

function findPosXAlt(obj)
{
        //obj = document.getElementById(obj);
        var curleft = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curleft += obj.offsetLeft
                        obj = obj.offsetParent;
                }
        }
        else if (obj.x)
                curleft += obj.x;
        return curleft;
}

function findPosYAlt(obj)
{
         //obj = document.getElementById(obj);
        var curtop = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curtop += obj.offsetTop
                        obj = obj.offsetParent;
                }
        }
        else if (obj.y)
                curtop += obj.y;
        return curtop;
}

function getWindowHeight(){
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
	return myHeight;
}

function getWindowWidth(){
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
        return myWidth;
}


function getScreenCenterY() {
	var y = 0;
	 
	y = getScrollOffset()+(getInnerHeight()/2);
 
	return(y);
}
 
function getScreenCenterX() {
	return(document.body.clientWidth/2);
}
 
function getInnerHeight() {
var y;
if (self.innerHeight) // all except Explorer
{
y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
y = document.body.clientHeight;
}
return(y);
}
 
function getScrollOffset() {
var y;
if (self.pageYOffset) // all except Explorer
{
y = self.pageYOffset;
}
else if (document.documentElement && 
document.documentElement.scrollTop)
// Explorer 6 Strict
{
y = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
y = document.body.scrollTop;
}
return(y);
}


function doSignup(){

		q = document.getElementById('emailaddress').value;
			
        //create canvas that is dimmed out
        show_blankout();

        //create the alert
        w = 640;
        h = 150;
        uid = 'popup-xaetad';
        mCreateDiv(uid);
        mDivBackgroundColor(uid,'#ffffff');
	mDivBorder(uid,'1','solid','#cccccc');
        mDivSize(uid,w,h);


        x = getScreenCenterX() - parseInt((w/2));
        y = getScreenCenterY() - parseInt((h/2));
        mDivPos(uid,y,x,'absolute');
        document.getElementById(uid).style.zIndex=5000;

	ajax_loadContent(uid,'/birmingham/newsletter_signup?email=' + urlEncode(q) + '&hash=1234');
}

function showSearch(){


	x = findPosX('search_header') - 100;
	y = findPosY('search_header') -50;

        w = 400;
        h = 150;
        uid = 'searchpop-xaetad';
        mCreateDiv(uid);
        mDivBorder(uid,'0','solid','#cccccc');
        mDivSize(uid,w,h);
	document.getElementById(uid).style.zIndex=5000;

        mDivPos(uid,y,x,'absolute');

       ajax_loadContent(uid,'/tools/searchpop.php','') ;

}

function closeSearchPop(){

       mRemoveDiv('searchpop-xaetad');
}

function doSearch(){
	show_searching();

	q = document.getElementById('textbox-search-main').value;
	if(q == 'Enter keyword(s)' || q == ''){
		setTimeout(doSearchError,2000);
	} else {
		setTimeout(doSearchOK,2000);
	}

}

function doSearchError(){
                close_searching();
                show_alert('Please ensure you fill out the search form correctly.',0);
}

function doSearchOK(){
	close_searching();
	q = document.getElementById('textbox-search-main').value;


        //create canvas that is dimmed out
        show_blankout();

        //create the alert
        w = 640;
        h = 480;
        uid = 'search-xaetad';
        mCreateDiv(uid);
        mDivBackgroundColor(uid,'#ffffff');
	mDivBorder(uid,'1','solid','#cccccc');
        mDivSize(uid,w,h);

        x = getScreenCenterX() - parseInt((w/2));
        y = getScreenCenterY() - parseInt((h/2));
        mDivPos(uid,y,x,'absolute');
document.getElementById(uid).style.zIndex=5000;
	ajax_loadContent(uid,'/tools/search.php?query=' + urlEncode(q)) ;


}

function closeDoSearchOK(){
        mRemoveDiv('search-xaetad');
        close_blankout();	
}

function doSearchInBox(){

        q = document.getElementById('popup-search-query').value;
	document.getElementById('textbox-search-main').value = q; //reset top box search

        ajax_loadContent('search-box-results','/tools/search.php?justresults=1&query=' + urlEncode(q)) ;



}

function wait(msecs)
{
var start = new Date().getTime();
var cur = start
while(cur - start < msecs)
{
cur = new Date().getTime();
}
}




function doPopup(url){
	q = document.getElementById('top').value;


        //create canvas that is dimmed out
        show_blankout();

        //create the alert
        w = 640;
        h = 480;
        uid = 'popup-xaetad';
        mCreateDiv(uid);
        mDivBackgroundColor(uid,'#ffffff');
	mDivBorder(uid,'1','solid','#cccccc');
        mDivSize(uid,w,h);

        x = getScreenCenterX() - parseInt((w/2));
        y = getScreenCenterY() - parseInt((h/2));
        mDivPos(uid,y,x,'absolute');

	url = url + '?hash=1234'

	ajax_loadContent(uid,url) ;
}

function closePopup(){
        mRemoveDiv('popup-xaetad');
        close_blankout();	
}


function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}


function getVal(inpt){

  var gv = document.getElementById(inpt).value == '';
  return gv;
}


function getErCol(inpt){
  var gec = document.getElementById(inpt).style.borderColor='#ff0000';
  return gec;
}

function getCol(inpt){
  var gec = document.getElementById(inpt).style.borderColor='#ffffff';
  return gec;
}


function processsignup(){
  var error = false;
  var errormsg = "Please fill out your information to continue:<br/><br/>";
  msg = '';

//  if(!isValidEmail(document.getElementById('emailaddress').value)){
 //       getErCol('emailaddress');
//		errormsg = errormsg + ' - Email Address\n';
 //       error = true;
//  } else {
//        getCol('emailaddress'); }
          


//  if (error == true){
//	show_alert (errormsg,0);
//
//  } else {
		processsignupOK(); 
//}

}

function processsignupOK(){

        //create canvas that is dimmed out
        show_blankout();
	q = document.getElementById('emailaddress').value;

        //create the alert
        w = 800;
        h = 600;
        uid = 'signup-xaetad';
        mCreateDiv(uid);
        mDivBackgroundColor(uid,'#ffffff');
        mDivBorder(uid,'1','solid','#cccccc');
        mDivSize(uid,w,h);

        x = getScreenCenterX() - parseInt((w/2));
        y = getScreenCenterY() - parseInt((h/2));
        mDivPos(uid,y,x,'absolute');
document.getElementById(uid).style.zIndex=5000;
        ajax_loadContent(uid,'/tools/signup.php?email=' + urlEncode(q)) ;


}

function closesignupok(){
        mRemoveDiv('signup-xaetad');
        close_blankout();
}

function processsignupfull(){

  var error = false;
  var errormsg = "Please fill out your information to continue:<br><br>";
  msg = "";


  if(getVal('Firstname')){
        getErCol('Firstname');
                errormsg = errormsg + ' - Your First name<br>';
        error = true;
  } else {
        getCol('Firstname'); }


  if(getVal('Surname')){
        getErCol('Surname');
                errormsg = errormsg + ' - Your Surname<br>';
        error = true;
  } else {
        getCol('Surname'); }

  if(!isValidEmail(document.getElementById('Email').value)){
        getErCol('Email');
                errormsg = errormsg + ' - Email Address<br>';
        error = true;
  } else {
        getCol('Email'); }

  if (error == true){
        show_alert (errormsg,0);

  } else {
		show_alert('Processing... this box will automatically close when finished');

                document.WebsiteForm.submit(); }

}


function process(){
  var error = false;
  var errormsg = "Please fill out your information to continue:\n\n";
  msg = "";

 
  if(getVal('Name')){
        getErCol('Name');
		errormsg = errormsg + ' - Your Name\n';
        error = true;
  } else {
        getCol('Name'); }

 
  if(getVal('Company')){
        getErCol('Company');
		errormsg = errormsg + ' - Your Company\n';
        error = true;
  } else {
        getCol('Company'); } 
 
  if(!isValidEmail(document.getElementById('Email').value)){
        getErCol('Email');
		errormsg = errormsg + ' - Email Address\n';
        error = true;
  } else {
        getCol('Email'); }
          

         
	

  if (error == true){
	alert (errormsg);

  } else {
		document.WebsiteForm.submit(); } 
}

function processreg(){
  var error = false;
  var errormsg = "Please fill out your information to continue:\n\n";
  msg = "";

 
	if(getVal('Name')){
        getErCol('Name');
		errormsg = errormsg + ' - Your Name\n';
        error = true;
  } else {
        getCol('Name'); }

 
  if(getVal('Company')){
        getErCol('Company');
		errormsg = errormsg + ' - Your Company\n';
        error = true;
  } else {
        getCol('Company'); } 


   if(!isValidEmail(document.getElementById('Email').value)){
        getErCol('Email');
		errormsg = errormsg + ' - Email Address\n';
        error = true;
  } else {
        getCol('Email'); }
        
  if(getVal('Publication')){
        getErCol('Publication');
		errormsg = errormsg + ' - Publication\n';
        error = true;
  } else {
        getCol('Publication'); } 

  if(getVal('PressPasses')){
        getErCol('PressPasses');
		errormsg = errormsg + ' - Number of Press Passes\n';
        error = true;
  } else {
        getCol('PressPasses'); } 
         

         
	

  if (error == true){
	alert (errormsg);

  } else {
		document.WebsiteForm.submit(); } 
}


function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {

setInterval( "slideSwitch()", 7000 );

});


function bannerSwitch() {
    var $active = $('#bannershow DIV.active');

    if ( $active.length == 0 ) $active = $('#bannershow DIV:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#bannershow DIV:first');

    // uncomment the 3 lines below to pull the images in random order
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {

setInterval( "bannerSwitch()", 5000 );

});
