﻿// JScript File

// parse query string
function QueryString() { 
   var objQuery = new Object(); 
   var sSearch = document.location.search.substring(1); 
   if (sSearch.length > 0) { 
	 var asKeyValues = sSearch.split('&'); 
	 var asKeyValue = ''; 
	 for (var i = 0; i < asKeyValues.length; i++) { 
	   asKeyValue = asKeyValues[i].split('='); 
	   objQuery[asKeyValue[0]] = asKeyValue[1]; 
	 } 
  } 
   return objQuery; 
}

function validateSearch() {
	var val = document.forms[0].keyword.value;
	if (val == "" || val == null) {
		alert("Please type the word or words you wish to search for in the search box.");
	} else {
		location.href = 'Search.aspx?q=' + val;
	}
 }
 
function validateHCPSearch() {
	var val = document.forms[0].keyword.value;
	if (val == "" || val == null) {
		alert("Please type the word or words you wish to search for in the search box.");
	} else {
		location.href = 'HCPSearch.aspx?q=' + val;
	}
 }

function hivSpecCloseRedirect(url)
{
  var queryString = new QueryString(); 
  window.opener.location.href = url + '?zip=' + (queryString['zip']?queryString['zip']:"") + '&distance=' +  (queryString['distance']?queryString['distance']:""); 
  window.close();
    //window.opener.document.forms(0).submit();
    //opener.location.href = opener.location.href;
 /*   if (opener.location.href.toLowerCase().indexOf("asofinder.aspx")!=-1)
    {
     opener.submitASOFinder();
    }
    else 
    {
     var queryString = new QueryString(); 
     window.opener.location.href = url + '?zip=' + (queryString['zip']?queryString['zip']:"") + '&distance=' +  (queryString['distance']?queryString['distance']:""); 
    } 
    self.close();*/
} 
function alertEnter()
	{
	 if (document.cookie.indexOf("enterSite")==-1) 
	 {
	    window.alert('The information on this site is intended for residents of the United States who are 18 years of age or older.');
        var the_cookie = "enterSite";
	    document.cookie = "enterSite=1; path=/";
	 }
	}
	
function HCPalertEnter()
	{
	    if (document.cookie.indexOf("enterHCPSite")==-1) 
	    {
	       window.alert('The information on this site is intended for healthcare professionals in the United States.\n\n I certify that I am a Healthcare Professional licensed to practice in the United States.');
           var the_cookie = "enterHCPSite";
	       document.cookie = "enterHCPSite=1; path=/";
	    }
	}


//popUp Windows
function popAsoClose()
	{
		window.close();
}

function popFindAsoDisclaimer() {
    var zip = document.getElementById('ctl00_contentPlaceHolderMaster_txtZip').value; //document.forms[0].txtZip.value;
    
    var selectBoxCtl = document.getElementById('ctl00_contentPlaceHolderMaster_ddlDistance');
    var distance = selectBoxCtl.options[selectBoxCtl.selectedIndex].value;
    
    if (zip == "" || zip == null) {
        alert("Please enter a valid ZIP code.");
    }
    else if (!zip.match(/^\d{5}?$/)) {
        alert("Please enter a valid ZIP code.");
    }
    else if (distance == "" || distance == null) {
        alert("Please select a distance to search.");
    }
    else {
        url = 'ASODisclaimer.aspx?zip=' + zip + '&distance=' + distance;
        window.open(url, '_blank', 'width=400,height=400');
    }
}
	
function popAsoDisclaimer()
	{
		var zip = document.forms[0].asoZip.value;
		var distance = document.forms[0].asoDistance.value;
		if (zip == "" || zip == null) 
		{
			alert("Please enter a valid ZIP code.");
		}
		else if (!zip.match(/^\d{5}?$/))
		{
		    alert("Please enter a valid ZIP code.");
		}
		else if (distance == "" || distance == null) 
		{
		    alert("Please select a distance to search.");
		}
		else
		{
		    url = 'ASODisclaimer.aspx?zip=' + zip + '&distance=' + distance;
		    window.open(url, '_blank', 'width=400,height=400');
		}    
	}
	
	function popHCPAsoDisclaimer()
	{
		var zip = document.forms[0].asoZip.value;
		var distance = document.forms[0].asoDistance.value;
		if (zip == "" || zip == null) 
		{
			alert("Please enter a valid ZIP code.");
		}
		else if (!zip.match(/^\d{5}?$/))
		{
		    alert("Please enter a valid ZIP code.");
		}
		else if (distance == "" || distance == null) 
		{
		    alert("Please select a distance to search.");
		}
		else
		{
		    url = 'HCPASODisclaimer.aspx?zip=' + zip + '&distance=' + distance;
		    window.open(url, '_blank', 'width=400,height=400');
		}    
	}
function popAsoGlossary()
	{
		window.open('Glossary.aspx?type=ASOGlossary', '_blank', 'width=400,height=200');
	}
function popAsoServicesGlossary()
	{
		window.open('Glossary.aspx?type=ASOServicesGlossary', '_blank', 'width=400,height=675');
	}
function popHivSpecDisclaimer()
	{
		var zip = document.forms[0].hivZip.value;
		var distance = document.forms[0].hivDistance.value;
		if (zip == "" || zip == null) 
		{
			alert("Please enter a valid ZIP code.");
		}
		else if (!zip.match(/^\d{5}?$/))
		{
		    alert("Please enter a valid ZIP code.");
		}
		else if (distance == "" || distance == null) 
		{
		    alert("Please select a distance to search.");
		}
		else
		{
		    url = 'HIVSpecDisclaimer.aspx?zip=' + zip + '&distance=' + distance;
		    window.open(url, '_blank', 'width=400,height=400');
		}    
	}
function siteEnterPop()
	{
		window.open('siteEnterPop.html', '_blank', 'width=400,height=200');
	}
//confirms

function confirmLeave()
	{
		return window.confirm('By following this link, you are now leaving ATRIPLA.com. Bristol-Myers Squibb & Gilead Sciences, LLC provides these links as a convenience, but these sites are not controlled by Bristol-Myers Squibb & Gilead Sciences, LLC. Bristol-Myers Squibb & Gilead Sciences, LLC is not responsible for their content or your use of them. IF YOU WANT MEDICAL ADVICE, YOU SHOULD TALK TO YOUR DOCTOR.');
	}
	
function confirmLeaveHCP()
	{
		return window.confirm('By following this link, you are now leaving ATRIPLA.com. Bristol-Myers Squibb & Gilead Sciences, LLC provides these links as a convenience, but these sites are not controlled by Bristol-Myers Squibb & Gilead Sciences, LLC. Bristol-Myers Squibb & Gilead Sciences, LLC is not responsible for their content or your use of them.');
	}

//Zip code Clear
firstZip = 0;
firstZip2 = 0;
function clearZip(obj, num) {
	if ((obj.value == "ZIP code") && (firstZip == 0) && (num == 1)) {
			firstZip = 1;
			obj.value = "";
		}
		else if ((obj.value == "ZIP code") && (firstZip2 == 0) && (num == 2))
		{
			firstZip2 = 1;
			obj.value = "";
		}
}

function restoreZip(obj, num) {
	if (obj.value == "") {
		obj.value = "ZIP code";
		if(num == 1)
			firstZip = 0;
		else if(num == 2)
			firstZip2 = 0;
	}
}

//image rollovers
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_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_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];}
}
//end image rollovers

//Drop Down Menus
function SubMenuView(obj, viewState) {

    if (document.getElementById(obj) != null) {
        if (viewState)
            document.getElementById(obj).style.display = 'block';
        else
            document.getElementById(obj).style.display = 'none';
    }
}
function clearForm() 
{
    var allElements = document.getElementsByTagName("input");
    for (var i=0; i < allElements.length; i++)
    {
        if(allElements[i].type == "text")
        {
            allElements[i].value = "";
        }
    }
    var selectElements = document.getElementsByTagName("select");
    for (var x=0; x < selectElements.length; x++)
    {
        selectElements[x].selectedIndex = 0;
    }
}

//function AppendAmpToBreadcrumb() {
//  
//    var   href =new String(window.location.href);
//    if (href.indexOf("atripla-starter-kit") >= 0 && href.indexOf("?breadcrumb") >= 0) {
//        href = href.replace("?breadcrumb", "&breadcrumb");
//       }
//    
//    window.location = href;
//}	
	
