var wndLog           = null;
var xmlHttpReq       = null;
var wndPopup         = null;


function doMultiple (c){eval(c);}

function isNumeric (elemValue)
{
  var numericExpression = /^[0-9]+$/;
  return (elemValue.match(numericExpression));
}

function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
  {
    window.onload = func;
  }
  else
  {
    window.onload = function()
    {
      if (oldonload)
        oldonload();
      func();
    }
  }
}

function createDiv(divName, parentalUnitName, beforeSyblingName, flt, clr, overflow, bi, width, height, display, innerHtml)
{
  var oDiv  = document.createElement('<div>');
  var style = oDiv.style;

  oDiv.id   = divName;

  if (flt             != "") style.styleFloat          = style.cssFloat = flt;
  if (clr             != "") style.clear               = clr;
  if (overflow        != "") style.overflow            = overflow;
  if (bi              != "") style.backgroundImage     = "url("+bi+")";
  if (width           != "") style.width               = width;
  if (height          != "") style.height              = height;
  if (display         != "") style.display             = display;
  if (innerHtml       != "") oDiv.innerHTML            = innerHtml;

  if (beforeSyblingName != "")
    $(parentalUnitName).insertBefore(oDiv, $(beforeSyblingName));
  else
    $(parentalUnitName).appendChild(oDiv);
}

function detectIE ()
{
  return (navigator.userAgent.toLowerCase().indexOf("msie") != -1);
}
function detectIE6 ()
{
  return (navigator.userAgent.toLowerCase().indexOf("msie 6") != -1);
}
function detectFF ()
{
  return (navigator.userAgent.toLowerCase().indexOf("firefox") != -1);
}
function detectMac ()
{
  return (navigator.appVersion.toLowerCase().indexOf("mac") != -1);
}



function centerWindow (url, name, w, h, scroll, menu, resizable)
{ 
  // if width or height specified as zero, then use parent's width and height
  if (w == 0) w = getWindowWidth  () - 20;
  if (h == 0) h = getWindowHeight () - 40;

  if (window.screen)
  {
    var chasm     = screen.availWidth;
    var mount     = screen.availHeight;
    var left      = (chasm - w - 10) * .5;
    var top       = (mount - h - 30) * .5;
    
    var winprops  = 'width=' + w + ',height=' + h + ',left=' + left + ',top=' + top + ',scrollbars=' + scroll + ',menubar=' + menu + ',resizable=' + resizable;

    wndPopup = window.open(url, name, winprops);
    
    if(wndPopup == null) {
      alert("You will need to disable your Pop-Up Blocker to view the product details. If you're using Windows, try holding down the CTRL key while clicking the View Details button; Macintosh users should try holding down control 'z' while clicking on the button.");
    }
    else
    
    wndPopup.focus();
  }
}

function centerMinimalWindow (url, name, w, h)
{
  return (centerWindow (url, name, w, h, "no", "no", "no"));
}

function getWindowHeight ()
{
  var height = 680;
  if (navigator.appName=="Netscape")
    height = window.innerHeight;
  else if (navigator.appName.indexOf("Microsoft") != -1)
    height = document.body.offsetHeight;
  return (height);
}

function getWindowWidth ()
{
  var width = 480;
  if (navigator.appName=="Netscape")
    width = window.innerWidth;
  else if (navigator.appName.indexOf("Microsoft") != -1)
    width = document.body.offsetWidth;
  return (width - 6);
}

function swapImages (oldImage, newImage)
{
  $(oldImage).src = eval(newImage + ".src");
}


function logDebug (message)
{
  if (wndLog == null)
    wndLog = window.open ("", "log");
  wndLog.document.write (message + "<br/>");
}


function getParser (xml)
{
  var doc;

  // IE support
  if (window.ActiveXObject)
  {
    doc = new ActiveXObject ("Microsoft.XMLDOM");
    doc.async = "false";
    doc.loadXML (xml);
  }
  // code for Mozilla, Firefox, Opera, etc.
  else
  {
    var parser = new DOMParser ();
    doc = parser.parseFromString (xml,"text/xml");
  }
  return (doc);
}


function getXmlHttpReq ()
{
  if (window.XMLHttpRequest)
  {
    // Mozilla, Safari,...
    xmlHttpReq = new XMLHttpRequest();
    if (xmlHttpReq.overrideMimeType)
      xmlHttpReq.overrideMimeType('text/xml');
  }
  else if (window.ActiveXObject)
  {
    // IE
    try
    {
      xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      try
      {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {
      }
    }
  }
}

function createBookmark()
{
  title = "Olay Spa Discovery";
  url   = "http://www.olayspadiscovery.com";

  if (detectFF())                               // Mozilla Firefox Bookmark
    if (detectMac())
      alert("You need to press Command/Cmd + D to bookmark our site.");
    else
      alert("You need to press CTRL + D to bookmark our site.");
  else
    if (window.external)                        // IE Favorite
      window.external.AddFavorite( url, title);
    else
      alert("In order to bookmark this site, you need to do so manually through your browser.");
}

function autoTab(formName,tabTo)
{
    document.forms[formName].elements[tabTo].focus();
}
  

function clearIt(formName)
{
  eval("document."+formName).srch_query.value = "";
}


function getObject(obj)
{
	var theObj;
	if(document.all)
	{
		if(typeof obj=="string")
		{
			return document.all(obj);
		}
		else
		{
			return obj.style;
		}
	}
	if(document.getElementById)
	{
		if(typeof obj=="string")
		{
			return document.getElementById(obj);
		}
		else
		{
			return obj.style;
		}
	}
	return null;
}
function toCount(txtArea, txtCount, text, maxChars)
{
	var txtAreaObj = getObject(txtArea);
	var txtCountObj = getObject(txtCount);
	var length = maxChars - txtAreaObj.value.length;
	if(length <= 0)
	{
		length = 0;
		text = '<span class="errCharCount">' + text + '</span>';
		txtAreaObj.value = txtAreaObj.value.substr(0,maxChars);
	}
	txtCountObj.innerHTML = text.replace("{NUM}",length);
}
