var _applicationPath="/";var _urlServer="http://"+location.host+_applicationPath;var _urlMunicipality=encodeURIComponent(_urlServer+"Ws/PlaceManager.asmx/GetMunicipalitySimpleListByDistrictId?districtId=");var _urlMunicipalityS=encodeURIComponent(_urlServer+"Ws/PlaceManager.asmx/GetMunicipalitySimpleListByDistrictId?districtId=");var _urlSubcategory=encodeURIComponent(_urlServer+"Ws/CategoryManager.asmx/GetListSimple?categoryId=");var _urlLeadSave=encodeURIComponent(_urlServer+"Ws/LeadManager.asmx/Save?");var _urlUrlBuildSearch=_urlServer+"Ws/UrlBuildManager.asmx/GetSearchUrlFriendly?categoryId={0}&districtId={1}&municipalityId={2}&query={3}";var _urlUrlBuildLocation=_urlServer+"Ws/UrlBuildManager.asmx/GetLocationUrlFriendly?districtId={0}&municipalityId={1}";var _urlLeadToFriendSave=encodeURIComponent(_urlServer+"Ws/LeadManager.asmx/ToFriendSave?");var _urlGadsSave=encodeURIComponent(_urlServer+"Ws/GadsManager.asmx/Save?");var _urlJson=_urlServer+"json.axd?jsonUrl=";var __MaxPhotoCount=4;var _photoList=new Array();_photoList[0]=false;_photoList[1]=false;_photoList[2]=false;_photoList[3]=false;var regexEmail=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;var regexIsNumberWithDecimal=/^\d+\,\d{0,2}$/;var regexIsNumber=/^\d+$/;var municipalityJsonObject=null;var municipalitySJsonObject=null;var subcategoryJsonObject=null;var leadSaveJsonObject=null;var urlBuildSearchJsonObject=null;var urlBuildLocationJsonObject=null;var gadsJsonObject=null;function JSONscriptRequest(fullUrl){this.fullUrl=fullUrl;this.noCacheIE='&noCacheIE='+(new Date()).getTime();this.headLoc=document.getElementsByTagName("head").item(0);this.scriptId='JscriptId'+JSONscriptRequest.scriptCounter++;}
JSONscriptRequest.scriptCounter=1;JSONscriptRequest.prototype.buildScriptTag=function(){this.scriptObj=document.createElement("script");this.scriptObj.setAttribute("type","text/javascript");this.scriptObj.setAttribute("charset","utf-8");this.scriptObj.setAttribute("src",this.fullUrl+this.noCacheIE);this.scriptObj.setAttribute("id",this.scriptId);}
JSONscriptRequest.prototype.removeScriptTag=function(){this.headLoc.removeChild(this.scriptObj);}
JSONscriptRequest.prototype.addScriptTag=function(){this.headLoc.appendChild(this.scriptObj);}
function Loader(){var o=GetElement('loader');if(o!=null){o.style.display=o.style.display=='inline'?'none':'inline';}}
function PMunicipality(id,v){Loader();ClearDropdown('ddlMunicipality');if(v!="0"){var o=GetElement(id);if(o!=null){var jsonUrl=_urlJson+_urlMunicipality+v+'&jsonCallback=PopulateMunicipality';municipalityJsonObject=null;municipalityJsonObject=new JSONscriptRequest(jsonUrl);municipalityJsonObject.buildScriptTag();municipalityJsonObject.addScriptTag();}}
else{Loader();}}
function PopulateMunicipality(o){try
{if(o!=null)
{var municipalityList=null;if(o.ArrayOfM.M.length==null){municipalityList=new Array(1);municipalityList[0]=o.ArrayOfM.M}
else{municipalityList=o.ArrayOfM.M}
PopulateMunicipalityDropdown(municipalityList,'ddlMunicipality');o=null;municipalityJsonObject.removeScriptTag();municipalityJsonObject=null;}}
catch(ex)
{}
Loader();}
function PopulateMunicipalityDropdown(o,id){var dropdown=GetElement(id);if(dropdown!=null){var anOption=document.createElement("OPTION");anOption.value="0";anOption.text="Todas Localidades";dropdown.options.add(anOption);for(var i=0;i<=o.length-1;i++){if(o[i].I!=null&&o[i].N!=null){var anOption=document.createElement("OPTION");anOption.value=o[i].I;anOption.text=o[i].N;dropdown.options.add(anOption);}}}}
function PMunicipalityS(id,v){Loader();ClearDropdown('ddlMunicipality');if(v!="0"){var o=GetElement(id);if(o!=null){var jsonUrl=_urlJson+_urlMunicipalityS+v+'&jsonCallback=PopulateMunicipalityS';municipalitySJsonObject=null;municipalitySJsonObject=new JSONscriptRequest(jsonUrl);municipalitySJsonObject.buildScriptTag();municipalitySJsonObject.addScriptTag();}}}
function PopulateMunicipalityS(o){try
{if(o!=null)
{var municipalityList=null;if(o.ArrayOfM.M.length==null){municipalityList=new Array(1);municipalityList[0]=o.ArrayOfM.M}
else{municipalityList=o.ArrayOfM.M}
PopulateMunicipalitySDropdown(municipalityList,'ddlMunicipality');o=null;municipalitySJsonObject.removeScriptTag();municipalitySJsonObject=null;}}
catch(ex)
{}
Loader();}
function PopulateMunicipalitySDropdown(o,id){var dropdown=GetElement(id);if(dropdown!=null){var anOption=document.createElement("OPTION");anOption.value="0";anOption.text="Seleccione uma Localidade";dropdown.options.add(anOption);for(var i=0;i<=o.length-1;i++){if(o[i].I!=null&&o[i].N!=null){var anOption=document.createElement("OPTION");anOption.value=o[i].I;anOption.text=o[i].N;dropdown.options.add(anOption);}}}}
function ClearDropdown(o){var dropdown=GetElement(o);if(dropdown!=null&&dropdown.options!=null){while(dropdown.options.length>0){dropdown.removeChild(dropdown.options[0]);}}}
function GetElement(o){return document.getElementById(o);}
function SetText(o,txt){var t=GetElement(o);if(t!=null){t.innerHTML=txt;}}
function GetText(o){var txt='';var t=GetElement(o);if(t!=null){txt=t.innerHTML;}
return txt;}
function IsValid(text,r){return r.test(text);}
function messageBox(msg,color){var o=GetElement('message');if(o!=null){o.style.color=color;o.innerHTML=msg;}
setTimeout('messageBoxClear()',3000);}
function messageBoxClear(){SetText('message','');}
function SwapImage(o,url){var img=GetElement(o);if(img!=null){img.src=url;}}
function LeadSave(){var caSubmit=GetElement('caSubmit');var email=GetElement('caE');var name=GetElement('caN');var photo=GetElement('caP');var comment=GetElement('caC');var guid=GetText('guid');var eto=GetText('eto');if(guid.length>0&&email.value.length>0&&IsValid(email.value,regexEmail))
{caSubmit.disabled=true;var jsonUrlLead=_urlJson+_urlLeadSave+encodeURIComponent("guid="+guid+"&email="+email.value+"&name="+name.value+"&phone="+photo.value+"&comment="+comment.value)+'&jsonCallback=PopulateLeadSave';leadSaveJsonObject=null;leadSaveJsonObject=new JSONscriptRequest(jsonUrlLead);leadSaveJsonObject.buildScriptTag();leadSaveJsonObject.addScriptTag();}
else
{messageBox("e-mail inválido!","#aa0000")}}
function PopulateLeadSave(o){var caSubmit=GetElement('caSubmit');try
{if(o!=null){if(o.boolean.value=='true'){GetElement('caE').value='';GetElement('caN').value='';GetElement('caP').value='';GetElement('caC').value='';messageBox("Mensagem enviada com sucesso.","#3855FF")}}
o=null;leadSaveJsonObject.removeScriptTag();leadSaveJsonObject=null;}
catch(ex)
{}
finally
{caSubmit.disabled=false;}}
function PSubcategory(id,v){Loader();ClearDropdown('ddlSubcategory');CategoryVisible(false);if(v!="0"){var o=GetElement(id);if(o!=null){var jsonUrl=_urlJson+_urlSubcategory+v+'&jsonCallback=PopulateSubcategory';subcategoryJsonObject=null;subcategoryJsonObject=new JSONscriptRequest(jsonUrl);subcategoryJsonObject.buildScriptTag();subcategoryJsonObject.addScriptTag();}}}
function PopulateSubcategory(o){try
{if(o!=null)
{var categoryList=null;if(o.ArrayOfCategorySimple.CategorySimple.length==null){categoryList=new Array(1);categoryList[0]=o.ArrayOfCategorySimple.CategorySimple}
else{categoryList=o.ArrayOfCategorySimple.CategorySimple}
PopulateSubcategoryDropdown(categoryList,'ddlSubcategory');}
o=null;subcategoryJsonObject.removeScriptTag();subcategoryJsonObject=null;}
catch(ex)
{}
Loader();}
function PopulateSubcategoryDropdown(o,id){CategoryVisible(true);var dropdown=GetElement(id);if(dropdown!=null){var anOption=document.createElement("OPTION");anOption.value="0";anOption.text="Seleccione uma Subcategoria";dropdown.options.add(anOption);for(var i=0;i<=o.length-1;i++){if(o[i].CategoryId!=null&&o[i].Name!=null){var anOption=document.createElement("OPTION");anOption.value=o[i].CategoryId;anOption.text=o[i].Name;dropdown.options.add(anOption);}}}}
function CategoryVisible(v){var cVisible='inline'
if(v==false){cVisible='none';}
GetElement('subCn1').style.display=cVisible;GetElement('subCn2').style.display=cVisible}
function addPhoto(){if(_photoCount<__MaxPhotoCount)
{for(var i=0;i<_photoList.length;i++){if(_photoList[i]==false){_photoList[i]=true;GetElement('dpht00'+i.toString()).style.display='inline'
if(i==_photoList.length-1){GetElement('addPhoto').style.display='none'
GetElement('addPhotoF').style.display='none'}
break;}}}
else
{alert('O limite máximo de fotografias é de '+__MaxPhotoCount+'.\nPara inserir uma nova fotografia deverá remover uma existente.');}}
function removePhoto(id){GetElement('addPhoto').style.display='inline'
GetElement('addPhotoF').style.display='inline'
_photoList[id]=false;var dph=GetElement('dpht00'+id.toString());dph.innerHTML='<input name=\"ctl00$Main$pht00'+id.toString()+'\" type=\"file\" id=\"ctl00_Main_pht00'+id.toString()+'\" class=\"myCnP\" onchange=\"PhotoExtension(this, '+id.toString()+')\" />&nbsp;&nbsp;&nbsp;<span class=\"myFFCnf\" onclick=\"removePhoto('+id.toString()+')\">remover</span><br />';dph.style.display='none'}
function FidvDistrict(){var r=false;var o=GetElement('ddlDistrict');if(o.value=='0'||o.value.length==0){GetElement('idvDistrict').style.color='red';}else{GetElement('idvDistrict').style.color='#000000';r=true;}
return r;}
function FidvMunicipality(){var r=false;var o=GetElement('ddlMunicipality');if(o.value=='0'||o.value.length==0){GetElement('idvMunicipality').style.color='red';}else{GetElement('idvMunicipality').style.color='#000000';r=true;}
return r;}
function FidvCategory(){var r=false;var o=GetElement('ddlCategory');if(o.value=='0'||o.value.length==0){GetElement('idvCategory').style.color='red';}else{GetElement('idvCategory').style.color='#000000';r=true;}
return r;}
function FidvSubcategory(){var r=false;var o=GetElement('ddlSubcategory');if((o.value=='0'||o.value.length==0)&&GetElement('subCn1').style.display=='inline'){GetElement('subCn1').style.color='red';}else{GetElement('subCn1').style.color='#000000';r=true;}
return r;}
function FidvTitle(){var r=false;var o=GetElement('ctl00_Main_txtTitle');if(o.value.length==0){GetElement('idvTitle').style.color='red';}else{GetElement('idvTitle').style.color='#000000';r=true;}
return r;}
function FidvDescription(){var r=false;var t=FTB_API['ctl00_Main_ftbDescription'].GetHtml();if(t.length==0){GetElement('idvDescription').style.color='red';}else{GetElement('idvDescription').style.color='#000000';r=true;}
return r;}
function FidvPrice(){var r=false;var o=GetElement('ctl00_Main_txtPrice');if(o.value.length>0&&(!IsValid(o.value,regexIsNumber)&&!IsValid(o.value,regexIsNumberWithDecimal))){GetElement('idvPrice').style.color='red';}else{GetElement('idvPrice').style.color='#000000';r=true;}
return r;}
function FidvEmail(){var r=false;var o=GetElement('ctl00_Main_txtEmail');if(!IsValid(o.value,regexEmail)){GetElement('idvEmail').style.color='red';}else{GetElement('idvEmail').style.color='#000000';r=true;}
return r;}
function formSaveNewIsValid(){var _result=true;var _f1=FidvDistrict();var _f2=FidvMunicipality();var _f4=FidvCategory();var _f5=FidvSubcategory();var _f6=FidvTitle();var _f7=FidvDescription();var _f8=FidvPrice();var _f9=FidvEmail();if(!_f1||!_f2||!_f4||!_f5||!_f6||!_f7||!_f8||!_f9)
{_result=false;MessageSaveNew();setTimeout('MessageSaveNew()',3500);}
else
{var o=GetElement('ctl00_Main_btnSave');o.style.visibility='hidden';setTimeout('MessageUpload1()',1);for(var i=1;i<20;i++){if(i%2==0){setTimeout('MessageUpload1()',parseInt((i*3500).toString()));}
else{setTimeout('MessageUpload2()',parseInt((i*3500).toString()));}}}
return _result;}
function MessageUpload1(){messageBox('<b>Aguarde, dados a serem enviados para o servidor.</b>','#3855FF');}
function MessageUpload2(){messageBox('<b>Servidor a receber dados.</b>','#008008');}
function MessageSaveNew(){messageBox('<b>Complete ou corrija os campos assinalados a vermelho.</b>','red');}
function onlyDecimal(e){var isIE=document.all?true:false;var isNS=document.layers?true:false;var _ret=true;if(isIE){if(window.event.keyCode<48&&window.event.keyCode!=44||window.event.keyCode>57){window.event.keyCode=0;_ret=false;}}
if(isNS){if(e.which<48&&e.which!=44||e.which>57){e.which=0;_ret=false;}}
return(_ret);}
function IsValidPhotoExtension(who){var url=who.value;var extension=url.substring(url.lastIndexOf(".")).toLowerCase();var extensionPattern='.gif .jpg .jpeg .pjpeg .tiff .png';var result=true;return extension.length>0&&(extensionPattern.indexOf(extension)>=0);}
function PhotoExtension(who,id){if(!IsValidPhotoExtension(who)){removePhoto(id);alert('O ficheiro seleccionado não é uma imagem.')}}
function ConfirmPhotoDelete(){return confirm("Deseja apagar esta fotografia?");}
function messageBoxII(msg,color){var o=GetElement('msg02');if(o!=null){o.style.color=color;o.innerHTML=msg;}
setTimeout('messageBoxIIClear()',3000);}
function messageBoxIIClear(id){SetText('msg02','&nbsp;');}
function messageSucessSave(){MessageUpdateClassified();setTimeout('MessageUpdateClassified()',4000)}
function MessageUpdateClassified(){messageBoxII('<b>Registo gravado com sucesso.</b>','#3855FF','msg02')
messageBox('<b>Registo gravado com sucesso.</b>','#3855FF')}
function buildSearch(){var _cid=GetElement('ddlCatg');var _did=GetElement('did');var _mid=GetElement('mid');var _SQuery=GetElement('SQuery');if(_cid!=null&&_did!=null&&_mid!=null){var jsonUrl=_urlJson+encodeURIComponent(_urlUrlBuildSearch.replace('{0}',_cid.value).replace('{1}',_did.value).replace('{2}',_mid.value).replace('{3}',encodeURIComponent(_SQuery.value)))+'&jsonCallback=ChangeSearch';urlBuildSearchJsonObject=null;urlBuildSearchJsonObject=new JSONscriptRequest(jsonUrl);urlBuildSearchJsonObject.buildScriptTag();urlBuildSearchJsonObject.addScriptTag();}
return false;}
function ChangeSearch(o){try
{if(o!=null&&o.string.value.length!=null){location=o.string.value;}
o=null;urlBuildSearchJsonObject.removeScriptTag();urlBuildSearchJsonObject=null;}
catch(ex)
{}}
function buildLocation(){var _did=GetElement('ddlDistrict');var _mid=GetElement('ddlMunicipality');if(_did!=null&&_mid!=null){var jsonUrl=_urlJson+encodeURIComponent(_urlUrlBuildLocation.replace('{0}',_did.value).replace('{1}',_mid.value))+'&jsonCallback=ChangeLocation';urlBuildLocationJsonObject=null;urlBuildLocationJsonObject=new JSONscriptRequest(jsonUrl);urlBuildLocationJsonObject.buildScriptTag();urlBuildLocationJsonObject.addScriptTag();}
return false;}
function ChangeLocation(o){try
{if(o!=null&&o.string.value.length!=null){location=o.string.value;}
o=null;urlBuildLocationJsonObject.removeScriptTag();urlBuildLocationJsonObject=null;}
catch(ex)
{}}
function LeadToFriendSave(){var ppSubmit=GetElement('ppSubmit');var name=GetElement('ppN');var comment=GetElement('ppC');var email1=GetElement('ppE1');var email2=GetElement('ppE2');var email3=GetElement('ppE3');var email4=GetElement('ppE4');var guid=GetText('ppGuid');if((guid.length>0&&email1.value.length>0&&IsValid(email1.value,regexEmail))&&(email2.value.length==0||(email2.value.length>0&&IsValid(email2.value,regexEmail)))&&(email3.value.length==0||(email3.value.length>0&&IsValid(email3.value,regexEmail)))&&(email4.value.length==0||(email4.value.length>0&&IsValid(email4.value,regexEmail))))
{ppSubmit.disabled=true;var jsonUrlLeadToFriend=_urlJson+_urlLeadToFriendSave+encodeURIComponent("guid="+guid+"&email1="+email1.value+"&email2="+email2.value+"&email3="+email3.value+"&email4="+email4.value+"&name="+name.value+"&comment="+comment.value)+'&jsonCallback=PopulateLeadToFriendSave';leadToFriendSaveJsonObject=null;leadToFriendSaveJsonObject=new JSONscriptRequest(jsonUrlLeadToFriend);leadToFriendSaveJsonObject.buildScriptTag();leadToFriendSaveJsonObject.addScriptTag();}
else
{messageBoxIII("E-mail inválido!","#aa0000")}}
function PopulateLeadToFriendSave(o){var ppSubmit=GetElement('ppSubmit');try
{if(o!=null){if(o.boolean.value=='true'){GetElement('ppN').value='';GetElement('ppC').value='';GetElement('ppE1').value='';GetElement('ppE2').value='';GetElement('ppE3').value='';GetElement('ppE4').value='';messageBoxIII("Mensagem enviada com sucesso.","#3855FF")}}
o=null;leadToFriendSaveJsonObject.removeScriptTag();leadToFriendSaveJsonObject=null;}
catch(ex)
{}
finally
{ppSubmit.disabled=false;}}
function messageBoxIII(msg,color){var o=GetElement('messageLtf');if(o!=null){o.style.color=color;o.innerHTML=msg;}
setTimeout('messageBoxClearIII()',3000);}
function messageBoxClearIII(){SetText('messageLtf','');}
function querySt(ji){hu=window.location.search.substring(1);gy=hu.split("&");for(i=0;i<gy.length;i++){ft=gy[i].split("=");if(ft[0]==ji){return ft[1];}}}
function GetPartnerLink(){var gadsppSubmit=GetElement('gadsppSubmit');var txtClientId=GetElement('txtClintId');var txtChannel=GetElement('txtChannel');var txtEmail=GetElement('txtEmail');if(txtClientId.value.length==0){messageBoxGads('<b>ID Editor inválido. Verifique o campo ID Editor</b>.','#aa0000');}else if(txtChannel.value.length==0||!IsValid(txtChannel.value,regexIsNumber)){messageBoxGads('<b>ID Criterio inválido. Verifique o campo ID Criterio</b>.','#aa0000');}else if(txtEmail.value.length==0||!IsValid(txtEmail.value,regexEmail)){messageBoxGads('<b>Email inválido. Verifique o campo Email</b>.','#aa0000');}else{gadsppSubmit.disabled=true;var jsonUrl=_urlJson+_urlGadsSave+encodeURIComponent('client='+txtClientId.value+'&channel='+txtChannel.value+'&email='+txtEmail.value)+'&jsonCallback=PopulateGads';gadsJsonObject=null;gadsJsonObject=new JSONscriptRequest(jsonUrl);gadsJsonObject.buildScriptTag();gadsJsonObject.addScriptTag();}}
function PopulateGads(o){var gadsppSubmit=GetElement('gadsppSubmit');try
{if(o!=null){if(o.int.value>0){var _gadsTitle=decodeURIComponent(querySt("gads_title"));var _gadsUrl=decodeURIComponent(querySt("gads_url"));var _gadsLink="<a href=\"{0}\" title=\"{1}\">{2}</a>";var txtResult=GetElement('txtResult');_gadsUrl+=(_gadsUrl.indexOf("?",0)>=0?"&":"?")+"gads="+o.int.value;txtResult.value=_gadsLink.replace('{0}',_gadsUrl).replace('{1}',_gadsTitle).replace('{2}',_gadsTitle);messageBoxGads('Parabéns, link gerado com sucesso. Copie o código abaixo','#3855FF');}}
o=null;gadsJsonObject.removeScriptTag();gadsJsonObject=null;}
catch(ex)
{}
finally
{gadsppSubmit.disabled=false;}}
function messageBoxGads(msg,color){var o=GetElement('messageGads');if(o!=null){o.style.color=color;o.innerHTML=msg;}
setTimeout('messageBoxGadsClear()',5000);}
function messageBoxGadsClear(id){SetText('messageGads','&nbsp;');}
function selectToCopy(o){return true;}
function revealModal(divID){window.onscroll=function(){document.getElementById(divID).style.top=document.body.scrollTop;};document.getElementById(divID).style.display="block";document.getElementById(divID).style.top=document.body.scrollTop;}
function hideModal(divID){document.getElementById(divID).style.display="none";}