// 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 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()
	{
		return 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.');
	}


//popUp Windows
function popAsoClose()
	{
		window.close();
	}
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 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 (viewState)
		document.getElementById(obj).style.display = 'block';
	else
		document.getElementById(obj).style.display = 'none';
}
	
	







function demoPop(w,h,webaddress)
	{
var viewimageWin = window.open(webaddress,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=No,resizable=no,copyhistory=no,width='+w+',height='+h);

viewimageWin.moveTo(screen.availWidth/2-(w/2),220);
	}

function demoLegal(url)
{
  window.opener.location.href = 'http://www.bms.com/legal/data/'; 
  window.close();
}

function demoPrivacy(url)
{
  window.opener.location.href = 'http://www.orencia.com/orencia/channels/content.jsp?BV_UseBVCookie=Yes&channelName=Misc/200@Privacy_policy'; 
  window.close();
}

function demoRedirect(url)
{
  window.opener.location.href = 'result1.html'; 
  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();*/
} 

	
//This function now accepts a variable to pass to the pop up window	
function demo_leaving_Pop(website)
	{
		//this line was modified to pass the website data to the popup window
		window.open('leaving_pop.html?'+website, '_blank', 'width=400,height=250,top=0,left=0');
	}
	
//this function has two lines commented out that arent necessary for design testing they can be put back in when the time is appropritate.	
function demo_leaving_Redirect(url)
{
  window.close();
  //var queryString = new QueryString(); 
  //window.opener.location.href = 'http://maps.google.com/maps?hl=en&tab=wl' + '?zip=' + (queryString['zip']?queryString['zip']:"") + '&distance=' +  (queryString['distance']?queryString['distance']:""); 
	window.opener.location.href=url;
} 
