
/*************************************************************************
  This code is from Dynamic Web Coding at www.dyn-web.com
  Copyright 2001-4 by Sharon Paine
  See Terms of Use at www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

  function initScrollLayer() {
    // arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll,
    // if horizontal scrolling, id of element containing scrolling content (table?)
    var wndo = new dw_scrollObj('wn', 'lyr1', 't1');

  }


  //keep around the old call function
  xajax.realCall = xajax.call;
  //override the call function to bend to our wicked ways
  xajax.call = function(sFunction, aArgs, sRequestType)
  {
      //show the spinner
      this.$('spinner').style.display = 'inline';
      //Effect.toggle(this.$('spinner'), 'appear');
      //call the old call function
      return this.realCall(sFunction, aArgs, sRequestType);
  }

  //save the old processResponse function for later
  xajax.realProcessResponse = xajax.processResponse;
  //override the processResponse function
  xajax.processResponse = function(xml)
  {
      //hide the spinner
      this.$('spinner').style.display = 'none';
      //Effect.toggle(this.$('spinner'), 'appear');
      //call the real processResponse function
      return this.realProcessResponse(xml);
  }

  function validate(req, input){
    id = document.getElementById(input.id);
    if (input.value == '' && req){
        id.className = "errorfieldname";
    }else{
        id.className = "fieldname";
    }
  }

  var StartDate;
  var EndDate;

  function setStartDate(myform, mysdate){
    StartDate = new calendar1(document.forms[myform].elements[mysdate]);
    StartDate.year_scroll = true;
    StartDate.time_comp = false;
  }
  
  function setEndDate(myform, myedate){
    EndDate = new calendar1(document.forms[myform].elements[myedate]);
    EndDate.year_scroll = true;
    EndDate.time_comp = false;
  }


  function checkRecipient(myform, sel){
    if (sel.options[sel.selectedIndex].value == '--'){
        document.getElementById('newalias').style.display = '';
    }else{
        var seltext = sel.options[sel.selectedIndex].value;
        var sel_array =seltext.split("-");
        var seldevopt = sel_array[0];

        myform.devopt[seldevopt].checked = true;
        document.getElementById('newalias').style.display = 'none';
    }
  }

  function changealias(ch){

        if (ch.options[ch.selectedIndex].value == '--'){
            Effect.toggle('txt_'+ch.id, 'appear');

        }else{
            document.getElementById('txt_'+ch.id).style.display    = "none";
            xajax_call('cart', '_changealias', ch.options[ch.selectedIndex].value);
        }
  }

  function enableRecipientForm(mode){
        if (mode == 1){
            document.recipientfrm.block.disabled = false;
            document.recipientfrm.unit.disabled = false;
            document.recipientfrm.building.disabled = false;
            document.recipientfrm.street1.disabled = false;
            document.recipientfrm.street2.disabled = false;
            document.recipientfrm.street3.disabled = false;
            document.recipientfrm.city.disabled = false;
            document.recipientfrm.state.disabled = false;
            document.recipientfrm.country.disabled = false;
            document.recipientfrm.zip.disabled = false;
            document.recipientfrm.officeaddress_check.disabled = false;

        }else{
            document.recipientfrm.block.disabled = true;
            document.recipientfrm.unit.disabled = true;
            document.recipientfrm.building.disabled = true;
            document.recipientfrm.street1.disabled = true;
            document.recipientfrm.street2.disabled = true;
            document.recipientfrm.street3.disabled = true;
            document.recipientfrm.city.disabled = true;
            document.recipientfrm.state.disabled = true;
            document.recipientfrm.country.disabled = true;
            document.recipientfrm.zip.disabled = true;

            document.recipientfrm.officeaddress_check.disabled = true;
            document.recipientfrm.officeaddress_check.checked = true;
        }
  }

  function OfficeAddressCheck(myform){

      var sel;

      t = myform.noelofficeaddress_check;

      if (!t){
        return;
      }

      for (var i=0; i<t.length; i++) {
          if (t[i].checked) sel = t[i].value;
      }

      if (sel == "1"){
          myform.block.value = "";
          myform.unit.value = "#03-01";
          myform.building.value = "";
          myform.street1.value = "7 Tai Seng Drive";
          myform.street2.value = "";
          myform.street3.value = "";
          myform.city.value = "Singapore";
          myform.state.value = "NA";
          myform.country.value = "Singapore";
          myform.zip.value = "535218";
          myform.officeaddress_check.checked = true;
          enableRecipientForm(0);

      }else{
          enableRecipientForm(1);
          myform.block.value = "";
          myform.unit.value = "";
          myform.building.value = "";
          myform.street1.value = "";
          myform.street2.value = "";
          myform.street3.value = "";
          myform.city.value = "";
          myform.state.value = "";
          myform.country.value = "";
          myform.zip.value = "";
          myform.officeaddress_check.checked = false;
      }
  }

  function SubmitOfficeAddressCheck(myform, issubmit){

        t = myform.noelofficeaddress_check;
        sel = t.value;

        //if (!t){
        //   return;
        //}

        //for (var i=0; i<t.length; i++) {
        //    if (t[i].checked) sel = t[i].value;
        //}

        if (sel == "1" && issubmit === 1){
            enableRecipientForm(1);
        }else if (sel == "1") {
            enableRecipientForm(0);
        }
  }

  //Billing Section
  function addPackage(mainform, keycode) {
      var inputlength = keycode.length;
      if (inputlength > 8){
        if (checkExistEvoucher(mainform, keycode)){
            alert("The eVoucher Code that you have entered already exist in the list.");
        }else{
            var len = mainform.eVoucherList.options.length;
            mainform.eVoucherList.options[len] = new Option(keycode);
            mainform.eVoucherList.options[len].value = keycode;
            mainform.keycode.focus();
        }
      }else{
          alert('The eVoucher code that you have key in is invalid.');
      }
  }

  function checkExistEvoucher(mainform, strCode){
      var maxItems = mainform.eVoucherList.options.length;
      for (i=0;i<maxItems;i++){
          if (strCode == mainform.eVoucherList.options[i].value){
              return true;
          }
      }
      return false;
  }


  function removePackage(mainform) {
    var obj = mainform.eVoucherList.options;
    if(obj.selectedIndex > 0) {
      if(confirm("Are you sure you want to remove eVoucher\nnamed \""+obj[obj.selectedIndex].text+"\"?")) {
        obj[obj.selectedIndex] = null;
        obj[0].selected = true;
      }
    }
  }

  function submitForm( mainform ) {
    var obj = mainform.eVoucherList.options;
    var vv = "";
    for(i=1; i<obj.length; i++) {
      vv = vv+obj[i].value+",";
    }
    //alert(vv);
    mainform.billingvoucher.value = vv;
  }

  function autoSubmitForm(myform){
    myform.submit();
    return true;
  }

  function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
      var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  }

  function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  }

  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 MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
     if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  }
  
  function reloadPage(){
      // Notice the use of the each method to gain access to each element individually
     
       $('a.item-tooltips').each(function()
       {
          // Create image content using websnapr thumbnail service
          
          var pid = $(this).attr('rel');
    
          // Setup the tooltip with the content
          $(this).qtip(
          {
             content: {
                text: '<img src="/images/loading.gif" />',
                url: 'index.php',
                data: { id: pid, module: 'product_catalog', action: 'getItemTooltips' },
                method: 'get'
             },
            position: {
                corner: {
                   target: 'rightMiddle', // Position the tooltip above the link
                   tooltip: 'leftMiddle'
               }
             },
             hide: {
                fixed: true // Make it fixed so it can be hovered over
             },
             style: {
                tip: true,
                background: '#FFEABD',
                width: 340 // Set the tooltip width
             }
    
          });
       });
       
       // Notice the use of the each method to gain access to each element individually
       $('a.item-tooltips-left').each(function()
       {
          // Create image content using websnapr thumbnail service
          
          var pid = $(this).attr('rel');
    
          // Setup the tooltip with the content
          $(this).qtip(
          {
             content: {
                text: '<img src="/images/loading.gif" />',
                url: 'index.php',
                data: { id: pid, module: 'product_catalog', action: 'getItemTooltips' },
                method: 'get'
             },
            position: {
                corner: {
                   target: 'leftMiddle', // Position the tooltip above the link
                   tooltip: 'rightMiddle'
               }
             },
             hide: {
                fixed: true // Make it fixed so it can be hovered over
             },
             style: {
                tip: true,
                background: '#FFEABD',
                width: 340 // Set the tooltip width
             }
    
          });
       });
  }

