// Populate Product Line drop down
function fillCategory(autoCat, autoSub){
 // this function is used to fill the category list on load
 
// 		addOption(document.formfind.Category, "1", "D&O", "");
//		addOption(document.formfind.Category, "2", "EPL", "");

 	if(autoCat == 1){
		addOption(document.formfind.Category, "1", "Accountants Professional Liability", "1");
		SelectSubCat(autoSub);
	}
	else{
		addOption(document.formfind.Category, "1", "Accountants Professional Liability", "");
	}

 	if(autoCat == 2){
		addOption(document.formfind.Category, "2", "Directors & Officers Liability", "1");
		SelectSubCat(autoSub);
	}
	else{
		addOption(document.formfind.Category, "2", "Directors & Officers Liability", "");
	}

 	if(autoCat == 3){
		addOption(document.formfind.Category, "3", "Employment Practices Liability", "1");
		SelectSubCat(autoSub);
	}
	else{
		addOption(document.formfind.Category, "3", "Employment Practices Liability", "");
	}

 	if(autoCat == 4){
		addOption(document.formfind.Category, "4", "Excess Liability", "1");
		SelectSubCat(autoSub);		
	}
	else{
		addOption(document.formfind.Category, "4", "Excess Liability", "");
	}

	if(autoCat == 5){
		addOption(document.formfind.Category, "5", "Independent Director Liability", "1");
		SelectSubCat(autoSub);		
	}
	else{
		addOption(document.formfind.Category, "5", "Independent Director Liability", "");
	}

 	if(autoCat == 6){
		addOption(document.formfind.Category, "6", "Lawyers Professional Liability", "1");
		SelectSubCat(autoSub);		
	}
	else{
		addOption(document.formfind.Category, "6", "Lawyers Professional Liability", "");
	}

 	if(autoCat == 7){
		addOption(document.formfind.Category, "7", "Management Liability", "1");
		SelectSubCat(autoSub);		
	}
	else{
		addOption(document.formfind.Category, "7", "Management Liability", "");	
	}

 	if(autoCat == 8){
		addOption(document.formfind.Category, "8", "Nonprofit Management Liability", "1");
		SelectSubCat(autoSub);		
	}
	else{
		addOption(document.formfind.Category, "8", "Nonprofit Management Liability", "");
	}
}

// Populate Product drop downs
function SelectSubCat(autoComplete){
// ON selection of category this function will work

	removeAllOptions(document.formfind.SubCat);
	//addOption(document.formfind.SubCat, "", " ");


	if(document.formfind.Category.value == '1'){
//		addOption(document.formfind.SubCat, "", " ");
//		if(autoComplete==5)		
//			addOption(document.formfind.SubCat,"5", "AccountOne", "1");
//		else
//			addOption(document.formfind.SubCat,"5", "AccountOne");
//			
//		if(autoComplete==6)
//			addOption(document.formfind.SubCat,"6", "AccountPro", "1");
//		else
//			addOption(document.formfind.SubCat,"6", "AccountPro", "");
//			
		if(autoComplete==0)		
			addOption(document.formfind.SubCat,"0", "Standard","1");
		else
			addOption(document.formfind.SubCat,"0", "Standard");

	}

	if(document.formfind.Category.value == '2'){
		addOption(document.formfind.SubCat, "", " ");
		if(autoComplete==1)		
			addOption(document.formfind.SubCat,"1", "Public Company", "1");
		else
			addOption(document.formfind.SubCat,"1", "Public Company");
			
		if(autoComplete==2)
			addOption(document.formfind.SubCat,"2", "Private Company", "1");
		else
			addOption(document.formfind.SubCat,"2", "Private Company", "");

		//if(autoComplete==3)		
		//	addOption(document.formfind.SubCat,"3", "Nonprofit Organization", "1");
		//else
		//	addOption(document.formfind.SubCat,"3", "Nonprofit Organization");
	}
	
	if(document.formfind.Category.value == '3'){
		addOption(document.formfind.SubCat, "", " ");
		if(autoComplete==0)	
			addOption(document.formfind.SubCat,"0", "Standard","1");
		else
			addOption(document.formfind.SubCat,"0", "Standard");
		if(autoComplete==4)		
			addOption(document.formfind.SubCat,"4", "Retail Agent Small Business", "1");
		else
			addOption(document.formfind.SubCat,"4", "Retail Agent Small Business");
	}
	
	if(document.formfind.Category.value == '4'){
		if(autoComplete==0)		
			addOption(document.formfind.SubCat,"0", "Standard","1");
		else
			addOption(document.formfind.SubCat,"0", "Standard");
	}
	
	if(document.formfind.Category.value == '5'){
		if(autoComplete==0)
			addOption(document.formfind.SubCat,"0", "Standard","1");
		else			
			addOption(document.formfind.SubCat,"0", "Standard");
	}

	if(document.formfind.Category.value == '6'){
		if(autoComplete==0)		
			addOption(document.formfind.SubCat,"0", "Standard","1");
		else
			addOption(document.formfind.SubCat,"0", "Standard");
	}

	if(document.formfind.Category.value == '7'){
		//addOption(document.formfind.SubCat, "", " ");
		if(autoComplete==0)
			addOption(document.formfind.SubCat,"2", "Private Company","1");
		else
			addOption(document.formfind.SubCat,"2", "Private Company");
		
		//if(autoComplete==3)
		//	addOption(document.formfind.SubCat,"3", "Nonprofit Organization","1");
		//else
		//	addOption(document.formfind.SubCat,"3", "Nonprofit Organization");
	}
	
	if(document.formfind.Category.value == '8'){
		if(autoComplete==0)
			addOption(document.formfind.SubCat,"0", "Standard","1");
		else
			addOption(document.formfind.SubCat,"0", "Standard");
	}


}

// Reset all options so as to blank drop down
function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}

// Adds the options to the drop down
function addOption(selectbox, value, text, selected )
{
	var optn = document.createElement("option");
	optn.text = text;
	optn.value = value;
	if(selected)
		optn.selected = true;

	selectbox.options.add(optn);
}


// Formats the field to display the message when validating the form 
function msg(fld,     // id of element to display message in
             msgtype, // class to give element ("warn" or "error")
             message) // string to display
{
  var elem = document.getElementById(fld);

 if(message != "")
	 elem.firstChild.nodeValue = message;

  elem.className = msgtype;   // set the CSS class to adjust appearance of message

}

// Only script specific to this form goes here.
// General-purpose routines are in a separate file.
function validateOnSubmit(formname) {
	var elem;
	var errs=0;
	var validreturn = true;
	var errortxt = "";

	if(formname!='product'){
		msg ("inf_productline", "norm", "");
		msg ("inf_product", "norm", "");
	}
	msg ("inf_state", "norm", "");
	

	if(formname!='product'){
		if (document.formfind.Category.value == "") {
				errs += 1;
				errortxt += "\t - Product Line\n";
				msg ("inf_productline", "error", "");
		}
	
		if (document.formfind.SubCat.value == "") {
				errs += 1;
				errortxt += "\t - Product\n";
				msg ("inf_product", "error", "");
		}
	
		if (document.formfind.state.value == "") {
				errs += 1;
				errortxt += "\t - State\n";
				msg ("inf_state", "error", "");
		}
	}else{
		if (document.product.state.value == "") {
			errs += 1;
			errortxt += "\t - State\n";
			msg ("inf_state", "error", "");
		}
	}
	
	if (errs) {
		error = "Please enter the following before searching again:\n\n" + errortxt;
		alert(error);
		validreturn = false;
	}

	return validreturn;
}
