﻿// JScript File
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function submitSearchFormBase() {
    if (validateSearchFormBase()) {
        window.location = window.root + 'hcp/search_results.aspx?q=' + document.getElementById("ctl00_navigation1_utilitybarSearchText").value;
    }
    return false;
}

function validateSearchFormBase() {
    var valid = true;
    if (document.getElementById('ctl00_navigation1_utilitybarSearchText').value == "Search" ||
    document.getElementById('ctl00_navigation1_utilitybarSearchText').value.length == 0) {
        window.alert("Please enter a search term.");
        valid = false;
    }
    else {
        var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
        for (var i = 0; i < document.getElementById('ctl00_navigation1_utilitybarSearchText').value.length; i++) {
            if (iChars.indexOf(document.getElementById('ctl00_navigation1_utilitybarSearchText').value.charAt(i)) != -1) {
                window.alert("Your search text has special characters. \nThese are not allowed.\nPlease remove them and try again.");
                valid = false;
                break;
            }
        }
    }
    return valid;
}

function submitSearchForm() {
    if (validateSearchForm()) {
        window.location = window.root + 'search_results.aspx?q=' + document.getElementById("ctl00_top_utilitybarSearchText").value;
    }
    return false;
}

function validateSearchForm() {
    var valid = true;
    if (document.getElementById('ctl00_top_utilitybarSearchText').value == "Search" ||
    document.getElementById('ctl00_top_utilitybarSearchText').value.length == 0 ) {
        window.alert("Please enter a search term.");
        valid = false;
    }
    else {
        var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
        for (var i = 0; i < document.getElementById('ctl00_top_utilitybarSearchText').value.length; i++) {
            if (iChars.indexOf(document.getElementById('ctl00_top_utilitybarSearchText').value.charAt(i)) != -1) {
                window.alert("Your search text has special characters. \nThese are not allowed.\nPlease remove them and try again.");
                valid = false;
                break;
            }
        }
    }
    return valid;
}


function openWin(windowURL, windowName, windowFeatures) {
    window.open(windowURL, windowName, windowFeatures);
}

function doClear(theText) {
    if (theText.value == theText.defaultValue) {
        theText.value = ""
    }
}

function CV_HelpPay(source, args) {
    if ((document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_1_1').checked == true) ||
        (document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_1_2').checked == true)) {
            args.IsValid = true;
            return;
        }
        else {
            args.IsValid = false;
            return;
        }        
}

function CV_EligibleAge(source, args) {
    if ((document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_C_1_2_1').checked == true)){
            args.IsValid = true;
            return;
        }
        else {
            args.IsValid = false;
            return;
        }
    }

    function validateMASS(source, args) {
        if ((document.getElementById('ctl00_ContentPlaceHolder1_UserState').value == 'MA')) {
            args.IsValid = false;
            return;
        }
        else {
            args.IsValid = true;
            return;
        }
    }

function CV_Diagnosed(source, args) {
    if ((document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_3_1').checked == true) ||
        (document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_3_2').checked == true)) {
            args.IsValid = true;
            return;
        }
        else {
            args.IsValid = false;
            return;
        }        
}

function Validate_Taking(source, args) {
    if ((document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_3_2').checked == true)) { args.IsValid = true; return; }

    if ((document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_3_1').checked == false) && (document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_3_2').checked == false)) { args.IsValid = true; return; }
    
    if ((document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_3_1').checked == true) &&
    (document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_4_1').checked == true) ||
    (document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_4_5').checked == true) ||
    (document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_4_6').checked == true)) {
            args.IsValid = true;
            return;
        }
        else {
            args.IsValid = false;
            return;
        }
        
    }

    function onlyNumbers(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

        return true;

    }

    function showf(objId) {        
        var agt = navigator.userAgent.toLowerCase();
        // *** BROWSER ***
        // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
        var is_major = parseInt(navigator.appVersion);
        var is_minor = parseFloat(navigator.appVersion);

        var is_nav = ((agt.indexOf('mozilla') != -1) && (agt.indexOf('spoofer') == -1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1)
                && (agt.indexOf('webtv') == -1) && (agt.indexOf('hotjava') == -1));
        var is_nav2 = (is_nav && (is_major == 2));
        var is_nav3 = (is_nav && (is_major == 3));
        var is_nav4 = (is_nav && (is_major == 4));
        var is_nav4up = (is_nav && (is_major >= 4));
        var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)));
        var is_nav6 = (is_nav && (is_major == 5));
        var is_nav6up = (is_nav && (is_major >= 5));
        var is_gecko = (agt.indexOf('gecko') != -1);

        var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
        var is_ie3 = (is_ie && (is_major < 4));
        var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4") != -1));
        var is_ie4up = (is_ie && (is_major >= 4));
        var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0") != -1));
        var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") != -1));
        var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
        var is_ie5_5up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);
        var is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.") != -1));
        var is_ie6up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

        // *** PLATFORM ***
        var is_win = ((agt.indexOf("win") != -1) || (agt.indexOf("16bit") != -1));
        // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
        //        Win32, so you can't distinguish between Win95 and WinNT.
        var is_win95 = ((agt.indexOf("win95") != -1) || (agt.indexOf("windows 95") != -1));

        // is this a 16 bit compiled version?  
        var is_win16 = ((agt.indexOf("win16") != -1) ||
           (agt.indexOf("16bit") != -1) || (agt.indexOf("windows 3.1") != -1) ||
           (agt.indexOf("windows 16-bit") != -1));

        var is_win31 = ((agt.indexOf("windows 3.1") != -1) || (agt.indexOf("win16") != -1) ||
                (agt.indexOf("windows 16-bit") != -1));

        // NOTE: Reliable detection of Win98 may not be possible. It appears that:
        //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
        //       - On Mercury client, the 32-bit version will return "Win98", but
        //         the 16-bit version running on Win98 will still return "Win95".
        var is_win98 = ((agt.indexOf("win98") != -1) || (agt.indexOf("windows 98") != -1));
        var is_winnt = ((agt.indexOf("winnt") != -1) || (agt.indexOf("windows nt") != -1));
        var is_win32 = (is_win95 || is_winnt || is_win98 ||
                ((is_major >= 4) && (navigator.platform == "Win32")) ||
                (agt.indexOf("win32") != -1) || (agt.indexOf("32bit") != -1));

        var is_os2 = ((agt.indexOf("os/2") != -1) ||
                (navigator.appVersion.indexOf("OS/2") != -1) ||
                (agt.indexOf("ibm-webexplorer") != -1));

        var is_mac = (agt.indexOf("mac") != -1);
        var is_mac68k = (is_mac && ((agt.indexOf("68k") != -1) ||
                           (agt.indexOf("68000") != -1)));
        var is_macppc = (is_mac && ((agt.indexOf("ppc") != -1) ||
                            (agt.indexOf("powerpc") != -1)));

        if (is_ie)
            document.getElementById(objId).style.display = "inline";
        else
            document.getElementById(objId).style.display = "inherit";

        

    }

    function hidef(objId) {
        document.getElementById(objId).style.display = "none";
        
    }

    function disablesubmitbuttton() {
        document.getElementById('ctl00_ContentPlaceHolder1_btnSubmit').disabled = true;
    }

    function enablesubmitbuttton() {
        document.getElementById('ctl00_ContentPlaceHolder1_btnSubmit').disabled = false;
    }

    function ResetForm() {
        if ((document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_3_1').checked == true)) {
            showf('divMedication');
        }
    }

    function validateLastName(source, args)
    {
       if (document.getElementById('ctl00_ContentPlaceHolder1_UserLastName').value.length < 2 ){
        args.IsValid = false;
            return;
       }
       else
       {
        args.IsValid = true;
            return;
       }

   }

   function clearPrescription() {
       if (document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_3_2').checked == true) {
           document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_4_1').checked = false
           document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_4_5').checked = false
           document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_4_6').checked = false
       }

   }

   function displayPrescription() {

       if (document.getElementById('ctl00_ContentPlaceHolder1_UserEmailAddress').value.length < 1 || document.getElementById('ctl00_ContentPlaceHolder1_UserEmailRepeat').value.length < 1) {
           document.getElementById('litMes').style.display = "none";
           document.getElementById('litMes').style.display = "none";
       }
   }

   function showMass(objId) {
       var agt = navigator.userAgent.toLowerCase();
       var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
       if (document.getElementById('ctl00_ContentPlaceHolder1_UserState').value == 'MA') {
           if (is_ie)
               document.getElementById(objId).style.display = "inline";
           else
               document.getElementById(objId).style.display = "inherit";
       }
       else
           document.getElementById(objId).style.display = "none";
   }
