function loadapp(what,where,selected) {
xmlHttpnew=createRequest();

var bookcover = get_cookie ( "bookcover" ); 
var bookpages = get_cookie ( "bookpages" ); 
//alert(bookcover + bookpages);

if (selected=="start"){
document.cookie = "bookedit=";
document.cookie = "bookcover=";
document.cookie = "bookpages=";
document.getElementById("start").className = "app1-s";
document.getElementById("wiz").style.display = 'none';
document.getElementById("cus").style.display = 'none';
document.getElementById("cov").style.display = 'none';
document.getElementById("pre").style.display = 'none';
}else{
document.getElementById("wiz").style.display = 'block';
document.getElementById("cus").style.display = 'block';
document.getElementById("cov").style.display = 'block';
document.getElementById("pre").style.display = 'block';
document.getElementById("start").className = "app1";
}
if (selected=="wiz"){
document.getElementById("wiz").className = "app2-s";
}else{
document.getElementById("wiz").className = "app2";
}
if (selected=="cus"){
document.getElementById("cus").className = "app3-s";
//alert(selected);
}else{
document.getElementById("cus").className = "app3";
}
if (selected=="cov"){
document.getElementById("cov").className = "app4-s";
}else{
document.getElementById("cov").className = "app4";
}
if (selected=="pre"){
document.getElementById("pre").className = "app5-s";
}else{
document.getElementById("pre").className = "app5";
}

document.cookie = "what-a=" + what;
document.cookie = "where-a=" + where;
document.cookie = "selected-a=" + selected;


	what=what+"&sid="+Math.random();
	document.getElementById("application").innerHTML ="<table width=100% height=575px bgcolor=#ffffff align=center valign=center><tr><td align=center style='color:#6b0f0f;font-size:20px;'><img src=./images/loading-1.gif></td></tr></table>";


	xmlHttpnew.onreadystatechange=statechangedapp;
	xmlHttpnew.open("GET",what,true);
	xmlHttpnew.send(null);

}

function done(what,where,selected) {

var bookcover = get_cookie ( "bookcover" ); 
var bookpages = get_cookie ( "bookpages" ); 
//alert(bookcover + bookpages);

if (selected=="start"){
//document.cookie = "bookedit=";
document.cookie = "bookcover=";
document.cookie = "bookpages=";
document.getElementById("start").className = "app1-s";
document.getElementById("wiz").style.display = 'none';
document.getElementById("cus").style.display = 'none';
document.getElementById("cov").style.display = 'none';
document.getElementById("pre").style.display = 'none';
}else{
document.getElementById("wiz").style.display = 'block';
document.getElementById("cus").style.display = 'block';
document.getElementById("cov").style.display = 'block';
document.getElementById("pre").style.display = 'block';
document.getElementById("start").className = "app1";
}
if (selected=="wiz"){
document.getElementById("wiz").className = "app2-s";
}else{
document.getElementById("wiz").className = "app2";
}
if (selected=="cus"){
document.getElementById("cus").className = "app3-s";
//alert(selected);
}else{
document.getElementById("cus").className = "app3";
}
if (selected=="cov"){
document.getElementById("cov").className = "app4-s";
}else{
document.getElementById("cov").className = "app4";
}
if (selected=="pre"){
document.getElementById("pre").className = "app5-s";
}else{
document.getElementById("pre").className = "app5";
}

document.cookie = "what-a=" + what;
document.cookie = "where-a=" + where;
document.cookie = "selected-a=" + selected;
finish();

}

function statechangedapp(){
	if (xmlHttpnew.readyState==4){
	test=document.getElementById("application").innerHTML=xmlHttpnew.responseText;
	//alert(test);
	document.getElementById("application").innerHTML=xmlHttpnew.responseText;
	var loadwhat = get_cookie ( "selected-a" );
	//alert(loadwhat);
		if (loadwhat=="start"){
			document.cookie = "bookedit=";
			document.cookie = "bookcover=";
			document.cookie = "bookpages=";
			loadtab('./mybook-new.php?page=2','displaycontent','mybook','editmy','orders');
		}if (loadwhat=="wiz"){
			showtab('Activities','Physical','Qualities','Attributes','coupons','act','phy','qua','att','cou');
		}if (loadwhat=="pre"){

		var bid = get_cookie ( "bookedit" );
		var url="preview.php?bookId="+bid;
		window.location.href = url;	
		
		}if (loadwhat=="cov"){		
			var t=document.coverform.covertype.value;
			var id=document.coverform.coverId.value;
			var p=document.coverform.price.value;
			var title=document.coverform.bookname.value;
			var where='preview';
			
//			alert(t);
			
			if (id==''){
			var t="1";
			var id="16";
			var p='39.95';
			}
			
			if (t==2){
			showcovertab('displaysoft','displayhard','soft','hard');
			coverselect(where,t,id,'24.95',title);
			}else{
			showcovertab('displayhard','displaysoft','hard','soft');
			coverselect(where,t,id,'39.95',title);
		}	
		}
	}
}

function loadtab(what,where,tab1,tab2,tab3) {
xmlHttpnew=createRequest();
//alert(what);
document.getElementById(tab1).className = "selected";
document.getElementById(tab2).className = "detail";
document.getElementById(tab3).className = "detail";
 
document.cookie = "1=" + what;
document.cookie = "2=" + where;
document.cookie = "3=" + tab1;
document.cookie = "4=" + tab2;
document.cookie = "5=" + tab3; 
 
what=what+"&sid="+Math.random();


document.cookie = "location=" + where;
var display = get_cookie ( "location" ); 
document.getElementById(display).innerHTML ="<table width=100% height=300px bgcolor=#6b0f0f align=center valign=center><tr><td align=center style='color:white;font-size:20px;'>Loading....</td></tr></table>";

xmlHttpnew.onreadystatechange=statechangednew;
xmlHttpnew.open("GET",what,true);
xmlHttpnew.send(null);
}

function showtab(show,no1,no2,no3,no4,tab1,tab2,tab3,tab4,tab5) {
//alert(what);
var ws = document.forms["info"].wsize.value;
document.getElementById("selected").style.width = ws;

var pcount = document.forms["info"].pc.value;
document.getElementById("pagecount").innerHTML ="<p style='color:red; padding:0 0 0 10px'><b>"+pcount+"</b></p>";

document.getElementById(tab1).className = "selected";
document.getElementById(tab2).className = "detail";
document.getElementById(tab3).className = "detail";
document.getElementById(tab4).className = "detail";
document.getElementById(tab5).className = "detail";

//alert("show"+show+"-hide"+no);
document.getElementById(show).style.display = 'block';
document.getElementById(no1).style.display = 'none';
document.getElementById(no2).style.display = 'none';
document.getElementById(no3).style.display = 'none';
document.getElementById(no4).style.display = 'none';
}

function pageselect(where,image) {
document.getElementById(where).innerHTML ="<img src='book_created/singleimage/"+image+"' style='height:370px; width:250px; border:0; padding:0; margin:0;'>";
}

function select(where,image,el,hide) {
//alert (hide);
	document.getElementById(hide).style.display = 'none';
	pageselect(where,image);

	var w = document.forms["info"].wsize.value;
	var ws = parseInt(w)
	ws = ws + 75;
	document.getElementById("selected")
	//alert( document.getElementById("selected") );

	document.getElementById("selected").style.width = ws;

	document.forms["info"].wsize.value=ws;
	
	var newdiv = document.createElement('div'); 
	var divIdName = el+"selected";
	newdiv.setAttribute('id',divIdName);
		//for FF
	newdiv.setAttribute("style","float:left");
		// for IE
	newdiv.style.styleFloat = "left";

	newdiv.style.height = "110";
	newdiv.innerHTML = "<div><a href=# onclick=pageselect('preview','"+image+"','"+el+"');><img id='"+el+"' src='book_created/thumb/"+image+"' style='border:2px solid #00cc00; height:60px; margin:8px 15px 0px 15px;'></a></div><div style='padding:0px 0px 0px 10px;' id='"+el+"remove'><a href=# onclick=remove('"+el+"selected','"+el+"add','"+el+"');>remove</a></div>";
	document.getElementById("selected").appendChild(newdiv);
	
	var pcount = document.forms["info"].pc.value;
	var pagecount = parseInt(pcount)
	pagecount =pagecount + 1;
	document.getElementById("pagecount").innerHTML ="<p style='color:red; padding:0 0 0 10px'><b>"+pagecount+"</b></p>";
	document.forms["info"].pc.value=pagecount;
	
//	var sesId = document.forms["info"].sesId.value;	

	var sesId = document.getElementById('sesId').value;
	url= "processWizard.php?action=addBookWizardnew&pageId="+el+"&sesId="+sesId;
//	alert(url);
	tempdata(url,'addremove');
}

function remove(remove,show,el) {
if (confirm("Are you sure you want to remove this page")) {
	document.getElementById(show).style.display = 'block';
	var w = document.forms["info"].wsize.value;
	var ws = parseInt(w)
	ws = ws - 75;
	document.forms["info"].wsize.value=ws;
	document.getElementById("selected").style.width = ws;	
	var removediv = document.getElementById(remove);
	document.getElementById("selected").removeChild(removediv);

	var pcount = document.forms["info"].pc.value;
	var pagecount = parseInt(pcount)
	pagecount = pagecount - 1;
	document.getElementById("pagecount").innerHTML ="<p style='color:red; padding:0 0 0 10px'><b>"+pagecount+"</b></p>";
	document.forms["info"].pc.value=pagecount;
	
	var sesId = document.getElementById('sesId').value;
	url= "processWizard.php?action=deletePage&pageId="+el+"&sesId="+sesId;
//	alert(url);
	tempdata(url,'addremove');
}
}

function removeExisting(remove,el) {
if (confirm("Are you sure you want to delete this page")) {
	var w = document.forms["info"].wsize.value;
	var ws = parseInt(w)
	ws = ws - 75;
	document.forms["info"].wsize.value=ws;
	document.getElementById("selected").style.width = ws;	
	
	var removediv = document.getElementById(remove);
	document.getElementById("selected").removeChild(removediv);

	var pcount = document.forms["info"].pc.value;
	var pagecount = parseInt(pcount)
	pagecount = pagecount - 1;
	document.getElementById("pagecount").innerHTML ="<p style='color:red; padding:0 0 0 10px'><b>"+pagecount+"</b></p>";
	document.forms["info"].pc.value=pagecount;
	
	var sesId = document.getElementById('sesId').value;
	url= "processWizard.php?action=deletePageExisting&pageId="+el+"&sesId="+sesId;
//	alert(url);
	tempdata(url,'addremove');
}
}

function tempdata(what,where) {
xmlHttpnew=createRequest();
what=what+"&sid="+Math.random();
//alert(what);
document.cookie = "location=" + where;
	if (where=="addremove"){
		document.getElementById(where).innerHTML ="<div style='color:#ffffff;'><b>Processing&nbsp;&nbsp;&nbsp;<img src=./images/loading-3.gif></b></div>";
	}if (where=="application"){
		document.getElementById(where).innerHTML ="<table width=100% height=575px bgcolor=#ffffff align=center valign=center><tr><td align=center style='color:#6b0f0f;font-size:20px;'><img src=./images/loading-1.gif></td></tr></table>";
	}
xmlHttpnew.onreadystatechange=statechangedtemp;
xmlHttpnew.open("GET",what,true);
xmlHttpnew.send(null);
}


function finish() {
	var sesId = document.getElementById('sesId').value;
//	tempdata(what,'application');
	url= "processWizard.php?action=wizardFinishnew&sesId="+sesId;

	document.forms["info"].pc.value=0;
	document.forms["info"].wsize.value=0;
	tempdata(url,'application');
}


function statechangedtemp(){
	if (xmlHttpnew.readyState==4){
	var display = get_cookie ( "location" );
	var loadwhat = get_cookie ( "selected-a" );

//	alert(loadwhat);
		if (loadwhat=="pre"){
			var bid = get_cookie ( "bookedit" );
			var url="preview.php?bookId="+bid;	
			window.location.href = url;	
		}else{
		document.getElementById(display).innerHTML=xmlHttpnew.responseText;
		test=document.getElementById(display).innerHTML=xmlHttpnew.responseText;
//		alert(test);
		if (loadwhat=="start"){
			document.cookie = "bookedit=";
			document.cookie = "bookcover=";
			document.cookie = "bookpages=";		
			loadtab('./mybook-new.php?page=2','displaycontent','mybook','editmy','orders');	
		}
		
		if (loadwhat=="cov"){	

			var t=document.coverform.covertype.value;
			var id=document.coverform.coverId.value;
			var p=document.coverform.price.value;
			var title=document.coverform.bookname.value;
			var where='preview';
			
//			alert(t);
			
			if (id==''){
			var t="1";
			var id="16";
			var p='39.95';
			}
			
			if (t==2){
			showcovertab('displaysoft','displayhard','soft','hard');
			coverselect(where,t,id,'24.95',title);
			}else{
			showcovertab('displayhard','displaysoft','hard','soft');
			coverselect(where,t,id,'39.95',title);
			}	
		}
			}				
		
	}
}


function mybookEditapp(what,where,selected,bookId,pages,cover)
	{
//	alert(bookId)
	document.cookie = "bookedit=" + bookId;
	document.cookie = "bookcover=" + cover;
	document.cookie = "bookpages=" + pages;
	
	loadapp(what,where,selected);
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function thisMovie(movieName) {

        // IE and Netscape refer to the movie object differently.
        // This function returns the appropriate syntax depending on the browser.
        if (navigator.appName.indexOf ("Microsoft") !=-1) {
                return window[movieName];       
        } else {
                return window.document[movieName];
       }
}


//success flag, set by flash/flex app
var bFunctionCallFinished = true;
//param delimiter, kind of unique string
var paramDelimiter =  "-->$$###$$##$$<--";
//this function would call a flash/flex function.
function isBookSaved(functionName, paramsArray)
{
	var isBookSaved;
	//Get the reference so activeX or Plugin. flexApp is id/name of OBJECT/EMBED tags
	var flashObject  = thisMovie("LoveBook");
	var dd = flashObject.isBookSaved(paramsArray);
	bFunctionCallFinished = false;
}

function jscall()
	{
	var data  = document.getElementById('bookId').value;
//	objPage.user = get_cookie ('bookedit');

//	var statusVal= get_cookie ('hashType'); 	
	var statusVal = document.getElementById('hashType').value;

	var splVal = data.split("=");
	var objPage = new Object();
	var bookArr1 = new Array()
	
	if (data==null || data=='' || data==' ')
		objPage.bookId = 0; // Create A New Book
	else if (splVal[0]=='bookId')
		objPage.bookId = splVal[1]; // Edit Book
	else if (splVal[0]=='pageId')
		{
		objPage.bookId  = '-1'; //  Wizard
		var splVal1   = splVal[1].split(",");
		var splLength = splVal1.length;
		var i = 0;
			while (i < splLength)
				{
				bookArr1[i] = splVal1[i];
				i++;
				}
		objPage.bookArr = bookArr1;
		}
	objPage.status = statusVal;
	
	return objPage;
	}

function loginCheck()	
	{
	var objPage = new Object();
//	objPage.status = document.getElementById('hashType').value;
//	objPage.user   = document.getElementById('userVal').value;

////added cookies to handle login kjz 2-16-08
	objPage.user = get_cookie ('hash');
	objPage.status = get_cookie ('hashType'); 
	
	return objPage;
	}
	
//////////////////////////////////////////////////cover design//////////////////////////////////////

function showcovertab(show,no,tab1,tab2) {
//alert(what);
document.getElementById(tab1).className = "selected";
document.getElementById(tab2).className = "detail";

//alert("show"+show+"-hide"+no);
document.getElementById(show).style.display = 'block';
document.getElementById(no).style.display = 'none';
}

function coverselect(where,t,id,p,title) {
xmlHttpnew=createRequest();

document.cookie = "bookcover=" + t;
//document.cookie = "bookpages=" + pages;

document.cookie = "location=" + where;
var display = get_cookie ( "location" ); 
document.getElementById(display).innerHTML ="<table align=center valign=center><tr><td align=center bgcolor=#ffffff width=250px height=370px><img src='../images/loading.gif' width=250></td></tr></table>";

var title=document.coverform.bookname.value;
var sub=document.coverform.subname.value;
var bookid=document.coverform.bookid.value;

document.coverform.covertype.value = t;
document.coverform.coverId.value = id;

if (p==0 || p==null){
document.coverform.price.value = '39.95';
}else{
document.coverform.price.value = p;
}
//alert (p);

if (id=='16' || id=='24' || id=='32' || id=='34' || id=='36' || id=='38' || id=='40' || id=='44' || id=='46'){ //hard cover top
var what = "./cover/imagem-process.php?coverImage="+id+".jpg&coverText="+title+"&subText="+sub+"&bookId="+bookid+"&locations=90&coverSize=preview&fontsize=32&coverPrice="+p;
var cover_print = "./cover/imagem.php?coverImage="+id+".jpg&coverText="+title+"&subText="+sub+"&bookId="+bookid+"&location=650&coverSize=print&fontsize=180&coverPrice="+p;
}
else if (id=='20' || id=='26' || id=='33' || id=='35' || id=='37' || id=='39' || id=='41' || id=='45' || id=='47'){ //soft cover top
var what = "./cover/imagem-process.php?coverImage="+id+".jpg&coverText="+title+"&subText="+sub+"&bookId="+bookid+"&locations=90&coverSize=preview&fontsize=32&coverPrice="+p;
var cover_print = "./cover/imagem.php?coverImage="+id+".jpg&coverText="+title+"&subText="+sub+"&bookId="+bookid+"&location=525&coverSize=print&fontsize=160&coverPrice="+p;
}
else if (id=='17' || id=='18' || id=='19' || id=='28' || id=='30' || id=='42'){ //hard cover bottom
var what = "./cover/imagem-process.php?coverImage="+id+".jpg&coverText="+title+"&subText="+sub+"&bookId="+bookid+"&locations=340&coverSize=preview&fontsize=32&coverPrice="+p;
var cover_print = "./cover/imagem.php?coverImage="+id+".jpg&coverText="+title+"&subText="+sub+"&bookId="+bookid+"&location=2000&coverSize=print&fontsize=180&coverPrice="+p;
}
else if (id=='21' || id=='22' || id=='23' || id=='29' || id=='31' || id=='43'){ //soft cover bottom
var what = "./cover/imagem-process.php?coverImage="+id+".jpg&coverText="+title+"&subText="+sub+"&bookId="+bookid+"&locations=340&coverSize=preview&fontsize=32&coverPrice="+p;
var cover_print = "./cover/imagem.php?coverImage="+id+".jpg&coverText="+title+"&subText="+sub+"&bookId="+bookid+"&location=1775&coverSize=print&fontsize=160&coverPrice="+p;
}
//alert(cover_print);
//document.getElementById('print').innerHTML = cover_print;
document.cookie = "cover=" + cover_print;

//alert(what)
xmlHttpnew.onreadystatechange=statechangednew;
xmlHttpnew.open("GET",what,true);
xmlHttpnew.send(null);
}


function changetitle(what,where,form,v,hide,IdName) {
//alert(form+v);
xmlHttpnew=createRequest();
//Get the form reference:
var form = document.forms[form];
//Get the exact form element:
var formTag = form.elements[v];
//Get the value of the input element:
var tag = formTag.value; 

if(tag.length<32){
	if (v=="bookTitle"){
	document.coverform.bookname.value = tag;
	}
	else {
	document.coverform.subname.value = tag;
	}
	what = what + "&formvalue=" + tag + "&hide=" + hide;
	//alert (what);
	what=what+"&sid="+Math.random();

	document.cookie = "location=" + where;
	var display = get_cookie ( "location" ); 
	document.getElementById(display).innerHTML ="<div style='color:red;'>Processing.....</div>";

	//alert ("page udated");
	var t=document.coverform.covertype.value;
	var id=document.coverform.coverId.value;
	
	var p=document.coverform.price.value;

	xmlHttpnew.onreadystatechange=statechangedcover;
	xmlHttpnew.open("GET",what,true);
	xmlHttpnew.send(null);
	
		if (v=="bookTitle"){
		var title=document.coverform.bookname.value;
		}
		else {
		var title=document.coverform.subname.value;
		}
}
else{
alert("your book title cannot exceed 32 characters");
}
}

function statechangedcover(){
if (xmlHttpnew.readyState==4){
	test=xmlHttpnew.responseText;
var display = get_cookie ( "location" );
document.getElementById(display).innerHTML=xmlHttpnew.responseText;

var t=document.coverform.covertype.value;
var id=document.coverform.coverId.value;
var p=document.coverform.price.value;
//alert(p);
var title=document.coverform.bookname.value;

coverselect('preview',t,id,p,title);

return null;

}
}

function coverchoose(what,f) {
xmlHttpnew=createRequest();

var id = document.forms[f].coverId.value;
var p = document.forms[f].price.value;
var title=document.coverform.bookname.value;
var bookid=document.coverform.bookid.value;

what=what+"&coverImage=book"+bookid+".jpg&coverId="+id+"&coverPrice="+p+"&coverText="+title+"&bookId="+bookid;
what=what+"&sid="+Math.random();

var where="finished";
document.cookie = "location=" + where;
document.getElementById(where).innerHTML ="<div style='color:#ffffff;'><b>Processing&nbsp;&nbsp;&nbsp;<img src=./images/loading-3.gif></b></div>";

xmlHttpnew.onreadystatechange=statechangedcoverselected;
xmlHttpnew.open("GET",what,true);
xmlHttpnew.send(null);
}
	
function statechangedcoverselected(){
if (xmlHttpnew.readyState==4){
	test=xmlHttpnew.responseText;
var display = get_cookie ( "location" );
//document.getElementById(display).innerHTML=xmlHttpnew.responseText;
//setTimeout ( "document.getElementById(display).innerHTML=xmlHttpnew.responseText", 6000 );
setTimeout ( "loadapp('./displaydetail-new.php?page=2','application','pre','cov','cus','wiz')", 3000 );
//loadapp('./displaydetail-new.php?page=2','application','pre','cov','cus','wiz');

return null;

}
}	

function loadapp2(what,where,selected){
document.cookie = "what-a=" + what;
document.cookie = "where-a=" + where;
document.cookie = "selected-a=" + selected;
window.location.href = "app-2.php";
}

function loadapp3(what,where,selected){
document.cookie = "what-a=" + what;
document.cookie = "where-a=" + where;
document.cookie = "selected-a=" + selected;

var bid = get_cookie ( "bookedit" );
var url="preview.php?bookId="+bid;
window.location.href = url;
}

function loadpreview(what,where,selected,bookId,pages,cover){

if (cover==2){
var tp=24;
var c ="Soft Cover";
}else{
var tp=54;
var c="Hard Cover";
}
//alert (pages+"-"+tp + "-" + cover);
if(pages<tp){
	if (confirm("There are only "+pages+" pages in your book.\nA "+c+" book requires a minimum of "+tp+" pages.\nBlank pages will be added at the end of your book.\n\nDo you wish to continue?")) {
		document.cookie = "what-a=" + what;
		document.cookie = "where-a=" + where;
		document.cookie = "selected-a=" + selected;
		document.cookie = "bookedit=" + bookId;
		document.cookie = "bookcover=" + cover;
		document.cookie = "bookpages=" + pages;
		var bid = get_cookie ( "bookedit" );
		var url="preview.php?bookId="+bid;
		window.location.href = url;		
		}
}else{
		document.cookie = "what-a=" + what;
		document.cookie = "where-a=" + where;
		document.cookie = "selected-a=" + selected;
		document.cookie = "bookedit=" + bookId;
		document.cookie = "bookcover=" + cover;
		document.cookie = "bookpages=" + pages;
		var bid = get_cookie ( "bookedit" );
		

		var url="preview.php?bookId="+bid;
		window.location.href = url;	
}
}


function fix()
	{
		document.cookie = "what-a=./book_creator-new.php?page=2";
		document.cookie = "where-a=application";
		document.cookie = "selected-a=cus" ;

		var url="app-2.php";
		window.location.href = url;		
	}