ie=document.all?1:0;

function bookmark() {
 url='http://www.culturism.ro';
 title='Culturism.ro - Antrenorul tau personal';

 if (document.all) window.external.AddFavorite(url,title);
  else alert ('Apasa CTRL+D pentru a adauga acest site la Bookmarks');
}

function selectall (form,val) { 
 for (i=0; i<form.elements.length; i++)
  if ((form.elements[i].type=='checkbox')&&(form.elements[i].name!='selall')) form.elements[i].checked=val;
}

function winopen (nm, fx, fy, mdl) {
 sw=screen.width-8; sh=screen.height-55;
 s='no';
 if (fx>sw) { x=0; s='yes'; fx=sw; } else x=Math.round((sw-fx)/2);
 if (fy>sh) { y=0; s='yes'; fy=sh; } else y=Math.round((sh-fy)/2);
 abc=window.open('/_popup.php?mdl='+mdl+'&nm='+nm,'ViewPic','top='+y+',left='+x+',width='+fx+',height='+fy+',scrollbars='+s);
}

function radiovalue(o) {
  v=-1;
  for (i in o) if (o[i].checked) v=o[i].value;
  return v;  
}        


// rating

rateditems=new Array();

function rateset(id,result,startype) {
 for (i=1; i<=5; i++)
  document.getElementById('rate'+id+'_'+i).src='/_skins/cult/pics/'+startype+'_'+((i<=result)?('f'):('e'))+'.gif';
}

function rateover(x,startype) {
 tmp=x.split('_');
 if (!rateditems[tmp[0]])
  rateset(tmp[0],parseInt(tmp[1]),startype);
}

function rateout(x,startype,value) {
 tmp=x.split('_');
 if (!rateditems[tmp[0]])
  rateset(tmp[0],value,startype);
}

function rateclick(x,startype,islogged,module) {
 tmp=x.split('_');
 if (!rateditems[tmp[0]]) {
  if (!islogged) document.getElementById('ratetext'+tmp[0]).innerHTML='Nu poti vota! Trebuie sa te logezi sau <a href="/cont/adduser">sa-ti faci cont</a>.';
   else {
    ajax('/_ajax.php','todo=rate&module='+module+'&id='+tmp[0]+'&vote='+tmp[1]+'&startype='+startype,rateupdate);
   } 
    
 }
}

function rateupdate(r) {
 if (r!='Error') {
  r=r.split('~');
  rateditems[r[0]]=1;
  rateset(r[0],r[1],r[2]);
  document.getElementById('ratetext'+r[0]).innerHTML='Votul tau a fost inregistrat.';
 }
}

// devcode

function insertTag(field,to,tc,ic,l1) {
 if (ic) {
  x=prompt(l1,'');
  if (x)
   insertAtCursor(field,to+x+tc);
 } else insertAtCursor(field,to);
 field.focus();
}

function insertEmoticon(field,x) {
 insertAtCursor(field,x);
 field.focus();
}

function insertAtCursor(field,value) {
 if (document.selection) {
// IE & Opera
  field.focus();
  sel=document.selection.createRange();
  sel.text=value;
 } else
    if (field.selectionStart||field.selectionStart=='0') {
// Mozilla
     var startPos=field.selectionStart;
     var endPos=field.selectionEnd;
     field.value=field.value.substring(0, startPos)+value+field.value.substring(endPos, field.value.length);
    } else
       field.value+=value;
}

// forum

function poll_checkenoughanswers() {
  document.getElementById('pollnoanswers').style.display=(document.getElementById('pollanswers').getElementsByTagName('div').length<4)?('block'):('none');
}

function poll_deleteanswer(o) {
  d=o.parentNode; p=d.parentNode;
  p.removeChild(d);
  poll_checkenoughanswers();
}

function poll_addanswer() {
  newdiv=document.createElement('div');
  newdiv.style.marginBottom='5px';
  newdiv.innerHTML='<input type="text" name="answers[]" class="input_top" maxlength="255" style="width:200px"/> <a href="javascript:;" onclick="poll_deleteanswer(this);"><img src="/_skins/cult/pics/b_delete.gif" style="vertical-align:top; margin-top:5px"></a>';
  document.getElementById('pollanswers').insertBefore(newdiv,document.getElementById('polladd'));
  poll_checkenoughanswers();
}

// poll

function iagetpoll(r) {
 document.getElementById('pollbooth').innerHTML=r;
}

function iavotepoll(r) {
 if (r.match(/^\d+$/))
  ajax ('/_ajax.php','todo=getpoll&idpoll='+r,iagetpoll);
   else
    if (r=='Not logged') 
     document.getElementById('poll').innerHTML='Poti vota in acest sondaj doar daca esti inregistrat.<p class="p7"></p><a href="/cont/adduser">Fa-ti un cont nou</a>, dureaza doua un minut sau daca ai cont deja <a href="/cont/login">intra in contul tau</a>.';
      else alert (r);
}

function votepoll(idpoll,obj) {
 idanswer=radiovalue(obj.poll);
 if (idanswer!='') {
  ajax ('/_ajax.php','todo=votepoll&idpoll='+idpoll+'&idanswer='+idanswer,iavotepoll);
 } else alert ('Alege o optiune!'); 

 return false;
}

function sendemail(o) {
  if (!o.email.value) alert ('Completeaza o adresa de email!');
    else ajax('/_ajax.php','todo=sendmail&email='+o.email.value, sendmailreturn);
  
  return false;
}

function sendmailreturn(r) {
  document.getElementById('nl').innerHTML=r;
}

function unsubscribe(o) {
  if (!o.email.value) alert ('Completeaza o adresa de email!');
    else ajax('/_ajax.php','todo=unsubscribe&email='+o.email.value, unsubscribereturn);
  
  return false;
}

function unsubscribereturn(r) {
  document.getElementById('nlu').innerHTML=r;
}


