 function isArray(a)
 {
  return isObject(a) && a.constructor == Array;
 }

 function isObject(a)
 {
     return (typeof a == 'object' && !!a) || isFunction(a);
 }
  function isFunction(a)
 {
      return typeof a == 'function';
 }

function ShowHide(id1, id2) {
  if (id1 != '') expMenu(id1);
  if (id2 != '') expMenu(id2);
}

function expMenu(id) {
  var itm = null;
  if (document.getElementById) {
    itm = document.getElementById(id);
  } else if (document.all){
    itm = document.all[id];
  } else if (document.layers){
    itm = document.layers[id];
  }

  if (!itm) {
   // do nothing
  }
  else if (itm.style) {
    if (itm.style.display == "none") { itm.style.display = ""; }
    else { itm.style.display = "none"; }
  }
  else { itm.visibility = "show"; }
}

function ShowHide2(id1, id2) {
  if (id1 != '') expMenu2(id1);
  if (id2 != '') expMenu2(id2);

  

}

function expMenu2(id) {
  var itm = null;
  if (document.getElementById) {
    itm = document.getElementById(id);
  } else if (document.all){
    itm = document.all[id];
  } else if (document.layers){
    itm = document.layers[id];
  }

  if (!itm) {
   // do nothing
  }
  else if (itm.style) {
    if (itm.style.display == "none") { itm.style.display = ""; }
    else { itm.style.display = "none"; }
  }
  else { itm.visibility = "show"; }

  //modificacao
	document.getElementById('s'+id).value = '-1';

}

function getLista(){

	fmobj=document.getElementById('ListaEquipe');
		var txtn = "";
		var txt = "";
		for (var i=0;i<fmobj.options.length;i++) {
    		var e = fmobj.options[i];
			txtn += ","+e.value+"->"+e.text;
 		}
 		if(txtn!='')
			txtn = txtn.substr(1);	
							    			
		return unescape(escape(txtn));
}

function showOrdenaPele(){
	document.getElementById('OrdenaPele').style.display = 'block';
}

function closeOrdenaPele(){
	document.getElementById('OrdenaPele').style.display = 'none';
}

function showOrdenaLabios(){
	document.getElementById('OrdenaLabios').style.display = 'block';
}

function closeOrdenaLabios(){
	document.getElementById('OrdenaLabios').style.display = 'none';
}

function showOrdenaOlhos(){
	document.getElementById('OrdenaOlhos').style.display = 'block';
}

function closeOrdenaOlhos(){
	document.getElementById('OrdenaOlhos').style.display = 'none';
}

function getLista(lista){

	fmobj=document.getElementById(lista);
		var txtn = "";
		var txt = "";
		for (var i=0;i<fmobj.options.length;i++) {
    		var e = fmobj.options[i];
			txtn += ","+e.value+"->"+e.text;
 		}
 		if(txtn!='')
			txtn = txtn.substr(1);	
							    			
		return unescape(escape(txtn));
}

function ordenaPele(){
	var ad = new AjaxData();
	ad.add("lista", getLista('ListaPele'));
	ad.add("tipo", "ORDENA_PELE");
	var toDo = function(o){

		if( o.get('saida')=='OK'){
			closeOrdenaPele();
			window.location.replace(unescape(window.location.pathname)+"?list");
		}
	
	}
	//DEBUGANDO=1;
	linkwork("ajax", "load.php", ad, toDo);	
}

function ordenaLabios(){
	var ad = new AjaxData();
	ad.add("lista", getLista('ListaLabios'));
	ad.add("tipo", "ORDENA_LABIOS");
	var toDo = function(o){

		if( o.get('saida')=='OK'){
			closeOrdenaLabios();
			window.location.replace(unescape(window.location.pathname)+"?list");
		}
	
	}
	//DEBUGANDO=1;
	linkwork("ajax", "load.php", ad, toDo);	
}

function ordenaOlhos(){
	var ad = new AjaxData();
	ad.add("lista", getLista('ListaOlhos'));
	ad.add("tipo", "ORDENA_OLHOS");
	var toDo = function(o){

		if( o.get('saida')=='OK'){
			closeOrdenaOlhos();
			window.location.replace(unescape(window.location.pathname)+"?list");
		}
	
	}
	//DEBUGANDO=1;
	linkwork("ajax", "load.php", ad, toDo);	
}


function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
}

function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[j].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[i].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
}
	
function moveOptionUp(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
			}
		}
	}
}

function moveOptionDown(obj) {
	if (!hasOptions(obj)) { return; }
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
			}
		}
	}
}


