var debugMode = false;

function onHomeProductsMouseEnter()
{
  var sClass = $(this).attr("class");
  if(sClass.indexOf("active") >= 0) return;
  
  sClass = sClass.split(" ")[0];
  $("div.products td.active").mouseleave();
  $("div.products td."+sClass).addClass("active");
  $("div.products td."+sClass+" .extended").slideDown("fast");
}
function onHomeProductsMouseLeave()
{
  var sClass = $(this).attr("class");
  if(sClass.indexOf("active") < 0) return;
  
  sClass = sClass.split(" ")[0];
  $("div.products td."+sClass+".bottom").removeClass("active");
  $("div.products td."+sClass+" .extended").slideUp("fast",function(){
    $("div.products td."+sClass).removeClass("active");
  });
}
function initHomeProducts() {
  $("div.products td").mouseenter(onHomeProductsMouseEnter);
  $("div.products td:not(.bottom)").mouseleave(onHomeProductsMouseLeave);
  var tipsModule = new cRotating();
  tipsModule.idContainer = ".banners";
  tipsModule.idItems = ".banner";
  tipsModule.controls = ".menu";
  tipsModule.timer = 5000;
  tipsModule.init();
}

function initProductsLanding() {
  var nHeight = 0;
  $(".brand .brandContent").each(function(){
    if(parseInt($(this).height()) > nHeight) nHeight = parseInt($(this).height());
  });
  if(nHeight > 0) $(".brand .brandContent").height(nHeight);
    
  $(".brand").mouseenter(function() {
    $(".brand").removeClass("brandOver");
    $(this).addClass("brandOver");
    $(".spotlight").removeClass("selected");
    $(".experiences.selected").removeClass("selected");
    $("#"+$(this).attr("id")+"-exp").addClass("selected");
  });
  $(".brand").click(function() {
  });
  $(".brand").mouseleave(function() {
    //$(this).removeClass("brandOver");
  });  
    
  $(".products").mouseleave(function() {
     $(".experiences.selected").removeClass("selected");
      $(".brand").removeClass("brandOver");
     $(".spotlight").addClass("selected");
     //console.log("mouseout")
    });  
}

function initAbout() {
}
function initDownloads() {
  //initRemainingCharacters(".form");
}
function onFAQTopicsChange(){
  if(this.selectedIndex > 0)
  {
    var goTo = this.value;
    $(this).jqSelectedIndex(0);
    $.scrollTo(goTo,300);
  }
}
function initAboutFAQs() {
  var obj = $(".faqs .topics .combobox select")[0];
  obj.onchange = onFAQTopicsChange;
  initExpandableModules(".faqs");
//  alert(obj.onchange);
  $(".faqs .topics").jqTransform({imgPath:'../images/controls/'});
}
function initCatalogQFind()
{
  //$(".scroll-pane").jScrollPane();
  $(document).ready(function(){
    
    $(".result .categories").jqTransform({imgPath:'../images/controls/'});
    initSearch(".find .item")
  });    
}
function initResourcesLanding()
{
  $(document).ready(function(){
    initSearch(".find .item");
    initSearch(".search .item");
    var tipsModule = new cRotating();
    tipsModule.idContainer = "#FAQsModule";
    tipsModule.idItems = ".tip";
    tipsModule.controls = "pager";
    tipsModule.init();
    
  });  

  $(".faq .visibleArea .tip").each(function(){
    var ph = $(this).parents(".visibleArea:first").height();
    var h = $(this).height();
    $(this).css("margin-top",(ph-h)/2);
  });
}


/** Solution Bundles **/
var bundleId = ".bundle";

function setOverBundleHotspot(objBundle,nItem,bActive)
{
  var hotSpot = null;
  if(!bActive)
  {
    var objThumbnail = $(objBundle).find(".thumbnail");
    $(objThumbnail).show()
    $(objThumbnail).attr("rel",nItem);
    
    $(".thumb img",$(objThumbnail)).hide();
    $($(".thumb img",$(objThumbnail)).get(nItem)).show();
    
    hotSpot = $(".hotspots a",$(objBundle)).get(nItem);
    $(objThumbnail).css("top",$(hotSpot).css("top"));
    $(objThumbnail).css("left",$(hotSpot).css("left"));
    objThumbnail = null;
    
    $(".menu ol li",$(objBundle)).removeClass("hover");
  }
    
  hotSpot = $(".menu ol li",$(objBundle)).get(nItem);
  $(hotSpot).addClass("hover");
  hotSpot = null;
  objBundle = null;
}

function overBundleHotspot()
{
  var nItem = $(this).index();
  var objBundle = $(this).parents(bundleId);
  setOverBundleHotspot(objBundle,nItem,$(".detail",$(objBundle)).hasClass("active"));
}
function outBundleMenuItem()
{
  var objBundle = $(this).parents(bundleId);
  if($(".detail",$(objBundle)).hasClass("active") && !$(this).hasClass("active"))
  {
    $(this).removeClass("hover");
    objItem = null;
  }
  objBundle = null;
}
function hideBundleThumbnail()
{
  var objBundle = $(this).parents(bundleId);
  $(".thumbnail",$(objBundle)).attr("rel","");
  $(this).parents(".thumbnail").hide();
  $(".thumb img",$(this).parents(".thumbnail")).hide();
  $(".menu ol li",$(objBundle)).removeClass("hover");
  objBundle = null;
}
function showBundleDescriptionItem(objBundle,nItem)
{
  var objDetail = $(".detail",$(objBundle));
  $(".item",$(objDetail)).hide();
  var objItem = $(".item",$(objDetail)).get(nItem);
  $(objItem).show();
  objDetail = null;
  objItem = null;
  objBundle = null;
}
function showBundleDescription()
{
  var objBundle = $(this).parents(bundleId);
  var nItem = $(this).parents(".menu").length > 0?$(this).index():parseInt($(".thumbnail",$(objBundle)).attr("rel"));
  $(".menu ol li.active",$(objBundle)).removeClass("active");
  var objDetail = $(".menu ol li",$(objBundle)).get(nItem);
  $(objDetail).addClass("active");
  objDetail = $(".detail",$(objBundle));
  if(!$(objDetail).hasClass("active"))
  {
    $(objDetail).addClass("active");
    $(".bundles .bar").hide();
    $(objDetail).fadeIn("fast",function(){showBundleDescriptionItem(objBundle,nItem); objBundle = null;});
  }
  else
  {
    setOverBundleHotspot(objBundle,nItem,false);
    showBundleDescriptionItem(objBundle,nItem);
    objBundle = null;
  }
  objDetail = null;
}
function hideBundleDescription(){
  var objBundle = $(this).parents(bundleId);
  var objDetail = $(".detail",$(objBundle));
  $(".item",$(objDetail)).hide();
  $(".menu ol li",$(objBundle)).removeClass("active");
  $(objDetail).fadeOut("fast",function(){$(this).removeClass("active");});
  objDetail = null;
  $(".bundles .bar").show();
}
function initSolutionBundles()
{  
  initTabModule();
  
  $('.solutions '+bundleId).each(function(){
    $(".detail .item .leftCol",$(this)).each(function(){
      var bundlesItems = new cRotating();
        bundlesItems.idContainer = $(this);
        bundlesItems.idItems = ".media";
        bundlesItems.controls = "title";
        bundlesItems.init();
    });
      
    $(".thumb img",$(this)).hide();
    $(".thumbnail .hit",$(this)).mouseleave(hideBundleThumbnail);
    
    var aHotspots = $(".menu li a",$(this));
    var sHotspots = "";
    var sPos;
    for(var i= 0; i < aHotspots.length; i++)
    {
      sPos = $(aHotspots[i]).attr("rel");
      sPos = sPos.split(",");
      if(sPos.length > 1)
      {
        sHotspots += "<a style='top:"+sPos[1]+"px;left:"+sPos[0]+"px;' rel='"+i+"'>" + (i+1) + "</a>";
      }
    }
    $(".hotspots",$(this)).append(sHotspots);
    
    $(".menu li",$(this)).mouseenter(overBundleHotspot);
    $(".menu li",$(this)).mouseleave(outBundleMenuItem);
    $(".hotspots a",$(this)).mouseenter(overBundleHotspot);
    //$(".hotspots a",$(this)).mouseleave(hideBundleThumbnail);
    
    $(".thumbnail",$(this)).click(showBundleDescription);
    $(".menu li",$(this)).click(showBundleDescription);
    
    $(".detail .close",$(this)).click(hideBundleDescription);
    $(".detail .item",$(this)).hide();
    $(".detail",$(this)).hide();
    $(".thumbnail",$(this)).hide();
    $(".detail",$(this)).css("visibility","visible");
    $(".map",$(this)).css("visibility","visible");
  });
  
  var nStart = -1;
  $('.solutions .bar .jcarousel-skin-bundle li').each(function(){if(nStart < 0 && $("a.active", $(this)).length > 0) nStart = $(this).index()});
  jQuery('#bundlecarousel').jcarousel({start:nStart+1});
  $(".solutions .bar").css("visibility","visible");

  $(".solutions .bundle").css("visibility","visible");
}
/** End Solutions Bundle **/

function initCatalogCategory()
{
  initExpandableModules(".category");
}
function initCatalogDetail()
{
  initExpandableModules(".detail .Tab.Overview");
  $(".left .section").jqTransform({imgPath:'../images/controls/'});
  $(".left .sectionRadio").jqTransform({imgPath:'../images/controls/'});
  $(".TabModule .TabControl a").each(function(){
    var sTab = $(this).attr("rel");
    var rotatingHero = new cRotating();
    rotatingHero.idContainer = "."+sTab+" .rotatingHero";
    rotatingHero.sequenceControls = false;
    rotatingHero.init();
  });
  
  initTabModule();
}
function initProductMarketingOverview()
{
//  initExpandableModules(".detail");
  initTabModule();
  
  $(".marketing .language").jqTransform({imgPath:'../images/controls/'});
}
function onCheckGroupChange(event,group,items)
{
  if(items != null)
  {
    var sLabel = "";
    if(items.length == 1)
    {
      sLabel = items[0];
    }
    else if(items.length > 1)
    {
      sLabel = "(Multiple)";
    }
    if(sLabel.length > 12) sLabel = sLabel.substr(0, 10)+"...";
    $(group).parents(".dropdownModule").find(".label").html(sLabel);
  }
  event.stopPropagation();
}
function setCheckGroupLabel(sel)
{
  if(sel == null) sel = "";
  $(sel+" .checkgroup").bind('change',onCheckGroupChange);
}
function initSearchResults()
{
  initSearch(".find");
  $(".searchresults .combobox").jqTransform({imgPath:'../images/controls/'});
  //$(".searchresults .filter .fields").hide();
  $(".searchresults .filter .fields").css("visibility","visible");
  $(".searchresults .filter .fields").css("height","auto");
  $(".searchresults .filter .fields").css("overflow","visible");
  setCheckGroupLabel(".searchresults .filter .content");
  initCheckBoxGroup(".searchresults .filter .content");
  
  
  initDropDownModule(".searchresults");
  //initExpandableModules(".searchresults");
}
function initCaregivers()
{
  var rotatingHero = new cRotating();
  rotatingHero.idContainer = ".Testimonial";
  rotatingHero.sequenceControls = true;
  rotatingHero.nWidthControls = null;
  rotatingHero.timer = 13000; //[DS] 21-09-2011
  rotatingHero.init();

  initTabModule();
}

function initAJAXSearchPage()
{
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(AJAXSearchPageLoaded);    
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(AJAXSearchPageBeginRequest);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
}

function initAJAXCatalogQuickFind()
{
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(AJAXCatalogQuickFindPageLoaded);    
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(AJAXSearchPageBeginRequest);
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
}

function AJAXCatalogQuickFindPageLoaded(sender, args)
{
    initCatalogQFind();
    $('.scroll-pane').jScrollPane({scrollbarWidth: 22,animateTo:true, animateInterval:50, animateStep:5,arrowSize:15,showArrows:true, dragMinHeight:20 });
    initRequiredFields();
}

function AJAXSearchPageBeginRequest(sender, args)
{
  window.status = "Searching...";
  document.body.style.cursor = "wait";
}
    
function AJAXSearchPageLoaded(sender, args)
{
    initSearchResults();    
    setSearchResultCounts();
    initRequiredFields();
}  


function endRequest(sender, args)
{
   window.status = "Done";
   document.body.style.cursor = "default";
   
   var topPagingElement = $(".paging:visible").filter(".onTop:first");
   if (topPagingElement.length > 0)
   {
  var offset = topPagingElement.offset();
  window.scrollTo(offset.left, offset.top);
   }
    
   if (args.get_error() != undefined) //error occurred
   {
       var errorMessage = "An error occurred communicating with the server. Please try again.";
       
       if(debugMode)
       {
            errorMessage = args.get_error().message;        
             alert(errorMessage);
       }
            
        args.set_errorHandled(true);
    }
}


function setSearchResultCounts()
{
    var resourcesResultCount = $('#resourcesResultsCount');
    var continuingEdResultCount = $('#continuingEdResultsCount');
    var productsResultCount = $('#productsResultsCount');
    var siteSearchResultCount = $('#siteSearchResultsCount');
     
    if(resourcesResultCount != null)
      resourcesResultCount.text('(' + $('#txtResourcesSearchResultsCount').val() + ')');  
    if(continuingEdResultCount != null)
      continuingEdResultCount.text('(' + $('#txtContinuingEdSearchResultsCount').val() + ')');
    if(productsResultCount != null)
      productsResultCount.text('(' + $('#txtProductSearchResultsCount').val() + ')');  
    if(siteSearchResultCount != null)
      siteSearchResultCount.text('(' + $('#txtSiteSearchResultsCount').val() + ')');
}  



/** Forms Functions **/
function disableForm(val){
    $("form input[type=submit]").attr('disabled', ((val == null) ? true : false));
}

/** Check Key down **/
function checkKey(reg, e){
    var nKey = e.which;
    var sKey = String.fromCharCode(nKey);
    if (nKey == 0 || nKey == 8 || nKey == 13)
        return true;
    
    var re = new RegExp(reg);
    return (sKey.match(re) == null);
}


function initSearch(sel)
{
  $(sel+' input[type=text]').keypress(function(e){
    if(e.which == 13)
    {
      $(this).parents(".item").find('input[type=button]').click();
    e.stopPropagation();
      return false;
    }
    /*return checkKey(/\D/,e);*/
    return true;
  });
  $(sel).not(".initialized").each(function(){
    if($(this).find(".defaultValue").length > 0)
    {
      $('input[type=text]',$(this)).focus(function(){
        var textDefault = $(this).parents(".item").find(".defaultValue").html();
        if($(this).val() == textDefault || $(this).hasClass("required_error")){
          $(this).val("");
          $(this).removeClass("required_error");
        }
        $(this).select();
      });
      $('input[type=text]',$(this)).blur(function() {
        var textDefault = $(this).parents(".item").find(".defaultValue").html();
        if ($(this).val() == '') {
          $(this).val(textDefault);
        }
      });
      $('input[type=text]',$(this)).each(function(){
        if($(this).val() == "")
          $(this).val($(this).parents(".item").find(".defaultValue").html());
      });
    }
    else $('input[type=text]',$(this)).val("");
    $(this).addClass("initialized");
  });
  
}

function initExpandableModules(sel,vel)
{
  if(sel == null) sel = "";
  if(vel == null) vel = "fast";
  $(sel+" .expandableModule").not(".initialized").each(function(){
    $(".handler:first",$(this)).mouseenter(function(){$(this).toggleClass("hover")}).mouseleave(function(){$(this).toggleClass("hover")});
  if($(".content",$(this)).length > 0)
  {
    $(".handler:first",$(this)).click(function(){
      $(this).parents(".expandableModule").addClass("animating");
      $(this).siblings(".content").slideToggle(vel,function(){
      $(this).parents(".expandableModule").toggleClass("open");
      $(this).parents(".expandableModule").removeClass("animating");
      });
    });
    $(".handler:first a",$(this)).click(function(ev){ev.stopPropagation();});
  }
  else
  {
    $(".handler:first *",$(this)).andSelf().not("a").click(function(ev){
      var hand = $(this).parents(".handler:first");
      if(hand.length == 0) hand = $(this);
      var sHref = $("a:first",$(hand)).attr("href");
      if(sHref != null && sHref != "")
      {
        document.location = sHref;
        //$("a:first",$(hand)).click();
        //alert(sHref);
      }
    });
    $(".handler:first a",$(this)).andSelf().click(function(ev){ev.stopPropagation();});
  }
    $(this).addClass("initialized");
  });
  $(sel+" .collapseAll").click(function(){
    $(sel+" .expandableModule.open:not(.animating) .handler:first, "+sel+" .expandableModule.animating:not(.open) .handler:first").click();
  });
  $(sel+" .expandAll").click(function(){
    $(sel+" .expandableModule:not(.open):not(.animating) .handler:first, "+sel+" .expandableModule.open.animating .handler:first").click();
  });
}
function initDropDownModule(sel,vel)
{
  if(sel == null) sel = "";
  if(vel == null) vel = "fast";
  $(sel+" .dropdownModule").not(".initialized").each(function(){
    $(".handler:first",$(this)).mouseenter(function(){$(this).toggleClass("hover")}).mouseleave(function(){$(this).toggleClass("hover")});
    $(".handler:first",$(this)).click(function(){
      if($(this).parents(".dropdownModule").hasClass("animating")) return;
      $('body').unbind("click");
      $(this).parents(".dropdownModule").addClass("animating");
      $(sel+" .dropdownModule.open:not(.animating) .handler:first").click(); //Close Others
      $(this).siblings(".content").slideToggle(vel,function(){
        $(this).parents(".dropdownModule").toggleClass("open");
        $(this).parents(".dropdownModule").removeClass("animating");
        if($(this).parents(".dropdownModule").hasClass("open"))
        {
          //Add body event to close on click outside
          $('body').bind("click",function() { $(sel+" .dropdownModule.open .handler:first").click(); });
        }
      });
    });
    $(".content:first",$(this)).hide();
    $(".content:first",$(this)).css("visibility","visible");
    $(this).addClass("initialized");
  });
  $(sel+" .dropdownModule").click(function(event){event.stopPropagation();});
}
function triggerCheckGroupChange(checkGroup)
{
  var items = new Array();
  var nOptions = $(":not(.all) input:checkbox",$(checkGroup)).length;
  var nChecked = $(":not(.all) input:checkbox:checked",$(checkGroup)).length;
  if(nOptions == nChecked) items.push("All");
  else $(":not(.all) input:checkbox:checked",$(checkGroup)).each(function(){items.push($(this).siblings("label").html());});
  $(checkGroup).trigger('change', [checkGroup, items]);
}
function checkGroupState(checkGroup)
{
  var nOptions = $(":not(.all) input:checkbox",$(checkGroup)).length;
  var nChecked = $(":not(.all) input:checkbox:checked",$(checkGroup)).length;
  if(nOptions == nChecked) $(".all input:checkbox:not(:checked)",$(checkGroup)).attr('checked','checked');
  else $(".all input:checkbox:checked",$(checkGroup)).removeAttr('checked');
  triggerCheckGroupChange(checkGroup);
}
function initCheckBoxGroup(sel)
{
  if(sel == null) sel = "";
  $(sel+" .checkgroup").not(".initialized").each(function(){
    checkGroupState($(this));
    $(":not(.all) input:checkbox",$(this)).click(function(){checkGroupState($(this).parents(".checkgroup:first"));});
    $(".all input:checkbox",$(this)).click(function(){
      var checkGroup = $(this).parents(".checkgroup:first");
      if($(this).is(":checked"))
      {
        $(":not(.all) input:checkbox:not(:checked)",$(checkGroup)).attr('checked','checked');
      }
      else
      {
        $(":not(.all) input:checkbox:checked",$(checkGroup)).removeAttr('checked');
      }
      triggerCheckGroupChange(checkGroup);
    });
    $(this).addClass("initialized");
  });
}
function activateTabModule()
{
  var sTab = $(this).attr("rel");
  if(sTab != null && sTab != "")
  {
    $(this).parents(".TabModule").find(".breadcrumb,.TabControl").find("a.active").removeClass("active");
    $(this).parents(".TabModule").find(".Tab.active").fadeOut("fast",function(){
      $(this).removeClass("active");
      $(this).parents(".TabModule").find(".breadcrumb,.TabControl").find("a[rel="+sTab+"]").addClass("active");
      $(this).parents(".TabModule").find(".Tab."+sTab).fadeIn("fast",function(){$(this).addClass("active");});
    });
  }
}
function initTabModule(sel)
{
  if(sel == null) sel = "";
  $(sel+" .TabModule").each(function(){
    $(".TabControl a",$(this)).click(activateTabModule);
    $(".breadcrumb a",$(this)).click(activateTabModule);
    $(".bar #openResourceTab", $(this)).click(activateTabModule);
    $(".Tab:not(.active)",$(this)).hide();
  });
}
function initRemainingCharacters(sel)
{
  if(sel == null) sel = "";
  $(sel+" .remainingCharacters").each(function(){
    $(".textarea",$(this)).keyup(function(){
      var sVal = $(this).val();
      $(this).parents(".remainingCharacters").find(".counter").html(sVal.length);
    });
  });
}


/**Show-Hide print Box**/
function iniBoxPrint(){
  
  $(".printLeftBox").mouseenter(function () {$('body').unbind("click");});
  $(".printLeftBox").mouseleave(function () {$('body').bind("click",function() { $(".printBtn").click(); });});
  $(".printBtn").click(function () {    
     $('body').unbind("click");
     $(".printLeftBox").toggle();  
     $(".printLeftBox").toggleClass("openPrint");
     if($(".printLeftBox").hasClass("openPrint")){
       $('body').bind("click",function() { $(".printBtn").click(); });
     }
     return false;
    });  
  
}


$(document).ready(function(){    
  //Autostart textoverflow
  if($(this).textOverflow != null)
  {
    $(".textOverflow").each(function(){
//    $(".textOverflow.to_debug").each(function(){
      var config = new Object();
      var sClass = $(this).attr("class");
      var param = parseInt(getStringParam(sClass, "to_lines_"));
      if(param == null) param = 1;
      config.lines = param;
      param = getStringParam(sClass, "to_fill_");
      if(param != null) config.ellipsis = param;
      param = getStringParam(sClass, "to_link_");
      if(param != null) config.link = param;
      $(this).textOverflow(config);
      $(this).css("visibility","visible");
    });
  }
  
  /** Email Validation Field **/
    $(".email").keypress(function(e){
        return checkKey(/[^\w.@_-]/, e);
    });
  /** Name Validation Field **/
/*    $(".name_field").keypress(function(e){
        return checkKey(/[^a-zA-Z\s'.-]/, e);
    });*/
  initSearch(".searchBox .item");
  
  $("#header .region").jqTransform({imgPath:'../images/controls/'});
  
  if($(this).jScrollPane != null)
    $('.scroll-pane').each(function(){$(this).jScrollPane({scrollbarWidth: 22,animateTo:true, animateInterval:50, animateStep:5,arrowSize:15,showArrows:true, dragMinHeight:20 });});
    
});
function getStringParam(str, param)
{
  if(str.indexOf(param) >= 0)
  {
    var auxs = str.substring(str.indexOf(param)+param.length);
    if(auxs.indexOf(' ') > 0) auxs = auxs.substring(0, auxs.indexOf(' '));
    return auxs;
  }
  return null;
}

function submitKeywordSearch(inputName, url)
{
  //alert(url + $('[name=' + inputName + ']').val())
  window.location = url + $('[name=' + inputName + ']').val();
    return false;
}

var sRequiredError = "Keyword Required";
function onCheckRequiredFields(obj)
{
  if(obj == null) obj = this;
  var bCheck = true;
  $(obj).parents(".requiredFields:first").find("input[type=text]").each(function(){
    var sValue = "";
    if($(this).parents(".item").find(".defaultValue").length > 0)
    {
      sValue = $(this).parents(".item").find(".defaultValue").html();
    }
    if($(this).hasClass("required_error") || $(this).val() == sValue)
    {
      $(this).addClass("required_error");
      $(this).val(sRequiredError);
      bCheck = false;
    }
  });
  
  return bCheck;
}
function initRequiredFields(sel)
{
  if(sel == null) sel = "";
  $(sel+" .requiredFields").find("input[type='button'],input[type='submit']").each(function(){

    var clickhandler = this.onclick;
    this.onclick = null;

    // new click handler
    $(this).click(function(ev) {
    ev.stopPropagation();

      if(onCheckRequiredFields(this))
      {
        if(clickhandler != null)
        {
         clickhandler()
        }
      }
      return false;
    });
  });
}


$(document).ready(function () {
  if($("a.zoom").fancybox){
    $("a.zoom").fancybox({
          'overlayColor'    : '#FFF',
          'overlayOpacity'  : 0.7
        });
  }
  $("#siteSearch").autocomplete({
    source: function( request, response )
    {
      $.ajax({
        url: "/umbraco/search/AutocompleteHandler.ashx",
        dataType: "json",
        data: {                     
          r_keyword: request.term,
          searchType: 'site',
          currentPageURL: window.location.pathname
        },        
        type: "POST",
        success: function( data )
        {
          response(data);
        }
      });
    },
    minLength: 2,
     open: function(event, ui)
     { $('.ui-autocomplete').css('zIndex', '100000');    }

  });
  initRequiredFields();

  //DD_roundies.addRule('.ui-autocomplete', '4px');  
});
  
