function initPage()
{
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)
	{
		if (inputs[i].type == "text" && (inputs[i].name == "email" || inputs[i].name == "query"))
		{
			var form = getAncestor(inputs[i], "form");
			if (form)
				form.onsubmit = handleSubmit;

			inputs[i].onfocus = function () {
					if ((this.value != ""))
						this.value = "";
				}
			inputs[i].onblur = function () {
					if (this.value == "" && this.name == "email") this.value = "enter email";
					if (this.value == "" && this.name == "search") this.value = "search STORENAME";
				}	
		}
	}
}

function handleSubmit()
{
	var re = new RegExp('^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$');
	var element = this.elements["email"];
	if (element)
	{
		if (element.value == "")
		{
			alert("Email address is empty!");
			return false;
		}
		else
			return element.value.match(re)
				|| (alert("You have entered incorrect email address!"), false);
	}
	return true;
}

function getAncestor(element, tagName)
{
	var node = element;
	while (node.parentNode && (!node.tagName ||
			(node.tagName.toUpperCase() != tagName.toUpperCase())))
		node = node.parentNode;
	return node;
}



if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent){
	window.attachEvent("onload", initPage);
	}


function goToURL(val)
  {
    if(val!="")
      {
        window.location.href=val;
      }
}

/* PNG HACK FOR IE */
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
         i = i-1
      }
   }
}
/* END HACK */
/* POPUP WINDOW FUNCTION */ 

/*function popup(img,ht,wd){
if(!ht) ht=465;
if(!wd) wd=330;
features = "width= " + wd + ", height=" + ht + ",scrollbars=yes,resizable=yes";
	window.open(img,"Facts",features);
}
*/

function popup(page,ht,wd){
	if(!ht) ht=465;
	if(!wd) wd=330;
	features = "width= " + wd + ", height=" + ht + ",scrollbars=yes,resizable=yes";
		window.open(page,"Facts",features);
}


function dosagePopup(){
	var doseCont = document.getElementById("dosage");
		doseCont.style.display = "block";
		doseCont.style.top = "315px";
		doseCont.style.left = "300px";
	}
function hideDosage(){
	var doseCont = document.getElementById("dosage");
		doseCont.style.display = "none";
}