function replicate( cChar, nTimes )
{
	if (nTimes < 1) return '';
	if (nTimes == 1) return cChar;
	return cChar + replicate( cChar,nTimes-1 );
}

function currencyFormat(fld, milSep, decSep, e, decPlaces)
{
	var whichCode = (window.Event) ? e.which : e.keyCode;

	if ( whichCode < 32 ) return true;

	var dcPressed = 0;
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';

	//if (whichCode == 13) return true;	// Enter
	key = String.fromCharCode(whichCode);	// Get key value from key code
//	if ((key=='.') || (key==','))
	if ( key == decSep )
	{
		dcPressed = 1;
		key = '0';
	}

	if (strCheck.indexOf(key) == -1) return false;	// Not a valid key

	len = fld.value.length;
	
	//Se o campo nao ultrapassar a propriedade maxlength
	if (len >= fld.maxLength) return false;

	for(i = 0; i < len; i++)
	{
	 if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
	}

	aux = '';

	for(; i < len; i++)
	{
	 if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
	}

	if (dcPressed==1)
	{
		aux += replicate('0',decPlaces);
	}
	else
	{
		aux += key;
	}

	len = aux.length;

	fld.value = '0' + decSep + replicate('0',decPlaces-len) + aux;

	if (len > decPlaces)
	{
		aux2 = '';
		for (j = 0, i = len - (decPlaces + 1); i >= 0; i--)
		{
			if (j == 3)
			{
				aux2 += milSep;
				j = 0;
			}
			aux2 += aux.charAt(i);
			j++;
		}
		fld.value = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		{
			fld.value += aux2.charAt(i);
		}
		if (decPlaces>0) fld.value += decSep + aux.substr(len - decPlaces, len);
	}
	return false;
}

/*
*
*	openPopupWindow('example','ex',800,600,"no","no","no","no","no","no")
*
*/
function openPopupWindow(page,title,width,height,location,menubar,status,toolbar,scrollbars,resizable)
{
	if (!page) page = "";
	if (!title) title = "";
	if (!width) width = 640;
	if (!height) height = 420;
	if (!location) location = "no";
	if (!menubar) menubar = "no";
	if (!status) status = "no";
	if (!toolbar) toolbar = "no";
	if (!scrollbars) scrollbars = "no";
	if (!resizable) resizable = "no";
	
	return window.open(page,title,"width=" + width + ",height=" + height + ",location=" + location + ",menubar=" + menubar + ",status=" + status + ",toolbar=" + toolbar + ",scrollbars=" + scrollbars + ",resizable=" + resizable);
}

function isDate( date )
{
	if (date.length!=10) return false;

	var dn1 = date.substr(0,2);
	var dn2 = date.substr(3,2);
	var dn3 = date.substr(6,4);

	if ( (date.indexOf("/",0) != 2) || (date.indexOf("/",3) != 5) || (date.charAt(7) == "") )
	{
		return false;
	}

	if ( (isNaN(dn1)) || (isNaN(dn2)) || (isNaN(dn3)) )	return false;

	if ( (dn1 > 31) || (dn2 > 12) )	return false;
	
	return true;
}

function mask(obj,e,mask )
{
	var whichCode = (window.Event) ? e.which : e.keyCode;

	// if a control character was typed accept it without check
	if ( whichCode < 32 ) return true;

	// to prevent a bug in the mozilla browsers
	if ( mask.length > obj.maxLength ) obj.maxLength = mask.length;
	if ((obj.value.length >= obj.maxLength) || (obj.value.length >= mask.length)) return false;

	var strCheck	= '#ADMYHMS';
	var numbers	= '0123456789';
//	var whichCode = (window.Event) ? e.which : e.keyCode;
	var key		 = String.fromCharCode(whichCode);
	var cChar		= mask.charAt(obj.value.length);

	while ((obj.value.length < obj.maxLength) && (obj.value.length < mask.length))
	{
		if (strCheck.indexOf(cChar) < 0)
		{
			obj.value += cChar;
		}
		else
		{
			if (('#DMYHMS'.indexOf(cChar) >= 0) && (numbers.indexOf(key) < 0)) return false;
			break;
		}
		cChar = mask.charAt(obj.value.length);
	}
	return true;
}
///
///	controls the input data in a text field
///
///	dependencies: none
///
///	usage: <input type=text name=text1 maxlenght=9 size=9 onkeypress="javascript:return(mask2(this,event,'####-####'));">
///			<input type=text name=text1 maxlenght=10 size=10 onkeypress="javascript:return(mask2(this,event,'AAAAAAAAAA',' !@+'));">
///
function mask2(obj,evt,msk,deny)
{
	var nCode = (window.Event) ? evt.which : evt.keyCode;
	
	// if a control character was typed accept it without check
	if ( nCode < 32 ) return true;
	
	// if maxlength value or the mask´s length was reached, abort the function
	if ((obj.value.length >= obj.maxLength) || (obj.value.length >= msk.length)) return false;

	var sKey	= String.fromCharCode(nCode);
	var sChar = msk.charAt(obj.value.length);

	// if a denied character was typed, abort the function
	if ( typeof(deny) != "undefined" )
	{
		if ( deny.indexOf(sKey) >= 0 ) return false;
	}

	while ((obj.value.length < obj.maxLength) && (obj.value.length < msk.length))
	{
		switch ( sChar )
		{
			case "*":
				if ( (nCode >= 48 && nCode <= 57) || (nCode >= 65 && nCode <= 90) || (nCode >= 97 && nCode <= 122) ) return true;
				return false;
			case "A": // accept only AaBbCc...Zz
				if ( (nCode >= 65 && nCode <= 90) || (nCode >= 97 && nCode <= 122) ) return true;
				return false;
			case "#": // accept only 123...9
				if ( nCode >= 48 && nCode <= 57 ) return true;
				return false;
			case "X": // accept any character
				return true;
			default:	// any character else in the msk variable must be added
				obj.value += sChar;
				sChar = msk.charAt(obj.value.length);
		}
	}
}
///
///	controls the data entrance in a text field
///
///	usage: <input type=text name=text1 maxlenght=9 size=9 onkeypress="javascript:return(mask2(this,event,'A'));">
///			<input type=text name=text1 maxlenght=10 size=10 onkeypress="javascript:return(mask2(this,event,'X',,' !@+'));">
///
///	obj	- object representing the text field
///	evt	- event (always this)
///	type - '*' = numeric & alphabetic characters only
///			'A' = alphabetic characters only
///			'#' = numeric characters only
///			'X' = any character type
///	acpt - string of characters that must be accepted
///	deny - string of characters that must be denied
///
function accepts(obj,evt,type,acpt,deny)
{
	var nCode = (window.Event) ? evt.which : evt.keyCode;
	
	// if a control character was typed accept it without check
	if ( nCode < 32 ) return true;
	
	var sKey	= String.fromCharCode(nCode);

	// if a accepted character was typed, abort the function
	if ( typeof(acpt) != "undefined" )
	{
		if ( acpt.indexOf(sKey) >= 0 ) return true;
	}

	// if a denied character was typed, abort the function
	if ( typeof(deny) != "undefined" )
	{
		if ( deny.indexOf(sKey) >= 0 ) return false;
	}

	if ( typeof(type) == "undefined" ) type = "X";

	switch ( type )
	{
		case "*":
			if ( (nCode >= 48 && nCode <= 57) || (nCode >= 65 && nCode <= 90) || (nCode >= 97 && nCode <= 122) ) return true;
			return false;
		case "A": // accept only AaBbCc...Zz
			if ( (nCode >= 65 && nCode <= 90) || (nCode >= 97 && nCode <= 122) ) return true;
			return false;
		case "#": // accept only 123...9
			if ( nCode >= 48 && nCode <= 57 ) return true;
			return false;
		case "X": // accept any character
			return true;
		default:	// deny all
			return false;
	}
}


/***
* This script and many more are available free online at -->
* The JavaScript Source!! http://javascript.internet.com -->
*
* V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
* Original:	Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
* Changes:
*
* 1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
* international characters) were allowed.
* 
* 1.1.3: Added the restriction to only accept addresses ending in two
* letters (interpreted to be a country code) or one of the known
* TLDs (com, net, org, edu, int, mil, gov, arpa), including the
* new ones (biz, aero, name, coop, info, pro, museum).	One can
* easily update the list (if ICANN adds even more TLDs in the
* future) by updating the knownDomsPat variable near the
* top of the function.	Also, I added a variable at the top
* of the function that determines whether or not TLDs should be
* checked at all.	This is good if you are using this function
* internally (i.e. intranet site) where hostnames don't have to 
* conform to W3C standards and thus internal organization e-mail
* addresses don't have to either.
* Changed some of the logic so that the function will work properly
* with Netscape 6.
* 
* 1.1.2: Fixed a bug where trailing . in e-mail address was passing
* (the bug is actually in the weak regexp engine of the browser; I
* simplified the regexps to make it work).
* 
* 1.1.1: Removed restriction that countries must be preceded by a domain,
* so abc@host.uk is now legal.	However, there's still the 
* restriction that an address must end in a two or three letter
* word.
* 
* 1.1: Rewrote most of the function to conform more closely to RFC 822.
* 
* 1.0: Original
*/
function isEmail (emailStr)
{
	/* The following variable tells the rest of the function whether or not
		to verify that the address ends in a two-letter country or well-known
		TLD.	1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
		fits the user@domain format.	It also is used to separate the username
		from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
		characters.	We don't want to allow special characters in the address. 
		These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
		username or domainname.	It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
		which case, there are no rules about which characters are allowed
		and which aren't; anything goes).	E.g. "jiminy cricket"@disney.com
		is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
		rather than symbolic names.	E.g. joe@[123.124.233.4] is a legal
		e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
		For example, in john.doe@somewhere.com, john and doe are words.
		Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
		domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
		different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null)
	{
		/* Too many/few @'s or something; basically, this address doesn't
			even fit the general mould of a valid e-mail address. */
//		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}

	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++)
	{
		if (user.charCodeAt(i)>127)
		{
//			alert("Ths username contains invalid characters.");
			return false;
		}
	}
	
	for (i=0; i<domain.length; i++)
	{
		if (domain.charCodeAt(i)>127)
		{
//			alert("Ths domain name contains invalid characters.");
			return false;
		}
	}

	// See if "user" is valid 

	if (user.match(userPat)==null)
	{
		// user is not valid
//		alert("The username doesn't seem to be valid.");
		return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
		host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);

	if (IPArray!=null)
	{
		// this is an IP address
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
//				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}

	// Domain is symbolic name.	Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;

	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat)==-1)
		{
//			alert("The domain name does not seem to be valid.");
			return false;
		}
	}

	/* domain name seems valid, but now make sure that it ends in a
		known top-level domain (like com, edu, gov) or a two-letter word,
		representing country (uk, nl), and that there's a hostname preceding 
		the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)
	{
//		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2)
	{
 //		alert("This address is missing a hostname!");
		return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}


function checkSelect( frm, fld, idx, nowarn )
{
	if (typeof(frm.elements[fld])=="undefined")
	{
		window.alert( "O campo \"" + fld + "\" não existe!" );
		return false;
	}

	if ( frm.elements[fld].type != "select-one" )
	{
		window.alert( "Erro na função checkSelect.\n\nO campo \"" + fld + "\" não é do tipo \"select-one\"!" );
		return false;
	}

	idx = (typeof(idx)=="number"?idx:0);
	idx = (idx<0?0:idx);
	idx = (idx>=frm.elements[fld].length?frm.elements[fld].length:idx);

	nowarn = (typeof(nowarn)=="boolean"?nowarn:false);

	if ( (frm.elements[fld].selectedIndex < idx) && (! nowarn) )
	{
		window.alert( "Selecione uma das opções da lista de " + (frm.elements[fld].title==""?frm.elements[fld].name:frm.elements[fld].title) );
		frm.elements[fld].focus();
	}
	return (frm.elements[fld].selectedIndex >= idx);
}


function checkEquals( frm1, fld1, frm2, fld2 )
{
	if ( typeof( frm1.elements[fld1] ) != "object" )
	{
		window.alert("O campo \"" + fld1 + "\" não existe no formulário \"" + frm1.name + "\"");
		return false;
	}
	if ( typeof( frm2.elements[fld2] ) != "object" )
	{
		window.alert("O campo \"" + fld2 + "\" não existe no formulário \"" + frm2.name + "\"");
		return false;
	}
	return (frm1.elements[fld1].value == frm2.elements[fld2].value);
}

///
///
///
function checkText( frm, fld, min, nowarn, originalV )
{
	//alert( ":: checkText (" + fld + ") ::" );
	if (typeof(frm.elements[fld])=="undefined")
	{
		window.alert( "O campo \"" + fld + "\" não existe!" );
		return false;
	}
	else
	{
		if ( "$text$hidden$password$textarea$".indexOf("$"+frm.elements[fld].type+"$") == -1 )
//		if (frm.elements[fld].type != "text" && frm.elements[fld].type != "hidden" && frm.elements[fld].type != "password")
		{
			window.alert( "\"" + fld + "\" não é uma caixa de texto!" );
			return false;
		}
	}

	if ( typeof(min) != "number" ) min = 1;
	if ( min < 1 ) min = 1;
	nowarn = (typeof(nowarn)=="boolean"?nowarn:false);

	if ( (frm.elements[fld].value.length < min) && (! nowarn) && frm.elements[fld].type != "hidden" || frm.elements[fld].value == originalV )
	{
		window.alert("O campo \"" + frm.elements[fld].title + "\" deve ser preenchido" + (min>1?" com pelo menos " + min + " caracteres":"") + "!");
		frm.elements[fld].focus();
	}

	return (frm.elements[fld].value.length >= min || frm.elements[fld].type == "hidden");
}
///
///	check if the value of a text field contains a valid email address
///
function checkEmail( frm, fld, nowarn )
{
	if (typeof(frm.elements[fld])=="undefined")
	{
		window.alert( "O campo \"" + fld + "\" não existe!" );
		return false;
	}
	else
	{
		if (frm.elements[fld].type != "text" && frm.elements[fld].type != "hidden")
		{
			window.alert( "\"" + fld + "\" não é uma caixa de texto!" );
			return false;
		}
	}

	nowarn = (typeof(nowarn)=="boolean"?nowarn:false);

	var flag = isEmail( frm.elements[fld].value );

	if ( (!flag) && (!nowarn) )
	{
		alert("O endereço de e-mail informado não é válido!");
		frm.elements[fld].focus();
	}
	return flag;
}

function checkRadio( frm, fld, nowarn )
{
	if (typeof(frm.elements[fld])=="undefined")
	{
		window.alert( "O campo \"" + fld + "\" não existe!" );
		return false;
	}

	if ( typeof(frm.elements[fld].length) == "undefined" )
	{
		window.alert( "Erro na função checkRadio.\n\nO campo \"" + fld + "\" não é do tipo \"radio\"!" );
		return false;
	}

	if ( frm.elements[fld][0].type != "radio" )
	{
		window.alert( "Erro na função checkRadio.\n\nO campo \"" + fld + "\" não é do tipo \"radio\"!" );
		return false;
	}

	nowarn = (typeof(nowarn)=="boolean"?nowarn:false);

	var rtn = false;
	var fid = "";

	for (var i=0;i<frm.elements[fld].length;i++)
	{
		if (frm.elements[fld][i].checked)
		{
			rtn = true;
			fid = frm.elements[fld][i].title;
			break;
		}
	}
	
	if ( (! rtn) && (! nowarn) )
	{
		if ( frm.elements[fld][0].title == "" )
		{
			if ( frm.elements[fld][0].parentNode.title == "" )
			{
				frm.elements[fld][0].title = frm.elements[fld][0].name;
			}
			else
			{
				frm.elements[fld][0].title = frm.elements[fld][0].parentNode.title;
			}
		}
		window.alert( "Você deve marcar uma das " + frm.elements[fld].length + 
						" opções do item \"" + frm.elements[fld][0].title + "\"");
	}
	return rtn;
}
///
///	extract only charcters numbers of a given string
///
function numbersOnly( s )
{
	var r = "";
	for ( var i=0;i<s.length;i++ )
	{
		if ( "0123456789".indexOf( s.substr(i,1) ) >= 0 ) r += "" + s.substr(i,1);
	}
	return r;
}
///
///	check if a given cnpj number is valid
///
///	dependecies: numbersOnly
///
function isCNPJ( cnpj )
{
	// this function works only with character number
	cnpj = numbersOnly( cnpj );
	// cpfs must have eleven character numbers
	if ( cnpj.length != 14 ) return false;
	// numbers like 11111111111111, 22222222222222, ..., 99999999999999 are not valid
	if ( (parseInt(cnpj) / (parseInt(cnpj) % 10)) == 11111111111111 ) return false;

	var tmp = cnpj.substring(0,12);

	var dv1 = 0, dv2 = 0, plus = tmp.length + 1;

	for ( var i=(tmp.length-1);i>=0;i-- )
	{
		if ( (plus - i) > 9 ) plus = 2 + i;
		dv1 += tmp.charAt(i) * (plus - i);
//		window.alert( tmp.charAt(i) + " | " + (plus - i) );
	}

	dv1 = 11 - ((dv1 % 11)<2?11:(dv1 % 11));

	tmp += '' + dv1;

	plus = tmp.length + 1;

	for ( var i=(tmp.length-1);i>=0;i-- )
	{
		if ( (plus - i) > 9 ) plus = 2 + i;
		dv2 += tmp.charAt(i) * (plus - i);
	}

	dv2 = 11 - ((dv2 % 11)<2?11:(dv2 % 11));

	tmp += '' + dv2

	return ( cnpj == tmp );
}
///
///	check if a form field contains a valid cnpj number
///
function checkCNPJ(frm,fld)
{
	if (typeof(frm.elements[fld])=="undefined")
	{
		window.alert( "O campo \"" + fld + "\" não existe!" );
		return false;
	}
	else
	{
		if (frm.elements[fld].type != "text" && frm.elements[fld].type != "hidden")
		{
			window.alert( "\"" + fld + "\" não é uma caixa de texto!" );
			return false;
		}
	}
	if ( !isCNPJ(frm.elements[fld].value) )
	{
		window.alert( "O nº de CNPJ informado não é válido" );
		frm.elements[fld].focus();
		return false;
	}
	return true;
}
///
///	check if a given cpf number is valid
///
///	dependecies: numbersOnly
///
function isCPF(c)
{
	var i;
	// this function works only with character number
	c = numbersOnly( c );
	// cpfs must have eleven character numbers
	if ( c.length != 11 ) return false;
	// numbers like 11111111111, 22222222222, ..., 999999999999 are not valid
	if ( (parseInt(c) / (parseInt(c) % 10)) == 11111111111 ) return false
	s = c;
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	var v = false;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(10-i);
	}
	if (d1 == 0)
	{
		return false;
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1) return false;
	d1 *= 2;
	for (i = 0; i < 9; i++)
	{
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) return false;
	return true;
}
///
///	check if a form field contains a valid cpf number
///
function checkCPF(frm,fld)
{
	if (typeof(frm.elements[fld])=="undefined")
	{
		window.alert( "O campo \"" + fld + "\" não existe!" );
		return false;
	}
	else
	{
		if (frm.elements[fld].type != "text" && frm.elements[fld].type != "hidden")
		{
			window.alert( "\"" + fld + "\" não é uma caixa de texto!" );
			return false;
		}
	}
	if ( !isCPF(frm.elements[fld].value) )
	{
		window.alert( "O nº de CPF informado não é válido" );
		frm.elements[fld].focus();
		return false;
	}
	return true;
}
///
///	check if a form field contains a valid date
///
function checkDate(frm,fld,nowarn)
{
	var fRet = true
	if (typeof(frm.elements[fld])=="undefined")
	{
		window.alert( "O campo \"" + fld + "\" não existe!" );
		return false;
	}
	else
	{
		if (frm.elements[fld].type != "text" && frm.elements[fld].type != "hidden")
		{
			window.alert( "\"" + fld + "\" não é uma caixa de texto!" );
			return false;
		}
		if (frm.elements[fld].value == "00/00/0000")
		{
			window.alert( "\"" + fld + "\" não é uma caixa de texto!" );
			return false;
		}
	}

	if ( (!isDate(frm.elements[fld].value)) && (!nowarn))
	{
		fRet = false;
		window.alert("O data informada no campo \"" + fld + "\" não é válida");
	}

	return fRet;
}
///
/// © 2006, Fabio Tezedor
///
/// makes a key-value object record
///
/// parameters: val -> a string containing the key and its value in format key=value.
///             sep -> a character that specify the key-value separator. 
///                    it´s optional. by default the separator is '=' character.
///
///    returns: nothing
///
///      usage: var x = new KeyValue('name=Jennifer');
///
function KeyValue( val, sep )
{
	if ( typeof(sep) != "string" ) sep = "=";
	var p = val.indexOf(sep);
	this.name = val;
	this.value = "";

	if ( p > 0 )
	{
		this.name = val.substr(0,p);
		this.value = val.substr(p+1);
	}
}
///
/// © 2006, Fabio Tezedor
///
/// seek for the specified object in the whole document
///
/// parameters: object -> the oject name/id to seek.
///             type   -> the object type to seek for.
///                       it´s optional. by default any kind of objects will be considered.
///
///    returns: the object or null if not found
///
///      usage: var o = findObject( "MyObj" );
///                     findObject( "MyObj", "div" );
///
function findObject( object, type )
{
	try
	{
		var array;
		if (typeof(type)!="string")
		{
			array = document.all || document.getElementsByTagName('*');
		}
		else
		{
			array = document.getElementsByTagName(type);
		}
		for (var i=0;i<array.length;i++)
		{
			if ( array[i].id == object || array[i].name == object ) return array[i];
		}
		return null;
	}
	catch ( ex )
	{
		return null;
	}
}
///
///  © 2006, Fabio Tezedor
///
///  builds a form and its text´s fields dinamically and submits them
///
///  parameters: values -> the key-value pairs in the format key1=value1&key2=value2&key3=value3...
///                 url -> the internet address or just a page name to post the form data.
///                        it´s optional. by default the data will be sent to the sender´s page.
///              method -> the submit form method (get or post).
///                        it´s optional. by default the method is get.
///
///     returns: nothing
///
///       usage: <a href="javascript:submitIt('name=Jennifer&age=25&genre=F',null,'post')">post</a>
///
function submitIt(values,url,method,target)
{
	var f, e, v;
	
	if ( typeof(url) != "string" ) url = window.location.href;
	if ( typeof(method) != "string" ) method = "get";
	if ( typeof(target) != "string" ) target = "_self";
	if ( "post|get".indexOf(method.toLowerCase()) < 0 ) method = "get";
	
	var avalues = "pi=3.14".split("&");
	if ( typeof(values)=="string" ) avalues = values.split("&");
	
	try
	{
		f = findObject("post","form");
		//if ( typeof(document.forms["post"]) != "object" )
		if ( f == null )
		{
			var o = findObject("dvFrm","div");
			if(o==null)
			{
				o = document.createElement("div");
				o.name="dvFrm";
				o.id="dvFrm";
				o.style.position="absolute";
				o.style.top="0px";
				o.style.left="0px";
				//o.style.height="50px";
				//o.style.border="1px solid";
				o.style.display="none";
				document.body.appendChild(o);
			}
			f = document.createElement("form");
			f.name = "post";
			f.id = "post";
			o.appendChild(f);
		}
		else
		{
			f = document.forms["post"];
		}

		f.action = url;
		f.method = method;
		f.target = target;

		for ( var i=0;i<avalues.length;i++ )
		{
			kv = new KeyValue( avalues[i] );
			if ( typeof(f.elements[kv.name]) != "object" )
			{
				e = document.createElement("input");
				e.name = kv.name;
				e.id = kv.name;
				e.type = "hidden";
				f.appendChild(e);
			}
			else
			{
				e = f.elements[kv.name];
			}
			e.value = kv.value;
		}
		f.submit();
	}
	catch ( ex )
	{
		window.alert( ex.message );
	}
}

// This code was written by Tyler Akins and has been placed in the
// public domain.  It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com

function toBase64(input)
{
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;

	do
	{
		chr1 = input.charCodeAt(i++);
		chr2 = input.charCodeAt(i++);
		chr3 = input.charCodeAt(i++);

		enc1 = chr1 >> 2;
		enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
		enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
		enc4 = chr3 & 63;

		if (isNaN(chr2))
		{
			enc3 = enc4 = 64;
		}
		else if (isNaN(chr3))
		{
			enc4 = 64;
		}

		output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
	}
	while (i < input.length);
	
	return output;
}

function fromBase64(input)
{
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;

	// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
	input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

	do
	{
		enc1 = keyStr.indexOf(input.charAt(i++));
		enc2 = keyStr.indexOf(input.charAt(i++));
		enc3 = keyStr.indexOf(input.charAt(i++));
		enc4 = keyStr.indexOf(input.charAt(i++));

		chr1 = (enc1 << 2) | (enc2 >> 4);
		chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
		chr3 = ((enc3 & 3) << 6) | enc4;

		output = output + String.fromCharCode(chr1);

		if (enc3 != 64) output = output + String.fromCharCode(chr2);

		if (enc4 != 64) output = output + String.fromCharCode(chr3);
	}
	while (i < input.length);

	return output;
}

function checkHTML( frm, fld )
{
	if (typeof(frm.elements[fld])=="undefined")
	{
		window.alert( "O campo \"" + fld + "\" não existe!" );
		return false;
	}
	else
	{
		if ( "$text$hidden$password$textarea$".indexOf("$"+frm.elements[fld].type+"$") == -1 )
		{
			window.alert( "\"" + fld + "\" não é uma caixa de texto!" );
			return false;
		}
	}
	frm.elements[fld].value = htmlRemovall( frm.elements[fld].value );
}

function checkNumeric(frm,fld)
{
	//alert( ":: checkNumeric :: (" + fld + ")" );
	if (typeof(frm.elements[fld])=="undefined")
	{
		window.alert( "O campo \"" + fld + "\" não existe!" );
		return false;
	}
	else
	{
		if ( "$text$hidden$password$".indexOf("$"+frm.elements[fld].type+"$") == -1 )
		{
			window.alert( "\"" + fld + "\" não é uma caixa de texto!" );
			return false;
		}
		if ( isNaN( frm.elements[fld].value ) )
		{
			alert("Informe apenas números no campo \""+(frm.elements[fld].title==""?fld:frm.elements[fld].title)+"\"");
			return false;
		}
	}
	return true;
}

function htmlRemovall(t)
{
	//alert("eita!!!");
	var a = t.indexOf("<");
	var b = t.indexOf(">");
	var c = t.substring(0, a);
	if ( b == -1 ) b = a;
	var d = t.substring((b + 1), t.length);
	t = c + d;
	if ( t.indexOf("<") >= 0 ) t = htmlRemovall(t);
	return t;
}

function validaForm2(form){
	if(form.txtNome.value==''){
		alert('O campo ' + form.txtNome.title + ' não pode estar vazio');
		form.txtNome.focus();
		return false;
	}
	if(form.txtEmail.value=='' || !isEmail(form.txtEmail.value)){
		form.txtEmail.focus();
		alert('Email inválido!');
		return false; 
    }
	if(form.txtMensagem.value==''){
		alert('O campo ' + form.txtMensagem.title + ' não pode estar vazio');
		form.txtMensagem.focus();
		return false;
	}
	return true;
}

function setHome(t){
	try{
		t.style.behavior='url(#default#homepage)';
		t.setHomePage('http://www.aprofem.com.br');
	}catch(err){
		alert('Clique e arraste este link para o símbolo de Homepage do seu navegador.');
	}
	return false;
}

function doDown(v){
	if (v!=''){
		document.frmDown.action = v;
		document.frmDown.submit();
	}
}