function cambiarEstado(upd,url) {
	var aj = new Ajax(url, {	method: 'get', update: $(upd) });
	aj.request();
}
function delCell(upd,url) {
	if(verifyDelete("¿Confirma eliminar este elemento?") == true) {
	var aj = new Ajax(url, { method: 'get'});
	document.getElementById(upd).style.display='none';
	aj.request();
	}
}
function delCellCont(upd,url) {
	if(verifyDelete("¿Confirma eliminar este elemento?\nIMPORTANTE:\nLos ítems anidados también serán borrados.") == true) {
	var aj = new Ajax(url, { method: 'get'});
	document.getElementById(upd).style.display='none';
	aj.request();
	}
}
function setReferStruct(idstr) {
	var aj = new Ajax('main.php?serv=remote&func=setReferStruct&id='+idstr, {	method: 'get'});
	aj.request();
}

function llevarFormStruct(formul,upd) {
	$(formul).send({ update: $(upd) });

}

function chProp(url) {
	var aj = new Ajax(url, {	method: 'get' });
	aj.request();
}

function stopRKey(evt) {
   var evt = (evt) ? evt : ((event) ? event : null);
   var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}

function verifyDelete(ms) {
    if (confirm(ms) == true) {
       return true;
    } else {
       return false;
    }
}
document.onkeypress = stopRKey;

function GP_popupConfirmMsg(msg) { 
	document.MM_returnValue = confirm(msg);
}
function fadeIn(element, opacity) {
	var reduceOpacityBy = 5;
	var rate = 5;	// 15 fps


	if (opacity < 100) {
		opacity -= reduceOpacityBy;
		if (opacity > 100) {
			opacity = 100;
		}

		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		} else {
			element.style.opacity = opacity / 100;
		}
	}

	if (opacity < 100) {
		setTimeout(function () {
			fadeIn(element, opacity);
		}, rate);
	}
}

function traerImagen(upd,turl) {

new Effect.Opacity('imgc', { from: 1, to: 0 });
new Ajax.Updater(upd, turl, {method: 'get',
																			onCreate:fadeOut,
																			onComplete:comp
																		});
}

function fadeOut() {
		new Effect.FadeOut('imgc', { duration: 3 });
}
function comp() {
	$('imgc').onload = function() {
	new Effect.FadeIn('imgc', { duration: 3 });
	$('loader').style.display='none';
	}

	var sli = Math.round($('ancho').value);
	setSliderValue(slider1, sli); 
	startCrop();
}

function getAll(upd,turl) {
new Ajax.Updater(upd, turl, {method: 'get'});
}

function templateEdit(idt) {
	$('bla').style.display = '';
	setOpacity(5);
	new Ajax.Updater($('edtp'), 'main.php?serv=remote&func=templateEdit&id='+idt, {method: 'get'});
}

function setOpacity(value) {
	$('bla').style.opacity = value/10;
	$('bla').style.filter = 'alpha(opacity=' + value*10 + ')';
}


function startCrop() {
	var cropper = new Cropper.Img('imgc',{onEndCrop: onEndCrop });
}
function onEndCrop( coords, dimensions ) {
	$( 'rx' ).value = Math.round(coords.x1*getRatio());
	$( 'ry' ).value = Math.round(coords.y1*getRatio());
	$( 'cw' ).value = Math.round(dimensions.width*getRatio());
	$( 'ch' ).value = Math.round(dimensions.height*getRatio());
	$('infoimg').innerHTML = "Medidas Reales | X:"+Math.round(coords.x1*getRatio())+"px Y:"+Math.round(coords.y1*getRatio())+"px <b>Ancho:"+Math.round(dimensions.width*getRatio())+"px Altura:"+Math.round(dimensions.height*getRatio())+"px</b>";
	$('infor').innerHTML = "Ancho de Recorte: "+Math.round(dimensions.width*getRatio())+"px";
}
function getW(elem) {
	if(elem=='sl')
	return $('ancho').value*1.5;
	if(elem=='im')
	return $('ancho').value;
}
function getName() {
	return $('fileme').value;
}
function setName(val) {
	var elem = val.split("::");
	$('fileme').value = elem[0];
	$('filename').value = delExtension('REC_'+elem[1]);
}
function getRatio() {
	var ratio = $('ancho').value/400;
	return ratio;
}

function setMod(val){
	$('mod').value = val;
	new Effect.FadeIn('loader', { duration: 3 });
}

function switchVis(obj,val) {
	var tid = $(obj);
	$('repl').value = val;
	if (val == 0) 
		new Effect.FadeIn(tid);
	else
		new Effect.FadeOut(tid);
}
function switchDiv(ob,ob1) {
	var tid = $(ob);
	var tid1 = $(ob1);
	(tid.style.display == 'none')? new Effect.FadeIn(tid) : new Effect.FadeOut(tid);
	(tid1.style.display == '')? new Effect.FadeOut(tid1) : new Effect.FadeIn(tid1);
}

function switchCapa(ob) {
	var tid = $(ob);
	(tid.style.display == 'none')? new Effect.FadeIn(tid) : new Effect.FadeOut(tid);
}

function setSliderValue(slider, value) {
	if(value == '') return;
	if(isNaN(value))
	slider.setValue(0);
	else
	slider.setValue(value/getW('sl'));
}
function delExtension(fname){
	var ret = fname.split(".");
	return ret[0];
}
function setURL() {
	var server = "main.php?serv=remote&func=saveImage";
	var flipdeg = "&mod="+$('mod').value;
	var whrec = "&w="+$('cw').value+"&h="+$('ch').value+"&x="+$('rx').value+"&y="+$('ry').value;
	var namef = "&name="+getName()+"&reemplazar="+$('rep').checked+"&reload="+$('reload').checked+"&newname="+$('filename').value;
	var resizeX = "&resize="+$('redim').checked+"&resizew="+$('recw').value;
	if($('newcat').value == "")
		var grupo = $('cats').value;
	else
		var grupo = $('newcat').value;
	
	var infoadic = "&grupo="+grupo+"&desc="+$('descr').value;
	
	var turl = server+flipdeg+whrec+namef+resizeX+infoadic;

		new Ajax.Request(turl, {method: 'get'});
		setMod(0);
		if($('rep').checked == true)
				traerImagen('con','main.php?serv=remote&func=getImageSelector&flip=null&degr=0&image='+getName());
		if($('rep').checked == false)
				traerImagen('con','main.php?serv=remote&func=getImageNew&flip=null&degr=0&newname='+$('filename').value);

	
}
function savename() {
$('filename').value = $('filename').value.replace(" ","_");
}

Effect.FadeIn = function(element) {
   new Effect.Appear(element, arguments[1] || {});
}

Effect.FadeOut = function(element) {
  new Effect.Fade(element, arguments[1] || {});
}

Effect.Fader = function(element) {
  if(element.style.display == 'none') {
  new Effect.FadeIn(element, arguments[1] || {}); }
  else { new Effect.FadeOut(element, arguments[1] || {}); }
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

//comodoro
function setTel() {
	//alert("hola");
	//document.getElementById('pie').style.top = '-240px';
	$('pie').style.top = '-225px';
  //  $('fldiv').style.height = '225px';
  //$('fldiv').style.overflow = 'hidden';
}
function resTel() {
	//alert("hola");
	$('pie').style.top = '';
	//$('fldiv').style.height = '';
	//document.getElementById('pie').style.top = '';
}

function comGetProd(){
	$('adi').style.display = '';
	var turl = "http://www.comodoro.coop/index.php?page=getProd";
	new Ajax.Updater($('adi'), turl, {method: 'get'});
}
function comHideProd(){
	$('adi').style.display = 'none';
}

function traerGuia(arg1){
	var xx = arg1.split("::");
	$('adi').style.display = '';
	var turl = "http://www.comodoro.coop/index.php?page=guia&nombre="+xx[0]+"&tel="+xx[1]+"&car="+xx[2];
	new Ajax.Updater($('adi'), turl, {method: 'get'});
}
function traerGuiaInt(arg1){
	var xx = arg1.split("::");
	//$('adi').style.display = '';
	var turl = "http://www.comodoro.coop/index.php?page=guiaint&nombre="+xx[0]+"&tel="+xx[1]+"&car="+xx[2];
	new Ajax.Updater($('gint'), turl, {method: 'get'});
}
function delImage(im) {
	if(verifyDelete("Desea realmente eliminar este elemento?") == true) {
	var turl = "http://devcenter.interpymes.org/main.php?serv=multimedia&func=delImage&id="+im;
	new Ajax.Updater($(im), turl, {method: 'get'});
	}
}
function prev(im) {
	var turl = "http://devcenter.interpymes.org/main.php?serv=remote&func=prevista&image="+im;
	new Ajax.Updater($('prevista'), turl, {method: 'get',onCreate:esperar("Creando Vista...")});
}
function prevGal(gal) {
	var turl = "http://devcenter.interpymes.org/main.php?serv=remote&func=previstaGal&id="+gal;
	$('prevista').style.display='';
	new Ajax.Updater($('prevista'), turl, {method: 'get',onCreate:esperar("Creando Vista...")});
}
function prevImage(nam) {
	var turl = "http://devcenter.interpymes.org/main.php?serv=remote&func=previstaImg&id="+nam;
	$('previstaImg').style.display='';
	new Ajax.Updater($('previstaImg'), turl, {method: 'get'});
}

function prevDoc(val) {
	var turl = "http://devcenter.interpymes.org/main.php?serv=remote&func=previstaDoc&id="+val;
	$('previstaDoc').style.display='';
	new Ajax.Updater($('previstaDoc'), turl, {method: 'get'});
}
function prevFile(val) {
	var turl = "http://devcenter.interpymes.org/main.php?serv=remote&func=previstaFile&id="+val;
	$('previstaFile').style.display='';
	new Ajax.Updater($('previstaFile'), turl, {method: 'get'});
}

function esperar(tx) {
	$('prevista').innerHTML = tx;
}
function adGal(im) {
	var turl = "http://devcenter.interpymes.org/main.php?serv=remote&func=addGal&image="+im;
	new Ajax.Updater($('galeria'), turl, {method: 'get'});
}
function quitarGal(im) {
	var turl = "http://devcenter.interpymes.org/main.php?serv=remote&func=quitarGal&imagedel="+im;
	new Ajax.Updater($('galeria'), turl, {method: 'get'});
}

function swnormal() {
  if($('radioc').checked) {
  $('swc').style.display='';
  $('swn').style.display='none';
  $('ucorp').style.display='';
  $('unormal').style.display='none';
} else {
  $('swc').style.display='none';
  $('swn').style.display='';
  $('ucorp').style.display='none';
  $('unormal').style.display='';
} 
}

function setstb() {  
  if($('radioc').checked) {
    var imapuser = $('usr').value+$('dmc').value;
   } else {
    var imapuser = $('usr').value+$('dm').value;
  }
$('imapuser').value = imapuser;
$('imp_login').submit();
}
function swContent(str) {
  var st = str.split('|');
  $('desc').innerHTML = '';
  $('desc').innerHTML = '<b>'+st[1]+'</b><br>'+st[2];
}
function smProducto(idp) {
	$('serv').value = idp;
	$('intp').submit();
}

function checkemail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   } else {
   return true; 
   }
}

function validateAdic() {
	$('alert').innerHTML = "";
	if($('servad').options.selectedIndex > 0) {
		$('form1').submit();
	} else {
		$('alert').innerHTML = '<font color=red><b>ERROR</b></font><br><b>Revise los datos.</b><br>';
		$('alert').innerHTML += '&bull; Debe seleccionar al menos un (1) producto o servicio.';
		werror();
		
	}
	
}
function checkForm() {
	restoreForm();
	var mailcheck = checkemail($('mail').value);
	var err = 0;
	$('alert').innerHTML = "";
	if($('mail').value != "" && mailcheck == false) {
		$('alert').innerHTML += '&bull; Formato de e-email inv&aacute;lido.<br>';
		$('mail').style.border = '2px solid red';
		err+=1;
	}
	if($('nombre').value == "") {
		$('alert').innerHTML += '&bull; Debe Ingresar su Nombre y Apellido.<br>';
		$('nombre').style.border = '2px solid red';
		err+=1;
	}
	if($('tel').value == "") {
		$('alert').innerHTML += '&bull; Debe Ingresar un tel&eacute;fono de contacto.<br>';
		$('tel').style.border = '2px solid red';
		err+=1;
	}
	if($('dom').value == "") {
		$('alert').innerHTML += '&bull; D&iacute;ganos su domicilio para comprobar disponibilidad.<br>';
		$('dom').style.border = '2px solid red';
		err+=1;
	}
	if(err == 0) {
	$('formt').submit();
}	else {
	$('alert').innerHTML = '<font color=red><b>ERROR</b></font><br><b>Revise los campos delineados con Rojo.</b><br>'+$('alert').innerHTML;
	werror();
}
	
}
function restoreForm() {
	$('mail').style.border = '1px solid #ccc';
	$('nombre').style.border = '1px solid #ccc';
	$('tel').style.border = '1px solid #ccc';
	$('dom').style.border = '1px solid #ccc';
	
}
function werror() {
	setOpacity(8);
	$('bla').style.display = '';
//	
	var posh = (document.body.offsetWidth/2)-150;
	var posv = (document.body.offsetHeight/2);
	
	$('caja').style.left = posh+'px';
	$('caja').style.top = posv+'px';
	
	$('okc').style.top = parseInt(repl($('alert').style.height)-20)+'px';
	$('okc').style.left = '320px';
	new Effect.FadeIn($('caja'));
}
function repl(str){
	var ret = str.split("px");
	return ret[0];
}
function denuevo() {
	$('bla').style.display = 'none';
	$('caja').style.display = 'none';
	$('alert').innerHTML="";
}



function posFle(pos) {
	switch(pos) {
		case "hogar":
		$('point').style.left = '35px';
		break;
		case "empresa":
		$('point').style.left = '135px';
		break;
		case "pro":
		$('point').style.left = '255px';
		break;
		case "internet":
		$('point').style.left = '330px';
		break;
		case "guia":
		$('point').style.left = '380px';
		break;
		case "esp":
		$('point').style.left = '435px';
		break;
		case "mail":
		$('point').style.left = '500px';
		break;
		
	}
}
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function infodiv(obj,content,tit) {
	tit = tit.split("(usuario@comodoro.coop)")[0];
	tit = tit.split("(usuario@suempresa.com)")[0];
	tit = tit.split("(usuario@radatilly.coop)")[0];
	$('alertinfo').style.left = findPosX(obj)-160+'px';
	$('cajacont').innerHTML = "<span class='tooltip'>"+tit+"</span>"+"<br>"+content;
	$('alertinfo').style.display = '';
	$('flci').style.display = '';
	$('alertinfo').style.top = parseInt(findPosY(obj)-($('alertinfo').clientHeight/2.5))+'px';
	$('flci').style.top = parseInt(findPosY($('alertinfo'))+($('alertinfo').clientHeight/2.5))+'px';
	$('flci').style.left = parseInt(findPosX($('alertinfo'))+150)+'px';
}
function infodivout() {
	$('alertinfo').style.display = 'none';
	$('flci').style.display = 'none';
}
function resizemenu() {
	$('menulat').style.height = parseInt($('mn').clientHeight-548)+'px';
	//$('model').style.marginTop = parseInt(repl($('menulat').style.height)-548)+'px';
	
}

 
//comodoro


//asocespa
function infoAs(cont) {
$('alert').innerHTML = "";
	$('alert').innerHTML = cont;
$('bla').style.display = '';
$('caja').style.display = '';
 werror();
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function pop(id) {
  MM_openBrWindow('index.php?rset=pop&id='+id,'','scrollbars=yes,width=430,height=400');
}
//asocespa

function traerStrc(idsec){
	var turl = "http://devcenter.interpymes.org/main.php?serv=remote&func=traerStructs&idsec="+idsec;
	new Ajax.Updater($('lista_structs'), turl, {method: 'get'});
}

function nuevaGal() {
	document.location = "main.php?serv=multimedia&func=createGal";
}
function popImage(cod) {
	MM_openBrWindow('main.php?serv=multimedia&func=editImage&id='+cod,'pep','status=no,scrollbars=no,resizable=no,width=600,height=480');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

//devcenter
function checkFormUser() {
	//restoreForm();
	var mailcheck = checkemail($('mail').value);
	var err = 0;
	$('alert').innerHTML = "";
	if($('user').value == "") {
		$('alert').innerHTML += '&bull; Ingrese un nombre de usuario.<br>';
		$('user').style.border = '2px solid red';
		err+=1;
	}
	if($('mail').value == "" || mailcheck == false) {
		$('alert').innerHTML += '&bull; Formato de e-email inv&aacute;lido.<br>';
		$('mail').style.border = '2px solid red';
		err+=1;
	}
	if($('nombre').value == "") {
		$('alert').innerHTML += '&bull; Debe Ingresar su Nombre y Apellido.<br>';
		$('nombre').style.border = '2px solid red';
		err+=1;
	}
	if($('telefono').value == "") {
		$('alert').innerHTML += '&bull; Debe Ingresar un tel&eacute;fono de contacto.<br>';
		$('telefono').style.border = '2px solid red';
		err+=1;
	}
	if($('apellido').value == "") {
		$('alert').innerHTML += '&bull; Debe Ingresar su apellido.<br>';
		$('apellido').style.border = '2px solid red';
		err+=1;
	}
	if($('sector').value == "") {
		$('alert').innerHTML += '&bull; Debe Ingresar el sector al que pertenece.<br>';
		$('sector').style.border = '2px solid red';
		err+=1;
	}
	if($('cargo').value == "") {
		$('alert').innerHTML += '&bull; Debe Ingresar el cargo que ocupa.<br>';
		$('cargo').style.border = '2px solid red';
		err+=1;
	}
	if($('pass').value == "") {
		$('alert').innerHTML += '&bull; Debe ingresar una clave.<br>';
		$('pass').style.border = '2px solid red';
		err+=1;
	}
	if(err == 0) {
	$('usr').submit();
}	else {
	$('alert').innerHTML = '<font color=red><b>ERROR</b></font><br><b>Revise los campos delineados con Rojo.</b><br>'+$('alert').innerHTML;
	werror();
}
}


function checkFormSec() {
	//restoreForm();
	var err = 0;
	$('alert').innerHTML = "";
	if($('seccion').value == "") {
		$('alert').innerHTML += '&bull; Ingrese un nombre de usuario.<br>';
		$('seccion').style.border = '2px solid red';
		err+=1;
	}

	if($('descripcion').value == "") {
		$('alert').innerHTML += '&bull; Debe Ingresar su Nombre y Apellido.<br>';
		$('descripcion').style.border = '2px solid red';
		err+=1;
	}
	
	if(err == 0) {
	$('usr').submit();
}	else {
	$('alert').innerHTML = '<font color=red><b>ERROR</b></font><br><b>Revise los campos delineados con Rojo.</b><br>'+$('alert').innerHTML;
	werror();
}
}

