/* This file runs on every page, every time they are loaded. Do not remove it, it's a core file. */
/* Init - runs when document is ready. All functions which require the document to be ready should be called from here */
var timer;
$(function () {
    //$(":text").labelify();
    //addFirstAndLastClass("addFirstAndLastClass");
    //initDatePicker();
    createTabs();
    //testIfPageContainsColumns();
    moveClassToElement("#content", "body");
    addClassToInputElements();
    removeLoadingClass("body", "pageLoading");
    $(".topnav_popover").hoverIntent(showPopover, hidePopover);    
    $('.marquee_center').marquee('marquee_center');
    loadtip();
    tipdropCurves();   
    getDynamicPhone();    
    removeClueTipRollover();
    //loadCustomSelectBox();
    
});
function loadCustomSelectBox() {
    $("#ctl00_PageHolder_ContentHolder_Main_ctl00_ControlsList_rptControls_ctl00_ctl00_ddlPet").selectbox();
    $("#ddlBreed").selectbox();    
}
function loadFancybox() {
    $("a[rel=pets]").fancybox({
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titlePosition': 'over',
        'cyclic': false,
        'padding': 5,
        'title': this.description,
        'onComplete': onComplete,
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {

            return '<span id="fancybox-title-over">' + (title.length ? '' + title : '') + '</span>';
        }
    });

}
// CA
// image swap for rollovers 
function SwapImage(id, source) {
    var imgId = document.getElementById(id);
	if (imgId!='undefined'){ imgId.src = source; }
}

function getDynamicPhone() {
    try {
        var wayfair = readCookie('wayfair');
        var petmeds = readCookie('petmeds');
        var tv = readCookie('tv');
        var onTv = readCookie('ontv');
        var nva = readCookie('nva');

//        var ppCookies = { "Cookies": [
//                "PetMeds" : "petmeds", 
//                "TV" : "tv",
//                
//                
//            ]
//        }
        //make array of possible cookie values    
        //    var ppCookieVal = { 
        //        "cookie:
        //    
        //    }
        //    
        //    
        //    for (var i=0; i < cookieObj.cookies.length; i++) {
        //        
        //    }
        var el = document.getElementById('dynamicphone1'); //any pages with dynamicphone grahic
        
            if (tv) {
                if (document.getElementById) {
                    $(".header .phone").html("<img src=\'/images/CallUs_phone_top_7914.png\' width=\'152\' height=\'16\' />");
                    $("span[id=phone]").html("1-800-518-7914");
                    if (el) { document.getElementById('dynamicphone1').src = '/images/need_help_TVads_7914.png'; }
                }
            }
            else if (onTv) {
                $(".header .phone").html("<img src=\'/images/CallUs_phone_top_7917.png\' width=\'152\' height=\'16\' />");
                $("span[id=phone]").html("1-800-518-7917");
                if (el) { document.getElementById('dynamicphone1').src = '/images/need_help_TVads_7917.png'; }
            }
            else if (petmeds) {
                $('.header .phone').html("<img src=\'/images/phone_top_PM.png\' width=\'152\' height=\'16\' alt=\'Call us! 1.800.395.8660 NEW EXTENDED HOURS Mon - Fri 8:00 AM - 10:30 PM (EST) Sat 8:30 AM - 8:30 PM (EST) Sun 10:00 AM - 6:00 PM (EST)\' title=\'Call us! 1.800.395.8660 NEW EXTENDED HOURS Mon - Fri 8:00 AM - 10:30 PM (EST) Sat 8:30 AM - 8:30 PM (EST) Sun 10:00 AM - 6:00 PM (EST)\' />");
                $("span[id=phone]").html("1-800-395-8660");
                if (el) { document.getElementById('dynamicphone1').src = '/uploads/media/16/7074_PM.png'; }
            }
            else if (nva) {
            $('.header .phone').html("<img src=\'/images/CallUs_phone_top_NVA.png\' width=\'152\' height=\'16\' alt=\'Call us! 1.888.751.7351 NEW EXTENDED HOURS Mon - Fri 8:00 AM - 10:30 PM (EST) Sat 8:30 AM - 8:30 PM (EST) Sun 10:00 AM - 6:00 PM (EST)\' title=\'Call us! 1.888.751.7351 NEW EXTENDED HOURS Mon - Fri 8:00 AM - 10:30 PM (EST) Sat 8:30 AM - 8:30 PM (EST) Sun 10:00 AM - 6:00 PM (EST)\' />");
                $("#phone").html("1-888-751-7351");
                if (el) { document.getElementById('dynamicphone1').src = '/images/need_help_NVA.png'; }
            }             
            else {
                $('.header .phone').html("<img src=\'/images/phone_top.png\' width=\'152\' height=\'16\' alt=\Call us! 1.866.467.3875 - NEW EXTENDED HOURS Mon - Fri 8:00 AM - 10:30 PM (EST) Sat 8:30 AM - 8:30 PM (EST) Sun 10:00 AM - 6:00 PM (EST)\' title=\'Call us! 1.866.467.3875 - NEW EXTENDED HOURS Mon - Fri 8:00 AM - 10:30 PM (EST) Sat 8:30 AM - 8:30 PM (EST) Sun 10:00 AM - 6:00 PM (EST)\' />");

            }
        }
    catch (e) {
        alert("error in GetDynamicPhone method:" + e);
    }
}

// CA - 07/15/2011
// removes 'title' attr from clueTip anchor links
// displays yellow box tooltip when clicked
function removeClueTipRollover() {

    // remove title attribute only from clueTip anchor links
    $('a.tip[title]').each(function() {
    
    $(this).data("title", $(this).attr("title")).removeAttr("title");
//        $this = $(this);
//        $.data(this, 'title', $this.attr('title'));
//        $this.removeAttr('title');
    });
            
    // when clueTip anchor clicked, retrieve title attribute text
    $('a.tip').click(function () {
//        var $this = $this(this);
//        var title = $this.data('title');            
    });  
}
function onComplete(currentArray, currentIndex) {
    
    $("#fancybox-wrap").unbind('mousewheel.fb');
    if (currentIndex + 1 == currentArray.length) {
		//alert(currentIndex + "," + currentArray.length);
        $('#fancybox-right').css('display', 'block');
        $('#fancybox-right').click(function () {

            var page = parseInt(QueryString("page") == "" ? "1" : QueryString("page")) + 1;
            
            var pagecount = parseInt(document.getElementById('pagecount').value);
            if (page > pagecount) { page = 1; }            
            redirectUrl('/gallery/pet?page=' + page + '&pos=1');
        });
    }
    else {
        $('#fancybox-right').unbind('click');
        $('#fancybox-right').click(function () {
            $.fancybox.next();
        });

    }

    if (currentIndex == 0) {
        $('#fancybox-left').css('display', 'block');
        $('#fancybox-left').click(function () {

            var page = parseInt(QueryString("page") == "" ? "1" : QueryString("page")) - 1;
            var pagecount = parseInt(document.getElementById('pagecount').value);
            if (page == 0) { page = pagecount; }
            redirectUrl('/gallery/pet?page=' + page + '&pos=0');
        });
    }
    else {
        $('#fancybox-left').unbind('click');
        $('#fancybox-left').click(function () {
            $.fancybox.prev();
        });

    }

}


function QueryString(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (!results) { return ""; }
    return results[1] || "";
}

	var fbTitle;

	function loadFancybox_pro(nav) {
	    $("a[rel=people]").fancybox({
	        'transitionIn': 'none',
	        'transitionOut': 'none',
	        'titlePosition': 'over',
	        'cyclic': true,
	        'showNavArrows': nav,
	        'padding': 5,
	        'title': this.description,
	        'onComplete': function () { $("#fancybox-wrap").unbind('mousewheel.fb'); reset(); },
	        'onCleanup': reset,
	        'titleFormat': formatTitle
	    });
	    
	}
	
	function loadFancybox_people(nav) {
	    $("a[rel=people]").fancybox({
	        'transitionIn': 'none',
	        'transitionOut': 'none',
	        'titlePosition': 'over',
	        'cyclic': true,
	        'showNavArrows': nav,
	        'padding': 5,
	        'title': this.description,
	        'onComplete': onComplete1,
	        'onCleanup': reset,
	        'titleFormat': formatTitle
	    });

	}

	function reset() {
	    
	    var preHeight = document.getElementById("fancybox-description").offsetHeight;
	    document.getElementById('fancybox-outer').style.height = document.getElementById('fancybox-description').offsetHeight + document.getElementById('fancybox-content').offsetHeight - preHeight + "px";
    }


    function formatTitle(title, currentArray, currentIndex, currentOpts) {
        fbTitle = title;
	    //alert(fbTitle);
        return '<span id="fancybox-title-over">' + "<span id=\"fancybox-description\">" + (stripHtml(title).length ? RestictTitle(230, true) : '') + '</span></span>';
	    //return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/data/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '') + 'Image ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
	}
	
	function onComplete1(currentArray, currentIndex) {
    
    $("#fancybox-wrap").unbind('mousewheel.fb');
    if (currentIndex + 1 == currentArray.length) {
		
        $('#fancybox-right').css('display', 'block');
        $('#fancybox-right').click(function () {

            var page = parseInt(QueryString("page") == "" ? "1" : QueryString("page")) + 1;
            
            var pagecount = parseInt(document.getElementById('pagecount').value);
            //alert(pagecount + "," + currentArray.length);
            if (page > pagecount) { page = 1; }            
            redirectUrl('/people/meet-the-team?page=' + page + '&pos=1');
        });
    }
    else {
        $('#fancybox-right').unbind('click');
        $('#fancybox-right').click(function () {
            $.fancybox.next();
        });

    }

    if (currentIndex == 0) {
        $('#fancybox-left').css('display', 'block');
        $('#fancybox-left').click(function () {

            var page = parseInt(QueryString("page") == "" ? "1" : QueryString("page")) - 1;
            var pagecount = parseInt(document.getElementById('pagecount').value);
            if (page == 0) { page = pagecount; }
            redirectUrl('/people/meet-the-team?page=' + page + '&pos=0');
        });
    }
    else {
        $('#fancybox-left').unbind('click');
        $('#fancybox-left').click(function () {
            $.fancybox.prev();
        });

    }
    reset();

}


	function RestictTitle(l, resize) {
	    //alert(T.length);
	    if (fbTitle.length > l) {
	        return stripHtml(fbTitle).substring(0, l) + "..." + "  <a href=\"javascript:showAllTxt(" + resize + ")\">read more &raquo</a>";
	    }
	    else {
	        return stripHtml(fbTitle) + "<div class='clear'></div>";
	    }
	}

	function stripHtml(stringWithHTML) {
	   return  stringWithHTML.replace(/<\/?[a-z][a-z0-9]*[^<>]*>/ig, "");
    }

	function showTxt(resize) {
	    document.getElementById('fancybox-description').innerHTML = RestictTitle(200, resize);
	    //alert(txt);
	    if (resize) {
	        document.getElementById('fancybox-outer').style.height = document.getElementById('fancybox-content').offsetHeight + "px";
	    }
    }

    function showAllTxt(resize) {

        //alert(fbTitle + "<a href=\"javascript:showTxt('" + RestictTitle(fbTitle, 200) + "')\">read less</a>");
        var preHeight = document.getElementById("fancybox-description").offsetHeight;
        //alert(preHeight);
        document.getElementById("fancybox-description").innerHTML = fbTitle + "  <a href=\"javascript:showTxt(" + resize + ")\">read less &raquo</a>";
        //alert(document.getElementById('description').offsetHeight);
        if (resize) {
            //alert(document.getElementById('fancybox-description').offsetHeight);
            document.getElementById('fancybox-outer').style.height = document.getElementById('fancybox-description').offsetHeight + document.getElementById('fancybox-content').offsetHeight - preHeight + "px";
            document.getElementById('fancybox-right').style.height = document.getElementById('fancybox-content').offsetHeight + "px";
            document.getElementById('fancybox-left').style.height = document.getElementById('fancybox-content').offsetHeight + "px";
        }
    }

// document load 
$(window).load(function() {
	openExternalLinksInNewWindow();
});

function initDatePicker() {
	// Datepickers for date input fields
	$('input.date').datepicker({ dateFormat: 'dd/mm/yy' });
}
 
// Open an AJAX dialog
function openDialog(url,title,width,height) {
	// Width and height
	var w = 500;
	var h= 300;
	if(width) {
		w = width;	 
	}
	if(height) {
		h = height;	 
	}
	 // Reset the dialog
    $("#dialog").html('').dialog('destroy'); 
    // Set up dialog
    $("#dialog").dialog({
		width: w,
		height: h,
		modal: true,
		title: title,
		cache: false
    }); 
    // Fetch content
    $.ajax({
		type: "GET",
		url: url,
		data: "ajax=1",
		success: function(data){
			$("#dialog").html(data);
		}
    });
}

// Replace alrt boxes with a much nicer alternative
function ajaxAlert(msg) {
	if($('#alert').length == 0) {
		$("body").append('<div id="alert"></div>');	
	}
    $('#alert').dialog('destroy').html(msg).dialog({
		dialogClass: 'alert',
		width: 200,
		minHeight: 80,
		modal: true,
		cache: false,
		buttons: { "Ok": function() { $(this).dialog("close"); } }
    }); 
}

/* create tabs function - to allow for tabs to be called by other means */
function createTabs(){
	$(".tabs").tabs();
}

// columns script - checks number of div.columns inside of div.row and adds specific class to div.inner.
function testIfPageContainsColumns() {
	// test is .row is in the DOM
	if($(".row").length>=1) {
		// run getNumberOfColumns function
		getNumberOfColumns();
	}
	function getNumberOfColumns() {
		var rowStore = $(".row");
		for(var i=0;i<rowStore.length;i++) {
			var numberOfChildren = new Number($(rowStore[i]).find(".inner .column").length);
			if(numberOfChildren<=2) {
				// do nothing
			}
			else {
				$(rowStore[i]).find(".inner").addClass("numberOfColumns" + numberOfChildren);
			}
		}
	}
}

// removes class from target div and adds it to a given tag
function moveClassToElement(targetID, moveClassNameTo) {
	if($(targetID).length == 1) {
		var className = $(targetID).attr("class");
		$(moveClassNameTo).addClass(className);
		$(targetID).removeAttr("class");
	}
}

// add classes to input elements
function addClassToInputElements() {
	$("input[type=text]").addClass("input_type_text");
	$("input[type=password]").addClass("input_type_password");
	$("input[type=radio]").addClass("input_type_radio");
	$("input[type=checkbox]").addClass("input_type_checkbox");
	$("input[type=submit]").addClass("input_type_submit");
	$("input[type=image]").addClass("input_type_image");
	$("input[type=button]").addClass("input_type_button");
	$("input[type=file]").addClass("input_type_file");
}

// add first and last class to elements which are drawn dynamically 
function addFirstAndLastClass(className) {
	if($("." + className).length>=1) {
		var numberOfFirstAndLastClass = $("." + className);
		for(var i=0;i<numberOfFirstAndLastClass.length;i++) {
			$(numberOfFirstAndLastClass[i]).removeClass(className);
			$(numberOfFirstAndLastClass[i]).children(":first-child").addClass("first-child");
			$(numberOfFirstAndLastClass[i]).children(":last-child").addClass("last-child");
			if($(numberOfFirstAndLastClass[i]).attr("class")==null) {
				$(numberOfFirstAndLastClass[i]).removeAttr("class");
			}
		}
	}
}

function removeLoadingClass(target, pageLoadingClass) {
	$(target).removeClass(pageLoadingClass);
}

// open external links in new window
function openExternalLinksInNewWindow() {
	$("a[href^='http://']" || "a[href^='www.']").click(function(){
		window.open(this.href);
		return false;
	});
}


function SaveSearchLink(Url, SiteSearchId) {

    PageMethods.SaveClickedLink(Url, SiteSearchId);
}

function trackIFA(AdvisorId, Action) {

    PageMethods.trackIFA(AdvisorId, Action);
}

// Show the popovers
function showPopover() {
    clearTimeout(timer);$(".popover").hide();
    var $thisPopover = $(".popover", this);

    $thisPopover.show();
    //ie6ToggleSelect('hide');
    //alert(iPop);
    
    if (document.getElementById(iMenu) != null && document.getElementById(iSub) != null && document.getElementById(iHidden).value == "0") {
        //alert(iDif);
        iMW = document.getElementById(iMenu).offsetWidth;
        iSW = document.getElementById(iSub).offsetWidth;

        //alert(document.getElementById("startPoint").offsetLeft);
        document.getElementById(iSub).style.left = document.getElementById("startPoint").offsetLeft + "px";
        //iPO = document.getElementById(iNav).offsetLeft;
        //alert(document.getElementById(iTab).offsetWidth + "," + document.getElementById(iList).offsetWidth);
        
//        if(document.getElementById(iTab).offsetWidth >=  document.getElementById(iList).offsetWidth)
//        {
//            document.getElementById(iList).style.width = document.getElementById(iList).offsetWidth +5 + "px";
//            document.getElementById(iList).style.height = document.getElementById(iList).offsetHeight +10 + "px";
//        }else
//        {
//            iSW= iSW-5;
//        }
       
        if (iDif != 0) {
           
            //document.getElementById(iSub).style.Left = document.getElementById(iPop).offsetLeft + "px";
            //alert(document.getElementById(iPop).offsetLeft + "," + document.getElementById(iNav).offsetLeft + "," + iSW + "," + iMW + "," + iDif);
            //document.getElementById(iSub).style.marginLeft = (document.getElementById(iPop).offsetLeft - document.getElementById(iNav).offsetLeft - iSW + iMW - iDif) + "px";
            //document.getElementById(iPop).style.width = iMW + 15 + "px";
            //alert(document.getElementById(iPop).offsetLeft + document.getElementById(iPop).offsetWidth - document.getElementById("startPoint").offsetLeft + "," + document.getElementById(iList).offsetWidth);
            document.getElementById(iList).style.marginLeft = (document.getElementById(iPop).offsetLeft + document.getElementById(iPop).offsetWidth - document.getElementById("startPoint").offsetLeft) - document.getElementById(iList).offsetWidth + 4 + "px";
            //alert(document.getElementById(iSub).style.left);
        }
        else {

            if (document.getElementById(iList).offsetWidth > 960 - document.getElementById(iPop).offsetLeft) {
                document.getElementById(iList).style.marginLeft =0;
            }
            else {
                document.getElementById(iList).style.marginLeft = document.getElementById(iPop).offsetLeft - document.getElementById("startPoint").offsetLeft - 6 + "px";

            } //alert(document.getElementById(iSub).style.Left);

            
            //alert( iSub + "," + iPop + "," + (960 - document.getElementById(iPop).offsetLeft) + "," + iSW);
//            if (960 - document.getElementById(iPop).offsetLeft + 5 < iSW && iPop != "ctl00_PageHolder_HeaderHolder_Siteheader1_rptTopMenu_ctl03_nav_popup") {
//                document.getElementById(iSub).style.marginLeft = 960 - iSW + "px";
//            }
//            else {
//                //alert(document.getElementById(iPop).offsetLeft + "," + document.getElementById(iNav).offsetLeft);
//                document.getElementById(iSub).style.marginLeft = (document.getElementById(iPop).offsetLeft - document.getElementById(iNav).offsetLeft - 6) + "px";
//                //alert(document.getElementById(iSub).style.marginLeft);
//            }

        }

        if (iPop == "ctl00_PageHolder_HeaderHolder_Siteheader1_rptTopMenu_ctl06_nav_popup") {
            document.getElementById(iList).style.marginLeft = (document.getElementById(iPop).offsetLeft + document.getElementById(iPop).offsetWidth - document.getElementById("startPoint").offsetLeft) - document.getElementById(iList).offsetWidth + 4 + "px";
        }

        if (iPop == "ctl00_PageHolder_HeaderHolder_Siteheader1_rptTopMenu_ctl03_nav_popup" || iPop == "ctl00_PageHolder_HeaderHolder_Siteheader1_rptTopMenu_ctl01_nav_popup") {
            document.getElementById(iList).style.marginLeft = document.getElementById(iPop).offsetLeft - document.getElementById("startPoint").offsetLeft - 6 + "px";

        }

//        if (document.getElementById(iTab).offsetWidth >= document.getElementById(iList).offsetWidth) {
//            document.getElementById(iList).style.width = document.getElementById(iList).offsetWidth + 5 + "px";
//            document.getElementById(iList).style.height = document.getElementById(iList).offsetHeight + 10 + "px";
//        }

//        document.getElementById(iHidden).value = "1";

        SubdropCurves(iList);
    }
   
}

// Hide the popovers
function hidePopover() {

  timer =  setTimeout('$(".popover").hide()',1500);
    //ie6ToggleSelect('show');
}

// Show hide select boxes in IE6 (they overlap popups)
function ie6ToggleSelect(action) {

    if ($.browser.msie && parseInt($.browser.version, 10) < 7) {

        if (action == 'hide') {
            $('select').css('visibility', 'hidden');
        } else if (action == 'show') {
            $('select').css('visibility', 'visible');
        }

    }

}

var iSub;
var iMenu;
var iNav;
var iDif;
var iPop;
var iList;
var iTab;
var iHidden;
function setPopPosition(aid,bid,cid, did, idiff, popId, tid, hid ) {
    iMenu = aid;
    iSub = bid;
    iNav = cid;
    iDif = idiff;
    iPop = popId;
    iList = did;
    iTab = tid;
    iHidden = hid;
}


function redirectUrl(iurl) {
    window.location = iurl;
}

function redUrl() {
    window.location = document.getElementById("bloglink").href;
}

var curExpert;
function changeSet(aid, bid, atxt) {
    if (curExpert != null) {
        document.getElementById(curExpert).className = "";
    }
    document.getElementById(bid).innerHTML = atxt;
    document.getElementById(aid).className = "over";

    curExpert = aid;
    //alert(document.getElementById(aid).className);
}



function changeCPE1() {
    $find('LoginBehavior')._animation._duration = 0;    
    $find('ForVetsBehavior')._animation._duration = 0.5;
    //alert($find('ForVetsBehavior').get_Collapsed() + "," + $find('LoginBehavior').get_Collapsed())
    if ($find('ForVetsBehavior').get_Collapsed() && $find('LoginBehavior').get_Collapsed()) {
        $find('ForVetsBehavior')._collapsedImage = '/images/for_vets.gif';
        $find('LoginBehavior')._collapsedImage = '/images/customer_login_on.gif';
        document.getElementById('hplCancel').style.display = 'block';
    }
    else if (!$find('ForVetsBehavior').get_Collapsed() && $find('LoginBehavior').get_Collapsed()) {
        $find('LoginBehavior')._collapsedImage = '/images/customer_login.gif';
        $find('ForVetsBehavior')._collapsedImage = '/images/for_vets.gif';
        document.getElementById('hplCancel').style.display = 'block';
    }
    else if ($find('ForVetsBehavior').get_Collapsed() && !$find('LoginBehavior').get_Collapsed()) {
    $find('LoginBehavior')._collapsedImage = '/images/customer_login_on.gif';
    }
    $find('LoginBehavior').collapsePanel();

}

function setCPE() {
    $find('LoginBehavior')._animation._duration = 0.05;
    $find('LoginBehavior')._animation._fps = 50;
    $(".dialog a.close").show();
}

function changeCPE2() {
     
    
    if ($find('LoginBehavior').get_Collapsed() ) {
        $find('LoginBehavior')._collapsedImage = '/images/policyholder_login_on.png';  
    }
    else{

        $find('LoginBehavior')._collapsedImage = '/images/policyholder_login.png';
    }  
}

var sharetimer;
function hideSub(aid) {

    sharetimer =setTimeout("document.getElementById('" + aid + "').style.display = 'none'", 2000);
}

var curSelect;
function showSelect(aid) {

   
    if (curSelect != null && document.getElementById(curSelect) != null) {
        document.getElementById(curSelect).style.display = "none";
    }
    document.getElementById(aid).style.display = "block";
    curSelect = aid;
}

function showOver(aid) {
    document.getElementById(aid).style.display = "block";
}

function hideSelect(aid) {

    document.getElementById(aid).style.display = "none";

}

function clearHide() {
    if (sharetimer != null) {
        clearTimeout(sharetimer);
    }

}

function setDefaultImg(aid, src) {
    document.getElementById(aid).src = src;
}

//for condtion check
function loadtips() {
    $('a.tips').cluetip({
        splitTitle: '|',
        showTitle: false,
        arrows: true,
        cluetipClass: 'rounded',
        dropShadow: false,
        sticky:true,
        topOffset:20, 
        leftOffset:5,
        closeText: '<img src="/images/buttons/close_small.png" alt="close" />'
    });
}


//for content page
function loadtip() {
    $('a.tip').cluetip({
        splitTitle: '|',
        showTitle: false,
        arrows: true,
        cluetipClass: 'rounded',
        dropShadow: false,
        sticky: true,
        topOffset: 18,
        leftOffset: -12,
        activation: 'click',
        positionBy: 'mouse',
        arrows: true,
        mouseOutClose: false,        
        closeText: '<img src="/images/buttons/close_small.png" alt="close" />',
        hoverIntent: {
            sensitivity: 10,
            interval: 750,
            timeout: 750
        }

    });
   
}


function tipdropCurves() {
   //alert(document.getElementById('cluetip').childNodes.length);
    if (document.getElementById('cluetip') != null && document.getElementById('cluetip').childNodes.length > 0) {
        
        var myBorder = RUZEE.ShadedBorder.create({ corner: 8, shadow: 20 });
        myBorder.render('cluetip');
    }
}

function SubdropCurves(iid) {
    var myBorder = RUZEE.ShadedBorder.create({ corner: 8, shadow: 20 });
    myBorder.render(iid);
}


function loadVideoSlide() {
    $("#video_slider").easySlider({
        auto: false,
        continuous: true,
        prevId: 'controls_prev',
        nextId: 'controls_next',
        prevText: '<img src="/images/buttons/left.png" alt="previous">',
        nextText: '<img src="/images/buttons/right.png" alt="next">',
        controlsFade: false
    });

}

function textChange(elementID, defaultText)
{
   var element = document.getElementById(elementID);

   if(element.value == defaultText)
   {
      element.value = "";
   }
   else if(element.value == "")
   {
      element.value = defaultText;
   }

}

function changeClass(aid) {
    var iElement = document.getElementById(aid);
    
    if (iElement.className == "pnlHeader") {
        iElement.className = "pnlHeaderOn";
    } else {
    iElement.className = "pnlHeader";
    }

}


function tableResults() {
    if ($("table.results").length >= 1) {
        $("table.results tbody tr:odd").addClass("even");
    }
}

function submitted(iElement, vGroup) {
    //alert(Page_ClientValidate('vdgComment'));
    if (Page_ClientValidate(vGroup) || Page_ClientValidate()) {
        iElement.style.visibility = 'hidden';
        document.getElementById("loading").style.display = "block";
    }
    else {

        return false;
    }
}

function is_child_of(parent, child) {
    if (child != null) {
        while (child.parentNode) {
            if ((child = child.parentNode) == parent) {
                return true;
            }
        }
    }
    return false;
}

function fixOnMouseOut(element, event, JavaScript_code) {
    var current_mouse_target = null;
    if (event.toElement) {
        current_mouse_target = event.toElement;
    } else if (event.relatedTarget) {
        current_mouse_target = event.relatedTarget;
    }
    if (!is_child_of(element, current_mouse_target) && element != current_mouse_target) {
        eval(JavaScript_code);
    }
}

function bookmark_this(url, title) {

    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all)// ie
        window.external.AddFavorite(url, title);
}


//to fix postback
//Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
//    function EndRequestHandler(sender, args) {
//        if (args.get_error() == undefined) {            

//        }
//        
//    }

function isInteger(s) {
    var i;

    if (isEmpty(s))
        if (isInteger.arguments.length == 1) return 0;
        else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    return true;
}

function isEmpty(s) {
    return ((s == null) || (s.length == 0))
}

function isDigit(c) {
    return ((c >= "0") && (c <= "9"))
}

function CalculateClaim() { // Claim Calculator
    var CostDollars="0";
    var CostCents = "0";
    if (isInteger(document.getElementById("CostDollars").value) == false && document.getElementById("CostDollars").value != "") {
        alert("Whoops??! You're giving us too much information! We just need the dollars, not the cents.");
        return;
    }
    else if (isInteger(document.getElementById("CostDollars").value) == true) {
        CostDollars = document.getElementById("CostDollars").value;
    }

    if (isInteger(document.getElementById("CostCents").value) == false && document.getElementById("CostCents").value != "") {
        alert("Please enter vaild cost for vet costs");
        return;
    } else if (isInteger(document.getElementById("CostCents").value) == true) {
        CostCents = document.getElementById("CostCents").value;
    }
    //var CostDollars = document.getElementById("CostDollars").value;

    // remove commas for computation
    CostDollars = CostDollars.replace(/\,/g, "");

    // append cent to dollar value 
    var Cost = parseFloat(CostDollars) + "." + CostCents;
   
    //alert("Cost = " + Cost); // test ***

    // add commas for display
    //document.getElementById("CostDollars").value = parseFloat(CostDollars).withCommas();

    var Plan = parseFloat(document.getElementById("Plan").value);

    var CoInsurance = parseFloat(Plan * document.getElementById("CoInsuranceValue").value);

    // round number to two decimal places

    CoInsurance = Math.round(CoInsurance * 100) / 100;

    //alert("CoInsurance = " + CoInsurance); // test ***

    var Deductible = parseFloat(document.getElementById("DeductibleValue").value);

    // Gold   $20,000
    // Silver $12,000
    // Bronze  $8,000

    //if (Cost > Plan){ // reimbursement is capped by plan limit

    //	var Reimbursement = Plan - CoInsurance - Deductible;

    //}else{

    //	var Reimbursement = Cost - CoInsurance - Deductible;		
    //}

    if ((Cost - Plan) > 0) {
        var AmountOverIns = Cost - Plan;
    }
    else {
        var AmountOverIns = 0;
        var CoInsurance = parseFloat(Cost * document.getElementById("CoInsuranceValue").value);

    }
    //alert("Cost="+Cost);
    //alert("Plan="+Plan);
    //alert("CoInsurance="+CoInsurance);
    //alert("CoInsurance selected="+document.getElementById("CoInsuranceValue").value);


    //Reimbursement = Math.round(Reimbursement * 100) / 100;

    //var YourCost = Cost - Reimbursement+AmountOverIns;

    var YourCost = CoInsurance + Deductible + AmountOverIns;

    //alert("YourCost="+YourCost);

    if ((Plan - Cost) > 0) {
        var Reimbursement = Cost - CoInsurance - Deductible;
    }
    else {
        var Reimbursement = Plan - CoInsurance - Deductible;
    }

    if (Reimbursement < 0) {
        Reimbursement = 0;
    }

    YourCost = Math.round(YourCost * 100) / 100;

    // display Your Share of Costs
    document.getElementById("YourCost").innerHTML = "$" + YourCost.withCommas();

    // display Reimbursement
    document.getElementById("Reimbursement").innerHTML = "$" + Reimbursement.withCommas();


    if ((Plan - Cost) > 0) {
        var ReaminaingCoverage = parseFloat(Plan - Reimbursement);
        //was cost
    }
    else {
        var ReaminaingCoverage = 0;
    }

    //if (ReaminaingCoverage<AmountOverIns)
    //{
    //	ReaminaingCoverage=0;
    //}
    //else
    //{
    //	ReaminaingCoverage=ReaminaingCoverage-AmountOverIns;

    //}

    // display Reaminaing Coverage
    document.getElementById("RemainingCoverage").innerHTML = "$" + ReaminaingCoverage.withCommas();

}

// add commas to a large number

String.prototype.reverse = function () {

    return this.split('').reverse().join('');
}

Number.prototype.withCommas = function () {

    if (isNaN(this)) {

        return NaN.toString();
    }

    var n = Math.abs(this).toFixed(2).split('.');

    return [(this < 0 ? '-' : ''), (n[0].length > 3 ? n[0].reverse().match(/\d{1,3}/g).join(',').reverse() : n[0]), n[1] > 0 ? '.' + n[1] : undefined].join('');
} 

function readCookie(name) {
                var nameEQ = name + "=";
                var ca = document.cookie.split(';');
                for(var i=0;i < ca.length;i++) {
                                var c = ca[i];
                                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
                }
                return null;
}



