var prefcollections= new Array();
var currentContentHeight=0;
var currentTabHeight=0;


// Function for corporate tree window. Generates the value for chosen fields
function updateParentTd(chkObj, val) {
  if(val==true) {
    chkObj.parentNode.setAttribute("name","ChosenFld");
    chkObj.parentNode.setAttribute("id","ChosenFld");
  } else {
    chkObj.parentNode.setAttribute("name","");
    chkObj.parentNode.setAttribute("id","");
  }
}

//Java script written for error page
function visibility() {
  var elem=document.getElementById("Exception");
  if (elem){
	if(elem.className=='hide height200px') {
		elem.className='show height200px';
	    document.getElementById('mainDiv').style.height=400;
	} else {
 	 	elem.className='hide height200px';
	  	document.getElementById('mainDiv').style.height=220;
	}
  }
}


function refreshInnerHTML() {
  var loadingDiv = document.getElementById("AjaxLoadingInfo");
  if(loadingDiv!=null) {
    //refreshing the innerHTML of the loading div to prevent struck up of the animation after page submit
    loadingDiv.innerHTML = loadingDiv.innerHTML;
  }
}

function submitFedSearch(contentSet) {
	document.getElementById("isQuickSearch").value="true";
   if(document.getElementById('value').value==''){
      alert(_gl_getMessage("SRCH.MSG.VALID_QUERY_PAT_SEARCH")); 
      return false; 
       }
   if(contentSet=="") {
   	//FIXME Internationalization :Following alert is not being displayed to user.
      alert("To be implemented");
      return false;
   }
   if(contentSet==_gl_getMessage("APP_CTRL_SELECT_ITEM")) {
	  alert(_gl_getMessage("SRCH.MSG.SELECT_SEARCH_TYPE")); 
      return false;
   }
   else {

       if(contentSet == "PATNO")
       {
       	// patent lookup flow.
         var qStr = document.getElementById("value").value;
         //replace trailing ;
         qStr = qStr.replace(/\s*;\s*$/img,"");
         /*
         convertToQuery(qStr);
         var noError=patNumberCheck("value");
         */
         setLoadingIcon();
         startValidatePatentNumberAjaxCall(qStr,processQuickSearchRequest,true);
         return;	 
		 
       }
       else
       {
       	noError=true;
       }
       if(true && noError){
       	 if (document.getElementById('AjaxLoadingInfo'))
    {
        document.getElementById('AjaxLoadingInfo').className = "show";
    }
    
       document.fedSearchForm.action="federatedSearch.do";
       document.fedSearchForm.submit();
     
       }
   }
   refreshInnerHTML();
}


function processQuickSearchRequest(fromSearchPatent)
{
    if(req.readyState == 4){
        if (req.status == 200){
            var msg = req.responseText;
            var result = msg.split("&");
             if(result[1]=="" && result[2] =="" && result[3]=="")
             { 
             	if(fromSearchPatent){
	                //all patent numbers are valid (result[0]), hence search is triggered.
	                document.fedSearchForm.action="federatedSearch.do";
	                document.getElementById("value").value = result[0];
	                hideLoadingIcon();
	                if(result[0]!="" && document && document.fedSearchForm ){
	                   document.fedSearchForm.submit();
	                }
             	}
             	else{
             		 //all patent numbers are valid (result[0]), hence search is triggered.
                    this.opener.document.fedSearchForm.action="federatedSearch.do";
                    this.opener.document.getElementById("value").value = result[0];
                    hideLoadingIcon();
                    if(result[0]!="" && this.opener.document && this.opener.document.fedSearchForm ){
                       this.opener.document.fedSearchForm.submit();
                    }
                    this.close();
                    
                }
             	
             	
             }
             else
             {
                //Validation error still exist.
                 hideLoadingIcon();
                 
                 var url = "showPNSFormatIssuesPage.do";
                
                if(fromSearchPatent)
                {
                    // Failed for first time.
                    
                     var form = document.createElement("form");
                     form.setAttribute("action",url);
                     form.setAttribute("method","post");
                     form.setAttribute("name","dummyForm");
                     form.setAttribute("class","hide");
                     
                     var validPNs = document.createElement("input");
                     validPNs.setAttribute("name","validPNs");
                     validPNs.setAttribute("value",result[0]);
                     validPNs.setAttribute("type","hidden");
                     
                     var invalidFormatPNs = document.createElement("input");
                     invalidFormatPNs.setAttribute("name","invalidFormatPNs");
                     invalidFormatPNs.setAttribute("value",result[1]);
                     invalidFormatPNs.setAttribute("type","hidden");
                     
                     var invalidRangePNs = document.createElement("input");
                     invalidRangePNs.setAttribute("name","invalidRangePNs");
                     invalidRangePNs.setAttribute("value",result[2]);
                     invalidRangePNs.setAttribute("type","hidden");
                     
                     var invalidCCdePNs = document.createElement("input");
                     invalidCCdePNs.setAttribute("name","invalidCCdePNs");
                     invalidCCdePNs.setAttribute("value",result[3]);
                     invalidCCdePNs.setAttribute("type","hidden");
                     
                     var searchBy = document.createElement("input");
                     searchBy.setAttribute("name","searchBy");
                     searchBy.setAttribute("id","searchBy");                     
                     searchBy.setAttribute("value","QuickSearch");
                     searchBy.setAttribute("type","hidden");
                                          
                     form.appendChild(validPNs);
                     form.appendChild(invalidFormatPNs);
                     form.appendChild(invalidRangePNs);
                     form.appendChild(invalidCCdePNs);
                     form.appendChild(searchBy);
                     
                     document.body.appendChild(form);
                      /* Below logic, creates a eempty window popup,submits the dummy form and making 
                      * its target as the opened window.
                      * Its is done to make window open as post request
                      */
                     window.open("","FormatIssuesPopup","dependent=yes,dialog=yes,height=700px,width=600px");
                     form.setAttribute("target","FormatIssuesPopup");
                     form.submit();
                 }
                 else
                 {
                     // Recursive Failures.
                     
                     var form = this.opener.document.createElement("form");
                     form.setAttribute("action",url);
                     form.setAttribute("method","post");
                     form.setAttribute("name","dummyForm");
                     form.setAttribute("class","hide");
                     
                     var validPNs = this.opener.document.createElement("input");
                     validPNs.setAttribute("name","validPNs");
                     validPNs.setAttribute("value",result[0]);
                     validPNs.setAttribute("type","hidden");
                     
                     var invalidFormatPNs = this.opener.document.createElement("input");
                     invalidFormatPNs.setAttribute("name","invalidFormatPNs");
                     invalidFormatPNs.setAttribute("value",result[1]);
                     invalidFormatPNs.setAttribute("type","hidden");
                     
                     var invalidRangePNs = this.opener.document.createElement("input");
                     invalidRangePNs.setAttribute("name","invalidRangePNs");
                     invalidRangePNs.setAttribute("value",result[2]);
                     invalidRangePNs.setAttribute("type","hidden");
                     
                     var invalidCCdePNs = this.opener.document.createElement("input");
                     invalidCCdePNs.setAttribute("name","invalidCCdePNs");
                     invalidCCdePNs.setAttribute("value",result[3]);
                     invalidCCdePNs.setAttribute("type","hidden");
                     
                     var searchBy = this.opener.document.createElement("input");
                     searchBy.setAttribute("name","searchBy");
                     searchBy.setAttribute("id","searchBy");                     
                     searchBy.setAttribute("value","QuickSearch");
                     searchBy.setAttribute("type","hidden");
                     
                     form.appendChild(validPNs);
                     form.appendChild(invalidFormatPNs);
                     form.appendChild(invalidRangePNs);
                     form.appendChild(invalidCCdePNs);
                     form.appendChild(searchBy);
                     
                     this.opener.document.body.appendChild(form);
                     /* Below logic, creates a eempty window popup,submits the dummy form and making 
                      * its target as the opened window.
                      * Its is done to make window open as post request
                      */
                     this.opener.window.open("","FormatIssuesPopup","dependent=yes,dialog=yes,height=700px,width=600px");
                     form.setAttribute("target","FormatIssuesPopup");
                     form.submit();
                 }
             }
        }
    }    
}

function focusChange(e,item) {
            var keynum;
            var keychar;
            var numcheck;
            if(window.event) {
                        keynum = e.keyCode;
            }
            else if(e.which) {
                        keynum = e.which;
            }
            if(keynum==13){
            submitFedSearch(item);
            } else{
                        return String.fromCharCode(keynum) ;
            }
}

function openRecordViewWindow(url,isLitEnt)
{
  setLoadingIcon();
  var objILoginWindow;
  if(isLitEnt == "false"){
  	  var urlElems = url.split('&');
  	  var reckeys;
  	  var idType;
  	  for(var i=0; i<urlElems.length;i++){
  	  	if(urlElems[i].indexOf('recordKeys') > -1)
  	  	 reckeys = urlElems[i];
  	    if(urlElems[i].indexOf('idType') > -1)
  	  	 idType = urlElems[i];
  	  }
  	 var printUrl = "printBrdCrumbRecView.do?resultsetId="+ document.getElementById('rsId').value + "&" + reckeys + "&databaseIds=WOS&contentSet=LIT&datasource=WOK&category=LIT&docType=LIT&isLitEnt=" + isLitEnt+ "&" + idType + "&idatabaseName=WOS";
     objILoginWindow=window.open(printUrl,"IPRecordViewWindow","width=930,height=680,xtop=0,xleft=0,scrollbars=1,status=0,resizable=1");
  }else{
  	 if(isLowSystemRes()){ // If the system resolution 1024x768 and smaller
	    objILoginWindow=window.open(url,"IPRecordViewWindow","width=930,height=600,xtop=0,xleft=0,scrollbars=1,status=0,resizable=1");
     }else{ //The system resolution grater then 1024x768.
	    objILoginWindow=window.open(url,"IPRecordViewWindow","width=930,height=680,xtop=0,xleft=0,scrollbars=1,status=0,resizable=1");
	 }
  }
  objILoginWindow.focus();
  setTimeout("hideLoadingIcon()",10);
}

function openNewWindow(url,fwidth,fheight)
{
  setLoadingIcon();
  var objILoginWindow=window.open(url,"IPCommonWindow","width="+fwidth+",height="+fheight+",top=0,left=0,scrollbars=0,status=0,resizable=0");
}

function OpenShellIndex(redirectUrl,param)
{
  var objILoginWindow= null;
  if(redirectUrl == "null") {
    objILoginWindow = window.open("viewLoginPage.do?"+param,_main_window_name,"width=1012,height=700,xtop=0,xleft=0,scrollbars=1,status=0,resizable=1");
	window.close();
  } else {

      if(redirectUrl.indexOf('*') != -1)
        {
        s = new String(redirectUrl);
        redirectUrl=s.replace(/\*/g,"&");
       }
    objILoginWindow = window.open(redirectUrl,"AppWindow","width=1012,height=700,xtop=0,xleft=0,scrollbars=0,status=0,resizable=1");
  }
}

function openWindow(url,fwidth,fheight)
{
    var cutIndex =  url.indexOf('&fieldValue') + 12;
    //FIXME Internationalization :This method is not reached;hence the string "and" below is not taken care of.
    url = url.substring(0, cutIndex ) +  (url.substring(cutIndex, url.length)).replace(/& amp;/g, "and");
    var opener = null;
    var winstatus1=url.indexOf('&isFirstRecord=true');
    var winstatus2=url.indexOf('&idType=recordid');
    if(winstatus1 != -1 || winstatus2!=-1){
        // changed the second parameter of window.open() method to the current window name. Because, on clicking any citation link
        // in record view, it should not open in new page, instead it should open in existing recordview page. Fix for regression issue. - Vijay
    	var objNewWindow=window.open(url,window.name,"width="+fwidth+",height="+fheight+",top=0,left=0,scrollbars=1,status=0,resizable=1");
    	objNewWindow.focus();
    	}
    else{
    if(document.getElementById("checkbox22")!=null){
      document.getElementById("checkbox22").checked = false; 	
      }
      if(document.getElementById("islevel2")!=null && document.getElementById("islevel2").value == "true")
      {
      opener = window.parent; 
      opener.opener.opener.location = url;
      opener.opener.opener.focus();
      }
      else{
      opener = window.parent; 
      opener.opener.location = url;
      opener.opener.focus();
      }
     } 
}

 function openWindowSelf(url,fwidth,fheight)
{
    var cutIndex =  url.indexOf('&fieldValue') + 12;
    //FIXME Internationalization :This method is not reached;hence the string "and" below is not taken care of.
    url = url.substring(0, cutIndex ) +  (url.substring(cutIndex, url.length)).replace(/& amp;/g, "and");
  var objILoginWindow=window.open(url,"_self","width="+fwidth+",height="+fheight+",top=0,left=0,scrollbars=1,status=0,resizable=1");
}

function maximizeWindow(objILoginWindow)
  {
    var intScreenHeight = screen.availHeight;
    var intScreenWidth = screen.availWidth;
    objILoginWindow.moveTo(0, 0);
    objILoginWindow.resizeTo(intScreenWidth, intScreenHeight);
  }

function minimizeWindow() {
    window.resizeTo(400,300);   
}

//There should be only one application main window open at a time.
//Window name need to be consistent since we need to target the main window in some cases.
var _main_window_name='InnovationWindow';
function viewMigrationOption(param) {
  confrmMigFlag=1;
    
  window.open("viewMigrationPage.do?platform=" +param, "_blank", "width=1012,height=740,xtop=0,xleft=0,scrollbars=1,status=0,resizable=yes");
  window.parent.close();
}

function showWorkspace() {
  window.open("folderPanelIndex.do", _main_window_name, "width=1012,height=740,xtop=0,xleft=0,scrollbars=1,status=0,resizable=1");
  //window.open("html/legacyAccountDisable.html","pop","width=500,height=225");
}

function disableOldLogin(p) {
  confrmMigFlag=1;
  var param = "migOptionFlag=true&platform=" + p; 
  window.open("showOldLogin.do?"+param, "_blank","width=1012,height=700,xtop=0,xleft=0,scrollbars=1,status=0,resizable=1");  
  window.parent.close();
}

//This function is to open the links from the record view  in the parent resultset page.
function openInParent(url,w,h) {
  WindowName = "InnovationWindow";
  WindowFeatures = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=1, width="+w+", height="+h;
    var cutIndex =  url.indexOf('&fieldValue') + 12;
    //Fix to remove paranthesis from the term when it is clicked from the Recordview page
    url = url.substring(0, cutIndex ) +  (url.substring(cutIndex, url.length)).replace(/& amp;/g, "and").replace(/%28/g, "").replace(/%29/g, "");
  //The result page will be refreshed from Citation Record view also.
  if(document.getElementById('citationPubNo')){
    //The application's main window will be refreshed with result set.
      returnWin = window.open(url,WindowName,"height=1100,width=900,status=yes,toolbar=no,menubar=no,location=no,resizable=yes");
      returnWin.document.getElementById("AjaxLoadingInfo").className = "Show";
      returnWin.focus()
   }else{
    //The application's main window will be refreshed with result set from record view page.
    //If the resultset page exists, the existing page is refreshed since the window name used is main window name.
    //If the resultset page is closed, a new resultset page is opened with the window name.      
        
    returnWin  = window.open(url,WindowName,WindowFeatures);
	if( returnWin.document.getElementById("AjaxLoadingInfo") !=null){
	    returnWin.document.getElementById("AjaxLoadingInfo").className = "Show";
	}
    returnWin.focus()
  }
}

function ExpandCollapse(Expand,CurrentField,FlagImg,ImgHolder)
{
flag=true;
if(document.getElementById(Expand).className=='hide')
  {
  document.getElementById(Expand).className="show";
  document.getElementById(CurrentField).className='ColorTab hCenter vMiddle';
  document.getElementById(FlagImg).className='ViewUpImg';
  document.getElementById(ImgHolder).className='none';
  // to vary the size of the div
  var heightAdj = document.getElementById("ResultsetExpand").offsetHeight;
  var divHeight = document.getElementById("searchResultsSizeDiv").style.height;
  document.getElementById("searchResultsSizeDiv").style.height = parseInt(divHeight) - heightAdj + 'px';

  flag=false;
  }
else
  {
  var heightAdj = document.getElementById("ResultsetExpand").offsetHeight;
  document.getElementById(Expand).className="hide";
  document.getElementById(CurrentField).className='none hCenter nowrap';
  document.getElementById(FlagImg).className='DrillDownImg';
  var divHeight = document.getElementById("searchResultsSizeDiv").style.height;
  document.getElementById("searchResultsSizeDiv").style.height = parseInt(divHeight) + heightAdj + 'px';
  flag=true;
  }
}

/**
 * Method to update the session with the current open/close status for maintaining session stickiness
 * Limited to search page components only
 */
function updateSession(param1, param2) {
  if(param1=="patentCollections" && param2=="flagPatentCollections") {
    if(document.getElementById(param1).className=='hide') {
      updateTempPeferences("COLLECTIONSTOSEARCH_PAT", "true", "BOOLEAN");
    } else {
      updateTempPeferences("COLLECTIONSTOSEARCH_PAT", "false", "BOOLEAN");
    }
  } else if(param1=="QueryPreviewer" && param2=="FlagQueryPreview") {
    if(document.getElementById(param1).className=='hide') {
      updateTempPeferences("SHOW_QUERYPREVIEW", "true", "BOOLEAN");
    } else {
      updateTempPeferences("SHOW_QUERYPREVIEW", "false", "BOOLEAN");
    }
  } else if(param1=="DisplayFieldExpand" && param2=="flagImg") {
    if(document.getElementById(param1).className=='hide') {
      updateTempPeferences("SHOW_OPERATORS", "true", "BOOLEAN");
    } else {
      updateTempPeferences("SHOW_OPERATORS", "false", "BOOLEAN");
    }
  } else if(param1=="specializedSearches" && param2=="FlagSplSearch") {
    if(document.getElementById(param1).className=='hide') {
      updateTempPeferences("SHOW_SPECAIALIZESEARCH", "true", "BOOLEAN");
    } else {
      updateTempPeferences("SHOW_SPECAIALIZESEARCH", "false", "BOOLEAN");
    }
  } else if(param1=="expertDisplayFieldExpand" && param2=="expertflagImg") {
    if(document.getElementById(param1).className=='hide') {
      updateTempPeferences("SHOW_TAGS", "true", "BOOLEAN");
    } else {
      updateTempPeferences("SHOW_TAGS", "false", "BOOLEAN");
    }
  } else if(param1=="DisplayTagsExpand" && param2=="flagExpImg") {
    if(document.getElementById(param1).className=='hide') {
      updateTempPeferences("SHOW_TAGS", "true", "BOOLEAN");
    } else {
      updateTempPeferences("SHOW_TAGS", "false", "BOOLEAN");
    }
  } else if(param1=="CitedDisplayFieldExpand" && param2=="CitedflagImg") {
    if(document.getElementById(param1).className=='hide') {
      updateTempPeferences("SHOW_OPERATORS", "true", "BOOLEAN");
    } else {
      updateTempPeferences("SHOW_OPERATORS", "false", "BOOLEAN");
    }
  }
}

function CommonExpandCollapse(Expand,FlagImg)
{
  // updates the session with the current open/close status for session stickiness
  updateSession(Expand,FlagImg);
  flag=true;
if(document.getElementById(Expand).className=='hide')
{
  document.getElementById(Expand).className="show";
  document.getElementById(FlagImg).className='CollapseImg';
  var heightAdj = document.getElementById(Expand).offsetHeight;
  flag=false;
  }
else
  {
  var heightAdj = document.getElementById(Expand).offsetHeight;
  document.getElementById(Expand).className="hide";
  document.getElementById(FlagImg).className='ExpandImg';
  flag=true;
  }
}

function ChangeTab(ActiveTab,NewTab)
{
  if(document.getElementById(NewTab).className=='internalbottomborder hCenter tablink')
  {
    document.getElementById(NewTab).className='internaltabborder hCenter activelink'
    document.getElementById(ActiveTab).className='internalbottomborder hCenter tablink'

  }

}

// added window focus event to set focus on the first non hidden form input in tile header. Bug fix 3618

function focusAtFirstInput() {
    var inputs = document.getElementsByTagName("input");
    for(var i=0;i<inputs.length;i++) {
        if(inputs[i] && inputs[i].type!="hidden") {

                 // sometimes the elemnt class is made to invisible and so it throws an error. In that case 

                  //go to the next element and focus it
                 try {
            inputs[i].focus();
            break;
            } catch(err) {
          
            }

        }

    }

}


/*var prevTab="";
function ChangeTab(ActiveTab,NewTab)
{
  if(prevTab!="")
    {
    document.getElementById(prevTab).className='internalbottomborder hCenter tablink'
    }
    document.getElementById(ActiveTab).className='internaltabborder hCenter activelink'
    prevTab=ActiveTab;
    }
}*/

function BreadCrumbs(Home,Level1, Level2,HelpIndex)
{
  //alert(top.HeaderPanel.document.getElementById('breadCrumbs').innerHTML);
  //FIXME Internationalization :This method is not reached;hence the text in href is not taken care of.
  top.HeaderPanel.document.getElementById('breadCrumbs').innerHTML='<a href=# class=navlink>'+Home+'</a> > <a href="#" class="navlink">'+Level1+' </a> > <span>'+Level2+'</span>';
  top.HeaderPanel.document.getElementById('helpIndex').innerHTML='<a href=# class=helpindex>'+HelpIndex+'</a>';
}

function textinput_textArea(txtinput,txtarea,textpanel,fieldValue,examplefld)
{
var cnt = "";
if(txtinput != "" && txtinput != null){
cnt = txtinput.substring(txtinput.lastIndexOf('txt') + 3);
}
if(document.getElementById('contentSet').value == "LIT" && cnt != ""){
if(document.getElementById('LITfldButton'+cnt) != null){
	if(document.getElementById('LITfldButton'+cnt).className == 'displayButton show inline'){
       document.getElementById('LITfldButton'+cnt).className='hide';
       }
    else{
  	  populateLITResources(cnt);
  	  }
    document.getElementById("row"+cnt+"div1").className = "vTop width130px";
    document.getElementById(textpanel).colSpan = 3;
    document.getElementById(textpanel).className = "vTop width130px";
//    document.getElementById(textpanel).style.padding = "3";
    }
    }
  
  document.getElementById(txtinput).className='hide';
  document.getElementById(txtarea).className='show';
  if(examplefld !=null){
    document.getElementById(examplefld).className = 'hide';
    // Added for Displaying the example field when Textarea appears
        document.getElementById(examplefld+"Bottom").className = 'show';
    }
  document.getElementById(txtarea).focus();

  if(document.getElementById(txtinput).value==""){
  document.getElementById(txtarea).value="";
  }
  else{
      if(fieldValue && document.getElementById(fieldValue).value != "")
  document.getElementById(txtarea).value=document.getElementById(fieldValue).value;
    else document.getElementById(txtarea).value=document.getElementById(txtinput).value;
  }
    if(document.getElementById('actualQuery') != null){
      document.getElementById(txtarea).value = document.getElementById('actualQuery').value;
  }

if(textpanel !=null){
  document.getElementById(textpanel).setAttribute("colSpan",3);
}
 // document.getElementById(textpanel).className = "vTop width170px";
}

//Business Search - Tabpanel - Begin//
var curTab="";
var prevTab="";

function changeTab(defaultTab,currentTab)
{
  dftTab=document.getElementById(defaultTab);
  curTab=document.getElementById(currentTab);
  if(curTab!=prevTab)
  {
    document.getElementById(currentTab).className="internalTabBorder hCenter activeLink";
    if(curTab==dftTab)
    {
    document.getElementById(defaultTab).className="internalTabBorder hCenter activeLink"
    }
    else
    {
    dftTab.className="internalBottomBorder hCenter tabLink";
    }
    prevTab.className="internalBottomBorder hCenter tabLink";
    }

  prevTab=curTab;
}

//Business Search - Tabpanel - End/


function loginSuccess(obj){
  if(obj == '1'){
  	window.open("modalHistoryMarkedList.jsp","pop","width=348,height=189,xtop=0,xleft=0,scrollbars=0,status=0,resizable=0");
  }else if(obj == '2'){
    var param = "migOptionFlag=true";
    window.open("viewLoginPage.do?"+param,_main_window_name,"width=1012,height=700,xtop=0,xleft=0,scrollbars=1,status=0,resizable=1");
  }
}

//Include CSS File - Begin//
function insertCSS(path)
{
  document.write("<link rel='stylesheet' href='"+path+"style/interface.css' type='text/css'></link>");
  document.write("<link rel='stylesheet' href='"+path+"style/images.css' type='text/css'></link>");
  document.write("<link rel='stylesheet' href='"+path+"style/common.css' type='text/css'></link>");
  document.write("<link rel='stylesheet' href='"+path+"style/modalAnnotations.css' type='text/css'></link>");
  document.write("<link rel='stylesheet' href='"+path+"style/print.css' type='text/css' media='print'></link>");
}
//Include CSS File - End//

//Function to select all collections in patent search page.
function selectAllCollectionsToSearch() {

    var table_ref = document.getElementById("parentTable");
  var search=table_ref.getElementsByTagName("input");
  searchLength=search.length;
    for(i=0;i<searchLength;i++) {
   search[i].checked = true;
  }
  document.getElementById('collectionsDescription').innerHTML=_gl_getMessage("PREF_DISPLAY_COLLECTIONS");
  //document.getElementById('collectionsDescription').title=getSelectAllRolloverText();
  updateCollection();
    document.getElementById('selectAll').disabled=true;
    document.getElementById('clearAll').disabled=false;
    if(!document.all)
    {
      document.getElementById('selectAll').className="frmGreyData";
      document.getElementById('clearAll').className="navLink";
    }

}

function getSelectAllRolloverText(){
  var collections = document.getElementById("biblioPropColl").value.split(',');
  var collectionNames = document.getElementById("fullTextPropColl").value.split(',');

  rollOverText="";

  if((collectionNames != null) && (typeof(collectionNames)!="undefined")){
    for (i = 0; i < collectionNames.length; i++) {
      rollOverText += collectionNames[i] + ", ";
    }
  }

  if((collections != null) && (typeof(collections)!="undefined")){
     for(i = 0; i < collections.length; i++) {
       if(i !=  collections.length-1){
        rollOverText += collections[i] + ", ";
       }else{
        rollOverText += collections[i];
       }
    }
  }
  return rollOverText;
}
//function getPrefCollections()
//{
////	alert("Enter");
//	var collectionarray=document.getElementsByName("collections");
//	alert(collectionarray.length);
//	for(i=0;i<collectionarray.length;i++){
//		if(collectionarray[i].checked){
//		alert("check");
//		prefcollections[i]=collectionarray[i].value;}
//		else
//		prefcollections[i]=null;
//		
//	}
////	alert(prefcollections);
////	return prefcollections;
//}

function putcollections(prefcollections)
{
//	alert(prefcollections);
	var str=prefcollections;
	var collect =document.getElementById("fullTextCollections");
	var bibcollect=document.getElementById("biblioCollections");
	var check=collect.getElementsByTagName("input");
	var bibcheck=bibcollect.getElementsByTagName("input");

	for(var i=0;i<check.length;i++) {
    if(str.indexOf(check[i].value+",")>-1 || str.indexOf(","+check[i].value)>-1) {
     check[i].checked=true;
    }
    }
	
	for(var i=0;i<bibcheck.length;i++) {
    if(str.indexOf(bibcheck[i].value+",")>-1 || str.indexOf(","+bibcheck[i].value)>-1) {
     bibcheck[i].checked=true;
    }
    }

}

//FIXME duplicate in resultset.js
function clearAllCollectionsToSearch()
{
  var table_ref = document.getElementById("parentTable");
  var search=table_ref.getElementsByTagName("input");

  for(i=0;i<search.length;i++) {
     search[i].checked = false;
  }
  document.getElementById('collectionsDescription').innerHTML=_gl_getMessage("SRCH_PAT_SELECT_COLLECTION");
  document.getElementById('collectionsDescription').title ="";
  document.getElementById('clearAll').disabled=true;
  document.getElementById('selectAll').disabled=false;
    if(!document.all)
    {
    document.getElementById('selectAll').className="navLink";
    document.getElementById('clearAll').className="frmGreyData";
    }

}
//Collections to Search End//


function loadDetail() {
  if(document.getElementById("searchForm") != null) {
    var patentCollections = document.getElementById("patentCollections");
    if(patentCollections) {
	    CommonExpandCollapse('patentCollections','flagPatentCollections');
	    setDefaultValues();
    }
  }
}

function selectChilds(_parentId) {	
	var objId = document.getElementById('imgParam' +_parentId);
	var imgId = document.getElementById('imgExp'   +_parentId);
	
	if(imgId) 
	if(trim(imgId.className) == 'expandFamilyImg')
		return;
	
	if(objId) {
		 var bChecked = document.getElementById(_parentId).checked;
	 	 var childs = objId.value.split(",");
		 for(var i=0; i<childs.length; i++) {		 		
		 	if(document.getElementById(childs[i]) != null) {	 		
		 		var chkboxObj = document.getElementById(childs[i]).getElementsByTagName("input");		 	
		 		if(chkboxObj[0] != null) {		 		
		 			if(bChecked) { chkboxObj[0].click(); }	 			
		 			chkboxObj[0].checked = bChecked;		 			
		 		}		 	
		 	}
		 }
	}
}

function selectAll() {
  var eleIndex = 0;
  var chkElements;
  var chkElement;
  var bChecked=true;
  var chkHeader;
  var temp;

  chkHeader = document.getElementsByName("headerChk");
  if(chkHeader[0] == null)
    return;
  if(chkHeader[0].checked == false)
    bChecked=false;
  //alert(chkHeader.checked);
  
  if(document.getElementById("selectAllStatus") != null){
	document.getElementById("selectAllStatus").value = bChecked;
  }	
	
  if(bChecked == false){
  	document.getElementById('recordIds').value = "";
  	document.getElementById('uncheckedRecordIds').value = "";
  	if(document.getElementById('tempUncheckedRecordIds'))
  		document.getElementById('tempUncheckedRecordIds').value = "";
  	if(document.getElementById('tempRecordIds'))
  		document.getElementById('tempRecordIds').value = "";	
  }else{
  	document.getElementById('uncheckedRecordIds').value = "";
  	if(document.getElementById('tempUncheckedRecordIds'))
  		document.getElementById('tempUncheckedRecordIds').value = "";
  }
  var chkElements = document.getElementsByName("recCheckBox");
  for(eleIndex=0;eleIndex<chkElements.length;eleIndex++) {
    chkElement = chkElements[eleIndex];
    var chkObj = document.getElementById("child1" + chkElement.id);     	
   	if(chkObj)
   	if(trim(chkObj.style.display) == "none")
   		continue;
	   
    if( ! (chkElement.checked == chkHeader[0].checked)) {
      chkElement.click();
    }
    chkElement.checked = chkHeader[0].checked;
  }
}

function cit_selectAll() {
  var eleIndex = 0;
  var chkElements;
  var chkElement;
  var bChecked=true;
  var chkHeader;
  var temp;

  chkHeader = document.getElementsByName("headerChk");
  if(chkHeader[0] == null)
    return;
  if(chkHeader[0].checked == false)
    bChecked=false;
  //alert(chkHeader.checked);
  var chkElements = document.getElementsByName("recCheckBox");
  for(eleIndex=0;eleIndex<chkElements.length;eleIndex++) {
    chkElement = chkElements[eleIndex];
    //alert(eleIndex.Name)
    if( ! (chkElement.checked == chkHeader[0].checked)) {
      chkElement.click();
    }
    chkElement.checked = chkHeader[0].checked;
  }
}


// Return the position of control as array.
//array[0]=left
//array[1]=top

function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent) {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  return [curleft,curtop];
}

// Function to get Message
// key : Key that is used to look up the value in the property file
// arg : Dyanamic arguments separated by #ARG# which will be used to 
// replace the place holders in the message resolved.
function _gl_getMessage(key,arg) {
  if(document.getElementById(key)){
    var messageString = document.getElementById(key).innerHTML;
    if(typeof(arg) != "undefined" && arg != null && arg != ""){
   		 var arguments = arg.split("#ARG#");
   		 var source = "";
   	 	 for(var i=0 ; i < arguments.length ; i++){
   	 		source = "{" + i + "}";
    		messageString = messageString.replace(source,arguments[i])
     	}
    }
    messageString = messageString.replace(/%NEWLINE%/g, "\n");
    messageString = messageString.replace(/&lt;/, "<");
	messageString = messageString.replace(/&gt;/, ">");
    return messageString;
  }
  else
    return key;

}

function trim(str)
{
	if(str!="" && str.length>0)
	{
        return str.replace(/^\s*|\s*$/g,"");
	}
}


function closeDivPanel(event){

  if(typeof(tempCount) != "undefined"){

  for(var k=0;k<=tempCount;k++){
    //alert(i)
    var panel = document.getElementById("masterExpandPanel"+k);

    if(panel != null && panel.className=="showDropDownComponent"){
      obj=document.getElementById("masterExpandPanel"+k);
      inputbox=document.getElementById("selectedPanel"+k);
      leftPos=obj.offsetLeft;
      rightPos=leftPos+obj.offsetWidth;
      leftBottomPos=leftPos+obj.offsetHeight;
      rightBottomPos=rightPos+obj.offsetHeight;
      objTop=obj.offsetTop;
      tt=(event.clientY+inputbox.offsetHeight-document.body.scrollTop);
      //alert('event.clientY= '+event.clientY+'  >obj.offsetHeight= '+obj.offsetHeight);
      if(event.clientX < leftPos || event.clientX > rightPos || (event.clientY+inputbox.offsetHeight+document.body.scrollTop) < objTop )
      obj.className="hideDropDownComponent";
    }
  }
  }

}

function closeAllDivPanel(){

    if(typeof(tempCount) != "undefined"){
  for(k=0;k<=tempCount;k++){
    var panel = document.getElementById("masterExpandPanel"+k);
    if(panel != null && panel.className=="showDropDownComponent"){
      panel.className="hideDropDownComponent";
    }
  }
    }
}

//To get the browser type
function getBrowserType(){
var agt = navigator.userAgent.toLowerCase();
this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)&& (agt.indexOf('compatible') == -1)));
this.ie   = (agt.indexOf("msie") != -1);
if(this.ie){
browserType=1;
}else if(this.nav){
browserType=2;
}
return browserType;
}

//Refersh the UI
 function refereshUIScreen(){
	  setH();
	  if((getBrowserType()!=1) && (currentContentHeight > currentTabHeight)){//Only for the firefox in will relod the page from the browser cache.
			//  for browsers that support JavaScript version 1.2
		    //  The argument to the location.reload function determines if the browser should retrieve the document from the  web-server or not.
	        // JavaScript block in the document body to be re-evaluated.If we needed to pull the document from the web-server again  need to pass the argument as 'true'.
			window.location.reload(false);
	   }
	}

	function getScreenHeight(){
		var height=0;
		 if (self.innerHeight) {
				height = self.innerHeight;
		 }else if (document.documentElement && document.documentElement.clientHeight){
				height = document.documentElement.clientHeight;
		 }else if (document.body){
			height = document.body.clientHeight;
		 }
		 return height;
	}

	function getScreenWidth(){
		var width=0;
		 if (self.innerWidth) {
				width = self.innerWidth;
		 }else if (document.documentElement && document.documentElement.clientWidth){
				width = document.documentElement.clientWidth;
		 }else if (document.body){
			width = document.body.clientWidth;
		 }
		 return width;
	}
function mainClose(){
  var markedListClear = document.getElementById("markedListClear").value;
  var searchHistoryClear = document.getElementById("searchHistoryClear").value;	
  var migOptionFlag = "false";
  if (migFlag == 0 ) {  
    OpenShellIndex('null','migOptionFlag=' + migOptionFlag + 'markedListClear=' + markedListClear + '&searchHistoryClear=' + searchHistoryClear);
  }
}
function confirmMigrationWinClose() {

 if(confrmMigFlag == 0) {
    var param = "migOptionFlag=true";
    window.open("viewLoginPage.do?"+param,_main_window_name,"width=1012,height=700,xtop=0,xleft=0,scrollbars=1,status=0,resizable=1");
  }
}

function getMigration() {
  var markedListClear = document.getElementById("markedListClear").value;
  var searchHistoryClear = document.getElementById("searchHistoryClear").value;	
  var noPopup = document.getElementById("nopopup").checked;
  var showPopup = !noPopup;
  
  migFlag=1;
  MigFlagsObj = new MigrationObjectPrototype('markedListClear=' + markedListClear + '&searchHistoryClear=' + searchHistoryClear + '&showPopup=' + showPopup);
  //MigFlagsObj.getMigrationFlags("getMigrationFlags.do", 'markedListClear=' + markedListClear + '&searchHistoryClear=' + searchHistoryClear);
  MigFlagsObj.getMigrationFlags("getMigrationFlags.do");
}

function setMarkedListClear(val){
	document.getElementById("markedListClear").value = val ;
}
function setSearchHistoryClear(val) {
  document.getElementById("searchHistoryClear").value = val;
}
function callBreadCrumb(selectObj){
    if(document.getElementById('AjaxLoadingInfo')){
       document.getElementById('AjaxLoadingInfo').className = "show";
    }
    if(document.getElementById('AjaxLoadingInfoRecordView')){
       document.getElementById('AjaxLoadingInfoRecordView').className = "show";
    }
	var url = selectObj.options[selectObj.selectedIndex].value;
	if(url){
        var index = selectObj.selectedIndex;
		url=url+'&navigationIndex='+index;
		window.location = url;
	}
	
}
//This method is used to move forward and backward in bread crumbs
function forwardAndBackwardNavigation(flag){
	if(flag){
	var selectObject = document.getElementById("breadCrumbList");
	var backWardNavigator = document.getElementById("backwardBreadCrumb").className;
	var forWardNavigator = document.getElementById("forwardBreadCrumb").className;
	if(selectObject){
		var url;
		if(flag =="BACKWARD"){
			if(backWardNavigator == "backwardImg"){
	             url = selectObject.options[selectObject.selectedIndex+1].value;
				 var index = selectObject.selectedIndex+1;
        	     url=url+'&navigationIndex='+index
	  	     }
	  	 }else if(flag =="FORWARD"){
	  	 	if(forWardNavigator == "forwardImg"){
        	     url = selectObject.options[selectObject.selectedIndex-1].value;
	             var index = selectObject.selectedIndex-1;
        	     url=url+'&navigationIndex='+index
             }
		}
		if(url){
			if(selectObject.options[selectObject.selectedIndex].value){
				if(selectObject.options[selectObject.selectedIndex].value == "Error"){
					url+="&error=true"
				}
			}
			window.location = url;
		}
	}
	}
}

//This method is mainly used to set the bread crumb list
function setBreadCrumbList(title){
	var breadCrumbElement = document.getElementById("breadCrumbList");
	if(breadCrumbElement){
		var length = breadCrumbElement.options.length;
		if(title){
			var specifiedLength = length +1;
			var value = "invokeBreadCrumb.do?id="+specifiedLength;
			
			for(var i = breadCrumbElement.options.length; i > 0; i--) {
				var prevVal = breadCrumbElement.options[i - 1];
				breadCrumbElement.options[i] = new Option(prevVal.text, prevVal.value);
			}
			breadCrumbElement.options[0] = new Option(title,value);
			breadCrumbElement.options[0].selected="true";
			var backCursor = document.getElementById("backwardBreadCrumb");
			var forwardCursor = document.getElementById("forwardBreadCrumb");
			if(backCursor){
				document.getElementById("backwardBreadCrumb").className = "backwardImg";
			}
			if(forwardCursor){
				document.getElementById("forwardBreadCrumb").className = "forwardImgNoCursor";
			}
		}
	}
}

//This method helps in showing the public folder tree 
function showPublicTree(){
 var objectTypeFound = document.getElementById('objectTypeFound').value;
 objectTypeFound ='objectTypeFound=' + objectTypeFound;
 var url = "modalPublicTree.do?"+objectTypeFound
 e = window.open(url,'publicfolder','width=370,height=400,resizable=no,scrollbars=no');
}

//This method helps in activating the public permissions and browse options
function enableBrowse(from){
	var objPublic = document.getElementById('cpublic');
	if(objPublic){
	if(objPublic.checked ==1){
		document.getElementById('browsePublicTree').disabled = false;
		document.getElementById('opublic').disabled = false;
		//This condition is applicable for active alert
		var alertStatus = document.getElementById('active');
		if(!from && alertStatus && document.getElementById('fromstatus').value == "setalert"){
			if(alertStatus.value == "true"){
				alert(_gl_getMessage("APP_CTRL_MOVE_ACTIVE_ALERT"));
			}
		}
		setPublicPermission();
	}else{
			document.getElementById('opublic').disabled=true;
			document.getElementById('opublic').selectedIndex=0;			
			document.getElementById('publicFolderName').value='';
			document.getElementById('browsePublicTree').disabled=true;		
	}
  }
}

//This method sets the value for the public permissions
function setPublicPermission(){
	var oPublicObj = document.getElementById("opublic");
	var oPublicVal = oPublicObj.options[0].value;
	if(oPublicObj.options[oPublicObj.selectedIndex].value){
		oPublicVal = oPublicObj.options[oPublicObj.selectedIndex].value;
	}
	if(oPublicVal){
		document.getElementById("publicPermission").value=oPublicVal;	
	}
	
}

function skipEnter(evt) {
    var evt  = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
  }

//TODO remove the duplicate methods
function getDate(idate,range){
	if(idate == 'XX'){
		//var d = new Date();
		//var year = parseInt((d.getFullYear() - range) + 1);
		//d.setYear(year)
		//idate = d.getDate();
		//if(idate < 10) idate = "0"+ idate;
		idate="01";
	} else if(idate == 'YY') {
		var d = new Date();
		idate = d.getDate();
		if(idate < 10) idate = "0"+ idate;		
	} else if(idate == 'undefined') {
		idate = "";
	}
	return idate;
}
//TODO remove the duplicate methods
function getMonth(idate,range){
	if(idate == 'XX'){
		//var d = new Date();
		//var year = parseInt((d.getFullYear() - range) + 1);
		//d.setYear(year)
		//idate = d.getMonth() + 1;
		//if(idate < 10) idate = "0"+ idate;
		idate = "01";
	} else if(idate == 'YY') {
		var d = new Date();
		idate = d.getMonth() + 1;
		if(idate < 10) idate = "0"+ idate;
	} else if(idate == 'undefined') {
		idate = "";
	}
	return idate;
}
//TODO remove the duplicate methods
function getYear(idate,range){
	if(idate == 'XX'){
		var d = new Date();
		var year = parseInt(d.getFullYear() - range);
		idate = year;
	} else if(idate == 'YY') {
		var d = new Date();
		idate = d.getFullYear();
	} else if(idate == 'undefined') {
		idate = "";
	}
	return idate;
}
function validateAndCopy(tempHidFld,txtinput,txtarea,fieldValue,isRs){
	var hiddenText=null;
	var content="";
	if(document.getElementById(txtarea))
	var content = document.getElementById(txtarea).value;
	var cnt = "";
	if(txtinput != "" && txtinput != null){
	cnt = txtinput.substring(txtinput.lastIndexOf('txt') + 3);
	}
	if(document.getElementById("hiddenText"+cnt)){
		hiddenText=document.getElementById("hiddenText"+cnt);
	}
	if(isRs==null){
    var tempValue=content.trim().toUpperCase();
    if(operatorList1!=null && operatorList1!=""){
    for(var i=0;i<operatorList1.length;i++){
        var re=new RegExp("^\\b"+operatorList1[i]+"\\s");
        if(re.test(tempValue)==true){
            alert(_gl_getMessage("SRCH.MSG.CANNOT_START_OPERATOR"));
			if(hiddenText)
            hiddenText.value=1;
			document.getElementById(txtarea).value="";
			break;
        }
        else if(hiddenText)
        hiddenText.value=0;
        if(tempValue == "AND" || tempValue == "OR" ||tempValue == "NOT" ||tempValue == "ADJ" ||
                                tempValue == "NEAR" ||tempValue == "SAME" ||tempValue == "WITH"){
            alert(_gl_getMessage("SRCH.MSG.CANNOT_START_OPERATOR"));
		    if(hiddenText)
            hiddenText.value=1;
			document.getElementById(txtarea).value="";
			break;
        }
        else if(hiddenText)
        hiddenText.value=0;
    }
    }
    var regex=new RegExp("={2,}|=(?=[<>=])|[\\w]=|[^><](?==)","g");
    if(regex.test(tempValue) && tempValue.trim().indexOf("\"")!=0){    	
        alert(_gl_getMessage("SRCH.MSG.INVALID_OPERATOR"));
		if(hiddenText)
        hiddenText.value=1;
    }
    else if(hiddenText)
    hiddenText.value=0;
    var regex=new RegExp(".+[<>]|[<>]={2,}|[<>][<>]","g");
    if(regex.test(tempValue)){
        alert(_gl_getMessage("SRCH.MSG.INVALID_OPERATOR"));
        if(hiddenText)
        hiddenText.value=1;
    }
    else if(hiddenText)
    hiddenText.value=0;
	}
 if (tempHidFld) {
    currentHiddenFld = tempHidFld;
    document.getElementById(tempHidFld).value = content;
  }
  if(document.getElementById(txtinput))
   document.getElementById(txtinput).value = document.getElementById(txtarea).value;
   
   
   if(document.getElementById('contentSet')){
   	 if(document.getElementById('actualQuery') != null){
      document.getElementById('actualQuery').value = document.getElementById(txtarea).value;
    }
  if(document.getElementById(txtarea).value=="") {
    document.getElementById(txtinput).value=document.getElementById(txtarea).value;
   if(fieldValue)
    document.getElementById(fieldValue).value="";
  }
  else
  {
    var areaText = document.getElementById(txtarea).value;
  if(fieldValue)
    document.getElementById(fieldValue).value = areaText;
    if(areaText && areaText.length > 70){
      document.getElementById(txtinput).value=areaText.substring(0,70)+'...';
    }else{
      document.getElementById(txtinput).value=trimSpaceAndLineFeed(areaText);
    }
  }
   }
}

function isEnterPressed(evt){
		var charCode;
		if(evt && evt.which){
			charCode=evt.which;
		}else{
			evt = event;
			charCode = evt.keyCode;
		}
		if(charCode==13){ // check if enter key is pressed
			return true;
		}
		return false;
}

/*
 * Javascript function identify client System resolution.
 * return true if the system resolution 1024x768 and low.
 */
function isLowSystemRes() {
	
	   if (self.screen){
		 // Available in JavaScript 1.2
		 return (screen.height <= 800) && (screen.width <= 1024);
	   }else  if (navigator.javaEnabled && navigator.javaEnabled()){
		   // Available in JavaScript 1.1
		   return (java.awt.Toolkit.getDefaultToolkit().getScreenSize().height <= 800 && java.awt.Toolkit.getDefaultToolkit().getScreenSize().width <= 1024);
	   }
	   return true;
}

function updateTempPeferences(key, value, type) {
   var ajaxReq = new AjaxRequest();
   ajaxReq.requestData("GET","updateTempPreferences.do?key=" + key + "&value=" + value + "&dataType=" + type, null, null, null, true);
}

function setLoadingIcon(){
  if(document.getElementById('AjaxLoadingInfo')){
     document.getElementById('AjaxLoadingInfo').className = "visible";
  }
  if(document.getElementById('AjaxLoadingInfoRecordView')){
     document.getElementById('AjaxLoadingInfoRecordView').className = "visible";
  }
}

function hideLoadingIcon(){
  if(document.getElementById('AjaxLoadingInfo')){
    document.getElementById('AjaxLoadingInfo').className = "hide";
  }
  if(document.getElementById('AjaxLoadingInfoRecordView')){
     document.getElementById('AjaxLoadingInfoRecordView').className = "hide";
  }
  
}

function showLoadingIcon(_jsCode) {
	setLoadingIcon();
	_jsCode = _jsCode + "hideLoadingIcon();";                             
	setTimeout(_jsCode,10);                                                                   
}

function convertDateFormat(date, dlimiter)
{
  if(date.trim() == "") return date;
  
  var dateArray = date.split(dlimiter);               
  return dateArray[1]+dlimiter+dateArray[2]+dlimiter+dateArray[0]; // YYYY/MM/DD  ->  MM/DD/YYYY Format
}

function removeLineBreaks(string)
{
  var newString = "";
  for(var i=0; i<string.length; i++){
    string = string.replace(/'/g,"");
    if(string.charCodeAt(i) != 10 && string.charCodeAt(i) != 13)
       newString = newString + string.charAt(i);
   }

  return newString;
}

function validateCountry(countryId, stateId,msg1,msg2) {
  var countryCombo = document.getElementById(countryId);
  var stateCombo   = document.getElementById(stateId);
  if(countryCombo.value.indexOf("(US)")>-1 || countryCombo.value.indexOf("(CA)")>-1) {
    if(stateCombo.selectedIndex==0 || stateCombo.selectedIndex==-1) {
      alert(_gl_getMessage(msg2));
      return false;
    } else {
      var regx = /\([a-zA-Z]{2,}\)/g; 
      var countryMatch = countryCombo.value.match(regx)[0];
      var stateMatch  =  stateCombo.value.match(regx)[0];
      if(countryMatch != stateMatch) {
        alert(_gl_getMessage(msg1));
        return false;
      } else return true;
    }
  } else if(stateCombo.selectedIndex > 0) {
    alert(_gl_getMessage(msg1));
    return false;
  } else return true;
}

var innovationModalPopup;

function checkModalPopup(){
	if(innovationModalPopup != null && innovationModalPopup!= "undefined" && !innovationModalPopup.closed ) {
		innovationModalPopup.focus();
	}
}
/*
function changeParentResize(){
	try{
	window.resizeTo(window.screen.availWidth,window.screen.availHeight);
	window.moveTo(0,0);
	}
	catch(e){}
}
*/
/* This method is used to implement the modal dialog window.
 * If there is any change in this method need to be replicated
 * in the modalExportFrame.jsp too.
 */
var XYZ = true;
function getMouseXY(e){
		var tempX;
		var tempY;
		if(document.all){
  			 tempX = event.clientX;
    		 tempY = event.clientY;  		  	
		}
		else
		{
			tempX = e.clientX; 
    		tempY = e.clientY; 
		}
		if(tempX == -1) { XYZ= true; }
		else 			{ XYZ=false; }	
		return true;
}	
	
function checkonBlur(){
	//FIXME: remove this
	try
	{
		if(XYZ){
			if(childFlag && childFlag == "3"){
				try{
				if(window.opener)
					window.opener.focus();
					}catch(e){}	
			}
			else{
				try{
				window.focus();
				}catch(E){}
				}	
		}
	}
	catch(E)
	{}
}
//function checkModalPopupOnClick(evt) {
  //if(innovationModalPopup != null && innovationModalPopup!= "undefined" ) {
  	//evt.preventDefault();
  //}
//}

function handleOnClose(evt) {
	if(!evt) {
	  evt = event;
	} 
  if (evt.clientY < 0) {
    closeMe();
  }
}

function closeMe(){
	if (window.opener) {
		try{
			if (window.opener.innovationModalPopup) {
				window.opener.innovationModalPopup = null;
	 		 	window.opener.focus();
	 		}
	  } catch(err){}
	} 
}

//decrements the session idle time in cookie 

function decrementSessionTime(){
	var sessionMaxInactiveInterval = getCookie("sessionMaxInactiveInterval");
	sessionMaxInactiveInterval--;
	setCookie("sessionMaxInactiveInterval",sessionMaxInactiveInterval);
	setTimeout("decrementSessionTime()", 1000);
}


function closeIfSessionEndedOnClick(){
	var returnvalue = true;
    if(document.getElementById("mainPage")){
      document.getElementById("mainPage").value = "reloading..."
	  if(getCookie("autoLogin") == "OFF"){
		  alert(_gl_getMessage("CMN.SESSION_EXPIRED") + "\n" + _gl_getMessage("CMN.RE_LOGIN"));
		  setCookie("isSessionExpired","true");
	      window.close();
	  }else{
		  alert(_gl_getMessage("CMN.SESSION_EXPIRED_AUTO_LOGIN"));
		  setCookie("isSessionExpired","true");
          window.location = "viewLoginPage.do";
	  }
    }else{
      if(getCookie("autoLogin") == "OFF"){
		  alert(_gl_getMessage("CMN.SESSION_EXPIRED") + "\n" + _gl_getMessage("CMN.RE_LOGIN"));
          returnvalue = false;
          if(setCookie("isSessionExpired","true")){
      	     window.close();
          }
	  }else{
	     alert(_gl_getMessage("CMN.SESSION_EXPIRED_AUTO_LOGIN"));
         returnvalue = false;
         if(setCookie("isSessionExpired","true")){
      	     window.close();
          }
	  }      
    }
    return returnvalue;
}

function closeIfSessionEnded(){
  var sessionIdleTime = getCookie("sessionMaxInactiveInterval");
  var isSessionExpired = getCookie("isSessionExpired");
  if (sessionIdleTime <= 0 && document.getElementById("disabled").value == "false"){
  	disableClickEvents();
  	document.getElementById("disabled").value = "true";
  }
  if (sessionIdleTime <= 1 && isSessionExpired == "true" ){
     if(document.getElementById("mainPage")){
       if(document.getElementById("mainPage").value == ""){
       	document.getElementById("mainPage").value = "reloading...";
       	if(getCookie("autoLogin") == "OFF"){
       		window.close();
       	}else{
       	  	window.location = "viewLoginPage.do";
        }  
        }     
     }else{
       window.close();
     }
  }
}


function xmlhttpPost(strURL) {
    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");
    }
    if(self.xmlHttpReq){
    self.xmlHttpReq.open('GET', strURL, false);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
		     closeIfSessionEndedOnClick();
		   //may need any code here later
		}
    }
    }
    return self.xmlHttpReq.send(strURL);
}

//Get cookie routine by Shelley Powers 
function getCookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function setCookie(variable, value){
	//store data using name/value format
	document.cookie=variable + "=" + value;
	return true;
}

function validateSessionID(){
	if(getCookie("sessionMaxInactiveInterval") <= 0 && getCookie("isSessionExpired") != "true"){
		disableClickEvents();
		xmlhttpPost('killsession.jsp');
	}
}

function disableClickEvents(o){
    if(!o){
	var o = document.getElementsByTagName("BODY")[0];
	}	
 	 var s = o.childNodes;
     if(!s) return;
     for(var i=0; i<s.length; i++){
       if(s[i].onclick){
          s[i].onclick = function(){return false};
       }
       if(s[i].onmouseover){
          s[i].onmouseover = function(){return false};
       }
       if(s[i].childNodes){
          disableClickEvents(s[i]);
       }
     }
     return false;
}

function isEnterPressed(evt){
		var charCode;
		if(evt && evt.which){
			charCode=evt.which;
		}else{
			evt = event;
			charCode = evt.keyCode;
		}
		if(charCode==13){ // check if enter key is pressed
			return true;
		}
		return false;
}

function breakName(name){
if(name != ""){
	name = name.replace(/,/g,", ");
	}
	return name;
}
function stringReplaceAll( str, searchTerm, replaceWith, ignoreCase )
{
var regex = "/"+searchTerm+"/g";
if( ignoreCase ) regex += "i";
return str.replace( eval(regex), replaceWith );
}

//This function checkPersonalReferences of the workspace object and alert the user appropriately 
function checkPersonalReferences()
{
if(document.getElementById('from') && document.getElementById('personalSharedPath')){
	var from=document.getElementById('from').value;
	var personalPath=document.getElementById('personalSharedPath').innerHTML;
	if(personalPath.length > 0 && (from !="" && from.length > 0 )){
	if(!document.getElementById('rpermissionsPersonal').checked && !(from=='FOLDER_PUBLIC' || from == 'FOLDER_PUBLIC_SYSTEM')){
	 		var error_code;
 			if(from=='FOLDER_PERSONAL_SYSTEM' || from == 'FOLDER_PERSONAL')
 				{error_code="WS.MSG.PERSONAL_REF_REMOVAL_ALONE";}
 			else
 				{error_code="WS.MSG.PERSONAL_REF_REMOVAL";}
		var status=confirm(_gl_getMessage(error_code));
		if(!status) document.getElementById('rpermissionsPersonal').checked  = true;
		}
	}
}
}
//This function checkPublicReferences of the workspace object and alert the user appropriately 
function checkPublicReferences()
{
if(document.getElementById('from') && document.getElementById('publicSharedPath')){
	var from=document.getElementById('from').value;
	var personalPath=document.getElementById('publicSharedPath').innerHTML;
	if(personalPath.length > 0 && (from !="" && from.length > 0 )){
	 if(!document.getElementById('cpublic').checked && !(from == 'FOLDER_PERSONAL_SYSTEM' || from == 'FOLDER_PERSONAL')){
 		var error_code;
 			if(from=='FOLDER_PUBLIC' || from == 'FOLDER_PUBLIC_SYSTEM')
 				{error_code="WS.MSG.PUBLIC_REF_REMOVAL_ALONE";}
 			else
 				{error_code="WS.MSG.PUBLIC_REF_REMOVAL";}
		var status=confirm(_gl_getMessage(error_code));
		if(!status){ document.getElementById('cpublic').checked = true;enableBrowse();}
		}
	}
}
}
//This function checkUserReferences of the workspace object and alert the user appropriately 
function checkUserReferences(chkBoxId,buttonId)
{
if(document.getElementById('from') && document.getElementById('IndNames')){
	var from=document.getElementById('from').value;
	var personalPath=document.getElementById('IndNames').innerHTML;
	if(personalPath.length > 0 &&(from !="" && from.length > 0 )){
	if(!document.getElementById(chkBoxId).checked && !(from == 'FOLDER_PERSONAL_SYSTEM' || from == 'FOLDER_PERSONAL')){
		var status=confirm(_gl_getMessage("WS.MSG.GROUP_INDIV_REMOVAL"));
		if(!status){ document.getElementById(chkBoxId).checked  = true; document.getElementById(buttonId).disabled=false;} 
		}
	}
}
}
//This function checkSharedReferences of the workspace object and alert the user appropriately 
function checkSharedReferences(chkBoxId,buttonId)
{
if(document.getElementById('from') && document.getElementById('publicSharedPath')){
	var from=document.getElementById('from').value;
	var publicPath=document.getElementById('publicSharedPath').innerHTML;
	var recipients=document.getElementById('IndNames').innerHTML;
	if((publicPath !="" && publicPath.length > 0 )|| (recipients !="" && recipients.length > 0 ) && !document.getElementById('rpermissionsShared').checked &&(from !="" && from.length > 0 )){
	if((document.getElementById('cpublic').checked || document.getElementById(chkBoxId).checked )&& !(from == 'FOLDER_PERSONAL_SYSTEM' || from == 'FOLDER_PERSONAL')){
		var error_code;
 			if(from=='FOLDER_PUBLIC' || from == 'FOLDER_PUBLIC_SYSTEM')
 				{error_code="WS.MSG.PUBLIC_REF_REMOVAL_ALONE";}
 			else
 				{error_code="WS.MSG.SHARED_REMOVAL";}
		var status=confirm(_gl_getMessage(error_code));
		if(!status){ 
		document.getElementById('rpermissionsShared').checked=true;
		document.getElementById('cpublic').disabled=false;
		document.getElementById(chkBoxId).disabled=false;
		if(publicPath !="" && publicPath.length > 0 )document.getElementById('cpublic').checked = true;enableBrowse();
		if(recipients !="" && recipients.length > 0){
		document.getElementById(chkBoxId).checked  = true; 
		document.getElementById(buttonId).disabled=false;
		}
		}
		}
	}
}
}
// Utility method to get the number of equals symbol in a query. Only in term search queries. 
function getEqualsCount(inputString) {
  var equalsFlag = false;
  var quotesFlag = false;
  var equalsCounter = 0;
  var tempChar = "";
  for(var i=0;i<inputString.length;i++) {
    tempChar = inputString.charAt(i);
    if(tempChar=="\"") {
      quotesFlag = !quotesFlag;
    }
    if(tempChar=="=") {
      if(quotesFlag==false) {
        equalsCounter++;
      }
    }
  }
  return equalsCounter;
}

function findUnion(fields1, fields2) {
  var k = fields1.length;
  for (var i = 0; i < fields2.length; i++) {
    var flag = false;
    for (j = 0; j < fields1.length; j++) {
      if (fields2[i].toUpperCase() == fields1[j].toUpperCase()) {
        flag = true;
        break;
      }
    }
    if (!flag) {
      fields1[k++] = fields2[i];
    }
  }
  return fields1;
}

function findDifference(fields1, fields2) {
  var fields = new Array();
  var isAvailable = false;
  var k = 0;
  for (i = 0; i < fields1.length; i++) {
    for (j = 0; j < fields2.length; j++) {
      if (fields1[i].toUpperCase() == fields2[j].toUpperCase()) {
      	isAvailable = true;
      	break;
      }
    }
    if(!isAvailable){
    fields[k++] = fields1[i];
    }
    isAvailable = false;
  }
  return fields;
}

function enablePersonal(){
if(document.getElementById('rpermissionsPersonal').checked){
if(document.getElementById('browseTree'))document.getElementById('browseTree').disabled=false;
if(document.getElementById('lblPersonal'))document.getElementById('lblPersonal').className="frmData";
}else{
if(document.getElementById('browseTree'))document.getElementById('browseTree').disabled=true;
if(document.getElementById('lblPersonal'))document.getElementById('lblPersonal').className="frmGrayData";
}
}


/** 
 * Removes the unwanted char,if present at the last at the end of the given string 
 * str -> string to be removed.
 * char1 -> string checked for matching.
 * noTrim -> true - donot trim the strings. default false.
 * noRecursive -> true - donot recursively remove the string. default false. 
 */ 
function removeLastUnwantedChar(str,char1,noTrim,noRecursive)
{
    if(str.length > 0 && char1.length>0)
    {
    	if(!noTrim)
    	{
            str = trim(str);
            char1 = trim(char1);
    	}
        if (str.lastIndexOf(char1)+char1.length  == str.length)
        {
            str = str.substring(0,str.length-char1.length);
            if(!noRecursive)
            {
                str = removeLastUnwantedChar(str,char1,noTrim,noRecursive);
            }
        }
    }
    return str;
}


function loadGeneralPreferencePage() {
    var d = new Date();
    var url = "preferencesGeneral.do?time=" + d.getTime();
    window.location = url;
}
function addElements(form)
{
    var newdiv = document.createElement('div');
    newdiv.innerHTML = "<input type='hidden' name='fields' value='addedField'> <input type='hidden' name='value' value=''>";
    form.appendChild(newdiv); 
}

/**
 * This method will get the object id and checks if it is available in document object and returns its value, 
 * if it has value else empty string.
 * Use this method for more readability and less LOC in JS codes
 */
function checkAndReturnValue(objectID)
{
    var obj = document.getElementById(objectID);
    if(obj)
    {
        return obj.value.trim();
    }
    return "";
    
}




function loadHighlightPreferencePage() {
    var d = new Date();
    var url = "preferencesHighlighting.do?time=" + d.getTime();
    window.location = url;
}

function trimSpaceAndLineFeed(str)
{
	if(str != " " || str != "" || str != null)
		return str.replace(/[\n\r]/g," ");
	else
		return str;
}