/**
 * Get a URL parameter from window.location.href.
 * @param name of the parameter to find
 * @returns value of the first instance of the parameter, empty string if not found
 */
function getUrlParameter( name, href ){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&#]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( href );
	if( results == null )
		return "";
	else
		return results[1];
}

function retrievePath( href ){
	var lastIndex = href.lastIndexOf("/");
	var path = href.substr(0,lastIndex+1);
	return path;
}

function loadAjaxRequest(){
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp=false;
		}
	}
}

/**
 * Shows the products found panel by switching the css class name of the parent
 * and switching the image.
 * @param obj The object which is being hovered
 */
function showProductsFoundLabel(obj){
	obj.className="familyproductheaderHover";
	
	var images = obj.getElementsByTagName("img");
	for(var i=0; i<images.length; i++) {
		var value = images[i];
		value.src="/assets_lt/img/blue_count_lines.png";
	}
}

/**
 * Hides the products found panel by switching the css class name of the parent
 * and switching the image.
 * @param obj The object which is being hovered
 */
function hideProductsFoundLabel(obj){
	obj.className="familyproductheader";
	
	var images = obj.getElementsByTagName("img");
	for(var i=0; i<images.length; i++) {
		var value = images[i];
		value.src="/assets_lt/img/count_lines.png";
	}
}

/**
 * Preloads the hover image to make the image available immediately when hovering
 */
function productImagePreloader(){
	var hoverImage = new Image(); 
	hoverImage.src = "/assets_lt/img/blue_count_lines.png";
}

/**
 * Adds a shade to the background when hovering over a tile
 * @param obj The object which is being hovered
 */
function tileHover(obj){
	obj.className="tileblockHover";
}

/**
 * Removes the shade from the background onmouseout
 * @param obj The object which is being hovered
 */
function tileUnHover(obj){
	obj.className="tileblock";
}


function showLinkUnderline(obj){
	var imageDivNode = obj.parentNode.parentNode;
	var nameDivNode = getNextElementSibling(imageDivNode);
	
	nameDivNode.className="familynameHover";
}

function hideLinkUnderline(obj){
	var imageDivNode = obj.parentNode.parentNode;
	var nameDivNode = getNextElementSibling(imageDivNode);
	
	nameDivNode.className="familyname";
}

function getPreviousElementSibling(obj){
	var previousSibling = obj.previousSibling;
	while( previousSibling != null && previousSibling.nodeType != 1){
		previousSibling = previousSibling.previousSibling;
	}
	return previousSibling;
}

function getNextElementSibling(obj){
	var nextSibling = obj.nextSibling;
	while( nextSibling != null && nextSibling.nodeType != 1){
		nextSibling = nextSibling.nextSibling;
	}
	return nextSibling;
}

