//
var fpbase = 1000;
if (location.href.indexOf('lamp') != -1) {
    fpbase = 1000;    
}

var currenfontsize = 12;
var m_timer = 1000;
var RemoveSides_done = false;

function RemoveSides() {
    if (RemoveSides_done) return;
    // $('.content_right_fm').remove();
    $('.content_left_fm').remove();
    $('.content_bg_p, .content_bg_line').removeAttr('class');
    $('.content_main_fm').width(717);
    $('.cm_text').width(707);
    $('.cm_text div:eq(0)').removeAttr('style');
    $('.cm_text p:last').append('<a href="http://www.lyrichearing.com" target="_blank" style="font-size:16px;"><b>For more information about Lyric Hearing, please click here.</b></a>');
    RemoveSides_done = true;
}
$(document).ready(function() {

    if ($('.hideright').length > 0) {
        //$('.content_right_fm').hide();
        //$('.content_main_fm').css('width','auto');

        $('.content_right_fm').html($('.hideright').html());
        $('.content_right_fm input[type=text]').css('width', '200px');
        $('.content_right_fm select').css('width', '200px');
        $('.content_main_fm .hideright').hide();
    }

    if ($('.removesides').length > 0) {
        RemoveSides();
    }





    //not leaving site
    $('a').click(function() {
        /*
        if ($(this).attr('href').indexOf('http') != -1) {
        still_in_site('0');
        }
        else {
        still_in_site('1');
        }*/
        still_in_site('1');
    });
    $('form').submit(function() {
        still_in_site('1');
    });
    setTimeout("CheckStill_In_Site_Events()", m_timer);



    $(window).unload(function() {
        LeavingSite();
    });

    //fonts
    $('.lbtnlargerfont').click(function() {
        currenfontsize = parseInt(currenfontsize) + 2;
        if (currenfontsize > 26) currenfontsize = 26;
        SetFontsize(currenfontsize - 2, currenfontsize);
    });

    $('.lbtnsmallerfont').click(function() {
        currenfontsize = parseInt(currenfontsize) - 2;
        if (currenfontsize < 12) currenfontsize = 12;
        SetFontsize(currenfontsize + 2, currenfontsize);
    });


    $('.lbtnnormalfont').click(function() {
        currenfontsize = 12;
        $('body').attr('class', '');
        $.get('/ajax_setfontsize.asp?f=0');
        SyncAreaHeight();
    });

    //lbtntellafriend
    $('.lbtntellafriend').attr('href', '/tell-a-friend/#' + location.href);

    //submitbutton
    $('.submitbutton').click(function() { $(this).parents('form').submit(); });

    try {
        $(".sf-menu").superfish();
    } catch (err) { }



    //landingrequestform
    Load_landingrequestform();


    //autofields
    InitFormFields();

    //
    try {
        InitValidations();
    } catch (err) { }
    //
    setTimeout(playerafter, 46.5 * fpbase);

    //9686

    try {
        $('.main_4').html('<div class="main_4_fm">' + $('.main_4').html() + '</div>');
    }
    catch (err) { }
    var hd_providerid = $('#hd_providerid').val();

    if (hd_providerid || $.cookie('providerid') != '') {
        if (hd_providerid == "0") {
            var ta3 = $('.area_3').html();
            var tm4 = $('.main_4').html();

            if (ta3 && tm4) {
                //$('.area_3').html('<div class="tm4">' + tm4 + '</div>');
                //$('.main_4').html('<div class="ta3">' + ta3 + '</div>');

            }
            //  alert(ta3);
        } else {
            $('.main_3').html('<div class="main_4_outside"><img src="/images/fap-graphic.jpg" alt="99% of Lyric users prefer Lyric over their prior traditional hearing aid" /></div>');
            //$('.main_3').height(80);
            $('.main_4').html('');

            $('.cr_1 .fap_side').parent().remove();
            $('.faptoplink').remove();
        }
    }

    //

    try {
        //$('.area_3').html('<div class="area_3_fm">' + $('.area_3').html() + '</div>');
        $('.slide2').cycle({ timeout: 5000, cleartype: 1 });
    } catch (err) {
    }

    $('.faptoplink').click(function() {
        ShowFAPBox();
        return false;
    });
    $('.txtformItem_4').click(function() {
        ShowFAPBox();
        $('.txtformItem_4').blur();
    });

    $('.txtformItem_4').parents('form').find('input:submit').click(function() {
        ShowFAPBox();

        if ($('.txtformItem_4').val().length == 0) return false;
    });

    $('#aSideFAP').click(function() { SideFAP_click(true) });
    setTimeout("SideFAP_click_false()", 1000);


    try {
        $('#dialog').jqm();
    } catch (err) { }

    //alert(window.name);

    if ($('.fm11011 .more0521').length == 1) {
        var more0521_height = $('.more0521_right').height();

        if ((more0521_height) < $('.more0521_left').height()) {
            more0521_height = $('.more0521_left').height();
        }
        // if (more0521_height < 150) more0521_height = 150;
        $('.more0521_right').height(more0521_height);
        $('.more0521_left').height(more0521_height);
        $('.more0521').height(more0521_height + 40);
    }




});


function galink_click(obj) {
    try {      
        var text = $.trim($(obj).text());
        if (text.length == 0 && $(obj).find('img').length > 0) {
            text = $(obj).find('img').attr('alt');
        }
        var url =unescape( $(obj).attr('href').replace('/go.asp?url=', ''));

        if (url != text) {
            text = url + '(' + text + ')';
        }        
        
        pageTracker._trackPageview(text);

    } catch (err) {alert(err);}
}

function SideFAP_click_false() {
    SideFAP_click(false);
}

function SideFAP_click(fromclick) {
    if (fromclick)
        $('.fap_side').toggle(500, function() { $('.fap_side input').eq(0).focus(); });
    else {
        $('.fap_side').toggle();
    }
}
function ToggleFAPEmail(chked) {
    ToggleFAPEmailMail(chked, '.fapEmail');

}
function ToggleFAPNames(chked) {
    ToggleFAPEmailMail(chked, '.fapNames');
}
function ToggleFAPMail(chked) {
    ToggleFAPEmailMail(chked, '.fapMail');
}
function ToggleFAPEmailMail(chked, id) {
    if (chked) {
        $(id).show();
        $(id + ' input:eq(0)').focus();
    } else {

        $(id + ' input[type="text"]').val('');
        $(id).hide();
    }

    if (chked) {
        $('.fapform ' + id + ' input').removeClass('norequired');
        $('.fapform ' + id + ' input').addClass('required');
    } else {
        $('.fapform ' + id + ' input').removeClass('required');
        $('.fapform ' + id + ' input').addClass('norequired');
    }

    $('.radio').attr('class', 'radio');
}

var ShowFAPBoxed = false;
var ShowFAPBoxing = false;

function ShowFAPBox() {
    still_in_site('1');
    if (ShowFAPBoxing) return;
    ShowFAPBoxing = true;

    //  if (ShowFAPBoxed) return;
    ShowFAPBoxed = true;

    /*
    var t = 0;
    if (document.documentElement && document.documentElement.scrollTop) {
    t = document.documentElement.scrollTop;
    } else if (document.body) {
    t = document.body.scrollTop;
    }

    t = 370-t;
    if(t<0) t=0;
    
    //alert(t);
    $('#dialog').css('top',t+'px');
    //$('#dialog').css('top',t+'px');
    $('#dialog').jqmShow();
    $('.fapform input:text').eq(0).focus();*/



    try {
        window.name = 'lyric';
        //alert(window.name);
        var sw = window.screen.width;
        var sh = window.screen.height;
        var ss = 'dialogLeft:' + parseInt((window.screen.width - 500) / 2 - 100) + '; dialogTop:300;'
        //alert(ss);
        if (document.height) {

            window.showModalDialog('/fap.asp', null, 'dialogWidth:500px; dialogHeight:335px; center:yes; ' + ss);
        } else {
            window.showModalDialog('/fap.asp', null, 'dialogWidth:500px; dialogHeight:370px; center:yes; ' + ss);
        }


    } catch (err) {
    }
    ShowFAPBoxing = false;




}



function CheckStill_In_Site_Events() {
    $('input').focus(function() {
        still_in_site('1');
    });
    m_timer = m_timer * 5;
    setTimeout("CheckStill_In_Site_Events()", m_timer);
}

function still_in_site(val) {
    if ($('#still_in_site').attr('id')) {
        $('#still_in_site').val(val + '');
    }
}


function LeavingSite() {
    //[1:14:47 PM] Jason: can we disable the exit pop-up? there are issues when closing the FaP form for the front page and other inconveniences
    return;

    //leaving site
    if ($('#still_in_site').val() == '0') {
        //window.open("videopop.html","","status,menubar,height=535,width=720");

        try {
            if (document.height) {
                window.showModalDialog('/survey.asp', null, 'dialogWidth:500px; dialogHeight:335px; center:yes');
            } else {
                window.showModalDialog('/survey.asp', null, 'dialogWidth:500px; dialogHeight:370px; center:yes');
            }
        } catch (err) {
        }

    }
}

function Keypress(e) {

    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    if (keycode == 116) {
        still_in_site('1');
    }

}

function SyncAreaHeight() {
    if ($('.area_height').length > 0) {
        $('.area_height').removeAttr('style');
        $('.area_line').removeAttr('style');

        var maxheight = $('.area_height:eq(0)').height();
        for (var i = 1; i < $('.area_height').length; i++) {
            if ($('.area_height').eq(i).height() > maxheight) {
                maxheight = $('.area_height').eq(i).height();
            }
        }
        $('.area_height').height(maxheight);

        $('.area_line').height($('.areas').height());
    }
}
function SetFontsize(psize, csize) {
    currenfontsize = csize;
    $('body').removeClass('fontsize');
    $('body').removeClass('fontsize' + psize);

    $('body').addClass('fontsize');
    $('body').addClass('fontsize' + csize);
    $.get('/ajax_setfontsize.asp?f=' + csize);

    SyncAreaHeight();

}

var hbac_regFileTypes = new RegExp("\s*.(pdf|swf|gif|jpg|jpeg|jpe|xls|ppt|doc|mp3|txt|wav)");
var hbac_regMetaTypes = new RegExp("\s*WT.\s*");
var hbac_linksCallBack = "hbac_internalLink(this);";


function XMLHttpObj() {
    if (window.XMLHttpRequest) {
        obj = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        obj = new ActiveXObject("MSXML2.XMLHTTP");
    }
    return obj;
}



function Load_landingrequestform() {

    if (!$('.landingrequestform').attr('class')) {
        if (!$('#c15_contact_form').attr('id'))
            return;
    }
    if ($('input[name="_NotifySubject"]').length==1) {
        if (!$('input[name="_NotifySubject"]').parents('form').html()) {
            $('input[name="_NotifySubject"]').appendTo($('form[action="/register.asp"]'));

           // alert($('form[action="/register.asp"]').html());
        }
    }
    var email = $.trim($('#emailnotify').val());

    if (email.length == 0) {
        email = $.trim($('input[name="emailnotify"]').val());
    }

    if (email.length == 0) {
        if ($('.landingrequestform').html())
            email = $.trim($('.landingrequestform').html().replace(/&nbsp;/g, ''));
    }
    if (email.length == 0) {
        email = 'kesha@mdnetsolutions.com,Kathy@mdnetsolutions.com';
    }

    email = email.replace(/ /g, ',');

    var url = '/ajax_landingform.asp';
    if ($('.landingrequestform').attr('class') && $('.landingrequestform').attr('class').indexOf('inForm') != -1) {
        url = '/ajax_landingform_inform.asp';
    }

    if ($('.landingrequestform').attr('class')) {
        $('.landingrequestform').load(url, function() {
            $('#txtTargetEmail').val(email);
            CheckHowDidYouHear();
            InitFormFields();
            Init_c15_contact_form();
            $('#chkSendMeFreeDVD').change(SendMeFreeDVD_change);
        });
    } else {
        $('#txtTargetEmail').val(email);
        CheckHowDidYouHear();
        InitFormFields();
        Init_c15_contact_form();
        $('#chkSendMeFreeDVD').change(SendMeFreeDVD_change);
    }


}

function CheckHowDidYouHear() {
    //check how  hear
    if ($('#c15_contact_form').length > 0) {
        if ($('#c15_contact_form #drpHowDidYouHear').length == 0) {
            $('#c15_contact_form input:submit').parents('tr').before('<tr><td align="left"  colspan="2" class="regularText">How did you hear about us? <select name="HowDidYouHearAboutUs" id="drpHowDidYouHear" class="required"><option value="">Please Select...</option><option>Newspaper/Magazine Advertisement</option><option>Mailer</option><option>Seminar</option><option>Friend/Family</option><option>Family Physician</option><option>Audiologist/ENT Physician</option><option>Television Commercial</option><option>Newspaper Article</option><option>Radio</option><option>Online</option><option>Other</option></select></td></tr>');
        }
    }
}


function popupvideo() {
    if (document.height) {
        window.showModalDialog('/videopop.html', null, 'dialogWidth:720px; dialogHeight:535px; center:yes');
    } else {
        window.showModalDialog('/videopop.html', null, 'dialogWidth:730px; dialogHeight:570px; center:yes');
    }
    return false;
    /*
    NewWindow('/videopop.html', 'name', '720', '530', 'no');
    return false*/
}


/*
1) Show video
2) Kelly Slide - 5 minutes
3) SEO Slide 1 (#fp3) - 3 minutes
4) SEO Slide 2 (#fp4) - 30 seconds
5) Kelly Slide - indefinite 
*/


function playerafter() {
    $('.main_1_player').remove();
    $('.curve').fadeOut(2000);
    $('#akelly').show();
    $('#fp3, #fp4').hide();
    $('.main_1_after').fadeIn(2000, function() { });
    setTimeout("afterkelly()", 3 * 60 * fpbase);    
}
function afterkelly() {
    //alert('next');
    $('#akelly, #fp4').hide();
    $('#fp3').show();
    setTimeout("afterslide3()", 3 * 60 * fpbase);
    
}
function afterslide3() {
	//alert('next');
    $('#akelly, #fp3').hide();
    $('#fp4').show();
    setTimeout("afterslide4()", 30 * fpbase);
}

function afterslide4() {
    $('#fp3, #fp4').hide();
    $('#akelly').show();  
}

function fixPng(png) {
    if (!png) return;
    if (!png.src) return;
    // get src
    var src = png.src;
    // set width and height
    if (!png.style.width) { png.style.width = $(png).width(); }
    if (!png.style.height) { png.style.height = $(png).height(); }
    // replace by blank image
    png.onload = function() { };
    png.src = blank.src;
    // set filter (display original image)
    png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}

var send_locationsing = false;
function send_locations(em, _SendMeUpdates, sid, _name, _address, _city, _state, _zip, _fapzip, _EmailMeResults, _MailHardCopy, _Firstname, _Lastname) {
    if (send_locationsing) return;

    em = $.trim(em);
    if (em.length > 0) {
        if (em.indexOf('.') == -1 || em.indexOf('@') == -1) {
            alert(em + ' is invalid.');
            $('#txtlocationsemail').focus();
            return;
        }
    }
    send_locationsing = true;

    $('.locationsemail').html('<ul style="font-family: Arial,Verdana,serif; font-size:12px;  margin:0px; padding:0px; line-height:150%; list-style:none; ">' + $('.ullocations').html() + '</ul>');
    //$('.locationsemail .lbtn_appointment').after('<br />');
    $('.locationsemail .lbtn_appointment').remove();
    $('.locationsemail .cl').remove();
    $('.locationsemail .googlemapcontent').remove();
    $('.locationsemail li').css({ 'margin-bottom': '20px', 'padding': '5px', 'margin-top': '0px' });
    $('.locationsemail a[href]').css({ 'color': '#f57f20' });
    var html = $('.locationsemail').html();

    if (em.length > 0 || _name.length > 0) {
        $.post('ajax_sendlocations.asp', {
            Firstname: _Firstname,
            Lastname: _Lastname,
            email: em,
            EmailMeResults: _EmailMeResults,
            MailHardCopy: _MailHardCopy,
            SendMeUpdates: _SendMeUpdates,
            sessionid: sid,
            locations: html,
            name: _name,
            address: _address,
            city: _city,
            state: _state,
            zip: _zip,
            fapzip: _fapzip
        }, function(data) {
            if (em.length > 0) {
                if (data == "1") {
                    $('.plsendlocations_side').html('An email was sent to ' + em + '.');
                    $('.plsendlocations_side2').html('An email was sent to ' + em + '.');
                } else {
                    $('.plsendlocations_side').html('Failed to send an email to ' + em + '.');
                    $('.plsendlocations_side2').html('Failed to send an email to ' + em + '.');
                }
            }
            send_locationsing = false;
        });
    } else {
        send_locationsing = false;
    }
}


function initialize() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 15);
        map.setUIToDefault();

        geocoder = new GClientGeocoder();
    }
}

function showAddress(address) {
    if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
              if (!point) {
                  alert(address + " not found");
              } else {
                  map.setCenter(point, 13);
                  var marker = new GMarker(point, { icon: xIcon });
                  map.addOverlay(marker);
                  marker.openInfoWindowHtml(address);
              }
          }
        );
    }
}


function showmap_old(obj, url) {
    $('.ullocations li').not($(obj).parent()).css('background', 'none');
    $(obj).parent().css('background', '#f7f7f7');

    var t = 0;
    if (document.documentElement && document.documentElement.scrollTop) {
        t = document.documentElement.scrollTop;
    } else if (document.body) {
        t = document.body.scrollTop;
    }

    //content_right_fm min-height
    if ($('.content_right_fm').attr('class')) {
        if ($('.content_right_fm').height() < 200) {
            $('.content_right_fm').height(200);
        }
    }
    $('.googleiframe').css('top', (t + 160) + 'px');
    $('.googleiframe').show();
    //   showAddress(url);


    $('.googleiframe').html('<iframe width="300" height="350" frameborder="0" scrolling="no" marginheight="0" name="googlemap" id="googlemap" marginwidth="0" src="' + url + '"></iframe>');

}


function showmap(obj, url) {
    still_in_site('1');

    var parent = $(obj).parent();

    $('.ullocations li').not(parent).css('background', 'none');
    parent.css('background', '#f7f7f7');


    var id = parent.attr('id');
    id = id.substr(id.indexOf('_') + 1);

    $('.ullocations li .googlemapcontent').hide();

    if (!parent.find('.googlemapcontent').attr('class')) {
        parent.append('<div class="googlemapcontent"><iframe width="508" height="420" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="' + url + '"></iframe></div>');
    }
    parent.find('.googlemapcontent').show();
    var loc = location.href;
    if (loc.indexOf('#') != -1) {
        loc = loc.substr(0, loc.indexOf('#'));
    }
    location.href = loc + '#l' + id;
}


function lbtn_appointment_click(obj) {
    still_in_site('1');

    var parent = $(obj).parent().parent();
    var id = parent.attr('id');
    id = id.substr(id.indexOf('_') + 1);

    $('.ullocations li .fap_appointment_form').hide();

    if (!parent.find('.fap_appointment_form').attr('class')) {

        var cp = parent.clone();
        cp.find('.fap_appointment_form').remove();
        cp.find('.lbtn_appointment').remove();
        cp.find('.googlemaplink').remove();
        cp.find('a').eq(0).remove();
        var pro = cp.html();

        pro = $('.location_appointment_fm').html().replace('[LocationID]', id).replace('[Provider]', pro);
        //alert(pro);
        parent.find('.lbtn_appointment').after(pro);
    }
    parent.find('.fap_appointment_form').show();
    parent.find('.fap_appointment_form').attr('id', 'fap_appointment_form' + id);
    fap_appointment_form_validate(id);
    //alert(id);
    parent.find('.fap_appointment_form input:text').eq(0).focus();
}

function sort_locations() {

    var arr = new Array($('.ullocations li').length);


    $('.ullocations li').each(function(i) {
        arr[i] = new loc(parseFloat($(this).attr('title')), $(this).html(), $(this).attr('id'), $(this).find('.cl').html());
    });
    //   arr.sort(loc_sort);
    //arr.sort(loc_sort);
    arr.sort(loc_sort);
    var h10 = false;
    var h20 = false;
    var h99 = false;



    var html = '';
    for (var i = 0; i < arr.length; i++) {

        if (!h10 && arr[i].dis <= 10) {
            html += '<li style="margin:0"><h1 style="font-size:18px; line-height: 22px; margin:0px; padding:0px">Providers within 0 - 10 miles</h1><hr /><\/li>';
            h10 = true;
        }


        if (!h20 && arr[i].dis > 10 && arr[i].dis <= 20) {
            html += '<li  style="margin:0"><h1 style="font-size:18px; line-height: 22px; margin:0px; padding:0px">Providers within 10 - 20 miles</h1><hr /><\/li>';
            h20 = true;
        }


        if (!h99 && arr[i].dis > 20) {
            html += '<li  style="margin:0"><h1 style="font-size:18px; line-height: 22px; margin:0px; padding:0px">Providers within 20 - ' + $('.fap_miles').html() + '  miles</h1><hr /><\/li>';
            h99 = true;
        }

        html += '<li id="' + arr[i].id + '">' + arr[i].html + '<\/li>';
    }
    $('.ullocations').html(html);

    //lbtn_appointment
    //$('.lbtn_appointment input').click(function() { lbtn_appointment_click(this) });

    //galink
    $('.galink').click(function () { galink_click(this); });
}

function loc(dis, html, id, cl) {
    this.dis = dis;
    this.html = html;
    this.id = id;
    this.cl = cl;


    //alert(html+cl)
}
function GetK(cl) {
    var k = 1;
    switch (cl) {
        case 'P':
            k = 1; break;
        case 'S':
            k = 2; break;
        case 'NP':
            k = 4; break;
        default:
            k = 8; break;
    }
    return k;
}

function loc_sort(a, b) {
    //alert((a.dis > b.dis) + ' ' + a.dis + '>' + b.dis);
    // if ((a.dis <= 10 && b.dis <= 10) || (a.dis > 10 && b.dis > 10 && a.dis <= 20 && b.dis <= 20) || (a.dis > 20 && b.dis > 20)) {
    if ((a.dis <= 10 && b.dis <= 10) || (a.dis > 10 && b.dis > 10 && a.dis <= 20 && b.dis <= 20)) {

        if (a.id == 'location_37' || b.id == 'location_37') {


            //   alert(a.dis+'-'+a.cl+'-'+ (GetK(a.cl) + a.dis/10000.0) +'-'+b.dis+'-'+b.cl+'-'+(GetK(b.cl)+ b.dis/10000.0));
        }
        return ((GetK(a.cl) + a.dis / 10000.0) - (GetK(b.cl) + b.dis / 10000.0));
    }


    return (a.dis - b.dis);
}



function SendMeFreeDVD_change() {
    if ($('#chkSendMeFreeDVD').attr('checked')) {
        $('#txtStreet').removeClass('norequired');
        $('#txtCity').removeClass('norequired');
        $('#txtState').removeClass('norequired');


        $('#txtStreet').addClass('required');
        $('#txtCity').addClass('required');
        $('#txtState').addClass('required');
    } else {
        $('#txtStreet').removeClass('required');
        $('#txtCity').removeClass('required');
        $('#txtState').removeClass('required');


        $('#txtStreet').addClass('norequired');
        $('#txtCity').addClass('norequired');
        $('#txtState').addClass('norequired');
    }


}


function InitFormFields() {
    if ($('.autofields').html()) {
        if (!$('.autofields input[name=_fieldOrder]').attr('type')) {
            var fields = ',';
            //alert($('.autofields :input').length);
            $('.autofields :input').each(function(i) {
                var fname = $('.autofields :input').eq(i).attr('name');
                if (fname) {
                    if (fname.substr(0, 1) != '_' && fields.indexOf(',' + fname + ',') == -1 && (',form_redirect,submit,submitbutton,FORM_ID,NEXT_PAGE,').indexOf(',' + fname + ',') == -1) {
                        fields = fields + fname + ',';
                    }
                }
            });
            fields = fields.substr(1);
            if (fields.substr(fields.length - 1) == ',') {
                fields = fields.substr(0, fields.length - 1);
            }

            $('.autofields').append('<input type="hidden" name="_fieldOrder" value="' + fields + '" /> ');
        }
    }
}
var msgs = '';
var alerthanlder = null;

function AlertOnce() {
    if (msgs.length > 0) {
        alert(msgs.split('|||')[0]);
        msgs = '';
        alerthanlder = null;
    }
}

function Msg(msg) {
    msgs += msg + '|||';
    if (!alerthanlder) {
        alerthanlder = setTimeout(AlertOnce, 200);
    }
}

function Init_c15_contact_form() {
    var c15_contact_form = $("#c15_contact_form").validate({
        rules: {
            Firstname: "required",
            Lastname: "required",
            Phone: "required",
            Street: {
                required: function() { return ($('#chkSendMeFreeDVD').attr('checked') == true); }
            },
            City: {
                required: function() { return ($('#chkSendMeFreeDVD').attr('checked') == true); }
            },
            State: {
                required: function() { return ($('#chkSendMeFreeDVD').attr('checked') == true); }
            },


            Zip: "required",
            Email: { required: true, email: true },
            LikeToBeContacted: "required"
            //  SendMeUpdates: "required"
        }
    });
}
function InitValidations() {
    var questionForm = $('#questionForm').validate({
        rules: {
            Q1: "required",
            Q2: "required",
            Q3: "required",
            Q4: "required",
            Q5: "required",
            Q6: "required",
            Q7: "required",
            Q8: "required",
            Q9: "required",
            Q10: "required"
        },
        messages: {
            Q1: '<script type="text/javascript">Msg("Please answer all the questions.")</script>',
            Q2: '<script type="text/javascript">Msg("Please answer all the questions.")</script>',
            Q3: '<script type="text/javascript">Msg("Please answer all the questions.")</script>',
            Q4: '<script type="text/javascript">Msg("Please answer all the questions.")</script>',
            Q5: '<script type="text/javascript">Msg("Please answer all the questions.")</script>',
            Q6: '<script type="text/javascript">Msg("Please answer all the questions.")</script>',
            Q7: '<script type="text/javascript">Msg("Please answer all the questions.")</script>',
            Q8: '<script type="text/javascript">Msg("Please answer all the questions.")</script>',
            Q9: '<script type="text/javascript">Msg("Please answer all the questions.")</script>',
            Q10: '<script type="text/javascript">Msg("Please answer all the questions.")</script>'

        }

    });

    var checklistform = $('#checklistform').validate({
        rules: {
            Invisibility: "required",
            Ease: "required",
            Maintenance: "required",
            Mostsituations: "required",
            Water: "required",
            Scubasky: "required"
        },
        messages: {
            Invisibility: '<script type="text/javascript">Msg("Please let us know how important invisibility is to you")</script>',
            Ease: '<script type="text/javascript">Msg("Please let us know how important ease of use is to you")</script>',
            Maintenance: '<script type="text/javascript">Msg("Please let us know how important maintenance is to you")</script>',
            Mostsituations: '<script type="text/javascript">Msg("Please let us know how important the ablity to wear in most situations is to you")</script>',
            Water: '<script type="text/javascript">Msg("Please let us know how often you do water activities")</script>',
            Scubasky: '<script type="text/javascript">Msg("Please let us know if you sky dive")</script>'
        }
    });



    Init_c15_contact_form();

    $('#chkSendMeFreeDVD').change(SendMeFreeDVD_change);
    var frmCustomForm = $("#frmCustomForm").validate({
        rules: {
            Firstname: "required",
            Lastname: "required",
            Street: {
                required: function() { return ($('#chkSendMeFreeDVD').attr('checked') == true); }
            },
            City: {
                required: function() { return ($('#chkSendMeFreeDVD').attr('checked') == true); }
            },
            State: {
                required: function() { return ($('#chkSendMeFreeDVD').attr('checked') == true); }
            },
            Zip: "required",
            Email: { required: true, email: true }
        }
    });


    //frmCustomForm
    var frmCustomForm = $("#frmCustomForm").validate({
        rules: {
            Firstname: "required",
            Lastname: "required",
            Country: "required",
            Email: { required: true, email: true }
        }
    });


    //frmForward
    if ($('#txtURL').attr('type')) {
        var url = location.href;
        if (url.indexOf('#') != -1) {
            url = url.substr(url.indexOf('#') + 1);
            $('#txtURL').val(url);
        } else {
            $('#txtURL').val('http://www.lyrichearing.com/');
        }
    }
    var frmForward = $("#frmForward").validate({
        rules: {
            ToEmail: "required",
            FromEmail: { required: true, email: true }
        }
    });


    //fmMyLyric
    $('#drpHowHear').change(function() {
        if ($('#drpHowHear').val() == 'Other') {
            $('#txtOther').addClass('required');
        } else {
            $('#txtOther').removeClass('required');
        }
    })
    var fmMyLyric = $("#fmMyLyric").validate({
        rules: {
            Firstname: "required",
            Lastname: "required",
            Email: { required: true, email: true },
            Phone: { required: true, digits: true },
            Street: "required",
            City: "required",
            State: "required",
            Zip: "required",
            PreviousHearing: "required",
            Office: "required",
            SendMeUpdates: "required",
            AcceptPrivacy: "required",
            Other: {
                required: function() { return $('#drpHowHear').val() == 'Other'; }
            }

        }
    });

    //stories

    $('#tdImg1').html('<iframe src="/inc/saveimage.asp?id=txtImg1" height="30" width="470" frameborder="0" scrolling="no"></iframe>');
    $('#tdImg2').html('<iframe src="/inc/saveimage.asp?id=txtImg2" height="30" width="470" frameborder="0" scrolling="no"></iframe>');
    $('#tdImg3').html('<iframe src="/inc/saveimage.asp?id=txtImg3" height="30" width="470" frameborder="0" scrolling="no"></iframe>');
    $('#txtImg1').css({ 'border': '0px' }); $('#txtImg1').attr("readonly", "readonly");
    $('#txtImg2').css({ 'border': '0px' }); $('#txtImg2').attr("readonly", "readonly");
    $('#txtImg3').css({ 'border': '0px' }); $('#txtImg3').attr("readonly", "readonly");

    var fmTellUsYourStory = $("#fmTellUsYourStory").validate({
        rules: {
            Firstname: "required",
            Lastname: "required",
            Email: { required: true, email: true },
            Phone: "required",
            Zip: "required",
            HowLongWearing: "required",
            AgreePrivacy: "required",
            AgreeRules: "required"
        }
    });

    var fmSweepstakesEntry = $("#fmSweepstakesEntry").validate({
        rules: {
            Firstname: "required",
            Lastname: "required",
            Email: { required: true, email: true },
            Phone: "required",
            Zip: "required",
            HowDidYouHearAbout: "required",
            AgreePrivacy: "required",
            AgreeRules: "required",
            SendMeUpdates: "required"
        }
    });

    //landing0521

    var landing0521 = $("#landing0521").validate({
        rules: {
            Firstname: "required",
            Lastname: "required",
            Email: { required: true, email: true },
            Phone: "required",
            Street: "required",
            City: "required",
            State: "required",
            Zip: "required"

        },
        messages: {
            Firstname: "*",
            Lastname: "*",
            Email: { required: "*", email: "@" },
            Phone: "*",
            Street: "*",
            City: "*",
            State: "*",
            Zip: "*"
        }
    });


    //fapform
    $('.fapform').validate();



    //fap_contact_form
    $('.fap_contact_form').validate({
        messages: {
            Email: { required: "*", email: "invalid" }
        }
    });

    $('.validate').validate();



}

function fap_appointment_form_validate(id) {
    //fap_appointment_form
    // $('#fap_appointment_form' + id+' input').
    $('#fap_appointment_form' + id).validate(
        {
            messages: {
                Email: { required: "*", email: "invalid" }
            }
        }
    );

    // alert($('#fap_appointment_form' + id).html());
}




function SwitchFLV0(flv, obj) {
    $('.plplayer').show();
    if (flv.indexOf('/') == -1)
        flv = '/ufiles/File/flv/' + flv;
    thisMovie("flvplayer").playVideo(flv);
}
function removetitle() {
    document.title = document.title.replace(/#player/g, '');
}

function flvEvent(msg) {
    flvLastStatus = msg;
    if (msg == '6.stopped' && flvAutoNext && flvFiles.length > 0) FLVNext();
}
function SwitchFLV_Event(path, obj) {
    flvAutoNext = false;
    SwitchFLVMain(path, obj, '/flvplayer-320x240-fl8.swf');
}
function FLVNext() {
    flvLastStatus = '';
    SwitchFLVMain(flvFiles[flvCurrentPos % flvFiles.length], null, '/flvplayer-320x240-fl8.swf');
    flvCurrentPos++;
}

function SwitchFLVMain(flv, obj, swf) {
    $('.plplayer').show();
    if (flv.indexOf('/') == -1)
        flv = '/ufiles/File/flv/' + flv;
    var html = '<embed height="100%" align="middle" width="100%" type="application/x-shockwave-flash" salign="" allowscriptaccess="sameDomain" allowfullscreen="true" menu="true" name="flvplayer" id="flvplayer" bgcolor="#ffffff" devicefont="false" wmode="transparent" scale="showall" loop="true" play="true" pluginspage="http://www.macromedia.com/go/getflashplayer" quality="high" src="' + swf + '" flashvars="flvPath=' + flv + '&amp;flvTitle=&amp;autoPlay=true&amp;autoBuffer=true"></embed>   <br />';
    //  html = '<embed height="100%" flashvars="flvPath=' + flv + '" align="middle" width="100%" src="/flvplayer-320x240.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" play="true" loop="true" scale="showall" wmode="transparent" devicefont="false" bgcolor="#ffffff" name="flvplayer" menu="true" allowfullscreen="true" allowscriptaccess="sameDomain" salign="" type="application/x-shockwave-flash"></embed>';
    $('.plplayer').html(html);
    removetitle();
    setTimeout(removetitle, 1);
    setTimeout(removetitle, 50);
    setTimeout(removetitle, 100);
    setTimeout(removetitle, 300);
    setTimeout(removetitle, 3000);
}
function SwitchFLV(flv, obj) {
    SwitchFLVMain(flv, obj, '/flvplayer-320x240.swf');
}



function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}


//fixpng
var blank = new Image();
blank.src = '/images/1.gif';
$(document).ready(function() {
    var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
    if (badBrowser) {

        $('.png').each(function() {
            if (!this.complete) {
                this.onload = function() { fixPng(this) };
            } else {
                fixPng(this);
            }
        });
    }
});