/*** COPYRIGHT 2000  BY CUTSEY BUSINESS SYSTEMS LTD. - ALL RIGHTS RESERVED  **/
/*** global.js --                                                           **/ 
/*****************************************************************************/
/* 040002 10/23/07 APY- Add file extention check for enlargeImage function.  */
/* 040001 10/10/07 J2 - Added trim, isNumeric, and loadJS functions.         */
/* 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 */
var imageExt   = "jpg,jpeg,gif,png,bmp";                           /* 040002 */

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

var missingImgSmall = new Image();      
var missingImgThumb = new Image();      
var missingImgBig   = new Image();       
var missingImgHide  = new Image();       

/********************v 040001 v********************/

missingImgSmall.src="/missing_small.gif"; 
missingImgThumb.src="/missing_thumb.gif"; 
missingImgBig.src="/missing_large.gif";    
missingImgHide.src="/spacer.gif";    

/********************^ 040001 ^********************/

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
    imgObj.src = missingImgHide.src;
}

/********************^ 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) 
{ 
   var validExt  = false;            /* 040002 */
   var imageType = largeImage;       /* 040002 */   
   imagePath = largeImage;
   maxWidth  = defWidth;
   maxHeight = defHeight;
   img.src   = largeImage;
   
   /******vv 040002 vv******/
   imageType = largeImage.substring(largeImage.lastIndexOf('.')+1, largeImage.length);
   
   if(imageExt.indexOf(imageType)!=-1)
   { validExt = true; }
   
   if(validExt)
   {
      if ( !( (navigator.userAgent.indexOf("Mac") != -1) && (navigator.userAgent.indexOf("MSIE") != -1) ) ) 
      {
         imageWidth = setInterval("setWidth();", 100);
         stopWidth  = setTimeout("clearInterval(imageWidth); clearTimeout(stopWidth); ", 1000);
      }
      else
         openImage();
   }
   else
      var newWindow = window.open(largeImage, "View", "resizable=yes");
   /******^^ 040002 ^^******/      
} 

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 ^********************/

/********************v 040001 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);
}

function loadJS(source,func) {
   if (document.getElementsByTagName("head")[0])
   {
      var vSiteHead = document.getElementsByTagName("head")[0];
      var vScript = document.createElement("script");
      vScript.type = "text/javascript";
      if (func != "")
      {
       vScript.onreadystatechange= function () {
       if (this.readyState == 'loaded') eval(func + "()");
         }
       vScript.onload= eval(func);
      }
      vScript.src = source;
      vSiteHead.appendChild(vScript); 
   }
}

function getTarget(e)
{
  var targ;
	 if (!e) var e = window.event;
	 if (e.target) targ = e.target;
	 else if (e.srcElement) targ = e.srcElement;
	 if (targ && targ.nodeType && targ.nodeType == 3)
		targ = targ.parentNode; 
  return targ;
}


/********************^ 040001 ^********************/


