ie=document.all?1:0;
n6=document.getElementsByTagName?1:0;

// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresarch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// ====================================================================
function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +
				        "(URL encoding only supports 8-bit characters.)\n" +
						"A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function URLDecode(encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while

   return  plaintext;
};

function swfembed(src,w,h){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,0,0" height="'+h+'" width="'+w+'"><param name="movie" value="'+src+'"><param name="quality" value="high"><param name="play" value="true"><embed height="'+h+'" width="'+w+'" pluginspage="http:\/\/www.macromedia.com\/go\/getflashplayer" src="'+src+'" type="application\/x-shockwave-flash" quality="high" play="true"><\/object>')
}

function agregaArqa(mail) {
	if( mail.value.length > 0 && mail.value.indexOf("@") == -1 ) 
		mail.value = mail.value + "@arqae.net";
}

function xdo_old(a){
n=a.name;
var y=(n!="m0");
var f=a.form;
var l=f.elements;
var e=0;
for(var i=0;i<l.length;i++){
	if(l[i].type=='checkbox')e++;
	};
var u=0;
if(f["m0"]){var s=f["m0"].checked;}
else{var s=false}

for(var i=1;i<e;i++){
	var g=f["m"+i];
	if(y){u=u+g.checked;}
	else{g.checked=s;xbg(g,s);}
	}

if(y){xbg(a,a.checked);if(f["m0"]){f["m0"].checked=(u==e-1);}}
}

function xdo(a){
n=a.name;
var y=(n!="m0");
var f=a.form;
var l=f.elements;
var e=0;
for(var i=0;i<l.length;i++){
	if(l[i].type=='checkbox')e++;
	};
var u=0;
if(f["m0"]){var s=f["m0"].checked;}
else{var s=false}

for(var i=1;i<e;i++){
	var g=f["m"+i];
	if(y){u=u+g.checked;}
	else{g.checked=s;xbg(g,s);}
	}

if(y){xbg(a,a.checked);if(f["m0"]){f["m0"].checked=(u==e-1);}}
}

function xdoall(a){
n=a.name;
var f=a.form;
var l=f.elements;
for(var i=0;i<l.length;i++){
	if(l[i].type=='checkbox' && l[i].name != 'm0') 
	{
		l[i].checked = f["m0"].checked;
		l[i].refresh; 
		// xbg(l[i],l[i].checked);
	}
};
}

function xdo2(a){
n=a.name;
var f=a.form;
// lo unico que hago es apagar el checked del de arriba
f["m0"].checked = false;
}


function xbg(x,s){if(n6||ie){
while(x.tagName!="TR"){x=ie?x.parentElement:x.parentNode}
x.className=(s?"H":"");}
}


function movesel(a) {
	var s=a.selectedIndex;
	var v=a.options[s].value;
	var f=a.form;
	var msgs=getInputValue(f.UID);
	if ( msgs == null ) {
		alert( "Debe seleccionar al menos un mensaje.")
		return false
	}	
		
	var texto = ( msgs.indexOf(",") == -1 ? "el mensaje" : "los mensajes seleccionados" );
	if ( v == "" ) {
		alert("Debe seleccionar alguna carpeta.");
		return;
	}	
	if ( v == "~new" ) {
		while ( true ) {
			var nuec = prompt( "Si desea mover " + texto + ",\ntipee el nombre de la nueva carpeta.","");
			if ( nuec == null ) { return }
			else { v = nuec }
			if ( validaFolder(v) ) { break }
		}	
	}	
	if ( confirm( "\u00BFDesea mover " + texto + " a\nla carpeta '" + v + "'?") )
	{
		f.ACT_MOVEMSG.value = v;
		f.submit();
	}	
}

function vaciarPapelera(rndtok) {
	if (confirm( "\u00BFDesea vaciar todo el contenido de la Papelera?" ))
	{ location.href="action.cfm?ACT_EMPTYDELETED=1&"+rndtok+"&referer="+URLEncode(document.location.href); }
}

function admfold(a,act) {
	var f=a.form;
	var txt;
	var fold = null;
	var fold = getInputValue(f.mboxrad);
	if ( fold == null ) {		
		alert("Debe seleccionar una carpeta.");
		return false;
	}	
		
	if ( act == "vaciar" ) {
	 if ( confirm("\u00BFDesea vaciar todo el contenido de la carpeta \"" + fold + "\"?") ){
	 	f.ACT_EMPTYFOLDER.value = fold;
		f.submit();
	 }
	} 
	else if ( act == "eliminar" ) {
		 if ( confirm("\u00BFDesea eliminar la carpeta \"" + fold + "\"?\nRecuerde que perder\u00E1 todos los mensajes contenidos en esta." )){
	 	f.ACT_DELFOLDER.value = fold;
		f.submit();
	 }
   } 
	else if ( act == "renombrar" ) {
		while ( true ) {
			var nuec = prompt( "Si desea renombrar la carpeta \"" + fold + "\", tipee el NUEVO NOMBRE de la misma.","" );
			if ( nuec == null ) { return }
			else { v = nuec }
			if ( validaFolder(v) ) { break }
		}	
	 	f.ACT_RENFOLDER.value = fold;
	 	f.ACT_RENFOLDERNAME.value = v;
		f.submit();
	}	
}

function validaFolder(folder) {
	results = folder.match("^[a-zA-Z0-9_ \-]+$");
	if( results == null ){
		alert('El nombre de la carpeta contiene un caracter no permitido.\nEntre otros, no se pueden utilizar acentos ni e\u00F1es.');
		return false;
	}		
	return true;
}

function vmsgAddMail(name,mail,rndtok) {
	if ( name == "" )
		name = mail.substring(0,mail.indexOf("@"));
	var name = prompt( "Si desea agregar la direcci\u00F3n \"" + mail + "\"\na la libreta de direcciones, tipee un nombre identificatorio de la misma:",name );
	if ( name == null ) { return }
	else 
	{ location.href="action.cfm?"+rndtok+"&ACT_ADDADDRBOOK="+URLEncode(mail)+"&ACT_ADDADDRBOOKNAME="+URLEncode(name)+"&referer="+URLEncode(document.location.href); }
}

function vmsgBlockMail(mail,rndtok) {
	if ( confirm( "Al bloquear una direcci\u00F3n no vuelve a recibir mensajes de la misma.\n\u00BFDesea bloquear la direcci\u00F3n \"" + mail + "\"?" ) ) 
	{ location.href="action.cfm?"+rndtok+"&ACT_BLOCKMAIL="+URLEncode(mail)+"&referer="+URLEncode(document.location.href); }
}

function addrbook(a,act) {
	var f=a.form;
	var txt;
	var fold = getInputValue(f.addrrad);
	if ( fold == null ) {		
		alert("Debe seleccionar una direcci\u00F3n.");
		return false;
	}	
		
	if ( act == "eliminar" ) {
		 if ( confirm("\u00BFDesea eliminar la direcci\u00F3n \"" + fold + "\"?" )){
	 	f.ACT_DELADDRBOOK.value = fold;
		f.submit();
	 }
   } 
	else if ( act == "renombrar" ) {
		var nuec = prompt( "Si desea cambiar el nombre relacionado al e-mail \n\"" + fold + "\", tipee el NUEVO NOMBRE del mismo." );
		if ( nuec == null ) { return }
		else { v = nuec }
	 	f.ACT_RENADDRBOOK.value = fold;
	 	f.ACT_RENADDRBOOKNAME.value = v;
		f.submit();
	}	
}

function blockmail(a,act) {
	var f=a.form;
	var txt;
	var fold = getInputValue(f.blockrad);
	if ( fold == null ) {		
		alert("Debe seleccionar una direcci\u00F3n.");
		return false;
	}	
		
	if ( act == "eliminar" ) {
		 if ( confirm("\u00BFDesea eliminar la direcci\u00F3n \"" + fold + "\"?" )){
	 	f.ACT_DELBLOCKMAIL.value = fold;
		f.submit();
	 }
   } 
	else if ( act == "renombrar" ) {
		var nuec = prompt( "Si desea cambiar al e-mail \n\"" + fold + "\", tipee el NUEVO EMAIL del mismo.", fold);
		if ( nuec == null ) { return }
		else { v = nuec }
	 	f.ACT_RENBLOCKMAIL.value = fold;
	 	f.ACT_RENBLOCKMAILNAME.value = v;
		f.submit();
	}	
}

