// functions that work with windows


function onChangeCountry(countryDropdown, stateDropdown, stateBlock, ajaxIndicator, ajaxUrl)
{
	var currentCountry = htmlHelper.currentOption(countryDropdown);
	if (currentCountry.value=='US' || currentCountry.value=='CA')
	{
		ajaxIndicator.style.visibility = 'visible';
		new Ajax.Request(ajaxUrl.replace(/\$iso/i, currentCountry.value),
		{
			method		: 'GET',
			onException	: function(req, e) { throw e },
			onSuccess	: function(transport)
			{
				ajaxIndicator.style.visibility = 'hidden';
				var xml = transport.responseXML;
				if (xml)
				{
					var states = {'':''};
					var nodes = xml.getElementsByTagName('state');
					for (var i=0; i<nodes.length; i++)
					{
						var sid = nodes.item(i).getAttribute('sid');
						var name = nodes.item(i).getAttribute('name');
						states[sid] = sid + ' (' + name + ')';
					}
					htmlHelper.replaceOptions(stateDropdown, states);
					stateBlock.style.display = 'inline';			
					return;
				}
			}
		});
	}	
	stateBlock.style.display = 'none';
}


/**
 * always open one window only
 */
function winOpener(url, name, args) 
{
    if (typeof(popupWin) != "object"){
        popupWin = window.open(url,name,args);
    } else {
        if (!popupWin.closed){
            popupWin.location.href = url;
        } else {
            popupWin = window.open(url, name,args);
        }
    }
    popupWin.focus();
}

/**
 * focus and open url on the base window (opener)
 */
function winOpenBase(url) 
{
    if (window.opener && !window.opener.closed) {
        window.opener.document.location.href = url;
    }
    window.opener.focus();
    // window.close();
}

// returns number of new names added to className attribute
function addClass(theElement, classToAdd) {
    classList = theElement.className.split(' ');
    alreadyThere = false;
    for (var i=0;i<classList.length;i++) {
        if (classList[i] == classToAdd) {
            alreadyThere = true;
            break;
        }
    }
    if (alreadyThere) {
        return 0;
    } else {
        classList.push(classToAdd);
        classList.sort();
        theElement.className = classList.join(' ');
        return 1;
    }
}

// returns number of names removed from className attribute
function removeClass(theElement, classToRemove) {
    classList = theElement.className.split(' ');
    if (classToRemove == '*') {
        theElement.className = '';
        return classList.length;
    }
    classesRemoved = 0;
    for (var i=0;i<classList.length;i++) {
        if (classList[i] == classToRemove) {
            classList.splice(i, 1);
            ++classesRemoved;
        }
    }
    if (classesRemoved > 0) {
        theElement.className = classList.join(' ');
    }
    return classesRemoved;
}


function showError()
{
  if($('inline_msg') != null)
  {
     $('inline_msg').id = 'nonthing';
  }

  $('nonthing').style.display= "none";


  document.write('<div style="clear: both;"></div><div id="inline_msg" style="display:none;"></div>');
}

function open_msd_window (url) {
  var win = window.open(url, "MSD", "width=500,height=400,resizable=yes,scrollbars=no");
  if (win.focus != null) {
    win.focus();
  }
}

function textOutline(msg, fontSize)
{
	var message=msg;
	var thickness=1
	var color2="white";
	var color1="black";
	var extra="font-size:" + fontSize + "px;";
	var x = -thickness;
	var y = -thickness;

	while (y<=thickness) {
		while (x<=thickness) {

			document.write ("<span style='"+extra+" color:"+color2+"; position:absolute; left:"+x+"; top:"+(-y)+"px;'>"+message+"</span>");
			document.write ("<span style='"+extra+" color:"+color2+"; position:absolute; left:"+x+"px; top:0;'>"+message+"</span>");
			document.write ("<span style='"+extra+" color:"+color2+"; position:absolute; left:"+x+"px; top:"+y+";'>"+message+"</span>");

			x=x+1;
		}
		y=y+1;
	}

	document.write ("<span style='"+extra+" color:"+color1+"; position:absolute; left:0; top:0;'>"+message+"</span>");
}
