
function getFlashMovieObject(movieName){
if (window.document[movieName]){return window.document[movieName];}
if (navigator.appName.indexOf("Microsoft Internet")==-1){if (document.embeds && document.embeds[movieName])return document.embeds[movieName];}else{return document.getElementById(movieName);}
}

function gen_iconuri(){
nume=new Array('imobiliare','auto','servicii','locuridemunca','hoteluripensiuni','licitatiipublice','animale','produsedevanzare');
var obj;
for (i=0;i<nume.length;i++){
obj='<OBJECT id="i_'+nume[i]+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=8,0,0,0" WIDTH=120 HEIGHT=60>';
obj=obj+'<PARAM NAME=movie VALUE="img/i_'+nume[i]+'.swf"><PARAM NAME=quality VALUE=high><PARAM NAME="wmode" VALUE="transparent"><PARAM NAME=loop VALUE=true>';
obj=obj+'<EMBED name="i_'+nume[i]+'" src="img/i_'+nume[i]+'.swf" wmode="transparent" loop=true quality=high WIDTH=120 HEIGHT=60 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
document.write(obj);}
}

function play_icon(n,x){
var movie=getFlashMovieObject('i_'+n);
switch (x){
case 1:{movie.GotoFrame(1);movie.Play();break;}
case -1:{movie.GotoFrame(15);movie.Play();break;}
default:{break;}}
}

nano=5;
function anoi(){
e=document.getElementById('anoi');t=parseInt(e.style.top);
if (t>-95){e.style.top=t-5;window.setTimeout('anoi()',50);}else{nano++;ajf('anoi','st='+nano.toString());}
}

function anoi_fin(r){
document.getElementById('anoi').style.top=0;
e=document.getElementById('anoi');s=e.innerHTML;
s=s.substring(s.indexOf('</div></div></div>')+18);
e.innerHTML=s+r;
if(nano<50){window.setTimeout('anoi()',7000)}
}

function map_sjud(n,j){
document.getElementById('mapsjud').className='disp';
if (n!='București'){n='județul '+n;}
var txt='<div class="mapjud" id="mapjud">'+n+':</div><div id="maploc" class="maploc"></div>';
if (n=='București'){txt=txt+'<a href="#" onclick="map_sjud(\'Ilfov\',26)">Vezi județul <b>Ilfov</b></a>';}
document.getElementById('mapsjc').innerHTML=txt;
if (j>0){ajf('maploc','jud='+j)};
}

function map_cat(j,n){
if (n=='București'){map_sjud(n,0)}
document.getElementById('mapjud').innerHTML=n+':';
ajf('mapcat','jud='+j+'&loc='+n);
}

function map_cl(){
document.getElementById('mapsjud').className='dispno';
}

function ppcauta(){
qs=document.getElementById('qs').value;
a=new RegExp('[^ăîșțâa-z0-9]','ig');qs=qs.replace(a,' ');
a=new RegExp('  ','g');qs=qs.replace(a,' ');
q=qs.split(' ');qs='';
a=new RegExp('[^0-9]','ig');
var exc=['vw','tt','a3','a4','a6','a8'];
for (i=0;i<q.length;i++){if ((q[i].length>2)||(!a.test(q[i]))||(exc.indexOf(q[i].toLowerCase())!=-1)){qs=qs+' '+q[i];}}
if (qs.length>0){qs=qs.substring(1);document.getElementById('qs').value=qs;location.href='index.asp?m=cauta&q='+enc(qs);}
}

function dgn(n){
e=document.getElementsByName(n)[0];if(e!=undefined){if(e.value!=undefined){
if(document.getElementById('tr_'+n)!=undefined){if(document.getElementById('tr_'+n).className=='dispno'){return '';}}
return e.value};}return '';
}

function sepmii(s){
ss="";s=s.toString();
k=0;
for(i=s.length-1;i>=0;i--){
 k=k+1;
 ss=s.substring(i,i+1)+ss;
 if((k%3==0)&&(i>0)){ss='.'+ss;}
 }
return ss;
}

function uploading(){
if (document.getElementById('upl').style.display==''){du='none';}else{du='';}
document.getElementById('upl').style.display=du;
return true;
}

function loading(n){
document.getElementById(n).innerHTML='<img src="img/loading.gif">';
return true;
}

function sh_firma(){
if (document.getElementById('tip_p').checked==true){document.getElementById('isfirma').className='disp';}else{document.getElementById('isfirma').className='dispno';}
}

function nhelp(n){
if (document.getElementById('helptxt_'+n).innerHTML=='-'){
 ajf('nnhelp','t='+n);}
 else{document.getElementById('helpbox_'+n).style.display='';}
}
function clhelp(n){
document.getElementById('helpbox_'+n).style.display='none';
}

function localitati(n,sel){
loading('form_'+n+'localitate');
ajf('localitati','jud='+document.getElementById(n+'judet').value+'&n='+n+'localitate&sel='+sel);
}

function cca(s,i){return s.charCodeAt(i);}

function pem(s){var ss='';for(var i=0;i<s.length;i++){ss=ss+''+String.fromCharCode(cca(s,i)-1)}document.write(ss);}
function pes(s){var ss='';for(var i=0;i<s.length;i++){ss=ss+''+String.fromCharCode(cca(s,i)-1)}document.write('<a href="http://'+ss+'" target="_blank">'+ss+'</a>');}

function tar(){
if (document.getElementById('tara').value!='România'){
document.getElementById('judet').style.display='none';document.getElementById('form_localitate').innerHTML='<input type="text" id="localitate" name="localitate" class="fld" value="'+selected_localitate+'">';}
else{document.getElementById('judet').style.display='';localit();}
}

function localit(){
loading('form_localitate');
ajf('localitati','n=localitate&jud='+document.getElementById('judet').value+'&sel='+enc(selected_localitate));
}

function pas2anunt(){
document.getElementById('m').value=document.getElementById('categ').value+'_editanunt2';
document.getElementById('f_tara').value=document.getElementById('tara').value;
document.getElementById('f_judet').value=document.getElementById('judet').value;
document.getElementById('f_localitate').value=document.getElementById('local').value;
document.getElementById('f_dest').value=dest;
document.getElementById('fa').submit();
}

function localitatitot(){
loading('form_loc');
ajf('localitati','jud='+document.getElementById('judet').value+'&n=loc');
}

function create_request_string(theform){
var reqStr = "";
for(i=0;i<theform.elements.length;i++){
 v='';
 e=theform.elements[i];
 if (e.name!=''){
 switch (e.tagName){
  case "INPUT"   :{
  switch (e.type){
   case "text":case "hidden"   :{v=e.value;break;}
   case "checkbox":case "radio":{if(e.checked){v=e.value};break;}
  }break;}
  case "SELECT"  :{v=e.value;break;}
  case "TEXTAREA":{v=e.value;break;}
  } 
if (v.length>0){reqStr+=e.name+"="+(enc(v))+"&";}
}}
if (reqStr.length>0){reqStr=reqStr.substring(0,reqStr.length-1)}
return reqStr;
}

function validate_form(theform){
gok=true;
for(i=0;i<theform.elements.length;i++){
 v='';
 e=theform.elements[i];
 if (e.name!=''){
 switch (e.tagName){
  case "INPUT"   :{
  switch (e.type){
   case "text":{v=e.value;break;}
  }break;}
  case "SELECT"  :{v=e.value;break;}
  case "TEXTAREA":{v=e.value;break;}
  }
 ok=true;cnt=false;
 if(vck[e.name]!=undefined){cnt=true;if(document.getElementById('tr_'+e.name)!=undefined){if(document.getElementById('tr_'+e.name).className=='dispno'){cnt=false;}}
 if(cnt){
  p=vck[e.name].split(',');p[0]=parseInt(p[0]);p[1]=parseInt(p[1]);p[2]=parseInt(p[2]) ;
  if (v.length<p[0]) ok=false;
  if ((v.length>p[1])&&(p[1]!=0)) ok=false;
  if (p[2]==1){var re = new RegExp('[^0-9]','g');if (v.match(re)) ok=false;}
  if (!ok){if (gok){gok=false;alert('completați corect toate câmpurile obligatorii!');e.focus();}}
  }}
}}
if (gok){uploading()}
return gok;
}

function rsslink(s){
var head = document.getElementsByTagName('head').item(0);
var link = document.createElement("link");
link.setAttribute('rel','alternate');
link.setAttribute('type','application/rss+xml');
link.setAttribute('title','PubliActual');
link.setAttribute('href',s);
head.appendChild(link);
}

function chpas1(){
s=document.getElementById('modul').value.split(',');
document.getElementById('m').value=s[1]+'_editanunt2';
if (s[1]=='hoteluripensiuni'){d='';}else{d='none';}document.getElementById('tara').style.display=d;
if (s[1]=='produsedevanzare'){oz=true;}else{oz=false;}
if(ziare.indexOf(','+document.getElementById('judet').value+',')==-1){zj=false;}else{zj=true;}
//if(!zj){oz=false;}document.getElementById('apare_oz').disabled=!oz;document.getElementById('apare_o').disabled=!oz;
t=ta[parseInt(document.getElementById('zile').value)/7];
//if(!oz){if(zj){oz=true}else{oz=false};document.getElementById('apare_oz').checked=oz;document.getElementById('apare_o').checked=!oz;}
//if(document.getElementById('apare_o').checked){t=0}
if(gra){t=0;}
document.getElementById('tarif').innerHTML=(t+' &euro;').replace(/\./,',');
}

function limch(e,max){
e.value=e.value.replace(/\n/g,' ');e.value=e.value.replace(/  /g,' ');
if (e.value.length>max){e.value=e.value.substring(0,max);}
document.getElementById(e.name+'_rem').innerHTML=max-e.value.length+' caractere rămase';
}

function chpret(){
p=parseInt(document.getElementById('pret').value);EURRON=parseFloat(document.getElementById('EURRON').value.replace(/,/,'.'));
document.getElementById('pretlei').value=Math.round(p*EURRON);
}

function wrn(){
document.write('<p><a href="ajutor.asp?id=4" style="color:AA0000;font-weight:bold;"><img src="img/wrn.gif" style="float:left;padding-right:10;"> ATENTIE! Nu plătiți în avans...</a></p>');
}

function addCSSRule(selector, attributes){
var ss = document.styleSheets[document.styleSheets.length-1];
if(ss.insertRule) ss.insertRule(selector + '{' + attributes + '}', ss.cssRules.length);
else if(ss.addRule) ss.addRule(selector, attributes);
}

function fixIE(){
if (navigator.userAgent.indexOf("MSIE")!=-1){
 addCSSRule('.mapsjc','width:300;height:170;');
 addCSSRule('.azb','top:78;');addCSSRule('.azs','top:78;');addCSSRule('.ayb','top:178;');addCSSRule('.ays','top:178;');
 };
}
fixIE();

//ajax

var qsParam;
function qs(s){
qsParam = new Array();;
var query = s;var parms = query.split('&');
for (var i=0; i<parms.length; i++){var pos = parms[i].indexOf('=');if (pos > 0) {var key = parms[i].substring(0,pos);var val = parms[i].substring(pos+1);qsParam[key] = val;}}
} 

function enc(s){
s=s.replace(/ă/g,"%E3");
s=s.replace(/â/g,"%E2");
s=s.replace(/î/g,"%EE");
s=s.replace(/ș/g,"%BA");
s=s.replace(/ț/g,"%FE");
s=s.replace(/Ă/g,"%C3");
s=s.replace(/Â/g,"%C");
s=s.replace(/Î/g,"%CE");
s=s.replace(/Ș/g,"%AA");
s=s.replace(/Ț/g,"%DE");
s=s.replace(/ \& /g,' %26 ');
s=s.replace(/ /g,'+');
return s;
}

function ajf(m,s){var xmlHttp;try{xmlHttp=new XMLHttpRequest();}catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){return false;}}}
xmlHttp.onreadystatechange=function(){if(xmlHttp.readyState==4){procajf(m,s,xmlHttp.responseText);}}
xmlHttp.open("POST","ajf.asp",true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-2");
s=enc(s);
xmlHttp.send('m='+m+'&'+s);
}
function procajf(m,s,r){
qs(s);
switch(m){
 case 'anoi':{anoi_fin(r);break}
 case 'maploc':{document.getElementById('maploc').innerHTML=r;break}
 case 'mapcat':{document.getElementById('maploc').innerHTML=r;break}
 case 'nnhelp':{document.getElementById('helptxt_'+qsParam['t']).innerHTML=r;document.getElementById('helpbox_'+qsParam['t']).style.display='';break}
 case 'localitati':{document.getElementById('form_'+qsParam['n']).innerHTML=r;break}
 default: {break}
  }
}
