function redirect(selectObj) {
	document.location = selectObj.options[selectObj.selectedIndex].value;
}

function getRef(obj){
        return (typeof obj == "string") ?
        document.getElementById(obj) : obj;
}

function setStyle(obj,style,value){
        getRef(obj).style[style]= value;
}

function setClassName(obj, className){
        getRef(obj).className= className;
}

/*
	Function used by various CWI widgets for click tracking
*/
function doClick() {
			
	if ( arguments.length == 2 ) {	// arguments are 0 - anchor reference, 1 - widget id (destination type is assumed to be 'doc')
		var destination = arguments[0].href;
		var destination_title = null;
		if ( arguments[0].innerText )
			destination_title = arguments[0].innerText;
		else if ( arguments[0].textContent )
			destination_title = arguments[0].textContent;
		else if ( arguments[0].childNodes[0] && arguments[0].childNodes[0].nodeType == "TEXT_NODE" )
			destination_title = arguments[0].childNodes[0].nodeValue;
		else
			destination_title = 'Unavble';

		sendClick(destination, destination_title, 'doc', arguments[1]);
	}
	if ( arguments.length == 3 ) { // arguments are 0 - anchor reference, 1 - destination type, 2 - widget id
		var destination = arguments[0].href;
		var destination_title = null;
		if ( arguments[0].innerText )
			destination_title = arguments[0].innerText;
		else if ( arguments[0].textContent )
			destination_title = arguments[0].textContent;
		else if ( arguments[0].childNodes[0] && arguments[0].childNodes[0].nodeType == "TEXT_NODE" )
			destination_title = arguments[0].childNodes[0].nodeValue;
		else
			destination_title = 'Unavble';

		sendClick(destination, destination_title, arguments[1], arguments[2]);
	}
	else if ( arguments.length == 4 ) { // arguments are 0 - destination, 1 - destination title, 2 - destination type, 3 - widget id
		sendClick(arguments[0], arguments[1], arguments[2], arguments[3]);
	}
}

/*
	Function which sends click track request
*/
function sendClick(destination, destination_title, destination_type, widget_id) {
	
	// source info
	var source = document.location.href;
	var source_title = document.title;
	
	// add source info to click counter
	var click_url = 'http://' + document.location.hostname + '/scripts/stats/click.aspx?s=' + encodeURIComponent(source) + '&st=' + encodeURIComponent(source_title) + '&w=' + encodeURIComponent(widget_id);

	// add destination info to click counter
	click_url += '&d=' + encodeURIComponent(destination) + '&dt=' + encodeURIComponent(destination_title) + '&dp=' + encodeURIComponent(destination_type);

	//alert(click_url);

	var http_req = null;
	
	if ( window.XMLHttpRequest ) {
		try {
			http_req = new XMLHttpRequest();
		}
		catch (e) {
			http_req = false;
		}
	}
	else if ( window.ActiveXObject ) {
		try {
			http_req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				http_req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				http_req = false;
			}
		}
	}

	if (http_req) {
		if ( document.all ) {
			http_req.onreadystatechange = doNothing;
			http_req.open("GET", click_url, true);
		}
		else
			http_req.open("GET", click_url, false);
		http_req.send("");
	}
}

/*
	Required for async XmlHttpRequest 	
*/
function doNothing() {
	// do nothing
}


