function show(id) {
	var d = document.getElementById(id);
	var state = 'block';
	if (d) {
		if(d.style.display=='block')
			state='none';
		else
			state='block';
	}
	for (var i = 1; i<=20; i++) {
		if (document.getElementById('smenu'+i)) {
			document.getElementById('smenu'+i).style.display='none';
		}
	}
	if (d) {
		d.style.display=state;
	}
	
}

function fillCategory(selectB, arrayS, qualcat, qualtipo){ 
	var i;
	for (i=0; i < arrayS.length; i++){
		addOptionT(document.getElementById(selectB), arrayS[i][0], arrayS[i][1]);
		if (arrayS[i][0] == parseInt(qualcat)){
			document.getElementById(selectB).options[i+1].selected = true;
			SelectSubCat('categoria', 'tipo', typ, '-- Tipo de produto --', qualtipo);
		}
	}
}

function SelectSubCat(cat, subCat, arrayS, subtext, qual){
	var z;
	var sel;
	sel = document.getElementById(cat).options[document.getElementById(cat).selectedIndex].value;
	
	removeAllOptionsT(document.getElementById(subCat));
	
	addOptionT(document.getElementById(subCat), "0", subtext, "");
	var r=0;
	
	for(z=0; z < arrayS.length; z++){
		if(sel == arrayS[z][0]){
			addOptionT(document.getElementById(subCat),arrayS[z][1], arrayS[z][2]);
			if (arrayS[z][1] == parseInt(qual))
				document.getElementById(subCat).options[r+1].selected = true;
			r++;
		}
	}

}

function addOptionT(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}


function removeAllOptionsT(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		selectbox.remove(i);
	}
}	


function switchidT(id, idT){
	ids = new Array;
	ids = idT;
	hideallids();
	showdiv(id);
}


function hideallids(){

	//loop through the array and hide each element by id

	for (var i=0;i<ids.length;i++){

		hidediv(ids[i]);

	}		  

}


function hidediv(id) {

	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function swapStyle(vec, style_sel, style_desel, sel)
{
	var i;
	for(i=0; i < vec.length; i++){
		document.getElementById(vec[i]).className = style_desel;
	}
	document.getElementById(sel).className=style_sel;
}


function moveOptions(theSelFrom, theSelTo, form0, select0)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }
  
  recalculateOrder(form0, select0);
}

function move(formO,selectO,to) 
{
	var index = selectO.selectedIndex;
	
	var selectLength  = selectO.length - 1;
	
	//error handling
	//nothing selected
	if (index == -1) return false;
	
	if(to == +1 && index == selectLength)
	{
		//alert("Cannot move down anymore!");
		return false;
	}
	else if(to == -1 && index == 0)
	{
		//alert("Cannot move up anymore!");
		return false;
	}
	
	swap(index,index+to,formO,selectO);
	return true;
}
	
	
function swap(fIndex,sIndex,formO,selectO)
{
	//store first
	fText  = selectO.options[fIndex].text;
	fValue = selectO.options[fIndex].value;
	
	
	//make first = second
	selectO.options[fIndex].text  = selectO.options[sIndex].text;
	selectO.options[fIndex].value = selectO.options[sIndex].value;  
	
	//make second = first
	selectO.options[sIndex].text = fText;
	selectO.options[sIndex].value = fValue;
	
	//amke new one be selected
	selectO.options[sIndex].selected = true;    
	
	//maintain field that stores order
	recalculateOrder(formO,selectO);
}

//store in text field current order
//note field that it writes to is hardcoded
function recalculateOrder(formO,selectO)
{
	
	var sep = "";
	var newOrderText = "";
	for (i = 0; i <= selectO.options.length-1; i++) 
	{   
		//alert(selectO.options[i].value);
		newOrderText += "" + sep + selectO.options[i].value;
		sep = ",";
	}
	formO.sectionOrder.value  = newOrderText;
}


function addOption(theSel, theText, theValue)
{
	var newOpt = new Option(theText, theValue);
	var selLength = theSel.length;
	theSel.options[selLength] = newOpt;
}


function deleteOption(theSel, theIndex)
{ 
	var selLength = theSel.length;
	if(selLength>0)
	{
		theSel.options[theIndex] = null;
	}
}


function addbookmark(bookmarkurl, bookmarktitle){
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(bookmarktitle, bookmarkurl,"");
	} 
	else 
		if( window.external ) { // IE Favorite
			window.external.AddFavorite( bookmarkurl, bookmarktitle); 
		}
		else 
			if(window.opera && window.print) { // Opera Hotlist
				return true; 
			}
}