//function to fix the IE rollover 
function addEvent(obj, evType, fn)
{ 
 if (obj.addEventListener) {
  obj.addEventListener(evType, fn, false);
  return true;
  }
  else if (obj.attachEvent) {
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  }
  else  {
    return false;
  } 
}

addEvent(window, 'load', setClearing);
addEvent(window, 'load', sizeArticleContent);

function fixIE6flicker(fix) {
 try {
  document.execCommand("BackgroundImageCache", false, fix);
 } catch(err) { }
}
fixIE6flicker(true);

/*Fixes IE7's Article Layout's display*/
function setClearing()
{
	var features=$$('.feature_article');
	if(features[0])
	{
		var ieclearfix = $$('.feature_article .content.clearfix')
		var ieclearfixEl = $(ieclearfix[0]);
		if (ieclearfixEl) {
			ieclearfixEl.removeClassName('clearfix');
			ieclearfixEl.addClassName('articleclearfix');
		}
	}
}

function sizeArticleContent()
{
	var articleNode = $$('.regular_article .container .photo:empty');
	for (i=0;i<articleNode.length;i++)
	{
		if(articleNode[i])
		{
			var el = $(articleNode[i].parentNode);
			el.addClassName('fullwidth');
		}
	}
}

function toggler(el) 
{
	var obj = $(el);
	var listing = el.next();

	if (obj.hasClassName('expanded')) 
	{
		obj.removeClassName('expanded');
		listing.addClassName('hidden')
	}
	else 
	{
		obj.addClassName('expanded');
		listing.removeClassName('hidden')
	}

	return false;

}


//Global variable used to hold old CTA string
var oldSearchCTA = "";
var searchFocused = false;

//Hide the "search..." CTA string
function hideSearchCTA(ctrlName)
{
	var ctrl = document.getElementById(ctrlName);
	if ((ctrl) && (!searchFocused))
	{
		oldSearchCTA = ctrl.value;
		ctrl.value = "";
	}
}

//Show the CTA string "search..." if no search entered
function showSearchCTA(ctrlName)
{
	var ctrl = document.getElementById(ctrlName);
	
	if ((ctrl) && (ctrl.value.length == 0))
	{
		ctrl.value = oldSearchCTA;
		searchFocused = false;
	}
	else
		searchFocused = true;

}

//Return a tridion date string parsed to a Javascript date object
//Expected Tridion format is yyyy-mm-ddThh:mm:ss
function tridionToJSDate(dte)
{
	var result = new Date;
	
	result.setYear(dte.substring(0, 4));
	result.setMonth(Number(dte.substring(5, 7)) - 1);
	result.setDate(dte.substring(8, 10));
	result.setHours(dte.substring(11, 13));
	result.setMinutes(dte.substring(14, 16));
	result.setSeconds(dte.substring(17, 19));
	
	return result;
}

//Format the date to the company standard
function doDateFmt(dte) {

	alert('Input Date: '+ dte);
	var dteFmt = tridionToJSDate(dte);
	
	var m_names = new Array("January", "February", "March", 
	"April", "May", "June", "July", "August", "September", 
	"October", "November", "December");

	document.write(m_names[dteFmt.getMonth()] + ' ' + dteFmt.getDate() + ', ' + dteFmt.getFullYear());
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name, value, path)
{
    var expire = new Date();
    var today = new Date();
    if (!path)
        path = "/";
		
    expire.setTime(today.getTime() + 3600000*24*365);
    document.cookie= name + "=" + escape(value) + ";expires="+expire.toGMTString()+";path="+path;
}

function setTempCookie(name, value, path)
{
    var expire = new Date();
    var today = new Date();
    if (!path)
        path = "/";
		
    expire.setTime(today.getTime() + 3600000*1);
    document.cookie= name + "=" + escape(value) + ";expires="+expire.toGMTString()+";path="+path;
}

function Delete_Cookie( name, path, domain ) {
if ( getCookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function refreshRememberme(){
	var test= document.getElementById("RememberMe").checked;
	if(test==false)
		Delete_Cookie('eis_remeber_me', '/', '');
	
		//deleteCookie("eis_remeber_me", "/", "");
	
	setCookie('eis_fresher', '1', '/');	
}

function pollFilter(){
	var xmlHttpReq = false;
    	var self = this;
	var vote_cookie, res, pid, graph;
		
    	// Mozilla/Safari
    	if (window.XMLHttpRequest) {
        	self.xmlHttpReq = new XMLHttpRequest();
    	}
    	// IE
    	else if (window.ActiveXObject) {
       	self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	self.xmlHttpReq.open('POST', '/Poll', false);
    	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	if(document.getElementById("poll_id"))
		pid= document.getElementById("poll_id").value;
	else
		pid=0;
	
	vote_cookie= getCookie("voted_"+pid);
	if(vote_cookie!=null){
		var formDiv = document.getElementById("eisdp_poll_data");
		var resDiv = document.getElementById("eisdp_poll_results");

		var graphTypeCtrl = document.getElementById("graph_type"), graphType = "";
		if(graphTypeCtrl)
			graphType = "&graph_type=" + graphTypeCtrl.value;

		formDiv.style.display="none";
		resDiv.style.display="block";
		res = "mode=result&poll_id=" + pid+ graphType;
		self.xmlHttpReq.send(res);
		updatepage(self.xmlHttpReq.responseText);
    	}
}

function openPopupWindow(url)
{
	//window.open (url,"mywindow","width=450,height=768,left=275,top=0,menubar=0,toolbar=0,location=0,directories=0,resizable=0");
	//window.open (url,"mywindow","width=400,height=650,scrollbars=auto,resizable=yes,status=yes,toolbar=no,location=no,menubar=no");
	window.open (url,"mywindow","width=400,height=600,scrollbars=auto,resizable=yes,status=yes,toolbar=no,location=no,menubar=no");
}

function openTermsWindow(url)
{
	//window.open (url,"mywindow","width=450,height=768,left=275,top=0,menubar=0,toolbar=0,location=0,directories=0,resizable=0");
	//window.open (url,"mywindow","width=400,height=650,scrollbars=auto,resizable=yes,status=yes,toolbar=no,location=no,menubar=no");
	window.open (url,"mywindow","width=400,height=600,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no,menubar=no");
}

function openRefWindow(url)
{
	//window.open (url,"mywindow","width=450,height=768,left=275,top=0,menubar=0,toolbar=0,location=0,directories=0,resizable=0");
	//window.open (url,"mywindow","width=400,height=650,scrollbars=auto,resizable=yes,status=yes,toolbar=no,location=no,menubar=no");
	//window.open (url,"mywindow","width=400,height=300,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no,menubar=no");
                OpenWindow(url, "small");
}

function saveRefererCookie(cookieName)
{
	setCookie(cookieName,window.location.href);
}

function displayArticleTitle(name)
{
	var cookie = getCookie(name);
	if(cookie!=null) 
	{
		document.write(cookie);
	}
}

function OpenWindow(url, windowSize)
{
                trackClick(url);
	if(windowSize=="small")
                       window.open (url,"mywindow","width=400,height=300,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no,menubar=no");
                else
                        window.open (url,"window","width=770,height=500,top=50,left=125,location=1,status=1,scrollbars=1,menubar=1,toolbar=1,resizable=1");
}

//created by Hosam 
function trackClick(url){
                /* Modified By Hosam Elkhodary - Unilytics - 20070220
	   - Added functionality to attach an onclick for offsite or download. 
	*/
	l = document.createElement("A");
	l.setAttribute('href',url);
	// alert(l.hostname);
	// alert(WT.cg_n+" | "+WT.cg_s);
	if (l.hostname) {
  	if (dcsIsOnsite(l.hostname)){ // Onsite Link - Check if it is a link to a download document
    	// alert("ONsite - download");
  		var types="xls,doc,pdf,txt,csv,zip";
			var fileType=l.pathname.substring(l.pathname.lastIndexOf(".")+1,l.pathname.length);
    	if (types.indexOf(l.pathname.substring(l.pathname.lastIndexOf(".")+1,l.pathname.length))!=-1){
				WT.cg_n += ';Downloads';
				WT.cg_s += ';'+fileType;
    		var qry=l.search?l.search.substring(l.search.indexOf("?")+1,l.search.length):"";
    		if (qry.toUpperCase().indexOf("WT.SVL=")==-1){
    			WT.svl=dcsParseSvl(l.name?l.name.toString():(l.onclick?l.onclick.toString():""));
    		}
    		var path=l.pathname?((l.pathname.indexOf("/")!=0)?"/"+l.pathname:l.pathname):"/";
    		dcsMultiTrack("DCS.dcssip",l.hostname,"DCS.dcsuri",path,"DCS.dcsqry",l.search||"","WT.ti","Download:"+(path||""),"WT.dl","1");
    		DCS.dcssip=DCS.dcsuri=DCS.dcsqry=WT.ti=WT.svl=WT.dl="";
    	}
		}
  	else { // This is an offsite link
  	  // alert("Offsite");
			WT.cg_n += ';External Links';
			WT.cg_s += ';'+l.hostname;
			var qry=l.search?l.search.substring(l.search.indexOf("?")+1,l.search.length):"";
			if (qry.toUpperCase().indexOf("WT.SVL=")==-1){
				WT.svl=dcsParseSvl(l.name?l.name.toString():(l.onclick?l.onclick.toString():""));
			}
			var path=l.pathname?((l.pathname.indexOf("/")!=0)?"/"+l.pathname:l.pathname):"/";
			var trim=false; //Set to true/false to exclude/include the query parameters (see below trim?"":qry)
			dcsMultiTrack("DCS.dcssip",l.hostname,"DCS.dcsuri",path,"DCS.dcsqry",trim?"":qry,"WT.ti","Offsite:"+l.hostname+path+qry,"WT.os","1");
			DCS.dcssip=DCS.dcsuri=DCS.dcsqry=WT.ti=WT.svl=WT.os="";
		}
	}
}

function setPageTitle()
{
	var pageTitle = "   ";
	var titleArray = document.getElementsByTagName("h2");
	for (var i=0; i<titleArray.length; i++) {
		if (titleArray[i].innerHTML != null) {
			if (titleArray[i].id == "eis_page_title") {
				pageTitle = cleanText(titleArray[i].innerHTML);
				i=titleArray.length;
			}
		}
	}
	setCookie("CallingArticleTitle",pageTitle);
}

function cleanText(text)
{
	var newText = text;
	if (text.indexOf('">')>0)
	{
		if (text.substring(text.indexOf('">')+2).indexOf('</')>0)
		{
			newText = text.substring(text.indexOf('">')+2,text.indexOf('</'));
		}
		else newText = text.substring(text.indexOf('">')+2);
	}
	return newText;
}

function WriteDivForStaticContainer(tagID,classValue,IDType) {
	var returnValue = classValue;
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			if (key == 'Group_Name' && val.length>0) {
				returnValue = 'hidden';
				i = parms.length;
			}
		}
	}

	if (IDType == 'opening') {
		returnValue = '<' + tagID + ' class="' + returnValue + '">';
	}

	if (IDType == 'closing') {
		returnValue = '</' + tagID + '>';
	}

	return returnValue;
}

function resultPage()
{
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	var returnValue = false;
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
			if (key == 'result_page' && val.length>0) {
				returnValue = true;
				i = parms.length;
			}
		}
	}
	return returnValue;
}

//Generate client side computer date
function getCalendarDate()
{
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   
   var days= new Array(7);
   days[0]= "Sunday";
   days[1]= "Monday";
   days[2]= "Tuesday";
   days[3]= "Wednesday";
   days[4]= "Thursday";
   days[5]= "Friday";
   days[6]= "Saturday";
   
   var now         = new Date();
   var daynumber= now.getDay();
   var day= days[daynumber];
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getYear();
   if(year < 2000) { year = year + 1900; }
   var dateString = day + ", "+ monthname +
                    ' ' +
                    monthday +
                    ', ' +
                    year;
   return dateString;
} // function getCalendarDate()

//generate Client side clock time
function getClockTime()
{
   var now    = new Date();
   var hour   = now.getHours();
   var minute = now.getMinutes();
   var second = now.getSeconds();
   var ap = "AM";
   if (hour   > 11) { ap = "PM";             }
   if (hour   > 12) { hour = hour - 12;      }
   if (hour   == 0) { hour = 12;             }
   if (hour   < 10) { hour   = "0" + hour;   }
   if (minute < 10) { minute = "0" + minute; }
   if (second < 10) { second = "0" + second; }
   var timeString = hour +
                    ':' +
                    minute +
                    ':' +
                    second +
                    " " +
                    ap;
   return timeString;
} // function getClockTime()

//random header image rotator
function imageRotator(){
      var p = 2;
      var whichImage = Math.round(Math.random()*(p-1));
      var headerImage= document.getElementById("logo_image");
       headerImage.className = "logo"+whichImage ; 
} //function imageRotator()

//print years of option
function print_yr_option(start, end){
      document.write("<select><option>select a value</option>");
      for(var index=start; index<=end; index++){
                 document.write("<option value='"+index+"'>"+index+"</option>");
      }
      document.write("</select>");
} //function print_yr_option()

function textCounter(field,cntfield,maxlimit) {
     if (field.value.length > maxlimit) // if too long...trim it!
                field.value = field.value.substring(0, maxlimit);
      // otherwise, update 'characters left' counter
     else
                cntfield.value = maxlimit - field.value.length;
}

function showProfession(){
	updateCtrlsClass('Profession_container', ''); 
		//alert('not hidden');
}

function hideProfession(){
	updateCtrlsClass('Profession_container', 'hidden'); 
	document.reg.Profession_specialty.selectedIndex=-1;
}

function showAgencymailing(){
	document.reg.Mailing_adress1.value = document.reg.Agency_address.value
	document.reg.Mailing_adress2.value = document.reg.Agency_address2.value
	document.reg.Mailing_city.value = document.reg.City.value
	document.reg.Mailing_state.selectedIndex = document.reg.State.selectedIndex
	document.reg.Mailing_zip.value = document.reg.Zip.value
	updateCtrlsClass('Agency_mailing_container', ''); 	
}

function hideAgencymailing(){
	updateCtrlsClass('Agency_mailing_container', 'hidden'); 	
}

function show_mailing(){
	if(document.reg.Country.value=='United States')
		updateCtrlsClass('subscription_container', ''); 
	else
		updateCtrlsClass('subscription_container', 'hidden'); 
}

function showAllChecked()
{
var el, els = document.reg.Profession_Specialty.elements;
var x = '';
var i = els.length;
while(i--){
el = els[i];
if (el.checked){
x += '\n' + el.type + ': ' + el.value;
}
}
return x;
}

function changeSpecialtyCss(){
     if(document.reg.Profession.options[document.reg.Profession.selectedIndex].value=='Physician'){
           if(document.reg.Speciality_1.options[document.reg.Speciality_1.selectedIndex].value=='Oncology, Hematology/Oncology' ||
		document.reg.Speciality_1.options[document.reg.Speciality_1.selectedIndex].value=='Oncology, Medical' ||
		document.reg.Speciality_1.options[document.reg.Speciality_1.selectedIndex].value=='Oncology, Other' ||
		document.reg.Speciality_1.options[document.reg.Speciality_1.selectedIndex].value=='Oncology, Radiation' ||
		document.reg.Speciality_1.options[document.reg.Speciality_1.selectedIndex].value=='Surgery, Surgical Oncology'){
		updateCtrlsClass('cancer_type_container', '');
		 document.reg.Cancer_type.selectedIndex=0;
           }else{
		updateCtrlsClass('cancer_type_container', 'hidden');
		document.reg.Cancer_type.selectedIndex=0;
          }
     }
}



//unccheck subscription box if other country instead us is being selected
function uncheckSub(){
                var country= document.reg.Country.options[document.reg.Country.selectedIndex].value
                if(country == 'United States'){
                        for(var j=1; j<=4; j++){
                                box = eval("document.reg.Sub" + j);
                                box.checked = true;
                        }
                 }else{
                        for(var j=1; j<=4; j++){
                                box = eval("document.reg.Sub" + j);
                                box.checked = false;
                        }
                }
}  

function uncheckNewsletter(){
                for(var j=1; j<=20; j++){
                                box = eval("document.reg.Sub" + j);
		if(box)
		        box.checked = false;
                }
}

function uncheckOptoutBox(){
	document.reg.Optout.checked= false;
}


//function will truncate a textarea, set maxlength
function ismaxlength(obj)
{
	var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : 0
	var len = obj.value.length

	if (obj.getAttribute && len > mlength)
		obj.value=obj.value.substring(0, mlength)

	return Math.max(mlength - len, 0);
}                      

//This function updates the element with the passed ID
//  with the number of characters allowed to enter left
function maxLengthDisplay(obj, updID)
{
	var el = document.getElementById(updID);
	var val = String(ismaxlength(obj));

	if (el)
		el.innerHTML = val;
}            

//display hidden drop down menu
function display_pulldown(el) {
	//use radio button's value to identify which select menu to display
	var selectMenu;
	var selectContainers = document.getElementById(el.form.id).getElementsByTagName('div');
			
	//hide all select menu containers
	for (var i=0; i<selectContainers.length; i++) {
		if(cssjs('check',selectContainers[i],'showBlock')) {
			cssjs('swap',selectContainers[i],'showBlock','hidden');
		}
		else {
			cssjs('add',selectContainers[i],'hidden');
		}
	}

	var obj = document.getElementById(el.value + '_select');

	cssjs('swap',obj,'hidden','showBlock');
			
	// put focus on appropriate select menu;
	selectMenu = obj.getElementsByTagName('select');
	if (selectMenu.length >= 0) {
		selectMenu[0].focus();
	}
}      

function cssjs(a,o,c1,c2) {
	switch (a){
		case 'swap':
		o.className=!cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
		break;

		case 'add':
		if(!cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
		break;

		case 'remove':
		var rep=o.className.match(' '+c1)?' '+c1:c1;
		o.className=o.className.replace(rep,'');
		break;

		case 'check':
		return new RegExp('\\b'+c1+'\\b').test(o.className)
		break;
	}
}

//show or hidden profession fields by change patient handout div css between hidden and show
function changeHandoutCss(displayDiv, hiddenDiv, hiddenOption){
                document.handout.HandoutConditions.selectedIndex=0;
                document.handout.HandoutTreatments.selectedIndex=0;
                updateCtrlsClass(displayDiv, '');
                updateCtrlsClass(hiddenDiv, 'hidden');          
}

function addJournal(el) {
	var srcParent = el.parentNode.previousSibling;
	var src;
	var srcClone;
	if (srcParent.nodeName.indexOf('#text') >= 0) {
		srcParent = srcParent.previousSibling;
		}
	src = srcParent.getElementsByTagName('div');
	srcClone = src[0].cloneNode(true);
	srcClone.getElementsByTagName('input')[0].value='';
	document.getElementById(srcParent.id).appendChild(srcClone);
	}

function removeJournal (el) {
	var divContainer = el.parentNode;
	var divAncestor = divContainer.parentNode;
	var coll = divAncestor.getElementsByTagName('div');
	if (coll.length > 1) {
		var deletedNode = divAncestor.removeChild(divContainer);
		}
	}

//Attempt to capture the article title from the div with "eis_page_title" ID
function getArticleTitle () 
{
	var elTitle = document.getElementById("eis_page_title");

	//Capture article title if possible, otherwise use page title
	if (elTitle)
		return cleanText(elTitle.innerHTML);
	else
		return document.title;
}

function clearGroup(el) {
	var parent = el.parentNode;
	var selector = 'field';
	var inputFields;
	while (String(parent.className) != 'field') {
		parent = parent.parentNode;
		}
	inputFields = parent.getElementsByTagName('input');
	for (var i=0; i<inputFields.length; i++) {
		if (inputFields[i].type == 'text') {
			inputFields[i].value = '';
			}
		if (inputFields[i].type == 'checkbox') {
			inputFields[i].checked = '';
			}
		}
	}

function displayDateRange(selectObj,containerEl) {
	var showDateRange = 'specific';
	var container = document.getElementById('date_range_group');
	if (String(selectObj.options[selectObj.selectedIndex].value) == showDateRange) {
		cssjs('add',container,'showBlock');
		}
	else {
		if(cssjs('check',container,'showBlock')) {
			cssjs('remove',container,'showBlock');
			}
		}
	}


//=========================================
// JavaScript Document
// BY: Michale Cai
// CREATED: October 13, 2006
// ABSTRACT: Contains javascript functions used with the "seven feature items" forms in EIS Platform

//Name of  component/date we want to retrieve information for
var dateRetrieve = "";
var weekClass= "";

//Update the week div class
function updateDayTabClass(dayCode)
{
               var days= new Array(7);
               days[0]= "sunday";
               days[1]= "monday";
               days[2]= "tuesday";
               days[3]= "wednesday";
               days[4]= "thursday";
               days[5]= "friday";
               days[6]= "saturday";
 
               var this_date= new Date();                                       
               var ctrl= document.getElementById("week");
                if(ctrl!=null)
	        ctrl.className = "current_day"+dayCode;
                this_date.setDate(this_date.getDate()- dayCode);

               var request_month= this_date.getMonth()+1;
               var request_year= this_date.getFullYear();
               var request_day= this_date.getDate();
               var request_day_number= this_date.getDay();

               if(request_day<10)
	        request_day= "0"+request_day;
               if(request_month<10)
                        request_month= "0"+request_month;
               dateRetrieve= request_day+"/"+request_month+"/"+request_year;

               //alert("dateRetrieve is "+ dateRetrieve);	   
                
	//update the div featureDate content
	var featureDate = document.getElementById("featureDate");
	var featureDate_content= getFeatureDate(request_day_number, request_day, request_month, request_year);
                //temporarily disable this dynamic function for show dynamic date in the feature seven items home page, may be used in the future
	//featureDate.innerHTML = "<span>"+featureDate_content+"</span>";
			   
	//Ajax request
	xmlHTTPRetrievePost("/FeatureSeven", "featuresweek");  
}

function RefreshServerDateTime()
{
	//Ajax request
	xmlHTTPRetrievePost("/ServerDateTime", "datetime");  
}

function updateDayTabClassWithServerTime(dayCode)
{
               dateRetrieve= dayCode;
	//Ajax request
	xmlHTTPRetrievePost("/FeatureSeven", "feature");  
}

//Show the featured items for the selected day
//Show the featured items for the selected day
function changeItems(dayCode)
{
     //code for web trends
     trackHomeFeature(dayCode);

     //client side time 
     //updateDayTabClass(dayCode); 

    //server side time
    updateDayTabClassWithServerTime(dayCode);
}

//function for Web trends track Feature Seven
function trackHomeFeature(dayCode){
      if (dayCode!=0) {
            dcsuri_ORIG = DCS.dcsuri;
            ti_ORIG=WT.ti;
            var dayDelta = "_Previous_Day(-"+dayCode+")"; 
            var fileName = DCS.dcsuri.substring(DCS.dcsuri.lastIndexOf("/")+1);
            fileName = fileName.replace(/\./,dayDelta+"\.");
            var pathNoFile = DCS.dcsuri.substring(0,DCS.dcsuri.lastIndexOf("/")+1);
            var datedURI = pathNoFile+fileName;
            dcsMultiTrack("DCS.dcssip",DCS.dcssip,"DCS.dcsuri",datedURI,"DCS.dcsqry",DCS.dcsqry,"WT.ti",WT.ti+dayDelta,"WT.ajax","1");
            WTajax="";
            DCS.dcsuri=dcsuri_ORIG;
            WT.ti=ti_ORIG;
     }
}

//when page landed, generate the class for the div week
function refreshItems()
{
             var dayCode="0";

              //For Client time, disable it
              //updateDayTabClass(dayCode);  
 
             // For server time
             updateDayTabClassWithServerTime(dayCode);
}

//Post an XML HTTP Request for AJAX
function xmlHTTPRetrievePost(strURL, divName) 
{
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            populateItems(self.xmlHttpReq.responseText, divName);
        }
    }
	
    //Compose and send the request string
    self.xmlHttpReq.send("forDate=" + dateRetrieve);
}

//Update the page according to results returned from the AJAX request
// This code was taken from common.css originally written by Will Price
function populateItems(strResult, divName)
{
    //var ctrl = document.getElementById("featuresweek");
    var ctrl = document.getElementById(divName);

    //alert("populate");    
    if (ctrl) 
          ctrl.innerHTML = strResult;         		
}


//Does load testing script fire client-side JS?
function doJSLoadTest() 
{
    var xmlHttpReq = false;
    var self = this;
    var strURL = "/Comment";

    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            populateItems(self.xmlHttpReq.responseText);
        }
    }
	
	//Compose and send the request string
    self.xmlHttpReq.send("commentAction=post&uri=tcm:13-435-64&comment=load_test_JS_fired" );
}

//Generate client side computer date
function getFeatureDate(request_day_number, request_day, request_month, request_year)
{
   var months = new Array(13);
   months[0]  = "January";
   months[1]  = "February";
   months[2]  = "March";
   months[3]  = "April";
   months[4]  = "May";
   months[5]  = "June";
   months[6]  = "July";
   months[7]  = "August";
   months[8]  = "September";
   months[9]  = "October";
   months[10] = "November";
   months[11] = "December";
   
   var days= new Array(7);
   days[0]= "Sunday";
   days[1]= "Monday";
   days[2]= "Tuesday";
   days[3]= "Wednesday";
   days[4]= "Thursday";
   days[5]= "Friday";
   days[6]= "Saturday";      

   var day= days[request_day_number];
   var monthname   = months[request_month-1];
   var dateString = day + ", "+ monthname +
                    ' ' +
                    request_day +
                    ', ' +
                    request_year;
   return dateString;
} // function getFeatureDate()

//This function print out the month name for Feature Seven Items
//Param Daycode passing from template page
function printMonth(dayCode){
      var months = new Array(13);
      months[0]  = "Jan";
     months[1]  = "Feb";
     months[2]  = "Mar";
     months[3]  = "Apr";
     months[4]  = "May";
     months[5]  = "Jun";
     months[6]  = "Jul";
     months[7]  = "Aug";
     months[8]  = "Sep";
     months[9]  = "Oct";
     months[10] = "Nov";
     months[11] = "Dec";

      var this_date= new Date();   
      this_date.setDate(this_date.getDate()- dayCode);
      var request_month= months[this_date.getMonth()];
      document.write(request_month);
}

//This function print out name of day for Feature Seven Items
function printDay(dayCode){
    var this_date= new Date();   
      this_date.setDate(this_date.getDate()- dayCode);
      var request_day= this_date.getDate();
      document.write(request_day);
} //fucntion printDay

function doClear(elementId)
{
	var el = document.getElementById(elementId);
	if ((el)  && (!focused))
	{
		focused = true;
		el.value = '';
	}
}

//*************Following code is for Gold standard Web Service Application

//Ajax Call for Web Service
function getSearchResult(strURL) 
{
    var searchString= document.getElementById("gsSearch").value;
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            populateContent(self.xmlHttpReq.responseText, "goldStandard_results");
        }
    }
	
    //Compose and send the request string
    self.xmlHttpReq.send("gsSearch=" + searchString);
 }

//Ajax Call for Web Service for getMonograph web service result
function getMonographWebService(strURL, divId, intCpnum) 
{
   //alert("I am here");    
    updateCtrlsClass('webservice', 'hidden');    
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
   self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            populateContent(self.xmlHttpReq.responseText, divId);
        }
    }

    //Compose and send the request string
    self.xmlHttpReq.send("intCpnum="+intCpnum);    
}

function populateContent(strResult, divId)
{
    var ctrl = document.getElementById(divId);
    //alert("populate");    
    if (ctrl) 
          ctrl.innerHTML = strResult;    
    updateCtrlsClass(divId, "");  		
}

function checkEnter(e){
        //literal character code will be stored in this variable
       var characterCode;
       if(e && e.which){ //if which property of event object is supported (NN4)
              e = e
              characterCode = e.which //character code is contained in NN4's which property
       }
       else{
              e = event
              characterCode = e.keyCode //character code is contained in IE's keyCode property
       }
        
       if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
               // Web Service Call
               getSearchResult('/GoldStandard');
               return true;
       }
}

var current_photo=0;
function getNextDrugPhoto(photo_length){
       if(current_photo<(photo_length-1)){

           var photo_pre= "photo"+ current_photo;
           var des_pre= "des"+ current_photo;
           updateCtrlsClass(photo_pre, "hidden");
           updateCtrlsClass(des_pre, "hidden");

           current_photo= current_photo+1;
           var photo_current= "photo"+ current_photo;
           var des_current= "des"+current_photo;
           updateCtrlsClass(photo_current, "");
           updateCtrlsClass(des_current, "");
           
       }else{
           current_photo= photo_length-1;
       }            
}

function getPreDrugPhoto(photo_length){
       if(current_photo>0){

           var photo_pre= "photo"+ current_photo;
           var des_pre= "des"+ current_photo;
           updateCtrlsClass(photo_pre, "hidden");
           updateCtrlsClass(des_pre, "hidden");

           current_photo= current_photo-1;
           var photo_current= "photo"+ current_photo;
           var des_current= "des"+current_photo;
           updateCtrlsClass(photo_current, "");
           updateCtrlsClass(des_current, "");
           
       }else{
           current_photo= 0;
       }            
}

//********************preview 7 Feature Items Javascript function**********************************
var preview_current=0;
function previewUpdateDayTabClass(dayCode)
{
               var days= new Array(7);
               days[0]= "sunday";
               days[1]= "monday";
               days[2]= "tuesday";
               days[3]= "wednesday";
               days[4]= "thursday";
               days[5]= "friday";
               days[6]= "saturday";
 
               var this_date= new Date(); 
               //alert("preview current is "+	preview_current);	   
			   this_date.setDate(this_date.getDate()+ preview_current);
               var ctrl= document.getElementById("week");
               if(ctrl!=null)
					ctrl.className = "current_day"+dayCode;
                this_date.setDate(this_date.getDate()- dayCode);

               var request_month= this_date.getMonth()+1;
               var request_year= this_date.getFullYear();
               var request_day= this_date.getDate();
               var request_day_number= this_date.getDay();

               if(request_day<10)
	        request_day= "0"+request_day;
               if(request_month<10)
                        request_month= "0"+request_month;
               dateRetrieve= request_day+"/"+request_month+"/"+request_year;

               //alert("dateRetrieve is "+ dateRetrieve);	   
                
	//update the div featureDate content
	var featureDate = document.getElementById("featureDate");
	var featureDate_content= getFeatureDate(request_day_number, request_day, request_month, request_year);
                //temporarily disable this dynamic function for show dynamic date in the feature seven items home page, may be used in the future
	//featureDate.innerHTML = "<span>"+featureDate_content+"</span>";
			   
	//Ajax request
	//xmlHTTPRetrievePost("/FeatureSeven");  
                xmlHTTPRetrievePost("/FeatureSeven", "featuresweek");  
}


//Show the featured items for the selected day
function previewChangeItems(dayCode)
{
                //client time
	previewUpdateDayTabClass(dayCode);	
}

function previewPrintMonth(dayCode){
      var months = new Array(13);
      months[0]  = "Jan";
     months[1]  = "Feb";
     months[2]  = "Mar";
     months[3]  = "Apr";
     months[4]  = "May";
     months[5]  = "Jun";
     months[6]  = "Jul";
     months[7]  = "Aug";
     months[8]  = "Sep";
     months[9]  = "Oct";
     months[10] = "Nov";
     months[11] = "Dec";
      var this_date= new Date(); 
	  this_date.setDate(this_date.getDate()+ preview_current);
      this_date.setDate(this_date.getDate()- dayCode);
      var request_month= months[this_date.getMonth()];
	  var preview_month = document.getElementById("month"+dayCode);
	  preview_month.innerHTML = "<span>"+request_month+"</span>";
      //document.write(request_month);
}

function previewPrintDay(dayCode){
    var this_date= new Date();  
     this_date.setDate(this_date.getDate()+ preview_current);	
      this_date.setDate(this_date.getDate()- dayCode);
      var request_day= this_date.getDate();
      var preview_day = document.getElementById("date"+dayCode);
      preview_day.innerHTML = request_day;
      //document.write(request_day);
}

function previewRefreshItems()
{
             //var dayCode="0";
              //previewUpdateDayTabClass(dayCode);      
			previewPrintMonth("0"); 
			previewPrintMonth("1"); 
			previewPrintMonth("2");
			previewPrintMonth("3");  
			previewPrintMonth("4"); 
			previewPrintMonth("5");
			previewPrintMonth("6");

            previewPrintDay("0");
			previewPrintDay("1");
			previewPrintDay("2");
			previewPrintDay("3");
			previewPrintDay("4");
			previewPrintDay("5");
			previewPrintDay("6");
}

//*******************end functions for preview 7 Feature Items javascript function***********************************

//code from Matt
function getStyle(obj, style){
	if(!document.getElementById) return;

	var obj = document.getElementById(obj);
	var value = obj.style[style];

	if(!value)
		if(document.defaultView)
			value = document.defaultView.
			getComputedStyle(obj, "").getPropertyValue(style);

		else if(obj.currentStyle)
			value = obj.currentStyle[style];

	return value;
}

//toggle results
function toggleGs(dir) {
	var direction = dir;
	var gs_carousel = $('carousel');

	var gs_photo = $('carousel_photo');
	var gs_description = $('carousel_des');
	var gs_page = $('page_amt');

	var gs_photo_coll = gs_photo.getElementsByTagName("DIV");
	var gs_description_coll = gs_description.getElementsByTagName("DIV");
	var gs_page_coll = gs_page.getElementsByTagName("DIV");
	
	var current = -1;

	var nav_back = $('carousel_nav_back');
	var nav_fwd = $('carousel_nav_fwd');
	var nav_delim = $('carousel_nav_delim');

	//hide current visible elements, copy it's position in the array
	for (var i=0; i<gs_photo_coll.length; i++) {
		var photo_el = $(gs_photo_coll[i].id);
		var description_el = $(gs_description_coll[i].id);
		var page_el = $(gs_page_coll[i].id);
		if (getStyle(photo_el.id,'display').indexOf('block') > -1) {
			photo_el.style.display = 'none';
			description_el.style.display = 'none';
			page_el.style.display = 'none';
			current = i;
		}

	}
	
	// display next group of elements
	if (current > -1) {
		if (direction.indexOf('forward') > -1&& current < (gs_photo_coll.length-1)) {
			current+=1;
		}
		if (direction.indexOf('back') > -1 && current) {
			current-=1;
		}

		var photo_el = $(gs_photo_coll[current].id);
		var description_el = $(gs_description_coll[current].id);
		var page_el = $(gs_page_coll[current].id);
		photo_el.style.display = 'block';
		description_el.style.display = 'block';
		page_el.style.display = 'block';
		nav_back.style.visibility = 'visible';
		nav_delim.style.visibility = 'visible';
		nav_fwd.style.visibility = 'visible';

		if ((current > 0) && (current < gs_photo_coll.length-1)) {
			nav_back.style.visibility = 'visible';
			nav_delim.style.visibility = 'visible';
			nav_fwd.style.visibility = 'visible';
		}

		else if (current == 0) {
			nav_back.style.visibility = 'hidden';
			nav_delim.style.visibility = 'hidden';
		}

		else if (current == gs_photo_coll.length-1) {
			nav_fwd.style.visibility = 'hidden';
			nav_delim.style.visibility = 'hidden';
		}


	}

}

function panelOpen() {
	if(cssjs('check',document.getElementById('ipanel'),'ipanel_closed')) {
		cssjs('swap',document.getElementById('ipanel'),'ipanel_closed','ipanel_open');
		cssjs('swap',document.getElementById('ipanel_content'),'ipanel_content_narrow','ipanel_content_wide');
	}
}
	
function panelClose() {
	if(cssjs('check',document.getElementById('ipanel'),'ipanel_open')) {
		cssjs('swap',document.getElementById('ipanel'),'ipanel_open','ipanel_closed');
		cssjs('swap',document.getElementById('ipanel_content'),'ipanel_content_wide','ipanel_content_narrow');
	}
}

//displays main feature content section and sets tab states
function setMainfeature(el) {
	var amt = $$('#topstories_container .content_container .feature');
	var lnkAmt = $$('#mainfeature_tabs a');
	var section;
	for (var i=0;i<lnkAmt.length;i++) {
		if (el == lnkAmt[i]) {
			section = i;
		}
	}

	for (var j=0;j<lnkAmt.length;j++) {
		if (j != section) {
			if (amt[j].hasClassName('showBlock')) {
				amt[j].removeClassName('showBlock');
				amt[j].addClassName('hidden');
			}
			if (lnkAmt[j].hasClassName('active')) {
				lnkAmt[j].removeClassName('active');
			}
		}
		else {
			amt[j].removeClassName('hidden');
			amt[j].addClassName('showBlock');
			lnkAmt[j].addClassName('active');
		}
	}
}

function resendReg(form){
	//document.ref_ref.reg_ref_url.value= window.location.pathname;
	setTempCookie("reg_ref_url",window.location.pathname);
	//alert("I am here");
	return true;
}


//end code from Matt

function OpenCompanyWindow(url)
{
              OpenWindow(url,"width=400,height=600,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no,menubar=no");
}


function ClickThru(CTurl, cat, subCat, AdType, CTAdName, CTCompany)
{
//	alert("cat: " + cat + ", subCat: " + subCat + ", AdType:" + AdType +
//		", name: " + name + ", rep_name: " + rep_name);
/**==WEBTRENDS REMOVED

	DCSext.pAds=DCSext.cAds=DCSext.scAds=DCSext.adAction="";
	domainStart=CTurl.indexOf('//')+2;
	firstWAC=CTurl.indexOf('/',domainStart);
	CTDomain=CTurl.substring(domainStart,(firstWAC==-1)?CTurl.length:firstWAC);
	CTDomain=(CTDomain.indexOf(':')==-1)?CTDomain:CTDomain.substring(0,CTDomain.indexOf(':'));
	CTuri=(firstWAC==-1)?'/':CTurl.substring(firstWAC,(CTurl.indexOf('?',firstWAC)==-1)?CTurl.length:CTurl.indexOf('?'));
	// alert(CTDomain+" | "+CTuri);
	//Query string for offsite link is not captured for analysis
	if (AdType=='P') {
		tiText='Product Ad ClkThru: ';
		dcsMultiTrack("DCS.dcssip",CTDomain,"DCS.dcsuri",CTuri,"DCS.dcsqry","","WT.ti",tiText+CTAdName,"DCSext.pAds",CTAdName,"WT.os","1","DCSext.adAction","CT");
	}
	else {
		if (AdType=='SC') {
			tiText='Sponsored Co. ClkThru: ';
			dcsMultiTrack("DCS.dcssip",CTDomain,"DCS.dcsuri",CTuri,"DCS.dcsqry","","WT.ti",tiText+CTAdName,"DCSext.scAds",CTAdName,"WT.os","1","DCSext.adAction","CT");
		}
		else {
			if (AdType=='C') {
				tiText='Company ClkThru: ';
				dcsMultiTrack("DCS.dcssip",CTDomain,"DCS.dcsuri",CTuri,"DCS.dcsqry","","WT.ti",tiText+CTAdName,"DCSext.cAds",CTAdName,"WT.os","1","DCSext.adAction","CT");
			}
		}
	}
  DCS.dcssip=DCS.dcsuri=DCS.dcsqry=WT.ti=WT.svl=WT.os=DCSext.cAds=DCSext.scAds=DCSext.pAds=DCSext.adAction="";

==WEBTRENDS REMOVED**/

	OpenWindow(CTurl);
}

function submitRelProdCatFrm(id, facetVal)
{
	document.getElementById("facet_Product_Categories_" + id).value = facetVal;
	document.getElementById("frmProdCat_" + id).submit();
}

//Get querystring request paramter in javascript
function getParameter (parameterName ) {

   var queryString = window.top.location.search.substring(1);

   // Add "=" to the parameter name (i.e. parameterName=value)
   var parameterName = parameterName + "=";
   if ( queryString.length > 0 ) {
      // Find the beginning of the string
      begin = queryString.indexOf ( parameterName );
      // If the parameter name is not found, skip it, otherwise return the value
      if ( begin != -1 ) {
         // Add the length (integer) to the beginning
         begin += parameterName.length;
         // Multiple parameters are separated by the "&" sign
         end = queryString.indexOf ( "&" , begin );
      if ( end == -1 ) {
         end = queryString.length
      }
      // Return the string
      return unescape ( queryString.substring ( begin, end ) );
   }
   // Return "null" if no parameter has been found
   return "null";
   }
}

//WebTrends has been removed but there are many references
//to the DCSext object. Make a bogus object to prevent errors
var DCSext = new Object();

//==================END COMMON JS===