// JavaScript Document

var totItems = 0;
var TotalPrice = 0;

var theIDs = new Array();

var kidFirstName = new Array();
var kidMiddleName = new Array();
var kidLastName = new Array();
var kidNickName = new Array();
var kidAge = new Array();
var kidGender = new Array();
var kidHomeTown = new Array();
var kidState = new Array();
var kidRelative1 = new Array();
var kidRelative2 = new Array();
var kidRelative3 = new Array();
var kidDedication = new Array();
var kidSentFrom = new Array()



var aa = new Array();
var CurrentItemCost;
var CurrentItemType;
var CurrentBookTitle;
var CurrentBookSize;
var isNav = (window.navigator.appName.toLowerCase().indexOf("netscape")>=0);
var isIE = (window.navigator.appName.toLowerCase().indexOf("microsoft")>=0);

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.documentElement.scrollLeft;
tempY = event.clientY + document.documentElement.scrollTop;
}
else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}  
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}  

return true;
}

//test by bryan 
function ShowCompDIV(id){
	var comp_div = document.getElementById(id);
	
	if(isIE){
		//alert(tempX);
		 tempX = (document.body.clientWidth/2) - 395;
		 
	}else{
		 tempX = (window.innerWidth/2) - 395;
	}
	comp_div.style.top = (tempY - 10)+"px";
	comp_div.style.left = tempX+"px";
	
}

var path = "/";
var lifeTime = 0;
var domain = "";

function setCookie(cookieName,cookieValue)
{
//var exdate=new Date()
//exdate.setDate(exdate.getDate()+expiredays)
//document.cookie=c_name+ "=" +escape(value)+ "; path=/";
//((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
document.cookie = escape( cookieName ) + "=" + escape( cookieValue ) +
 ( lifeTime ? ";expires=" + ( new Date( ( new Date() ).getTime() + ( 1000 * lifeTime ) ) ).toGMTString() : "" ) +
 ( path ? ";path=" + path : "") + ( domain ? ";domain=" + domain : "") +
 ( isSecure ? ";secure" : "");
 alert(document.cookie);
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

function AddBookToOrder2a(CurrentSelectBookTitle) {
	//if (PgLoaded != 1) {
	//	LoadCheck()
	//} else {

	ReloadSwitch = 2
	//CurrentKidID = OrderList.length

	aa = CurrentSelectBookTitle.split("|")

	CurrentItemCost = aa[1]
	CurrentItemType = aa[3]
	CurrentBookTitle = aa[0]
	CurrentBookSize = aa[2]

	//props = "top=0,left=0,width=600,height=550,resizable,scrollbars"
	setTimeout("AddBookToOrder3()",600)

	//}
}
var evt = null;
var clientXY = new Array();
function getClientXY(e){
	//var evt = (evt) ? evt : ((window.event) ? event : null);
	clientXY[0] = e.clientX;
	clientXY[1] = e.clientY;
	//alert(clientXY[0] + " " + clientXY[1]);
	
}

var theX = 0;
var theY = 0;
function getXY(){
	theX = window.innerWidth/2;
	theY = window.innerHeight/2;
	
}


function AddBookToOrder3() {
	var theDiv;
	var theDiv2;
	if (CurrentItemType == "cd") {
		//props = "top=0,left=0,width=540,height=540,resizable,scrollbars"
		//wind = window.open("order.process.cd.htm","addwin",props)
		hideLayer('div1');
		hideLayer('div2');
		hideLayer('div3');
		hideLayer('div4');
		theDiv = document.getElementById("div5");
	} else if (CurrentItemType == "b1") {
		
		hideLayer('div2');
		hideLayer('div3');
		hideLayer('div4');
		theDiv = document.getElementById("div1");
		//wind = window.open("order.process.book1.htm","addwin",props)
		theDiv2 = document.getElementById("bookTitle");
		theDiv2.innerHTML = "<font color=#DF7000>Book Title:</font>"+CurrentBookTitle+ "<font color=#DF7000> (size:</font>"+CurrentBookSize+"<font color=#DF7000>/</font> $"+CurrentItemCost+"<font color=#DF7000>)</font>";
		//getXY();
		//document.Order.ItemType.value = "";
		//document.Order.ItemCost.value = CurrentItemCost;
		//document.Order.BookTitle.value = CurrentBookTitle;
		
	} else if (CurrentItemType == "b2") {
		//wind = window.open("order.process.book2.htm","addwin",props)
		hideLayer('div1');
		hideLayer('div3');
		hideLayer('div4');
		theDiv = document.getElementById("div2");
		theDiv2 = document.getElementById("bookTitle2");
		theDiv2.innerHTML = "<font color=#DF7000>Book Title:</font>"+CurrentBookTitle+ "<font color=#DF7000> (size:</font>"+CurrentBookSize+"<font color=#DF7000>/</font> $"+CurrentItemCost+"<font color=#DF7000>)</font>";
		
	} else if (CurrentItemType == "b3") {
		//wind = window.open("order.process.book3.htm","addwin",props)
		hideLayer('div1');
		hideLayer('div2');
		hideLayer('div4');
		theDiv = document.getElementById('div3');
		theDiv2 = document.getElementById('bookTitle3');
		theDiv2.innerHTML = "<font color=#DF7000>Book Title:</font>"+CurrentBookTitle+ "<font color=#DF7000> (size:</font>"+CurrentBookSize+"<font color=#DF7000>/</font> $"+CurrentItemCost+"<font color=#DF7000>)</font>";
	} else if (CurrentItemType == "b4") {
		hideLayer('div1');
		hideLayer('div2');
		hideLayer('div3');
		//wind = window.open("order.process.book4.htm","addwin",props)
		theDiv = document.getElementById('div4');
		theDiv2 = document.getElementById('bookTitle4');
		theDiv2.innerHTML = "<font color=#DF7000>Book Title:</font>"+CurrentBookTitle+ "<font color=#DF7000> (size:</font>"+CurrentBookSize+"<font color=#DF7000>/</font> $"+CurrentItemCost+"<font color=#DF7000>)</font>";
		
	} else {
		alert("You did not select a CD or Book.\nPlease try again.")
	}
	theDiv.style.left = tempX +'px';
		theDiv.style.top = tempY +'px';
		theDiv.style.visibility = "visible";
}



function checkCart(){

		var p = document.getElementById("theCart");
		p.innerHTML = "<table><tr><td>My Cart &nbsp;<a href=kids.books.cart.php border=0><img border=0 src=images/icn_cart.png></a></td></tr><tr><td><font size=-1>Your cart is empty</font></td></tr><tr><td><font size=-1>&nbsp;</font></td></tr></table>";
	var theTotalItems = getCookie('totalitems');
	if (theTotalItems != ""){
			setCookie('totalitems',0);
	}
}

function buildSQL1_(){
	var d = new Date();
	alert(d.getDate());
	return
}


//function buildSQL1(){
function buildSQL1(book_name, child, book_cd_id, childMiddleName, childLastName,childAge, childHometown, childState, dedication, giverName, friend1, friend2, friend3, gender ){
	var strSQL = "";
	var d = new Date();
	var dT = d.getTime();
	//var entDate = "1111-11-11";
	var month = d.getMonth()+1;
	var entDate = d.getFullYear()+"-"+month +"-"+d.getDate();
	//alert(entDate);
	//var selInd = document.Order.KidState.selectedIndex;
	strSQL = "''|1234567890|"+dT+"|''|"+entDate+"|"+book_name+"|"+book_cd_id+"|''|"+child+"|"+childLastName+"|"+childMiddleName+"|''|"+childAge+"|"+friend1+"|"+friend2+"|"+friend3+"|"+giverName+"|"+dedication+"|"+childHometown+"|"+childState+"|''|''|''|''|''|''|''|''|''|''|''|''|''|"+gender+"";
	//alert(strSQL);
	return strSQL;
	
}

//function buildSQL2(){
function buildSQL2(book_name, child, book_cd_id, childMiddleName, childLastName,childAge, childHometown, childState, dedication, giverName, friend1, friend2, friend3, deliveredBy,hospital,momFirstName,dadFirstName, gender ){
	var strSQL = "";
	var d = new Date();
	var dT = d.getTime();
	
	var month = d.getMonth()+1;
	var entDate = d.getFullYear()+"-"+month +"-"+d.getDate();
	//alert(entDate);
	//var selInd = document.order_names.KidState.selectedIndex;
	var selDOBMonth = document.order_names.DOB_Month.selectedIndex;
	var selDOBDate = document.order_names.DOB_Date.selectedIndex;
	var selDOBYear = document.order_names.DOB_Year.selectedIndex;
	var selBirthHour = document.order_names.BirthHour.selectedIndex;
	var selBirthMinute = document.order_names.BirthMinute.selectedIndex;
	var selBirthAmPm = document.order_names.BirthAmPm.selectedIndex;
	var selBabyWeightPounds = document.order_names.BabyWeightPounds.selectedIndex;
	var selBabyWeightOunce = document.order_names.BabyWeightOunce.selectedIndex;
	var selBabyLength = document.order_names.BabyLength.selectedIndex;
	
	var DOB = document.order_names.DOB_Month.options[selDOBMonth].text +"/"+document.order_names.DOB_Date.options[selDOBDate].text+"/"+document.order_names.DOB_Year[selDOBYear].text;
	var birthTime = document.order_names.BirthHour.options[selBirthHour].text+":"+document.order_names.BirthMinute.options[selBirthMinute].text+":"+document.order_names.BirthAmPm.options[selBirthAmPm].text;
	var birthWeight = document.order_names.BabyWeightPounds.options[selBabyWeightPounds].text+","+document.order_names.BabyWeightOunce.options[selBabyWeightOunce].text;
	strSQL = "''|1234567890|"+dT+"|''|"+entDate+"|"+book_name+"|"+book_cd_id+"|''|"+child+"|"+childLastName+"|"+childMiddleName+"|''|"+childAge+"|"+friend1+"|"+friend2+"|"+friend3+"|"+giverName+"|"+dedication+"|"+childHometown+"|"+childState+"|''|''|''|''|''|"+deliveredBy+"|"+hospital+"|"+momFirstName+"|"+dadFirstName+"|"+DOB+"|"+birthTime+"|"+birthWeight+"|"+document.order_names.BabyLength.options[selBabyLength].text+"|"+gender+"";
	
	
	return strSQL;
	
}

//function buildSQL3(){
function buildSQL3(book_name, child, book_cd_id, childMiddleName, childLastName,childAge, childHometown, childState, dedication, giverName, friend1, friend2, friend3, favoritePlayer, losingTeam, winningTeam,gender ){
	var strSQL = "";
	var d = new Date();
	var dT = d.getTime();
	
	var month = d.getMonth()+1;
	var entDate = d.getFullYear()+"-"+month +"-"+d.getDate();
	//alert(entDate);
	//var selInd = document.Order3.KidState.selectedIndex;
	strSQL = "''|1234567890|"+dT+"|''|"+entDate+"|"+book_name+"|"+book_cd_id+"|''|"+child+"|"+childLastName+"|"+childMiddleName+"|''|"+childAge+"|"+friend1+"|"+friend2+"|"+friend3+"|"+giverName+"|"+dedication+"|"+childHometown+"|"+childState+"|"+favoritePlayer+"|"+losingTeam+"|"+winningTeam+"|''|''|''|''|''|''|''|''|''|''|"+gender+"";
	
	return strSQL;
	
}

//function buildSQL4(book_name,child,book_type){
function buildSQL4(book_name, child, book_cd_id, childMiddleName, childLastName,childAge, childHometown, childState, dedication, giverName, friend1, friend2, friend3, teachersName, schoolName,gender ){
	var strSQL = "";
	var d = new Date();
	var dT = d.getTime();
	
	var month = d.getMonth()+1;
	var entDate = d.getFullYear()+"-"+month +"-"+d.getDate();
	//alert(entDate);
	var selInd = document.Order4.KidState.selectedIndex;
	strSQL = "''|1234567890|"+dT+"|''|"+entDate+"|"+book_name+"|"+book_cd_id+"|''|"+child+"|"+childLastName+"|"+childMiddleName+"|''|"+childAge+"|"+friend1+"|"+friend2+"|"+friend3+"|"+giverName+"|"+dedication+"|"+childHometown+"|"+childState+"|''|''|''|"+teachersName+"|"+schoolName+"|''|''|''|''|''|''|''|''|"+gender+"";
	
	return strSQL;
	
}

function buildSQL5(cd_name, child, ded1, ded2, ded3,gender){
	var strSQL = "";
	var d = new Date();
	var dT = d.getTime();
	
	var month = d.getMonth()+1;
	var entDate = d.getFullYear()+"-"+month +"-"+d.getDate();
	//alert(entDate);
	//var selInd = document.Order4.KidState.selectedIndex;
	strSQL = "''|1234567890|"+dT+"|''|"+entDate+"|"+cd_name+"|cd|"+child+"|"+child+"|''|''|''|''|"+ded1+"|"+ded2+"|"+ded3+"|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|''|"+gender+"";
	
	return strSQL;
	
}

function buildUpdateSQL1(type){
	
	var selInd = document.Order.KidState.selectedIndex;
	strSQL = document.Order.bkType.value+"|"+document.Order.KidFirstName.value+"|"+document.Order.KidLastName.value+"|"+document.Order.KidMiddleName.value+"|"+document.Order.KidNickName.value+"|"+document.Order.KidAge.value+"|"+document.Order.KidFriend1.value+"|"+document.Order.KidFriend2.value+"|"+document.Order.KidFriend3.value+"|"+document.Order.BookSentFrom.value+"|"+document.Order.Dedication.value+"|"+document.Order.KidHomeTown.value+"|"+document.Order.KidState.options[selInd].text;
	//alert(strSQL);
	
	if (type == "b2"){
		var selDOBMonth = document.Order.DOB_Month.selectedIndex;
	var selDOBDate = document.Order.DOB_Date.selectedIndex;
	var selDOBYear = document.Order.DOB_Year.selectedIndex;
	var selBirthHour = document.Order.BirthHour.selectedIndex;
	var selBirthMinute = document.Order.BirthMinute.selectedIndex;
	var selBirthAmPm = document.Order.BirthAmPm.selectedIndex;
	var selBabyWeightPounds = document.Order.BabyWeightPounds.selectedIndex;
	var selBabyWeightOunce = document.Order.BabyWeightOunce.selectedIndex;
	var selBabyLength = document.Order.BabyLength.selectedIndex;
		var DOB = document.Order.DOB_Month.options[selDOBMonth].text +"/"+document.Order.DOB_Date.options[selDOBDate].text+"/"+document.Order.DOB_Year[selDOBYear].text;
	var birthTime = document.Order.BirthHour.options[selBirthHour].text+":"+document.Order.BirthMinute.options[selBirthMinute].text+":"+document.Order.BirthAmPm.options[selBirthAmPm].text;
	var birthWeight = document.Order.BabyWeightPounds.options[selBabyWeightPounds].text+","+document.Order.BabyWeightOunce.options[selBabyWeightOunce].text;
		strSQL += "|"+document.Order.DeliveryPerson.value+"|"+document.Order.Hospital.value+"|"+document.Order.MomFirstName.value+"|"+document.Order.DadFirstName.value+"|"+DOB+"|"+birthTime+"|"+birthWeight+"|"+document.Order.BabyLength.options[selBabyLength].text;
	}else if (type == "b3"){
		strSQL += "|"+document.Order.FavoritePlayer.value+"|"+document.Order.LosingTeam.value+"|"+document.Order.WinningTeam.value;
	}else if (type == "b4"){
		strSQL += "|"+document.Order.Teacher.value+"|"+document.Order.School.value;
	}
	//alert(strSQL);
	
	return strSQL;
	
}

function clearDIV1(){
	document.Order.reset();

}

function clearDIV2(){
	document.Order2.reset();

}

function clearDIV3(){
	document.Order3.reset();

}
function clearDIV4(){
	document.Order4.reset();

}
function clearDIV5(){
	document.Order5.reset();

}

var value = 100;
var glbDIV = "";
var divFadeOut = true;
var intID = "";
function preFadeOut(i){
	glbDIV = i;
	divFadeOut = true;
	intID = setInterval('fadeOut()',200);
	
}
function fadeOut(){
	if (divFadeOut){
	if (value > 0){		
		value -= 20;
		if (navigator.appName.indexOf("Netscape")!=-1){	
		document.getElementById(glbDIV).style.MozOpacity = value/100;
		}else{	
		
				document.getElementById(glbDIV).style.filter = "alpha(opacity='"+value+"')";
				
		}
	}else{
			//alert("here");
			value = 100;
			if (navigator.appName.indexOf("Netscape")!=-1){	
			document.getElementById(glbDIV).style.MozOpacity = value/100;
			}
		else{	
		//document.getElementById(glbDIV).filters.item("DXImageTransform.Microsoft.Alpha").Opacity = value
		document.getElementById(glbDIV).style.filter = "alpha(opacity='"+value+"')";
		}
			divFadeOut = false;
			clearInterval(intID);
			hideLayer(glbDIV);
		} 
	}
	
	
}

function EraseLineKid() {
	document.Order5.LineA.value=""; document.Order5.LineB.value="";
	document.Order5.LineC.value=""
}

function BuildNameList(i) {
	var theReturn = "";
	if (i == 0){
	theReturn = "<select name=\"GirlsName\" size=\"8\">\n" +
	"<option value=\"\">pick matching name</option>\n"
	len = Grl.length
	for (a=0; a<len; a++) { theReturn += "<option value=\"" + Grl[a] + "\">" +
		Grl[a] + "</option>\n" }
	theReturn += "</select>"
	}else{
	theReturn = "<select name=\"BoysName\" size=\"8\">\n" +
	"<option value=\"\">pick matching name</option>\n"
	len = Boy.length
	for (a=0; a<len; a++) { theReturn += "<option value=\"" + Boy[a] + "\">" +
		Boy[a] + "</option>\n" }
	theReturn += "</select>"
	}
	return theReturn;
}
