// JavaScript Document

function sendEmail(sendFrom, replyTo, sendTo, sendCC, sendBCC, subjectLine, HTMLBody)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
HTMLBody = HTMLBody.replace("&", "%26");
var url="includes/ajax-sendEmail.asp";
url=url+"?sendFrom="+sendFrom;
url=url+"&replyTo="+replyTo;
url=url+"&sendTo="+sendTo;
url=url+"&sendCC="+sendCC;
url=url+"&sendBCC="+sendBCC;
url=url+"&subjectLine="+subjectLine;
url=url+"&HTMLBody="+HTMLBody;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=emailSent;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function logCourseStats(courseTable, IDField, courseID, fieldToUpdate)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="includes/ajax-logCourseStats.asp";
url=url+"?courseTable="+courseTable;
url=url+"&IDField="+IDField;
url=url+"&courseID="+courseID;
url=url+"&fieldToUpdate="+fieldToUpdate;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=statsLogged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function updateRec(tablename, fieldname, fieldData, idField, idFieldData, isText)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
if (isNaN(fieldData))
	{fieldData = fieldData.replace("&", "%26");}
var url="/shorthorn/includes/updateDB.asp";
url=url+"?tablename="+tablename;
url=url+"&fieldname="+fieldname;
url=url+"&fieldData="+fieldData;
url=url+"&idField="+idField;
url=url+"&idFieldData="+idFieldData;
url=url+"&isText="+isText;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=recordUpdated;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function emailSent() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		//alert(xmlHttp.responseText);
		alert("Email Sent");
	}
}

function statsLogged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		//alert(xmlHttp.responseText);
	}
}

function recordUpdated() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
