// JScript File
function submitSearchFormBase()
{
 if (validateSearchFormBase()) { 
    window.location=window.root+'searchResults.aspx?q='+document.getElementById("ctl00_con_utilitybar1_SearchText").value;
   }
    return false;
}

function validateSearchFormBase()
{
    var valid = true;
    if (document.getElementById('ctl00_con_utilitybar1_SearchText').value == "Enter search term" || 
    document.getElementById('ctl00_con_utilitybar1_SearchText').value.length == 0 ) {
 	    window.alert ("Please enter a search text.");
  		valid = false;
 	}
 	else
 	{
 	    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
 		for (var i = 0; i < document.getElementById('ctl00_con_utilitybar1_SearchText').value.length; i++) {
  		    if (iChars.indexOf(document.getElementById('ctl00_con_utilitybar1_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 openWin( windowURL, windowName, windowFeatures) {
     window.open( windowURL, windowName, windowFeatures ) ;
}

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 showISI() {
	MM_showHideLayers('divFlash','','show')
 	window.document.aravaScroller_Consumer.Play();
}

function printVoucher(){
    var urlString = unescape(window.location);
    var aValue = urlString.substring(urlString.indexOf("?WT.mc_id="));
    if(urlString.indexOf("?WT.mc_id=")>=0)
    window.open('https://www.altsampling.com/9068050/Coupon.aspx' + aValue ,'','left=500,top=50,width=700,height=900,,resizable=0');
    else
    window.open('https://www.altsampling.com/9068050/Coupon.aspx','','left=500,top=50,width=700,height=900,,resizable=0');
   }

function doClear(theText) {
    if (theText.value == theText.defaultValue) {
        theText.value = ""
    }
}


function submitSearchForm()
{
    if (validateSearchText(document.searchForm.SearchText.value)) {
      //document.searchForm.submit(); 
      return true;
    } else {
      return false;
    }
}

function clearSearch()
{
   if (document.searchForm.SearchText.value == 'Enter search term')
       document.searchForm.SearchText.value = ''
}

function validateSearchText(searchText)
{
    var valid = true;
    
    if (searchText.length == 0) {
 	    window.alert ("Please enter a search text.");
  		valid = false;
 	}
 	else
 	{
 	    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
 		for (var i = 0; i < searchText.length; i++) {
  		    if (iChars.indexOf(searchText.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 gotoGlossary(term) 
{
    window.location = window.root+ 'glossary.aspx#'+term;
}

function exitSite(destination,interstitial)
{
	openWin(window.root + 'exitsite.aspx?url=' + destination + "&inst="+interstitial ,'pop_up','width=550,height=400,scrollbars=auto');
}

function validateQuiz(source, args)
{
    args.IsValid = true;
    var valid = false;
    var qvalid = true;    
    var obj ;
    for(var j=1;j<=8;j++) {
       valid = false;
       for(var index=1;index<=7;index++) {        
        if (document.getElementById("UserResponse_R_3_" + j + "_" + index)!=null)
         valid = (valid || document.getElementById("UserResponse_R_3_" + j + "_" + index).checked);         
       }
       qvalid = qvalid && valid;
    }
   args.IsValid = qvalid;   
}

// Registration Validation
function validateAge(source, args) {    
    var now = new Date();
    if(args.Value == "") {
        args.IsValid = true;
        return;
    }
    try {
        var dif = eval (now.getFullYear() + "-" + args.Value);
        args.IsValid = dif > 17;
    } catch(x) {
        args.IsValid = true;        
    }  
}

function confirmHCP(destination)
{
	var bln = confirm('This information is intended for U.S. Healthcare Professionals. If you are a Healthcare Professional, click OK to continue. ');
	if (bln)
	{
		window.location.href=destination;
	}

}

function openQuizPrint(resultQueryString)
{
	openWin(window.root + 'consumer/about_bph/prostate_quiz.aspx?prf=true&'+resultQueryString,'pop_up','width=800,height=700,scrollbars=yes');
}

function openSendToFriend(WindowURL,PageLink,ResultPage,WindowProperties,WindowWidth,WindowHeight) 
{
   window.open(window.root+WindowURL+'?PageLink='+PageLink+'&ResultPage=' + window.root + ResultPage,'Email_To_Friend',WindowProperties+',width='+WindowWidth+',height='+WindowHeight);
}

function gotoSearch(page,SearchText) {

   window.location = "search_results.aspx?page="+page+"&SearchText="+SearchText;
}

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_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";
       }
   }


   

