﻿String.prototype.ReplaceAll = function(s1, s2) {

    if (this.indexOf(s1) > -1) {
        return this.split(s1).join(s2);
    }
    else {
        return this;
    }
}

////////////////////////////////////////////////////////////
// Function returns HTTP request object for all browsers.
function getHttpRequestObj() {
    var xmlhttp;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}





///////////////////////////////////////////////////
// Contact Submit Function
function SubmitContact() 
{
    var ContactValObj = document.getElementById("ContactVal");
    ContactValObj.value = "dsklwyh2893wrr34t3456";
    return(true);
}



///////////////////////////////////////////////////
// CMsS Edit Link Functions
function ShowAdminEdit() 
{

    document.getElementById("AdminEditLinkspan").innerHTML = '<a onclick="HideAdminEdit();">Hide CMS Edit</a>';
    $('.CmsEditLink').show();

}

function HideAdminEdit()
{
    document.getElementById("AdminEditLinkspan").innerHTML = '<a onclick="ShowAdminEdit();">Show CMS Edit</a>';
    $('.CmsEditLink').hide();
}



function ShowMoreNews(CategoryId) 
{
    var PlusDiv = document.getElementById("PlusDiv" + CategoryId);
    $('#HiddenNews' + CategoryId).show(1000);
    PlusDiv.innerHTML = '<img title="Hide" onclick="HideMoreNews(' + CategoryId + ')" src="/images/NewsMinus.jpg" />';
}

function HideMoreNews(CategoryId) {
    var PlusDiv = document.getElementById("PlusDiv" + CategoryId);
    $('#HiddenNews' + CategoryId).hide(1000);
    PlusDiv.innerHTML = '<img title="Show More" onclick="ShowMoreNews(' + CategoryId + ')" src="/images/NewsPlus.jpg" />';
}


function ScrollToPageAnchor(Anchor) 
{
    try 
    {
       // $("html,body").animate({ scrollTop: 0 }, 0); 
        Anchor = Anchor.ReplaceAll(" ", "-");
        Anchor = Anchor.ReplaceAll(".", "-");
        var offset = $('#' + Anchor).position().top;
        
        $('html,body').animate({
            scrollTop: offset - 40
        }, 1);   
    }
    catch(e){}
}




jQuery.fn.zoom = function(fn) 
{
  jQuery(document).keyup(function(e){
    switch (true) {
      case jQuery.browser.mozilla || jQuery.browser.msie :
        if (e.ctrlKey && (
          e.which == 187 ||
          e.which == 189 ||
          e.which == 107 ||
          e.which == 109 ||
          e.which == 96  ||
          e.which == 48
        )) fn();
        break;
      case jQuery.browser.opera :
        if (
          e.which == 43 ||
          e.which == 45 ||
          e.which == 42 ||
          (e.ctrlKey && e.which == 48)
        ) fn();
        break;
      case jQuery.browser.safari :
        if (e.metaKey && (
          e.charCode == 43 ||
          e.charCode == 45
        )) fn();
        break;
    }
    return;
  });

  jQuery(document).bind('mousewheel', function(e){
    if (e.ctrlKey) fn();
  });

  jQuery(document).bind('DOMMouseScroll', function(e){
    if (e.ctrlKey) fn();
  });
};



