

function brightStars (num)
{	
	if (!document.images) return;

	for (var i = 1; i <= num; i ++)
	{
		document.getElementById ('star' + i).src = "images/icons/star.png";
	}
	
	if (num == 1) document.getElementById ('ratingLegend').innerHTML = 'Hated it';
	if (num == 2) document.getElementById ('ratingLegend').innerHTML = 'Alright';
	if (num == 3) document.getElementById ('ratingLegend').innerHTML = 'Good times';
	if (num == 4) document.getElementById ('ratingLegend').innerHTML = 'Awesome';
	if (num == 5) document.getElementById ('ratingLegend').innerHTML = 'Best ever';

/*
	if (document.images) 
	{
		img_on = new Image();  img_on.src ="../hi-icons/1.gif"; 
		img_off = new Image();  img_off.src="../hi-icons/2.gif"; 
	}
	
	function handleOver() { 
	 if (document.images) document.imgName.src=img_on.src;
	}

	function handleOut() {
	 if (document.images) document.imgName.src=img_off.src;
	}			
*/	
}

function dullStars (num)
{	
	if (!document.images) return;

	for (var i = 1; i <= num; i ++)
	{
		document.getElementById ('star' + i).src = "images/icons/star_gray.png";
	}
	
	document.getElementById ('ratingLegend').innerHTML = '';
}	

function toggleDisplayOnSelect (value, targetElementName)
{	
//	alert ('value = ' + value + ', targetElementName = ' + targetElementName);
	
	var hider = document.getElementById (targetElementName);
	
//	alert (hider.innerHTML);

	if (value == 'nothere')
	{
		hider.style.display = 'block';
	}
	
	else hider.style.display = 'none';
}

function togglechecked ()
{ 	
	for (var i = 0; i < document.inviteform.elements.length; i++) 
	{
		var e = document.inviteform.elements[i];

		if ((e.disabled == false) && (e.name != 'mastercheckbox') && (e.type == 'checkbox')) 
		{
			e.checked = document.inviteform.mastercheckbox.checked;
		}
	}

	var span = document.getElementById ('checkclear');
	
	if (document.inviteform.mastercheckbox.checked)
	{
		span.innerHTML = 'Clear All';
	}
	
	else
	{
		span.innerHTML = 'Check All';
	}
}

function toggleselect ()
{ 
	document.inviteform.mastercheckbox.checked = !document.inviteform.mastercheckbox.checked;
	togglechecked();
}

//prepareImageSwap(document.body);

function prepareImageSwap(elem,mouseOver,mouseOutRestore,mouseDown,mouseUpRestore,mouseOut,mouseUp) { 
    if (typeof(elem) == 'string') elem = document.getElementById(elem); 
    if (elem == null) return; 
    var regg = /(.*)(_nm\.)([^\.]{3,4})$/ 
    var prel = new Array(), img, imgList, imgsrc, mtchd; 
    imgList = elem.getElementsByTagName('img'); 
    for (var i=0; img = imgList[i]; i++) { 
        if (!img.rolloverSet && img.src.match(regg)) { 
            mtchd = img.src.match(regg); 
            img.hoverSRC = mtchd[1]+'_hv.'+ mtchd[3]; 
            img.outSRC = img.src; 
            if (typeof(mouseOver) != 'undefined') { 
                img.hoverSRC = (mouseOver) ? mtchd[1]+'_hv.'+ mtchd[3] : false; 
                img.outSRC = (mouseOut) ? mtchd[1]+'_ou.'+ mtchd[3] : (mouseOver && mouseOutRestore) ? img.src : false; 
                img.mdownSRC = (mouseDown) ? mtchd[1]+'_md.' + mtchd[3] : false; 
                img.mupSRC = (mouseUp) ? mtchd[1]+'_mu.' + mtchd[3] : (mouseOver && mouseDown && mouseUpRestore) ? img.hoverSRC : (mouseDown && mouseUpRestore) ? img.src : false; 
                } 
            if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;} 
            if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;} 
            if (img.mdownSRC) {preLoadImg(img.mdownSRC); img.onmousedown = imgMouseDownSwap;} 
            if (img.mupSRC) {preLoadImg(img.mupSRC); img.onmouseup = imgMouseUpSwap;} 
            img.rolloverSet = true; 
        } 
    } 
    function preLoadImg(imgSrc) { 
        prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc; 
    } 
} 
function imgHoverSwap() {this.src = this.hoverSRC;} 
function imgOutSwap() {this.src = this.outSRC;} 
function imgMouseDownSwap() {this.src = this.mdownSRC;} 
function imgMouseUpSwap() {this.src = this.mupSRC;}

function loadingMessage (elementID)
{
	document.getElementById(elementID).innerHTML = "<img src='images/spinner.gif' alt='Loading...' />"; 	
}

//onLoad="javascript:preloader()"

function preloader () 
{
	spinner = new Image(); 
	spinner.src = "images/spinner.gif";

	star = new Image(); 
	star.src = "images/icons/star.png";
	
	grayStar = new Image(); 
	grayStar.src = "images/icons/star_gray.png";	
}

function selectRow (row)
{
//	row.style.class=\'selectRow\';	
}

function newProvinceSelectedMJ (provinceID)
{
	loadingMessage('citySpan');						//spinner
	document.getElementById('newVenueInput').style.display = 'none';
	xajax_populateCitiesWithVenue (provinceID);		//populate new cities according to selected province
}

function newCitySelectedMJ (cityID)
{	
	loadingMessage('venueSpan');
		
	if (cityID == 'nothere')
	{
		var provinceID = document.getElementById('province').value;
		var cityName = prompt ('What is the name of the City?');
		if (cityName != '') xajax_insertCity (provinceID, cityName);
	}	

	document.getElementById('newVenueInput').style.display = 'none';
	xajax_populateVenues(cityID); //must select right one too
}

function newVenueSelectedMJ (venueID)
{
	toggleDisplayOnSelect (venueID, 'newVenueInput');

//	var cityID = document.getElementById('city').value;
//	var venueName = prompt ('What is the name of the Venue?');
//	if (venueName != '') xajax_insertVenue (cityID, venueName);
}

function setSelectedCity (cityID)
{	alert ('setting selected city');
	box = document.getElementById('city');
	alert (box.options.length);
	
	for (var i = 0; i < box.options.length; i ++)
	{
		alert ('checking ' + cityID + ' against ' + box.options[i].value);
		
		if (box.options[i].value == cityID)
		{
			box.selectedIndex = box.options[i].index;
			break;
		}
	}
}

function toggleDisplay (linkID, divID)
{
	var div = document.getElementById (divID);
	var link = document.getElementById (linkID);
	
	if (div.style.display == 'none')
	{
		div.style.display = 'block';
		link.innerHTML = 'collapse';
	}
	
	else
	{
		div.style.display = 'none';
		link.innerHTML = 'expand';
	}
}

function id (x) 
{
	return document.getElementById(x);
}

function xClientHeight()
{
  var v=0,d=document,w=window;
  if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientHeight)
    {v=d.documentElement.clientHeight;}
  else if(d.body && d.body.clientHeight)
    {v=d.body.clientHeight;}
  else if(xDef(w.innerWidth,w.innerHeight,d.width)) {
    v=w.innerHeight;
    if(d.width>w.innerWidth) v-=16;
  }
  return v;
}

function xClientWidth()
{
  var v=0,d=document,w=window;
  if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientWidth)
    {v=d.documentElement.clientWidth;}
  else if(d.body && d.body.clientWidth)
    {v=d.body.clientWidth;}
  else if(xDef(w.innerWidth,w.innerHeight,d.height)) {
    v=w.innerWidth;
    if(d.height>w.innerHeight) v-=16;
  }
  return v;
}

function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xNum()
{
  for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}
  return true;
}

function xScrollTop(e, bWin)
{
  var offset=0;
  if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    var w = window;
    if (bWin && e) w = e;
    if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
    else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
  }
  else {
    e = xGetElementById(e);
    if (e && xNum(e.scrollTop)) offset = e.scrollTop;
  }
  return offset;
}
