var closeframe = 0;
function formaddtitle(el){
  if (""==jQuery(el).val())
   jQuery("<label id='lb-"+jQuery(el).attr('name')+"' class='lb-title' style='margin-left: -"+(jQuery(el).width()+5)+"px'>"+jQuery(el).attr('title')+"</label>").insertAfter(el);
}
function formaddtitle2(el){
  if (""==jQuery(el).val())
   jQuery("<label id='lb-"+jQuery(el).attr('name')+"' class='lb-title' style='left: "+(jQuery(el).offset().left-jQuery(el).width())+"px; top: "+(jQuery(el).offset().top-94)+"px'>"+jQuery(el).attr('title')+"</label>").insertAfter(el);
}
function sendForm(url){
  jQuery('.frm form').css('display','none');
  jQuery('#thanks').css('display','block');
  var buff = []; 
  jQuery('.frm input').each(function (i, el){
    if (jQuery(el).attr('type') == 'text')
      buff.push(jQuery(el).attr('name')+'"="'+jQuery(el).attr('value'));
    if (jQuery(el).attr('type') == 'checkbox')
      if (jQuery(el).attr('checked'))
        buff.push(jQuery(el).attr('name')+'"="'+jQuery(el).attr('value'));
  });
  jQuery('.frm select').each(function (i, el){
    buff.push(jQuery(el).attr('name')+'"="'+jQuery(el).attr('value'));
  });
  jQuery('.frm').append(jQuery('<iframe style="border: none" width="10" height="10" id="formframe" src="/wp-content/themes/accountant purposes/iform.php?action='+url+'&'+buff.join('&')+'">').load(function(){ if (closeframe<1) ++closeframe; else jQuery(this).remove();}));
}
jQuery(document).ready(function() {
  if (jQuery('.frm').length) {
    if (jQuery('.frm input[type=text]')[0]['placeholder']===''){
      jQuery('.frm input[type=text]').each(function(i, e){ jQuery(e).attr('placeholder',jQuery(e).attr('title'));});
    } else {
      jQuery('.frm input[type=text]').each(function(i,e){formaddtitle2(e);});
      jQuery('.frm input[type=text]').live('focusin',function(){ jQuery("#lb-"+jQuery(this).attr('name')).remove(); });
      jQuery('.frm input[type=text]').live('focusout',function(){ formaddtitle2(this); });
      jQuery('.lb-title').live("click", function(){jQuery(this).prev().focus(); jQuery(this).remove();});
    }
  }
  if (!jQuery('.form-tag').length) return;
  jQuery('.form-tag input[type=text],.form-tag input[type=checkbox],.form-tag input[type=radio], .form-tag textarea').uniform();
  if (jQuery('.form-tag input[type=text]')[0]['placeholder']===''){
    jQuery('.form-tag input[type=text]').each(function(i, e){ jQuery(e).attr('placeholder',jQuery(e).attr('title'));});
  } else {
    jQuery('.form-tag input[type=text]').each(function(i,e){formaddtitle(e);});
    jQuery('.form-tag input[type=text]').live('focusin',function(){ while (jQuery(this).next()[0] && jQuery(this).next()[0].tagName=="LABEL") jQuery(this).next().remove(); });
    jQuery('.form-tag input[type=text]').live('focusout',function(){ formaddtitle(this); });
    jQuery('.lb-title').live("click", function(){
      while (jQuery(this).prev()[0] && jQuery(this).prev()[0].tagName=="LABEL") jQuery(this).prev().remove();
      jQuery(this).prev().focus();
      while (jQuery(this).next()[0] && jQuery(this).next()[0].tagName=="LABEL") jQuery(this).next().remove();
      jQuery(this).remove();
    });
  }
  jQuery('.form-tag').validate();
});
