// General js utilities

// Add/Remove functions
var Dom = 
{
    get: function(el) 
    {
      if (typeof el === 'string') 
      {
        return document.getElementById(el);
      } 
      else 
      {
        return el;
      }
    },

    add: function(el, dest) 
    {
      var el = this.get(el);
      var dest = this.get(dest);
      dest.appendChild(el);
    },

    remove: function(el) 
    {
      var el = this.get(el);
      el.parentNode.removeChild(el);
    }
};

// Add Event
var Event = 
{
    add: function() 
    {
        if (window.addEventListener) 
        {
            return function(el, type, fn) 
                {  
                    Dom.get(el).addEventListener(type, fn, false);
                };
        } 
        else if (window.attachEvent) 
        {
            return function(el, type, fn) 
                {
                    var f = function() 
                        {
                            fn.call(Dom.get(el), window.event);
                        };
                    Dom.get(el).attachEvent('on' + type, f);
                };
        }
    }()
};


// Move/Copy functions
/*
This script is copyright (c) 2006 Elliot Swan under the
Creative Commons Attribution-ShareAlike 2.5 license:
http://creativecommons.org/licenses/by-sa/2.5/

More information on this script can be found at:
http://www.elliotswan.com/2006/04/12/move-and-copy/
*/

var Move =	{

  copy	:   function(e, target)	{
            var eId      = document.getElementById(e);
            var copyE    = eId.cloneNode(true);
            var cLength  = copyE.childNodes.length -1;
            copyE.id     = e+'-copy';

            for(var i = 0; cLength >= i;  i++)	{
            if(copyE.childNodes[i].id) {
            var cNode   = copyE.childNodes[i];
            var firstId = cNode.id;
            cNode.id    = firstId+'-copy'; }
            }

            if (typeof target === 'string') 
	        {
	            document.getElementById(target).appendChild(copyE);
	        }
	        else
	        {
	            target.appendChild(copyE);
	            return copyE;
	        }
        },
  element:  function(e, target, type)	{
            var eId =  document.getElementById(e);

	            if(type == 'move') {
                   if (typeof target === 'string')
                   { 
    	               document.getElementById(target).appendChild(eId);
    	           }
    	           else
    	           {
    	               target.appendChild(eId);
    	           }
	            }
	            else if(type == 'copy')	{
	               var newCopy = this.copy(e, target);
                   if (typeof target === 'string')
                   {}
                   else
                   {
                        return newCopy;
                   }
	               
	            }


	    }
}



// Cookie functions
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
    expires = expires * 1000 * 60 * 60 * 24;
}
    var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


function Get_Cookie(search_name) {
  // note: document.cookie only returns name=value, not the other components
  var tab_cookies = document.cookie.split( ';' );
  for ( i = 0; i < tab_cookies.length; i++ ) {
    // now we'll split apart each name=value pair
    var cookie_tmp = tab_cookies[i].split('=');
    // and trim left/right whitespace while we're at it
    var cookie_name = cookie_tmp[0].replace(/^\s+|\s+$/g, '');
    // if the extracted name matches passed search_name
    if (cookie_name==search_name) {
      // we need to handle case where cookie has no value but exists (no = sign, that is):
      if (cookie_tmp.length>1) {
        return unescape( cookie_tmp[1].replace(/^\s+|\s+$/g, '') );
      }
      // cookie is initialized but no value => result = null
      return null;
    }
  }
  return null;
} 

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/* aggsearch.js */

function placePremium(profList)
{
    // place premium content in placeholder near to of results    
    var premWrap = document.getElementById('premWrapper');
    var caResults = document.getElementById('caresultsdiv');
    var emptyResults = document.getElementById('er');
    if (emptyResults && profList == 'true')
        emptyResults.style.display = 'none';
    Move.element(premWrap.id, caResults.id, 'move');
    premWrap.style.display = 'block';

}

/*
CSS Browser Selector v0.3.5 (Feb 05, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
