// functions.js

function getArgs() {
	var args = new Object();
	// Get Query String
	var query = location.search.substring(1); 
	// Split query at the comma
	var pairs = query.split("&"); 
	
	// Begin loop through the querystring
	for(var i = 0; i < pairs.length; i++) {

		// Look for "name=value"
		var pos = pairs[i].indexOf('='); 
		// if not found, skip to next
		if (pos == -1) continue; 
		// Extract the name
		var argname = pairs[i].substring(0,pos); 
		
		// Extract the value
		var value = pairs[i].substring(pos+1); 
		// Store as a property
		args[argname] = unescape(value); 
	}
	return args; // Return the Object
}

function loadTopics(thisForm, index){

//index = options.selectedIndex

  for (m = thisForm.topic.options.length; m>=0; m--){
    thisForm.topic.options[m]=null    
    }
    
  for (i=0;i<(topicGroup[index].length);i++){
    thisForm.topic.options[i]=new Option(topicGroup[index][i].text,topicGroup[index][i].value)
  }
  thisForm.topic.options[0].selected=true
}

function selectTopic (thisForm, topicCode) {

	for (index=0;index < thisForm.topic.options.length;index++)  {
		if (thisForm.topic.options[index].value == topicCode) {
			thisForm.topic.options.selectedIndex = index;
			break;
		}
	}
}

function doMastSearch() {

  var mastquery = document.forms["mastform"].q.value;
  
  //if (mastquery == '') {
    //alert("No search string entered.\nPlease type your search string and try again.");
	if (document.mastform.prodID.selectedIndex == 0 ) {  // if all of IBM selected	
		window.location = "//www.ibm.com/search/help/";
		return false;
	}	
    else {  
  	return true;
  }
}


   var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}
   
 function changeColor(tempObject, newColor)  {
	
	if (!DHTML) return;
	
	var x = new getObj(tempObject);
	x.style.color = newColor;

 }
   
function switchOptions (whichDomain)  {
	
	if (whichDomain > 1) {  // Support search is selected
		document.myform.prodFamily.disabled = false;
		document.myform.prodID.disabled = false;
			
		//change labels to black
		changeColor ("labelFamilyOrProduct", "#000");
		changeColor ("labelFamily", "#000");
		changeColor ("labelProduct", "#000");
		changeColor ("labelHelpText", "#000");

		switchDocTypeTaskTopic("on");		
	
	}
	else {
		document.myform.prodFamily.disabled = true;
		document.myform.prodID.disabled = true;
		
		//change labels to grey
		changeColor ("labelFamilyOrProduct", "#999");  
		changeColor ("labelFamily", "#999");
		changeColor ("labelProduct", "#999");
		changeColor ("labelHelpText", "#999");
						
		switchDocTypeTaskTopic("off");	
			
	}
}

function switchDocTypeTaskTopic (switcher)  {


	// Only enable Doc type and Task/Topic if a user has selected a Family AND Product	
	//
	//	Enable Doc type choices if user selected the Doc type radio button
	//  If user chooses Task/topic radio button, enable dropdowns
	
		//alert ("family index: " + document.myform.prodFamily.selectedIndex);
		//alert ("product index: " + document.myform.prodID.selectedIndex);

		

		// if product family and product are both selected, enable the Doctype and task/topic radio buttons
		if (document.myform.prodID.selectedIndex > 0 && switcher=="on") {
		
			document.myform.radioSearchOption[0].disabled = false;
			document.myform.radioSearchOption[1].disabled = false;
			changeColor ("labelDocTypes", "#000");
			changeColor ("labelTaskTopic", "#000");
			
		
			//alert ("doc type checked: " + document.myform.radioSearchOption[0].checked);
			//alert ("tasktopic checked: " + document.myform.radioSearchOption[1].checked);
		
			// if doc type radio button is selected, enable doc type checkboxes and disable task/topic
			if ( document.myform.radioSearchOption[0].checked)  {  
		
				for (i=0; i < document.myform.searchDoctype.length; i++){
					document.myform.searchDoctype[i].disabled = false;
					}

				changeColor ("labelDocTypes", "#000");			
				changeColor ("docTypeCheckBoxes", "#000");
			
				// turn off task/topic
				document.myform.task.disabled = true;
				document.myform.topic.disabled = true;
			
				changeColor ("labelTask", "#999");
				changeColor ("labelTopic", "#999");
			}
			else if (document.myform.radioSearchOption[1].checked) {  // if task/topic radio button is selected, enable task/topic and disable doc type
			
				// turn off doc type
				for (i=0; i < document.myform.searchDoctype.length; i++){
					document.myform.searchDoctype[i].disabled = true;
				}
				changeColor ("docTypeCheckBoxes", "#999");
				
				// turn on task/topic	
				document.myform.task.disabled = false;
				document.myform.topic.disabled = false;
		
				changeColor ("labelTask", "#000");
				changeColor ("labelTopic", "#000");
				
			}
		}
		
		else {
		// if product is not selected, or "off" is passed in, turn everything off
		
			// turn off radio buttons.
			document.myform.radioSearchOption[0].disabled = true;
			document.myform.radioSearchOption[1].disabled = true;
				
				
			for (i=0; i < document.myform.searchDoctype.length; i++){
			document.myform.searchDoctype[i].disabled = true;
			}
			document.myform.task.disabled = true;
			document.myform.topic.disabled = true;
			
			//change labels to grey
			changeColor ("labelDocTypes", "#999");
			changeColor ("labelTaskTopic", "#999");
			changeColor ("docTypeCheckBoxes", "#999");
			changeColor ("labelTask", "#999");
			changeColor ("labelTopic", "#999");
		
		}
}
  