// JavaScript Document
//SHARED FUNCTIONS




function showLoading()
{
	document.getElementById('ContentStatus').innerHTML = "<center><img src='images/loading.gif'></center>";
};

function getCurrentTime()
{
	var currentTime = new Date();
	var hours = currentTime.getHours();
	var minutes = currentTime.getMinutes();
	var seconds = currentTime.getSeconds();
	var AMPM = "AM";
	if(hours > 11){
	AMPM = "PM";
	} 		
	if (hours > 12)
	hours = hours - 12;		
	if (minutes < 10)
	minutes = "0" + minutes
	if (seconds < 10)
	seconds = "0" + seconds
	currentTime = (hours + ":" + minutes + ":" + seconds + " ");		
	if(AMPM == "PM"){
	currentTime = currentTime + "PM";
	} else {
	currentTime = currentTime + "AM";
	}
	return currentTime;
};

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
};
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
};

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function ShowMeHowWindow(section){

	ColdFusion.Window.show('ShowMeHowWindow');
	var URL = 'ShowMeHow.cfm';
	ColdFusion.navigate(URL,'ShowMeHowWindow');			
	
};

function disableTabsWhenLocked(){
		ColdFusion.Layout.disableTab('mainTab','tab1');
		ColdFusion.Layout.disableTab('mainTab','tab2');
		ColdFusion.Layout.disableTab('mainTab','tab3');
		ColdFusion.Layout.disableTab('FinalTabs','FinalStep1');
		ColdFusion.Layout.disableTab('FinalTabs','FinalStep2');
};


function StartNewBook(WebId){
	if(confirm('Are you sure you want to close Item Number ' + WebId + ' and start a new book?')){
		location.replace('index.cfm?Action=New');
	}
	
};

function ShowCommonModal(page){
	$j('#CommonModalInner').html('Loading... please wait.');
	$j('#CommonModal').modal({overlayClose:false,opacity:80,overlayCss:{backgroundColor:"#000"}});
	$j('#CommonModalInner').load(page);
};

function ShowPINModal(){
	$j('#PINModal').modal({overlayClose:false,opacity:80,overlayCss:{backgroundColor:"#000"}});
};

function MailPINCode(){
		$j.post('SendPINEmail.cfm','',function(data,status){
			if (trim(data) == 1){
				alert('An email has been sent.  Check your inbox shortly.');	
			}
			else{
				alert('An error has occured.  For assistance call 888-457-7958.');
			}
			
	  },"html");
};

function GetStarted(){ 
	if(ActiveCookie == 'True'){
		EnableMainTabs();
		ColdFusion.Layout.selectTab('mainTab','tab1');
		window.scrollTo(0,0);
	}	
	else{
		ShowCommonModal('GetStartedInc.cfm');
		//$j('#GetStartedContainer').modal({overlayClose:false,opacity:80,overlayCss:{backgroundColor:"#000"}});
		};
	
};
function SubmitGetStarted(){
	var FormData = $j('#GetStartedForm').serialize();
	$j.post('ActivateBook.cfm', FormData,function(data,status){	  
			GetStartedCallback(data);		
	}, "html");
};

function GetStartedCallback(text)
{ 
	if(trim(text) == 'True')
	{
		$j.modal.close();
		EnableMainTabs();
		ColdFusion.Layout.selectTab('mainTab','tab1');
		window.scrollTo(0,0);
	}
	else
	{
		alert('Error: Please review your information and re-submit.' + text);
	}
};

function EnableMainTabs(){
	ColdFusion.Layout.enableTab('mainTab','tab1');
	ColdFusion.Layout.enableTab('mainTab','tab2');
	ColdFusion.Layout.enableTab('mainTab','tab3');
	ColdFusion.Layout.enableTab('mainTab','tab4');
	var ActiveCookie = 'True';
};

function EnableInputTitleTip(){
	$j('.txbhint').focus(function(){
		if ($j(this).val() == "" || $j(this).val() == $j(this).attr('title')) {
			$j(this).val("").removeClass("hinted");
		}
	}).blur(function(){
		if ($j(this).val() == "") {
			$j(this).val($j(this).attr('title')).addClass("hinted");
		}
	}).filter(function(){
		if ($j(this).val() == "" || $j(this).val() == $j(this).attr('title')) {
			$j(this).val($j(this).attr('title')).addClass("hinted");
		}
	});
};	

function CloseModal(){
	$j.modal.close();
};

function ShowSample(ItemNumber){
	$j('.SampleContent').css('display','none');
	$j('#Sample_' + ItemNumber).css('display','block');
}

//END SHARED FUNCTIONS
//----------------------------------------------------------------------------------------------------------------------------

// CODE FOR SUBITTING FORM ON FIRST TAB
function submitForm(){
	showLoading();
	ColdFusion.Ajax.submitForm('GeneralInformation', 'CustomTextsAction.cfm?Action=GeneralUpdate', callback, errorHandler);
	TransferInformation();
};

function TransferInformation(){
	// form data from cover information
	var ProfName =	document.getElementById('ProfName').value;
	var Institution = document.getElementById('Cover_Institution').value;
	var CourseNumber = document.getElementById('Cover_CourseNumber').value;
	
	// form data from additional information section
	var Add_ProfName = 	document.getElementById('Add_ProfName').value;
	var Add_NameOfSchool = document.getElementById('Add_NameOfSchool').value;
	var Add_CourseNumber = document.getElementById('Add_CourseNumber').value;
	// form data from "request desk copy section"
	var DeskCopy_Institution = document.getElementById('DeskCopy_Institution').value;
	
	
	if(Add_ProfName == '' ){
		document.getElementById('Add_ProfName').value = ProfName;
	};
	if(Add_NameOfSchool == ''){
		document.getElementById('Add_NameOfSchool').value = Institution;
	};
	if(Add_CourseNumber == ''){
		document.getElementById('Add_CourseNumber').value = CourseNumber;			
	};
	if(DeskCopy_Institution == ''){
		document.getElementById('DeskCopy_Institution').value = Institution;						
	};
	
	
	
	
	

	
	
};

function callback(text)
{ 
	var currentTime = getCurrentTime();
	document.getElementById('ContentStatus').innerHTML = "<span class='StatusBar'>" + text + " " + currentTime + "</span>";
	RefreshPriceTotal();
	resetPreview();
};

function errorHandler(code, msg)
{
	document.getElementById('ContentStatus').innerHTML = "Error! " + code + ": " + msg; 
	RefreshPriceTotal();
	resetPreview();
};


function ShowCoverPreview(Template)
{	
	ColdFusion.Window.show('CoverPreviewWindow');
	var PicURL = 'CustomTextsAction.cfm?Action=PreviewCover&Template=' + Template;
	ColdFusion.navigate(PicURL,'CoverPreviewWindow');
	
};


// END CODE FOR SUBITTING FORM ON FIRST TAB


//------------------------------------------------------------------------------------------------------------------------------
//CODE FOR SUBMITTING FORM ON SECOND TAB
function ExpandSection(section)
{
	if (document.getElementById(section).style.display == 'none')
		{
			document.getElementById(section).style.display = 'block';
		}
	else
		{
			document.getElementById(section).style.display = 'none';
		}	
};

function ExpandDefinition(section)
{
	if (document.getElementById(section).style.display == 'none')
		{
			document.getElementById(section).style.display = 'inline';
		}
	else
		{
			document.getElementById(section).style.display = 'none';
		}	
};


function ShowSearchOptions(type){
	if (type == 'Basic'){
		$j('#AdvancedSearchContent').css('display','none');
		$j('#BasicSearchContent').css('display','block');
	}
	else if (type == 'Advanced'){	
		$j('#BasicSearchContent').css('display','none');
		$j('#AdvancedSearchContent').css('display','block');
	}
}

<!---- FORM SUBMIT AJAX CODE----->
function ShowUploadingStatus()
	{
		document.getElementById('UploadStatus').style.display = 'inline';
		FlashUploadStatus();
		document.getElementById('UploadStatus').innerHTML = "Uploading...";
	};
	
	
function ClearUploadStatus(){
	document.getElementById('UploadStatus').innerHTML = "";
	clearInterval(timerId);
	document.getElementById('UploadStatus').style.display = 'none';
	flashing = "off";
};
				
function RefreshUserFileList()
	{ ColdFusion.navigate('CustomTextsAction.cfm?Action=RefreshUserFileList','DivListUserContentFiles');
	  RefreshOrganizeContent();
	  RefreshPriceTotal();
	};

function DeleteUserFile(file,CustomBookLineId)
	{ 	if (confirm('Are you sure you want to delete ' + file))
			{
			var URLLink = 'CustomTextsAction.cfm?Action=FileDelete&CustomBookLineId=' + CustomBookLineId;
			ColdFusion.navigate(URLLink,'DivListUserContentFiles');
			
			ColdFusion.navigate('Tab2UploadIncV3.cfm','UploadFiles');
			RefreshOrganizeContent();
			RefreshPriceTotal();
			};
	};
	
	
function AddRemoveContentLine(ContentLineId){
	showLoading();
	var FormName = 'Form' + ContentLineId;
	ColdFusion.Ajax.submitForm(FormName, 'CustomTextsAction.cfm?Action=AddRemoveContentLine', ContentCallback, ContentErrorHandler);
	SwapAddRemove(ContentLineId);
};

function SwapAddRemove(ContentLineId){
	var FormName = 'Form' + ContentLineId;
	var imgName = ContentLineId + 'AddRemoveImg';
	if (document.getElementById(FormName).AddRemove.value == 'Add')
		{
			document.getElementById(FormName).elements[1].value = 'Remove';
			document.getElementById(imgName).src = 'Images/buttons/add.png';
			document.getElementById(imgName).alt = 'Remove from book';
		}
	else
		{
			document.getElementById(FormName).elements[1].value = 'Add';
			document.getElementById(imgName).src = 'Images/buttons/neutral.png';			
			document.getElementById(imgName).alt = 'Add to book';
		}
	 	
};


function HoverAddRemoveButton(ContentLineId){
	var FormName = 'Form' + ContentLineId;
	var imgName = ContentLineId + 'AddRemoveImg';
	if (document.getElementById(FormName).AddRemove.value == 'Remove')
	{
		document.getElementById(imgName).src = 'Images/buttons/remove.png';
		document.getElementById(imgName).alt = 'Remove from book';
	}
	else
	{
		document.getElementById(imgName).src = 'Images/buttons/add.png';
		document.getElementById(imgName).alt = 'Add to book';
	}
	
	
};
function MouseOutHoverAddRemoveButton(ContentLineId){
	var FormName = 'Form' + ContentLineId;
	var imgName = ContentLineId + 'AddRemoveImg';
	if (document.getElementById(FormName).AddRemove.value == 'Remove')
	{	
		document.getElementById(imgName).src = 'Images/buttons/Add.png';
	}
	else
	{
		document.getElementById(imgName).src = 'Images/buttons/neutral.png';			
	}
}


function ChangeContentRequestForm(Type){
	if (Type == 'Book')
		{
			document.getElementById('BookFields').style.display = 'block';
			document.getElementById('BookFields').style.visibility = 'visible';
			document.getElementById('PeriodicalFields').style.display = 'none';
			document.getElementById('PeriodicalFields').style.visibility = 'hidden';
		}
		
	if (Type == 'Periodical')
		{
			document.getElementById('BookFields').style.display = 'none';
			document.getElementById('BookFields').style.visibility = 'hidden';
			document.getElementById('PeriodicalFields').style.display = 'block';	
			document.getElementById('PeriodicalFields').style.visibility = 'visible';
			
		}
	
}



//TERMS TERMS TERMS TERMS TERMS TERMS TERMS TERMS TERMS TERMS TERMS TERMS 
function HoverTermAddRemoveButton(ProductTermId){
	var imgName = ProductTermId + 'AddRemoveImg';
	if (document.getElementById(ProductTermId).checked == true)
	{
		document.getElementById(imgName).src = 'Images/buttons/remove.png';
		document.getElementById(imgName).alt = 'Remove from book';
	}
	else
	{
		document.getElementById(imgName).src = 'Images/buttons/add.png';
		document.getElementById(imgName).alt = 'Add to book';		
	}
	
	
}
function MouseOutHoverTermAddRemoveButton(ProductTermId){
	var imgName = ProductTermId + 'AddRemoveImg';
	if (document.getElementById(ProductTermId).checked == true)
	{	
		document.getElementById(imgName).src = 'Images/buttons/Add.png';
		document.getElementById(imgName).alt = 'Add to book';	
	}
	else
	{
		document.getElementById(imgName).src = 'Images/buttons/neutral.png';	
		document.getElementById(imgName).alt = 'Remove from book';
	}
}


function TermChangeState(ProductTermId,FormName){
	var imgName = ProductTermId + 'AddRemoveImg';
	if (document.getElementById(ProductTermId).checked == true)
	{	
		document.getElementById(imgName).src = 'Images/buttons/neutral.png';
		document.getElementById(ProductTermId).checked = false;
	}
	else
	{
		document.getElementById(imgName).src = 'Images/buttons/Add.png';
		document.getElementById(ProductTermId).checked = true;
	}	
	
	submitGlossaryForms(FormName);	
}
//TERMS TERMS TERMS TERMS TERMS TERMS TERMS TERMS TERMS TERMS TERMS TERMS 

function RemoveAllTerms(){
	if(confirm('Are you sure you want to remove all selected terms from this book?'))
		{
		ColdFusion.navigate('CustomTextsAction.cfm?Action=RemoveAllTerms','GlossaryTerms');
		ColdFusion.navigate('Tab3Inc.cfm','tab3');
		callback('Saved!');
		}
}

	
function submitContentForm() {
	showLoading();
	ColdFusion.Ajax.submitForm('AddRemoveSMPContent', 'CustomTextsAction.cfm?Action=AddRemoveSMPContent', ContentCallback, ContentErrorHandler);
}

function submitGlossaryForms(FormName) {
	showLoading();
	ColdFusion.Ajax.submitForm(FormName, 'CustomTextsAction.cfm?Action=AddRemoveGlossaryContent', ContentCallback, ContentErrorHandler);
}	


function ContentCallback(text)
{ 
	var currentTime = getCurrentTime();
	document.getElementById('ContentStatus').innerHTML = "<span class='StatusBar'>" + text + " " + currentTime + "</span>";  
	RefreshOrganizeContent();
	RefreshPriceTotal();
	resetPreview();
}

function ContentErrorHandler(code, msg)
{document.getElementById('ContentStatus').innerHTML = "Error! " + code + ": " + msg; }


function RefreshOrganizeContent()<!--- REFRESH DIV IN TAB3---->
{ ColdFusion.navigate('CustomTextsAction.cfm?Action=RefreshOrganizeContent','divOrganizeContent');
}

function RefreshContentTab()<!--- REFRESH DIV IN TAB3---->
{ 
	ColdFusion.navigate('Tab2Inc.cfm','tab1');
}

function ShowMap(picture)
{	
	ColdFusion.Window.show('MapPreviewWindow');
	var PicURL = 'CustomTextsAction.cfm?Action=PreviewMap&Map=' + picture;
	ColdFusion.navigate(PicURL,'MapPreviewWindow');
	
}

function ShowChart(picture)
{	
	ColdFusion.Window.show('ChartPreviewWindow');
	var PicURL = 'CustomTextsAction.cfm?Action=PreviewChart&Chart=' + picture;
	ColdFusion.navigate(PicURL,'ChartPreviewWindow');
	
}

//FILE UPLOAD FLASHING TEXT
var flashing = "off";
function FlashUploadStatus()
{
		if (flashing == "off")
		{
			timerId = setInterval("switchClassName()", 1000);
			flashing = "on"
		}
}
function switchClassName(){
		if (document.getElementById('UploadStatus').style.display == 'none')
		{
			document.getElementById('UploadStatus').style.display = 'inline';
		}
/*	else
		{
			document.getElementById('UploadStatus').style.display = 'none';
		}	*/
		if (document.getElementById('UploadStatus').className == 'highlightGreen')
		{
			document.getElementById('UploadStatus').className = 'highlightGreenOff';
		}
		else
		{
			document.getElementById('UploadStatus').className = 'highlightGreen';
		}
}


	
var Q1Answer = 'none';
var Q2Answer = 'none';
/*		V3 toggle buttons  		*/
function Q1YesButtonClick(){
	Q1Answer = true;
	$j('#Q1No').removeClass('Nchecked');
	$j('#Q1Yes').addClass('Ychecked');
	DoStep2();
};
function Q1NoButtonClick(){
	Q1Answer = false;
	$j('#Q1Yes').removeClass('Ychecked');
	$j('#Q1No').addClass('Nchecked');
	DoStep2();	
};
function Q2YesButtonClick(){
	Q2Answer = true;
	$j('#Q2No').removeClass('Nchecked');
	$j('#Q2Yes').addClass('Ychecked');
	DoStep2();	
};
function Q2NoButtonClick(){
	Q2Answer = false;
	$j('#Q2Yes').removeClass('Ychecked');
	$j('#Q2No').addClass('Nchecked');
	DoStep2();	
};

function ResetUploadQuestionButtons(){
	Q1Answer = 'none';
	Q2Answer = 'none';
	$j('#Q1No').removeClass('Nchecked');
	$j('#Q1Yes').removeClass('Ychecked');
	$j('#Q2No').removeClass('Nchecked');
	$j('#Q2Yes').removeClass('Ychecked');
};

function DoStep2(){
	if(Q1Answer != 'none' && Q2Answer != 'none'){
		if(Q1Answer == true && Q2Answer == true){
			//Just let them upload, they don't need permission
			ShowCommonModal('Tab2UploadInc.cfm');
		}
		else if (Q1Answer == true && Q2Answer == false){
			//Show CCC Search then upload file
			ShowCommonModal('Tab2IncCCCSearchForm.cfm');
		}
		else if (Q1Answer == false){
			//Tell them to call customer service for additional assistance
			ShowCommonModal('Tab2IncTier3.cfm');
		};
	};
};




CCCSavedFormData = "";
function DoPermissionsSearch(FormData){
	if(FormData == undefined){ //if they don't specify, then get it from the form.  If they stecify, it's probobly CCCSavedFormData data
		FormData = $j('#CCCSearchForm').serialize();
	};
	CCCSavedFormData = FormData; //Save the search. This is used in the QuickPrice page to "go back to search"
	$j('#CommonModalInner').html('<div align="center">Loading...Please wait.</div>');							
	$j.post('Tab2IncCCCSearchAction.cfm', FormData,function(data,status){
			$j("#CommonModalInner").html(data);																							
	}, "html");
};

function QuickPrice(formName){
	FormData = $j(formName).serialize();
	$j.post('Tab2IncCCCQuickPriceAction.cfm', FormData,function(data,status){
		$j("#CommonModalInner").html(data);
	}, "html");	
};

function SubmitConciereService(){
	$j.post('ConciereRequestForm.cfm',$j('#frmConciereRequest').serialize(),function(data,status){
			$j("#CommonModalInner").html(data);								  
	  },"html");
	
};

function SubmitContentRequest(){
	$j.post('ContentRequestForm.cfm',$j('#frmContentRequest').serialize(),function(data,status){
			$j("#CommonModalInner").html(data);								  
	  },"html");
};


function SpecialOrder(formName){
	FormData = $j(formName).serialize();
	$j.post('Tab2IncCCCSpecialOrder.cfm', FormData,function(data,status){
		$j("#CommonModalInner").html(data);
	}, "html");	
};

function ShowPermissions(){
	document.getElementById('divPermissions').style.display = 'block';
};
function HidePermissions(){
	document.getElementById('divPermissions').style.display = 'none';	
};
function DisablePermissions(){
	HidePermissions();
	document.getElementById('CopyrightNo').checked = true;
	document.getElementById('CopyrightYes').disabled = true;
};
function EnablePermissions(){
	document.getElementById('CopyrightYes').disabled = false;
};

function ToggleSearch(){
	ExpandSection('divSimpleSearch');
	ExpandSection('divAdvancedSearch');
}

function ChangeSearchOrderBy(SearchId){
	var OrderBy = document.getElementById('SearchOrderBy').elements[0].value;
	var URL = 'Tab2IncSearchAction.cfm?SearchId=' + SearchId + '&OrderBy=' + OrderBy + '&PageNumber=1';
	ColdFusion.navigate(URL,'DivSearchResults');
}

function SimpleSearch(){
	var Keyword = document.getElementById('frmSimpleSearch').elements[0].value;
	var URL = 'Tab2IncSearchAction.cfm?Keyword=' + Keyword + '&SimpleSearch=True';
	ColdFusion.navigate(URL,'DivSearchResults');
	return false;
};

function ReligionSearch(religion){
	//var Religion = document.getElementById('frmReligionSearch').elements[0].value;
	var URL = 'Tab2IncreligionSearchAction.cfm?Religion=' + religion + '&SimpleSearch=True';
	ColdFusion.navigate(URL,'DivReligionSearchResults');
	return false;
};

function SearchChangePage(SearchId, PageNumber, OrderBy){
	var URL = 'Tab2IncSearchAction.cfm?SearchId=' + SearchId + '&PageNumber=' + PageNumber + '&OrderBy=' + OrderBy;
	ColdFusion.navigate(URL,'DivSearchResults');	
}

function AdvSearch(){	
	var TypeBooks = document.getElementById('frmAdvSearch').elements[0].checked;
	var TypeArticles = document.getElementById('frmAdvSearch').elements[1].checked;
	var TypeMaps = document.getElementById('frmAdvSearch').elements[2].checked;
	var TypeCharts = document.getElementById('frmAdvSearch').elements[3].checked;
/*	var TypeScripture = document.getElementById('frmAdvSearch').elements[4].checked;*/
	var Keyword = document.getElementById('frmAdvSearch').elements[4].value;
	var ExactTitle = document.getElementById('frmAdvSearch').elements[5].checked;		
	var PublisherId = document.getElementById('frmAdvSearch').elements[6].value;		
	var Author = document.getElementById('frmAdvSearch').elements[7].value;
	var URL = 'Tab2IncSearchAction.cfm?TypeBooks=' + TypeBooks;
	var URL = URL + '&TypeArticles=' + TypeArticles;
	var URL = URL + '&TypeMaps=' + TypeMaps;
	var URL = URL + '&TypeCharts=' + TypeCharts;
	var URL = URL + '&ExactTitle=' + ExactTitle;
	var URL = URL + '&Keyword=' + Keyword;
	//var URL = URL + '&CategoryId=' + CategoryId;
	var URL = URL + '&PublisherId=' + PublisherId;
	var URL = URL + '&Author=' + Author;
	
	if ((TypeBooks != true) && (TypeArticles != true) && (TypeMaps != true) && (TypeCharts != true) )/*&& (TypeScripture != true)*/
		{
			alert('You must select at least one content type.');
		}
	else
		{
			ColdFusion.navigate(URL,'DivSearchResults');
		}
	return false;
};

function PublisherSearch(){
	var URL = 'Tab2IncSearchAction.cfm?PublisherId=' + document.getElementById('frmPublisherSearch').elements[0].value;
	ColdFusion.navigate(URL,'DivSearchResults');
};

function BrowseByType(Type){
	ColdFusion.navigate('Tab2IncSearchAction.cfm?BrowseByType=' + Type,'DivSearchResults');
};

function BrowseByCategory(GroupId, TaxLevel){
	ColdFusion.navigate('Tab2IncSearchAction.cfm?GroupId=' + GroupId + '&TaxLevel=' + TaxLevel,'DivSearchResults');
};


//------------------------------------------------------------------------------------------------------------------------------
//SORTING ON TAB 3
/* NOTE: THERE'S OTHER CODE IN THE HTML HEAD THAT IS REQUIRED FOR DRAG/DROP TO WORK */
function MakeSortable()<!--- This gets run when divOrganizeContent is finished loading---->
	{ Sortable.create("firstlist",{dropOnEmpty:true,containment:["firstlist"],constraint:false});	}

function FindListOrder()
	{
		var varSort = unescape(document.getElementById('ContentSort').value);
		var varSortLength = varSort.length;
		var NumOfElements = 1;
		var ReOrderNumber = 1;
		for(x=0; x <= varSortLength; x++)
		{
			if (varSort.charAt(x) == ',')
			{
				NumOfElements++;
			}
		}
		for(x=1; x <= NumOfElements; x++)
		{
			/*Get First Element then Chop it off*/
			if (x != NumOfElements)
			{
			var ThisElement = Left(varSort, varSort.indexOf(","));
			}
			else/*LAST ELEMENT*/
			{
			var ThisElement = varSort;
			}
			/*Renumber current div*/
			var ElementDivId = "firstlist_" + ThisElement + '_Num';
			document.getElementById(ElementDivId).innerHTML = ReOrderNumber;
			ReOrderNumber++;
			
			/*Chop off current Element*/			
			varSort = varSort.substring(ThisElement.length + 2, varSort.length);
		}
	}


function ShowOrderString()
{						
	var AlertVar = Sortable.serialize('firstlist');
	/* Loop through and clean up string */
	
	var intIndexOfMatch = AlertVar.indexOf( "firstlist[]=" );
	while (intIndexOfMatch != -1){
		var AlertVar = AlertVar.replace("firstlist[]=","");
		intIndexOfMatch = AlertVar.indexOf( "firstlist[]=" );
	}
	var intIndexOfMatch = AlertVar.indexOf( "&" );
	while (intIndexOfMatch != -1){
		var AlertVar = AlertVar.replace("&",", ");
		intIndexOfMatch = AlertVar.indexOf( "&" );
	}
	if (document.getElementById('ContentSort').value != AlertVar)
		{
		document.getElementById('ContentSort').value = AlertVar;
		submitContentSortForm();
		FindListOrder();
		}
}
	
function submitContentSortForm() {
	showLoading();
	ColdFusion.Ajax.submitForm('frmContentSort', 'CustomTextsAction.cfm?Action=SubmitContentSort', callback, errorHandler);
}

function SortContentRemoveItem(CustomBookLineId){
	if(confirm('Are you sure you want to remove this item?'))
		{
			var URL = 'CustomTextsAction.cfm?Action=RemoveLineId&CustomBookLineId=' + CustomBookLineId;
			ColdFusion.navigate(URL,'divOrganizeContent');
			callback('Saved!');
		}
	}
	
	
function SortContentRemoveItemSuccessful(){
	RefreshOrganizeContent();
	RefreshContentTab();
}

//----------------------------------------------------------------------------------------------------------------------------------
//TAB 4

function RefreshPriceTotal(){
ColdFusion.navigate('CustomTextsAction.cfm?Action=RefreshPriceTotal','DivPriceTotal');
ColdFusion.navigate('CustomTextsAction.cfm?Action=RefreshPriceMiniTotal','DivPriceMiniTotal');
RefreshBookstoreOrderingInfo();

}




// CODE FOR SUBITTING FORM ON ADDITIONAL INFO ON 4TH TAB
function submitAdditionalForm() {
	showLoading();
	ColdFusion.Ajax.submitForm('AdditionalInfo', 'CustomTextsAction.cfm?Action=AdditionalInfo', callbackAddInfo, errorHandler);
}

//We have a seperate CallBack here so we dont refresh the price total on submit
function callbackAddInfo(text){ 
	var currentTime = getCurrentTime();
	document.getElementById('ContentStatus').innerHTML = "<span class='StatusBar'>" + text + " " + currentTime + "</span>";
}


function submitAgreementForm() {
	showLoading();
	ColdFusion.Ajax.submitForm('AgreementForm', 'CustomTextsAction.cfm?Action=SubmitAgreement', callback, errorHandler);
}

function SubmitDeskCopy(){
	//Book info
	var BookTitle = document.getElementById('BookTitle').value;
	var ProfName = document.getElementById('ProfName').value;
	//Additional Info
	var ProfName2 = document.getElementById('ProfessorName').value;
	var Institution = document.getElementById('NameOfSchool').value;
	var CourseName = document.getElementById('NameOfCourse').value;
	var Enrollment = document.getElementById('ExpectedEnrollment').value;
	
	if (BookTitle == ''){
		alert('Your book does not have a Title assigned.  Please go back and enter the missing information.');
		ColdFusion.Layout.selectTab('mainTab','tab1');
		ColdFusion.Layout.selectTab('tabGeneralInformation','tabBookCoverInfo');
		return 0;
	}
	else if (ProfName == ''){
		alert('Your book does not have a Professors Name assigned.  Please go back and enter the missing information.');
		ColdFusion.Layout.selectTab('mainTab','tab1');
		ColdFusion.Layout.selectTab('tabGeneralInformation','tabBookCoverInfo');		
		return 0;
	}
	else if (ProfName2 == ''){
		alert('You must provide your name in the Additional Information Section.  Please go back and enter the missing information.');		
		ColdFusion.Layout.selectTab('mainTab','tab4');
		ColdFusion.Layout.selectTab('FinalTabs','FinalStep1');		
		return 0;
	}
	else if (Institution == ''){
		alert('You must provide your School/Institution name in the Additional Information Section.  Please go back and enter the missing information.');		
		ColdFusion.Layout.selectTab('mainTab','tab4');
		ColdFusion.Layout.selectTab('FinalTabs','FinalStep1');			
		return 0;
	}	
	else if (CourseName == ''){
		alert('You must provide your Course name in the Additional Information Section.  Please go back and enter the missing information.');		
		ColdFusion.Layout.selectTab('mainTab','tab4');
		ColdFusion.Layout.selectTab('FinalTabs','FinalStep1');			
		return 0;
	}
	else if (Enrollment == ''){
		alert('You must provide your Expected Enrollment in the Additional Information Section.  Please go back and enter the missing information.');		
		ColdFusion.Layout.selectTab('mainTab','tab4');
		ColdFusion.Layout.selectTab('FinalTabs','FinalStep1');			
		return 0;
	}	
	else{
		return 1;
	}
}

function EnableFinalStep()
{
	if (document.getElementById('Agreement').checked == true)
		{
			document.getElementById('AgreementProceed').style.display = 'block';
			ColdFusion.Layout.enableTab('FinalTabs','FinalStep3');
			submitAgreementForm();
		}
	else
		{
			document.getElementById('AgreementProceed').style.display = 'none';
			ColdFusion.Layout.disableTab('FinalTabs','FinalStep3');
			submitAgreementForm();
		}
}

function RefreshBookstoreOrderingInfo()
{
ColdFusion.navigate('CustomTextsAction.cfm?Action=BookstoreOrderingInfo','BookstoreOrderingInfo');
}

function PreviewYourBook(WebId){
	var BookTitle = document.getElementById('BookTitle').value;
	var ProfName = document.getElementById('ProfName').value;
	if (BookTitle == ''){
		alert('Your book does not have a Title assigned.  Please go back and enter the missing information.');
	}
	else if (ProfName == ''){
		alert('Your book does not have a Professors Name assigned.  Please go back and enter the missing information.');		
	}
	else{
		document.getElementById('PreviewButton').style.display = 'none';
		document.getElementById('PreviewCreated').style.display = 'none';
		document.getElementById('PreviewGenerating').style.display = 'block';
		document.getElementById('PreviewError').style.display = 'none';	
		ColdFusion.Ajax.submitForm('PreviewYourBook', 'CustomBookProcessing/PreviewCreate.cfm?WebId=' + WebId, PreviewCallback, PreviewErrorHandler);
	}		
}
	
function PreviewCallback(text){
	document.getElementById('PreviewButton').style.display = 'none';
	document.getElementById('PreviewCreated').style.display = 'block';
	document.getElementById('PreviewGenerating').style.display = 'none';
	document.getElementById('PreviewError').style.display = 'none';
	newFullPopupWindow('CustomBookPreview/OpenMyPreview.cfm');
}

function PreviewErrorHandler(code, msg)
{
	document.getElementById('PreviewButton').style.display = 'none';
	document.getElementById('PreviewCreated').style.display = 'none';
	document.getElementById('PreviewGenerating').style.display = 'none';
	document.getElementById('PreviewError').style.display = 'block';
	document.getElementById('PreviewError').innerHTML = "Error! " + code + ": " + msg;
}

function resetPreview(){
	document.getElementById('PreviewButton').style.display = 'block';
	document.getElementById('PreviewCreated').style.display = 'none';
	document.getElementById('PreviewGenerating').style.display = 'none';
	document.getElementById('PreviewError').style.display = 'none';
};
	
function StartVideo(){
		swfobject.registerObject("player","9.0.98","Scripts/expressInstall.swf");
};




