function populateCategory() {
    var category = document.form1.cat;
    var selectedtype=getSelectedItem('type');
    category.length = 0;
	populateSubCategory('reset');
	
	if(selectedtype==""){
		category.options[0] = new Option('--Category--');
	    category.options[0].value = '';
	}else{
	    category.options[0] = new Option('All');
	    category.options[0].value = '';
	
	    var subcat = eval("cats['"+ selectedtype + "']");
	    for(var j=0; j<subcat.length; j++) {
	        category.options[j+1] = new Option(subcat[j]);
	        category.options[j+1].value = subcat[j];
	    }
	}
}

function populateSubCategory(type) {
    var subcategory = document.form1.subcat;
    subcategory.length = 0;
    
	if(type=="reset"){
		subcategory.options[0] = new Option('--Subcategory--');
		subcategory.options[0].value = '';
	}else{
		subcategory.options[0] = new Option('All');
		subcategory.options[0].value = '';
		var selectedtype= (type? type : getSelectedItem('type'));
	    var selectedcat=getSelectedItem('cat');
        if(selectedcat != ''){
            var subcat = eval("cats['"+ selectedtype + "']['"+ selectedcat + "']");
            for(var j=0; j<subcat.length; j++) {
                subcategory.options[j+1] = new Option(subcat[j]);
                subcategory.options[j+1].value = subcat[j];
	        }
        }
	}
}

function popup(url,vars){
	var winVars = (vars? vars : 'height=550,width=660,scrollbars=yes,resizable=yes');
	var newWin = window.open(url, 'window', winVars);
	newWin.focus();
}

//popResults pops a search window from the dropdowns
function popResults(selecttype) {
    var type = (selecttype? selecttype : getSelectedItem('type'));

	if( type == "" ) {
		alert("Please select a search type.");
		return false;
	}

    var cat = getSelectedItem('cat');
    var subcat = getSelectedItem('subcat');
    var action="";
	
	switch(type){
		case 'design':
			action = 'design_rs.cgi';
			break;
		case 'flash':
			action = 'flash_rs.cgi';
			break;
		case 'images':
			action = 'library_rs.cgi';
			break;
		case 'layout':
			action = 'layout_rs.cgi';
			break;
		case 'splash':
			action = 'splash_rs.cgi';
			break;
		default:
			return false;
	}
	
    action += "?type="+escape(type)+"&cat="+escape(cat)+"&subcat="+escape(subcat);
    popup(action);
    return false;
}

//popDetail pops up a window with detailed info.
//only type and name are needed, except for images which need all params
//REQUIRED METHODS: popup(), selectImage()
//EXAMPLE USE: <a href="#" onClick="popDetail('design','Aster')">link</a>
function popDetail(type, name, imageType, cat, subcat){
	if( type=='images' )
		selectImage(imageType, name, cat, subcat);
	else
		popup( type+'_details.cgi?name='+name );
}

function selectImage(imageType, name, cat, subcat, target, rownum) {
    destfile = 'library_rs.cgi?stype=';
	if( rownum==1 || rownum==null) {
		destfile = 'library_details.cgi?type=';
	}
    destfile += escape(imageType)+'&cat='+escape(cat)+'&subcat='+escape(subcat)+'&name='+escape(name);
    
	if( target=='cur' )
		this.location = destfile;
	else
		popup(destfile);
}

function getSelectedItem(fieldname) {
    var listobj = eval("document.form1."+fieldname);
    var selecteditem = "";

    for(var k=1; k<listobj.length; k++) {
        if( listobj.options[k].selected) {
            selecteditem=listobj.options[k].value;
        }
    }
    return selecteditem;
}

function onSelectDetail(filename,name) {
    var doc = document.form1;
    var action = filename + ".cgi?name="+name;
    popup(action);
	return true;
}

function changeImage(imgname,color) {
    var image = eval("document."+imgname);
    var imgsrc = image.src;

    var pos1 = imgsrc.lastIndexOf('/');
	var imgtail = imgsrc.substring(pos1);
	imgsrc = imgsrc.substring(0,pos1);

    var pos2 = imgsrc.lastIndexOf('/');
    var newsrc = imgsrc.substring(0,pos2) + '/' + color + imgtail;
    image.src = newsrc;
}



	function platinum1(){
  		window.open("combos/platinum1.html", "combos", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=518,height=518")
		}
	function platinum2(){
  		window.open("combos/platinum2.html", "combos", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=518,height=518")
		}
	function platinum3(){
  		window.open("combos/platinum3.html", "combos", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=518,height=518")
		}
	function platinum4(){
  		window.open("combos/platinum4.html", "combos", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=518,height=518")
		}
	function platinum5(){
  		window.open("combos/platinum5.html", "combos", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=518,height=518")
		}	
	function gold1(){
  		window.open("combos/gold1.html", "combos", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=518,height=518")
		}
	function gold2(){
  		window.open("combos/gold2.html", "combos", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=518,height=518")
		}
	function gold3(){
  		window.open("combos/gold3.html", "combos", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=518,height=518")
		}
	function gold4(){
  		window.open("combos/gold4.html", "combos", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=518,height=518")
		}
	function gold5(){
  		window.open("combos/gold5.html", "combos", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width=518,height=518")
		}
