var groupNames = new Array(); 

groupNames['members']= 		'members';
groupNames['all-forums']= 	'All';
groupNames['esection']=		'e-Section members';
groupNames['am']= 			'Lean Manufacturing';
groupNames['asd']=			'Aviation, Space & Defense';
groupNames['audit']=		'Quality Audit';
groupNames['auto']=			'Automotive';
groupNames['biomed']=		'Biomedical';
groupNames['communities']=	'ASQ Communities';
groupNames['cpi']=			'Chemical & Process Industries';
groupNames['cqc']= 			'Community Quality Councils';
groupNames['cs']= 			'Customer-Supplier';
groupNames['design']= 		'Design and Construction';
groupNames['ec']=			'Electronic and Communications';
groupNames['edu']= 			'Education';
groupNames['ee']= 			'Energy and Environmental';
groupNames['fdc']= 			'Food-Drug-Cosmetic';
groupNames['gov']= 			'Governement';
groupNames['health']= 		'Healthcare';
groupNames['ii']=	 		'Information Integrity';
groupNames['inspect']= 		'Inspection';
groupNames['hdl']=	 		'Human Development & Leadership';
groupNames['le']=			'Lean Manufacturing';
groupNames['measure']= 		'Measurement Quality';
groupNames['pslp']= 		'Product Safety & Liability Prevention';
groupNames['qm']= 			'Quality Management';
groupNames['reliability']= 	'Reliability';
groupNames['service']= 		'Service Quality';
groupNames['sixsigma']= 	'Six Sigma';
groupNames['softwareforum']='Software Forum';
groupNames['statistics']= 	'Statistics';
groupNames['teamwork']= 	'Teamwork & Participation';
groupNames['textile']= 		'Textile';

function drawSearch(){
	drawGoogleMiniSearch();
	//drawUltrasearch();
}

function drawGoogleMiniSearch() {
	var groupURLname	= getGroupURLname('URL');
	var forumAddedLines	= '';

	if ( groupURLname != '' ) {
		var groupLabel= getGroupLabel(groupURLname);

		forumAddedLines = 	'<input type=radio name=restrict value="' + groupURLname + '" checked><small>' + groupLabel + '</small> &nbsp;' +
							'<input type=radio name=restrict value=""><small>ASQ</small> &nbsp;' ;
	}

	document.getElementById('search').innerHTML = 
	'<form method="get" name="gsearch" action="http://search.asq.org">' 					+
	'  <input type="hidden" name="site" value="my_collection"/>' 							+
	'  <input type="hidden" name="client" value="my_collection"/>' 							+
	'  <input type="hidden" name="proxystylesheet" value="my_collection"/>' 				+
	'  <input type="hidden" name="output" value="xml_no_dtd"/>' 							+
	'  <input type="text" name="q" size="23" maxlength="255" value=""/><br>' 				+
	   forumAddedLines																		+ 
	'  <font color=#3165ce><a href="#" onclick="gsearch.submit();">GO!</a></font></CENTER>' ;
}


function drawUltrasearch() {
	document.getElementById('search').innerHTML = 
	'<form name="usearchQbox" method="post" action="/ultrasearch/query/search.jsp">'		+
	'<input type="hidden" name="usearch_nextview" value="Submit">'							+
	'<input type="hidden" name="usearch_startnum" value="">'								+
	'<input type="hidden" name="usearch_endnum" value="">'									+
	'<input type="hidden" name="usearch.p_attrows" value="null">'							+
	'<input type="hidden" name="usearch.p_mode" value="Basic">'								+
	'<input type="hidden" name="grp" value="">'												+
	'<input type="hidden" name="grps" value="">'											+
	'<input type="text" size="15" maxlength="2000" name="p_mainsearch" value="">'			+
	'<font color=#3165ce><a href="#" onclick="usearchQbox.submit();">GO!</a></font>'		;
}

function handleRestrict(){
	if ( location.href.indexOf("restrict=") > -1){
		var isASQchecked = ''; var isGroupchecked = '';		

		var  groupURLname= getGroupURLname('URL','restrict');
		if ( groupURLname.length == 0 && document.cookie.toString().indexOf("restri") > -1 ){
			 groupURLname= getGroupURLname('cookie');
			isASQchecked = 'checked';
		}
		else {
			document.cookie = 'restri=' + groupURLname + ';path=/;' ;
			isGroupchecked = 'checked';
		}

		if (groupURLname.length > 1 || isASQchecked == 'checked'){
			var groupLabel	 = getGroupLabel(groupURLname);
			var groupLongName= getGroupLongName(groupURLname);

			forumAddedLines = 	'<input type=radio name=restrictR value="' + groupURLname + '" onclick="changeRestrict(' + "'" + groupURLname + "'" +  ') " ' + isGroupchecked + '><small>' + groupLongName + ' ' + groupLabel + '</small> &nbsp;&nbsp;' + 
								'<input type=radio name=restrictR value="" onclick="changeRestrict(' + "''" +')" ' + isASQchecked + '><small>All ASQ</small>' ;

			document.getElementById('searchForm_td').innerHTML = forumAddedLines + document.getElementById('searchForm_td').innerHTML ; 
			
		}
	}
}

function changeRestrict(selection){
	document.gs.restrict.value= selection ;
}

function getGroupURLname(fromWhere,caller) {
	var groupName = '';
	
	if (fromWhere == 'URL'){ 
		if (caller == 'restrict') {
			if (location.href.indexOf('restrict=') > -1) {
				groupName = location.href.substring( location.href.indexOf('restrict=')+9 );
				if (groupName.indexOf('&') > -1) {
					groupName = groupName.substring(0,groupName.indexOf('&')); 
				}
			}
		}
		else if	(location.href.indexOf('g=') > -1) { 
			groupName = location.href.substring( location.href.indexOf('g=')+2 ) ;
			if 	(groupName.indexOf('&') > -1) { 
				groupName = groupName.substring(0,groupName.indexOf('&')); 
			}
		}
		else if (location.href.indexOf('/forums/') > -1) { 
			groupName = location.href.substring( location.href.indexOf('/forums/')+8 ) ;
			groupName = groupName.substring(0,groupName.indexOf('/')); 
		}
		else if (location.href.indexOf('/perl/search') == -1) {
			groupName = location.href.substring( location.href.indexOf('asq.org/')+8 ) ;
			groupName = groupName.substring(0,groupName.indexOf('/')); 
		}
	}
	else if (fromWhere == 'cookie'){
			var startAt			=  document.cookie.toString().indexOf("restri=")+7; 
			var remainingPart 	=  document.cookie.toString().substring(startAt);

			groupName = remainingPart.indexOf(";") >-1 	? remainingPart.substring(0,remainingPart.indexOf(";")) 
														: remainingPart ;
	} 
	return groupName;
}

function getGroupLongName(groupURLname) {
	if (groupNames[groupURLname] == undefined) {
		return 	   groupURLname ;
	}
	else {
		return groupNames[groupURLname] ;
	}
}


function getGroupLabel(groupName){
	var groupLabel = '';
	if 		(groupName == 'sixsigma' || groupName == 'teamwork' ) 	{ groupLabel = 'Forum'; 	}
	else if (groupName == 'esection' ) 								{ groupLabel = 'eSection'; } 
	else if (groupName == 'communities' ) 							{ groupLabel = 'Network'; 	}
	else if (groupName == 'ii' ) 									{ groupLabel = 'I.I.';		}
	else if (groupName == 'all-forums' ) 							{ groupLabel = 'Divisions';}
	else 															{ groupLabel = 'Division'; }
	return groupLabel;
}


