/************************************************************************/
/*					funciones.js                                       */
/*  Contiene todas la funciones usadas por todas las páginas web        */
/*  unas son elaboradas por Rodrigo y otras por Roberto                 */
/************************************************************************/
function makeUrlJS(h1,h2,h3,path,query)
{
	if(path=="/")
		path="";
	if(query!="")
		query="?".query;
	var url='\<a href="http://'+ h1+'.'+h2+'.'+h3+path+query + '" target="_blank" rel="nofollow" ' + 
	'style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px;color:#006699; '+
    'font-weight:bold;">'+ h1+'.'+h2+'.'+h3+path+query + '</a>';
	document.write(url);
}
function mnuld_swapImage(iddiv)
{
	var d=document.getElementById(iddiv);
	if(d)
	{
		d.src="http://www.zonu.com/fotos/images/seli"+iddiv.substr(5)+".gif";		
	}	
}
function mnuld_swapImgRestore(iddiv)
{
	var d=document.getElementById(iddiv);
	if(d)
	{
		d.src="http://www.zonu.com/fotos/images/"+iddiv+".gif";
	}	
}
function Searchobjid(item)
{
	if(( window.mmIsOpera )|| (document.getElementById))
	{
		return(document.getElementById(item));
	}
	if (document.all) 
	{
		return(document.all[item]);
	}
	return(false);
}

//Estas son las funciones para cargar el menu de empresas
function DameDepInmo(ca,op,frm,pais,nivel,padre,idioma,categoria,estado)
{
	if(ca.selectedIndex==0)
		IrmeSegunCat(ca,frm);
	else
	Pedir('http://'+document.domain+'/inmobiliarias/librerias/funcionesax.php',"f=PonerNivelInmo&ps="+pais+"&nv="+nivel+"&pa="+padre+"&idioma="+idioma+"&cat="+categoria+"&estado="+estado,op,frm,"dep");
}
/*******************************************************/

function IrmeCon(que,frm)
{
			frm.Pon.value=que;
			window.document.location.search="?";
			frm.action=frm.action+"?";
			frm.submit();
}

function Irme(que,frm,obj)
{
			obj.value=que;
			window.document.location.search="?";
			frm.action=frm.action+"?";
			frm.submit();
}
function Irme2(que1,que2,que3,que4,que5,que6,que7,frm,obj1,obj2,obj3,obj4,obj5,obj6,obj7)
{			
			if(obj1)obj1.value=que1;
			if(obj2)obj2.value=que2;
			if(obj3)obj3.value=que3;
			if(obj4)obj4.value=que4;
			if(obj5)obj5.value=que5;
			if(obj6)obj6.value=que6;
			if(obj7)obj7.value=que7;
			if(document.feim)
				if(document.feim.pget)
					document.feim.pget.value=document.location.search;
			frm.submit();
}
function ChangeEspecialChar(cad)
{
	var ncad=cad;
	var repcads="áaéeíióoúuñnàaèeìiòoùuäaëeïiöoüuÁAÉEÍIÓOÚUÑnÀAÈEÌIÒOÙUÄAËEÏIÖOÜUãaÃAaaAAôoÔoâaÂAttTTssSS";
	for(i=0;i<repcads.length;i++)
	{
		var expre=new RegExp(repcads.substr(i,1),"g");
		i+=1;
		ncad=ncad.replace(expre,repcads.substr(i,1));
	}
	return ncad;
}
function FUpperCase(cad)
{
	var tmp=cad.split(" ");
	for(var i=0;i<tmp.length;i++)
	{
		tmp[i]=tmp[i].substr(0,1).toUpperCase() + tmp[i].substr(1).toLowerCase();
	}
	return tmp.join(" ");
}
function rawurlencodex(url)
{
	var ncad=url;
	var repcads="áéíóúñàèìòùäëïöüÁÉÍÓÚÑÀÈÌÒÙÄËÏÖÜãÃaAôÔâÂtTsS";
	for(i=0;i<repcads.length;i++)
	{
		
		var expre=new RegExp(repcads.substr(i,1),"g");
		ncad=ncad.replace(expre,escape(repcads.substr(i,1)).toString(16));
	}
	return ncad;
}
function Armar_URL(frm)
{
	
	var mdir="http://"+document.domain+"/"+folder_emp+"inmo/"+archivo_emp+"ip/"+Folder_Lenguage+"c/"+frm.Categoria.value+"/";
	var on_dep=frm.elements[g_n_dep_emp];
	//alert(on_dep+"="+on_dep.value);
	if(on_dep && on_dep.value!="")
	{
		mdir+="n/"+rawurlencode(on_dep.value)+"/";
		if(t_dep_emp!=""&&t_dep_emp&&on_dep.value==n_dep_emp)mdir+="t/"+rawurlencode(t_dep_emp)+"/";
	}
	if(frm.Texto&&frm.Texto.value!="")mdir+="tx/"+frm.Texto.value+"/";
	
	var ob=frm.elements["categoria_nombrelink_emp_"+frm.Categoria.value];
	var na_link_emp="";
	if(ob)na_link_emp+=ob.value;
	if(t_dep_emp!=""&&t_dep_emp&&on_dep.value==n_dep_emp&&nom_espt_emp!="")
	{
		na_link_emp+=ChangeEspecialChar(nom_espt_emp);
		if(na_link_emp.indexOf(nom_pais_emp)>=0)
			mdir+=na_link_emp+".htm";
		else
			mdir+=na_link_emp+nom_pais_emp+".htm";
	}
	else
	{
		var nom_est_sel="";
		if(on_dep.value!="")
		{
			/*nom_est_sel=on_dep.value.toLowerCase();
			nom_est_sel=nom_est_sel[0].toUpperCase()+nom_est_sel.substring(1);*/
			/*nom_est_sel=on_dep.value.substr(0,1).toUpperCase() + on_dep.value.substr(1).toLowerCase();*/
			nom_est_sel=FUpperCase(on_dep.value);
			var expre=new RegExp(" ","g");
			nom_est_sel=nom_est_sel.replace(expre,"_");
		}	
		na_link_emp+=ChangeEspecialChar(nom_est_sel);
		na_link_emp=ChangeEspecialChar(na_link_emp);
		if(na_link_emp.indexOf(nom_pais_emp)>=0)
			mdir+=na_link_emp+".htm";
		/*else if(nom_est_sel!="")*/
		else
			mdir+=na_link_emp+nom_pais_emp+".htm";
		/*else
			mdir+=na_link_emp+nom_pais_emp+".htm";*/
	}
	mdir=mdir.replace('Valle_Daosta','Valle_dAosta');
	mdir=mdir.replace('România','Romania');
	return mdir.replace(/__/g,"_");
}
function Armar_URLb(Action,frm)
{
	var mdir="http://"+document.domain+"/"+folder_emp+"inmo/"+archivo_emp+"ip/p/"+Action+"/"+Folder_Lenguage+"c/"+ccode+"/";
	var on_dep=frm.elements[g_n_dep_emp];
	if(on_dep && on_dep.value!="")
	{
		mdir+="n/"+rawurlencode(on_dep.value)+"/";
		if(t_dep_emp!=""&&t_dep_emp&&on_dep.value==n_dep_emp)mdir+="t/"+rawurlencode(t_dep_emp)+"/";
	}
	if(frm.Texto&&frm.Texto.value!="")mdir+="tx/"+frm.Texto.value+"/";
	
	var na_link_emp="";
	var ob=lnk;
	if(ob)na_link_emp+=ob;
	if(t_dep_emp!=""&&t_dep_emp&&on_dep.value==n_dep_emp&&nom_espt_emp!="")
	{
		na_link_emp+=ChangeEspecialChar(nom_espt_emp);
		if(na_link_emp.indexOf(nom_pais_emp)>=0)
			mdir+=na_link_emp+".htm";
		else
			mdir+=na_link_emp+nom_pais_emp+".htm";
	}
	else
	{
		var nom_est_sel="";
		if(on_dep.value!="")
		{
			nom_est_sel=FUpperCase(on_dep.value);
			var expre=new RegExp(" ","g");
			nom_est_sel=nom_est_sel.replace(expre,"_");
		}	
		na_link_emp+=ChangeEspecialChar(nom_est_sel);
		na_link_emp=ChangeEspecialChar(na_link_emp);
		if(na_link_emp.indexOf(nom_pais_emp)>=0)
			mdir+=na_link_emp+".htm";
		else
			{nom_pais_emp=ChangeEspecialChar(frm.Paises.options[frm.Paises.selectedIndex].text);
			nom_pais_emp="_"+nom_pais_emp.replace(' ','_');
			mdir+=na_link_emp+nom_pais_emp+".htm";}
	}
	mdir=mdir.replace('Valle_Daosta','Valle_dAosta');
	mdir=mdir.replace('România','Romania');
	return mdir.replace(/__/g,"_");
}
function IrmeConOpr(que,frm)
{
	if(frm.Categoria)
	{

		if(frm.Categoria.selectedIndex==0 && frm.Categoria.options[frm.Categoria.selectedIndex].innerHTML!="Todos" && 
		isNaN(parseInt(frm.Categoria.options[frm.Categoria.selectedIndex].innerHTML,10))==false)			
			IrmeSegunCat(frm.Categoria,frm);
		else
		{
			//frm.Opr.value=que;
			//window.document.location.search="?";
			//frm.action=frm.action;//+"?";
			//frm.submit();			
			window.document.location.replace(Armar_URL(frm));
		}
	}
	else
	{
			//frm.Opr.value=que;			
			//window.document.location.search="?";
			//frm.action=frm.action;//+"?";
			//frm.submit();
			window.document.location.replace(Armar_URL(frm));
	}
}
function IrmeConOprb(que,frm)
{	
	if(frm.Categoria)
	{

		if(frm.Categoria.selectedIndex==0 && frm.Categoria.options[frm.Categoria.selectedIndex].innerHTML!="Todos" && 
		isNaN(parseInt(frm.Categoria.options[frm.Categoria.selectedIndex].innerHTML,10))==false)			
				IrmeSegunCat(frm.Categoria,frm);
		else
		{
			window.document.location.replace(Armar_URLb(que,frm));
		}
	}
	else
	{
			window.document.location.replace(Armar_URLb(que,frm));
	}
}
function IrmeConOpradmin(que,frm)
{
	if(frm.Categoria)
	{

		if(frm.Categoria.selectedIndex==0 && frm.Categoria.options[frm.Categoria.selectedIndex].innerHTML!="Todos")			
			IrmeSegunCat(frm.Categoria,frm);
		else
		{
			frm.Opr.value=que;
			window.document.location.search="?";
			frm.action=frm.action+"?";
			frm.submit();
		}
	}
	else
	{
			frm.Opr.value=que;			
			window.document.location.search="?";
			frm.action=frm.action+"?";
			frm.submit();
	}
}
function IrmeSegunCat(cat,frm)
{
	if(frm.Texto)
		frm.Texto.value="";
		
	if(frm.DEPARTAMENTO)
		frm.DEPARTAMENTO.selectedIndex=0;
	else if(frm.PROVINCIA)
		frm.PROVINCIA.selectedIndex=0;
	else if(frm.GOUVERNORAT)
		frm.GOUVERNORAT.selectedIndex=0;
	else if(frm.ESTADO)
		frm.ESTADO.selectedIndex=0;
	else if(frm.CANTON)
		frm.CANTON.selectedIndex=0;
	else if(frm.CONDADO)
		frm.CONDADO.selectedIndex=0;
	else if(frm.DISTRITO)
		frm.DISTRITO.selectedIndex=0;
	else if(frm.LOCALIDAD)
		frm.LOCALIDAD.selectedIndex=0;
	else if(frm.MUNICIPIO)
		frm.MUNICIPIO.selectedIndex=0;
	else if(frm.REGIÓN)
		frm.REGIÓN.selectedIndex=0;
		
	if(cat.options[cat.selectedIndex].value=='')
	{
		d=frm.elements["idx"+frm.Paises.value].value;
		
		//window.document.location.search="?";
		frm.action=frm.action;//+"?";
		window.document.location.replace(d);
		return true
	}
	//window.document.location.search="?";
	//frm.action=frm.action;//+"?";
	//frm.submit();
	window.document.location.replace(Armar_URL(frm));
		
}
function ImerSegunAct(Action,frm)
{
	//window.document.location.replace(frm.elements["p"+Action].value);	
	if(frm.Texto)
		frm.Texto.value="";
	frm.action=frm.elements["p"+Action].value;
	frm.target="_top";
	frm.submit();
}

function ImerSegunPais(Action,frm)
{
	if(frm.Texto)
		frm.Texto.value="";
	frm.elements[g_n_dep_emp].value="";
	window.document.location.replace(Armar_URLb(Action,frm));
}

function validarEmail(valor,idioma) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor)){  
   return (true)
  } else {
   Mensajes(1,idioma);
   return (false);
  }
 }
 
 function validarURL(Valor,idioma)
 {
	 if(/^http(?:[s])*:\/\/\w+[.]\w+(?:[.-]\w+)*([.]\w{2,4})+(((([\/]\w*)(?:[.-]\w+)*)*)([\/.]\w{3})*)/.test(Valor))
	 {
		 return true
	 }
	 else
	 {
	 	//Mensajes(2,idioma);
		return false
	 }
 }
 
 function validarTelefono(Valor,idioma)
 {
	/* if(/^((?:[+{1}]\d{2,3})*(?:\([+{1}]*\d{2,3}\))*)[- {1}]*?\d+(?:[- ]\d+)*\d$/.test(Valor))
	 {*/
		 return true
	/* }
	 else
	 {*/
		 /*alert("El teléfono introducido no es válido. Si va a poner el código del país puede hacerlo asi: (505)2222222. Si no: 2222222.");*/
	/*	 return false
	 }*/
 }
 
 /* Estas son las funciones para las imágenes*/
 function visibilityObj(objid,vis)
 {
	 var div;
	 div=MM_findObj(objid);
	 if(div)
	 	div.style.visibility=vis;
 }
 function onloadimg(obj)
{
	var divreload,divimg;


	if(obj)
	{
		
		divreload=MM_findObj("wait" + obj.name);
		divimg=MM_findObj("div" + obj.name);
		if(divreload && divimg)
		{
			
			divreload.style.visibility="hidden";
			divreload.style.overflow="scroll";
			divreload.style.height="1px";
			divimg.style.visibility="visible";
			divimg.style.overflow="visible";
			divimg.style.height="auto";
		}
	}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function SubmitForm(Action,Target,frm)
{
	if(frm)
		var obj=MM_findObj(frm);
	else
	{
		LoadFormCamps();
		var obj=MM_findObj('frmgeneral');
	}
	if(obj)
	{
		/*if(obj.Texto)
			obj.Texto.value="";*/
		if(Action)
		{
			obj.action=Action;
		}
		if(Target)
			obj.target=Target;
		obj.submit();	
	}
	else
	{
		alert("Los procesos están cargando. ¡Por favor espere!");
	}
	
}
var categ="0101";
function Enter(e)
{
	var tecla;
	
	tecla=0;
	if(typeof(e.which)!="undefined")
		tecla=e.which;
	else if(typeof(event)!="undefined")
		tecla=e.keyCode;
	if(tecla==13 || tecla==10)
	{
		ValidCuenta();
	}
}
function LoadFormCamps(camp)
{
	var obj,obj2,cad,tmp;
	if(!camp)
	{
	 camp=new Array(Array("Categoria","Idcategoria"),Array("CR","VR"),Array("Estados","Iddivision"),
		Array("Municipios","Idsubdivision"),Array("Colonias","Idlocalidad"),Array("Desde","Pdesde"),
		Array("Hasta","Phasta"),Array("Texto","Textosearch"));
	}
	
	for(var i=0;i<camp.length;i++)
	{
		obj=MM_findObj(camp[i][0]);
		if(obj)
		{
			obj2=MM_findObj(camp[i][1]);
			if(obj2)
			{
				cad=obj.value;
				while(1)
				{
					tmp="..." + cad;
					if(tmp.indexOf('"')>0)
						cad=cad.replace('"',"&quot;");
					else
						break;
				}
				obj2.value=cad;			
			}
		}
	}
}

function VerificarValor()
{
	var obj=MM_findObj('Categoria');
	if(obj)
	{
		
		if(obj.value=="-")
		{
			obj.value=categ;
			return false;
		}
		else
		{
			categ=obj.value;
			return true;	
		}
		
	}
	else
		return false;
}
function ReloadMenuLatIzq(Cual)
{
	if(VerificarValor())
	{
		if(typeof(Cual)=="undefined")
			Cual=0;
		SubmitForm("./lateralizq.php?Cual=" + Cual,"FrameMenu");
		var obj=MM_findObj("Loding");
		if(obj)
		{
			obj.style.visibility='visible';
		}
		obj=MM_findObj("Search");
		if(obj)
		{
			obj.disabled=true;
		}
	}
	else
		alert("Elija una sub categoría válida");
}
function ValidCuenta()
{
	var Usr=MM_findObj('Usr');
	var Pass=MM_findObj('Pass');
	var Email=MM_findObj('Email');
	var Password=MM_findObj('Password');
	var chk=MM_findObj('checkbox');
	
	if(Usr && Pass && Email && Password && chk)
	{
		Usr.value=Email.value;
		Pass.value=Password.value;
		if(Usr.value.indexOf("@")>0)
		{
			if(Usr.value.substr(Usr.value.indexOf("@") + 1).indexOf("@")<=0)
			{
				if(chk.checked)
				{
					SubmitForm(ServerLib+"sendmail.php?Envio=1","FrameMenu");
				}
				else
				{
					SubmitForm(Serverprimario+"cuenta.php?INI=1&Transaccion=1","_parent");
				}
			}
			else
			{
				alert("Indique un E-mail válido");
			}
		}
		else
		{
			alert("Ingrese un E-mail válido");
		}
	}
	else
	{
		alert("Error con la página no se puede ingresar, favor notifique al webmaster");
	}
	
	
	
}
/*ESTAS SON FUNCIONES PARA QUITAR LOS ESPACIOS EN BLANCO*/
function TrimLeft( str ) {
var resultStr = "";
var i = len = 0;
// Return immediately if an invalid value was passed in
if (str+"" == "undefined" || str == null)
return null;
// Make sure the argument is a string
str += "";
if (str.length == 0)
resultStr = "";
else {
// Loop through string starting at the beginning as long as there
// are spaces.
// len = str.length - 1;
len = str.length;

while ((i <= len) && (str.charAt(i) == " "))
i++;
// When the loop is done, we're sitting at the first non-space char,
// so return that char plus the remaining chars of the string.
resultStr = str.substring(i, len);
}
return resultStr;
}
function TrimRight( str ) {
var resultStr = "";
var i = 0;
// Return immediately if an invalid value was passed in
if (str+"" == "undefined" || str == null)
return null;
// Make sure the argument is a string
str += "";

if (str.length == 0)
resultStr = "";
else {
// Loop through string starting at the end as long as there
// are spaces.
i = str.length - 1;
while ((i >= 0) && (str.charAt(i) == " "))
i--;

// When the loop is done, we're sitting at the last non-space char,
// so return that char plus all previous chars of the string.
resultStr = str.substring(0, i + 1);
}

return resultStr;
}
function Trim( str ) {
	var resultStr = "";
	
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	
	return resultStr;
}
//FIN DE FUNCIONES PARA QUITAR ESPACIOS EN BLANCOS
/***********************************************************************/

//var htmltoimage="http://70.83.13.83:911/snapshotweb/sethtmltoimage.php?"; //Canada
var htmltoimage="http://190.184.38.169:80/snapshotweb/sethtmltoimage.php?"; //Local
var htmltoimageh="600";
var htmltoimageq="80";

var hexChar = new Array(
   '0' , '1' , '2' , '3' ,
   '4' , '5' , '6' , '7' ,
   '8' , '9' , 'a' , 'b' ,
   'c' , 'd' , 'e' , 'f');

function displayHexString (s)
{
	//s="&";
    var sb=new Array();
   for ( i=0; i<s.length; i++ )
      {
	  	if(s.charAt(i)=="&")
		{
		   c = s.charCodeAt(i);
		   var dividido=c;
		   var divisor=16;
		   var residuo=0;
		   var resultado=0;
		   var re=false;
		   var strHex="";
		   do
		   {
			residuo=dividido%divisor;
			residuo=residuo.toFixed(0);
			resultado=dividido/divisor;
			resultado=resultado.toFixed(0);
			dividido=resultado;
			strHex+=hexChar[residuo];
			
		   }
		   while(resultado!=0&&resultado!="NaN")
		   strHex+="%";
		}
		else
			strHex=s.charAt(i);

		   var strHexv="";
		   for(j=strHex.length-1;j>=0;j--)
				strHexv+=strHex[j];
      sb.push(strHexv);      
      
      }
	var rCad="";
	for(i=0;i<sb.length;i++)
		rCad+=sb[i];
	//alert(rCad);
   return rCad;
}
function Mensajes(num,idioma)
{
	if(idioma=="en")
	{
		if(num==1)
			alert("Invalid E-mail address.");
		else if(num==2)
			alert("Invalid URL. Enter complete address with everything and http://");
		else if(num==3)
			alert("Invalid Phone Number.");
	}
	else if(idioma=="fr")
	{
		if(num==1)
			alert("E-mail non valido.");
		else if(num==2)
			alert("URL non valido. Inserisci l'indirizzo completo e con http://");
		else if(num==3)
			alert("Numero di telefono non valido.");
	}
	else if(idioma=="pt")
	{
		if(num==1)
			alert("Adresse E-mail incorrecte.");
		else if(num==2)
			alert("URL invalide. Insérer l'adresse complète avec http://");
		else if(num==3)
			alert("Numéro de téléphone invalide.");
	}
	else if(idioma=="it")
	{
		if(num==1)
			alert("E-mail inválido.");
		else if(num==2)
			alert("URL inválido. Digite endereço completo com tudo e http://");
		else if(num==3)
			alert("Número de telefone inválido.");
	}
	else if(idioma=="ro")
	{
		if(num==1)
			alert("Adresa de e-mail invalida.");
		else if(num==2)
			alert("URL invalid. Introduceti adresa completa, cu toate elementele si http://");
		else if(num==3)
			alert("Telefon invalid.");
	}
	else	{
		if(num==1)
			alert("La dirección de email es incorrecta.");
		else if(num==2)
			alert("La direccion del link o url no es válido. Escriba la dirección con todo y el http://");
		else if(num==3)
			alert("El teléfono introducido no es válido.");
	}
	return true;
}
function rawurldecode(cad)
{
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded =cad;
   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
			{
				plaintext += ch;
				i++;
			}
		} 
		else 
		{
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}

function rawurlencode(cad)
{
 var SAFECHARS = "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "!~*'()";
 var HEX = "0123456789ABCDEF";

 var plaintext = cad;
 var encoded = "";
 for (var i = 0; i < plaintext.length; i++ ) 
 {
 	var ch = plaintext.charAt(i);
 	if (ch == " ") 
 		encoded += "+";
	else if (SAFECHARS.indexOf(ch) != -1) 
 		encoded += ch;
	else 
	{
 		var charCode = ch.charCodeAt(0);
 		if (charCode > 255) 
 			encode+=ch;
		else 
		{
 			encoded += "%";
 			encoded += HEX.charAt((charCode >> 4) & 0xF);
 			encoded += HEX.charAt(charCode & 0xF);
 		}
 	}
 } // for
 return encoded;
}