// JScript source code
function adjustDateTime(InDateTime)
{
   var d, tz;
   d = new Date();
   tz = d.getTimezoneOffset();// difference between GMT and clients time
   var d = new Date(InDateTime);
   var d2 = d.sub("mi", (tz)); //+3days
   return d2.formatDate();
}

  Date.prototype.formatDate = function()
  {
  
    var dTemp = this;
    
    var intDate = dTemp.getDate();
    var intYear = dTemp.getFullYear(); 
//    var days = new Array(
//        'Sunday','Monday','Tuesday',
//        'Wednesday','Thursday','Friday','Saturday');
      var months = new Array(
        'Jan','Feb','Mar','Apr','May',
        'Jun','Jul','Aug','Sep','Oct',
        'Nov','Dec');
    var strMonth = months[dTemp.getMonth()];

    var strHour = String(dTemp.getHours()+1000);
    strHour = strHour .substring(strHour.length-2,strHour.length);

    var strMinutes = String(dTemp.getMinutes()+1000);
    strMinutes = strMinutes.substring(strMinutes.length-2,strMinutes.length);

    var strSeconds = String(dTemp.getSeconds()+1000);
    strSeconds = strSeconds.substring(strSeconds.length-2,strSeconds.length);
    
    return intDate + "-" + strMonth + "-" + intYear + " " + strHour + ":" + strMinutes + ":" + strSeconds;
    
  
  }

  Date.prototype.sub = function (sInterval, iNum){
  var dTemp = this;
  if (!sInterval || iNum == 0) return dTemp;
  switch (sInterval.toLowerCase()){
    case "ms":
      dTemp.setMilliseconds(dTemp.getMilliseconds() - iNum);
      break;
    case "s":
      dTemp.setSeconds(dTemp.getSeconds() - iNum);
      break;
    case "mi":
      dTemp.setMinutes(dTemp.getMinutes() - iNum);
      break;
    case "h":
      dTemp.setHours(dTemp.getHours() - iNum);
      break;
    case "d":
      dTemp.setDate(dTemp.getDate() - iNum);
      break;
    case "mo":
      dTemp.setMonth(dTemp.getMonth() - iNum);
      break;
    case "y":
      dTemp.setFullYear(dTemp.getFullYear() - iNum);
      break;
  }
  return dTemp;
}

var strInnerHTML=''; var intRows=0;

var arrayOptions = new Array();

arrayOptions[0] = new Array("All fields contains", 8);
arrayOptions[1] = new Array("Title contains", 1);
arrayOptions[2] = new Array("Abstract contains", 2);
arrayOptions[3] = new Array("Source contains", 3);
arrayOptions[4] = new Array("Author contains", 4);
arrayOptions[5] = new Array("Shipname contains", 5);
arrayOptions[6] = new Array("ISBN contains", 6);
arrayOptions[7] = new Array("Keyword contains", 7);
arrayOptions[8] = new Array("Year of publication", 9);

function checkUpdateRow(intRowNum)
{
    var intPreviousOption = eval("document.searchbuild.temp_criteria_type" + intRowNum + ".value");
    var intNewOption = eval("document.searchbuild.criteria" + intRowNum + ".options[document.searchbuild.criteria" + intRowNum + ".selectedIndex].value");
    if((intPreviousOption==9)&&(intNewOption<9))
    {
        document.getElementById('row'+intRowNum).innerHTML = makeHTMLTextRow(intRowNum, intNewOption, "");
    }
    else if((intPreviousOption<9)&&(intNewOption==9))
    {
        document.getElementById('row'+intRowNum).innerHTML = makeHTMLYearRow(intRowNum, eval("document.searchbuild.criteria_option" + intRowNum + ".options[document.searchbuild.criteria_option" + intRowNum + ".selectedIndex].value"),1,0);
    }
    eval("document.searchbuild.temp_criteria_type" + intRowNum + ".value=" + intNewOption);
}

function makeHTMLYearRow(intRowNum, intExcludeOption, intYearOption, intYear)
{

    var objDate = new Date();
    intCurrentYear = objDate.getFullYear();

    if(parseInt(intYear)==0) { intYear = intCurrentYear;}
    strTempRow = "<table cellpadding=0 cellspacing=0 border=0><tr valign=middle><td><a title='delete this search term' href='javascript:deleteRow(" + intRowNum + ");'><img alt='delete this search term' src='images/delete.gif' border=0></a></td><td>"
    strTempRow = strTempRow + "<input name='temp_criteria_type" + (intRowNum) + "' type='hidden' value='9'>"
    strTempRow = strTempRow + "<select name='criteria_option" + (intRowNum) + "'>";       
    strTempRow = strTempRow + "<option value='1'";
    if(parseInt(intExcludeOption)==1) { strTempRow = strTempRow + " selected";}
    strTempRow = strTempRow + ">include record if</option>";
    strTempRow = strTempRow + "<option value='2'";
    if(parseInt(intExcludeOption)==2) { strTempRow = strTempRow + " selected";}
    strTempRow = strTempRow + ">exclude record if</option></select>";
    strTempRow = strTempRow + "</td><td>"
    strTempRow = strTempRow + "<select name='criteria" + (intRowNum) + "' onChange='checkUpdateRow(" + (intRowNum) + ");'>";       
    for(var intCounter=0;intCounter<arrayOptions.length;intCounter++)
    {
        strTempRow = strTempRow + "<option value='" + arrayOptions[intCounter][1] + "'";
        if(parseInt(arrayOptions[intCounter][1])==9) { strTempRow = strTempRow + " selected"; } 
        strTempRow = strTempRow + ">" + arrayOptions[intCounter][0] + "</option>";
    }
    strTempRow = strTempRow + "</select></td><td>"
    strTempRow = strTempRow + "<select name='criteria_second_option" + (intRowNum) + "'>";       
    strTempRow = strTempRow + "<option value='1'";
    if(parseInt(intYearOption)==1) { strTempRow = strTempRow + " selected"; }
    strTempRow = strTempRow + ">is</option><option value='2'";
    if(parseInt(intYearOption)==2) { strTempRow = strTempRow + " selected"; }
    strTempRow = strTempRow + ">is/before</option><option value='3'";
    if(parseInt(intYearOption)==3) { strTempRow = strTempRow + " selected"; }
    strTempRow = strTempRow + ">is/after</option></select>";
    strTempRow = strTempRow + "</td><td>"
    strTempRow = strTempRow + "<select name='criteria_value" + intRowNum + "'>"
    for(var intCounter=1920;intCounter<=intCurrentYear;intCounter++)
    {
        strTempRow = strTempRow + "<option value='" + intCounter + "'";
        if(parseInt(intYear)==intCounter) { strTempRow = strTempRow + " selected";} 
        strTempRow = strTempRow + ">" + intCounter + "</option>"
    }
    strTempRow = strTempRow + "</select></td></tr></table>"
    return(strTempRow );
}

function deleteRow(intRowNum)
{
    var intCounter;
    var objRows = document.getElementById("tablecontainer").rows;
    document.getElementById("tablecontainer").deleteRow(document.getElementById("rowcontainer"+intRowNum).rowIndex);
}

function makeHTMLTextRow(intRowNum, intInitial, intExcludeOption, strTerm)
{
    var strTempRow=''; 
    strTempRow = "<table cellpadding=0 cellspacing=0 border=0><tr valign=middle><td><a title='delete this search term' href='javascript:deleteRow(" + intRowNum + ");'><img alt='delete this search term' src='images/delete.gif' border=0></a></td><td>"
    strTempRow = strTempRow + "<input name='temp_criteria_type" + (intRowNum) + "' type='hidden' value='1'>"
    strTempRow = strTempRow + "<select name='criteria_option" + (intRowNum) + "'>";       
    strTempRow = strTempRow + "<option value='1'";
    if(parseInt(intExcludeOption)==1) { strTempRow = strTempRow + " selected";}
    strTempRow = strTempRow + ">include record if</option>";
    strTempRow = strTempRow + "<option value='2'";
    if(parseInt(intExcludeOption)==2) { strTempRow = strTempRow + " selected";}
    strTempRow = strTempRow + ">exclude record if</option></select>";
    strTempRow = strTempRow + "</td><td>"
    strTempRow = strTempRow + "<select name='criteria" + (intRowNum) + "' onChange='checkUpdateRow(" + (intRowNum) + ");'>";       
    for(var intCounter=0;intCounter<arrayOptions.length;intCounter++)
    {
        strTempRow = strTempRow + "<option value='" + arrayOptions[intCounter][1] + "'";
        if(parseInt(arrayOptions[intCounter][1])==intInitial) { strTempRow = strTempRow + " selected"; } 
        strTempRow = strTempRow + ">" + arrayOptions[intCounter][0] + "</option>";
    }
    strTempRow = strTempRow + "</select></td><td><input type='text' style='width: 300px;' name='criteria_value" + (intRowNum) + "' value=\"" + strTerm.replace(/"/g,"&quot;") + "\"></td></tr></table>";    
    return(strTempRow);

}

function addToAdvancedForm()
{

    var strTempRow='';
    intRows++;
    strTempRow = "<div class='none' id='row" + eval(intRows) + "'>"
    strTempRow = strTempRow + makeHTMLTextRow(intRows, 8, 1,"") + "</table>";
    var objNewRow = document.getElementById("tablecontainer").insertRow(-1);
    objNewRow.setAttribute('id','rowcontainer'+intRows);
    var objNewCell= objNewRow.insertCell(objNewRow.cells.length);
    objNewCell.innerHTML = strTempRow + "</div>";
    document.searchbuild.numrows.value=intRows;

}

function testJSSupport()
{

    var objNewRow = document.getElementById("testJavascriptCapabilities").insertRow(-1);

    if(typeof(objNewRow)=='undefined')
    {
        return(false);
    }
    else
    {
        objNewRow.setAttribute('id','testrowcontainer');
        var objRows = document.getElementById("testJavascriptCapabilities").rows;
        document.getElementById("testJavascriptCapabilities").deleteRow(document.getElementById("testrowcontainer").rowIndex);        
        document.getElementById("testFrame").removeChild(document.getElementById("testJavascriptCapabilities"));
        return(true);
    }
}


function deleteconfirm(strType, intCustomerID, intIdentifier) {

    if (strType == 'login') {

        if (confirm("are you sure you wish to delete this login?")) {
            location.href = "customeradmin.asp?customerid=" + intCustomerID + "&loginid=" + intIdentifier + "&deletelogin=yes";
        }
        else {
            return (false);
        }
    }

    if (strType == 'ip') {

        if (confirm("are you sure you wish to delete this IP range?")) {
            location.href = "customeradmin.asp?customerid=" + intCustomerID + "&ipaddressid=" + intIdentifier + "&deleteiprange=yes";
        }
        else {
            return (false);
        }
    }
}
