var sc=document.createElement('script');
sc.type='text/javascript';
sc.id="_cfga";
sc.src='http://www.google-analytics.com/urchin.js';
document.getElementsByTagName('head')[0].appendChild(sc);

function toggleVisibility(id) {
	if(typeof id=='string')
		id=document.getElementById(id);
	if(!id)
		return;
	if(id.style.display!='')
		id.style.display='';
	else id.style.display='none';
	return id.style.display;
}
function ratingHighlight(img, num) {
	// get all images named img.name
	imgs = document.getElementsByName(img.name);
	// array of ratings
	var ratings = new Array('Awful', 'Poor', 'Average', 'Good', 'Excellent');
	// for any rating > 0 we need hover pictures
	var name = (num == 0 ? 'white' : 'hover');
	for(i = 0; i < imgs.length; i++) {
		imgs[i].src = 'images/stars/yri_star_' + name + '.png';
		if(((typeof num) == 'undefined' && img == imgs[i]) || i+1 == num) {
			//document.getElementById('rating').innerHTML = ratings[i];
			name = 'white';
		}
	}
}
function ratingReset(img, userRating) {
	ratingHighlight(img, userRating);
	//document.getElementById('rating').innerHTML = '';
}
function ratingSet(type,id,num) {
	AjaxRequest(null, 'ratingSet', type, id, num);
	userRating = num;
}
function XMLHttpRequst(url, node) {
	var req = getXmlHttpRequest();
	req.open('GET', url, node ? true : false);

	if (node) {
		req.onreadystatechange = function() {
			if(req.readyState == 4) {
				if(req.status == 200) {
					if (req.responseXML) {
						// remove all child nodes
						while(node.hasChildNodes()) {
							node.removeChild(node.firstChild);
						}

						// insert all input nodes into DOM
						ow.injectInputNodes(node, req.responseXML.documentElement, "input");

						// insert script node into DOM
						scriptsArray = req.responseXML.documentElement.getElementsByTagName("script");
						scriptEl = document.createElement("script");
						scriptEl.appendChild(document.createTextNode(scriptsArray[0].firstChild.data));
						node.appendChild(scriptEl);
					} else {
						node.innerHTML = req.responseText;
					}
				} else {
					dump("Error loading page\n");
				}
			}
		};
	}

	req.send(null);

	if (!node) {
		return req.responseText;
	}
}
function getXmlHttpRequest(){
	var xmlHttp;
	try {
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		var xmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
		                                'MSXML2.XMLHTTP.5.0',
		                                'MSXML2.XMLHTTP.4.0',
		                                'MSXML2.XMLHTTP.3.0',
		                                'MSXML2.XMLHTTP',
		                                'Microsoft.XMLHTTP');
		for (var i = 0; i < xmlHttpVersions.length && !xmlHttp; ++i) {
			try {
				xmlHttp = new ActiveXObject(xmlHttpVersions[i]);
			} catch (e) {}
		}
	}
	if (!xmlHttp)
		alert("Error creating the XMLHttpRequest object!");
	else
		return xmlHttp;
}

function AjaxRequest(node, func){
	var url = baseURI+'ajax.php?f=' + func;
	for (var i = 2; i < arguments.length; i++)
		if(arguments[i])
			url += '&p[' + (i-1) + ']=' + encodeURIComponent(arguments[i]);
	return XMLHttpRequst(url, node);
}