var html_old ;
var html_old_r ;
var headerHeight=96;
var mouseX;
var mouseY;
var IE = document.all?true:false
var image_shown = false;
var retailer_shown = false;
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  mouseX = tempX
  mouseY = tempY
  return true
}

function isValidEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   }
   return true;
}

function isZip(id) 
{
	var s = document.getElementById(id).value;
     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

     if (!reZip.test(s)) {
          alert("Zip Code Is Not Valid");
          document.getElementById(id).focus();
          return false;
     }
	return true;
}

function over_(id, image, style, right_side)
{
	if(image_shown==false)
	{
		// divide screen size to half, and cast it to integer, substract 32 to get middle point;
		var middle = parseInt(screen.height/2)-72;
//		alert(middle);
		var div = document.getElementById(id);
		var top, left;
		html_old = style;
		if(IE){
			if(mouseY>middle)top='-340';
			else top='18';
			if(right_side==0)
			left = '10';
			else
			left = '-260';
		}else {
			if(mouseY>middle)top='-360';
			else top='5';
			if(right_side==0)
			left='80'
			else
			left='-200'
		}
//		div.innerHTML = '<span style="color:red">'+div.innerHTML+'</span><div style="position:absolute;margin-top:'+top+'px;margin-left:'+left+'px;">'
		div.innerHTML = div.innerHTML+'<div style="position:absolute;margin-top:'+top+'px;margin-left:'+left+'px;">'
		+'<img src = "../images/product_images/MED/'+image+'" ></div>';
		image_shown = true;
		
	}
}

function out_(id)
{
	var div = document.getElementById(id);
	div.innerHTML = html_old;
	image_shown = false;
}

function over_r(id, store, info, right_side)
{
	if(retailer_shown==false)
	{
		// divide screen size to half, and cast it to integer, substract 32 to get middle point;
		var middle = parseInt(screen.height/2)-72;

		var div = document.getElementById(id);
		var top, left;
		html_old_r = store;
		if(IE){
			if(mouseY>middle)top='-155';
			else top='18';
			if(right_side==0)
			left = '10';
			else
			left = '-260';
		}else {
			if(mouseY>middle)top='-170';
			else top='5';
			if(right_side==0)
			left='80'
			else
			left='-200'
		}
		html_old_r = store;
		div.innerHTML = div.innerHTML+'<div class = "retailerinfo" style="margin-top:'+top+'px;margin-left:'+left+'px;">'
										+info+'</div>';
//		alert(div.innerHTML);
		retailer_shown = true;
		
	}
}

function out_r(id)
{
	var div = document.getElementById(id);
	div.innerHTML = html_old_r;
	retailer_shown = false;
}

function isChecked(form)
{
	var checked = false;
	for(i=0;i<form.length; i++)
	{
		ele =document.forms[1].elements[i];
		if(ele.type == "checkbox")
		{
			if(ele.checked==true) {
			checked = true;
			break;
			}
		}
	}
	return checked;
}

function selectCheckBoxes(form, selection){
	for(i=0;i<form.length; i++)
	{
		ele =form.elements[i];
		if(ele.type == "checkbox") ele.checked = selection;
	}
}

function checkEmpty(id, msg)
{
	var ele = document.getElementById(id);
	if(ele.value==''){
		alert(msg);
		ele.focus();
		return false;
	}
	return true;
}

function isInteger(str)
{
	var a=0;
	while(a<str.length)
	{
		if( str.charAt(a)< '0' || str.charAt(a) > '9' )
			return false;
		a++;
	}
	return true;
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function changeColor(id, action){
 	var row = document.getElementById(id);
 	
 	if(action == 2){
		if(row.className == "whiteRow")
		row.style.color="#f7f7f7";
		else
		row.style.color="gray";
	}
	else
	{
		if(row.className == "whiteRow")
		row.style.color="#c0504d";
		else
		row.style.color="#c0504d";
	}
}


function wopen(url, name, w, h, loc, menu, status, toolbar, scroll, resize)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  
  win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location='+loc+', menubar='+menu+', ' +
    'status='+status+', toolbar='+toolbar+', scrollbars='+scroll+', resizable='+resize);
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
}


function showWindowSize()
{
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth-16;
	  winH = window.innerHeight-16;
	  alert('net');
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth-20;
	  winH = document.body.offsetHeight-20;
	  alert('micro');
	 }
	}
	
	alert(winW +', '+winH);
}

function windowOpen(url, name, w,h, scrollable) {
 // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
    myWindow = window.open(url, name,"width=" + w + ",height=" + h+",top=" + wtop +",left=" + wleft + ",screenX=0,screenY=0, scrollbars="+scrollable);
}

function showImage(url, name, w,h, scrollable) {
 // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
    myWindow = window.open(url, name,"width=" + w + ",height=" + h+",top=" + wtop +",left=" + wleft + ",screenX=0,screenY=0, scrollbars="+scrollable);
}




function test_wopen(url, name, w, h, loc, menu, status, toolbar, scroll, resize)
{
  // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w += 32;
  h += 96;
  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  
  win = window.open(url,
    name,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    'location='+loc+', menubar='+menu+', ' +
    'status='+status+', toolbar='+toolbar+', scrollbars='+scroll+', resizable='+resize);
  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
  return win;
}
