// JavaScript Document

var xmlHttp
var uemail

function AddOneToCart(useremail, prodid)
{
if (useremail == "")
alert("Please login before adding items to your cart")
else
	{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 return
	 } 
	var url="add_cart.php"
	url=url+"?useremail="+useremail
	url=url+"&qty=1"
	url=url+"&code="+prodid
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged2
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	}

}

function AddToCart(useremail, prodid)
{	
if (useremail == "")
alert("Please login before adding items to your cart")
else
	{
	qty = 1;
	qty = document.getElementById("oqty").value;
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	 {
	 return
	 } 
	var url="add_cart.php"
	url=url+"?useremail="+useremail
	url=url+"&qty="+qty
	url=url+"&code="+prodid
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged2
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	}
}

function RemoveFromCart(useremail, prodid)
{	
alert("Removing Item From Your Cart");	
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="remove_cart.php"
url=url+"?useremail="+useremail
url=url+"&code="+prodid
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged3
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
uemail = useremail;
}

function viewCart(useremail)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="view_cart.php" 
url=url+"?useremail="+useremail
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function updateCart(useremail, prodid, currqty)
{
nqty = document.getElementById(currqty).value;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="change_cart.php" 
url=url+"?useremail="+useremail
url=url+"&prodid="+prodid
url=url+"&qty="+nqty
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged3
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
uemail = useremail
}

function checkOut(useremail)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="select_shipping.php" 
url=url+"?useremail="+useremail
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)	
}

function continuePurchase(useremail, addressno)
{
donation = document.getElementById("donamt").value;		
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="payment_options.php" 
url=url+"?useremail="+useremail
url=url+"&addressno="+addressno
url=url+"&donation="+donation
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)	
}

function showInvoice(useremail, addressno)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="show_invoice.php" 
url=url+"?useremail="+useremail
url=url+"&addressno="+addressno
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)	
}

function selectShipOptions(useremail, addressno)
{
alert("Selecting Shipping Options for "+useremail+" Address: "+addressno);
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="ship_options.php" 
url=url+"?useremail="+useremail
url=url+"&addressno="+addressno
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)	
}

function placeOrder(useremail, addressno)
{
	alert("Placing Order For "+useremail+" - "+addressno);
}

function updateInvoice(useremail, addressno)
{
donation = document.getElementById("donamt").value;	
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="show_invoice.php" 
url=url+"?useremail="+useremail
url=url+"&addressno="+addressno
url=url+"&donation="+donation
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)	
}

function finalInvoice(useremail, addressno, donation)
{
cctype = document.getElementById("cctype").value;	
ccno = document.getElementById("ccno").value;	
ccname = document.getElementById("ccname").value;	
ccmonth = document.getElementById("ccmonth").value;	
ccyear = document.getElementById("ccyear").value;
ccard = document.getElementById("ccard").checked;
dcard = document.getElementById("dcard").checked;
morder = document.getElementById("morder").checked;
check = document.getElementById("check").checked;
if (ccard) paymode = "creditcard"
if (dcard) paymode = "debitcard"
if (morder) paymode = "moneyorder"
if (check) paymode = "check"
comments = document.getElementById("comments").value;
alert("Final Invoice for "+useremail+" Address: "+addressno+" - "+cctype+" - "+ccno+" - "+ccname+" - "+ccmonth+" - "+ccyear+" - "+paymode+" - "+comments+" - "+donation);
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="authorize_order.php" 
url=url+"?useremail="+useremail
url=url+"&addressno="+addressno
url=url+"&donation="+donation
url=url+"&cctype="+cctype
url=url+"&ccno="+ccno
url=url+"&ccname="+ccname
url=url+"&ccmonth="+ccmonth
url=url+"&ccyear="+ccyear
url=url+"&paymode="+paymode
url=url+"&comments="+comments
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)	
document.getElementById("main").innerHTML="<body><h1>Authorising Your Credit Card - Please Wait!</h1></body>";
}

function stateChanged1() 
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
// alert("Result : "+xmlHttp.responseText);
 document.getElementById("main").innerHTML=xmlHttp.responseText;
 document.getElementById("main").scrollTop = 0;
 } 
}

function newShipping(useremail)
{
title = document.getElementById('Title').value;
firstname = document.getElementById('FirstName').value;
mi = document.getElementById('MI').value;
lastname = document.getElementById('LastName').value;
company = document.getElementById('Company').value;
phone = document.getElementById('Phone').value;
street = document.getElementById('Street').value;
city = document.getElementById('City').value;
state = document.getElementById('State').value;
zip = document.getElementById('Zip').value;
country = document.getElementById('Country').value;
alert (title+" "+firstname+" "+mi+" "+lastname+"\n"+company+"\n"+street+"\n"+city+", "+state+" "+zip+"\n"+country+"\n Phone: "+phone);
}

function stateChanged1() 
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
// alert("Result : "+xmlHttp.responseText);
 document.getElementById("main").innerHTML=xmlHttp.responseText;
 document.getElementById("main").scrollTop = 0;

 } 
}

function stateChanged2() 
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("loginbox").innerHTML=xmlHttp.responseText;
 alert("A New Item Has Been Added To Your Cart");
 } 
}

function stateChanged3() 
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("loginbox").innerHTML=xmlHttp.responseText;
 viewCart(uemail);
 alert("Your Cart Contents Have Been Modified");
 } 
}


function newMember()
{
	alert("Enrolling as New Member");
}

function sendPassword()
{
	alert("Sending Password");
}

function mouseOver(item)
{
document.getElementById(item).style.textDecoration="underline";
document.getElementById(item).style.color="blue";
document.getElementById(item).style.cursor="pointer";
}

function mouseOut(item)
{
document.getElementById(item).style.textDecoration="none";
document.getElementById(item).style.color="black";
document.getElementById(item).style.cursor="default";

}

function DoLogin()
{
	email = document.getElementById("email").value;
	pswrd = document.getElementById("password").value;
	alert("Logging in Now with Email: "+email+ " and "+pswrd);
}

function ShowLink(linktype)
{
	document.getElementById(linktype).style.cursor="pointer";
	document.getElementById(linktype).style.textDecoration="underline";
	// find id
	// change color
	// show hand icon
}

function RestoreLink(linktype)
{
	document.getElementById(linktype).style.cursor="default";
	document.getElementById(linktype).style.textDecoration="none";
	// find id
	// change color
	// show normal icon	
}

function GoHome()
{
	window.location.reload();
}

function GoBooks()
{
document.getElementById("main").scrollTop = 0;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="getproducts.php" 
url=url+"?prodtype=B"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}



function GetXmlHttpObject2()
{
var xmlHttp2=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp2=new XMLHttpRequest();
 }
 
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp2;
}


function GoEbooks()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="getproducts.php" 
url=url+"?prodtype=EB"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function GoVideo()
{
document.getElementById("main").scrollTop = 0;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="getproducts.php" 
url=url+"?prodtype=V"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function GoAudio()
{
document.getElementById("main").scrollTop = 0;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="getproducts.php" 
url=url+"?prodtype=A"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function GoSoftware()
{
document.getElementById("main").scrollTop = 0;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="getproducts.php" 
url=url+"?prodtype=SW"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}

function GoCourses()
{
document.getElementById("main").scrollTop = 0;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="getproducts.php" 
url=url+"?prodtype=K"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}


function GoSpecials()
{
document.getElementById("main").scrollTop = 0;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="getproducts.php" 
url=url+"?prodtype=SP"
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)

}

function SearchProducts()
{
	alert("Searching Products");
}

// This will show one product only when the graphic or title is clicked in the product list

function ShowProduct(prodid)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 return
 } 
var url="showproduct.php" 
url=url+"?prodid="+prodid;
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged1
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}


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;
}

