

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 switchid(id, type){
	switch (type){
		case 0:
			ids=new Array('a1','a2','a3','a4','a5');break;
		case 1:
			ids=new Array('b1','b2','b3','b4','b5','b6','b7','b8');break;
		case 2:
			ids=new Array('c1','c2','c3','c4');break;
		case 3:
			ids=new Array('p1','p2');break;
		case 4:
			ids=new Array('r1','r2');break;
		case 5:
			ids=new Array('c1','c2');break;
	}
	/*if (type == 0)
		ids=new Array('a1','a2','a3','a4','a5');
	else

		ids=new Array('b1','b2','b3','b4','b5','b6','b7','b8');*/
	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 toggleLayer(add, whichLayer)
{	
	if (add == "a")
	{
		whichLayer = "commentForm" + whichLayer;
	}
	else
	{
		whichLayer = "comments" + whichLayer;
	}
	
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display? "":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display? "":"block";
	}
}

function switchDisplay(whichLayer)
{	
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = (style2.display=="")? "none":"";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = (style2.display=="")? "none":"";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = (style2.display=="")? "none":"";
	}
}

function outputList(ar, name, size) {
 var strIDs = "<SELECT SIZE=\"" + size + "\" NAME=\"" + name + "\" ID=\"" + name + "\">"
 var sel = " SELECTED"
 for (var i=0;i<ar.length;i++) {
  strIDs += "<OPTION " + sel + " VALUE=\"" + ar[i][0] + "\">" + ar[i][1]
  sel = ""
 }
 strIDs+="</SELECT>"
 strIDs+="<INPUT NAME=\"" + name + "\" TYPE=hidden>"
 return strIDs
}

function outputButton(bDir,name,val) {
 return "<INPUT TYPE=button VALUE=\"" + val + "\" ONCLICK=\"move(this.form," + bDir + ",'" + name + "')\">"
}

function move(f,bDir,sName) {
 var el = f.elements["ro_lst" + sName]
 var idx = el.selectedIndex
 if (idx==-1) 
  alert("You must first select the item to reorder.")
 else {
  var nxidx = idx+( bDir? -1 : 1)
  if (nxidx<0) nxidx=el.length-1
  if (nxidx>=el.length) nxidx=0
  var oldVal = el[idx].value
  var oldText = el[idx].text
  el[idx].value = el[nxidx].value
  el[idx].text = el[nxidx].text
  el[nxidx].value = oldVal
  el[nxidx].text = oldText
  el.selectedIndex = nxidx
 }
}

function processForm(f) {
 for (var i=0;i<f.length;i++) {	
  var el = f[i]
  if (el.name.substring(0,6)=="ro_lst") {
   var strIDs = ""
   for (var j=0;j<f[i].options.length;j++)
     strIDs += f[i].options[j].value + ", "
   f.elements[f.elements[i].name.substring(6)].value = strIDs.substring(0,strIDs.length-2)
  }
 }
}  

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 concatOp(s1, s2){
	var ss = s1.value;
	if (ss.lastIndexOf(",") != (ss.length-1))
	{
		ss = ss + ",";
	}
	s1.value = ss + s2.value + ",";
}

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;
    }
    
    //basic swap
    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 addOtherView(sectionOrder, otherview, details2)
	{
		if (otherview.value != "")
		{
			concatOp(sectionOrder, otherview);
			addOption(details2, otherview.value, otherview.value);
			otherview.value='';
		}
	}
	
	function imgSwap(img1, img2, id)
	{
		var image;
		var i;
		var path;
		
		image = document.getElementById(id);
		path = image.src;
		i = path.indexOf("/imagens");
		path = path.substring(i+1)

		if (path == img1)
			image.src = img2;
		else
			image.src = img1;
	}
	
	function addLang(form0, lang, allLang, inputLang)
	{	
		var content;
		var newlang;
		var size;
		newlang = document.getElementById(inputLang).value
		size = newlang.length;
		content = allLang.value;
		if (content.indexOf(lang + ":") != -1){
			subs = content.slice(content.indexOf(lang + ":")+3);
			tam = eval(subs.slice(0, subs.indexOf(":")));
			textlang = subs.substr(subs.indexOf(":")+1,tam);
			if (newlang != "" )
			{
				content = content.replace(lang + ":" + tam + ":" + textlang, lang + ":" + size + ":" + newlang);
			}
			else
			{
				content = content.replace(lang + ":" + tam + ":" + textlang, "");
				
			}
			allLang.value = content;
		}
		else
			if (newlang != "")
				allLang.value = allLang.value + lang + ":" + size + ":" + newlang;
	}
	
function fillCategory(selectB, arrayS, qualpais, qualzona, qualcidade){ 
	var i;
	for (i=0; i < arrayS.length; i++){
		addOptionT(document.getElementById(selectB), arrayS[i][0], arrayS[i][1]);
		if (arrayS[i][0] == parseInt(qualpais)){
			document.getElementById(selectB).options[i+1].selected = true;
			SelectSubCat('cat', 'subcat', subvec, '-- Sub-categoria --', qualzona);
		}
	}
}

function fillCategoryClass(selectB, arrayS, qualclass, 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(qualclass)){
			document.getElementById(selectB).options[i+1].selected = true;
			SelectSubCat('cat', 'subcat', subcat, '-- Product Type --', 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 removeAllOptionsT(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


function addOptionT(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}

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 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; 
			}
}