// STYLE FORMS

function is_ok(Message, Link)
{
	if (confirm(Message))
	{
		window.location.href = Link
		return true
	}
	else
	{
		return false
	}
}

function style_forms(el) {

   //button
    el.find(".button").each(function(){
       $(this).wrap('<span class="button_left"><span class="button_right"></span></span>');
       $(this).parents('.button_left').addClass($(this).attr("id"));
       if ( $(this).find('br').length ) $(this).css({'line-height':'0.9','height':'23px','padding-top':'2px'});
		});


	el.find(".button_left").hover(
       function() {
          $(this).css({'background-position':'0 -25px'}).find('.button_right').css({'background-position':'right -25px'}).find('.button').css({'background-position':'0 -25px'});
       },
       function() {
          $(this).css({'background-position':'0 0'}).find('.button_right').css({'background-position':'right 0'}).find('.button').css({'background-position':'0 0'});
       }
    );

    el.find(".button_left").mousedown(function() {
       $(this).css({'background-position':'0 -25px'}).find('.button_right').css({'background-position':'right -25px'}).find('.button').css({'background-position':'0 -25px'});
    });


		// input :text :password
	  el.find("input.inpt").each(function(){
       $(this).wrap('<span class="inpt_left"><span class="inpt_right"></span></span>');
       $(this).parents('.inpt_left').addClass($(this).attr("id"));
		});

    // checkbox
    el.find(".chbox").each(function(){
       $(this).parent('label').addClass('chbox-label');
       $(this).wrap('<span class="checkbox"></span>');
       if ( $(this).attr("checked"))  $(this).parent('.checkbox').css({'background-position':'0 -24px'});
          else   $(this).parent('.checkbox').css({'background-position':'0 0'});
    });

    el.find(".chbox-label").click(function() {
	     if ( $('.checkbox .chbox',this).attr("checked") ) {
         $('.checkbox',this).css({'background-position':'0 0'});
         $('.chbox',this).attr("checked", false);
       }
       else {
        $('.checkbox',this).css({'background-position':'0 -24px'});
        $('.checkbox .chbox',this).attr("checked", true);
       }
	 });

   // radio
    el.find(".radio").each(function(){
       $(this).parent('label').addClass('radio-label');
       $(this).wrap('<span class="radiobox"></span>');
       if ( $(this).attr("checked"))  $(this).parent('.radiobox').css({'background-position':'0 -31px'});
          else   $(this).parent('.radiobox').css({'background-position':'0 0'});
    });

    el.find(".radio-label").click(function() {
         $(this).parents(".radioset").find('.radiobox').css({'background-position':'0 0'});
         $('.radiobox',this).css({'background-position':'0 -31px'});
         $(this).parents(".radioset").find('.radio').attr("checked", false);
         $('.radio',this).attr("checked", true);

	 });

   // select
   el.find(".sel").each(function(){
       $(this).wrap('<span class="sel_left '+$(this).attr("id")+'"><span class="sel_right"></span></span>');
       $(this).before('<span class="sel_val"></span><ul></ul>');
       $(this).parent().find('.sel_val').html($(this).find(":selected").text());
       $(this).find("option:gt(0)").each(function(){
          $(this).parent().prev('ul').append('<li>'+$(this).html()+'</li>');
	   	 });
   });


   el.find(".sel_left").click(function() {
      $(this).find('ul').toggle();
   });
   el.find(".sel_left").mouseleave(function() {
      $(this).find('ul').hide();
   });
   el.find(".sel_left li").click(function() {
      $(this).parent().parent().find('.sel_val').html( $(this).html());
      var num = $(this).index()+1;
      $(this).parent().next('select').find('option').attr('selected','');
      $(this).parent().next('select').find('option').eq(num).attr('selected','selected');
      $(this).parent().find('li').removeClass('cur');
      $(this).addClass('cur');
      var listitem = $("#add_catalog li").index(this)+1;
      $('#catalog_img').removeAttr('class').addClass("folder_"+listitem);
   });

   el.find(".sel").focus(function() {
      $(this).prev('ul').show();
   });


   var i=20;
   el.find(".sel_left").each(function(){
     $(this).css({'z-index':i});
     i-=1;
	 });

   // input :file
   el.find(".file").each(function(){
     $(this).wrap('<span class="file_inp"></span>');
     $(this).before('<span class="file_left"><span class="file_right"><span class="file_val"></span></span></span><span class="file_but">Îáçîð</span>');
	 });

   el.find(".file").change(function(){
      $(this).parent().find('.file_val').html( $(this).val());
	 });

//watermark
   el.find(":text[title!=''], textarea[title!='']").each(function(){
      $(this).wrap('<span class="el_wrap"></span>');
      $(this).before('<label class="watermark">&nbsp;&nbsp;&nbsp;'+$(this).attr('title')+'</label>');
      $(this).attr('title','');
   });
   if ( !($.browser.msie && $.browser.version == 7)) { el.find('.el_wrap').css({'display':'inline-block'})}

   el.find(".el_wrap :text, .el_wrap textarea").focus(function(){
      $(this).prev('.watermark').hide();
   });

   el.find(".watermark").click(function() {
     $(this).hide(0);
     $(this).next('input, textarea').focus();
   });

   el.find(":text, textarea").blur(function() {
     if ($(this).attr('value')=='')  $(this).prev('.watermark').show();
   });

   //popup-window
   el.find(".open_popup").click(function() {
      $(this).parents().find("#popup").animate({left:'230'},1000);
   });

   el.find(".close").click(function(){
      $(this).parents("#popup").animate({left:'-9999'},1000);
      $(':input','#add_catalog')
      .not(':button, :submit, :reset, :hidden')
      .val('')
      .removeAttr('checked')
      .removeAttr('selected');
   });



  }
jQuery(document).ready(function(){

		style_forms($('body'));

});
