var tableArray;
var tableItem;
var tableOffset;
var chWin = null;
var childOpen = false;
var removeArray = [];
var unalteredSize;
var dataTypeArray = [];
var dataTypeOk = false;
var DisplayWindow;
var CopyWindow;
var CommentWindow;
var msabForm;
var msabName;
var msabKey;
var msabAdd;
var criteria = "Starts With";
var metadatadisclaimer = "These metadata attributes include the Registration Authority's specification and may contain blanks for information which hasn't been provided to USHIK.";

function setAdminCookie(admin){
    document.cookie = "privateSite=" + admin;
}
function showHideDesc(elementid){
    if (document.getElementById(elementid).style.display == 'none'){
        document.getElementById(elementid).style.display = 'block';
        document.cookie = elementid + "=yes";
    }
    else {
        document.getElementById(elementid).style.display = 'none';
        document.cookie = elementid + "=no";
    }
}

function checkDescriptionView(elementid){
    //alert("in checktDescriptionView");
    var cookieString = document.cookie;
    //alert("cookie = " + cookieString);
    try{
        if(cookieString.indexOf(elementid + "=no", 0) > 0){
            document.getElementById(elementid).style.display = 'none';
        }
        else {
            document.getElementById(elementid).style.display = '';
        }
    } catch(err){}
}
function checkDownload(){
    var downLoad = location.search.indexOf("&DownFile=");
    if(downLoad > -1){
        fileName = location.search.substring(downLoad+10);
        urlPath = document.URL.indexOf("/dr.");
        path = document.URL.substring(0, urlPath+1);
        pathFile = path+fileName;
            javascript:popUpWindow(pathFile);
    }
}
function popUpWindow(URL) {
    day = new Date();
    //id = day.getTime();
    id="ushik_popup"
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 320,top = 50');");
}
function setFontSelection(selFont){
    try{
        var numOptions = document.forms['ChgFont'].FontFamily.options.length;
        for (i=0; i<numOptions; i++){
            if(selFont==document.forms['ChgFont'].FontFamily.options[i].text){
                document.forms['ChgFont'].FontFamily.selectedIndex=i;
                break;
            }
        }
    } catch(err){}
}
function setFontSizeSelection(selSize){
    try{
        var numOptions = document.forms['ChgFont'].FontSize.options.length;
        for (i=0; i<numOptions; i++){
            if(selSize==document.forms['ChgFont'].FontSize.options[i].text){
                document.forms['ChgFont'].FontSize.selectedIndex=i;
                break;
            }
        }
    } catch(err){}
}
function checkForFontChange(){
    var cookieString = document.cookie;
    var indexFont = cookieString.indexOf("chgFont",0);
    var indexSize = cookieString.indexOf("chgSize",0);
    if (indexFont > -1) {
        endFont = cookieString.indexOf(";", indexFont);
        if (endFont == -1){
            endFont = cookieString.length;
        }
        var newFont = cookieString.substring(indexFont+8,endFont);
        changeFontFamily(newFont);
        setFontSelection(newFont);
    }
    if (indexSize > -1) {
        endSize = cookieString.indexOf(";", indexSize);
        if (endSize == -1){
            endSize = cookieString.length;
        }
        var newSize = cookieString.substring(indexSize+8,endSize);
        changeFontSize(newSize, 0);
        setFontSizeSelection(newSize);
    } else {
        changeFontSize('12px', 0);
        setFontSizeSelection('12px');
    }
}
function changeFontFamily( chosenFont)
{  
    var p = document.getElementsByTagName('*');
    var sizeNow = false;
    document.cookie = "chgFont="+chosenFont;
    for(n=0; n<p.length; n++) {
        if (p[n].className == "resizeBody"){
            sizeNow = true;
        }
        if (sizeNow){
            p[n].style.fontFamily =chosenFont;
        }
    }
}
function changeFontSize(size, reload)
{ 
    //if(size.length > 2){
    //    size = size.substring(0,2) + 'px';
    //}
    //alert("The size is '" + size + "'");
    var p = document.getElementsByTagName('*');
    var sizeNow = false;
    document.cookie = "chgSize="+size;
    for(n=0; n<p.length; n++) {
        if (p[n].className == "resizeBody"){
            sizeNow = true;
        }
        if (sizeNow){
            p[n].style.fontSize =size;
        }
    }
    if (reload==1)
    {
        window.location.reload( false );
    }
}
function updateNavigation(id){
    var currentPath = "";
    var idSep = "IdSep";
    var nodeSep = "NodeSep";
    var cookieString = decodeURIComponent(document.cookie);
    var winName = window.name;
    //var viewPath = location.search.indexOf("system=mdr");
    //if (viewPath > -1){
    //     winPath = "mdr";
    //}
    //else {
    //     viewPath = location.search.indexOf("system=ps");
    //     if (viewPath > -1){
    //           winPath="ps";
    //     }
    //}
    var pathCookieName = winName + "Path";
    var begPath = document.cookie.indexOf(pathCookieName);
    if (begPath > -1){
        var endstr = cookieString.indexOf(";",begPath);
        if (endstr == -1){
            endstr = document.cookie.length;
        }
        var tempPath = cookieString.substring(begPath + 10,endstr);
        currentPath = tempPath;
    }
    var thisLoc = location.href;
    var thisQuery = location.search;
    if (currentPath.indexOf(id)> -1){
        var backupTo = currentPath.indexOf(thisLoc);
        if (backupTo > 0){
            currentPath = currentPath.substring(0,backupTo-7);
        }
        else {
            currentPath ="";
        }
    }
    if (currentPath.length == 1){
        currentPath = "";
    }
    else if (currentPath.length > 2){
        currentPath += nodeSep;
    }
    currentPath += thisLoc;
    currentPath += thisQuery;
    currentPath += idSep;
    currentPath += id;
    document.cookie = pathCookieName + "=" + encodeURIComponent(currentPath);
}
function getNavigationPath(id){
    var currentPath = "";
    var idSep = "IdSep";
    var nodeSep = "NodeSep";
    var pathName = window.name + "Path" + "=";
    var begPath = document.cookie.indexOf(pathName);
    if (begPath > -1){
        var endstr = document.cookie.indexOf(";",begPath);
        if (endstr == -1){
            endstr = document.cookie.length;
        }
        currentPath = decodeURIComponent(document.cookie.substring(begPath+pathName.length,endstr));
    }
    var thisLoc = location.href;
    if (currentPath.indexOf(id)> -1){
        var backupTo = currentPath.indexOf(thisLoc);
        if (backupTo > 8){
            currentPath = currentPath.substring(0,backupTo-7);
        }
        else {
            currentPath = "";
        }
    }
    var splitNodes = currentPath.split(nodeSep);
    if (currentPath.length > 0){
        for (var i = 0; i < splitNodes.length;i++){
            var nodeAndId = splitNodes[i].split(idSep);
            document.write("<Left>")
            if (nodeAndId.length == 2){
                if (i > 0){
                    document.write("&gt ");
                }
                document.write("<a href='");
                document.write(nodeAndId[0]);
                document.write("'>");
                var s1 = nodeAndId[1].replace("BSep"," ");
                document.write(s1);
                document.write("</a>");
            }
        }
    }
}
function lockAdminUserIdText() {
    if (!document.ADMINUSER.ADMINUSERNAME.value == "")
        document.ADMINUSER.ADMINUSERNAME.blur();
}

function lockThisPWText() {
    if (!document.ADMINUSER.ADMINPASSWORDCHANGEINTERVAL.value == "")
        document.ADMINUSER.ADMINPASSWORDCHANGEINTERVAL.blur();
}

//function lockThisText(form, field) {
// if (!form.value == "")
//  form.blur();
//}

/* Sean wrote this as generic form field checker ... please look at how it works
 *  before depending on it.
 *  The word "required" pre-pended before the form object name will be checked
 *  Special for dates: looks for the word "requireDate" and checks for format
 *  YYYY-MM-DD
 */

//NoDateRequired 


function checkrequired(which) {
    var focusFactor = {};
    var pass=true;
    var shortFieldName = "";
    if (document.images) {
        for (i=0;i<which.length;i++) {
            var tempobj=which.elements[i];
            if (tempobj.name.substring(0,8)=="required" ||tempobj.id.substring(0,8)=="required") {
                var fieldvalue = tempobj.value;
                if (((tempobj.type=="text"||tempobj.type=="textarea")&&
                    tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
                    tempobj.selectedIndex==0)) {
                    focusFactor[i] = tempobj;
                    pass=false;
                    shortFieldName=tempobj.id.substring(8,30).toUpperCase();
                    break;
                }
                if(tempobj.name == "requiredContextDescription" ||tempobj.id == "requiredContextDescription") {
                    if(tempobj.value.length > 125){
                        alert("Please make sure the Context Description is less than 125 characters.");
                        return false;
                    }
                }
            }
            else if ((tempobj.name.substring(0,11)=="requireDate" ||tempobj.id.substring(0,11)=="requireDate")  && tempobj.type=="text") {
                //alert("checking date field");
                
                
                if (!chkDate(tempobj.value)) {
                    focusFactor[i] = tempobj;
                    pass = false;
                    shortFieldName=tempobj.id.substring(11,30).toUpperCase();
                    break;
                }
            }
            else if ((tempobj.name.substring(0,14)=="NoDateRequired" || tempobj.id.substring(0,14)=="NoDateRequired") && tempobj.type=="text" && tempobj.value.length > 0) {
                //alert("checking date field" + tempobj.value);
                var value1 = tempobj.value;
                if(tempobj.name == "NoDateRequiredEffectiveDate" || tempobj.name=="CreationDate"){
                    if(value1.toString().toUpperCase()== "UNKNOWN"){
                        value1 = "1900-01-01";
                    }
                    if(value1.toString().toUpperCase()== "BLANK"){
                        value1 = "1990-01-01";
                    }
                    if(value1.toString().length == 0){
                        value1 = "1990-01-01";
                    }
                }
                if (!chkDate(value1)) {
                    focusFactor[i] = tempobj;
                    pass = false;
                    shortFieldName=tempobj.id.substring(14,30).toUpperCase();
                    break;
                }
            }
        }
    }
    if (!pass) {
        for (var n in focusFactor) {
            focusFactor[n].focus();
            break;
        }
        alert("Please make sure the "+shortFieldName+" field was properly completed.");
        return false;
    }
    else
        return true;
}

function checkUserAdminFields() {
    var missinginfo = "";
    var ch = "";
    var newString = "";
    var focusFactor = {};

    if (document.ADMINUSER.ADMINUSERNAME.value == "" || document.ADMINUSER.ADMINUSERNAME.value.indexOf("'") > -1) {
        missinginfo += "\n     -  User Identification is required. ";
        focusFactor[0] = document.ADMINUSER.ADMINUSERNAME;
    }
    if (document.ADMINUSER.ADMINFIRSTNAME.value == "" || document.ADMINUSER.ADMINFIRSTNAME.value.indexOf("'") > -1) {
        missinginfo += "\n     -  First Name is required. (No apostrophes)";
        focusFactor[1] = document.ADMINUSER.ADMINFIRSTNAME;
    }
    if (document.ADMINUSER.ADMINLASTNAME.value == "" || document.ADMINUSER.ADMINLASTNAME.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Last Name is required. (No apostrophes)";
        focusFactor[2] = document.ADMINUSER.ADMINLASTNAME;
    }
    if (document.ADMINUSER.ADMINTITLE.value.indexOf("'") > -1) {
        missinginfo += "\n     -  The use of apostrophes is not allowed.";
        focusFactor[3] = document.ADMINUSER.ADMINTITLE;
    }
    if (document.ADMINUSER.ADMINEMAIL.value == "" ||
        document.ADMINUSER.ADMINEMAIL.value.indexOf('.') == -1 ||
        document.ADMINUSER.ADMINEMAIL.value.indexOf('@') == -1 ) {
        missinginfo += "\n     -  Email Address is required. (user@mail.com)";
        focusFactor[4] = document.ADMINUSER.ADMINEMAIL;
    }
    if (document.ADMINUSER.ADMINPHONE.value == "") {
        missinginfo += "\n     -  Telephone Number is required. (555-555-5555\n\t\t\t  or 555.555.5555)";
        focusFactor[6] = document.ADMINUSER.ADMINPHONE;
    }
    else if ((document.ADMINUSER.ADMINPHONE.value.indexOf('.') == -1) && (document.ADMINUSER.ADMINPHONE.value.indexOf('-') == -1)) {
        missinginfo += "\n     -  Telephone Number in format 555-555-5555\n\t\t\t  or 555.555.5555";
        focusFactor[6] = document.ADMINUSER.ADMINPHONE;
    }
    if (document.ADMINUSER.ADMINPASSWORDVERIFY.value == "" || document.ADMINUSER.ADMINPASSWORD.value == "") {
        missinginfo += "\n     -  Passwords are required. ";
        focusFactor[8] = document.ADMINUSER.ADMINPASSWORD;
    }
    if (document.ADMINUSER.ADMINPASSWORD.value != document.ADMINUSER.ADMINPASSWORDVERIFY.value) {
        missinginfo += "\n     -  Passwords do no match. Please try again.";
        focusFactor[9] = document.ADMINUSER.ADMINPASSWORD;
    }
    if (document.ADMINUSER.ADMINPASSWORDCHANGEINTERVAL.value.length < 1) {
        missinginfo += "\n     -  Password Change Interval is required.";
        focusFactor[10] = document.ADMINUSER.ADMINPASSWORDCHANGEINTERVAL;
    }
    if (document.ADMINUSER.ADMINPASSWORDCHANGEINTERVAL.value.length > 0) {
        var valid = "0123456789"
        var ok = "yes";
        var temp;
        for (var i=0; i<document.ADMINUSER.ADMINPASSWORDCHANGEINTERVAL.value.length; i++) {
            temp = "" + document.ADMINUSER.ADMINPASSWORDCHANGEINTERVAL.value.substring(i, i+1);

            if (valid.indexOf(temp) == "-1") {
                //alert("checking for numbers: " + temp);
                ok = "no";
                break;
            }
        }
        if (ok == "no") {
            missinginfo += "\n     -  Password Change Interval must be a number.";
            focusFactor[10] = document.ADMINUSER.ADMINPASSWORDCHANGEINTERVAL;
        }
    }

    if (missinginfo != "") {
        missinginfo ="Please enter information or correct the following fields: \n - (Please do not use apostrophes)\n" +
        "_______________________________________________\n" +
        missinginfo + "\n_______________________________________________" +
        "\nPlease correct the form and submit again!";
        for (var n in focusFactor) {
            focusFactor[n].focus();
            break;
        }
        alert(missinginfo);
        return false;
    }
    else
        return true;
}

function checkOrgAdminFields() {
    var missinginfo = "";
    var ch = "";
    var newString = "";  
    var focusFactor = {};
    
    if (document.orgAdminForm.ORGNAME.value == "" || document.orgAdminForm.ORGNAME.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Organization Name is required. (No apostrophes)";
        focusFactor[0] = document.orgAdminForm.ORGNAME; 
    }   
    if (document.orgAdminForm.ORGABBREVIATION.value == "" || document.orgAdminForm.ORGABBREVIATION.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Organization Abbreviation is required. (No apostrophes)";
        focusFactor[1] = document.orgAdminForm.ORGABBREVIATION;
    }
    if (document.orgAdminForm.ADDRLINE1.value == "" || document.orgAdminForm.ADDRLINE1.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Organization Address is required. (No apostrophes)";
        focusFactor[2] = document.orgAdminForm.ADDRLINE1;
    }  
    if (document.orgAdminForm.CITY.value == "" || document.orgAdminForm.CITY.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Organization City is required. (No apostrophes)";
        focusFactor[3] = document.orgAdminForm.CITY;
    }  
    if (document.orgAdminForm.REGION.value == "" || document.orgAdminForm.REGION.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Organization Region is required. (No apostrophes)";
        focusFactor[4] = document.orgAdminForm.REGION;
    }  
    if (document.orgAdminForm.POSTAL.value == "" || document.orgAdminForm.POSTAL.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Organization Postal Code is required.";
        focusFactor[5] = document.orgAdminForm.POSTAL;
    } 
    if (document.orgAdminForm.ORGELECTRONICADDR.value == "" || document.orgAdminForm.ORGELECTRONICADDR.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Organization Internet or Email Address is required.";
        focusFactor[6] = document.orgAdminForm.ORGELECTRONICADDR;
    }  
    //if (document.orgAdminForm.ORGRA.checked == true) {
    // if (document.orgAdminForm.ORGTYPE.value == "") {
    //  missinginfo += "\n     -  Organization Type is required for a Registration Authority. ";
    //  focusFactor[7] = document.orgAdminForm.ORGTYPE;
    // }    
    // if (document.orgAdminForm.ORGDUNSNUMBER.value == "") {
    //  missinginfo += "\n     -  DUNS Number is required for a Registration Authority. ";
    //  focusFactor[8] = document.orgAdminForm.ORGDUNSNUMBER;
    // }    
    //}
    
    if (missinginfo != "") {
        missinginfo ="Please enter information or correct the following fields: \n - (Please do not use apostrophes)\n" +
        "_______________________________________________\n" +
        missinginfo + "\n_______________________________________________" +
        "\nPlease correct the form and submit again!";
        for (var n in focusFactor) {
            focusFactor[n].focus();
            break;
        }
        alert(missinginfo);
        return false;
    }
    else 
        return true;
}
function checkLoadFields() {
    var missinginfo = "";
    var ch = "";
    var newString = "";
    var focusFactor = {};
    if (document.upform.REPCLASSNAME.value.length < 3) {
        alert("in the if statement");
        missinginfo += "\n     -  Representation Class is required. ";
        focusFactor[0] = document.upform.REPCLASSNAME;
    }
    if (document.upform.REPCLASSNAME.value.indexOf("Data Element Concept") > 0 && document.upform.OBJCLASSNAME.value.length < 3) {
        missinginfo += "\n     -  Object Class required if Data Element Concept selected.";
        focusFactor[1] = document.upform.OBJCLASSNAME;
    }
    if (document.upform.CONTEXTCLASSNAME.value.length < 3) {
        missinginfo += "\n     -  Context is required.";
        focusFactor[2] = document.upform.CONTEXTCLASSNAME;
    }
    if (document.upform.OWNINGCLASSNAME.value.length < 3) {
        missinginfo += "\n     -  Owning Organization is required.";
        focusFactor[3] = document.upform.OWNINGCLASSNAME;
    }
    if (document.upform.RESPONSIBLECLASSNAME.value.length < 3) {
        missinginfo += "\n     -  Responsible Organization is required.";
        focusFactor[4] = document.upform.RESPONSIBLECLASSNAME;
    }
    if (document.upform.STEWARDCLASSNAME.value.length < 3) {
        missinginfo += "\n     -  Steward is required.";
        focusFactor[5] = document.upform.STEWARDCLASSNAME;
    }
    if (document.upform.SUBMITTINGCLASSNAME.value.length < 3) {
        missinginfo += "\n     -  Submitting Organization  is required.";
        focusFactor[6] = document.upform.SUBMITTINGCLASSNAME;
    }
    if (document.upform.SUBMITTERCLASSNAME.value.length < 3) {
        missinginfo += "\n     -  Submitter  is required.";
        focusFactor[7] = document.upform.SUBMITTERCLASSNAME;
    }
    if (missinginfo != "") {
        missinginfo ="Please enter information or correct the following fields: \n - (Please select one of the provided options.)\n" +
        "_______________________________________________\n" +
        missinginfo + "\n_______________________________________________" +
        "\nPlease correct the form and submit again!";
        alert(missinginfo);
        return false;
    }
    else
        return true;
}
function checkPersonAdminFields() {
    var missinginfo = "";
    var ch = "";
    var newString = "";  
    var focusFactor = {};
    
    if (document.PersonAdminForm.PERSONFIRSTNAME.value == "" || document.PersonAdminForm.PERSONFIRSTNAME.value.indexOf("'") > -1) {
        missinginfo += "\n     -  First Name is required. (No apostrophes)";
        focusFactor[0] = document.PersonAdminForm.PERSONFIRSTNAME; 
    }   
    if (document.PersonAdminForm.PERSONLASTNAME.value == "" || document.PersonAdminForm.PERSONLASTNAME.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Last Name is required. (No apostrophes)";
        focusFactor[1] = document.PersonAdminForm.PERSONLASTNAME;
    }
    if (document.PersonAdminForm.PERSONTITLE.value == "" || document.PersonAdminForm.PERSONTITLE.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Title is required. (No apostrophes)";
        focusFactor[2] = document.PersonAdminForm.PERSONTITLE;
    }
    if (document.PersonAdminForm.ADDRLINE1.value == "" || document.PersonAdminForm.ADDRLINE1.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Address is required. (No apostrophes)";
        focusFactor[3] = document.PersonAdminForm.ADDRLINE1;
    }  
    if (document.PersonAdminForm.CITY.value == "" || document.PersonAdminForm.CITY.value.indexOf("'") > -1) {
        missinginfo += "\n     -  City is required. (No apostrophes)";
        focusFactor[4] = document.PersonAdminForm.CITY;
    }  
    if (document.PersonAdminForm.REGION.value == "" || document.PersonAdminForm.REGION.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Region is required. (No apostrophes)";
        focusFactor[5] = document.PersonAdminForm.REGION;
    }  
    if (document.PersonAdminForm.ZIP.value == "" || document.PersonAdminForm.ZIP.value.indexOf("'") > -1) {
        missinginfo += "\n     -  Zip Code is required.";
        focusFactor[6] = document.PersonAdminForm.ZIP;
    } 
    if (document.PersonAdminForm.EMAIL.value == "" ||
        document.PersonAdminForm.EMAIL.value.indexOf("'") > -1 || 
        document.PersonAdminForm.EMAIL.value.indexOf("@") < 1 ||
        document.PersonAdminForm.EMAIL.value.indexOf(".") < 1) {
        missinginfo += "\n     -  Email Address is required (user@mail.org).";
        focusFactor[7] = document.PersonAdminForm.EMAIL;
    }
    
    if (missinginfo != "") {
        missinginfo ="Please enter information or correct the following fields: \n - (Please do not use apostrophes)\n" +
        "_______________________________________________\n" +
        missinginfo + "\n_______________________________________________" +
        "\nPlease correct the form and submit again!";
        for (var n in focusFactor) {
            focusFactor[n].focus();
            break;
        }
        alert(missinginfo);
        return false;
    }
    else 
        return true;
}


function openwin(myurl) {
    DisplayWindow=window.open(myurl, "DisplayWindow", "toolbar=no, menubar=no, height=350, width=350, resizable=no, scrollbars=yes");
}
function opendtwin(myurl) {
    DisplayWindow=window.open(myurl, "DisplayWindow", "toolbar=no, menubar=no, height=600, width=800, resizable=no, scrollbars=yes");
}

function alternateSubmitAction(here) {
    document.orgAdminForm.action = here;
    document.orgAdminForm.submit();
}

function InitializeTable()
{
    unalteredSize = (tableArray.length)/2;
    for (counter=1; (counter <= 5) && ((2*counter) <= tableArray.length); counter++)
    {
        eval("document.Mainform.row" + counter + "name.value=tableArray[" + (2*counter-2) + "];");
        eval("document.Mainform.row" + counter + "meaning.value=tableArray[" + (2*counter-1) + "];");
    }
}
function refreshTable()
{
    for (counter=tableOffset/2 + 1; (counter <= (tableOffset/2 + 5)) && ((2*counter) <= tableArray.length); counter++)
    {
        eval("document.Mainform.row" + (counter-tableOffset/2) + "name.value=tableArray[" + (2*counter-2) + "];");
        eval("document.Mainform.row" + (counter-tableOffset/2) + "meaning.value=tableArray[" + (2*counter-1) + "];");
    }
}
function deleteFromTable(Item)
{
    if ((Item/2) < unalteredSize) 
    {
        unalteredSize--;
        removeArray[removeArray.length] = tableArray[Item];
        removeArray[removeArray.length] = tableArray[Item + 1];
    }
    childOpen = !((chWin == null) || chWin.closed);
    if (Item > (tableArray.length - 2)) return;
    for (counter = Item; counter < (tableArray.length - 2); counter++)
    {
        tableArray[counter] = tableArray[counter + 2];
    }
    tableArray.length -= 2;
    if (tableOffset > tableArray.length - 10) tableOffset -= 2;
    if (tableOffset < 0) tableOffset = 0;
    
    for (counter=1; counter <= 5; counter++)
    {
        eval("document.Mainform.row" + counter + "name.value='';");
        eval("document.Mainform.row" + counter + "meaning.value='';");
    }
}
function AppendToTable()
{
    childOpen = !((chWin == null) || chWin.closed);
    if (!document.Mainform.curfunct[0].checked)
    {
        deleteFromTable(tableItem); 
    }
    tableArray[tableArray.length] = document.Mainform.newValue.value;
    tableArray[tableArray.length] = document.Mainform.newMeaning.value;
    tableOffset = 0;
    if (tableArray.length > 10) tableOffset = tableArray.length - 10;
    refreshTable(); 
    InitializeChild();
    document.Mainform.newValue.value = "";
    document.Mainform.newMeaning.value = "";
    document.Mainform.curfunct[0].checked = true;
}
function ChildRefresh(offset)
{
    tableOffset = offset;
    if (tableOffset > (tableArray.length - 10)) tableOffset=(tableArray.length - 10);
    refreshTable();
}

function InitializeChild()
{
    if (!childOpen) return;
    try{
        chWin.close();
    }
    catch(e)
    {
    }
    OP=(navigator.userAgent.indexOf('Opera')!=-1&&BV>=4)?true:false;
    BV=parseInt(navigator.appVersion.indexOf("MSIE")>0?navigator.appVersion.split(";")[1].substr(6):navigator.appVersion);
    BN=navigator.appName;
    SM=(BN.indexOf('Netscape')!=-1&&(BV>=5)||OP)?true:false;
    if (SM)
    {
        var tempString = "";
        chWin = open("", "", "width=400,height=300,status=no,toolbar=no,menubar=no,left=700,top=100,scrollbars=yes");
        tempString += ("<html><head><title>List of Permisible Values</title></head><body bgcolor = '#cccccc' onUnload='javascript:window.opener.childOpen=false;'><DL COMPACT>");
        for (counter=1; (2*counter) <= tableArray.length; counter++)
        {
            tempString += ("<dt><a href='javascript:window.opener.ChildRefresh(" + (2*counter-2) + ");'>"
                + tableArray[2*counter-2] + "</a></dt>");
            tempString += ("<dd>" + tableArray[2*counter-1] + "</dd>");
        }
        chWin.document.write (tempString + "</dl></body></html>");
    }
    else
    {
        chWin = open("", "", "width=400,height=300,status=no,toolbar=no,menubar=no,left=700,top=100,scrollbars=yes");
        chWin.document.write ("<html><head><title>List of Permisible Values</title></head><body bgcolor = '#cccccc' onUnload='javascript:window.opener.childOpen=false;'><DL COMPACT>");
        for (counter=1; (2*counter) <= tableArray.length; counter++)
        {
            chWin.document.write("<dt><a href='javascript:window.opener.ChildRefresh(" + (2*counter-2) + ");'>"
                + tableArray[2*counter-2] + "</a></dt>");
            chWin.document.write("<dd>" + tableArray[2*counter-1] + "</dd>");
        }
        chWin.document.write ("</dl></body></html>");
    }
    
}

function prepareSubmit()
{
    try{
        chWin.close();
    }
    catch(e)
    {
    }
    for (counter=1; (2*counter) <= removeArray.length; counter++)
    {
        document.Mainform.enumValueDelete.value += ("" + removeArray[2*counter-2] + "|#|" + removeArray[2*counter-1] + "|#|");
    }
    for (counter=unalteredSize + 1; (2*counter) <= tableArray.length; counter++)
    {
        document.Mainform.enumValueAdd.value += ("" + tableArray[2*counter-2] + "|#|" + tableArray[2*counter-1] + "|#|");
    }
    document.Mainform.submit();
}

function RAcheck() {
    var missinginfo = "";
    if(document.orgAdminForm.RESET.value == "Reset Values"){
        return true;
    }
    if (document.orgAdminForm.REGNAME.value == "") missinginfo += "\n     -  A registry name is required.";
    //if (document.orgAdminForm.RALIST.selectedIndex == -1) missinginfo += "\n     - Please select a Registration Authority.";
    
    if (missinginfo != "") {
        missinginfo ="Please enter information or correct the following fields: \n" +
        "_______________________________________________\n" +
        missinginfo + "\n_______________________________________________" +
        "\nPlease correct the form and submit again!";
        alert(missinginfo);
        return false;
    }
    else 
        return true;
}

function checkDataType()
{
    var upperType = document.Mainform.datatype.value.toUpperCase();
    localBool = false;
    for (counter = 0; counter < dataTypeArray.length; counter++)
    {
        if (upperType == dataTypeArray[counter])
        {
            if (localBool == false)
            {
                localBool = true;
            }
            else
            {
                localBool = false;
                break;
            }
        }
    }
    return localBool;
}
function popDataTypeWindow()
{
    opendtwin('dr.ui.sub.valDataType?system=subwin&dtName=' + document.Mainform.datatype.value);
}

// This date checker modfied by Sean to allow onSubmit processing
// Used in AdminRecAdmin forms
// Modified 3-17-2010 to allow for an unknown date which is indicated by a date of 1900-01-01
// by Jerry Carney
function chkDate(value) {
    //alert("chkDate value: " + value);
    // alert("chkDate value toString: " + value.toString());
    // alert("chkDate value toString.ToUpperCase: " + value.toString().toUpperCase());
    // alert(value.toString().toUpperCase()== "UNKNOWN");
    var bStatus = false;
    
    if(value.length ==10) {
        var myYear = value.substring(0,4);
        var myMonth = value.substring(5,7);
        var myDay = value.substring(8,10);
        if(validateMonth(myMonth)) {
            //alert("my month passed: " + myMonth);
            if(validateYear(myYear)){    
                //alert("my year passed: " + myYear);
                if(validateDay(myDay)){
                    //alert("my day passed: " + myDay);
                    bStatus = true;
                }else{
                    alert("Date format must be YYYY-MM-DD: Day " + myDay);
                    bStatus = false;
                }
            }else{
                alert("Date format must be YYYY-MM-DD: Year " + myYear);
                bStatus = false;
            }
        }else{
            alert("Date format must be YYYY-MM-DD: Month " + myMonth);
            bStatus = false;
        }
    }else{
        alert("Date format must be YYYY-MM-DD");
        bStatus = false;
    }  
    //alert("chkDate status: " + bStatus);
    if (!bStatus) {
        //alert("chkDate returns false");
        return false;
    }
    else {
        //alert("chkDate returns true");
        return true; 
    }
}

function checkNotReqDate(myDate){
    if(myDate.value.length ==10){
        var myYear = myDate.value.substring(0,4);
        var myMonth = myDate.value.substring(5,7);
        var myDay = myDate.value.substring(8,10);
        if(validateMonth(myMonth)){
            if(validateDate(myDay)){
                if(validateYear(myYear)){
                    return true;
                }else{
                    alert("Date format must be YYYY-MM-DD: Year " + myYear);
                }
            }else{
                alert("Date format must be YYYY-MM-DD: Day " + myDay);
            }
        }else{
            alert("Date format must be YYYY-MM-DD: Month " + myMonth);
        }
    }else{
        alert("Date format must be YYYY-MM-DD");
    }
    return false;
}

function chkFormDates(myForm){
    validDateFields = [];
    invalidDateFields = [];
    emptyDateFields = [];
    for (counter = 0; counter < myForm.length; counter++)
    {
        if (myForm.elements[counter].name.toUpperCase().indexOf("DATE") > -1)
        {
            if (myForm.elements[counter].value.length > 0)
            {
                var myDate = myForm.elements[counter];
                var dateValid = false;
                if(myDate.value.length ==10){
                    var myYear = myDate.value.substring(0,4);
                    var myMonth = myDate.value.substring(5,7);
                    var myDay = myDate.value.substring(8,10);
                    if(validateMonth(myMonth)){
                        if(validateYear(myYear)){
                            if(validateDate(myDay, myMonth, myYear)){
                                dateValid = true;
                            }
                        }
                    }
                }
                dateValid = (dateValid && (myDate.value.substring(4,5) == "-") && (myDate.value.substring(7,8) == "-"));
                if (dateValid)
                {
                    myForm.elements[counter].dateState = "Valid";
                }
                else
                {
                    myForm.elements[counter].dateState = "Invalid";
                }
            }
            else
            {
                myForm.elements[counter].dateState = "Empty";
            }
        }
    }
}
function inRange(inputStr, lo, hi) {
    //var num = parseInt(inputStr, 10);
    //alert("inRange() number to use: " + inputStr);
    var valid = "0123456789";
    var tempInput;
    for (var i=0; i < inputStr.length; i++) {    
        tempInput = inputStr.substring(i, i+1);
        if (valid.indexOf(tempInput) == "-1") {
            //alert("checking for numbers: " + tempInput);
            return false;
            break;
        }
    }
    if (inputStr < lo || inputStr > hi){
        return false;
    }
    else {
        return true;
    }  
}
function validateMonth(sMonth){
    //alert("month passed: " + sMonth);
    if(!inRange(sMonth,1,12)){
        return false;
    }
    else {
        return true;
    }
}
function validateDay(sDay){
    //alert("validateDay() day starting: " + sDay);
    if(!inRange(sDay,1,31)){
        return false;
    }
    else {
        return true;
    }
}
function validateDate(sDay, sMonth, sYear){
    var iLeapYear = 0;
    if (((sYear % 400) == 0) || (((sYear % 4) == 0) && ((sYear % 100) > 0)))
    {
        iLeapYear = 1;
    }
    switch(sMonth)
    {
        case "01" :
        case "03" :
        case "05" :
        case "07" :
        case "08" :
        case "10" :
        case "12" :
            if(!inRange(sDay,1,31)){
                return false;
            }
            else {
                return true;
            }
            break;
        case "04" :
        case "06" :
        case "09" :
        case "11" :
            if(!inRange(sDay,1,30)){
                return false;
            }
            else {
                return true;
            }
            break;
        case "02" :
            if(!inRange(sDay,1,28 + iLeapYear)){
                return false;
            }
            else {
                return true;
            }
            break;
        default :
            return false;
            break;
    }
    
}
function validateYear(sYear){
    if(!inRange(sYear,1900,9999)){
        return false;
    }
    else {
        return true;
    }
}
function makeSaveAsButton(ThisForm, NameField, KeyField, Caption, AddIndicator)
{
    if (eval(NameField + '.value == AddIndicator'))
    {
        return;
    }
    else
    {
        msabForm = ThisForm;
        msabName = NameField;
        msabKey = KeyField;
        msabAdd = AddIndicator;
        document.write('<input style="color: black; font-family: Arial; font-size: 10px; border: 1 solid #000000" SIZE="1" type="button" name="' + Caption + '" id="' + Caption + '" value="' + Caption + '" onClick="nameCopy()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
    }
}
function nameCopy()
{
    CopyWindow=window.open("about:blank", "CopyWindow", "toolbar=no, menubar=no, height=150, width=200, resizable=no, scrollbars=yes");
    CopyWindow.document.writeln("<html><head><title>Copy Confirmation</title><head><body onUnfocus='window.close()'>");
    CopyWindow.document.writeln("<form action='javascript:1==1;' name=utilForm>");
    CopyWindow.document.writeln("Enter the name of this copy.<br>Name:<input type=text name=copyName><br>");
    CopyWindow.document.writeln("<input type=button value=Proceed onClick='window.opener.msabSubmit()'>");
    CopyWindow.document.writeln("<input type=button value=Cancel onClick='window.close()'>");
    CopyWindow.document.writeln("</body></html>");
}
function msabSubmit()
{
    try{
        eval(msabName + '.value=CopyWindow.document.utilForm.copyName.value;');
        CopyWindow.close();
        eval(msabKey + '.value = msabAdd;');
        eval(msabForm + '.submit();');
    }
    catch(e)
    {
        alert(e);
    }
}
function cdvmValid(myForm)
{
    for (counter = 0; (counter < myForm.length); counter++)
    {
        if (myForm.elements[counter].name.indexOf("chosen") == 0)
        {
            if (myForm.elements[counter].checked)
            {
                if ((myForm.elements[counter + 2].dateState == "Valid") && (myForm.elements[counter + 1].dateState == "Empty"))
                {
                    alert("A value meaning with an End Date must also have a Begin Date.");
                    myForm.elements[counter + 1].focus();
                    myForm.elements[counter + 1].select();
                    return false;
                }
                if ((myForm.elements[counter + 1].dateState == "Invalid"))
                {
                    alert("Invalid Date. Dates must be in the format YYYY-MM-DD.");
                    myForm.elements[counter + 1].focus();
                    myForm.elements[counter + 1].select();
                    return false;
                }
                if ((myForm.elements[counter + 2].dateState == "Invalid"))
                {
                    alert("Invalid Date. Dates must be in the format YYYY-MM-DD.");
                    myForm.elements[counter + 2].focus();
                    myForm.elements[counter + 2].select();
                    return false;
                }
            }
        }
    }
    return true;
}
function logonModul(url,width,height) {
    if(width==0 && height==0) {
        CommentWindow = window.open(
            url,
            "subWindow",
            "toolbar=yes," +
            "location=yes," +
            "directories=no," +
            "status=no," +
            "menubar=no," +
            "scrollbars=yes," +
            "resizable=yes");
    } else  {
        CommentWindow = window.open(
            url,
            "cWindow",
            "toolbar=yes," +
            "location=yes," +
            "directories=no," +
            "status=no," +
            "menubar=no," +
            "scrollbars=yes," +
            "resizable=yes," +
            "width=" + width + "," +
            "height=" + height);
    }
  
}
document.include = function (url) {
    if ('undefined' == typeof(url)) return false;
    var p,rnd;
    if (document.all){
        // For IE, create an ActiveX Object instance
        p = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        // For mozilla, create an instance of XMLHttpRequest.
        p = new XMLHttpRequest();
    }
    // Prevent browsers from caching the included page
    // by appending a random  number
    rnd = Math.random().toString().substring(2);
    url = url.indexOf('?')>-1 ? url+'&rnd='+rnd : url+'?rnd='+rnd;
    // Open the url and write out the response
    p.open("GET",url,false);
    p.send(null);
    document.write( p.responseText );
}

    

function CheckSystem(System)
{
    if (location.search.indexOf(System) > -1 )
    {
        return " class='here' ";
    }
    return " style='' ";
}



try{
    document.addEvent('domready' , function(e) {
        //----------------------------------------------------------------------
        // Enable the attractive tooltips code:
        // to add new tooltips, use the following <... class="contextHelp" title="title::content></...>
        $$('.contextHelp').each(function(element) {
            try{
                if(element.get('title') == null || element.get('title').indexOf('::') == -1){
                    $(element).removeClass('contextHelp');
                } else {
                    var content = element.get('title').split('::');
                    element.store('tip:title', content[0]);
                    element.store('tip:text', content[1]);
                }
            } catch(err){
                $(element).removeClass('contextHelp');
            }
        });
        new Tips('.contextHelp',{
            className: 'contextHelpHouse',
            fixed: true,
            hideDelay: 50,
            showDelay: 50
        });
        //----------------------------------------------------------------------
        // Enable smooth-scrolling code:
        // to enable, use the following:  <a class="smoothScroll">...</a> and

        if (Browser.Engine.presto){
            // a bug with Opera prevents Fx.Scroll from working properly.
            // If this is Opera, let the named links work as designed:
            return;
        }
        $$('a.smoothScroll').each(function(item){
            $(item).addEvent('click', function(e){
                //try{
                var isError = false;
                if($(item).href.contains('#')){
                    var parts = $(item).href.split("#");
                    var anchor = parts[1];
                    if(anchor.contains('?')){
                        anchor = anchor.split('?')[0];
                    }
                    new Fx.Scroll(window).toElement('' + anchor);
                } else {
                    isError = true;
                }
                if(!isError){
                    e.stop();
                }
            //} catch(err){
            //    alert(err + "\n" + err.description);
            //}
            });
        });
        $$('a.toTop').each(function(item,index){
            $(item).addEvent('click', function(e){
                e.stop();
                new Fx.Scroll(window).toTop();
            });
        });



    });
} catch(err){

} 