﻿function validateSearchForm()
{
    var valid = true;
    
    if (document.getElementById('ctl00_top1_searchtext').value.length == 0 ) {
 	    window.alert ("Please enter a search text.");
  		valid = false;
 	}
 	else
 	{
 	    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
 		for (var i = 0; i < document.getElementById('ctl00_top1_searchtext').value.length; i++) {
  		    if (iChars.indexOf(document.getElementById('ctl00_top1_searchtext').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_top1_searchtext").value;        
    }
    return false;
}

function doClear(theText) {
    if (theText.value == theText.defaultValue) {
        theText.value = ""
    }
}


function openWin( windowURL, windowName, windowFeatures) {
     window.open( windowURL, windowName, windowFeatures );
}

function validateAge(source, args) {
    var yearObj = document.getElementById('ctl00_ContentPlaceHolder1_UserDateOfBirthYear');
    var monthObj = document.getElementById('ctl00_ContentPlaceHolder1_UserDateOfBirthMonth');
    var dayObj = document.getElementById('ctl00_ContentPlaceHolder1_UserDateOfBirthDay');
    var now = new Date();
    try {
        var ourdate = new Date(monthObj.value + "/" + dayObj.value + "/" + yearObj.value);
        var diff = days_between(now, ourdate)
        args.IsValid = diff >= 6576;
    } catch (x) {
        args.IsValid = true;
    }   
}

function days_between(date1, date2) {
    var ONE_DAY = 1000 * 60 * 60 * 24// The number of milliseconds in one day
    var date1_ms = date1.getTime()// Convert both dates to milliseconds
    var date2_ms = date2.getTime()
    var difference_ms = Math.abs(date1_ms - date2_ms)// Calculate the difference in milliseconds
    return Math.round(difference_ms / ONE_DAY)// Convert back to days and return
}

function validateFirstName(source, args) {
    var firstNameObj = document.getElementById('ctl00_ContentPlaceHolder1_UserFirstName');
   if(firstNameObj.value == "") {
        args.IsValid = true;
        return;
    }
    try {
        var lg = firstNameObj.value.length;
        args.IsValid = parseInt(lg) < 21;
    } catch(x) {
        args.IsValid = true;        
    }  
}

function validateLastName(source, args) {
    var lastNameObj = document.getElementById('ctl00_ContentPlaceHolder1_UserLastName');
   if(lastNameObj.value == "") {
        args.IsValid = true;
        return;
    }
    try {
        var lg = lastNameObj.value.length;
        args.IsValid = parseInt(lg) < 21;
    } catch(x) {
        args.IsValid = true;        
    }  
}

function validateLastName1(source, args){
    var lastNameObj = document.getElementById('ctl00_ContentPlaceHolder1_UserLastName');
    if(lastNameObj.value == "") {
        args.IsValid = true;
        return;
    }
    try {
        if(lastNameObj.value.match(" "))
            lastNameObj.value = lastNameObj.value.replace(" ","");
        var lg = lastNameObj.value.length;
        args.IsValid = parseInt(lg) > 1;
    } catch(x) {
        args.IsValid = true;        
    } 
}
function validateAddress1(source, args) {
    var address1Obj = document.getElementById('ctl00_ContentPlaceHolder1_UserAddress1');
   if(address1Obj.value == "") {
        args.IsValid = true;
        return;
    }
    try {
        var lg = address1Obj.value.length;
        args.IsValid = parseInt(lg) < 21;
    } catch(x) {
        args.IsValid = true;        
    }  
}

function validateAddress2(source, args) {
    var address2Obj = document.getElementById('ctl00_ContentPlaceHolder1_UserAddress2');
   if(address2Obj.value == "") {
        args.IsValid = true;
        return;
    }
    try {
        var lg = address2Obj.value.length;
        args.IsValid = parseInt(lg) < 21;
    } catch(x) {
        args.IsValid = true;        
    }  
}

function validateCity(source, args) {
    var cityObj = document.getElementById('ctl00_ContentPlaceHolder1_UserCity');
   if(cityObj.value == "") {
        args.IsValid = true;
        return;
    }
    try {
        var lg = cityObj.value.length;
        args.IsValid = parseInt(lg) < 21;
    } catch(x) {
        args.IsValid = true;        
    }  
}

function openRebateCoupon() {
    openWin(window.root+'registration-eligibility.aspx','RebateCoupon','scrollbars=yes,width=475,height=450');
}

function exitSite(destination)
{
	openWin(window.root+'exitsite.aspx?url=' + destination ,'pop_up','width=500,height=245,scrollbars=auto, resizable=1');
}

function interstitial(destination)
{
	openWin(window.root+'interstitial.aspx?url=' + destination ,'pop_up','width=500,height=215,scrollbars=auto');
}

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_findObj(n, d) 
{	//v4.0
  	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 && document.getElementById) x=document.getElementById(n); return x;
}

function openNewWindow(path)
{

    window.open(path, "_blank");
}

function showStudyDesign(x)
{
    document.getElementById(x).style.display = 'block';
}

function closeDiv(y)
{
    document.getElementById(y).style.display = 'none';
}

function validateOption(source, args) {
    if ((document.getElementById('prescription20').checked == true) || (document.getElementById('prescription25').checked == true))
        args.IsValid = true;
    else
        args.IsValid = false;

}

function validate_Help_Pay(source, args) {
    if ((document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_30_1').checked == true) ||
        (document.getElementById('ctl00_ContentPlaceHolder1_UserResponse_R_1_30_2').checked == true)) {
        args.IsValid = true;
        return;
    }
    else {
        args.IsValid = false;
        return;
    }
}

function CV_Mass(source, args) {
    if ((document.getElementById('ctl00_ContentPlaceHolder1_UserState').value != "MA" )) {
        args.IsValid = true;
        return;
    }
    else {
        args.IsValid = false;
        return;
    }
}

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;
}

