var Key={BACKSPACE:8,NONE:0};var IsIE=/MSIE/.test(navigator.userAgent);email_pattern=new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+");function onlyLetters(e){var k;document.all?k=e.keyCode:k=e.which;return((k>64&&k<91)||(k>96&&k<123)||k==8);}function onlyLettersOrSpace(e){var k;document.all?k=e.keyCode:k=e.which;return((k>64&&k<91)||(k>96&&k<123)||(k>191&&k<215)||(k>215&&k<247)||(k>247&&k<384)||k==8||k==32);}function onlyNumbers(e){var k;document.all?k=e.keyCode:k=e.which;return((k>47&&k<58)||k==Key.BACKSPACE||k==13||k==9||k==Key.NONE);}function textCounter(field,countfield,maxlimit){c=document.getElementById(countfield);c.innerHTML=maxlimit-field.value.length;if(field.value.length>maxlimit){field.value=field.value.substring(0,maxlimit);}}function isEmailValid(addr){if(email_pattern.test(addr)){return true;}return false;}function limitaDescricao(textarea,len){if(textarea.value.length>len){textarea.value=textarea.value.substr(0,len);}}function checkFieldsContactAd(f){var msg=CONST.MSG_FIELDS_REQUIRED;if(!isEmailValid(f.email.value)){alert(msg);f.email.focus();return false;}else if(f.nome.value==""){alert(msg);f.nome.focus();return false;}else if(f.mensagem.value==""){alert(msg);f.mensagem.focus();return false;}return true;}function deleteAd(adid){oldcookie=unescape(readCookie('quebarato_Csavedads'));tokens=oldcookie.split('&');newcookie=[];for(i=0;i<tokens.length;i++){c=tokens[i];if(c.substring(0,c.indexOf('.'))!=adid){newcookie[newcookie.length]=c;}}li=document.getElementById('list_ad_'+adid);li.style.display='none';span=document.getElementById('total_anuncios');span.innerHTML=(newcookie.length-1);if(newcookie.length>0)createCookie('quebarato_Csavedads',newcookie.join('&'),365*10);else createCookie('quebarato_Csavedads','',365*10);if((newcookie.length-1)==0){top.location.reload();}}function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires=";expires="+date.toGMTString();}else var expires=";";document.cookie=name+"="+value;}function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length);}return null;}
/*function toggleView(el){var img1=CONST.IMG_INAPPROPRIATE1;var img2=CONST.IMG_INAPPROPRIATE2;div=document.getElementById("posts");if(!div){return;}ols=div.getElementsByTagName("ol");for(i=0;i<ols.length;i++){if(ols[i].className==""||ols[i].className=="list"){ols[i].className="grid";el.className="grid";el.innerHTML=CONST.LABEL_SHOW_LISTMODE;$(".inappropriate").attr("src",img1);$(".inappropriate").attr("width","250");$(".inappropriate").attr("height","162");}else{ols[i].className="list";el.className="list";el.innerHTML=CONST.LABEL_SHOW_GRIDMODE;$(".inappropriate").attr("src",img2);$(".inappropriate").attr("width","863");$(".inappropriate").attr("height","90");}}}*/
function toggleView(el){var img1=CONST.IMG_INAPPROPRIATE1;var img2=CONST.IMG_INAPPROPRIATE2;ol = $('#posts ol');if(ol.hasClass('grid')) {ol.removeClass('grid');ol.addClass('list');el.className="list";el.innerHTML=CONST.LABEL_SHOW_GRIDMODE;$(".inappropriate").attr("src",img2);$(".inappropriate").attr("width","863");$(".inappropriate").attr("height","90");} else {ol.removeClass('list');ol.addClass('grid');el.className="grid";el.innerHTML=CONST.LABEL_SHOW_LISTMODE;$(".inappropriate").attr("src",img1);$(".inappropriate").attr("width","250");$(".inappropriate").attr("height","162");}}
function eraseCookie(name){createCookie(name,"",-1);}function checkNumChars(n,o){ var strValue = trim(o.value);if(strValue.length<n){msg=CONST.MSG_CHECKNUM_CHARS.replace(/\%d/g,n);alert(msg);o.focus();return false;}else{return true;}}function checkPwds(f){if(f.senha.value.length<5||f.senha2.value.length<5){alert(CONST.MSG_PASSWORD_MIN_LEN);return false;}if(f.senha.value!=f.senha2.value){alert(CONST.MSG_PASSWORD_NOT_EQUALS);return false;}}function calc_len(){if(!this.maxlength)return;var len=this.value.length;if(len>this.maxlength){this.value=this.value.substr(0,this.maxlength);len=this.value.length;}this.display_obj.innerHTML=this.maxlength-len;}function setup_counter(field_id,maxlength){var oTA=document.getElementById(field_id);if(!oTA)return;if(maxlength){oTA.maxlength=maxlength;len=oTA.value.length;}else{if(!oTA.maxlength)return;len=oTA.defaultValue.length;}var oCnt=document.getElementById(field_id+'r');if(!oCnt)return;oTA.display_obj=oCnt;oTA.onkeydown=calc_len;oTA.onkeyup=calc_len;oTA.onclick=calc_len;oTA.display_obj.innerHTML=oTA.maxlength-len;var obj=document.getElementById(field_id+'m');if(!obj)return;obj.style.display='inline';}function init_counter(field_id,maxlength){setup_counter(field_id,maxlength);}function reset_counter(field_id){setup_counter(field_id,0);}
function checkAttendanceForm(f){var submitted = false;if(isEmailValid(f.email.value)&&checkNumChars(3,f.nome)&&checkNumChars(5,f.message)){if (!submitted){submitted = true;return true;}return false;}else{alert(CONST.FEEDBACK_ATTENDANCE_FORM);return false;}}function cloneName(obj,frm){if(obj.name=='name')frm.name2.value=obj.value;else if(obj.name='name2')frm.name.value=obj.value;}
function formatCurrency(objTextBox,e){if(e.keyCode==9){document.getElementById("file").tabIndex = 4;return true;}var sep=0;var key='';var milSep=".";var decSep=",";var i=j=0;var len=len2=0;var strCheck='0123456789';var aux=aux2='';var lentext=11;var whichCode=(!IsIE)?e.which:e.keyCode;if(whichCode==13||whichCode==8)return true;key=String.fromCharCode(whichCode);if(strCheck.indexOf(key)==-1)return false;len=objTextBox.value.length;if(len <= lentext){for(i=0;i<len;i++)if((objTextBox.value.charAt(i)!='0')&&(objTextBox.value.charAt(i)!=decSep))break;aux='';for(;i<len;i++)if(strCheck.indexOf(objTextBox.value.charAt(i))!=-1)aux+=objTextBox.value.charAt(i);aux+=key;len=aux.length;if(len==0)objTextBox.value='';if(len==1)objTextBox.value='0'+decSep+'0'+aux;if(len==2)objTextBox.value='0'+decSep+aux;if(len>2){aux2='';for(j=0,i=len-3;i>=0;i--){if(j==3){aux2+=milSep;j=0;}aux2+=aux.charAt(i);j++;}objTextBox.value='';len2=aux2.length;for(i=len2-1;i>=0;i--)objTextBox.value+=aux2.charAt(i);objTextBox.value+=decSep+aux.substr(len-2,len);}}return false;}
function formatDate(d,e){var k;document.all?k=e.keyCode:k=e.which;if(!onlyNumbers(e)){return false;}else if(k==Key.BACKSPACE){return true;}value=d.value;if(value.length==2||value.length==5){value=value+"/";}d.value=value;}function isAgree(f){if(!isEmailValid(trim(f.email.value))){alert(CONST.MSG_EMAIL_INVALID);f.email.focus();return false;}else if(f.seq.value==''){alert(CONST.MSG_CAPTCHA_EMPTY);f.seq.focus();return false;}else if(f.li_termo.checked==false){alert(CONST.MSG_USAGE_TERMS_UNREAD);return false;}return true;}function displayAllStates(){document.getElementById("topuf").style.display="none";document.getElementById("alluf").style.display="block";}function checkImageType(o){fname=o.value;if(fname.length>0){ndx = fname.search(/[png|bmp|jpg|jpeg|gif]$/gi);if(ndx<0){alert(CONST.MSG_INVALID_IMG_TYPE);o.focus();o.value='';}}}function checkDocType(o){if(o.value.length>0){if(o.value.toLowerCase().indexOf(".doc")<0&&o.value.toLowerCase().indexOf(".pdf")<0&&o.value.toLowerCase().indexOf(".txt")<0){alert(CONST.MSG_INVALID_CV_TYPE);o.focus();o.value='';}}}function fixHeight(){div=document.getElementById("menu");if(document.getElementById("menu"))div=document.getElementById("menu");else if(document.getElementById("filters"))div=document.getElementById("filters");else if(document.getElementById("step1"))div=document.getElementById("step1");else if(document.getElementById("step2"))div=document.getElementById("step2");else return;divcontent=document.getElementById("content");cntHeight=parseInt(divcontent.offsetHeight);divHeight=parseInt(div.offsetHeight)+150;if(divHeight>cntHeight)divcontent.style.height=divHeight+70+"px";}
function checkNickName(o){var apelido_pat=new RegExp("[^a-zA-Z0-9_\-]","gi");if(apelido_pat.test(o.apelido.value)||o.apelido.value==''){alert(CONST.MSG_NICKNAME_INVALID);return false;}if(o.emailprom != null){if (o.emailprom.checked == true) {o.emailprom.value = '1';} else {o.emailprom.value = '0';}}return true;}
function disablePFPJ(v,frm){if(v==1){frm.pessoa[0].checked=1;frm.rsocial.disabled=0;frm.cnpj.disabled=0;frm.name2.disabled=1;frm.cpf.disabled=1;}else{frm.pessoa[1].checked=1;frm.rsocial.disabled=1;frm.cnpj.disabled=1;frm.name2.disabled=0;frm.cpf.disabled=0;}}function onFocus(){var url=window.location;if(url=='http://ao.quebarato.org/'||url=='http://www.quebarato.com.ar/'||url=='http://www.quebarato.com.bo/'||url=='http://www.quebarato.com.br/'||url=='http://cv.quebarato.org/'||url=='http://www.quebarato.cl/'||url=='http://www.quebarato.com.co/'||url=='http://www.quebarato.co.cr/'||url=='http://www.quebarato.com.ec/'||url=='http://www.quebarato.com.sv/'||url=='http://www.quebarato.com.es/'||url=='http://www.quebarato.org/'||url=='http://www.quebarato.com.gt/'||url=='http://gw.quebarato.org/'||url=='http://www.quebarato.com.hn/'||url=='http://mo.quebarato.org/'||url=='http://www.quebarato.com.mx/'||url=='http://www.quebarato.com.ni/'||url=='http://www.quebarato.com.pa/'||url=='http://www.quebarato.com.py/'||url=='http://www.quebarato.com.pe/'||url=='http://www.quebarato.com.pr/'||url=='http://www.quebarato.com.pt/'||url=='http://www.quebarato.com.do/'||url=='http://st.quebarato.org/'||url=='http://tl.quebarato.org/'||url=='http://www.quebarato.com.uy/'||url=='http://ve.quebarato.org/'){document.getElementById("kw").focus();}}
function showPromotions(){var location=top.location.href;if(location.indexOf('/minha-conta/descadastramento.htm')>=0){document.getElementById('proemail').style.display='block';}}function nicknameAvailability(){nick=document.getElementById("nick");if(!nick){return false;}var param="n="+nick.value;ajax=new HttpRequest();ajax.send("/NickChecker",function(xml){node=xml.getElementsByTagName("status").item(0);status_value=node.childNodes.item(0).nodeValue;message=xml.getElementsByTagName("content").item(0);p=document.getElementById("feedback_nickname");p.className="ok";if(status_value<0) p.className="error";p.innerHTML=message.childNodes.item(0).nodeValue; },param);return false;}
function onlyNumber(caracter, f){var nTecla = 0;if (document.all) {nTecla = caracter.keyCode;}else{nTecla = caracter.which;}if ((nTecla> 47 && nTecla <58) || nTecla == 8 || nTecla == 127 || nTecla == 0 || nTecla == 9 || nTecla == 13){return true;}else{return false;}}
function validaCPF(cpf){if (cpf.length == 11){if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){return false;}var a = [];var b = new Number;var c = 11;for (i=0; i<11; i++){a[i] = cpf.charAt(i);if (i < 9) b += (a[i] * --c);}if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }b = 0;c = 11;for (y=0; y<10; y++) b += (a[y] * c--);if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])) {return false;}}else{return false;}return true;}
function pingConversion(type,sbmt) {
	if(!type) return;
	var hash = "";
	switch(type) {
	case 1: hash = "EqdLCLr6bxCgvbv8Aw"; /*QB com PD*/
	break;
	case 2: hash = "SBzyCPTNdxCgvbv8Aw"; /*ClasseB com PD */
	break;
	case 3: hash = "ViKyCOC6ZhCgvbv8Aw"; /*ClasseB sem PD*/
	break;
	}
	$('body').append('<img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/1066327712/?label=' + hash + '&amp;script=0" style="display:none"/>')
	if(sbmt) $("form.form_div_of").submit();
}
function GetURLParam(strParamName){var strReturn = "";var strHref = top.location.href;if(strHref.indexOf("?") > -1 ){var strQueryString = strHref.substr(strHref.indexOf("?"));var aQueryString = strQueryString.split("&"); for(var iParam = 0; iParam < aQueryString.length; iParam++ ){ if ( aQueryString[iParam].indexOf(strParamName + "=") > -1 ){ var aParam = aQueryString[iParam].split("=");strReturn = aParam[1];break;}}} return strReturn;}
function trim(str){return str.replace(/^\s+|\s+$/g,"");}
function checkNumCharsFilters(o){ var strValue = trim(o.value);if(strValue.length==1){msg=CONST.MSG_CHECKNUM_CHARS.replace(/\%d/g,2);alert(msg);o.focus();return false;}else{return true;}}

function isAgreeOptOut(f){		
	if(f.opt1.checked==false && f.opt2.checked==false && f.opt3.checked==false && f.opt4.checked==false && f.opt5.checked==false){
		writeErrorMsgBox(CONST.TITLE_MSGBOX_ERRO,300,100,CONST.MSG_MOTIVO_CANCELAMENTO_NEWS);			
		return false;
	}else if(f.seq.value==''){		
		writeErrorMsgBox(CONST.TITLE_MSGBOX_ERRO,300,100,CONST.MSG_CAPTCHA_EMPTY);		
		f.seq.focus();
		return false;
	}
	return true;
}
var checkFilterFields = {
		
	sanityCheck : function(elementByid) {		
		var flag=false;
		for(var i=0;i<elementByid.length;i++) {
			var id = elementByid[i].value;		
			if(id == ''){flag = true;}else{flag = false; break;}		
		}
		if(elementByid.length == 0){flag = true;}
		
		if((!$.trim($('#kw2').val()) && !$('#uf').val() && !$('#pmin').val() && !$('#pmax').val())&& flag) {			
			alert(CONST.MSG_ONE_FILTER_AT_LEAST);			
			return false;
		}
		return this.minmaxPrice();
	},
	minmaxPrice : function() {
		if($('#pmin').val() && $('#pmax').val()) {
			var pmin = $('#pmin').val().replace(/^\s*|,|\./g,"") * 1;
			var pmax = $('#pmax').val().replace(/^\s*|,|\./g,"") * 1;			
			if(pmin > pmax) {
				alert(CONST.MSG_PMIN_PMAX_ERROR);
				return false;
			}else if($('#pmin').val()== $('#pmax').val()) {
				alert(CONST.MSG_PMIN_PMAX_EQUALS);
				return false;
			}
		}
		return true;
	}
}
