// Misc tools for the Datastore created by Brent Burval, feel free to use,
// give credit where credit is due,
// remeber to catch & release,
// listen to Moby

// Popup Windows

function PopupPrintSetupWindow(reporttype,searchby) {

	var strSearchBy

	if (searchby == 'allentries') {	strSearchBy = 'searchby=allentries' } else { strSearchBy = '' }

	if (GetCookie("SelectIDs") != null && reporttype == "ctc") {

		PrintSetupWindow = window.open('reportsetup.asp?ctc=1&' + strSearchBy,'PrintSetupWindow','width=398,height=406,status=0,resizable=1');

	}

	else if (GetCookie("SelectIDs") != null) {

		PrintSetupWindow = window.open('reportsetup.asp?' + strSearchBy,'PrintSetupWindow','width=398,height=406,status=0,resizable=1');

	}


	else {

		alert("There are no titles selected");

	}
}

// Email Friend pop-up window
function popup_ASEmailFrndWin() {
	NewASEmailFrndWin = window.open('','ASEmailFrndWindow','scrollbars=1,width=500,height=500,resizable=1');
}

// Generic pop-up window
function popup_ASINVReqWinwindow() {
	NewASINVReqWin = window.open('','ASINVReqWindow','width=500,height=500,resizable=1');
}

// Artstore Shopping Cart Window for MGI items BJB20020828

var NewShoppingCartWindow = null;

function ShoppingCart_Window(){

	if (NewShoppingCartWindow != null) { // WINDOW ALREADY OPEN

		if (NewShoppingCartWindow.closed == false) {  // WINDOW IS OPEN

			// RECONNECT TO WINDOW

			NewShoppingCartWindow = window.open('','ShoppingCart_Window');

			// CLOSE WINDOW BECAUSE MINIMIZED WINDOW WILL NOT GET FOCUS BJB20050705

			NewShoppingCartWindow.close();

		}

	}

	// OPEN WINDOW

	NewShoppingCartWindow = window.open('','ShoppingCart_Window','toolbar=1,location=0,directories=0,status=1,menubar=1,resizable=1,scrollbars=1,width=650,height=480');

}


// lexicon window BJB20020114
function Popup_Lex_Window(){
	NewLexWindow = window.open('','Lex_Window','width=780,height=550,status=0,resizable=1');
}

// bibliography windows
function Popup_Bibliography(){
	NewBibliographyWindow = window.open('','BibliographyWindow','width=670,height=450,status=0,resizable=1');
}

// bibliography menu window
function Popup_Bibliography_Menu(){
	NewBibliographyMenu = window.open('','BibliographyMenu','width=500,height=130,status=0,resizable=1');
}

// main boolean search window
function PopupMenu_PrintsPrices_BooleanSearchWindow(){
	BooleanSearchWindow = window.open('','Menu_PrintsPrices_BooleanSearchWindow','width=670,height=600,status=0,resizable=1');
}

// main boolean search window
function PopupMenu_PrintsPrices_BooleanSearchWindow3(strURL){
	BooleanSearchWindow = window.open(strURL,'Menu_PrintsPrices_BooleanSearchWindow','width=670,height=600,status=0,resizable=1');
}

// secondary boolean search window - such as mediums papers etc
function PopupMenu_PrintsPrices_BooleanSearchWindow2(strURL){

	if (strURL == null) {	

		BooleanSearchWindow2 = window.open('','Menu_PrintsPrices_BooleanSearchWindow2','width=450,height=300,status=0,resizable=1');
	
	}

	else {

		BooleanSearchWindow2 = window.open(strURL,'Menu_PrintsPrices_BooleanSearchWindow2','width=450,height=300,status=0,resizable=1');
	
	}

}

function PopupMenu_AdvertisersWindow() {
	AdvertisersWindow = window.open('','Menu_AdvertisersWindow','width=650,height=250,status=0,resizable=1');
}

function PopupMenu_PrintsPrices_SortCurrentWindowWindow(){
	SortCurrentWindowWindow = window.open('','Menu_PrintsPrices_SortCurrentWindowWindow','width=398,height=245,status=0,resizable=1');
}

function PopupMenu_FileWindow(){
	FileWindow = window.open('','Menu_FileWindow','width=500,height=500,status=0,resizable=1');
}

function PopupMenu_EditWindow(){
	EditWindow = window.open('','Menu_EditWindow','width=450,height=100,status=0,resizable=1');
}

function PopupMenu_WindowWindow(){
	WindowWindow = window.open('','Menu_WindowWindow','width=450,height=160,status=0,resizable=1');
}


function PopupMenu_PrintsPricesWindow(){
	PrintsPricesWindow = window.open('','Menu_PrintsPricesWindow','width=640,height=500,status=0,resizable=1');
}

function PopupMenu_PrintsPrices_FreeTextSearchWindow(){
	FreeTextSearchWindow = window.open('menu_printsprices_freetextsearch.htm','Menu_PrintsPrices_FreeTextSearchWindow','width=600,height=170,status=0,resizable=1');
}

//Set Datastore Window Variables

WinWi = 500
WinHt = 375

function NewDatastoreWindow(){

	var RandNumb = Math.round(Math.random() * 1000000)	

	var NewWindowName = "NewDatastoreWindow" + RandNumb.toString()

	var NewWindowName = window.open('../datastore.asp',NewWindowName,'width=' + WinWi + ',height=' + WinHt + ',status=1,resizable=1');

	// WORKS IN IE NewDatastoreWindow = window.open('datastore.asp','','width=' + WinWi + ',height=' + WinHt + ',status=1,resizable=1');
}

function NewDatastoreWindowArtist(){

	var RandNumb = Math.round(Math.random() * 1000000)	

	var NewWindowName = "NewDatastoreWindowTitle" + RandNumb.toString()

	var NewWindowName = window.open('datastore.asp',NewWindowName,'width=' + WinWi + ',height=' + WinHt + ',status=1,resizable=1');

	// WORKS IN IE NewDatastoreWindowTitle = window.open('datastore.asp','','width=' + WinWi + ',height=' + WinHt + ',status=1,resizable=1');
}

function NewDatastoreWindowCatNo(){

	var RandNumb = Math.round(Math.random() * 1000000)	

	var NewWindowName = "NewDatastoreWindowCatno" + RandNumb.toString()

	var NewWindowName = window.open('datastore.asp?searchby=catno',NewWindowName,'width=' + WinWi + ',height=' + WinHt + ',status=1,resizable=1');

	// WORKS IN IE NewDatastoreWindowCatno = window.open('datastore.asp?searchby=catno','','width=' + WinWi + ',height=' + WinHt + ',status=1,resizable=1');
}

function fulladwindow() {
	fullad_window = window.open('','fullad_window','width=700,height=570,status=0,resizable=1');
}

function HelpWindow() {
	Help_Window = window.open('','Help_Window','width=450,height=140,status=0,resizable=1');
}

function UnderConstructionWindow() {
	underconstruction_window = window.open('','underconstruction_window','width=300,height=260,status=0,resizable=1');
}

// Misc Functions

function AllEntries() { // popup boolean search window

	PopupMenu_PrintsPrices_BooleanSearchWindow();
	BooleanSearchWindow.location.href = "menu_printsprices_booleansearch.asp?searchby=allentries"
	
}

function InformBooleanSearch(){
	alert("You can only query a TITLE or ALL ENTRIES window");
}

function InformBooleanSearch2(){

	if (document.URL.indexOf("bookstore")>=0) {
		alert("Please select an author prior to filtering the data");
	} else {
		alert("Please select an artist prior to filtering the data");
	}

}

function InformTextSearch(){
	// alert("You can only search a TITLE or ALL ENTRIES window");
	alert("You can only query a TITLE or ALL ENTRIES window");
}

function DeleteSelectedTitles(){

	if (confirm("Are you sure you want to remove all selections?")) {

		DeleteCookie('SelectIDs');
	
		var URL = location.href

		if (URL.indexOf('catno') == -1) {		

			var StartAtElement = 2

		}

		else {

			var StartAtElement = 0

		}

		//alert(URL);

		if (URL.indexOf('buttons.asp') != -1) {		

			var TitlesURL = parent.titles.location.href

			//alert(TitlesURL);
			//alert(TitlesURL.indexOf('titlesbyartist.htm'));


			if (TitlesURL.indexOf('titlesbyartist.asp') != -1) { 		

				for (var i = StartAtElement; i<parent.titles.document.Form1.elements.length;i++) {

					var elementname = parent.titles.document.Form1.elements[i];
					elementname.checked = false;
	
				}

			}

		}

		else {		

			var TitlesURL = opener.parent.titles.location.href

			//alert(TitlesURL);
			//alert(TitlesURL.indexOf('titlesbyartist.htm'));


			if (TitlesURL.indexOf('titlesbyartist.asp') != -1) { 		

				for (var i = StartAtElement; i<opener.parent.titles.document.Form1.elements.length;i++) {

					var elementname = opener.parent.titles.document.Form1.elements[i];
					elementname.checked = false;
					self.close();
	
				}

			}

		}


	}
}

function ClearBooleanSearch(){

	DeleteCookie("BooleanFilter");
	DeleteCookie("BooleanSaleTypes");
	DeleteCookie("SelectMediumIDs");
	DeleteCookie("SelectAuctioneerIDs");
	DeleteCookie("SelectPaperTypeIDs");
	DeleteCookie("BlnFiltSaleOnly"); // BJB 20020927 Artstore item
}

function GetCookieForFormValue(name) {
	FormValue = null;
	FormValue = GetCookie(name);
	if (FormValue==null) {
		FormValue="";
	}
	return FormValue;
	FormValue = null;
}

function GetCheckBoxState(checkboxname, formname) {
	if (GetCookie(checkboxname) == "1") {
		document[formname][checkboxname].checked = true;
	}
}

function SetCheckBoxCookie(checkboxname, formname) {
	if (GetCookie(checkboxname) == "1") {	
		SetCookie(checkboxname, "0");
	}
	else {
		SetCookie(checkboxname, "1");	
	}
}	

function CheckAllCheckBoxes(formname, booleanvalue) {
  for (var i=0;i<document[formname].elements.length;i++)
    {
    var elementname = document[formname].elements[i];
      elementname.checked = booleanvalue;
    }
}
