function init_forms()
{
   $.ajaxSetup
   ({  
      cache: false  
   }); 

   $(document).ready(function(){
      // Add styling to INPUT TEXT except RECAPTCHA
      $("input[type=text]").not("#recaptcha_response_field").after("<div class=cap></div>");
      $("input[type=text]").addClass("container");
      $("input[type=text]").each(function(){
         $(this).css("width",$(this).width()-16);
      })

      // Add styling to INPUT PASSWORD
      $("input[type=password]").after("<div class=cap></div>");
      $("input[type=password]").addClass("container");

/*
      // Add styling to INPUT FILE
      $("input[type=file]").addClass("file");
      $("input[type=file]").wrap("<div class=file_inputs></div>");
      $("input[type=file]").change(function(){
         $("#sel_file").html("Selected file: <b>"+$(this).val() + "</b>");
      });
*/

      // Add styling to TEXTAREA
      $("textarea").after("<div class=cap_textarea></div>");
      $("textarea").addClass("container");

      // Add styling to SELECT
      $("select").each(function(){
         var u = navigator.userAgent.toLowerCase();

         // Create dummy image to maintain SELECT width and height in diff browsers
         // If Mac FF
         if ((u.indexOf('mac') != -1) && (u.indexOf('firefox') != -1))
         {
            $(this).parent().prepend("<div><img src=http://miiamo.mcandrewkaps.com/images/pixel.gif width="+($(this).width()+29)+" height="+($(this).height()+7)+"></div>");
         }
         // If PC Safari
         else if ((u.indexOf('windows') != -1) && (u.indexOf('chrome') == -1) && (u.indexOf('safari') != -1))
         {
            $(this).parent().prepend("<div><img src=http://miiamo.mcandrewkaps.com/images/pixel.gif width="+($(this).width()+25)+" height="+$(this).height()+"></div>");
         }
         // If Mac Safari
         else if ((u.indexOf('mac') != -1) && (u.indexOf('chrome') == -1) && (u.indexOf('safari') != -1))
         {
            $(this).parent().prepend("<div><img src=http://miiamo.mcandrewkaps.com/images/pixel.gif width="+$(this).width()+" height="+($(this).height()+6)+"></div>");
         }
         else
         {
            $(this).parent().prepend("<div><img src=http://miiamo.mcandrewkaps.com/images/pixel.gif width="+($(this).width()+2)+" height="+($(this).height()+4)+"></div>");
         }

         $(this).parent().prepend("<div class=select_replace></div>");
         $(this).parent().find(".select_replace").prepend("<div class=cur>"+$(this).find(":selected").text()+"</div>");

         // Adjust stylesheet appropriately for consistent width in diff browsers
         if ((u.indexOf('mac') != -1) && (u.indexOf('firefox')!=-1))
         {
            $(this).parent().find(".select_replace .cur").css("width",$(this).width()-1);
         }
         else if ((u.indexOf('windows') != -1) && (u.indexOf('chrome') == -1) && (u.indexOf('safari') != -1))
         {
            $(this).parent().find(".select_replace .cur").css("width",$(this).width()-3);
         }
         else if ((u.indexOf('mac') != -1) && (u.indexOf('chrome') == -1) && (u.indexOf('safari') != -1))
         {
            $(this).parent().find(".select_replace .cur").css("width",$(this).width()-28);
         }
         else if (u.indexOf('msie 6') != -1)
         {
            $(this).parent().find(".select_replace .cur").css("width",$(this).width()-24);
         }
         else
         {
            $(this).parent().find(".select_replace .cur").css("width",$(this).width()-26);
         }

         $(this).parent().find(".select_replace").append("<div class=cap_select></div>");
         $(this).parent().find(".select_replace").append("<ul></ul>");

         var list = $(this).find("option").map(function(){
            var rep = $("<li>").text($(this).text()).get();
            return rep;
         })

         $(this).parent().find("ul").append(list);

         // Adjust the UL width according to the SELECT width and UL padding
         var padding_val = parseInt($(this).parent().find("ul").css("padding-left"))+parseInt($(this).parent().find("ul").css("padding-right"));

         if ((u.indexOf('mac') != -1) && (u.indexOf('firefox')!=-1))
         {
            $(this).parent().find("ul").css("width",$(this).width()+25-padding_val);
         }
         else if ((u.indexOf('windows') != -1) && (u.indexOf('chrome') == -1) && (u.indexOf('safari') != -1))
         {
            $(this).parent().find("ul").css("width",$(this).width()+23-padding_val);
         }
         else if ((u.indexOf('mac') != -1) && (u.indexOf('chrome') == -1) && (u.indexOf('safari') != -1))
         {
            $(this).parent().find("ul").css("width",$(this).width()-2-padding_val);
         }
         else if (u.indexOf('msie 6') != -1)
         {
            $(this).parent().find("ul").css("width",$(this).width()+2-padding_val);
         }
         else
         {
            $(this).parent().find("ul").css("width",$(this).width()-padding_val);
         }
      })

      // Expand drop downs on click and contract others
      $(".select_replace").click(function(){
         $(this).find("ul").slideToggle("fast");
         $(".select_replace ul").not($(this).find("ul")).hide();
         $(this).css("zIndex","101");
      })

      // Display selected item and update corresponding option
      $(".select_replace ul li").click(function(){
         $(this).parent().parent().find(".cur").text($(this).text());
         $(this).parent().parent().parent().find("select option[text="+$(this).text()+"]").attr("selected","selected");

         // Check if SELECT is a jump
         if ($(this).parent().parent().parent().find("select").hasClass("jump"))
         {
            self.location = $(this).parent().parent().parent().find("select option:selected").val();
         }
      })

      $(".select_replace ul li:first-child").css("border","none");
      $(".select_replace ul li:last-child").css("border","none");

      // Jump to selected item for browsers that do not display the replacement SELECT
      $("select").find("jump").change(function(){
         self.location = $(this).find("option:selected").val();
      })

      // Contract pull down when click outside
      $("body").click(function(){
         $(".select_replace ul").hide();
      })

      $(".select_replace").click(function(e){
          e.stopPropagation();
      })

      // Init calendars
      $(".cal_btn").click(function(e){
         remove_cal();
         $(this).parent().append("<div class=cal></div>");
         $.get("f_get-cal.php", {}, function(data){
            $(".cal").html(data).fadeIn("fast");
         })
      })

      $(".cal_btn").siblings("input").click(function(e){
         remove_cal();
//         $(this).val("");
         $(this).parent().append("<div class=cal></div>");
         $.get("f_get-cal.php", {}, function(data){
            $(".cal").html(data).fadeIn("fast");
         })
      })

      $(".arw").live("click",function(e){
         e.preventDefault();
         $.get("f_get-cal.php", {d: $(this).attr("id")}, function(data){
            $(".cal").html(data).fadeIn("fast");
         })
      })

      $(".date a").live('click',function(e){
         e.preventDefault();
         $(".cal").siblings("input").val($(this).attr("id"));
         remove_cal();
      })

      $(".cls").live('click',function(e){
         e.preventDefault();
         remove_cal();
      })

      $(document).click(function(e){
         if (!$(e.target).parents().hasClass("cal") && !$(e.target).hasClass("cal_btn") && !$(e.target).siblings().hasClass("cal_btn")) remove_cal();
      })

      function remove_cal()
      {
         $(".cal").fadeOut("fast",function(){
            $(this).remove();
         })
      }
   })
}
