// load swfobject 
new Asset.javascript('/js/swfobject.js');

// legacy popup window function
function openWin(imsrc, ww, wh) {
	ww=ww+50; wh=wh+50;
	w1=window.open('','w1','width='+ww+',height='+wh+',status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes');
	w1.document.open();
	w1.document.write("<html><head><title>Large Image<\/title><\/head>");
	w1.document.write("<body bgcolor='#FFFFFF' text='#000000' leftmargin=2 topmargin=10><div align=center>");
	w1.document.write("<a href=javascript:close();><img name=theimg src=" + imsrc + " border=0 alt=\"Click to Close\" title=\"Click to Close\"></a><br>");
	w1.document.write("<a href=\"javascript:window.close();\">close window<\/a><\/div><\/body><\/html>");
	w1.focus();
};


/* open popup to nexternal */
function popNexternal(anHREF) {
	
	var twidth = 830;
	var theight = 650;
	
	var chasm = screen.availWidth;
	var mount = screen.availHeight;
	var attribs = 'toolbar=yes,location=no,directories=yes,width='+twidth+',height='+theight+',left=' + ((chasm - twidth - 10) * .5) + ',top=' + ((mount - theight - 30) * .5 ) + ',resizable=yes,status=yes,menubar=yes,scrollbars=yes';

	if (self.nexternal) {
		if (self.nexternal.closed) {
			popupwin = window.open(anHREF,'nexternal',attribs);
			self.nexternal = popupwin;
		} else {
			self.nexternal.focus();
		}
		self.nexternal.location.href = anHREF;
	} else {
		popupwin = window.open(anHREF,'nexternal',attribs);
		self.nexternal = popupwin;
		self.nexternal.focus();
	}
}

/* open popup  */
function openPopup(anHREF, twidth, theight) {
	
	var chasm = screen.availWidth;
	var mount = screen.availHeight;
	var attribs = 'toolbar=yes,location=no,directories=yes,width='+twidth+',height='+theight+',left=' + ((chasm - twidth - 10) * .5) + ',top=' + ((mount - theight - 30) * .5 ) + ',resizable=yes,status=yes,menubar=yes,scrollbars=yes';

	if (self.popup) {
		if (self.popup.closed) {
			popupwin = window.open(anHREF,'popup',attribs);
			self.popup = popupwin;
		} else {
			self.popup.focus();
		}
		self.popup.location.href = anHREF;
	} else {
		popupwin = window.open(anHREF,'popup',attribs);
		self.popup = popupwin;
		self.popup.focus();
	}
}

/* open link in popup to parent window */
function openParent(anHREF) {
	self.opener.location.href = anHREF;
	self.opener.focus();
	self.close();
}


/* fix nexternal links */
function initNexternal() {
	$$('a').each(function(el){
		if (el.hasClass('nexternal')) {
			el.target = "_self";
			el.onclick = function() {
				popNexternal(this.href);
				return false;
			}
		}
	});	
}
/* attach to domready event */
window.addEvent('domready', initNexternal);



/* init country selector */
var current_country;
var default_country = 'us';

function initCountrySelector() {
	
	/* get the country cookie */
	if (getCookie('country')) {
		current_country = getCookie('country');
	} else {
		current_country = default_country;
	}
	
	/* if the form is found, initialize it */
	var countryElem = $('countryElem');
	if (countryElem) {
		
		/* show the current country */
		showCountry(current_country);
		
		/* init the onchange event */
		countryElem.onchange = function() {
			changeCountry(this.value);
		};
		
		/* update the form value with the current country */
		countryElem.value = current_country;
		
	}
	
}

/* attach to domready event */
window.addEvent('domready', initCountrySelector);

/* show the country order form */ 
function showCountry(country) {
	if (country == 'other') {
		country = 'us';
	}
	cformid = country+'Form';
	cform = $(cformid);
	if (cform) cform.removeClass('hideForm');
	
	cformid2 = country+'Form2';
	cform2 = $(cformid2);
	if (cform2) cform2.removeClass('hideForm');
}

/* hide country */
function hideCountry(country) {
	if (country == 'other') {
		country = 'us';
	}
	cformid = country+'Form';
	cform = $(cformid);
	if (cform) cform.addClass('hideForm');
	
	cformid2 = country+'Form2';
	cform2 = $(cformid2);
	if (cform2) cform2.addClass('hideForm');
}

/* change the country */
function changeCountry(country) {
	hideCountry(current_country);
	showCountry(country);
	setCookie('country', country);
	current_country = country;
}



/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}



/* set up print button */
window.addEvent('domready', function() {
	var btn_print = $('content-btn-print');
	btn_print.onclick = (function(a){
		window.print(); 
		return false;
	});									 
});





