// JavaScript Document

function createRequestObjectSendIt(){
  var request_o; //declare the variable to hold the object.
  var browser = navigator.appName; //find the browser name
  if(browser == "Microsoft Internet Explorer"){
    request_o = new ActiveXObject("Microsoft.XMLHTTP");
  }else{
    request_o = new XMLHttpRequest();
  }
  return request_o; //return the object
}


var httpSendIt = createRequestObjectSendIt(); /* The variable http will hold our new XMLHttpRequest object. */
var pages = window.location;
var dh = null;
var dw = null;
var pie = null;
var goods = null;
var where = null;
var ic = null; // Item Color
var pid = null; // Parent ID
var prod_id = null; // product ID

///////////////////////////////////////////////////////
function SendIt_Setup()  {
  ewm_SendIt();
}

function fixDims()  {
  var dh = document.documentElement.clientHeight;
  var dw = document.documentElement.clientWidth;
  var pie = document.getElementById("div_SendIt");
	dhh=dh/2;
  var goods = document.getElementById("goodStuff");
  goods.style.top = (100) + "px";

	pie.style.width = dw + "px";
  pie.style.height = dh + "px";
}
//////////////////////////////////////////////////////////
function showMe(tpid,tic,tprod_id)  {
	pid=tpid;
	ic=tic;
	prod_id=tprod_id;
	fixDims();
  var pie = document.getElementById("div_SendIt");
	pie.style.display = "block";
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

function closeMe()  {
  pie = document.getElementById("div_SendIt");
  pie.style.display = "none";
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
  var dh = null;
  var dw = null;
  var pie = null;
  var goods = null;
}


function ewm_SendIt(){
  httpSendIt.open('get', '/sendit.php', true);
  httpSendIt.onreadystatechange = handle_SendIt;
  httpSendIt.send(null);
	document.ajaxInProgress = true;
}

function handle_SendIt(){
  if(httpSendIt.readyState == 4){ //Finished loading the response
    var response = httpSendIt.responseText;
    document.getElementById('div_SendIt').innerHTML = response;
    document.ajaxInProgress = false;
  }
}


function ewm_SendEmail(type){
	var emailadd = document.getElementById("SendIt").value;
  httpSendIt.open('get', '/sendit.php?action=send&goto='+emailadd+'&type='+type+'&pid='+pid+'&ic='+ic+'&prod_id='+prod_id, true);
  httpSendIt.onreadystatechange = handle_SendEmail;
  httpSendIt.send(null);
	document.ajaxInProgress = true;
}

function handle_SendEmail(){
  if(httpSendIt.readyState == 4){ //Finished loading the response
    var response = httpSendIt.responseText;
    closeMe();
		document.getElementById('div_SendItDone').innerHTML = response;
    document.ajaxInProgress = false;
  }
}

