﻿// Methods for Kolot Site

document.onkeydown = ExecuteDefaultButton;
function ExecuteDefaultButton(event) {
    if (!event) var event = window.event;
    if (event.keyCode == 13) {
        event.preventDefault ? event.preventDefault() : event.returnValue = false; event.cancel = true;
        if ($getElement('imgBtnSearch')) {
            $getElement('imgBtnSearch').click();
        }
    }
}

function Expand(id) {
    var elm = $getElement(id);
    if (elm != null) {
        elm.style.display = '';
    }
}

function ExpandCollapse(id) {
    var elm = $getElement(id);
    if (elm != null) {
        if (elm.style.display == 'none') elm.style.display = '';
        else if (elm.style.display == '') elm.style.display = 'none';
    }
}

//
//  Directly close the element with the specified id
//
function Collapse(id) {
    var elm = $getElement(id);
    if (elm != null) {
        elm.style.display = 'none';
    }
}


function ChangeHomePageSelectedItem(Param1, nextIndex) {
    var _span = $getElement("spanSelectedItems");
    _span.OnFadeOutComplete = function() {SetInnerHTML("spanSelectedItems",nextText); FadeIn("spanSelectedItems",0)};
    var nextText = Ajax.ExecuteRequest(String.Format("Ajax/ControlLoader.aspx?ctrlName=HomePageSelectedItemst&Param1={0}&param2={1}",Param1,nextIndex), false, null, null);
    if (typeof (NullString) == 'undefined') { return; }
    if( nextText != NullString ){   
      FadeOut("spanSelectedItems",100);
    }
}

//
//  Cross-Browser 'set opacity' 
//
function SetOpacity(obj, opacity) { 
  opacity = (opacity == 100)?99.999:opacity;
  obj.style.zoom = 1;// Stupied hack for IE
  obj.style.filter = "alpha(opacity="+opacity+")";
  obj.style.KHTMLOpacity = opacity/100;
  obj.style.MozOpacity = opacity/100;
  obj.style.opacity = opacity/100;
}

//
//  Fade in an object
//
function FadeIn(objId,opacity) {
    obj = $getElement(objId);
    if (opacity <= 100) {
      SetOpacity(obj, opacity);
      opacity += 8;
      window.setTimeout("FadeIn('"+objId+"',"+opacity+")", 80);
   }
   else {
     obj.style.zoom = '';
     if( obj.OnFadeInComplete ) {
        obj.OnFadeOutComplete();
     }
  }
}

//
//  Fade in an object
//
function FadeOut(objId,opacity) {
    obj = $getElement(objId);
    if (opacity > 0) {
      SetOpacity(obj, opacity);
      opacity -= 8;
      window.setTimeout("FadeOut('"+objId+"',"+opacity+")", 80);
   }
   else {
     obj.style.zoom = '';
     if( obj.OnFadeOutComplete ) {
        obj.OnFadeOutComplete();
     }
  }
}
//
// string.EndsWith implementation
//
String.prototype.EndsWith = function(suffix, ignoreCase) {
    if (!suffix) return false;
    if (suffix.length > this.length) return false;
    if (ignoreCase) {
        if (ignoreCase == true) {
            return (this.substr(this.length - suffix.length).toUpperCase() == suffix.toUpperCase());
        }
    }
    return (this.substr(this.length - suffix.length) === suffix);
}