/*

  Procyte - Global Javascript Code

  Author: Mark Ryan - Extractable Solutions
  Contact: mryan@extractable.com
  Date: 01-07-02

  Version: 1.0

*/

//-----------------------------------------------
// initial executed code
//-----------------------------------------------

// execute on events
/*
onerror = handleErrors
onLoad = setTimeout("preLoadem()",1000);
*/
//onUnload = stopTimer();

// preload images array
var pImg = new Array();
pImg[0] = 'nav';

// preload image exclude
var eImg = new Array();
eImg[0] = 'navline.gif';


//------------------------------------------------
// include javascript libraries
//------------------------------------------------

document.write('<script language="JavaScript1.2" src="/common/js/lib/breadcrumb.js" type="text/javascript"></script>');
document.write('<script language="JavaScript1.2" src="/common/js/lib/breadcrumb_spa.js" type="text/javascript"></script>');
document.write('<script language="JavaScript1.2" src="/common/js/lib/base_functions.js" type="text/javascript"></script>');
document.write('<script language="JavaScript1.2" src="/common/js/lib/validation.js" type="text/javascript"></script>');
document.write('<script language="JavaScript1.2" src="/common/js/lib/array_ext.js" type="text/javascript"></script>');
document.write('<script language="JavaScript1.2" src="/common/js/lib/browser.js" type="text/javascript"></script>');


//-------------------------------------------------
// begin site specific javascript functions
//-------------------------------------------------

function preLoadem()
{
	if(document.images.length!=0){

	  // switchImg contains the rollovered image that will
	  // be preloaded
	  var switchImg = "_f2.gif";
	  var re = /\.gif$/i;
	  var ia = new Array();
	  var d = document.images;
	  if(d){
	    for(i=0;i<d.length;i++)
	    {
	      for(z=0;z<pImg.length;z++)
	      {
	        var is = d[i].src.split('/');
	        if(is[is.length-1].indexOf(pImg[z])!=-1)
	        {
	          // make sure not part of the exclude array
	          var preloadTest = true;
	          for(n=0;n<eImg.length;n++)
	          {
	            if(is[is.length-1]==eImg[n])preloadTest = false;
	          }
	          var testSwitch = (is[is.length-1].indexOf(switchImg)==-1);
	          if(preloadTest&&testSwitch)
	          {
	            ia[i] = new Image();
	            ia[i].src = d[i].src.replace(re,switchImg);
	          }
	        }
	      }
	    }
	  }

	}else{
	  preLoadem();
	  // begin recursive loop
	}
}

function productNav()
{

  var str = '<br><br>>> ';

  if(GetCookie("prodMenu")=="category"){

    if(detectDir("/skincare")){
      str += '<a href="/products/category/skincare/default.shtml">Return to Skin Care Menu</a>';
    }else if(detectDir("/suncare")){
      str += '<a href="/products/category/suncare/default.shtml">Return to Sun Care Menu</a>';
    }else if(detectDir("/postskincare")){
      str += '<a href="/products/category/postskincare/default.shtml">Return to Post Procedure Skin Care Menu</a>';
    }else if(detectDir("/postwoundcare")){
      str += '<a href="/products/category/postwoundcare/default.shtml">Return to Hair Transplant Care Menu</a>';
    }else if(detectDir("/haircare")){
      str += '<a href="/products/category/haircare/default.shtml">Return to Hair Care Menu</a>';
    }else if(detectDir("/skin_care")){
      str += '<a href="/spa/products/category/skin_care/default.shtml">Return to Skin Care Menu</a>';
    }else if(detectDir("/sun_protection")){
      str += '<a href="/spa/products/category/sun_protection/default.shtml">Return to Sun Protection Menu</a>';
    }else if(detectDir("/hair_care")){
      str += '<a href="/spa/products/category/hair_care/default.shtml">Return to Hair Care Menu</a>';
    }

  }else if(GetCookie("prodMenu")=="brand"){

    if(detectDir("/neova")){
      str += '<a href="/products/brand/neova/default.shtml">Return to Neova&reg; Menu</a>';
    }else if(detectDir("/shm")){
      str += '<a href="/products/brand/shm/default.shtml">Return to Classic Skin Care Menu</a>';
    }else if(detectDir("/asp")){
      str += '<a href="/products/brand/asp/default.shtml">Return to Advanced Sun Protection Menu</a>';
    }else if(detectDir("/complex")){
      str += '<a href="/products/brand/complex/default.shtml">Return to Complex Cu<sub>3</sub>&reg; Menu</a>';
    }else if(detectDir("/tricomin")){
      str += '<a href="/products/brand/tricomin/default.shtml">Return to Tricomin&reg; Menu</a>';
    }else if(detectDir("/graftcyte")){
      str += '<a href="/products/brand/graftcyte/default.shtml">Return to GraftCyte&reg; Menu</a>';
    }else if(detectDir("/cutanix")){
      str += '<a href="/products/brand/cutanix/default.shtml">Return to Cutanix&reg; Menu</a>';
    }
  }else{

    str += '<a href="/products/default.shtml">Return to Products Menu</a>';

  }

  document.write(str);

}

function recommendedNav(arr)
{

	var myDir = new String();
	var str = new String();

	if(detectDir("/category")){

	  // cycle through possible categories
	  if(detectDir("/haircare")){
		myDir = 'category/haircare';
	  }else if(detectDir("/postskincare")){
		myDir = 'category/postskincare';
	  }else if(detectDir("/postwoundcare")){
		myDir = 'category/postwoundcare';
	  }else if(detectDir("/skincare")){
	    myDir = 'category/skincare';
	  }else if(detectDir("/suncare")){
	    myDir = 'category/suncare';
	  }else if(detectDir("/veterinary")){
	    myDir = 'category/veterinary';
	  }else if(detectDir("/woundcare")){
	    myDir = 'category/woundcare';
	  }

	}else if(detectDir("/brand")){

	  // cycle through possible brands
	  if(detectDir("/asp")){
		myDir = 'brand/asp';
	  }else if(detectDir("/complex")){
		myDir = 'brand/complex';
	  }else if(detectDir("/graftcyte")){
	    myDir = 'brand/graftcyte';
	  }else if(detectDir("/neova")){
		myDir = 'brand/neova';
	  }else if(detectDir("/shm")){
		myDir = 'brand/shm';
	  }else if(detectDir("/tricomin")){
		myDir = 'brand/tricomin';
	  }else if(detectDir("/cutanix")){
		myDir = 'brand/cutanix';
	  }

	}

  str += '<ul>\n';
  for(i=0;i<arr.length;i++){
	  str += '<li><a href="/products/';
	  if(detectDir("/category")){
		str += 'category/'+ arr[i][2] +'/';
	  }else{
	    str += myDir+'/';
	  }
	  str += arr[i][1]+'">';
	  str += arr[i][0];
	  str += '</a></li>';
  }
  str += '</ul>\n';

  document.write(str);

}



//----------------------------------------
// begin new generic functions
//----------------------------------------

function rollOver(image)
{
  var re = /\.gif$/i;
  var str = image.src;
  if(str.indexOf("_f2.gif")==-1)
  {
    str = str.replace(re,"_f2.gif");
    image.src = str;
    document.wasRolled = false;
  }else{
    document.wasRolled = str.toString();
  }
}

function rollOut(image)
{
  var re = /\_f2.gif$/i;
  var str = image.src;
  if(str.toString().indexOf(document.wasRolled)==-1)
  {
    str = str.replace(re,".gif");
    image.src = str;
  }
}

function detectDir(dir)
{
  var urlPath = window.location.href;
  if(urlPath.indexOf(dir)!=-1){return true;}else{return false;}
}

function calculate()
{
	if (!document.fileSize)
	{
		alert('This script does not work in your browser.');
		return;
	}
	var size = (document.fileSize)*1;
	var y = document.images;
	var imglength = 0;
	for (i=0;i<y.length;i++)
	{
		imglength += (y[i].fileSize)*1;
	}
	var total = size + imglength;
	var writestring = 'File size HTML: ' + size;
	writestring += '\nFile size images: ' + imglength;
	writestring += '\nTotal file size: ' + total;
	if (total > 40000 && total < 70000) writestring += "\nFile is average corporate size!";
	if (total < 40000) writestring += "\nFile is very optimized!";
	if (total > 70000) writestring += "\nFile is too large!";
	alert(writestring);
}

function handleErrors(errorMessage, url, line)
{
/*
  if(!isMSIE())
  {
   var msg = null;
   msg = "We're sorry but there was an error on this page.\n\n";
   msg += "This page may not display properly,\n";
   msg += "if this error continues please contact us.\n\n";
   msg += "Click OK to continue.\n\n";
   msg += "Error message: " + errorMessage + "\n";
   msg += "URL: " + url + "\n";
   msg += "Line #: " + line;
   alert(msg);
   return true
  }
*/
}

function startTimer()
{
  var pageOpen = new Date();
}

function stopTimer()
{
  var pageClose = new Date();
  var minutes = (pageClose.getMinutes() - pageOpen.getMinutes());
  var seconds = (pageClose.getSeconds() - pageOpen.getSeconds());
  var time = (seconds + (minutes * 60));
  // insert code that writes cookie with time and page
  // dynamic code can then log this and you know the clients
  // spent time on particular pages
}

