
// Initialization Functions //

function SetSelected(FormElement,CurrentValue){
  for (i=0;i<document.form[FormElement].length;i++){
    if (document.form[FormElement].options[i].value == CurrentValue){
      document.form[FormElement].selectedIndex = i
      break
    }
  }
}

function SetSelectedByText(FormElement,CurrentValue){
  for (i=0;i<document.form[FormElement].length;i++){
    if (document.form[FormElement].options[i].text == CurrentValue){
      document.form[FormElement].selectedIndex = i
      break
    }
  }
}

function SetSelectedMultiple(FormElement,CurrentValue){
  var firstSel;
  var safeList = CurrentValue.split(", ").join("|,|");
  safeList = "|" + safeList + "|";
  for (i=0;i<document.form[FormElement].length;i++) {
    if ( (safeList.indexOf("|" + document.form[FormElement].options[i].value + "|") > -1)
        &&  (document.form[FormElement].options[i].value != "") ){
      document.form[FormElement].options[i].selected = true;
    } else {
      document.form[FormElement].options[i].selected = false;
    }
  }
}

function SetSelectedMultipleByText(FormElement,CurrentValue){
  for (i=0;i<document.form[FormElement].length;i++){
    if (CurrentValue.indexOf(document.form[FormElement].options[i].text) > -1){
      document.form[FormElement].options[i].selected = true;
    } else {
      document.form[FormElement].options[i].selected = false;
    }
  }
}

function InsertChecks(FormElement,Values){
  if(document.form[FormElement].length) {
      for (i=0;i<document.form[FormElement].length;i++){
        if (Values.indexOf(document.form[FormElement][i].value) != -1){
          document.form[FormElement][i].checked = true
        }
      }
  } else {
    if (Values.indexOf(document.form[FormElement].value) != -1){
      document.form[FormElement].checked = true
    }
  }
}

function SetRadio(FormElement,Value){
  for (i=0;i<document.form[FormElement].length;i++){
    if (document.form[FormElement][i].value == Value){
      document.form[FormElement][i].checked = true
    }
  }
}

function SetValue( fldName, val ) {
  document.getElementById( fldName ).value = val;
}

function SetDate( fldName, val ) {
  var fmt
  if ( val == "" ) {
    fmt = "";
  } else {
    var d = new Date( val )
    fmt = d.getFullYear() + "-" + twoDigit(d.getMonth()+1) + "-" + twoDigit(d.getDate())
  }
  document.getElementById( fldName ).value = fmt;
}

function GetATCDate( val ) {
  var fmt;
  var arr = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
  if ( val == "" ) {
    fmt = "";
  } else {
    var d = new Date( val );
    //fmt = arr[d.getMonth()] + " " + twoDigit(d.getDate()) + ", " + d.getFullYear();
    fmt = d.getFullYear() + "-" + arr[d.getMonth()] + "-" + twoDigit(d.getDate());
  }
  return fmt;
}

function SetContractStartDate( fldName, val ) {
    if (val == "") {
        SetDate( fldName, "2/1/2007" );
    }
}

function SetContractEndDate( fldName, val ) {
    if (val == "") {
        SetDate( fldName, "01/31/2008" );
    }
}

/* Begin BOOKMARK code */

var displayFieldNames;
displayFieldNames = "";
displayFieldNames = "_ContactRole_SiteRole_PartnerType_PartnerTypeStatus_SiteStatus_OrgFields_SiteFields";
displayFieldNames += "_ContactFields_ParentFields_GeneralFields_SiteOrContactFields";
displayFieldNames += "_SNFields_InvoiceFields_ActivityId_Product_InvoiceType_batchSize_loggedSince";
displayFieldNames += "_Geo_Region_SubRegion_CountryCode_SubCountry_Industry_SiteRoleStatus_Language";
displayFieldNames += "_OrgGeo_OrgRegion_OrgSubRegion_OrgCountryCode_OrgSubCountry";
displayFieldNames += "_SiteGeo_SiteRegion_SiteSubRegion_SiteCountryCode_SiteSubCountry";

function processSaveStr( saveStr ) {
  if ( saveStr != "" ) {
    fldData = saveStr.split("|")
    for ( var i = 0 ; i < fldData.length ; i++ ) {
        if ( fldData[i] != null ) {
            fldParts = fldData[i].split(">")
            if ( fldParts[0] != null ) {
                fldName = fldParts[0];
                if ( fldName != "" ) {
                    var elm = document.getElementById( fldName );
                    if ( "_StartDate_EndDate_".indexOf( fldName ) > 0 ) {
                        elm.value = fldParts[1];
                    } else {
                        if ( "_equal_".indexOf( fldName ) > 0 ) {
                            SetRadio("equal",fldParts[1])
                        } else {
                            fldSelections = fldParts[1].split("_");
                            if ( fldSelections[0] == "ON" ) {
                                elm.checked = true;
                            } else {
                                elm.selectedIndex = -1
                                if ( displayFieldNames.indexOf( fldName ) > 0 ) {
                                    var valueList = "";
                                    for ( var j = 0 ; j < fldSelections.length ; j++ ) {
                                        if ( valueList = "" ) valueList = valueList + "," ;
                                        elm.options[fldSelections[j]].selected = "true"
                                        valueList = valueList + elm.options[fldSelections[j]].value
                                        if ( fldName == "OrgGeo" ) {
                                            OrgGeoChanged( document.form, elm.options[fldSelections[j]].value );
                                        }
                                        if ( fldName == "SiteGeo" ) {
                                            SiteGeoChanged( document.form, elm.options[fldSelections[j]].value );
                                        }
                                    }
                                    if ( fldName == "Geo" ) {
                                        pdbGeoChanged( document.form, valueList );
                                    }
                                    if ( fldName == "Region" ) {
                                        pdbRegionChanged( document.form, valueList );
                                    }
                                    if ( fldName == "SubRegion" ) {
                                        pdbSubRegionChanged( document.form, valueList );
                                    }
                                    if ( fldName == "CountryCode" ) {
                                        pdbCountryChanged( document.form, valueList );
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
  }
}

function findSelections( fldName ) {
    var str = "";
    var elm = document.getElementById( fldName );
    for ( var i = elm.length - 1 ; i >= 0  ; i-- ) {
        if ( elm.options[i].selected ) {
            var val;
            if ( displayFieldNames.indexOf( fldName ) > 0 ) {
                val = i;
            } else {
                val = elm.options[i].value;
            }
            if ( str == "" ) {
                str = fldName + ">" + val;
            } else {
                str += "_" + val;
            }
        }
    }
    if (str != "" ) {
        str += "|"
    }
    if ( str.indexOf(fldName + ">|") == 0 ) {
        str = "";
    }
    return str;
}

function findChecks( fldName ) {
    var str = "";
    var elm = document.getElementById( fldName );
    if ( elm.checked ) {
        str = fldName + ">ON|";
    }
    return str;
}

function findRadio( fldName ) {
    var str = "";
    var elm = eval("document.form." + fldName );
    for ( var i = elm.length - 1 ; i >= 0  ; i-- ) {
        if ( elm[i].checked ) {
            str = fldName + ">" + elm[i].value + "|";
        }
    }
    return str;
}

function findDate( fldName ) {
    var str = "";
    var elm = document.getElementById( fldName );
    if ( elm.value != "" ) {
        str = fldName + ">" + elm.value + "|";
    }
    return str;
}

/* End BOOKMARK code  */

function twoDigit( val ) {
  val = val + ""
  if (val.length == 2) {
    return val;
  }
  if (val.length == 1) {
    return "0" + val;
  }
}

function geoChanged( f, val, countryCode ) {
    f.CountryCode.length = 0;
    for ( var i = 0 ; i < gcoArray.length ; i++ ) {
        var c = gcoArray[i];
        var region = c.geo.substr(c.geo.indexOf(":") + 1);
        var geo = c.geo.substr(0,c.geo.indexOf(":"));
        if ( val.indexOf( c.geo ) > -1 || val.indexOf( geo + ":All" ) > -1 || val == "AllGeos" ) {
            f.CountryCode.options[f.CountryCode.options.length] = new Option( c.country, c.countryCode );
        }
    }
    return true;
}

function pdbGeoChanged( f, val, countryCode ) {
    var safeList = val.split(",").join("|");
    safeList = "|" + safeList + "|";
    var ctryArray = new Array();
    var lastRegion = ""
    f.Region.length = 0;
    f.SubRegion.length = 0;
    f.CountryCode.length = 0;
    f.SubCountry.length = 0;
    for ( var i = 0 ; i < gcoArray.length ; i++ ) {
        var c = gcoArray[i];
        if ( safeList.indexOf( "|" + c.geo + "|" ) > -1 || val == "All" ) {
            ctryArray[ctryArray.length] = c.country;
            if (val != "All" ) {
                if ( c.region != lastRegion ) {
                    f.Region.options[f.Region.options.length] = new Option( c.regionName, c.region );
                    lastRegion = c.region
                }
            }
        }
    }
    ctryArray.sort()
    for ( var i = 0 ; i < ctryArray.length ; i++ ) {
        for ( var j = 0 ; j < gcoArray.length ; j++ ) {
            var c = gcoArray[j];
            if ( ctryArray[i] == c.country ) {
                f.CountryCode.options[f.CountryCode.options.length] = new Option( c.country, c.countryCode );
            }
        }
    }
    return true;
}

function pdbRegionChanged( f, val, countryCode ) {
    var safeList = val.split(",").join("|");
    safeList = "|" + safeList + "|";
    var ctryArray = new Array();
    var lastRegion = ""
    f.SubRegion.length = 0;
    f.CountryCode.length = 0;
    f.SubCountry.length = 0;
    for ( var i = 0 ; i < gcoArray.length ; i++ ) {
        var c = gcoArray[i];
        if ( safeList.indexOf( "|" + c.region + "|" ) > -1 ) {
            ctryArray[ctryArray.length] = c.country;
            if ( c.subregion != lastRegion ) {
                f.SubRegion.options[f.SubRegion.options.length] = new Option( c.subregionName, c.subregion );
                lastRegion = c.subregion
            }
        }
    }
    ctryArray.sort()
    for ( var i = 0 ; i < ctryArray.length ; i++ ) {
        for ( var j = 0 ; j < gcoArray.length ; j++ ) {
            var c = gcoArray[j];
            if ( ctryArray[i] == c.country ) {
                f.CountryCode.options[f.CountryCode.options.length] = new Option( c.country, c.countryCode );
            }
        }
    }
    return true;
}

function pdbSubRegionChanged( f, val, countryCode ) {
    var safeList = val.split(",").join("|");
    safeList = "|" + safeList + "|";
    var ctryArray = new Array();
    f.CountryCode.length = 0;
    f.SubCountry.length = 0;
    for ( var i = 0 ; i < gcoArray.length ; i++ ) {
        var c = gcoArray[i];
        if ( safeList.indexOf( "|" + c.subregion + "|" ) > -1 ) {
            ctryArray[ctryArray.length] = c.country;
        }
    }
    ctryArray.sort()
    for ( var i = 0 ; i < ctryArray.length ; i++ ) {
        for ( var j = 0 ; j < gcoArray.length ; j++ ) {
            var c = gcoArray[j];
            if ( ctryArray[i] == c.country ) {
                f.CountryCode.options[f.CountryCode.options.length] = new Option( c.country, c.countryCode );
            }
        }
    }
    return true;
}

function pdbCountryChanged( f, val ) {
    f.SubCountry.length = 0;
    for ( var i = 0 ; i < scoArray.length ; i++ ) {
        var c = scoArray[i];
        if ( val.indexOf( c.countryCode ) > -1 ) {
            f.SubCountry.options[f.SubCountry.options.length] = new Option( c.subCountry, c.subCountry );
        }
    }
}


function SiteGeoChanged( f, val ) {
    f.SiteCountryCode.length = 0;
    f.SiteCountryCode.options[0] = new Option( "" );
    for ( var i = 0 ; i < gcoArray.length ; i++ ) {
        var c = gcoArray[i];
        var region = c.geo.substr(c.geo.indexOf(":") + 1);
        var geo = c.geo.substr(0,c.geo.indexOf(":"));
        if ( val.indexOf( c.geo ) > -1 || val.indexOf( geo + ":All" ) > -1 || val == "AllGeos" ) {
            f.SiteCountryCode.options[f.SiteCountryCode.options.length] = new Option( c.country, c.countryCode );
        }
    }
    return true;
}

function OrgGeoChanged( f, val ) {
    f.RegisteredCountryCode.length = 0;
    f.RegisteredCountryCode.options[0] = new Option( "" );
    for ( var i = 0 ; i < gcoArray.length ; i++ ) {
        var c = gcoArray[i];
        var region = c.geo.substr(c.geo.indexOf(":") + 1);
        var geo = c.geo.substr(0,c.geo.indexOf(":"));
        if ( val.indexOf( c.geo ) > -1 || val.indexOf( geo + ":All" ) > -1 || val == "AllGeos" ) {
            f.RegisteredCountryCode.options[f.RegisteredCountryCode.options.length] = new Option( c.country, c.countryCode );
        }
    }
    return true;
}

function changedCountry( obj, prefix ) {
// If country is managed, fill the StateProvince pulldown, hide the textbox, show the pulldown
// When pulldown is filled, save to hidden textbox
    if(obj.options) {
        var countrycode = obj.options[obj.selectedIndex].value;
    } else {
        var countrycode = obj.value;
    }
    var pulldown = eval("document.form." + prefix + "StateProvincePulldown");
    var textbox = eval("document.form." + prefix + "StateProvinceTxt");
    var StateProvinceRedStar = document.getElementById(prefix + "StateProvinceRedStar");
    var PostalCodeRedStar = document.getElementById(prefix + "PostalCodeRedStar");
    if ( countrycode != "" && g_managedCountryList.indexOf( "_" + countrycode + "_" ) > -1 ) {
        pulldown.length = 1;
        for ( var i = 0 ; i < g_countryStateMap.length ; i++ ) {
            var c = g_countryStateMap[i];
            if ( c[0] == countrycode ) {
                pulldown.options[pulldown.options.length] = new Option( c[1], c[2] );
            }
        }
        pulldown.style.display = "inline";
        StateProvinceRedStar.style.display = "inline";
        textbox.style.display = "none";
    } else {
        pulldown.style.display = "none";
        StateProvinceRedStar.style.display = "none";
        textbox.style.display = "inline";
    }
    if ( countrycode == "US" ) {
        PostalCodeRedStar.style.display = "inline";
    } else {
        PostalCodeRedStar.style.display = "none";
    }
    ValidateInputSelect( obj, null, obj.name );
}

function updateHiddenState( val, prefix ) {
    document.getElementById(prefix + "StateProvince").value = val;
}

function changedIndustry( obj ) {
    var industry = obj.options[obj.selectedIndex].value;
    var pulldown = document.form.SubIndustry;
    pulldown.length = 1;
    for ( var i = 0 ; i < g_industryMap.length ; i++ ) {
        var c = g_industryMap[i];
        if ( c[0] == industry ) {
            pulldown.options[pulldown.options.length] = new Option( c[2], c[1] );
        }
    }
    if ( pulldown.length == 2 ) {
        pulldown[1].selected = true;
    }
    ValidateInputSelect( pulldown, null, pulldown.name );
    if ( obj.name == "Industry" ) {
        ValidateInputSelect( obj, null, obj.name );
    }
}


function makeValueList( obj ) {
    var val = ""
    if (obj != null && obj.options != null) {
        for ( var i = 0 ; i < obj.options.length ; i++ ) {
            if ( obj.options[i].selected ) {
                if ( val != "" ) {
                    val = val + ","
                }
                val = val + obj.options[i].value
            }
        }
    }
    return val;
}

function OrderBy( fldName ) {
    document.form.orderBy.value = fldName;
    document.form.submit();
}

function showAddressList( fldName ) {
    document.form.showAddressList.value = fldName;
    document.form.submit();
}

function navhighlight( obj, overOrOut ) {
    if ( overOrOut == "over" ) {
        obj.style.backgroundColor = "#efefef"
    }
    if ( overOrOut == "out" ) {
        obj.style.backgroundColor = "white"
    }
}


// Validation Functions //

function IsPresent(value) {
  IsEmpty = true
  if (value.length > 0){
    for (i=0;i<value.length;i++){
      if (value.charAt(i) != " "){
        IsEmpty = false
        break
      }
    }
  }
  return !IsEmpty
}

function ValidEmailAddress(EmailAddress) {
  var regexp = /^[a-zA-Z0-9&._'-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/
  var IsValid = regexp.test(EmailAddress)
  return IsValid
}

//' restoring string balance

function InvalidPassword(value) {
  var regexp = /[^a-zA-Z0-9]+/
  var IsInvalid = regexp.test(value)
  return IsInvalid
}

function IsNumber(input){
  var checkOK = "0123456789";
  for (i = 0;  i < input.length;  i++)
  {
    c = checkOK.indexOf(input.charAt(i));
    if (c < 0) return (false);
  }
  return (true);
}

function IsNumber2(input){
  var checkOK = "0123456789,";
  for (i = 0;  i < input.length;  i++)
  {
    c = checkOK.indexOf(input.charAt(i));
    if (c < 0) return (false);
  }
  return (true);
}

function IsNumber3(input){
  var checkOK = "0123456789,.";
  for (i = 0;  i < input.length;  i++)
  {
    c = checkOK.indexOf(input.charAt(i));
    if (c < 0) return (false);
  }
  return (true);
}

function ValidateInputNumber( obj, labelId, labelText, len ) {
  if (!IsPresent(obj.value))
  {
    return ValidateInputFail( obj, labelId, labelText + " cannot be blank.  " );
  }
  if (!IsNumber(obj.value))
  {
    return ValidateInputFail( obj, labelId, labelText + " must be numeric.  " );
  }
  if (obj.value.length > len)
  {
    return ValidateInputFail( obj, labelId, labelText + " cannot exceed " + len + " characters.  " );
  }
  return (true);
}

function ValidateInputText( obj, labelId, labelText ) {
  if (!IsPresent(obj.value)) {
    return ValidateInputFail( obj, labelId, labelText + " cannot be blank.  " );
  }
  return true;
}

function ValidateInputRadio( obj, labelId, labelText ) {
  for ( var i = 0 ; i < obj.length ; i++ ) {
    if (obj[i].checked) {
      return true;
    }
  }
  Select( labelId );
  alert( labelText + " cannot be blank.  " );
  return false;
}

function ValidateInputSelect( obj, labelId, labelText ) {
  if ( obj.selectedIndex == 0 ) {
    return ValidateInputFail( obj, labelId, labelText + " cannot be blank.  " );
  }
  return true;
}

function ValidateInputSelectNoRed( obj, labelText ) {
  if ( obj.selectedIndex == 0 ) {
    alert( labelText + " cannot be blank.  " );
    obj.focus();
    return (false);
  }
  return true;
}

function ValidateInputTextLength( obj, labelId, labelText, len ) {
  if (obj.value.length > len)
  {
    return ValidateInputFail( obj, labelId, labelText + " cannot exceed " + len + " characters.  " );
  }
  return true;
}

function ValidateInputFail( obj, labelId, msg ) {
  if (labelId ) {
      Select( labelId );
  }
  alert( msg );
  obj.focus();
  return (false);
}

function ValidateCurrency( strValue ) {
  var objRegExp  = /^\d+\.?\d{0,2}$/;
  return objRegExp.test(strValue);
}

function CheckNumber3( input ) {
  if ( ! IsNumber3(input) ) {
    alert("invalid number format")
  }
}

function CheckCurrency( input ) {
  if ( ! ValidateCurrency(input) ) {
    alert("invalid currency format")
  }
}

function RemoveCommas(input){
  var output = ""
  for (i=0; i < input.length; i++)
  {
    n = input.charAt(i)
    if (n != ",") output = output + n
  }
  return output
}

ActiveId = ""
function Select(ElementId,Bookmark){
  if (Select.arguments.length > 1) location.hash = Bookmark; else location.hash = "TopOfForm"
  if (ActiveId != "") document.getElementById(ActiveId).style.color = "black"
  ActiveId = ElementId
  document.getElementById(ActiveId).style.color = "red"
}

function showAsExcel( report ) {
    Initialize();
    document.form.Excel.value="excel";
//    document.form.action = report + "?excel=excel"
    document.form.submit();
}

function cutAndPaste( report ) {
    Initialize();
    document.form.Excel.value="clean";
//    document.form.action = report + "?excel=clean"
    document.form.submit();
}

function SelectResultsTable() {
     //MoveCounterDivs();
     var node=document.getElementById("resultsTable");
     var rng=document.body.createTextRange();
     rng.moveToElementText(node);
     rng.select();
}

function MoveCounterDivs() {
    var cdivs = document.getElementsByTagName("DIV");
    var newParent = document.getElementById("totalrecords").parentElement;
    for ( var i = 0 ; i < cdivs.length ; i++ ) {
        var elm = cdivs[i];
        if ( elm.name == "counterdiv" ) {
            newParent.appendChild( elm );
        }
    }
}

function getSurroundingForm( obj ) {
    if ( obj.tagName = "FORM" ) {
        alert( obj.tagName );
        return;
    } else {
        return getSurroundingForm( obj.parentElement )
    }
}

function OpenWin(filename){
//  CloseWin()
  window.opener.location = filename;
//  win = window.open(filename,"win","width=900,height=500,resizable=yes,scrollbars=yes,menubar=yes,location=no,buttons=yes,screenX=60,screenY=60")
//  win.moveTo(60,60)
//  win.focus()
}
function CloseWin(){
  if (window.win){
    if (!win.closed) win.close()
  }
}

function OpenReport(filename){
  CloseReport()
  filename = filename.replace("A&P Inv","A%26P Inv")
  report = window.open(filename,"report","width=980,height=600,resizable=yes,scrollbars=yes,menubar=yes,location=yes,buttons=yes,screenX=20,screenY=20,status=yes")
  report.moveTo(20,20)
  report.focus()
}
function CloseReport(){
  if (window.report){
    if (!report.closed) report.close()
  }
}

function GoToOrg(OrgId){
  GoToEditor( "orgsummary.asp", "orgId=" + OrgId )
}
function GoToSite(OrgId, SiteId){
  GoToEditor( "sitesummary.asp", "orgId=" + OrgId + "&siteId=" + SiteId )
}
function GoToContact(ContactId){
  GoToEditor( "contactsummary.asp", "contactId=" + ContactId )
}
function GoToContactSite( OrgId, SiteId, ContactId){
  GoToEditor( "contactsummary.asp", "context=SITE&orgId=" + OrgId + "&siteId=" + SiteId + "&contactId=" + ContactId )
}

function GoToOrgEdit(OrgId){
  GoToEditor( "orgbasic.asp", "orgId=" + OrgId )
}
function GoToSiteEdit(OrgId, SiteId){
  GoToEditor( "sitebasic.asp", "orgId=" + OrgId + "&siteId=" + SiteId)
}
function GoToContactEdit(ContactId){
  GoToEditor( "contact.asp", "contactId=" + ContactId )
}
function GoToContactEditSite( OrgId, SiteId, ContactId){
  GoToEditor( "contact.asp", "context=SITE&orgId=" + OrgId + "&siteId=" + SiteId + "&contactId=" + ContactId )
}

function GoToJournal( args ){
  GoToEditor( "journal.asp", args )
}
function GoToInvoice( args ){
  GoToEditor( "invoice.asp", args )
}
function GoToSerialNumber( args ){
  GoToEditor( "serialnumber.asp", args )
}
function GoToQualification( args ){
  GoToEditor( "qualification.asp", args )
}

function GoToEditor( editorPage, args ){
  if (window.opener ) {
      window.opener.location = "../data/" + editorPage + "?" + args
      window.opener.focus()
  } else {
      document.location = "../data/" + editorPage + "?" + args
  }
}

function showDiv( obj, saveCookie ) {
    var id = obj.id;
    var atcDiv = document.getElementById("atcDiv");
    var authorsPublishersDiv = document.getElementById("authorspublishersDiv");
    var varDiv = document.getElementById("varDiv");
    if (atcDiv) atcDiv.style.display = "none";
    if (authorsPublishersDiv) authorsPublishersDiv.style.display = "none";
    if (varDiv) varDiv.style.display = "none";

    document.getElementById("ATC").style.borderBottomColor = "#000000";
    document.getElementById("VAR").style.borderBottomColor = "#000000";
    document.getElementById("AuthorsPublishers").style.borderBottomColor = "#000000";

    if ( id == "ATC" ) {
        if (atcDiv) atcDiv.style.display = "block";
        obj.style.borderBottomColor = "#85c3c2";
    }
    if ( id == "VAR" ) {
        if (varDiv) varDiv.style.display = "block";
        obj.style.borderBottomColor = "#77BB11";
    }
    if ( id == "AuthorsPublishers" ) {
        if (authorsPublishersDiv) authorsPublishersDiv.style.display = "block";
        obj.style.borderBottomColor = "#abcdef";
    }
    if ( saveCookie ) {
        setPersistentCookie("lastTab", id);
    }
}

//Action=Edit&ParentId=AM0132&OrgId=ORG111&SiteId=AM0132&ContactId=&ActivityType=Site+Attribute&JournalId=615

// ADDRESS & PERSON Mini forms //

function copyAddress( f, fromType, toType ) {
    copyAddressItem( f, fromType, toType, "Department" );
    copyAddressItem( f, fromType, toType, "Address1" );
    copyAddressItem( f, fromType, toType, "Address2" );
    copyAddressItem( f, fromType, toType, "Address3" );
    copyAddressItem( f, fromType, toType, "City" );
    copyAddressItem( f, fromType, toType, "CountryCode" );
    copyAddressItem( f, fromType, toType, "StateProvince" );
    copyAddressItem( f, fromType, toType, "StateProvincePulldown" );
    copyAddressItem( f, fromType, toType, "StateProvinceTxt" );
    copyAddressItem( f, fromType, toType, "PostalCode" );
    ToggleButtons();
}

function copyPerson( f, fromType, toType ) {
    copyAddressItem( f, fromType, toType, "FirstName" );
    copyAddressItem( f, fromType, toType, "LastName" );
    copyAddressItem( f, fromType, toType, "EmailAddress" );
    copyAddressItem( f, fromType, toType, "Telephone" );
    copyAddressItem( f, fromType, toType, "Fax" );
    ToggleButtons();
}

function copyAddressItem( f, fromType, toType, fldName ) {
    if ( fldName == "StateProvincePulldown" || fldName == "StateProvinceTxt") {
        var fromObj = eval( "f." + fromType + "StateProvince" )
    } else {
        var fromObj = eval( "f." + fromType + fldName )
    }
    var toObj = eval( "f." + toType + fldName )
    if ( fromObj != null && toObj != null) {
        if(toObj.options) {
            SetSelected( toType + fldName, fromObj.value );
        } else {
            toObj.value = fromObj.value;
        }
    }
    if ( fldName == "CountryCode" ) {
        changedCountry( fromObj, toType );
    }
}

// Cookie Functions //

function setPersistentCookie(name, value){
    setCookie2(name, value, "300")
}

function setCookie2(c_name,value,expiredays) {
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function setCookie(name, value, expires, path, domain, secure){
  var curCookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    "; path=/" +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

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 deleteCookie(name, path, domain){
  if (getCookie(name)){
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// End //
