//**************************************************
// Written by Chetan M. Soni (02/14/2001)
//**************************************************



//****************************************************************************
// HTML-BASED HTML EDITOR FUNCTIONS (ADMIN AREA) | Written by Chetan M. Soni |
//****************************************************************************

function addTags(theObj, theTags) {
  theObj = document.theForm.theText
  theObj.value = theObj.value + theTags;
}

function getFontInfo(theObj) {
  /* ASK THE USER FOR UNKNOWNS */
  theFace = prompt('FONT TYPE (default = arial):', 'arial');
  theColor = (!!theFace) ? prompt('FONT COLOR (default = black):', 'black'): null;
  theSize = (!!theColor) ? prompt('FONT SIZE (default = 12):', '12'): null;
  
  if ( (!!theFace) && (!!theColor) && (!!theSize) ) {
    /* LOAD IN TEXT BOX */
    addTags(theObj, '<span style="font-family:' + theFace + '; color:' + theColor + '; font-size:' + theSize + 'px;"></span>');
  }
}

function getTableInfo(theObj) {
  /* ASK THE USER FOR UNKNOWNS */
  howManyRows = prompt('TABLE ROWS (default = 1):', '1');
  howManyColumns = (!!howManyRows) ? prompt('TABLE COLUMNS (default = 1):', '1'): null;
  theBorder = (!!howManyColumns) ? prompt('TABLE BORDER (default = 0):', '0'): null;
  theCellpadding = (!!theBorder) ? prompt('TABLE CELL PADDING (default = 2):', '2'): null;
  theCellspacing = (!!theCellpadding) ? prompt('TABLE CELL SPACING (default = 0):', '0'): null;
  
  if ( (!!howManyRows) && (!!howManyColumns) && (!!theBorder) && (!!theCellpadding) && (!!theCellspacing) ) {
    /* GENEATE THE TABLE STRING */
    theTempString = ' \n<table border="' + theBorder + '" cellpadding="' + theCellpadding + '" cellspacing="' + theCellspacing + '">\n';
    for (rows = 0; rows < howManyRows; rows++) {
      theTempString = theTempString + '  <tr valign="top">\n';
      for (cols = 0; cols < howManyColumns; cols++) {
        theTempString = theTempString + '    <td>' + eval(rows + 1) + 'x' + eval(cols + 1) + '</td>\n';
      }
      theTempString = theTempString + '  </tr>\n';
    }
    theTempString = theTempString + '</table>\n';
    
    /* LOAD IN TEXT BOX */
    addTags(theObj, theTempString);
  }
}

function getOLInfo(theObj) {
  /* ASK THE USER FOR UNKNOWNS */
  howManyItems = prompt('HOW MANY LIST ITEMS (default = 1):', '1');
  indexType = (!!howManyItems) ? prompt('LIST INDEX TYPE [1,a,A,i,I] (default = 1):', '1'): null;
  listFont = (!!indexType) ? prompt('LIST FONT (default = arial):', 'arial'): null;
  listFontSize = (!!listFont) ? prompt('LIST FONT SIZE (default = 12):', '12'): null;
  listFontColor = (!!listFontSize) ? prompt('LIST FONT COLOR (default = black):', 'black'): null;
  
  if ( (!!howManyItems) && (!!indexType) && (!!listFont) && (!!listFontSize) && (!!listFontColor) ) {
    /* GENEATE THE TABLE STRING */
    theTempString = ' \n<ol type="' + indexType + '" style="font-family:' + listFont + '; font-size:' + listFontSize + 'px; color:' + listFontColor + ';">\n';
    for (items = 0; items < howManyItems; items++) {
      theTempString = theTempString + '  <li></li>\n';
    }
    theTempString = theTempString + '</ol>\n';

    /* LOAD IN TEXT BOX */
    addTags(theObj, theTempString);
  }
}

function getULInfo(theObj) {
  /* ASK THE USER FOR UNKNOWNS */
  howManyItems = prompt('HOW MANY LIST ITEMS (default = 1):', '1');
  bulletType = (!!howManyItems) ? prompt('LIST BULLET TYPE [disc,circle,square] (default = disc):', 'disc'): null;
  listFont = (!!bulletType) ? prompt('LIST FONT (default = arial):', 'arial'): null;
  listFontSize = (!!listFont) ? prompt('LIST FONT SIZE (default = 12):', '12'): null;
  listFontColor = (!!listFontSize) ? prompt('LIST FONT COLOR (default = black):', 'black'): null;
  
  if ( (!!howManyItems) && (!!bulletType) && (!!listFont) && (!!listFontSize) && (!!listFontColor) ) {
    /* GENEATE THE TABLE STRING */
    theTempString = ' \n<ul type="' + bulletType + '" style="font-family:' + listFont + '; font-size:' + listFontSize + 'px; color:' + listFontColor + ';">\n';
    for (items = 0; items < howManyItems; items++) {
      theTempString = theTempString + '  <li></li>\n';
    }
    theTempString = theTempString + '</ul>\n';

    /* LOAD IN TEXT BOX */
    addTags(theObj, theTempString);
  }
}

function getLinkInfo (theObj) {
  linkUrl = prompt('LINK URL :', 'http://');
  linkText = ( (!!linkUrl) && (linkUrl != 'http://') ) ? prompt('LINK TEXT :', ''): null;
  
  if ( ( (!!linkUrl) && (linkUrl != 'http://') ) && (!!linkText) ) {
    theTempString = '<a href="' + linkUrl + '">' + linkText + '</a>';

    /* LOAD IN TEXT BOX */
    addTags(theObj, theTempString);
  }
}

function showPreview(theObj, theWidth, theHeight) {
  if ((window.previewWindow) && (!window.previewWindow.closed)) {
    window.previewWindow.close();
  }
  
  previewWindow = window.open('','previewWindow','resizable=yes,width=' + theWidth + ',height=' + theHeight + ',scrollbars=yes');
  
  // CREATE THE FRAMESET
  frameSetString = '<html><head><title>Preview HTML</title></head><frameset rows="2%,93%,5%" framespacing="0" frameborder="0" border="0" bordercolor="black"><frame src="" name="emptyTop" id="emptyTop" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize><frameset cols="1%,98%,1%" framespacing="0" frameborder="0" bordercolor="black"><frame src="" name="emptyLeft" id="emptyLeft" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize><frame src="" name="main" id="main" scrolling="yes" marginwidth="0" marginheight="0" bordercolor="black" noresize><frame src="" name="emptyRight" id="emptyRight" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize></frameset><frame src="" name="closeLink" id="closeLink" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize></frameset><body></body></html>';
  window.previewWindow.top.document.open();
  window.previewWindow.top.document.write(frameSetString);
  window.previewWindow.top.document.close();
  
  // CREATE THE MAIN PREVIEW FRAME
  beginString = '<html><head><title>Preview</title></head><body topmargin="5" leftmargin="5" marginwidth="5" marginheight="5" bgcolor="white" text="black" link="blue" alink="red" vlink="blue">';
  previewString = theObj.value;
  endString = '</body></html>';
  window.previewWindow.main.document.open();
  window.previewWindow.main.document.write(beginString + previewString + endString);
  window.previewWindow.main.document.close();
  
  // CREATE THE TOP FRAME
  topFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"></body></html>';  
  window.previewWindow.emptyTop.document.open();
  window.previewWindow.emptyTop.document.write(topFrameString);
  window.previewWindow.emptyTop.document.close();
  // CREATE THE LEFT FRAME
  leftFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"></body></html>';  
  window.previewWindow.emptyLeft.document.open();
  window.previewWindow.emptyLeft.document.write(leftFrameString);
  window.previewWindow.emptyLeft.document.close();
  // CREATE THE RIGHT FRAME
  rightFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"></body></html>';  
  window.previewWindow.emptyRight.document.open();
  window.previewWindow.emptyRight.document.write(rightFrameString);
  window.previewWindow.emptyRight.document.close();
  
  // CREATE THE BOTTOM CLOSE WINDOW LINK
  closeLinkFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"><table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td align="center" valign="middle"><a href="javascript:window.top.self.close();" style="font-family:arial; font-size:12px; font-weight:bold; text-decoration:none;">C L O S E&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;W I N D O W</a></td></tr></table></body></html>';  
  window.previewWindow.closeLink.document.open();
  window.previewWindow.closeLink.document.write(closeLinkFrameString);
  window.previewWindow.closeLink.document.close();
}



function showHomePage() {
  if ((window.homePageWindow) && (!window.homePageWindow.closed)) {
    window.homePageWindow.close();
  }
  
  homePageWindow = window.open('','homePageWindow','resizable=no,width=800,height=475,scrollbars=yes');
  
  // CREATE THE FRAMESET
  frameSetString = '<html><head><title>View Home Page</title></head><frameset rows="2%,93%,5%" framespacing="0" frameborder="0" border="0" bordercolor="black"><frame src="" name="emptyTop" id="emptyTop" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize><frameset cols="1%,98%,1%" framespacing="0" frameborder="0" bordercolor="black"><frame src="" name="emptyLeft" id="emptyLeft" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize><frame src="/" name="main" id="main" scrolling="yes" marginwidth="0" marginheight="0" bordercolor="black" noresize><frame src="" name="emptyRight" id="emptyRight" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize></frameset><frame src="" name="closeLink" id="closeLink" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize></frameset><body></body></html>';
  window.homePageWindow.top.document.open();
  window.homePageWindow.top.document.write(frameSetString);
  window.homePageWindow.top.document.close();
  
  // CREATE THE TOP FRAME
  topFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"></body></html>';  
  window.homePageWindow.emptyTop.document.open();
  window.homePageWindow.emptyTop.document.write(topFrameString);
  window.homePageWindow.emptyTop.document.close();
  // CREATE THE LEFT FRAME
  leftFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"></body></html>';  
  window.homePageWindow.emptyLeft.document.open();
  window.homePageWindow.emptyLeft.document.write(leftFrameString);
  window.homePageWindow.emptyLeft.document.close();
  // CREATE THE RIGHT FRAME
  rightFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"></body></html>';  
  window.homePageWindow.emptyRight.document.open();
  window.homePageWindow.emptyRight.document.write(rightFrameString);
  window.homePageWindow.emptyRight.document.close();
  
  // CREATE THE BOTTOM CLOSE WINDOW LINK
  closeLinkFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"><table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td align="center" valign="middle"><a href="javascript:window.top.self.close();" style="font-family:arial; font-size:12px; font-weight:bold; text-decoration:none;">C L O S E&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;W I N D O W</a></td></tr></table></body></html>';  
  window.homePageWindow.closeLink.document.open();
  window.homePageWindow.closeLink.document.write(closeLinkFrameString);
  window.homePageWindow.closeLink.document.close();
}

function showNewsPage() {
  if ((window.newsPageWindow) && (!window.newsPageWindow.closed)) {
    window.newsPageWindow.close();
  }
  
  newsPageWindow = window.open('','newsPageWindow','resizable=no,width=800,height=475,scrollbars=yes');
  
  // CREATE THE FRAMESET
  frameSetString = '<html><head><title>View News Page</title></head><frameset rows="2%,93%,5%" framespacing="0" frameborder="0" border="0" bordercolor="black"><frame src="" name="emptyTop" id="emptyTop" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize><frameset cols="1%,98%,1%" framespacing="0" frameborder="0" bordercolor="black"><frame src="" name="emptyLeft" id="emptyLeft" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize><frame src="/news/" name="main" id="main" scrolling="yes" marginwidth="0" marginheight="0" bordercolor="black" noresize><frame src="" name="emptyRight" id="emptyRight" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize></frameset><frame src="" name="closeLink" id="closeLink" scrolling="no" marginwidth="0" marginheight="0" bordercolor="black" noresize></frameset><body></body></html>';
  window.newsPageWindow.top.document.open();
  window.newsPageWindow.top.document.write(frameSetString);
  window.newsPageWindow.top.document.close();
  
  // CREATE THE TOP FRAME
  topFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"></body></html>';  
  window.newsPageWindow.emptyTop.document.open();
  window.newsPageWindow.emptyTop.document.write(topFrameString);
  window.newsPageWindow.emptyTop.document.close();
  // CREATE THE LEFT FRAME
  leftFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"></body></html>';  
  window.newsPageWindow.emptyLeft.document.open();
  window.newsPageWindow.emptyLeft.document.write(leftFrameString);
  window.newsPageWindow.emptyLeft.document.close();
  // CREATE THE RIGHT FRAME
  rightFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"></body></html>';  
  window.newsPageWindow.emptyRight.document.open();
  window.newsPageWindow.emptyRight.document.write(rightFrameString);
  window.newsPageWindow.emptyRight.document.close();
  
  // CREATE THE BOTTOM CLOSE WINDOW LINK
  closeLinkFrameString = '<html><head><title></title></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="black" text="white" link="white" vlink="white" alink="red"><table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td align="center" valign="middle"><a href="javascript:window.top.self.close();" style="font-family:arial; font-size:12px; font-weight:bold; text-decoration:none;">C L O S E&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;W I N D O W</a></td></tr></table></body></html>';  
  window.newsPageWindow.closeLink.document.open();
  window.newsPageWindow.closeLink.document.write(closeLinkFrameString);
  window.newsPageWindow.closeLink.document.close();
}







//****************************************************************************
// PRODUCT IMAGE WINDOW OPENER                                               |
//****************************************************************************

function openProdImageWin(theProdID) {
  if ((window.aSysProdImageWinHandler) && (!window.aSysProdImageWinHandler.closed)) {
    // window.aSysProdImageWinHandler.top.main.location.href = "/productCatalog/prodImage/main.cfm?product_id=" + theProdID;
    // window.aSysProdImageWinHandler.focus();
    window.aSysProdImageWinHandler.close();
    window.aSysProdImageWinHandler = null;
  }
  window.aSysProdImageWinHandler = window.open("/resellerLogin/productCatalog/prodImage/load.cfm?product_id=" + theProdID ,"aSysProdImageWin", "location=no,height=350,width=350,toolbar=no,status=no,top=0,left=0,screenx=0,screeny=0,resizable=no")
  if (! window.aSysProdImageWinHandler.opener) {
    window.aSysProdImageWinHandler.opener = self
  }
  // if ((window.aSysProdImageWinHandler) && (!window.aSysProdImageWinHandler.closed)) {
  //   window.aSysProdImageWinHandler.focus();
  // }
}



//****************************************************************************
// HELP WINDOW OPENER                                                        |
//****************************************************************************

function openHelpWin(theUrl) {
  if ((window.aSysHelpWinHandler) && (!window.aSysHelpWinHandler.closed)) {
    window.aSysHelpWinHandler.close();
    window.aSysHelpWinHandler=null;
  }
  window.aSysHelpWinHandler = window.open(theUrl ,"aSyshelpWin", "location=no,height=300,width=520,toolbar=no,status=no,top=0,left=0,screenx=0,screeny=0,resizable=yes")
  if (! window.aSysHelpWinHandler.opener) { window.aSysHelpWinHandler.opener = self }
  if ((window.aSysHelpWinHandler) && (!window.aSysHelpWinHandler.closed)) {
    window.aSysHelpWinHandler.focus();
  }
}



//****************************************************************************
// ADMIN SORT FUNCTIONS                                                      |
//****************************************************************************

function moveup(theFormObj) {
  var selobj=theFormObj;
  var selidx=selobj.selectedIndex;
  var tempval, temptext;
  if(selidx > 0) {
    tempval=selobj.options[selidx-1].value;
    temptext=selobj.options[selidx-1].text;
    selobj.options[selidx-1].value=selobj.options[selidx].value;
    selobj.options[selidx-1].text=selobj.options[selidx].text;
    selobj.options[selidx].value=tempval;
    selobj.options[selidx].text=temptext;
    selobj.selectedIndex=selidx-1;
  }
}

function movedown(theFormObj) {
  var selobj=theFormObj;
  var selidx=selobj.selectedIndex;
  var listlen=selobj.length;
  var tempval, temptext;
  if(selidx >=0 && selidx < listlen-1) {
    tempval=selobj.options[selidx+1].value;
    temptext=selobj.options[selidx+1].text;
    selobj.options[selidx+1].value=selobj.options[selidx].value;
    selobj.options[selidx+1].text=selobj.options[selidx].text;
    selobj.options[selidx].value=tempval;
    selobj.options[selidx].text=temptext;
    selobj.selectedIndex=selidx+1;
  }
}

function movefirst(theFormObj) {
  var selobj=theFormObj;
  var selidx=selobj.selectedIndex;
  for (var i=0;i<selidx;i++) {
    moveup(theFormObj);
  }
}

function movelast(theFormObj) {
  var selobj=theFormObj;
  var selidx=selobj.selectedIndex;
  for (var i=selobj.options.length-1;i>selidx;i--) {
    movedown(theFormObj);
  }
}

function buildlist(sourceobj,targetobj) {
  var listlength=sourceobj.options.length;
  targetobj.value="";
  for (var i=0;i<listlength;i++) {
    if (i==listlength-1) {
      targetobj.value+=sourceobj.options[i].value;
    }
    else {
      targetobj.value+=sourceobj.options[i].value + ',';
    }
  }
}



//****************************************************************************
// ADD MIA WINDOW OPENER                                                        |
//****************************************************************************

function openMIAWin(theUrl) {
  if ((window.aSysMIAWinHandler) && (!window.aSysMIAWinHandler.closed)) {
    window.aSysMIAWinHandler.close();
    window.aSysMIAWinHandler=null;
  }
  window.aSysMIAWinHandler = window.open(theUrl ,"aSysMIAWin", "location=no,height=400,width=560,toolbar=no,status=no,top=0,left=0,screenx=0,screeny=0,resizable=yes,scrollbars=yes")
  if (! window.aSysMIAWinHandler.opener) { window.aSysMIAWinHandler.opener = self }
  if ((window.aSysMIAWinHandler) && (!window.aSysMIAWinHandler.closed)) {
    window.aSysMIAWinHandler.focus();
  }
}



//****************************************************************************
// ANNOUNCEMENTS WINDOW OPENER                                                        |
//****************************************************************************

function openAnnouncementsWin(theUrl) {
  if ((window.aSysAnnouncementsWinHandler) && (!window.aSysAnnouncementsWinHandler.closed)) {
    window.aSysAnnouncementsWinHandler.close();
    window.aSysAnnouncementsWinHandler=null;
  }
  window.aSysAnnouncementsWinHandler = window.open(theUrl ,"aSysAnnouncementsWin", "location=no,height=500,width=600,toolbar=no,status=no,top=0,left=0,screenx=0,screeny=0,resizable=yes,scrollbars=yes")
  if (! window.aSysAnnouncementsWinHandler.opener) { window.aSysAnnouncementsWinHandler.opener = self }
  if ((window.aSysAnnouncementsWinHandler) && (!window.aSysAnnouncementsWinHandler.closed)) {
    window.aSysAnnouncementsWinHandler.focus();
  }
}



//****************************************************************************
// PRINT SCRIPT                                                        |
//****************************************************************************

var da = (document.all) ? 1 : 0;
var pr = (window.print) ? 1 : 0;
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function loadWholeManual() {
  goAhead = false;
  goAhead = confirm("Depending on your connection speed, the whole manual may\ntake a long time to load, are you sure you want to load it?");
  if (goAhead) {
    manualDir = top.window.WORK.location.href.substr(0,top.window.WORK.location.href.lastIndexOf('manual/') + 7);
    top.window.WORK.location.href = manualDir + "fullmanual.html"
  }
}

function printPage() {
  if (pr) // NS4, IE5
    window.print()
  else if (da && !mac) // IE4 (Windows)
    vbPrintPage()
  else // other browsers
    alert("Sorry, your browser doesn't support this feature.");
  return false;
}

if (da && !pr && !mac) with (document) {
  writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
  writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
  writeln('Sub window_onunload');
  writeln('  On Error Resume Next');
  writeln('  Set WB = nothing');
  writeln('End Sub');
  writeln('Sub vbPrintPage');
  writeln('  OLECMDID_PRINT = 6');
  writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 1');
  writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
  writeln('  On Error Resume Next');
  writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
  writeln('End Sub');
  writeln('<' + '/SCRIPT>');
}
