/*** COPYRIGHT 2000  BY CUTSEY BUSINESS SYSTEMS LTD. - ALL RIGHTS RESERVED  **/
/*** global.js -- Global Functions for Web Sites                            **/ 
/*****************************************************************************/
/* E010000 01/20/10 PMS - Made Temp Custom                                   */
/*                     - Updated getCurrency function - unmarked             */
/*****************************************************************************/
/* 050000 04/03/09 JB - Update global.js from the web server.                */
/* 040000 04/23/02 JZ - Added missing image functionality.                   */
/*****************************************************************************/
/* 030100 10/15/01 JZ - Fix enlarge function for Mac IE 5.                   */
/* 030000 09/20/01 JZ - Added enlarge view functionality.                    */
/*****************************************************************************/
/* 020000 08/23/01 JZ - Wip'd to correct version problem.                    */
/*                    - Added blank function.                                */
/* 010102 12/12/00 IAB- Added functions for On Hold Alert                    */
/* 010100 08/22/00 JZ - Added a progress bar function with no time out.      */
/*****************************************************************************/

// This is a .js file that contains several commonly used javascript functions

var img        = new Image();                                      /* 030000 */
var maxWidth   = 0;                                                /* 030000 */
var maxHeight  = 0;                                                /* 030000 */
var imagePath  = "";                                               /* 030000 */

/********************v 040000 v********************/

var missingImgSmall = new Image();      
var missingImgThumb = new Image();      
var missingImgBig   = new Image();       
var missingImgSwatch  = new Image();                               /* 050000 */

/********************v 050000 v********************/

missingImgSmall.src="/missing_small.gif"; 
missingImgThumb.src="/missing_thumb.gif"; 
missingImgBig.src="/missing_large.gif";    
missingImgSwatch.src="/missing_swatch.gif";                        /* 050000 */

/********************^ 050000 ^********************/

// xp_progressbar
// Copyright 2004 Brian Gosselin of ScriptAsylum.com
//
// v1.0 - Initial release
// v1.1 - Added ability to pause the scrolling action (requires you to assign
//        the bar to a unique arbitrary variable).
//      - Added ability to specify an action to perform after a x amount of
//      - bar scrolls. This requires two added arguments.
// v1.2 - Added ability to hide/show each bar (requires you to assign the bar
//        to a unique arbitrary variable).

// var xyz = createBar(
// total_width,
// total_height,
// background_color,
// border_width,
// border_color,
// block_color,
// scroll_speed,
// block_count,
// scroll_count,
// action_to_perform_after_scrolled_n_times
// )

var w3c=(document.getElementById)?true:false;
var ie=(document.all)?true:false;
var N=-1;

function createBar(w,h,bgc,brdW,brdC,blkC,speed,blocks,count,action){
if(ie||w3c){
var t='<div id="_xpbar'+(++N)+'" style="visibility:visible; position:relative; overflow:hidden; width:'+w+'px; height:'+h+'px; background-color:'+bgc+'; border-color:'+brdC+'; border-width:'+brdW+'px; border-style:solid; font-size:1px;">';
t+='<span id="blocks'+N+'" style="left:-'+(h*2+1)+'px; position:absolute; font-size:1px">';
for(i=0;i<blocks;i++){
t+='<span style="background-color:'+blkC+'; left:-'+((h*i)+i)+'px; font-size:1px; position:absolute; width:'+h+'px; height:'+h+'px; '
t+=(ie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100);
t+='"></span>';
}
t+='</span></div>';

document.getElementById("procDiv").innerHTML = t; 
/*
document.write(t);
*/
var bA=(ie)?document.all['blocks'+N]:document.getElementById('blocks'+N);
bA.bar=(ie)?document.all['_xpbar'+N]:document.getElementById('_xpbar'+N);
bA.blocks=blocks;
bA.N=N;
bA.w=w;
bA.h=h;
bA.speed=speed;
bA.ctr=0;
bA.count=count;
bA.action=action;
bA.togglePause=togglePause;
bA.showBar=function(){
this.bar.style.visibility="visible";
}
bA.hideBar=function(){
this.bar.style.visibility="hidden";
}
bA.tid=setInterval('startBar('+N+')',speed);
return bA;
}}

function startBar(bn){
var t=(ie)?document.all['blocks'+bn]:document.getElementById('blocks'+bn);
if(parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w){
t.style.left=-(t.h*2+1)+'px';
t.ctr++;
if(t.ctr>=t.count){
eval(t.action);
t.ctr=0;
}}else t.style.left=(parseInt(t.style.left)+t.h+1)+'px';
}

function togglePause(){
if(this.tid==0){
this.tid=setInterval('startBar('+this.N+')',this.speed);
}else{
clearInterval(this.tid);
this.tid=0;
}}

function togglePause(){
if(this.tid==0){
this.tid=setInterval('startBar('+this.N+')',this.speed);
}else{
clearInterval(this.tid);
this.tid=0;
}}


/********************^ 050000 ^********************/

function ImageError(imgObj,size)
{
 if (size == "small")
    imgObj.src = missingImgSmall.src;
 else
 if (size == "thumb")
    imgObj.src = missingImgThumb.src;
 else
 if (size == "large")
    imgObj.src = missingImgBig.src;
 else
 if (size == "swatch")
    imgObj.src = missingImgSwatch.src;                             /* 050000 */
}

/********************^ 040000 ^********************/

function centreMe(jwindow, height, width) 
{ 
   var screenHeight = screen.height; 
   var screenWidth  = screen.width; 
   var topLeftx     = Math.round( (screenWidth - width)/2 ); 
   var topLefty     = Math.round( (screenHeight - height)/2 ); 
   jwindow.moveTo(topLeftx, topLefty); 
} 

function status_write(msg) 
{
   window.status = msg;
   return true;
}

/********************v 020000 v********************/

function blank()                       
{                                     
   return "<html></html>";           
}

/********************^ 020000 ^********************/

function setCookie(name, value, expires, path, domain, secure) 
{
   document.cookie = name + "=" + escape(value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "") +
                     ((domain) ? "; domain=" + domain : "") +
                     ((secure) ? "; secure" : "" );
}

function getCookie( label ) 
{ 
   var labelLen = label.length; 
   var cLen = document.cookie.length; 
   var i = 0; 
   var cEnd; 
   while ( i < cLen ) 
   { 
      var j = i + labelLen; 
      if ( document.cookie.substring(i,j) == label ) 
      { 
         cEnd = document.cookie.indexOf(";", j); 
         if ( cEnd == -1 ) 
         { 
            cEnd = document.cookie.length; 
         } 
         return unescape(document.cookie.substring(j + 1,cEnd)); 
      } 
      i++; 
   } 
   return ""; 
} 

function deleteCookie( name, path, domain )
{
   if ( getCookie(name) )
   {
      document.cookie = name + "=" +
                        ((path) ? "; path=" + path : "") +
                        ((domain) ? "; domain=" + domain : "") +
                        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
}

var clickFlag = false;
var onhold = false;                                               /* 010102 */
var OnHoldWindow = null;                                          /* 010102 */

function getClickFlag()
{
   return clickFlag;
}

function checkClickFlag(vWindow)
{
   var isWindow = vWindow;
   if ( (!getClickFlag()) && (!onhold) )
   {
      clickFlag = true;
      brokenHref();
      if ( isWindow != "YES" )
      {
         runProgressBar();
      }
      return true;
   }
   else
   {
     if (OnHoldWindow != null)                                     /* 010102 */
         OnHoldWindow.focus();                                     /* 010102 */
      return false;
   }
}

/**************** 010100 ******************/
function checkClickFlagNoTimeout(vWindow)
{
   var isWindow = vWindow;
   if ( !getClickFlag() )
   {
      clickFlag = true;
      /* removed call to brokenHref() */
      if ( isWindow != "YES" )
      {
         runProgressBar();
      }
      return true;
   }
   else
   {
      return false;
   }
}
/****************^ 010100 ^******************/

var errorFlag;
function brokenHref()
{
   errorFlag = setTimeout("clickFlag = false;",10000);
}

// progress bar stuff below 

var i = 0;
var progressBar;
var goForward = true;

function runProgressBar() 
{
   i         = 0;
   goForward = true;

   if ( navigator.appName != "Netscape" )
   {
      for (var j=1; j<=50; j++)
      {
         eval("menu.document.all.cell_" + j + ".style.background=\"white\"");
      }
      eval("menu.document.all.progress.style.visibility=\"visible\"");
   
      progressBar = setInterval("if ( getClickFlag() ) {changeColor();} else {clearInterval(progressBar); eval(  \"menu.document.all.progress.style.visibility='hidden'\"  );}",5);
   }
}

function changeColor() 
{
   if ( goForward )
   {
      i++;
      if ( i > 50 )
      {
         i = 50;
         goForward = false;
         for (var j=1; j<=50; j++)
         {
            eval("menu.document.all.cell_" + j + ".style.background=\"white\"");
         }
      }
   }
   else
   {
      i--;
      if ( i < 1 )
      {
         i = 1;
         goForward = true;
         for (var j=1; j<=50; j++)
         {
            eval("menu.document.all.cell_" + j + ".style.background=\"white\"");
         }
      }

   }   
   eval("menu.document.all.cell_" + i + ".style.background=\"#cccc99\"");
}

/********************v 030000 v********************/

function enlarge(defWidth, defHeight, largeImage) 
{ 
   imagePath = largeImage;
   maxWidth  = defWidth;
   maxHeight = defHeight;
   img.src   = largeImage;

   if ( !( (navigator.userAgent.indexOf("Mac") != -1) && (navigator.userAgent.indexOf("MSIE") != -1) ) ) 
   {
      imageWidth = setInterval("setWidth();", 100);
      stopWidth  = setTimeout("clearInterval(imageWidth); clearTimeout(stopWidth); ", 1000);
   }
   else
      openImage();
} 

function setWidth()
{
   if ( img.width != 0 )
   {
      clearInterval(imageWidth);
      clearTimeout(stopWidth);
      openImage();
   }

   if ( (navigator.userAgent.indexOf("Mac") != -1) && (navigator.userAgent.indexOf("MSIE") != -1)) 
      openImage();
}

function openImage()
{
   if ( imagePath != "" ) 
   { 
      if ( (navigator.userAgent.indexOf("Mac") != -1) && (navigator.userAgent.indexOf("MSIE") != -1)) 
         var large = window.open("", "Enlarge", "width=" + maxWidth + ",height=" + maxHeight + ",resizable=yes");  
      else 
         var large = window.open("", "Enlarge", "width=" + img.width + ",height=" + img.height + ",resizable=yes");  

      if ( large != null )    
      { 
         large.document.open();
         large.document.writeln('<html>'); 
         large.document.writeln('<head>'); 
         large.document.writeln('<title>Enlarged View</title>'); 
         large.document.writeln('</head>'); 
         large.document.writeln('<BODY bgcolor="#FFFFFF" marginheight="0" marginwidth="0" leftmargin="0" topmargin="0" bottommargin="0">'); 
         large.document.write('<img src="" name="largepic" border="0"'); 
                              
         if ( img.width != 0 && img.width != 1 && img.width != null ) /* 030100 */
            large.document.write(' width="' + img.width + '"');

         if ( img.height != 0 && img.height != 1 && img.height != null) /* 030100 */
            large.document.write(' height="' + img.height + '"');
         
         large.document.write('>');
         large.document.writeln('</body>'); 
         large.document.writeln('</html>');           
         large.document.close();
         large.document.largepic.src = imagePath;
         large.focus();  
      } 
   } 
}

/********************^ 030000 ^********************/

/** APY 4/23/07 - update header shopping bag **/
function set_cart_qty(vNumItems) {
  var strQyt;
  strQyt = vNumItems;
  if(vNumItems == 1) {
    strQyt = strQyt + " item";
  } else {
    strQyt = strQyt + " items";
  }
  if (top.document.getElementById("cartItems"))
  {
    top.document.getElementById("cartItems").innerHTML = strQyt;
  }
}
/** end APY **/

/********************v JJS v********************/
function ltrim (s) {
  return s.replace( /^\s*/, "" );
}

function rtrim (s) {
   return s.replace( /\s*$/, "" );
}

function trim(s) {
   var temp = s;
   return temp.replace(/^\s+/,'').replace(/\s+$/,'');
}

function echeck(str) {
  var emailRegxp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if(str.match(emailRegxp)){
		  return true;
		}else{
		  return false;
		}
}

function isNumeric(inNum) {	
	//CHECK FOR NUMBERS
	//ALLOWS -'s
	var x=inNum
	var anum=/(\-)|(^\d+$)|(^\d+\.\d+$)/
	if (anum.test(x))
		testresult=true;
	else{
		testresult=false;
	}
	return (testresult);
}
/********************^ JJS ^********************/
/******v APY 01/03/08 v*****/
function getCurrency(vAmt,vCurrency)
{
  var vSymbol = "";
  var vReturnAmt = vAmt.toString().replace(",","");
  var vReturnAmt = parseFloat(vReturnAmt).toFixed(2);
  var vReturn = "";

  switch(vCurrency)
  {
    case "CAD":
       vSymbol = "$";
       break;
    case "CA":
       vSymbol = "$";
       break;
    case "USD":
       vSymbol = "$";
       break;
    case "US":
       vSymbol = "$";
       break;
    case "USD":
       vSymbol = "$";
       break;
    case "EUR":
       vSymbol = "&euro;";
       break;
    case "GBP":
       vSymbol = "&pound;";
       break;
  }
  if(vSymbol == "")
    vReturn = vReturnAmt + " " + vCurrency.toUpperCase();
  else {
    if (clientLang.toUpperCase() == 'FR-CA' ) {
      vReturn = vReturnAmt.replace(","," ").replace(".",",") + " " + vSymbol;
      }
    else {
      vReturn = vSymbol + vReturnAmt;
      }
   }
   return vReturn;
} 
/******^ APY 01/03/08 ^*****/

/* vv 050000 jb vv */
function isDate(dateStr) {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
alert("Please enter date as either mm/dd/yyyy or use the calendar.");
return false;
}

month = matchArray[1]; // p@rse date into variables
day = matchArray[3];
year = matchArray[5];

if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}

if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn`t have 31 days!")
return false;
}

if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
alert("February " + year + " doesn`t have " + day + " days!");
return false;
}
}
return true; // date is valid
}
/* ^^ 050000 ^^ */

function findPosX(obj)
 {
  var curleft = 0;
  if(obj.offsetParent)
  while(1)
  {
   curleft += obj.offsetLeft;
  if(!obj.offsetParent)
    break;
  obj = obj.offsetParent;
  }
 else if(obj.x)
  curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
 var curtop = 0;
 if(obj.offsetParent)
 while(1)
 {
  curtop += obj.offsetTop;
  if(!obj.offsetParent)
    break;
  obj = obj.offsetParent;
  }
  else if(obj.y)
    curtop += obj.y;
  return curtop;
}

function checkBlank(vField)
{
     vField.value = rtrim(vField.value);
     vField.value = ltrim(vField.value);
 if (vField.value.length <= 0) return true;
 else return false;
}

