function nothing () { return; }

var showHideDivs = new Object();

function toggleDiv(kwd) {
  var hid = showHideDivs[kwd];
  var img = hid ? 'plus' : 'minus';
  var obj = null;
  if (obj = document.getElementById(kwd+'Div'))
    obj.style.display = (hid ? 'block' : 'none');
  if (obj = document.getElementById(kwd+'AltDiv'))
    obj.style.display = (hid ? 'none' : 'block');
  if (document.images[kwd+'Img'])
    document.images[kwd+'Img'].src = '/images/'+(hid ? 'minus' : 'plus')+'.gif';
  showHideDivs[kwd] = !hid;
  return hid;
}

function showDiv(kwd,hide) {  
  if (obj = document.getElementById(kwd+'Div'))
    obj.style.display = (hide ? 'none' : 'block');
}

function hideDiv(kwd) {
  showDiv(kwd,1); 
}

var ajax = null;

function AJAXinit (h) {
  // branch for native XMLHttpRequest object
  if (window.XMLHttpRequest && !(window.ActiveXObject)) {
    try {
      ajax = new XMLHttpRequest();
    } catch(e) {
      ajax = null;
    }
  // branch for IE/Windows ActiveX version
  } else if (window.ActiveXObject) {
    try {
      ajax = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
      ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        ajax = null;
      }
    }
  }
  
  if(ajax && h) {
    ajax.onreadystatechange = h;
  }
}

// Voting
starRatings = {};
function setStarsTo(id,num,sve) {
  // K, so go from .5 to 5 and see if the num is greater than
  for (var i=0.5; i <= 5; i += 0.5) {
    if (document.images['star'+ id +'_'+ i])
      document.images['star'+ id +'_'+ i].src = '/images/star' + ((i * 2) % 2 ? '1' : '2') + (num >= i ? 'on' : 'off') + '.gif';
  }
  if (sve)
    starRatings[id] = num;
}



function showSaving() {
  
  var gdiv = document.getElementById('greyOutDiv');
  var ldiv = document.getElementById('loadingDiv');
  
  if (!gdiv || !ldiv) return;
  
  gdiv.style.display='block';
  ldiv.style.display='block';
  
  var ww = document.all ? document.body.clientWidth : window.innerWidth;
  var wh = document.all ? document.body.clientHeight : window.innerHeight;
  
  ldiv.style.left= ((ww / 2) - 120);
  ldiv.style.top=  (wh / 2) - 60 + (document.all ? document.body.scrollTop : window.pageYOffset); 
  
  // Refresh the image
  if (document.images['savingImg'])
    setTimeout("document.images['savingImg'].src='/images/saving.gif?"+ Math.random() +"';",500);
  
}


function setCookie( 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 getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

  function shareFacebook () {
	  var u = location.href;
	  var t = document.title;
	  window.open('http://www.facebook.com/sharer.php?u='+escape(u)+'&t='+escape(t),'sharer','toolbar=0,status=0,width=626,height=436');
  }
  
  function shareTwitter (str) {
	  var u = location.href;
	  var t = document.title;
	  window.open('http://twitter.com/?status=' + escape((str ? str : 'Check out')+ ' ' + t +' at ' + u),'sharer');
  }
  
  function shareMyspace (T, C, U, L)	{
  	  var T = document.title;
  	  var U = location.href;
  	  var desc = '';  
  	  var metas = document.getElementsByTagName('meta');
			for (var x=0,y=metas.length; x<y; x++) {
			  if (metas[x].name.toLowerCase() == "description") {
			    desc = metas[x].content ? metas[x].content : metas[x];
			  }
			}	  
  	  var C = T + '<br />' + desc + ' <a href="'+ U +'">Check it out</a>.';  	  
  	  var L = 2;
	    var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + escape(T)
	    + '&c=' + escape(C) + '&u=' + escape(U) + '&l=' + L;
	    window.open(targetUrl,'sharer');
	}
