
var ns4, op5, op6, agt, mac, ie, firefox, mac_ie;
var debug=false;


function searchCatalog(searchCat, searchByList, searchText){

	var searchBy="";
	if(searchByList && searchByList){
		for(i=0;i<searchByList.length;i++){
			
			if(searchByList[i].checked){
				searchBy=searchByList[i].value;	
			}
		}
	
	}
	
	if(searchBy==""){
		searchBy=1;	
	}
	
	
	window.location="/catalog/search.asp?c="+searchCat+"&sb="+searchBy+"&t="+searchText;
}

function rightNavHighlight(){
	
	if(document.getElementById('siteRightNav')){
		theRightNav = document.getElementById('siteRightNav');
		theLinks = theRightNav.getElementsByTagName('a');
		
		matchFound = false;
		
		//Detect browser
		sniffBrowsers();
		
		currentUrl = document.location.href;
		
		for(i=0;i<theLinks.length;i++){
			//alert(cleanUrl(theLinks[i].href) + " : " +cleanUrl(currentUrl));
			cleanNavLink = cleanUrl(theLinks[i].href);
			cleanCurrentUrl = cleanUrl(currentUrl);
			
			if(cleanNavLink==cleanCurrentUrl || cleanCurrentUrl.indexOf(cleanNavLink)>-1){
				activeLink = theLinks[i];
				
				matchFound=true;
				
			}
		}
		
		//activeLink = theLinks[1];
		
		//IF MATCHING NAV LINK IS FOUND
		if(matchFound){
			activeLink.className = "active";				
			
		}
		
		
	}
}




function navHighlight(){

	theNav = document.getElementById('siteNav');
	theLinks = theNav.getElementsByTagName('a');
	
	matchFound = false;
	
	//Detect browser
	sniffBrowsers();
	
	currentUrl = document.location.href;
	
	for(i=0;i<theLinks.length;i++){
		//alert(cleanUrl(theLinks[i].href) + " : " +cleanUrl(currentUrl));
		cleanNavLink = cleanUrl(theLinks[i].href);
		cleanCurrentUrl = cleanUrl(currentUrl);
		
		if(cleanNavLink==cleanCurrentUrl || cleanCurrentUrl.indexOf(cleanNavLink)>-1){
			activeLink = theLinks[i];
			
			matchFound=true;
			
		}
	}
	
	//activeLink = theLinks[1];
	
	//IF MATCHING NAV LINK IS FOUND
	if(matchFound){
		activeLink.className = "active";					
		
	}
	//alert(findPos(theLinks[0]));
}

//cleans a url for better comparison
function cleanUrl(theLink){
	if(theLink.indexOf('http:')>-1){
		theLink	= theLink.substr(theLink.indexOf('http:')+5, theLink.length);
	}
	if(theLink.indexOf('index.html')>-1){
		theLink	= theLink.substr(0,theLink.indexOf('index.html'));
	}
	if(theLink[theLink.length-1]=='/'){
		theLink = theLink.substr(0, theLink.length-1);	
	}
	
	return theLink;
}




function inputStyles(){
	pageInputs = document.getElementsByTagName('input');
	
	
	//style buttons
	for(pi=0;pi<pageInputs.length;pi++){
		if(pageInputs[pi].type=='submit' || pageInputs[pi].type=='reset' || pageInputs[pi].type=='button'){
			pageInputs[pi].className="input-button";
		}else if(pageInputs[pi].type=="checkbox" || pageInputs[pi].type=="radio"){
			pageInputs[pi].className="input-checkbox";	
		}
	}
	
}

function centerObject(objToCenter, objContainer){
	
	if(objToCenter && objContainer){
		localTrace("centerObject("+objToCenter+","+objContainer+")");
		
		marginLeft = (findWidth(objContainer)-findWidth(objToCenter))/2;
		localTrace("objToCenter.width="+findWidth(objToCenter));
		localTrace("objContainer.width="+findWidth(objContainer));
		localTrace("style.marginLeft="+marginLeft);
		objToCenter.style.marginLeft=marginLeft+"px";
		
		
		
	}else{
		console.log("Could not complete centerObject().");	
	}
}

function localTrace(msg){
	if(debug){
		if(ie){
			alert(msg);
		}else if(firefox){
			console.log(msg);
		} 
	}
}


function getURL(url){
	
	window.location=url;	
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}


function findHeight(obj) {
		
		if (op5) {
			yPos = obj.style.pixelHeight;
		} else {
			yPos = obj.offsetHeight;
		}
		return yPos;
	
}



function findWidth(obj) {
		
		if (op5) {
			xPos = obj.style.pixelWidth;
		} else {
			xPos = obj.offsetWidth;
		}
		return xPos;
	
}


function sniffBrowsers() {
	ns4 = document.layers;
	op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) 
		||(navigator.userAgent.indexOf("Opera/5")!=-1);
	op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) 
		||(navigator.userAgent.indexOf("Opera/6")!=-1);
	firefox=(navigator.userAgent.indexOf("Firefox")!=-1)
	agt=navigator.userAgent.toLowerCase();
	mac = (agt.indexOf("mac")!=-1);
	ie = (agt.indexOf("msie") != -1); 
	mac_ie = mac && ie;
}


sniffBrowsers();
