 // JavaScript Document
function controlDivMenu(id){
	imagen="img_"+id;
	x=document.getElementById(imagen).src;
	if(x.lastIndexOf("vinetapress.gif")==-1){
	  document.getElementById(imagen).src="../img/vinetapress.gif";
	  mostrar('div_'+id);  
	}else{
	  document.getElementById(imagen).src="../img/vinetadown.gif";
	  ocultar('div_'+id);
	}
}	

function controlCateg(id){
	imagen="img_"+id;
	x=document.getElementById(imagen).src;
	if(x.lastIndexOf("vinetapress.gif")==-1){
	  document.getElementById(imagen).src="img/vinetapress.gif";
	  mostrar('div_'+id);  
	}else{
	  document.getElementById(imagen).src="img/vinetadown.gif";
	  ocultar('div_'+id);
	}
}	

function buscafotos(dest){
	window.open("co_imagenes.php?dest="+dest,"",'resizable=yes, scrollbars=yes,width=530,height=225');
}
 
function execform(formu,id){
	formu.mail.value=document.getElementById(id).value;
	formu.submit();
}

function ordenar(x,f){
	f.ord.value=x;
	f.submit();
}
 
function centrar(nombreCapa){
	x=window.screen.width/2;
	y=window.screen.height/2;
	ancho=document.getElementById(nombreCapa).offsetWidth/2;
	alto=document.getElementById(nombreCapa).style.offsetHeight/2;
	document.getElementById(nombreCapa).style.left=parseInt(x-ancho)+"px";
	document.getElementById(nombreCapa).style.top=parseInt(y-alto)+"px";
}
function winMax(v){
	window.open(v,'','scrollbars=yes,width='+window.screen.width+',height='+window.screen.height+'')
}
function yesno(formulario,mensaje){
	if(confirm(mensaje)){
		formulario.submit();
	}
}

function mostrar(nombreCapa){ 
document.getElementById(nombreCapa).style.visibility="visible"; 
document.getElementById(nombreCapa).style.display="block"; 
}
function ocultar(nombreCapa){ 
document.getElementById(nombreCapa).style.visibility="hidden"; 
document.getElementById(nombreCapa).style.display="none"; 
}

function idactivo(objcheck){
	seleccionado=-1;
    var i 
    for (i=0;i<objcheck.length;i++){ 
	   if (objcheck[i].checked){
          seleccionado=i
		  break; }
    }
	return seleccionado;
}

function controlarCapa(x,capa){
	if(document.getElementById(x).value==1){
		ocultar(capa);
		document.getElementById(x).value=0;
	}else{
		mostrar(capa);
		document.getElementById(x).value=1;
	}
}

function controlCapa(x,capa){
	if(x.checked){
		mostrar(capa);
	}else{
		ocultar(capa);
	}
}
function estaSeleccionado(objcheck){
	seleccionado=false;
    var i 
    for (i=0;i<objcheck.length;i++){ 
	   if (objcheck[i].checked){
          seleccionado=true;
		  break; }
    }
	return seleccionado;
}

function cambiarcheck(objcheck){
	if (estadocheck==0){
	objcheck.checked=true;
	estadocheck=1;
	}else{
	estadocheck=0;
	objcheck.checked=false;
	}
}

function vacio(campo)
{	if (campo.value.length==0)
		{ return true;}
	else{ return false;}
}

function novacio(campo,msj)
	{if (campo.value == "") 
		{ alert(msj);
		  campo.focus();
		  return false;}
	 else{ return true;
	     }
	}

function esNumerico(x)
{	var patronNumero = /^\d*\.?\d{0,2}$/;
    if(patronNumero.test(x))
	{return true;}
	else{
		return false;}
}

function esEntero(x,msj)
{	var patronNumero = /^\d*$/;
    if(patronNumero.test(x.value))
	{return true;}
	else{
		alert(msj);
		x.select();
		return false;}
}

function esnumero(x,msj)
{	if(esNumerico(x.value))
	{return true;}
	else{
		alert(msj);
		x.select();
		return false;}
}

function esEmail(email,msj) {
    var er_email = /^(.+\@.+\..+)$/
    if(!er_email.test(email.value)) {
       alert(msj);
	   email.focus();
       return false;
	}
	return true;
}

function sonIguales(x){
	valor=false;
	correoform=x.split(",");
	for (i=0;i<correoform.length-1;i++)
	{ if (valor){break;}
		for (j=i+1;j<correoform.length;j++)
		{	if(correoform[i]==correoform[j])
			{	valor=true;
				break;
			}
		}
	}
	return valor;
}

function calcular(num1,num2,res){
	if(esnumero(num1,"Ingrese un número")){
		if(esnumero(num2,"Ingrese un número")){
			a=parseFloat(num1.value);
			b=parseFloat(num2.value);
			res.value=Math.round(a*b*100)/100;
		}		
	}
}

//	INICIO MOVER ITEMS DE LISTAS
function addItem(obj,strText,strValue,blSel,intPos){
	var newOpt,i,ArTemp,selIndex;
	selIndex = (blSel)?intPos:obj.selectedIndex;
	newOpt = new Option(strText,strValue);
	Len = obj.options.length+1
	if (intPos > Len) return
	obj.options.length = Len
	if (intPos != Len) {
		ArTemp = new Array();
		for(i=intPos;i<obj.options.length-1;i++)
			ArTemp[i] = Array(obj.options[i].text,obj.options[i].value);
		for(i=intPos+1;i<Len;i++)
			obj.options[i] = new Option(ArTemp[i-1][0],ArTemp[i-1][1]);
	}
	obj.options[intPos] = newOpt;
	if (selIndex > intPos)
		obj.selectedIndex = selIndex+1;
	else if (selIndex == intPos) 
		obj.selectedIndex = intPos;
}
function delItem(obj,intPos){
	if(intPos > obj.length) return;
	obj.options[intPos] = null
}
function All(orig,dest){
	for(i=0;i<orig.length;i++) {
		addItem(dest,orig.options[i].text,orig.options[i].value,false,dest.length);
	}
	orig.options.length = 0;
}
function Add(orig,dest) {
	if(orig.selectedIndex == -1) {
		alert("Seleccione un item");
		return
	}
	addItem(dest,orig.options[orig.selectedIndex].text,orig.options[orig.selectedIndex].value,false,dest.length)
	delItem(orig,orig.selectedIndex)
}
//	FIN DE MOVER ITEMS DE LISTAS

function irMenuMensaje(x){
	document.menumensaje.action=x;
	document.menumensaje.submit();
}

function ratondown(td,resalta,normal){
		if(td.className==resalta){
			td.className=normal;
		}else{
			td.className=resalta;
		}
	}
	
function ratonover(td,resalta,selecc){
		if(td.className!=selecc){
			td.className=resalta;		
		}
	}
	
function ratonout(td,normal,selecc){
		if(td.className!=selecc){
			td.className=normal;
		}
	}
function vinculo(x){
	location.href=x;
	}




function controlTreeDivHelp(id,tipo){
	imagen="tree"+id+"_"+tipo;
	x=document.getElementById(imagen).src;
	if(x.lastIndexOf("tree_collapse_corner.png")==-1){
	  document.getElementById(imagen).src="../img/tree_collapse_corner.png";
	  mostrar('capa'+id+'_'+tipo);  
	}else{
	  document.getElementById(imagen).src="../img/tree_expand_corner.png";
	  ocultar('capa'+id+'_'+tipo);
	}
}	

function claseCambiar(id,x){
		id.className=x;
	}
