//Theme header JavaScript


// IFRAME:

// Standard iframe loading image.
function iframeLoad() {
  document.getElementById('iframeLoading').style.display = "none";
}

function modal(modal_type, modal_id, title, content, w, h) {
// Not in use.
}

// IE MODAL LAYER (not in use):

function modalLayer(modal_type, modal_id, title, content, w, h) {

  document.getElementById('modalDiv').style.display = 'block';

  // Hide listbox.
  document.getElementById('cat_browse_box').style.display = 'none';

  var close_img = 'themes/modern_blue/Windows/windowfiles/close.gif';
  var screenWidth = document.body.clientWidth;  // IE version (others > innerWidth)
  var screenHeight = document.body.clientHeight;  // IE version (others > innerHeight)

  var modW = ((w == 'max') ? (screenWidth - 120) : w);
  var modH = ((h == 'max') ? (screenHeight - 120) : h);
  var innerH = (modH - 30);

  // Auto center all.
  var leftPos = ((screenWidth/2) - (modW/2));
  var topPos = ((screenHeight/2) - (modH/2));

  var replaceHtml = new String('');
  replaceHtml += '<div id="' + modal_id +'" style="margin:0;height:' + modH + 'px;width:' + modW + 'px;border-top: 2px solid #555;border-right: 2px solid #3B3B3B;border-bottom: 6px solid #3B3B3B;border-left: 2px solid #3B3B3B;display: block;position: relative;margin: 0;background-color: #FFF;overflow: hidden;">';
  replaceHtml += '<div style="height: 28px;padding: 4px 8px 0 0;text-indent: 12px;font-size: 13px;font-family: Arial, Helvetica, sans-serif;letter-spacing: 0.1em;font-weight: bold;background-color: #444;border-bottom: 2px solid #333;color: #999;overflow: hidden;width: auto;">';
  replaceHtml += title + '<div style="position: absolute;right: 8px;top: 4px;cursor: hand;cursor: pointer;"><a href="#" onclick="modalHide(); return false"><img src="' + close_img + '" title="Close" border="0"></a></div>';
  replaceHtml += '</div>';
  if (modal_type == 'iframe') {
    replaceHtml += '<div class="iframewin" id="iframeLoading_' + modal_id +'"><span style="padding-left: 25px;">Loading content...</span></div>';
    replaceHtml += '<div class="drag-contentarea" style="height: ' + innerH + 'px;border: 0;padding:0;background-color: #FFF;color: #333;overflow: auto;">';
    replaceHtml += '<iframe class="dhtml_iframe" src="' + content + '" name="iframe_modal" style="margin: 0;padding-right: 30px;width: 100%;" frameborder="0" align="default" onload="iframeLoad_' + modal_id + '()"></iframe>';
    replaceHtml += '</div>';
  } else {
    // div
    replaceHtml += '<div class="drag-contentarea" style="height: ' + innerH + 'px;border: 0;padding: 0;background-color: #FFF;color: #333;overflow: auto;">';
    replaceHtml += document.getElementById(content).innerHTML;
    replaceHtml += '</div>';
  }
  replaceHtml += '</div>';
  replaceHtml += '</div>';

  document.getElementById('modalDiv').innerHTML = replaceHtml;

  // Height and width.
  document.getElementById('modalDiv').style.left = leftPos + 'px';
  document.getElementById('modalDiv').style.top = topPos + 'px';

  // Modal veil.
  document.getElementById('modalVeil').className = 'cover';
  document.getElementById('modalVeil').style.height = document.body.scrollHeight + 'px';
}

function modalHide() {
  document.getElementById('cat_browse_box').style.display = 'block';
  document.getElementById('modalDiv').style.display = 'none';
  document.getElementById('modalVeil').className = null;
}


// DHTML MODALS & WINDOWS:

// Set height to suit monitor. If max_modal_height = '', full height. Allow 180 inc. borders, modal footer etc.
function setModalHeight(max_modal_height) {

  var avl_height;

  if (typeof window.innerHeight != 'undefined') {
    avl_height = window.innerHeight;
  } else {
    avl_height = document.body.clientHeight;  // IE 6+
  }

  var full_height = (avl_height - 180);
  var min_required = (max_modal_height) ? (parseInt(max_modal_height) + 240) : avl_height;  // Allow approx 40px top and bottom

  // Default > use available height less space allowance.
  var output = full_height + 'px';

    if (max_modal_height && (avl_height >= min_required)) {
      // Plenty of space > use the input height.
      output = max_modal_height + 'px';
    }

  return output;
}

// Modals > change live help floatLayer z-index + other properties to avoid rendering issues. Not used in DHTML windows.
function setZIndex() {
  (document.getElementById('floatLayer')) ? document.getElementById('floatLayer').style.zIndex = "0" : null;
  (document.getElementById('qa_wrapper')) ? document.getElementById('qa_wrapper').style.zIndex = "0" : null;
  (document.getElementById('main_menu')) ? document.getElementById('main_menu').style.zIndex = "0" : null;
  (document.getElementById('ajax_response')) ? document.getElementById('ajax_response').style.zIndex = "0" : null;
}

function resetZIndex() {
  (document.getElementById('floatLayer')) ? document.getElementById('floatLayer').style.zIndex = "5000" : null;
  (document.getElementById('qa_wrapper')) ? document.getElementById('qa_wrapper').style.zIndex = "4" : null;
  (document.getElementById('main_menu')) ? document.getElementById('main_menu').style.zIndex = "5" : null;
  (document.getElementById('ajax_response')) ? document.getElementById('ajax_response').style.zIndex = "99999" : null;
}

// Hide list boxes.
function hideListboxes() {
  var aSelect = document.getElementsByTagName('select');
    for (var i=0; i<aSelect.length; i++) {
      if (aSelect[i].id != 'font_size' && 
         aSelect[i].id != 'hpfeat_per_row' &&
         aSelect[i].id != 'site_menu_system' &&
         aSelect[i].id != 'ad_editor' &&
         aSelect[i].id != 'row_limit' &&
         aSelect[i].id != 'screen' &&
         aSelect[i].id != 'mode_menu') {
         aSelect[i].style.visibility = 'hidden';
      }
    }
 }

// Ref: dhtmlwindows.js
function showListboxes() {
  resetZIndex();
  var aSelect = document.getElementsByTagName('select');
    for (var i=0; i<aSelect.length; i++) {
      aSelect[i].style.visibility = 'visible';
    }
}

// Open tool panel. See 'global_header.php' and body Onload functions. See setTpanelLink below.
function openToolPanel() {
//onclick="openToolPanel(); return false"
  var screenWidth = (screen.width - 270) + 'px';
  var modal_height = setModalHeight('250');
  tpanel=dhtmlwindow.open('tpbox','div','tpaneldiv','Tool Panel','width=195px,height=400px,left=' + screenWidth + ',top=100px,resize=1,scrolling=1,center=0')
}

// Popup bank details.
function openBankDetails(auction_id) {
//onclick="setZIndex();openBankDetails('100'); return false"
  hideListboxes();
  var modal_height = setModalHeight('250');
  var bdsetting = "popup_bank_details.php?auction_id=" + auction_id + "&modal=bdbox";
  bdbox=dhtmlmodal.open('bnkdetails','iframe',bdsetting,'Bank Details','width=450px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// About me page.
function openAboutMe(user_id, file_ext) {
//onclick="setZIndex();openAboutMe('100', 'file_ext'); return false"
  hideListboxes();
  var modal_height = setModalHeight('350');
  var aboutsetting = file_ext + "about_me.php?user_id=" + user_id + "&modal=aboutbox";
  aboutbox=dhtmlmodal.open('aboutme','iframe',aboutsetting,'About Me','width=650px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Profile page.
function openProfile(user_id, file_ext) {
//onclick="setZIndex();openProfile('100', 'file_ext'); return false"
  hideListboxes();
  var prsetting = file_ext + "profile.php?user_id=" + user_id + "&modal=profbox";
  profbox=dhtmlmodal.open('profile','iframe',prsetting,'Member Profile','width=750px,height=400px,left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Screen mode change. Triggered onload.
function screenModeChange() {
  setZIndex();
  hideListboxes();
  var modal_height = setModalHeight('250');
  scrpanel=dhtmlmodal.open('screenbox1','div','screendiv1','Screen Mode Changed','width=500px,height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
}

// Screen detect. Triggered onload.
function screenSizeDetect() {
  setZIndex();
  hideListboxes();
  var modal_height = setModalHeight('250');
  scrpanel2=dhtmlmodal.open('screenbox2','div','screendiv2','Screen Mode Option','width=500px,height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
}

// Screen detect. Triggered onload.
function setPreferences(highlight) {
//onclick="setZIndex();setPreferences(''); return false"
  hideListboxes();
  var modal_height = '350px';
    if (highlight && (highlight == 'hpfeat_per_row')) {
      modal_height = setModalHeight('300');
      prefspanel=dhtmlmodal.open('prefsbox','div','setprefs2','Featured Items','width=650px,height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
    } else if (highlight && (highlight == 'editor')) {
      prefspanel=dhtmlmodal.open('prefsbox','div','setprefs3','Template Editor & Selector','width=650px,height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
    } else {
      modal_height = setModalHeight('500');
      prefspanel=dhtmlmodal.open('prefsbox','div','setprefs','Preferences','width=650px,height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
    }
}

// Preview invoice.
function previewInvoice(invoice_id) {
//onclick="setZIndex();previewInvoice('100'); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var invsetting = "invoice_print.php?invoice_type=product_invoice&modal=previnv&preview=true&invoice_id=" + invoice_id;
  previnv=dhtmlmodal.open('invoice','iframe',invsetting,'Preview Invoice','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Message board > add new message
function messageBoard(winner_id, sender) {
//onclick="setZIndex();messageBoard('100'); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var msgsetting = "message_board.php?message_handle=3&winner_id=" + winner_id + "&modal=addmsg&sender=" + sender;
  addmsg=dhtmlmodal.open('msgboard','iframe',msgsetting,'Message Board','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Message board > view/reply to message.
function messageBoard2(params) {
//onclick="setZIndex();messageBoard2('params'); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var msgsetting2 = "message_board.php?" + params + "&modal=viewmsg";
  viewmsg=dhtmlmodal.open('msgboard2','iframe',msgsetting2,'Message Board','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Display invoice items.
function invoiceItems(invoice_id, winner_id, show) {
//onclick="setZIndex();invoiceItems('100', '101', 'msg'); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var itmsetting = "invoice_items.php?show=" + show + "&modal=invitems&invoice_id=" + invoice_id + '&message_handle=3' + ((winner_id) ? "&winner_id=" + winner_id : "");
  invitems=dhtmlmodal.open('invitm','iframe',itmsetting,'Invoice Items','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Add invoice note.
function invoiceNote(invoice_id, sender, auction_id) {
//onclick="setZIndex();invoiceNote('100', 'sender'); return false"
  hideListboxes();
  if (typeof auction_id === 'undefined') {
    auction_id = '';
  }
  var modal_height = setModalHeight('350');
  var insetting = "product_invoice_note.php?invoice_id=" + invoice_id + "&sender=" + sender + "&auction_id=" + auction_id + "&modal=invnote";
  invnote=dhtmlmodal.open('addinvnote','iframe',insetting,'Add Private Note','width=650px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Bid history.
function bidHistory(auction_id, sender) {
//onclick="setZIndex();bidHistory('100', '[page]'); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('350');
  var bhsetting = "bid_history.php?auction_id=" + auction_id + "&sender=" + sender + "&modal=bhistory";
  bhistory=dhtmlmodal.open('viewhist','iframe',bhsetting,'Bid History','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Currency converter.
function currencyConverter(currency, amount) {
//onclick="setZIndex();currencyConverter('AUD', '100'); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('350');
  var ccsetting = "currency_converter.php?currency=" + currency + "&amount=" + amount + "&modal=cconvert";
  cconvert=dhtmlmodal.open('currconv','iframe',ccsetting,'Currency Converter','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Add reputation rating & comments.
function addReputation(rep_id, sender) {
//onclick="setZIndex();addReputation('100', '[page]'); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var repsetting = "reputation_rating.php?reputation_id=" + rep_id + "&sender=" + sender + "&modal=addrep";
  addrep=dhtmlmodal.open('addreppage','iframe',repsetting,'Add Reputation','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// View reputation rating & comments.
function viewReputation(reputation_id, sender) {
//onclick="setZIndex();viewReputation('100', 'sender'); return false"
  hideListboxes();
  var modal_height = setModalHeight('350');
  var vrepsetting = "reputation_details.php?action=view_reputation&reputation_id=" + reputation_id + "&sender=" + sender + "&modal=viewrep";
  viewrep=dhtmlmodal.open('viewreppage','iframe',vrepsetting,'View Reputation','width=650px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// View user reputation.
function userReputation(user_id, sender) {
//onclick="setZIndex();userReputation('100'); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var urepsetting = "user_reputation.php?user_id=" + user_id +  "&sender=" + sender + "&modal=userrep";
  userrep=dhtmlmodal.open('viewuserrep','iframe',urepsetting,'User Reputation','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Auction summary.
function auctionSummary(auction_id, sender) {
//onclick="setZIndex();auctionSummary('100', 'sender'); return false"
  hideListboxes();
  var modal_height = setModalHeight('400');
  var adsetting = "auction_details.php?ad_summary=true&auction_id=" + auction_id + "&sender=" + sender + "&modal=auctsumm";
  auctsumm=dhtmlmodal.open('adsummary','iframe',adsetting,'Auction Summary','width=750px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Market data report.
function openMarketData(parent_id) {
//onclick="setZIndex();openMarketData('100'); return false"
  hideListboxes();
  var modal_height = setModalHeight('');  // Max
  var mktsetting = "../custom/Auctions/auction_market_data.php?parent_categoryID=" + parent_id + "&modal=mktdata";
  mktdata=dhtmlmodal.open('mktdatapage','iframe',mktsetting,'Market Data','width=840px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Edit available quantity.
function editAvailableQty(auction_id, sender) {
//onclick="setZIndex();editAvailableQty('100', '[page]'); return false"
  hideListboxes();
  var modal_height = setModalHeight('400');
  var eaqsetting = "edit_available_qty.php?auction_id=" + auction_id + "&sender=" + sender + "&modal=editaq";
  editaq=dhtmlmodal.open('editaqpage','iframe',eaqsetting,'Reduce Available Quantity','width=750px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Edit offered quantity.
function editOfferedQty(winner_id, sender) {
//onclick="setZIndex();editOfferedQty('100', '[page]'); return false"
  hideListboxes();
  var modal_height = setModalHeight('400');
  var eoqsetting = "edit_offered_qty.php?winner_id=" + winner_id + "&sender=" + sender + "&modal=editoq";
  editoq=dhtmlmodal.open('editoqpage','iframe',eoqsetting,'Adjust Offered Quantity','width=750px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Auction counter offer.
function auctionCounterOffer(offer_id) {
//onclick="setZIndex();auctionCounterOffer('100'); return false"
  hideListboxes();
  var modal_height = setModalHeight('450');
  var csetting = "auction_counter_offer.php?offer_id=" + offer_id + "&modal=cntroffer";
  cntroffer=dhtmlmodal.open('cntrofferpage','iframe',csetting,'Auction Counter Offer','width=750px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Swap counter offer.
function swapCounterOffer(swap_id) {
//onclick="setZIndex();swapCounterOffer('100'); return false"
  hideListboxes();
  var modal_height = setModalHeight('400');
  var csetting = "swap_counter_offer.php?swap_id=" + swap_id + "&modal=cntroffer2";
  cntroffer2=dhtmlmodal.open('cntrofferpage2','iframe',csetting,'Swap Counter Offer','width=750px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

function openCurrencyList() {
//onclick="openCurrencyList(); return false"
  hideListboxes();
  var modal_height = setModalHeight('250');
  currchange=dhtmlmodal.open('currencybox','div','currdiv','Change Active Currency','width=500px,height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
}

function openDemoUserInfo(mheight) {
//openDemoUserInfo();  // Body onload.
  if (document.getElementById('demodiv')) {
    hideListboxes();
    var modal_height = setModalHeight(mheight)
    demodetails=dhtmlmodal.open('demoinfo','div','demodiv','Demo User & Test Mode','width=350px,height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
  }
}

// Show auction description. (Not in use. Ref: 'custom_classes_general.php')
function openAuctionDescr(relpath, auction_name, auction_id) {
//onclick="setZIndex();openAuctionDescr(relpath, name, auction_id); return false"
  hideListboxes();
  var modal_height = setModalHeight('400');
  var asetting = relpath + "Auctions/auction_description.php?name=" + auction_name + "&auction_id=" + auction_id;
  auctionlink=dhtmlmodal.open('auctiondescr','iframe',asetting,'Auction Details Preview','width=750px,height=' + modal_height + ',left=200,top=150px,resize=1,scrolling=1,center=1')
}

// Show bid increments.
function openBidIncrements(relpath) {
//onclick="setZIndex();openBidIncrements(relpath); return false"
  var modal_height = setModalHeight('350');
  var isetting = relpath + "Auctions/auction_bid_increments.php";
  incrlist=dhtmlmodal.open('bidincr','iframe',isetting,'System Bid Increments','width=650px,height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
}

// Select guarantee image.
function setGuaranteeDetails(user_id) {
//onclick="setZIndex();setGuaranteeDetails('100'); return false"
  hideListboxes();
  var modal_height = setModalHeight('350');
  var gsetting = "../custom/Auctions/Admin/user_guarantee.php?user_id=" + user_id;
  glink=dhtmlmodal.open('gdetails','iframe',gsetting,'Guarantee Details','width=550px,height=' + modal_height + ',left=200,top=150px,resize=1,scrolling=1,center=1')
}

// Open KnowBase > view article.
function openKnowBase(kb_id, setanchor) {
//onclick="setZIndex();openKnowBase('100'); return false"
  hideListboxes();
  if (typeof setanchor === 'undefined') {
    setanchor = '';
  }
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var kbsetting = "http://www.seamarket.com.au/knowbase/public/kb_details.php?isipanel=true&frame=modal&KnowledgeID=" + kb_id + ((setanchor) ? "#" + setanchor : "");
  openkb=dhtmlmodal.open('knowbase','iframe',kbsetting,'Knowledge Base','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Open KnowBase > category. Set as '0' for no/home category.
function openKBCat(cat_id) {
//onclick="setZIndex();openKBCat('100'); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var kbcsetting = "http://www.seamarket.com.au/knowbase/public/index.php?isipanel=true&frame=modal&CategoryID=" + cat_id;
  openkbc=dhtmlmodal.open('kbasecat','iframe',kbcsetting,'Knowledge Base','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Swap images.
function swapImages(page, swap_ref_id, user_id) {
//onclick="setZIndex();swapImages('add_edit_swap_image', '100', '100'); return false"
  //var screenHeight = (screen.height - 450) + 'px';
  hideListboxes();
  var modal_height = setModalHeight('400');
  var swsetting = "../custom/Auctions/" + page + ".php?swap_ref_id=" + swap_ref_id + "&user_id=" + user_id;
    switch (page) {
      case 'add_edit_swap_image':
      swapimg=dhtmlmodal.open('swapimages','iframe',swsetting,'Auction Swap Images','width=650px,height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1');
      break;

      case 'auction_swap_images':
      swapimg2=dhtmlmodal.open('swapimages2','iframe',swsetting,'Auction Swap Images','width=650px,height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1');
      break;

      default:
      swapimg3=dhtmlmodal.open('swapimages3','iframe',swsetting,'Auction Swap Images','width=650px,height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1');
      break;
    }
}

// Auction fees.
function showAuctionFees(auction_id, is_relist) {
//onclick="setZIndex();showAuctionFees('100'); return false"
  hideListboxes();
  var modal_height = setModalHeight('400');
  var afsetting = "popup_auction_fees.php?auction_id=" + auction_id + "&is_relist=" + is_relist + "&modal=auctfees";
  auctfees=dhtmlmodal.open('auctfeespage','iframe',afsetting,'Auction Fees','width=650px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Subscription details.
function showSubscription(cust_id, sub_id) {
//onclick="setZIndex();showSubscription('100', '100'); return false"
  hideListboxes();
  var modal_height = setModalHeight('350');
  var subsetting = "http://www.seamarket.com.au/custom/PPCheckout/index_iframe_child.php?ppc_page=summary&ppc_section=sub&cust_id=" + cust_id + "&sub_id=" + sub_id + "&custom=php_pro_bid&modal=subscr";
  subscr=dhtmlmodal.open('subdetails','iframe',subsetting,'Subscription Details','width=650px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Display back link for invoice navigation.
function headerBackLink() {
  if ( ((parent.frames['_iframe-invoice']) || (parent.frames['_iframe-msgboard'])) && document.getElementById('header_back_link') ) {
    document.getElementById('header_back_link').style.display = "block";
  }
}

// Open help items. relpath eg. '../' if called from KnowBase.
function openHelpItems(relpath, page_name, key_words, search_phrase, system) {
//onclick="setZIndex();openHelpItems(relpath, page_name, key_words); return false"
  hideListboxes();
  var add_params = '';
  var add_params2 = '';
    if (typeof search_phrase === 'undefined') {
      search_phrase = '';
    }
    if (search_phrase) {
      add_params = '&s_phrase=' + search_phrase + '&apm=1_1';
    }
    if (typeof system === 'undefined') {
      system = 'auctions';
    }
    if (system) {
      add_params2 = '&system=' + system;
    }
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var hsetting = relpath + "../custom/Support/Help/index.php?page=page_help&page_name=" + page_name + "&keywords=" + key_words + "&isipanel=true&frame=modal&modal=helpitems&apm=1_1" + add_params + add_params2;
  helpitems=dhtmlmodal.open('helplist','iframe',hsetting,'Page Help Items','width=' + modal_width + ',height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
}

// Open single help item. Ref: 'custom_functions.php' re: generate help items list.
function helpItem(relpath, params) {
//onclick="setZIndex();helpItem(relpath, params); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var hisetting = relpath + "../custom/Support/Help/index.php?" + params;
  hitem=dhtmlmodal.open('helpitem','iframe',hisetting,'Page Help Items','width=' + modal_width + ',height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
}

// Open listing templates (window).
function openListingTpls(cat_id) {
//onclick="setZIndex();openListingTpls('100'); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var tplsetting = '../custom/Templates/popup_listing_template.php?page=popup_tpl&catID=' + cat_id + '&isipanel=true&apm=1_1';
  tplwin=dhtmlmodal.open('tpllist','iframe',tplsetting,'Listing Templates','width=' + modal_width + ',height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
}

// Preview store.
function previewStore(user_id, store_name) {
//onclick="setZIndex();previewStore('100', 'name'); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var shopsetting = 'shop.php?name=' + store_name + '&user_id=' + user_id + '&modal=prevstore';
  prevstore=dhtmlmodal.open('storepages','iframe',shopsetting,'Store Preview','width=' + modal_width + ',height=' + modal_height + ',left=200px,top=150px,resize=1,scrolling=1,center=1')
}

// Open tutorials. See 'global_header.php', 'mainpage.tpl.php', 'header.tpl.php' and body Onload functions. 
// No setZIndex.
function openTutorials(params, setlist, setstart) {
//onclick="openTutorials('tutorialID=100&itemID=100','false'); return false"
  var modal_width = '800px';
  var modal_height = setModalHeight('');
  if (typeof setlist === 'undefined') {
    setlist = 'false';
  }
  if (typeof setstart === 'undefined') {
    setstart = 'false';
  }
  var tusetting;
  if (setlist == 'true') {
     var tusetting = "http://www.seamarket.com.au/custom/Auctions/Tutorials/auction_tutorials.php";
  } else {

     // [params] s_sectionID=2&tutorialID=2 = (buyer tutorial - getting started)
     if (setstart == 'true') {
       var tusetting = "http://www.seamarket.com.au/custom/Auctions/Tutorials/tutorial_start.php?" + params;
     } else {
       var tusetting = "http://www.seamarket.com.au/custom/Auctions/Tutorials/tutorial_page.php?" + params;
     }
  }
  tubox=dhtmlwindow.open('tutor','iframe',tusetting,'Auction Tutorials','width=' + modal_width + ',height=' + modal_height + ',left=20px,top=20px,resize=1,scrolling=1,center=0')
}

// Open HelpDesk.
function openHelpDesk() {
//onclick="setZIndex();openHelpDesk(); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var hdsetting = "http://www.seamarket.com.au/helpdesk/public/index.php?isipanel=true&frame=modal";
  openhd=dhtmlmodal.open('hdesk','iframe',hdsetting,'Help Desk','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Open Support options.
function openSupportOptions() {
//onclick="setZIndex();openSupportOptions(); return false"
  hideListboxes();
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var suppsetting = "http://www.seamarket.com.au/custom/Support/support_options.php?page=support&isipanel=true&frame=modal";
  opensupport=dhtmlmodal.open('suppoptions','iframe',suppsetting,'Support Options','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Popup search box.
function searchBox() {
//onclick="setZIndex();searchBox(); return false"
  hideListboxes();
  var modal_height = setModalHeight('200');
  var schsetting = "popup_search_box.php?modal=sbox";
  sbox=dhtmlmodal.open('search','iframe',schsetting,'Search','width=700px,height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}

// Add or edit contingency group, add to group etc.
function contingencyGroup(task, sale_type, record_id, auction_id, group_id, sender) {
//onclick="setZIndex();contingencyGroup('add_contingency_group', 'bid', '100', '200'); return false"
  hideListboxes();
  if (typeof group_id === 'undefined') {
    group_id = '';
  }
  if (typeof sender === 'undefined') {
    sender = 'current_bids';
  }
  var modal_width = (screen.width <= 1280) ? ((screen.width - 80) + 'px') : '1200px';
  var modal_height = setModalHeight('');  // Max
  var cgsetting = "contingency_group.php?do=" + task + "&sale_type=" + sale_type + "&record_id=" + record_id + "&auction_id=" + auction_id + "&group_id=" + group_id + "&sender=" + sender + "&modal=cgbox";
  cgbox=dhtmlmodal.open('cgroup','iframe',cgsetting,'Add/Edit Contingency Group','width=' + modal_width + ',height=' + modal_height + ',left=100px,top=100px,resize=1,scrolling=1,center=1')
}


// POPUPS:

// Popup window.
function OpenPopWin(this_id, win_width, win_height) {
  var linkhref = this_id.href;
  var win=window.open(linkhref, "this_id.id", "left=20,top=20,width=" + win_width + ",height=" + win_height + ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,modal=yes");
  win.focus();
}


// TOGGLE PANEL:

//<a href="#" onmouseup="swapTools(this.id);" id="close_panel" style="DISPLAY: block" onclick="closePanel(); return false">Maximize</a> <a href="#" onmouseup="swapTools(this.id);" id="open_panel" style="DISPLAY: none" onclick="openPanel(); return false">Restore</a> 

function closePanel(panel_id) {
  if (document.getElementById(panel_id)) {
    document.getElementById(panel_id).style.display = 'none';
  }
}

function openPanel(panel_id) {
  if (document.getElementById(panel_id)) {
    document.getElementById(panel_id).style.display = 'block';
  }
}

function swapTools(this_link, panel_num) {
//onmouseup="swapTools(this.id);"
  if (this_link == 'open_panel_' + panel_num) {
    document.getElementById('open_panel_' + panel_num).style.display = 'none';
    document.getElementById('close_panel_' + panel_num).style.display = 'block';
  } else {
    document.getElementById('close_panel_' + panel_num).style.display = 'none';
    document.getElementById('open_panel_' + panel_num).style.display = 'block';
  }
}

// Toggle search panel.
//onclick="togglePanel('topPanel');swapPanelClass(this.id);"
function togglePanel(this_link) {
  if (document.getElementById(this_link).className == "toggleClose") {
    document.getElementById(this_link).className = "toggleOpen";
  } else {
    document.getElementById(this_link).className = "toggleClose";
  }
}

function swapPanelClass(this_link) {
//onclick="swapPanelClass(this.id);"
  if (document.getElementById(this_link).className == "closeTopPanel") {
    document.getElementById(this_link).className = "openTopPanel";
  } else {
    document.getElementById(this_link).className = "closeTopPanel";
  }
}

// GENERAL:

// Row style changer.
function rowHighlight(tableRow, highLight, current) {
  if (highLight) {
    tableRow.className = current + ' rowHover';
  } else {
    tableRow.className = current;
  }
}

// Show fx box onload.
function showFx() {
  (document.getElementById('fxContainer')) ? document.getElementById('fxContainer').style.display = 'block' : null;
}

/* Set wide tables to overflow if needed (classic menus). Applies to content that opens in members area. 
   Otherwise auto-controlled by parent container width. (Not in use: ref: global_header.php contentwrappers set width)

  <//? if (($set_screen == 'std') && ($site_menu_system == 'classic')) { ?>
  wkAreaSize('classic');  // Adjust widths.
  <//? } ?>
*/
function wkAreaSize(site_menu_system) {
  // Ref: members_area.tpl.php
  var wkarea = ((screen.width) - 236);  // 236 FF
  if (wkarea && (site_menu_system == 'classic')) {
    (document.getElementById('tbl_selling_open')) ? document.getElementById('tbl_selling_open').style.width = wkarea + 'px' : null;
    (document.getElementById('tbl_selling_invoices_sent')) ? document.getElementById('tbl_selling_invoices_sent').style.width = wkarea + 'px' : null;
    (document.getElementById('tbl_bidding_invoices_rcd')) ? document.getElementById('tbl_bidding_invoices_rcd').style.width = wkarea + 'px' : null;
    (document.getElementById('tbl_bidding_won_items')) ? document.getElementById('tbl_bidding_won_items').style.width = wkarea + 'px' : null;
    (document.getElementById('tbl_selling_sold')) ? document.getElementById('tbl_selling_sold').style.width = wkarea + 'px' : null;
    (document.getElementById('tbl_selling_closed')) ? document.getElementById('tbl_selling_closed').style.width = wkarea + 'px' : null;
  }
}

// Pause scroller.
function pauseScroller() {
  var iframeEl = document.getElementById('iframe_scroller');
    if ( iframeEl.contentDocument ) { // DOM
      var scroller = iframeEl.contentDocument.getElementById('p7VSCb_1');
    } else if ( iframeEl.contentWindow ) { // IE win
      var scroller = iframeEl.contentWindow.document.getElementById('p7VSCb_1');
    }
  scroller.P7_VSCpause(this);
}

// Set scroller height body onload to height of other element.
function setScrollerHeight() {

  var esource = document.getElementById('featured_wrapper');
  var source_height = (esource) ? esource.offsetHeight : 0;

  var iframeScr = document.getElementById('iframe_scroller');
    if ( iframeScr.contentDocument ) { // DOM
      var scroller = iframeScr.contentDocument.getElementById('p7VSCb_1');
      var scroller_inner = iframeScr.contentDocument.getElementById('p7VSCcn_1');
      var scroller_drag = iframeScr.contentDocument.getElementById('p7VSCdc_1');
    } else if ( iframeScr.contentWindow ) { // IE win
      var scroller = iframeScr.contentWindow.document.getElementById('p7VSCb_1');
      var scroller_inner = iframeScr.contentWindow.document.getElementById('p7VSCcn_1');
      var scroller_drag = iframeScr.contentWindow.document.getElementById('p7VSCdc_1');
    }

  if (esource && (source_height > 300) && iframeScr) {
    iframeScr.style.height = (source_height - 100) + 'px';
    scroller.style.height = (source_height - 140) + 'px';
    scroller_inner.style.height = (source_height - 140) + 'px';
    scroller_drag.style.height = (source_height - 140) + 'px';
  }
}

// Set wrapper width so overflows.
function setWrapper(linkItem, linkClass) {
 if (document.getElementById(linkItem)) {
    var setLink = document.getElementById(linkItem);
    setLink.className = linkClass;
 }
}

// Set active page link. Classic menu and shop pages.
//onload="setActiveLink('active')
function setActiveLink(linkClass, type) {
  var linkItem = 'no_link_id';
  if (type == 'ma_menu') {
    page = getURLParam("page");
    section = getURLParam("section");
    linkItem = page + section;
  } else {
    shop_link_ID = getURLParam("shop_link_ID");
    linkItem = shop_link_ID;
  }
  if (document.getElementById(linkItem)) {
     var setLink = document.getElementById(linkItem);
     setLink.className = linkClass;
  }
}

// Set active tool panel link.
//onload="setTpanelLink('current')
function setTpanelLink(linkClass) {
tpLink = getURLParam("tpanel");
 if (document.getElementById("tp_" + tpLink)) {
    var setLink = document.getElementById("tp_" + tpLink);
    setLink.className = linkClass;
 }
}

//Swap three-state button class.
//onmousedown="swapClass(this.id,'ts1 selected')"
function swapClass(linkItem, linkClass) {
 if (document.getElementById(linkItem)) {
    var setLink = document.getElementById(linkItem);
    setLink.className = linkClass;
 }
}

// Confirm page action.
function confirmAction(this_href, message) {
//onclick="confirmAction(this.href, 'message here');"
  var action = confirm(message);
    if (action == true) {
      window.location = this_href;
    } else {
      return false;
    }
}

// General onload alert.
function alertMsg(message) {
  alert(message);
}

// Capitalize > onblur="capitalizeFirst(this)" > onblur="capitalizeAll(this)"
function capitalizeFirst(obj) {
  val = obj.value;
  newVal = '';
    if (val != '') {
      val = val.split(' ');
       for(var c=0; c < val.length; c++) {
         newVal += val[c].substring(0,1).toUpperCase() + val[c].substring(1,val[c].length) + ' ';
       }
	}
  var trimmed = newVal.replace(/^\s+|\s+$/g, '') ;
  obj.value = trimmed;
}

function capitalizeAll(obj) {
  val = obj.value;
  newVal = '';
    if (val != '') {
      val = val.split(' ');
        for(var c=0; c < val.length; c++) {
          newVal += val[c].toUpperCase() + ' ';
        }
	}
  var trimmed = newVal.replace(/^\s+|\s+$/g, '') ;
  obj.value = trimmed;
}


// PROJECTSEVEN:

// P7 swap class. Not in use.
// onmouseup="P7_swapClass(0,'none','show','noshow','select')"
function P7_swapClass(){ //v1.4 by PVII
 var i,x,tB,j=0,tA=new Array(),arg=P7_swapClass.arguments;
 if(document.getElementsByTagName){for(i=4;i<arg.length;i++){tB=document.getElementsByTagName(arg[i]);
  for(x=0;x<tB.length;x++){tA[j]=tB[x];j++;}}for(i=0;i<tA.length;i++){
  if(tA[i].className){if(tA[i].id==arg[1]){if(arg[0]==1){
  tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];}else{tA[i].className=arg[2];}
  }else if(arg[0]==1 && arg[1]=='none'){if(tA[i].className==arg[2] || tA[i].className==arg[3]){
  tA[i].className=(tA[i].className==arg[3])?arg[2]:arg[3];}
  }else if(tA[i].className==arg[2]){tA[i].className=arg[3];}}}}
}

// P7 Jump menu.
/*
	  <form name="jmenu_form">
	    <select name="mode_menu" onChange="P7_JumpMenu(this,0)">
	      <option value="members_area.php~" selected>Normal mode</option>
	      <option value="members_area.php~">Full screen mode</option>
	    </select>
	    <input type="button" name="Button1" value="Go" onClick="P7_JumpMenuGo('mode_menu',0)">
	  </form>
*/
function P7_JumpMenu(selObj,restore){ //v1.4 by Project Seven
	var theFullString = selObj.options[selObj.selectedIndex].value;
	if (restore) selObj.selectedIndex=0;
	var theLength = theFullString.length;
	var endPos = theFullString.lastIndexOf("~");
	var theUrl, theTarget, theParent;
	if (endPos > 0) {theUrl = theFullString.substring(0,endPos);}
	else {theUrl = theFullString;}
	endPos++
	if (endPos < theLength) {theTarget = theFullString.substring(endPos,theLength)}
	else {theTarget = "window:Main";}
	if (theTarget == "window:New") {window.open(theUrl);}
	else if (theTarget == "window:Main") {eval("parent.location='"+theUrl+"'");}
	else {eval("parent.frames[\'"+theTarget+"\'].location='"+theUrl+"'");}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function P7_JumpMenuGo(selName,restore){ //v1.1 Beta Version by Project Seven
  var selObj = MM_findObj(selName); if (selObj) P7_JumpMenu(selObj,restore);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function P7AniMagic(el,x,y,a,b,c,s) { //v2.9 PVII-Project Seven Development
 var xx,yy,i,g,elo=el,f="",m=false,d="",pa='px';if(document.layers||window.opera){pa='';}
 x=parseInt(x);y=parseInt(y);var t='g.p7Magic=setTimeout("P7AniMagic(\''+elo+'\','; 
 if((g=MM_findObj(el))!=null){d=(document.layers)?g:g.style;}else{return;}
 if(parseInt(s)>0){eval(t+x+','+y+','+a+','+b+','+c+',0)",' + s+')');return;}
 xx=parseInt(d.left);if(isNaN(xx)){if(g.currentStyle){xx=parseInt(g.currentStyle.left);
 }else if(document.defaultView&&document.defaultView.getComputedStyle){
 xx=parseInt(document.defaultView.getComputedStyle(g,"").getPropertyValue("left"));}
 if(isNaN(xx)){xx=0;}}yy=parseInt(d.top);if(isNaN(yy)){if(g.currentStyle){yy=parseInt(g.currentStyle.top);
 }else if(document.defaultView&&document.defaultView.getComputedStyle){
 yy=parseInt(document.defaultView.getComputedStyle(g,"").getPropertyValue("top"));}
 if(isNaN(yy)){yy=0;}}if(c==1){x+=xx;y+=yy;m=true;c=0;}else if(c==2){m=false;
 if(g.p7Magic){clearTimeout(g.p7Magic);}}else{i=parseInt(a);if(g.p7Magic){clearTimeout(g.p7Magic);}
 if(xx<x){xx+=i;m=true;if(xx>x){xx=x;}}if(xx>x){xx-=i;m=true;if(xx<x){xx=x;}}
 if(yy<y){yy+=i;m=true;if(yy>y){yy=y;}}if(yy>y){yy-=i;m=true;if(yy<y){yy=y;}}}
 if(m){d.left=xx+pa;d.top=yy+pa;eval(t+x+','+y+','+a+','+b+','+c+',0)",'+b+')');}
}


