<?php

  /*
   *  Template file: common.js
   *  Copyright © Comrax Ltd., 1999-2003. All rights reserved.
   *  Unauthorized duplication and modification prohibited.
   *
   *  END-USER LICENSE AND AGREEMENT                                         >>>
   *
   *  THIS SOFTWARE IS PROVIDED BY "COMRAX LTD" ``AS IS'' AND ANY EXPRESS OR
   *  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   *  IN NO EVENT SHALL "COMRAX LTD" BE LIABLE FOR ANY DIRECT, INDIRECT,
   *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   ****************************************************************************/

  if( defined( '_COMMON_JS_INC' ) ) return;
  define( '_COMMON_JS_INC', 1 );

  include( 'portalce.inc' );
  include( SYS_SCRIPTS_DIR.'initialize.inc' );
?>
  var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
  // Handle all the FSCommand messages in a Flash movie.

  function bottom_banners_DoFSCommand(command, args) {
    var bottom_bannersObj = isInternetExplorer ? document.all.bottom_banners : document.bottom_banners;
    switch(command) {
      case 'birthday':
       location = "<?= HrefLink( LINK_BIRTHDAY ); ?>";
        break;
      case 'banner1':
       location = "<?= HrefLink( LINK_SALES_TRANSFORMERS ); ?>";
        break;
      case 'banner2':
        location = "<?= HrefLink( LINK_SALES1  ); ?>";
        break;
      case 'banner3':
        location = "<?= HrefLink( LINK_SALES3  ); ?>";
        break;
      case 'music':
        if( args == 'on' ) {
          top.music.startMusic( );
          top.home.document.bottom_banners.setvariable("music", "on");
        } else {
          top.music.stopMusic( );
          top.home.document.bottom_banners.setvariable("music", "off");
        }
        break;
      case 'game':
        top.location.href = '<?= HrefLink( LINK_MAZE_GAME ); ?>';
        break;
      case 'mini':
        top.location.href = '<?= HrefLink( LINK_SPIDER ); ?>';
        break;
      case 'snif':
        top.location.href = '<?= HrefLink( LINK_BRANCHES   ); ?>';
        break;  
      case 'back':
        history.back();
        break;  
    }
  }

  function menu_DoFSCommand(command, args) {
    var menuObj = isInternetExplorer ? document.all.menu : document.menu;
    switch(command) {
      case 'music':
        if( args == 'on' ) {
          top.music.startMusic( );
          top.home.document.menu.setvariable("music", "on");
        } else {
          top.music.stopMusic( );
          top.home.document.menu.setvariable("music", "off");
        }
        break;
      case 'game':
        top.location.href = '<?= HrefLink( LINK_MAZE_GAME ); ?>';
        break;
      case 'back':
        history.back();
        break;  
    }
  }

  function ValidateContactForm( form ) {

    if( !form.firstName.value ) {
      alert('נא למלא את שם פרטי');
      form.firstName.focus();
      return false;
    }
    if( !form.lastName.value ) {
      alert('נא למלא שם המשפחה');
      form.lastName.focus();
      return false;
    }
    if( !form.phone.value ) {
      alert('נא למלא טלפון');
      form.phone.focus();
      return false;
    }
    if( !form.email.value ) {
      alert('נא למלא דואר אלקטרוני');
      form.email.focus();
      return false;
    }

    /// Email validation
    if( !validate ( form, 'email', "[a-zA-Z0-9\-_.]+@[a-zA-Z0-9\-_.]+", 'נא להזין כתובת נכונה' ) ) return false;


    form.submit();
  }
  function validate( frm, fld, reg, msg )  {
      eval( 'field=frm.' + fld );
      field_value=field.value;
      if(field_value.match(reg)!=field_value) {
        alert ( msg );
        field.focus();
        return false;
      };
      return true;
    };


  var idout;

  var valPageLoaded = 0;
  var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                  parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
  var isMinIE4 = (document.all) ? 1 : 0;
  var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.")) >= 0 ? 1 : 0;

  function Skip(){
    document.location.href = '<?= HrefLink( $SYS_BASE_HREF ); ?>/home/';
  }

  function RollOver( img ) {
    if( isMinNS4 || isMinIE4 ) {
      document.images[ img ].src = '<?= ImageHref( ); ?>menu-' + img + '-on.gif';
    }
  }
  function RollOut( img, current ) {
    if( isMinNS4 || isMinIE4 ) {
      if( current != img ) {
        document.images[ img ].src = '<?= ImageHref( ); ?>menu-' + img + '.gif';
      }
    }
  }
  function openmenu( menu ) {
        document.getElementById( menu ).style.visibility = "visible";
  }
  function closemenu( menu ) {
        document.getElementById( menu ).style.visibility = "hidden";
  }

  function LoadImages( ) {
    if( isMinNS4 || isMinIE4 ) {
      img1  = new Image( );

      img1.src  = "<?= ImageHref( ); ?>";
    }
  }

  LoadImages( );

  function DoNothing( ) { }

  function showmenu( ) {
      if( isMinIE4 ) {
        document.getElementById('aboutMenu').style.visibility = "visible";
      }
  }

  function hidewithdelay( ) {
      setTimeout( "hidemenu( )", 1000 );
  }

  function hidemenu( ) {
      if( isMinIE4 ) {
        document.getElementById('aboutMenu').style.visibility = "hidden";
      }
  }

  // Specify the marquee's width (in pixels)
  var marqueewidth = "100%";

  // Specify the marquee's height
  var marqueeheight = "100%";

  // Specify the marquee's scroll speed (larger is faster)
  var speed = 1;

  //Specify the marquee contents
  var marqueecontents = '';

  function openCenterWindow( url, wd, ht, scroll ) {
    d = ( screen.width - wd )/2;
    h = ( ( screen.height-ht )/2 );

    window.open(url,'','top=' + h + ',left=' + d + ',width=' + wd + ',height=' + ht + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scroll + ',resizable=' + scroll + '').focus();
  }

  function submit_search() {
    form = document.SearchForm;
    form.submit();
  }

  function RedirectPage( strPage ) {
    switch( strPage ) {
      case 'join':
                    strLink = '<?= HrefLink( LINK_JOIN ); ?>';
                    break;
      case 'company':
                    strLink = '<?= HrefLink( LINK_ABOUT, array( $SYS_ARTICLES_VIEW_ID => '2f740988dc053a8522f193e955c7ce84' ) ); ?>';
                    break;
      case 'world':
                    strLink = '<?= HrefLink( LINK_ABOUT, array( $SYS_ARTICLES_VIEW_ID => '88c654743a24bc9e516d677b76525a4e' ) ); ?>';
                    break;
      case 'ten':
                    strLink = '<?= HrefLink( LINK_ABOUT, array( $SYS_ARTICLES_VIEW_ID => '3baea219d2f5f598386d78184dfb3012' ) ); ?>';
                    break;
      case 'new':
                    strLink = '<?= HrefLink( LINK_NEW ); ?>';
                    break;
      case 'birthday':
                    strLink = '<?= HrefLink( LINK_BIRTHDAY ); ?>';
                    break;
      case 'takemenu':
                    strLink = '<?= HrefLink( LINK_TAKEAWAY ); ?>';
                    break;
      case 'pricelist':
                    strLink = '<?= HrefLink( LINK_TAKEMENU ); ?>';
                    break;
      case 'sales':
                    strLink = '<?= HrefLink( LINK_SALES ); ?>';
                    break;
      case 'pesachmenu':
                    strLink = '<?= ImageHref( LINK_PESACHMENU_PDF ); ?>';
		    location = strLink;
                    break;
      case 'birthday_branches':
                    strLink = '<?= HrefLink( LINK_BIRTHDAY_BRANCHES ); ?>';
                    break;
      default:
                    strLink = '<?= HrefLink( LINK_HOME ); ?>';
                    break;
    }
    document.location.href = strLink;
  }

  function BranchLocation( intAreaID ) {
    strLink = '<?= HrefLink( LINK_BRANCHES, array( SYS_FORM_ACT_CMD => 'view' ) ); ?>';
    document.location.href = strLink + '&<?= $SYS_FORM_AREA_CMD; ?>=' + intAreaID
  }

  function openPopupURL( page ) {
    switch( page ) {
      case 'digital':
              strLink = '<?= HrefLink( LINK_DIGITAL ); ?>'
              openCenterWindow( strLink, 710, 378, 'no' );
              break;

      case 'summer':
              strLink = '<?= HrefLink( LINK_SUMMER ); ?>'
              openCenterWindow( strLink, 710, 440, 'no' );
              break;
    }
  }

  function bratz_DoFSCommand( command, args ) {

    if( command == 'goto' ) {
      if( args == 'vote' ) {
        document.location.href = '<?= HrefLink( LINK_VOTE ); ?>';
      } else if( args == 'home' ) {
        document.location.href = '<?= HrefLink( LINK_HOME_BRATZ ); ?>';
      } else if( args == 'images' ) {
        document.location.href = '<?= HrefLink( LINK_FUN, array( SYS_FORM_FUN_ID => 1 ) ); ?>';
      } else if( args == 'cards' ) {
        document.location.href = '<?= HrefLink( LINK_FUN, array( SYS_FORM_FUN_ID => 2 ) ); ?>';
      } else if( args == 'desktops' ) {
        document.location.href = '<?= HrefLink( LINK_FUN, array( SYS_FORM_FUN_ID => 3 ) ); ?>';
      } else if( args == 'screen savers' ) {
        document.location.href = '<?= HrefLink( LINK_FUN, array( SYS_FORM_FUN_ID => 4 ) ); ?>';
      }

    } else if( command == 'vote' ) {
      open_vote_form( args );
    } else if( command == 'popup' ) {
      if( args == 'info' ) {
        open_info();
      } else if( args == 'regulations' ) {
        open_regulations();
      }
    }
  }

  function open_vote_form( id ) {
    openCenterWindow( '<?= HrefLink( LINK_VOTE_FORM ); ?>?<?= SYS_FORM_VOTE_ID; ?>=' + id, 450, 500, 'no' );
  }

  function open_postcard( id ) {
    openCenterWindow( '<?= HrefLink( LINK_SEND ); ?>?<?= SYS_FORM_CARD_ID; ?>=' + id, 600, 450, 'no' );
  }

  function open_info() {
    openCenterWindow( '<?= HrefLink( LINK_INFO ); ?>', 300, 150, 'yes' );
  }

  function open_regulations() {
    openCenterWindow( '<?= HrefLink( LINK_REGULATIONS ); ?>', 600, 450, 'yes' );
  }

