/****************************************************************************************
Written by DY
Version: 1.01


-- COMMENTS - - - - - - 
 5May08	EL Add some comments.
03Apr08	DY	Created
*/

// Toggle Div Layer
function toggleLayer(whichLayer){
  	var elem, vis;

  	if(document.getElementById) // this is the way the standards work
   		elem = document.getElementById( whichLayer );
  	else if( document.all ) // this is the way old msie versions work
   		elem = document.all[whichLayer];
	 	else if( document.layers ) // this is the way nn4 works
   		elem = document.layers[whichLayer];
  	vis = elem.style;

  	// if the style.display value is blank we try to figure it out here
	 	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
   		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

//Moving Heading
function reposition(id, beginTop, beginLeft){
	var repositionObj = document.getElementById(id);
	//define reference to the body object in IE
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
	
	//define universal top point
	var top= document.all? iebody.scrollTop : pageYOffset;
	//define universal left point
	var left= document.all? iebody.scrollLeft : pageXOffset;

	//For IE 4+ or Firefox/ NS6+
	if (document.all||document.getElementById){
		repositionObj.style.top=(parseInt(top)+beginTop)+"px";
		repositionObj.style.left=(parseInt(left)+beginLeft)+"px";
	}
}

//Show tab
function showTab(tabs,curtab)
{	

	for(i=1; i<=tabs; i++)
	{
		//Objects to toggle
		var showHideObj = document.getElementById("tab" + i);
		if (i == curtab) {
			showHideObj.style.display = "block";
		} else {
			showHideObj.style.display = "none";
		}
	}
}

//Show sub tab
// subtabs -- total subtabs 
// cursubtab -- 1,2 ...
// subname -- first part of concatenate name like 'conName'
function showSubTab(subtabs,cursubtab,subname)
{	
	
	for(i=1; i<=subtabs; i++)
	{
		//Objects to toggle
		var showHideObj = document.getElementById(subname + i);
		if (i == cursubtab) {
			showHideObj.style.display = "block";
		} else {
			showHideObj.style.display = "none";
		}
	}
}

//Show multiple div
// subtabs -- total subtabs 
//            total number of subtab elements in the group.
// cursubtabs -- multiple tab numbers array
//               array of tab numbers to enable
// subname -- first part of concatenate name like 'conName'
//            stem of element id, e.g. conName, to be completed with number.
function showMultiDiv(subtabs,cursubtabs,subname)
{	
	//alert(cursubtabs);

	// For each of the sub-tabs in the group.
	for(i=1; i<=subtabs; i++)
	{
		//check selected options
		var isSelected = 0
		//Objects to toggle
		var showHideObj = document.getElementById(subname + i);
		
		// Scan the list of selected items for a match.
		for (j=0; j<cursubtabs.length; j++) {
			if (i == cursubtabs[j]) {
				isSelected = 1;
			}
		}
		
		// Set the display attribute.
		if (isSelected == 1) {
			showHideObj.style.display = "block";
		} else {
			showHideObj.style.display = "none";
		}
	}
}

//Show Category Information:
// . Make a list of the Resource Type's selected.
//   Each item in the list is a number that completes the id of the <DIV id=resSub*>
//    of the group of fields to be displayed, e.g. "1" enable display of id=resSub1
//    the Print section.
// . Pass that list to showMultiDiv to display the appropriate field groups and
//    un-display the others.
function showCatInfo(sel) {

	//Array of selected option numbers
	var selectedArray = new Array();
	//Count of total select for Array Index
	// (Index to selectedArray)
	var selectedCount = 0
	
	if (sel.options.selectedIndex < 0){
    alert('Please choose a Resource Category.');
    return false;
  } else {
		for (i=0; i<sel.options.length; i++) {
			if (sel.options[i].selected) {
				var selectText = sel.options[i].value;

				if (selectText.match(/[pP]rint/)) {
					//showSubTab(6,1,'resSub');
					selectedArray[selectedCount] = 1;
				} else if (selectText.match(/[Kk]it/)) {
					//showSubTab(6,2,'resSub');
					selectedArray[selectedCount] = 2;
				} else if (selectText.match(/[Aa]udio/)) {
					//showSubTab(6,3,'resSub');
					selectedArray[selectedCount] = 3;
				} else if (selectText.match(/[vV]ideo/)) {
					//showSubTab(6,4,'resSub');
					selectedArray[selectedCount] = 4;
				} else if (selectText.match(/[sS]oftware/)) {
					//showSubTab(6,5,'resSub');
					selectedArray[selectedCount] = 5;
				} else if (selectText.match(/[wW]eb/)) {
					//showSubTab(6,6,'resSub');
					selectedArray[selectedCount] = 6;
				}

				selectedCount++;
			}
		}

		showMultiDiv(6,selectedArray,'resSub');
		
	}
		
}
