<!--
MM_preloadImages('/Resources/Images/nav_knowledgeCenter_on.gif','/Resources/Images/nav_community_on.gif','/Resources/Images/nav_events_on.gif','/Resources/Images/nav_shopSolutions_on.gif','/Resources/Images/nav_aboutUs_on.gif');


function toggleDetails(ref){
    var descID = document.getElementById('details' + ref);
    if (descID != null)
    {
        if (descID.style.display == 'block'){
            descID.style.display = 'none';
            document.getElementById("btn" + ref).src = 'Resources/Images/btnExpand.gif';
            
        }else{
            descID.style.display = 'block';
            document.getElementById("btn" + ref).src = 'Resources/Images/btnCollapse.gif';
        }
    }
}

function sifrHeadline(ref,divID){
   var so = new SWFObject("Resources/swf/Sifr-Headline.swf", "Sifr-Headline", "492", "33", "7", "#336699");  
   so.addParam("wmode", "transparent");
   so.addVariable("titleText", ref);
   so.write("flashheadline" + divID);
}

function validateContact(){
    var msg = "";

    if (document.getElementById('firstname').value == ""){msg += "-- First Name\n";}
    if (document.getElementById('lastname').value == ""){msg += "-- Last Name\n";}
    
    var e = document.getElementById('email').value; 
    var c = document.getElementById('emailconfirm').value;
    if (e == "")
       {msg += "-- Valid E-mail Address\n";}
    else if (e == c)
       {
         if (ValidateEmail(document.getElementById('email')) == false)
            {msg += "-- Valid E-mail Address\n";}
       }
    else {msg += "-- Please confirm E-mail Address\n";}
      
    if (document.getElementById('comments').value == ""){msg += "-- Comment\n";}

    if (msg != ""){
        alert("The following required field(s) are missing:\n\n" + msg + "\nPlease complete the form and resubmit.");        
    }
    else
    {
        var x = getFormElementsXML("formfield", "contactUs");
        Deluxe.ContactUs.FormSave(x, Process_SubmitForm);    
    }
}

function Process_SubmitForm(res){
    if (res.error && res.error.Message != 'Unknown')
    {
        alert("An error occurred.\nYour inquiry could not be processed.  " + res.error.Message)
    }
    else
    {
        document.location.href="Deluxe_ContactUsConfirmation.aspx";
    }
}

function validateMemberAccount(page){
    var msg = "";

    if (document.getElementById('firstname').value == ""){msg += "-- First Name\n";}
    if (document.getElementById('lastname').value == ""){msg += "-- Last Name\n";}
    if (document.getElementById('title').value == ""){msg += "-- Business Title\n";}
    if (document.getElementById('company').value == ""){msg += "-- Financial Institution\n";}
    if (document.getElementById('address1').value == ""){msg += "-- Business Address\n";}
    if (document.getElementById('city').value == ""){msg += "-- City\n";}
    if (document.getElementById('state').value == ""){msg += "-- State\n";}
    if (document.getElementById('zip').value == ""){msg += "-- Zip Code\n";}
    
    var e = document.getElementById('email').value; 
    var c = document.getElementById('emailconfirm').value;
    if (e == "")
       {msg += "-- Valid E-mail Address\n";}
    else if (e == c)
       {
         if (ValidateEmail(document.getElementById('email')) == false)
            {msg += "-- Valid E-mail Address\n";}
       }
    else {msg += "-- Please confirm E-mail Address\n";}
      
    if (document.getElementById('routing').value == "")
    {
        msg += "-- Business Routing & Transit Number\n";
    }
    else if (!ValidateRoutingNumber(document.getElementById('routing').value))
    {
        msg += '-- ' + document.getElementById('routing').value + " is not a recognized Business Routing & Transit Number. Please check the number you have entered or contact us (knowledge.exchange@deluxe.com) if you are having difficulty.\n";
    }
    
    var e = document.getElementById('password').value; 
    var c = document.getElementById('passwordconfirm').value;
    if (e == ""){msg += "-- Password\n";}
    else if (e != c) {msg += "-- Password Confirm\n";}
    
    var topics = validateCheckboxes('dvTopics');
    if (topics == 'false'){msg += "-- What topics interest you?\n";}
    var refer = document.getElementById('referral').selectedIndex;
    if (document.getElementById('referral')[refer].value == 0){msg += "-- How did you hear about KES?\n";}
    var contact = validateCheckboxes('dvContact');
    if (contact == 'false'){msg += "-- How may we contact you?\n";}

    if (msg != ""){
        alert("The following required field(s) are missing:\n\n" + msg + "\nPlease complete the form and resubmit.");        
    }
    else
    {
        var x = getFormElementsXML("formfield", "signUp");
        if (page == "signup")
        {
            Deluxe.Registration.CreateAccount(x, Process_CreateAccount);  
        }  
        else
        {
            Deluxe.Registration.UpdateAccount(x, Process_UpdateAccount); 
        }
    }
}

function Process_CreateAccount(res){
    if (res.error && res.error.Message != 'Unknown')
    {
        alert("An error occurred.\nYour request could not be processed.  " + res.error.Message);
    }
    else
    {
        var success = $(res.value).find('Results').attr('success');
        if (success == 'true')
        {
            document.location.href="New_Member.aspx";  
        }
        else
        {
            var acctExists = $(res.value).find('Results').attr('acctExists');
            var err = $(res.value).find('ErrorMsg').text(); 
            if (acctExists == 'true') 
            {
                alert("Account already exists for this user."); 
            }
            else 
            {
                alert("An error occurred.\nYour request could not be processed:  " + err);
            }
        }
    }
}

function Process_UpdateAccount(res){
    if (res.error && res.error.Message != 'Unknown')
    {
        alert("An error occurred.\nYour request could not be processed.  " + res.error.Message)
    }
    else
    {
        var success = $(res.value).find('Results').attr('success');
        if (success == 'true')
        {
            location.reload(true);  
        }
        else 
        {
            var acctExists = $(res.value).find('Results').attr('acctExists');
            var err = $(res.value).find('ErrorMsg').text(); 
            if (acctExists == 'false') 
            {
                alert("Current user account not found."); 
            }
            else 
            {
                alert("An error occurred.\nYour request could not be processed.  " + err);
            }
        }
    }
}

function accountPages() 
{
    var signup = location.href.toLowerCase().indexOf("signup.aspx"); 
    var update = location.href.toLowerCase().indexOf("my_profile.aspx"); 
    var new_member = location.href.toLowerCase().indexOf("new_member.aspx"); 
    
    if (signup > 0)
    { 
        var btn = document.getElementById("aSubmitBtn");
        btn.href = "javascript:validateMemberAccount('signup');"; 
    }
    else if (update > 0 || new_member > 0)
    {
        var btn = document.getElementById("aSubmitBtn");
        btn.href = "javascript:validateMemberAccount('profile');"; 
        PopulateMyProfile();  
    }
}

function PopulateMyProfile()
{
    // get field values and populate fields  
    Deluxe.Registration.PopulateMyProfile(Process_PopulateMyProfile);
}  

function Process_PopulateMyProfile(res)
{
    if (res.error && res.error.Message != 'Unknown')
    {
        alert("An error occurred.\nYour request could not be processed.  " + res.error.Message)
    }
    else
    {
        var xml = res.value; 
        if (xml != null) 
        {
           var first    = $(xml).find('FirstName').text();  
           var last     = $(xml).find('LastName').text();  
           var title    = $(xml).find('BusinessTitle').text();   
           var inst     = $(xml).find('FinancialInstitution').text();  
           var add1     = $(xml).find('BusinessAddress1').text();  
           var add2     = $(xml).find('BusinessAddress2').text(); 
           var city     = $(xml).find('BusinessCity').text();  
           var state    = $(xml).find('BusinessState').text();  
           var zip      = $(xml).find('BusinessZip').text(); 
           var email    = $(xml).find('BusinessEmail').text();  
           var phone    = $(xml).find('BusinessPhone').text();  
           var rn       = $(xml).find('RoutingNumber').text(); 
           var pwd      = $(xml).find('Password').text();   
           var ref      = $(xml).find('ReferralMethodText').text(); 
           var contact  = $(xml).find('ContactMethodText').text(); 

           $("#firstname").val(first);
           $("#lastname").val(last);
           $("#title").val(title);
           $("#company").val(inst);
           $("#address1").val(add1);
           $("#address2").val(add2);
           $("#city").val(city);
           $("#state").val(state);
           $("#zip").val(zip);
           $("#email").val(email);
           $("#emailconfirm").val(email);
           $("#phone").val(phone);
           $("#routing").val(rn);
           $("#password").val(pwd);
           $("#passwordconfirm").val(pwd);
           $('#referral').val(ref);
           
           var topics = $(xml).find('Topics').children().size(); 
           
           if (topics > 0)
           {
                $(xml).find('Topic').each( function() {
                    var $topic = $(this);
                    var topicID = $topic.find('ItemID').text(); 
                    
                    if (topicID != null && topicID.length > 0)
                    {
                        var $ele = $('#' + topicID); 
                        if ($ele != null)
                        {
                            // set value to 'checked' 
                            $ele.attr('checked', 'true');
                        }
                    }
                });
           }
           
           if (contact.toLowerCase() == 'email(html)') 
           {
             var $ddl = $('#email_html');
             $ddl.attr('checked', 'true');
           }
           else if (contact.toLowerCase() == 'email(text)') 
           {
             var $ddl = $('#email_text');
             $ddl.attr('checked', 'true');  
           }
           else if (contact.toLowerCase() == 'no email') 
           {
             var $ddl = $('#no_email');
             $ddl.attr('checked', 'true');
           }
        }
    }  
}

function ValidateEmail(obj)
{
    return ValidateEmailString(obj.value);
}

function ValidateEmailString(str)
{
    if (str == "")
        return false;  
        
    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);
    if (str.indexOf(at)==-1){
       return false;
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
       return false;
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        return false;
    }

     if (str.indexOf(at,(lat+1))!=-1){
        return false;
     }

     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        return false;
     }

     if (str.indexOf(dot,(lat+2))==-1){
        return false;
     }

     if (str.indexOf(" ")!=-1){
        return false;
     }

     return true;
}

function ValidateRoutingNumber(rNum)
{
    var retVal = false;
    
    if (rNum == '111111111' || rNum == 'ASSOC123')
        retVal = true;
    else
    {
        if(rNum.length == 8 && rNum != '00000000')
        {
            retVal = /\d{8}/.test(rNum);
        }
    }
    
    return retVal;    
}

function RefreshPage()
{
    window.location.reload();
}

function validateCheckboxes(div)  //  validate checkboxes or radio buttons  
{ 
    var checked = 'false';   
    var chkArray = document.getElementById(div).getElementsByTagName('input');  
    for (var i = 0; i < chkArray.length; i++)   
    {
        if (chkArray[i].type == 'checkbox' || chkArray[i].type == 'radio')  
        {
            if (chkArray[i].checked)  
            {
                checked = 'true';   
            }  
        }   
    }  
    return checked;  
} 

function getFormElementsXML(strAttributeName, strAttributeValue){
    var arrElements = document.body;
    if (!arrElements.all)	
    {
        arrElements = arrElements.getElementsByTagName('*');
    }
    else
    {
       arrElements = arrElements.all;
    }
	
    var arrRetEl = new Array();
    var oAttribVal = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
    var oCurrent;
    var oAttribute;
    var sReturn='';
	
    var aReturn =new Array();
    aReturn.push('<root>');
    
        for(var i=0; i<arrElements.length; i++){
	    oCurrent = arrElements[i];
	    oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
	    
	    if(typeof oAttribute == "string" && oAttribute.length > 0){
		    if(typeof strAttributeValue == "undefined" || (oAttribVal && oAttribVal.test(oAttribute))){
		        if(oCurrent.type=="checkbox" || oCurrent.type=="radio"){
		            aReturn.push('<' + oCurrent.name + ' id=\"' + oCurrent.id + '\"><![CDATA[' + oCurrent.checked + ']]></' + oCurrent.name + '>');
		        }else{
                    aReturn.push('<' + oCurrent.id + '><![CDATA[' + oCurrent.value + ']]></' + oCurrent.id + '>'); 
		        }
		    }
	    }
    }
    aReturn.push('</root>');
    sReturn = aReturn.join('');

    return sReturn;
}

function Modal_Open(ref){
    document.getElementById(ref).style.top = getScrollY();
    document.getElementById(ref).style.display = "block";
    window.onscroll = function () { document.getElementById(ref).style.top = getScrollY(); };
}

function ModalFixed_Open(ref){
    document.getElementById(ref).style.top = getScrollY();
    document.getElementById(ref).style.display = "block";
}

function Modal_Close(ref){
    document.getElementById(ref).style.display = "none";
}

function getScrollY(){
    scrollY = 0;
    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }
    return scrollY + "px";
}

function getScrollFooter(ref){
    scrollY = 0;
    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }
    return (scrollY + document.documentElement.clientHeight - ref);
}

$("p").click(function () {
      $("div").hide("slide", {}, 1000);
});
    
  
var footerToggleTime = 500;
function toggleFooter()
{
    if ($("#footerToggle").attr("src") == "Resources/Images/iconFooterCollapse.gif")
    {
		$('#FooterSlide').animate({marginTop:143}, footerToggleTime, footerAnimationComplete);
        $("#footerToggle").attr("src", "Resources/Images/iconFooterExpand.gif");
    }
    else
    {
		$('#FooterSlide').css("display", "block");
		$('#FooterSlide').animate({marginTop: 0}, footerToggleTime);
        $("#footerToggle").attr("src", "Resources/Images/iconFooterCollapse.gif");
    }
}
function footerAnimationComplete()
{
	$('#FooterSlide').css("display", "none");
}

function showOverlay(ref){
    document.getElementById(ref).style.display = 'block';
}

function hideOverlay(ref){
    document.getElementById(ref).style.display = 'none';
}

function toggleDiv(ref){
    var divID = document.getElementById('div' + ref);
    if (divID != null)
    {
        if (divID.style.display == 'block'){
            divID.style.display = 'none';
            document.getElementById("btn" + ref).src = 'Resources/Images/btnExpand.gif';
            
        }else{
            divID.style.display = 'block';
            document.getElementById("btn" + ref).src = 'Resources/Images/btnCollapse.gif';
        }
    }
}

function toggle(ref){
    if (document.getElementById(ref).style.display == 'none'){
        document.getElementById(ref).style.display = 'block';
    } else {
        document.getElementById(ref).style.display = 'none';
    }
}

function toggleFAQ(ref){
    var cat = $('#category').val();
     
    if (cat == 0)
    { 
        $('.FAQquestion').siblings().css('display', 'none');
        $('#dvFAQContent').children().css('display', 'block'); 
    } 
    else 
    { 
       $('.FAQquestion').siblings().css('display', 'none');
       
       $('#dvFAQContent').children().css('display', 'none');

       $('#dvFAQContent').children('#' + cat).css('display', 'block');
    } 
} 

function LimitLength(tArea, len, charRemainingID)
{
	if(tArea && len > 0){
		if(tArea.value.length > len){
			tArea.value = tArea.value.substring(0,len);
		}
		
		var charRemainingElement = document.getElementById(charRemainingID);
		if(charRemainingElement){
			charRemainingElement.innerHTML = tArea.value.length;
		}
	}
}

function GetQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split('&');
    for (var i=0;i<vars.length;i++) 
    {
        var pair = vars[i].split('=');
        if (pair[0].toLowerCase() == variable.toLowerCase()) 
        {
            return pair[1];
        }
    }
    return "";
}

var addthis_config = {
     //username: "YOUR ADDTHIS USERNAME"
}


function changeHomeLatest(ref){
    for (i=1;i<4;i++){
        var menu = "HomeLatestMenu" + i;
        var copy = "HomeLatestCopy" + i;
        //document.getElementById(menu).setAttribute("class", "HomeLatestMenuOff");
        document.getElementById(menu).style.cssText = 'background-color: #f8f8f8; border-right: solid 1px #e4e4e4;cursor: pointer;';
        document.getElementById(copy).style.display = "none";
        document.getElementById(menu).style.color = "#434343";
    }
    var menuOn = "HomeLatestMenu" + ref;
    var copyOn = "HomeLatestCopy" + ref;
    //document.getElementById(menuOn).setAttribute("class", "HomeLatestMenuOn");
    document.getElementById(menuOn).style.cssText = 'background-color: #ffffff; border-right: solid 1px #ffffff;cursor: pointer;';
    document.getElementById(copyOn).style.display = "block";
    document.getElementById(menuOn).style.color = "#005288";
}


function GetCommunityLeftNav()
{
    Deluxe.Community.GetCommunityLeftNav(Process_GetCommunityLeftNav);
}
function Process_GetCommunityLeftNav(res)
{
    if (res.error && res.error.Message != 'Unknown')
    {
        alert("An error occurred.\nYour request could not be processed.  " + res.error.Message)
    }
    else 
    { 
        var results = res.value;
        var x = $(results).find('LeftNav');
        $('#divLeftColumnLinks').html(x.text());
    }
}

function PageChange(page)
{
    $('.Page').hide();
    $('.Page' + page).show();            
}


function keywordDown(event)
{
    key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (key == 13) 
    {
        ForgotPassword();
        return false;
    }
}


function ForgotPassword()
{
    var email = document.getElementById('txtForgotPwd').value; 
    
    if (email.length > 0)
    {
        if (ValidateEmailString(email))
        {
            Deluxe.Registration.ForgotPassword(email, Process_ForgotMyPassword);
        }
        else
        {
            alert("Please enter a valid email address.");
        }
    }
    else
    {
        alert("Please enter your email address.");
    }
}

function Process_ForgotMyPassword(res)
{
    if (res.error && res.error.Message != 'Unknown')
    {
        alert("An error occurred.\nYour request could not be processed.  " + res.error.Message)
    }
    else
    {
        var success = $(res.value).find('Success').text();
        if (success == 'true')
        {
            $('#dvForgotPwdForm').css('display', 'none'); 
            $('#dvForgotPwdConfirm').css('display', 'block'); 
        }
        else 
        {
            var err = $(res.value).find('Error').text(); 
            if (err == 'UserNotFound') 
            {
                alert("Current user account not found."); 
            }
            else 
            {
                alert("An error occurred.\nYour request could not be processed.  " + err);
            }
        }
    }
}

function queryItem(key) {
    var re = new RegExp("[?&]" + key + "=([^&$]*)", "i");
    var offset = location.search.search(re);
    if (offset == -1) return null;
    return RegExp.$1;
}

function addEventTracking(section, label)
{
    var page = getPageFilename();
    if (label.length > 0)
    {
        page = label + ' - ' + page;
    }

    // Featured box
    $('#FeaturedBoxTitle a').each(function() {
        var title = escape($(this).text());
        title = title.replace(/%20/gi, ' ');
        if ($(this).attr('href') && $(this).attr('href').length > 0 && title.length > 0)
        {
            $(this).click(function() {
                recordOutboundLink(this, section, page, title);
                return false; 
            }); 
        }
    });
    
    // Order Now buttons
    if (page.indexOf('solution') > -1)
    {
        $('.OrderNowButton').each(function() {
            $(this).click(function() {
                recordOutboundLink(this, section, page, 'Order Now Button');
                return false;
            });
        });
    }
}

function trackTwitter(link)
{
    var page = getPageFilename();
    recordOutboundLink(link, 'Footer', page, 'Twitter');
}

function getPageFilename()
{
    var path = window.location.pathname;
    var lastSlash = path.lastIndexOf('/');
    var q = path.indexOf('?');
    if (q == -1) { q = path.length; }
    var file = path.substring(lastSlash + 1, q);
    return file.toLowerCase();
}

function EI_trackLink(category, action, label, outbound)
{
    if(outbound)
    {
       _gat._getTrackerByName()._trackEvent(category, action, label);
       setTimeout('document.location = "' + label + '"', 100);
    }
    else
    {
        _gat._getTrackerByName()._trackEvent(category, action, label);
    }
}

//-->
