
var catList = new Array();

catList['choose']         = [];
catList['Abstract']       = ['Blurs', 'Materials', 'Miscellaneous', 'Patterns'];
catList['Animals']        = ['Birds', 'Fish', 'Miscellaneous', 'Pets'];
catList['Architecture']   = ['Bridges', 'Buildings Interiors', 'Churches/Religious', 'Office Buildings', 'Details and Close-Ups', 'Exteriors', 'Landmarks/Monuments', 'Miscellaneous', 'Residential'];
catList['Art-Illustration']   = ['2D', '3D', 'Paintings', 'Miscellaneous'];
catList['Backgrounds']    = ['Miscellaneous', 'Scrapbooking and Stationary', 'Textures'];
catList['Business']       = ['Financial', 'Miscellaneous', 'Objects', 'Office', 'People', 'Real Estate', 'Retail', 'Services'];
catList['Communication']  = ['Miscellaneous', 'Internet'];
catList['Computers']      = ['Miscellaneous', 'Internet'];
catList['Conceptual']     = ['Beauty', 'Diversity', 'Fear', 'Growth', 'Happiness','Helping/Giving', 'Humorous', 'Leadership', 'Love', 'Luxury', 'Miscellaneous', 'Peace', 'Power', 'Risk', 'Sadness', 'Safety', 'Security', 'Speed', 'Spiritual', 'Stress', 'Success', 'Uniqueness', 'Wealth'];
catList['Education']      = ['College', 'Graduation', 'Library', 'Miscellaneous', 'Objects', 'Preschool', 'Grade Schools'];
catList['Food']           = ['Beverages', 'Desserts/Sweets', 'Markets', 'Miscellaneous', 'Restaurants'];
catList['Health']         = ['Abuse', 'Alternative', 'Diet and Nutrition', 'Dental', 'Fitness', 'Hospitals', 'Hygiene', 'Medical', 'Mental Health', 'Miscellaneous', 'Obstetrics', 'Pharmaceuticals', 'Professionals'];
catList['Holidays']       = ['4th of July', 'Birthday', 'Christmas', 'Easter', 'Hanukah', 'Halloween', 'Miscellaneous', 'New Years', 'Valentines Day', 'Weddings'];
catList['Industry']     = ['Clothing/Fashion', 'Concepts', 'Construction', 'Electronics', 'Lumber', 'Manufacturing', 'Military', 'Miscellaneous', 'Police/Firefighters', 'Power and Energy'];
catList['Internet']       = ['Concepts', 'Miscellaneous'];
catList['Landscapes']     = ['Desert', 'Miscellaneous', 'Mountains', 'Ocean', 'Rivers', 'Rural'];
catList['Miscellaneous']  = ['Holidays and Seasonal', 'Miscellaneous'];
catList['Musical']        = ['Instruments', 'Live Music', 'Miscellaneous'];
catList['Nature']         = ['Flowers', 'Insects', 'Miscellaneous', 'Plants', 'Skies', 'Trees', 'Underwater', 'Weather'];
catList['Objects']        = ['Currency', 'Electronics', 'Extreme Close-Ups', 'Flags/Maps/Globes', 'Everyday', 'Industrial', 'Miscellaneous', 'Over White', 'Religious/Spiritual', 'Signs', 'Tools', 'Toys', 'Weapons'];
catList['People']         = ['Babies', 'Body Parts','Children', 'Couples', 'Families', 'Men', 'Miscellaneous', 'Seniors', 'Teens', 'Women'];
catList['Places']         = ['Aerial Views', 'Airports and Train Stations', 'American Cities', 'Asian Cities', 'Beaches', 'European Cities', 'Farmland', 'Graveyards', 'Home', 'Hospitals and Medical', 'Industrial', 'Landmarks/Monuments', 'Middle East', 'Miscellaneous', 'Rural', 'Schools', 'Travel', 'Urban', 'Winter'];
catList['Sexual']         = ['Men', 'Miscellaneous', 'Women'];
catList['Sports']         = ['Baseball', 'Basketball', 'Cycling', 'Extreme', 'Fishing', 'Football', 'Golf', 'Miscellaneous', 'Racing', 'Skateboarding', 'Skiing', 'Snowboarding', 'Soccer', 'Surfing', 'Swimming'];
catList['Transportation'] = ['Autos', 'Boats', 'Flying', 'Miscellaneous', 'Motorcycles', 'Trains'];


function select_item(obj, withvalue) 
{
  for(var i = 0; i < obj.length; i++) {
    if (obj.options[i].value == withvalue) {
      obj.options[i].selected = true;
      return;
    }
  }
}

function category_main_select(baseid, catval, subval, blanksub) {
  var idMain = 'cat' + baseid;
  var idSub  = 'subcat' + baseid;

  main = document.getElementById(idMain);
  sub  = document.getElementById(idSub);
  select_item(main, catval);

  BuildSubMenu(main, idSub, catList, blanksub);
  select_item(sub, subval);
}


/* 
 * obj   - the <select> object that has the value
 * subid - the html id of the submenu
 * list  - an associative array of arrays
 */
function BuildSubMenu(obj, subid, list, blanksub) {
	var subMenu = document.getElementById(subid);
	var mainCat = obj.value;

	if (! subMenu ) {
		//alert('no subcategory with id ' + subid);
		return false;
	}

	// reset sub category
	subMenu.options.length = 0;

	if (! list[mainCat] ) {
		//alert('no Category found ' + mainCat);	
		return false;
	}

	subCats = list[mainCat];
 
  var index = 0
	if (blanksub) {
		if (blanksub == true) {
			subMenu.options[0] = new Option('', '', false, false);
		} else {
			subMenu.options[0] = new Option(blanksub, '', false, false);
		}
    index++;
  }

	for(i = 0; i < subCats.length; i++) {
		catname = subCats[i];
		subMenu.options[i+index] = new Option(catname, catname, false, false);
	}

}

function AdjustRelease(obj, dupid, list, area) {

	var contain =  document.getElementById(area);
	var parent = document.getElementById(list);
	var dup = document.getElementById(dupid);

	var kids = parent.childNodes;
	var have = kids.length;
	var want = obj.value;


	if (want > have) {

		for (var i = have ; want > have; have++) {
			var newel = dup.cloneNode(true);
			newel.style.display = 'block';
			newel.id =  dup.id + i;
			parent.appendChild(newel);
		}

	} else if(want < have) {
		for (var i = have ; have > want; have--) {
			parent.removeChild(kids[have-1]);
		}
	}
	contain.style.display = have? 'block': 'none';

}

function ReleaseAdjust(obj, dupid, list, area, selected) {

	var contain =  document.getElementById(area);
	var parent = document.getElementById(list);
	var dup = document.getElementById(dupid);

	var kids = parent.childNodes;
	var have = kids.length;
	var want = obj.value;
	if(! selected ) {
		selected = new Array();
	}


	if (want > have) {

		for (var i = have ; want > have; have++) {
			var newel = dup.cloneNode(true);
			newel.style.display = 'block';
			newel.id =  dup.id + i;
			parent.appendChild(newel);

			var selbox = newel.getElementsByTagName('select');
			if(! selbox[0]) {
				return;
			}
			var attrib = document.createAttribute('id');
			attrib.value = 'realeaseforms' + i;
			selbox[0].setAttributeNode(attrib);

			if(selected[i]) {
				select_item(selbox[0], selected[i]);
			}
		}

	} else if(want < have) {
		for (var i = have ; have > want; have--) {
			parent.removeChild(kids[have-1]);
		}
	}
	contain.style.display = have? 'block': 'none';

}

