// JavaScript Document

hom = new Image(92,33);
hom.src = "/images/hwrc/home.jpg"
homh = new Image(92,33);
homh.src = "/images/hwrc/homeRollOver.jpg"

diseases = new Image(92,33);
diseases.src = "/images/hwrc/diseasesConditions.jpg"
diseasesh = new Image(92,33);
diseasesh.src = "/images/hwrc/diseasesConditionsRollOver.jpg"

alternative = new Image(92,33);
alternative.src = "/images/hwrc/alternativeMedicine.jpg"
alternativeh = new Image(92,33);
alternativeh.src ="/images/hwrc/alternativeMedicineRollOver.jpg"

drugs = new Image(92,33);
drugs.src = "/images/hwrc/drugs.jpg"
drugsh = new Image(92,33);
drugsh.src = "/images/hwrc/drugsRollOver.jpg"

directory = new Image(92,33);
directory.src = "/images/hwrc/directory.jpg"
directoryh = new Image(92,33);
directoryh.src = "/images/hwrc/directoryRollOver.jpg"

advancedHeaderButton = new Image(92,33);
advancedHeaderButton.src = "/images/hwrc/advancedSearch.jpg"
advancedHeaderButtonh = new Image(92,33);
advancedHeaderButtonh.src = "/images/hwrc/advancedSearchRollOver.jpg"

dictionary = new Image(92,33);
dictionary.src = "/images/hwrc/dictionary.jpg"
dictionaryh = new Image(92,33);
dictionaryh.src = "/images/hwrc/dictionaryRollOver.jpg"

other = new Image(92,33);
other.src = "/images/hwrc/otherSites.jpg"
otherh = new Image(92,33);
otherh.src = "/images/hwrc/otherSitesRollOver.jpg"

profiler = new Image(92,33);
profiler.src = "/images/hwrc/diseaseProfiler.jpg"
profilerh = new Image(92,33);
profilerh.src = "/images/hwrc/diseaseProfilerRollOver.jpg"

health = new Image(92,33);
health.src = "/images/hwrc/healthAssesment.jpg"
healthh = new Image(92,33);
healthh.src = "/images/hwrc/healthAssesmentRollOver.jpg"

books = new Image(92,33);
books.src = "/images/hwrc/booksFactsSheets.jpg"
booksh = new Image(92,33);
booksh.src = "/images/hwrc/booksFactsSheets.jpg"

magazine = new Image(92,33);
magazine.src = "/images/hwrc/magazinesJournals.jpg"
magazineh = new Image(92,33);
magazineh.src = "/images/hwrc/magazinesJournals.jpg"

drugresult = new Image(92,33);
drugresult.src = "/images/hwrc/drugsSearch.jpg"
drugresulth = new Image(92,33);
drugresulth.src = "/images/hwrc/drugsSearch.jpg"

pamphlet = new Image(92,33);
pamphlet.src = "/images/hwrc/pamphlets.jpg"
pamphleth = new Image(92,33);
pamphleth.src = "/images/hwrc/pamphlets.jpg"

video = new Image(92,33);
video.src = "/images/hwrc/videoRollOver.jpg"
videoh = new Image(92,33);
videoh.src = "/images/hwrc/videoRollOver.jpg"

news = new Image(92,33);
news.src = "/images/hwrc/news.jpg"
newsh = new Image(92,33);
newsh.src = "/images/hwrc/news.jpg"


function img_act (tag) 
{
    document[tag].src = eval(tag + "h.src");
}
function img_inact (tag) 
{
    document[tag].src = eval(tag + ".src");
}

function showTag()
{
    var id=document.getElementById('divTag');
    var more=document.getElementById('more');
    if(id.style.display=="block")
    {
       id.style.display="none";
       more.innerHTML="More>>";
    }
    else
    {
     id.style.display="block";
     more.innerHTML="Hide>>";
    }
}

function clearMain()
{
    document.sgSearch.SU.value='';
    document.sgSearch.aci.checked=false;
    document.sgSearch.aii.checked=false;
    document.sgSearch.month1.options[0].selected=true;
    document.sgSearch.month2.options[0].selected=true;
    document.sgSearch.day1.options[0].selected=true;
    document.sgSearch.day2.options[0].selected=true;
    document.sgSearch.year1.options[0].selected=true;
    document.sgSearch.year2.options[0].selected=true;
    document.sgSearch.SU.focus();
}
function clearSU()
{
    document.sgSearch.SU.value='';
    document.sgSearch.spa.checked=false;
    document.sgSearch.aci.checked=false;
    document.sgSearch.aii.checked=false;
    document.sgSearch.chi.checked=false;
    document.sgSearch.basicSearchOption[0].checked=true;
}
function clearOrg()
{
    document.healthOrgSearch.KE.value='';
    document.healthOrgSearch.CY.value='';
    document.healthOrgSearch.ST.options[0].selected=true;  
    document.healthOrgSearch.KE.focus();
}
function clearNews()
{
    document.News.KE.value='';
    document.News.SO.value='';
    document.News.month1.options[0].selected=true;
    document.News.month2.options[0].selected=true;
    document.News.day1.options[0].selected=true;
    document.News.day2.options[0].selected=true;
    document.News.year1.options[0].selected=true;
    document.News.year2.options[0].selected=true;
    document.News.newsop[0].checked=true;
    document.News.KE.focus();
}
function clearDrug()
{
    document.drugHerbSearch.FT.value='';
    document.drugHerbSearch.FT.focus();
}
function clearDict()
{
    document.dictionary.m.value='';
    document.dictionary.k[0].checked=true;
    document.dictionary.m.focus();
}
function clearAdv()
{
    document.advanced.text1.value='';
    document.advanced.text2.value='';
    document.advanced.text3.value='';
    document.advanced.index1.options[0].selected=true;
    document.advanced.index2.options[0].selected=true;
    document.advanced.index3.options[0].selected=true;
    document.advanced.op1.options[0].selected=true;
    document.advanced.op2.options[0].selected=true;
    document.advanced.aci.checked=false;
    document.advanced.aii.checked=false;
    document.advanced.chi.checked=false;
    document.advanced.czi.checked=false;
    document.advanced.spa.checked=false;
    document.advanced.month1.options[0].selected=true;
    document.advanced.month2.options[0].selected=true;
    document.advanced.day1.options[0].selected=true;
    document.advanced.day2.options[0].selected=true;
    document.advanced.year1.options[0].selected=true;
    document.advanced.year2.options[0].selected=true;
    document.advanced.text1.focus();
}
function testHealthSearchEmpty()
{
    var textBoxValue = new String(document.healthOrgSearch.KE.value);
    if (document.healthOrgSearch.KE.value.length<=0)
    {
        alert("Please enter Search Term ");
        document.healthOrgSearch.KE.focus();
        return false;
    }else if(textBoxValue.match(/ /) && !textBoxValue.match(/([a-z]|[0-9])/i))
    {
        alert("Please enter Search Term ");
        document.healthOrgSearch.KE.focus();
        return false;
    }
}


function testEmpty()
{
    var textBoxValue = new String(document.sgSearch.SU.value);
    if (document.sgSearch.SU.value.length<=0)
    {
        alert("Please enter Search Term");
        document.sgSearch.SU.focus();
        return false;
    }
    else
    {
        var SUval = document.sgSearch.SU.value;
        var openpLoc = SUval.indexOf("(");
        var clospLoc = SUval.indexOf(")");
        var quoteLoc = SUval.indexOf("\"");
        if ((openpLoc >= 0) && (quoteLoc == -1))
        {
            var SUleft = leftString(SUval,openpLoc);
            var SUmid = middleString(SUval,openpLoc + 1,clospLoc);
            if ((SUval.length) > (clospLoc + 1))
            {
                SUright = rightString(SUval,SUval.length - clospLoc - 1);
                SUval = SUleft + SUmid + SUright;
            }
            else
            {
                SUval = SUleft + SUmid;
            }
            document.sgSearch.SU.value = SUval;
            return true;
        }
   }
}

function checkEmptyAfterFilter(textBoxValue) {
  var addPattern = /[-\\+\\s]/g
  var removePattern = /('s|%22|&amp;|[!\\*\\?:&'"])/g
  var removeSequencePattern = /_+/g 
  var removeBeginandEndPattern = /^_+|_+$/g

  textBoxValue = textBoxValue.replace(addPattern,'_');
  textBoxValue = textBoxValue.replace(removeSequencePattern,'_')
  textBoxValue = textBoxValue.replace(removePattern,'')
  textBoxValue = textBoxValue.replace(removeBeginandEndPattern,'')

  if(textBoxValue.length == 0) {
        alert("Please enter Valid Search Term in first input box");
        document.advanced.text1.focus();
        return false;
  }
  return true;

}
function testAdvEmpty()
{
    var textBoxValue = new String(document.advanced.text1.value);
    if (document.advanced.text1.value.length<=0)
    {
        alert("Please enter Search Term in first input box");
        document.advanced.text1.focus();
        return false;
    }else if(textBoxValue.match(/ /) && !textBoxValue.match(/([a-z]|[0-9])/i))
    {
        alert("Please enter Search Term in first input box");
        document.advanced.text1.focus();
        return false;
    }else {
        return checkEmptyAfterFilter(document.advanced.text1.value);
    }
}
function testDrugEmpty()
{
    var textBoxValue = new String(document.drugHerbSearch.FT.value);
    if (document.drugHerbSearch.FT.value.length<=0)
    {
        alert("Please enter Search Term");
        document.drugHerbSearch.FT.focus();
        return false;
    }else if(textBoxValue.match(/ /) && !textBoxValue.match(/([a-z]|[0-9])/i))
    {
        alert("Please enter Search Term");
        document.drugHerbSearch.FT.focus();
        return false;
    }
}
function testSymptomEmpty()
{
    var textBoxValue = new String(document.drugSymtomSearch.ST.value);
    if (document.drugSymtomSearch.ST.value.length<=0)
    {
        alert("Please enter Search Term");
        document.drugSymtomSearch.ST.focus();
        return false;
    }else if(textBoxValue.match(/ /) && !textBoxValue.match(/([a-z]|[0-9])/i))
    {
        alert("Please enter Search Term");
        document.drugSymtomSearch.ST.focus();
        return false;
    }
}
function leftString (InString, num)
{
      OutString = InString.substring(InString, num);
      return (OutString);
}
function middleString (InString, lnum, rnum)
{
      OutString = InString.substring(lnum, rnum);
      return (OutString);
}
function rightString (InString, num)
{
      OutString = InString.substring(InString.length-num, InString.length);
      return (OutString);
}
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_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_findObj(n, d)
{ //v3.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); 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];}
}
//rollover function:
function img_act (tag)
{
        document [tag].src = eval(tag + "h.src");
}
function img_inact (tag)
{
        document [tag].src = eval(tag + ".src");
}
function popWindow(url)
{
     var loc = "/hwrc/HWRCtemplate.htm?"+url;
    calcAndPullUp(loc,"remotewinlegend",600,580,1);
}
// For Healthology video list.
function doSVvideo(vid)
{
     var url = "/servlet/HWRC/hits?docNum=DU2600000002&year2=&year1=&index3=KE&index2=KE&index1=RN&tcit=1_0_0_0_0&locID=gale&rlt=1&text3=&text2=&origSearch=true&text1=DU2600000002&op2=AND&op1=AND&t=RK&s=11&r=d&items=0&o=&secondary=false&n=10&day2=&l=d&day1=&sgPhrase=false&month2=&month1=&c=1&bucket=usage&healthology=video&f="+vid
    calcAndPullUpSV(url,"remotewinlegend",screen.width,screen.height,1);
}
// For Healthology keyword search.
function doSVsearch(kw)
{
     var url = "/servlet/HWRC/hits?docNum=DU2600000002&year2=&year1=&index3=KE&index2=KE&index1=RN&tcit=1_0_0_0_0&locID=gale&rlt=1&text3=&text2=&origSearch=true&text1=DU2600000002&op2=AND&op1=AND&t=RK&s=11&r=d&items=0&o=&secondary=false&n=10&day2=&l=d&day1=&sgPhrase=false&month2=&month1=&c=1&bucket=usage&healthology=text&keyword="+kw
    calcAndPullUpSV(url,"remotewinlegend",screen.width,screen.height,1);
return false;
}
function doSVsub(event, kw) {
  if ((event && event.which == 13) || (window.event && window.event.keyCode == 13))
    { doSVsearch(kw);
      return false; }
  else
    return true;}
   function calcAndPullUp( pageToLoad, winName, width, height, center)
   {
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center))
    {
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + "," + "height=" + height + "," + "location=0," + "menubar=0," + "resizable=1," + "scrollbars=0," + "status=0," + "titlebar=0," + "toolbar=0," + "hotkeys=0," + "screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + "," + "top=" + yposition;
    window.open( pageToLoad,winName,args);
   }
   function calcAndPullUpSV( pageToLoad, winName, width, height, center)
   {
    xposition=0; yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (center))
    {
        xposition = (screen.width - width) / 2;
        yposition = (screen.height - height) / 2;
    }
    args = "width=" + width + "," + "height=" + height + "," + "location=0," + "menubar=0," + "resizable=1," + "scrollbars=1," + "status=0," + "titlebar=0," + "toolbar=0," + "hotkeys=0," + "screenx=" + xposition + "," + "screeny=" + yposition + "," + "left=" + xposition + "," + "top=" + yposition;
    window.open( pageToLoad,winName,args);
   }
// For disease profiler info window.
function popDPWindow(url)
{
    calcAndPullUp("/servlet/HWRC/hits?docNum=DU2600000001&year2=&year1=&index3=KE&index2=KE&index1=RN&tcit=1_0_0_0_0&locID=gale&rlt=1&text3=&text2=&origSearch=true&text1=DU2600000001&op2=AND&op1=AND&t=RK&s=11&r=d&items=0&o=&secondary=false&n=10&day2=&l=d&day1=&sgPhrase=false&month2=&month1=&c=1&bucket=usage","remotewinlegend",600,580,1);
}
function popSVWindow(url)
{
    calcAndPullUpSV("/servlet/HWRC/hits?docNum=DU2600000002&year2=&year1=&index3=KE&index2=KE&index1=RN&tcit=1_0_0_0_0&locID=gale&rlt=1&text3=&text2=&origSearch=true&text1=DU2600000002&op2=AND&op1=AND&t=RK&s=11&r=d&items=0&o=&secondary=false&n=10&day2=&l=d&day1=&sgPhrase=false&month2=&month1=&c=1&bucket=usage&healthology=qsearch","remotewinlegend",screen.width,screen.height,1);
}


var checkflag = "false";
function check(field) {
    
    if(field.length != null)
    {
        if (checkflag == "false") 
        {
            for (i = 0; i < field.length; i++) 
            {
                field[i].checked = true;
            }
            checkflag = "true";
            return ""; 
        }
        else 
        {
            for (i = 0; i < field.length; i++) 
            {
                field[i].checked = false; 
            }
            checkflag = "false";
            return ""; 
            }
    }else{
        if (checkflag == "false") 
        {
            field.checked = true;
            checkflag = "true";
            return ""; 
        }
        else {
            field.checked = false; 
            checkflag = "false";
            return ""; 
        }
    }
}

function particularCheck(field)
{
    var checkAllFlag = true;
    if(field != null){
    if(field.length != null)
    {
        for (i = 0; i < field.length; i++) 
        {
            if (field[i].checked == true)
            {
                checkAllFlag = true;
            }
            else
            {
                checkAllFlag = false;
                i= field.length;
            }
        }   
    }else{
        if (field.checked == true)
        {
            checkAllFlag == true;
        }
        else
        {
            checkAllFlag = false;
        }
    }
    if(checkAllFlag)
    {   
        document.getElementById("overallCheck").checked=true;
        checkflag = "true";
    }
    else
    {
        document.getElementById("overallCheck").checked=false;
        checkflag = "false";
    }
    }
}


function echeck(str) {

        var at="@"
        var dot="."
        var lat=str.indexOf(at)
        var lstr=str.length
        var ldot=str.indexOf(dot)
        if (str.indexOf(at)==-1){
           alert("Invalid E-mail ID")
           return false
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           alert("Invalid E-mail ID")
           return false
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            alert("Invalid E-mail ID")
            return false
        }

         if (str.indexOf(at,(lat+1))!=-1){
            alert("Invalid E-mail ID")
            return false
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            alert("Invalid E-mail ID")
            return false
         }

         if (str.indexOf(dot,(lat+2))==-1){
            alert("Invalid E-mail ID")
            return false
         }
        
         if (str.indexOf(" ")!=-1){
            alert("Invalid E-mail ID")
            return false
         }

         return true                    
    }

function mailValidation1(){
    var sender=document.mailForm.mailfromID;    
    var emailID=document.mailForm.mailto

    
    if ((emailID.value==null)||(emailID.value=="")){
        alert("Please Enter your Email ID")
        emailID.focus()
        return false
    }
    
    if (echeck(emailID.value)==false){
        emailID.focus()
        return false
    }else if(sender.value.length > 0 )
    {
        if (echeck(sender.value)==false){
            sender.focus()
            return false
        }
    }   
    return true
 }
 
 function mailValidation(){

    var sender=document.mailForm.mailfrom;  
    var receiverBox=document.mailForm.mailto;
    var emailID="";
    var receiver=document.mailForm.mailto.value;
    var length=1;
    var count;
    var receiverList=new Array();
    var reg = /[,\s]/ig; 
    
    if(reg.test(receiver)) {
        receiverList=receiver.split(reg);
        length=receiverList.length; 
    }
    
    for(count=0;count<length;count++) {

        if(length>1) {
            emailID=receiverList[count];
        } 
        else {
            emailID=receiver;
        }

        if ((emailID==null)||(emailID=="")){
            alert("Please Enter your Email ID")
            receiverBox.focus()
            return false
        }

        if (echeck(emailID)==false){
            receiverBox.focus()
            return false
        } 
    }

    return true
 }