/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {
 
	// public method for url encoding
	encode : function (string) {
		if(!string){ return '';}
		return escape(string);
		//return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		if(!string){ return '';}
		return unescape(string);
		//return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		if(!string){ return '';}
		var utftext = "";
		if(string != undefined) {
			string = string.replace(/\r\n/g,"\n");
			for (var n = 0; n < string.length; n++) {
				var c = string.charCodeAt(n);
	 			if (c < 128) {
					utftext += String.fromCharCode(c);
				}
				else if((c > 127) && (c < 2048)) {
					utftext += String.fromCharCode((c >> 6) | 192);
					utftext += String.fromCharCode((c & 63) | 128);
				}
				else {
					utftext += String.fromCharCode((c >> 12) | 224);
					utftext += String.fromCharCode(((c >> 6) & 63) | 128);
					utftext += String.fromCharCode((c & 63) | 128);
				}
	 		}
		}
		return utftext;
	},
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		if(!utftext){ return '';}
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}

function toLowerCase_plus(texto){
	var ACENTOS_U =    "ÄÅÁÂÀÃÉÊËÈÍÎÏÌÖÓÔÒÕÜÚÛÇ";
	var acentos_l =    "äåáâàãéêëèíîïìöóôòõüúûç";
	if(texto){
		for (var i = 0; i < acentos_l.length; i++){
			texto = texto.replace(acentos_l.charAt(i), ACENTOS_U.charAt(i));
		}
		texto = texto.toLowerCase();
	}
	return texto;
}

function toUpperCase_plus(texto){
	var ACENTOS_U =    "ÄÅÁÂÀÃÉÊËÈÍÎÏÌÖÓÔÒÕÜÚÛÇ";
	var acentos_l =    "äåáâàãéêëèíîïìöóôòõüúûç";
	if(texto){
		for (var i = 0; i < acentos_l.length; i++){
			texto = texto.replace(ACENTOS_U.charAt(i), acentos_l.charAt(i));
		}
		texto = texto.toUpperCase();
	}
	return texto;
}

function getCapitalizeNameComplet(s)
{
    s = toLowerCase_plus(s);
    //s = toUpperCase_plus(s);
	if(s){
		s = s.charAt(0) + s.slice(1);
	}
	s = ' '+s;
    var po = 0;
    while(true){
        p = s.indexOf(' ',po);
        if((p>-1)&&((p+2)<s.length)){
            aux = s.toLowerCase();
            if( 
                (aux.substring(p,p+3)!=' a ')&&
                (aux.substring(p,p+3)!=' o ')&&
                (aux.substring(p,p+3)!=' e ')&&
                (aux.substring(p,p+3)!=' a ')&&
                (aux.substring(p,p+4)!=' da ')&&
                (aux.substring(p,p+4)!=' de ')&&
                (aux.substring(p,p+4)!=' di ')&&
                (aux.substring(p,p+4)!=' do ')&&
                (aux.substring(p,p+4)!=' du ')&&
                (aux.substring(p,p+5)!=' das ')&&
                (aux.substring(p,p+5)!=' dos ')&&
                (aux.substring(p,p+5)!=' dus ')
            ){
            s = s.substring(0,p)+toUpperCase_plus(s.substring(p,p+2))+s.substring(p+2,s.length);
            }
        } else {
            break;
        }
        po = p+1;
    }
    return s.substring(1,s.length);
}


