// JavaScript Document

// Opacity and Fade in script.
// Script copyright (C) 2008 http://www.cryer.co.uk/.
// Script is free to use provided this copyright header is included.
function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var opacity = element.style.opacity * 100;
  var msNow = (new Date()).getTime();
  opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity<0) 
    SetOpacity(element,0)
  else if (opacity>100)
    SetOpacity(element,100)
  else
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",1);
  }
}
function FadeIn(id)
{
  var element=document.getElementById(id);
  SetOpacity(element,0);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",0,100)",1);
   element.style.visibility = 'visible';	
}
function FadeOut(id)
{
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",100,0)",1);
}

function FadeInImage(foregroundID,newImage,map)
{
  var foreground=document.getElementById(foregroundID);
    if (map=="RH")
     foreground.useMap="#RH";
  else
     foreground.useMap="#LH";
 // SetOpacity(foreground,0);
  foreground.src = newImage;
//  if (foreground.timer) window.clearTimeout(foreground.timer); 
 // var startMS = (new Date()).getTime();
 // foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,100)",10); 
}

function FadeInImage2(foregroundID,newImage, map)
{
 
//  document.productImage.src=newImage;

//  alert(map);
  
  var foreground=document.getElementById(foregroundID);
  
  if (map=="RH")
     foreground.useMap="#RH";
  else
     foreground.useMap="#LH";
 // alert("before="+foreground.src);
   SetOpacity(foreground,0);
 //  alert("new="+newImage);
   foreground.src = newImage;
//    alert("after="+foreground.src);
  if (foreground.timer) window.clearTimeout(foreground.timer); 
  var startMS = (new Date()).getTime();
  foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,100)",10); 

}

function FadeInImage_Color(foregroundID,newImage, newColor)
{
 
//  alert(newImage);
  
//  document.productImage.src=newImage;

  var foreground=document.getElementById(foregroundID);
 // alert("before="+foreground.src);
   SetOpacity(foreground,0);
 //  alert("new="+newImage);
   foreground.src = newImage;
//    alert("after="+foreground.src);
  if (foreground.timer) window.clearTimeout(foreground.timer); 
  var startMS = (new Date()).getTime();
  foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "',1000," + startMS + ",0,100)",10); 
// alert(newColor);
    document.color_form.color.style.visibility="visible";
   document.color_form.color.value=newColor;
  
}

function hide_color(){
  document.color_form.color.value="";
  document.color_form.color.style.visibility="hidden";
}

function fan_survey(product, city)
{

 // var action="https://www.chaiexpectations.com/chai/index.php?content=admin&usercode="+document.admin_form.usercode.value;

var w=320, h=150;	
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var message = "testing";
var URL="fan_survey.inc.php"+"?product="+product+"&city="+city;

day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+w+",height="+h+",left ="+left+",top = "+top+"');");

  return(true);
  }
 
 function raffle()
{

 // var action="https://www.chaiexpectations.com/chai/index.php?content=admin&usercode="+document.admin_form.usercode.value;

var w=320, h=350;	
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var message = "testing";
var URL="raffle.inc.php";
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+w+",height="+h+",left ="+left+",top = "+top+"');");

  return(true);
  }

function popup_window(window_type, content, w, h, sport, title)
{

 // var action="https://www.chaiexpectations.com/chai/index.php?content=admin&usercode="+document.admin_form.usercode.value;
	
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);


var content="popup_window.inc.php?content="+content+"&window_type="+window_type+"&width="+w+"&height="+h+"&sport="+sport+"&title="+title;
w=w*1.05; h=h*1.05;
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(content, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+w+",height="+h+",left ="+left+",top = "+top+"');");

  return(true);
  }
  
  function popup_details(window_type, content, w, h, sport, title, cartid)
{
	
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);


var content="popup_window.inc.php?content="+content+"&window_type="+window_type+"&width="+w+"&height="+h+"&sport="+sport+"&title="+title+"&cartid="+cartid;
w=w*1.15; h=h*1.15;
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(content, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+w+",height="+h+",left ="+left+",top = "+top+"');");

  return(true);
  }




