// **********************************************************************
// * magicshop.js contains declarations for the magicshopitems and
// * declares an instance of the magicshop object.
// ***********************************************************************/ 

// If this alert doesn't show then there is a syntax problem with the code
//alert ('magicshop');   

// ****************************************
// * create a new magicshop entry
// ****************************************
function entry (theId, theRegion, theName, theContact, theAddr1, theAddr2, theAddr3, thePostcode,
                theTel, theFax, theEmail, theWebsite,
                theOpen1, theOpen2,
                theLogo, thePos1, thePos2, thePos3, theLastupdate) {


//alert ('magicshop ENTRY')

   this.id = theId;
   this.region = theRegion;
   this.name = theName;
   this.contact = theContact;
   this.addr1 = theAddr1;
   this.addr2 = theAddr2;
   this.addr3 = theAddr3;
   this.postcode = thePostcode;
   this.tel = theTel;
   this.fax	= theFax;
   this.email = theEmail;
   this.website	= theWebsite;
   this.open1	= theOpen1;
   this.open2	= theOpen2;
   this.logo = theLogo;
   this.pos1 = thePos1;
   this.pos2 = thePos2;
   this.pos3 = thePos3;
   this.lastupdate = theLastupdate;

//alert ('magicshop ENTRY-End')

}

// *************************************************
// * magicshop constructor creates a new magicshop
// *************************************************
function magicshop () {
//alert ('magicshop NEW')

    this.numberEntries = 0;      
    this.entries = new Array();  
    this.addEntry = magicshop_addEntry; 
    this.displayshopregionmap = magicshop_displayshopregionmap;
    this.menuindex = magicshop_menuindex; 
    this.showsoc = magicshop_showshop; 
    this.displayregion2 = magicshop_displayregion2;

//alert ('magicshop NEW-End')

//    this.displayregion = magicsoc_displayregion;  
//    this.dispheader = magicsoc_dispheader;   


}

// **********************************************************
// * magicshop_addEntry adds an item to the magicshop table
// **********************************************************

function magicshop_addEntry (pId, pRegion, pName, pContact,  
                             pAddr1, pAddr2, pAddr3, pPostcode,
                             pTel, pFax, pEmail, pWebsite,
                             pOpen1, pOpen2,
                             pLogo, pPos1, pPos2, pPos3, pLastupdate) {



   //alert ('add entry ' + pName);

   this.numberEntries += 1;
   this.entries[this.numberEntries-1] = new entry(pId, pRegion, pName, pContact, pAddr1, pAddr2, pAddr3, pPostcode, pTel, pFax, pEmail, pWebsite, pOpen1, pOpen2, pLogo, pPos1, pPos2, pPos3, pLastupdate);    

}

// **************************************************************
// * Create a TableRows to show Shop Details
// * Used Internally only: Displayregion2
// **************************************************************
function displayshoprow (theEntry) {
   var textstring = "";
   textstring +=  '<TR>';

  // **********************************
  // * Col 1: Image and Link 
  // **********************************
  
   textstring +=  '<TD Width="100" Height="90" valign="middle">' ;
   textstring +='<div id="' + theEntry.id + '" name="' + theEntry.id + '">';
   
   if (theEntry.logo != "") {
      if (theEntry.website != "") {
          textstring +=  '<a href="' + theEntry.website + '" target="_blank">';
      }
      textstring +=  '<img src="images/logos/shops/' + theEntry.logo + '" border="0">';
      if (theEntry.website != "") {
	      textstring +=  '</a>' ;
      }
   }
   
   textstring +='</div>';	        
   textstring +=  '</TD>';
	    
   //*********************************
//	*  Col 2: Details 
//	*********************************
	textstring +=  '<TD valign="top"><b>' + theEntry.name + '</b><br>';
	if (theEntry.contact != "") {
		textstring += theEntry.contact + '<br>' ;
	}
	if (theEntry.addr1 != "") {
		textstring +=  theEntry.addr1 + '<br>';
	}
	if (theEntry.addr2 != "") {
		textstring +=  theEntry.addr2 + '<br>';
	}
	if (theEntry.addr3 != "") {
		textstring +=  theEntry.addr3 + '<br>';
	}
	if (theEntry.email != "") {
		textstring +=  'Email: ' + theEntry.email  + '<br>';
	}

   if (theEntry.tel != "") {
       textstring += theEntry.tel;
       if (theEntry.fax != "") {
         textstring +=  ', ' + theEntry.fax;  
       }
       textstring += '<br>';
   }

   if (theEntry.website != "") {
      textstring +=  'Web: ' + theEntry.website  + '<br>';
   }

   if (theEntry.open1 != "") {
	  textstring +=  'Open: ' + theEntry.open1  + '<br>';
      if (theEntry.open2 != "") {  
    	  textstring +=  '      ' + theEntry.open2  + '<br>';
      }
   }
 
 
     textstring +=  'Last Updated: <i>' + theEntry.lastupdate + '</i><br><br>';
     textstring +=  '</TD>';
	        
    // *********************************
    // * Col 3: Mail, Web, Loc Icons 
	// *********************************
	 textstring +=  '<TD align=left valign="middle">';
	 if (theEntry.email != "") {
         textstring +=  '<a href="mailto:' + theEntry.email + '">';
		 textstring +=  '<img src="images/email.gif" border="0" ';
		 textstring +=  ' alt="Email: ' + theEntry.name + '"></a><br>';
	 }
	
     if (theEntry.website != "") {
		 textstring +=  '<a href="' + theEntry.website + '" target="_blank">';
		 textstring +=  '<img src="images/iconweb.gif" border="0" ';
		 textstring +=  ' alt="Web: ' + theEntry.website + '"></a><br>';
	 }
	 
	 if (theEntry.postcode != "") {
		 textstring +=  '<a href="http://www.streetmap.co.uk/streetmap.dll?Postcode2Map?code=';
		 textstring +=  theEntry.postcode + '&title=' + theEntry.name + '&nolocal=X" target="_blank">';
		 textstring +=  '<img src="images/iconmap.gif" border="0" ';
		 textstring +=  ' alt="Map of Shop"></a>';
	 }
     textstring +=  '</TD>';  
     textstring +=  '</TR>';
     return textstring;
}


// **********************************************************
// * magicshop_displayshopregionmap
// * Displays the regional Map for Shops
// * Processed From the HTM page 
// **********************************************************
function magicshop_displayshopregionmap () {

	var args = getArgs();
	var theRegion = "east";
	if (args.region) theRegion = args.region;
	//alert('>>displayshopregionmap: ' + theRegion);

  //***************************************
  //* Set Imagenames
  //***************************************
    var imagename = "construction.gif";
    var imagedetail = ' width="242" height="82" ';
    
    if (theRegion.toLowerCase() == "london") {
	    imagename = 'regionshop_london.jpg';
	    imagedetail = ' width="420" height="354"';
    }
    if (theRegion.toLowerCase() == "south east") {
	    imagename = 'regionshop_southeast.jpg';
	    imagedetail = ' width="440" height="340"';
    }
    if (theRegion.toLowerCase() == "north east") {
	    imagename = 'regionshop_northeast.jpg';
	    imagedetail = ' width="214" height="340"';
    }
    if (theRegion.toLowerCase() == "yorkshire") {
	    imagename = 'regionshop_yorkshire.jpg';
	    imagedetail = ' width="393" height="340"';
    }
    if (theRegion.toLowerCase() == "east") {
	    imagename = 'regionshop_east.jpg';
	    imagedetail = ' width="323" height="340"';
    }
    if (theRegion.toLowerCase() == "east midlands") {
	    imagename = 'regionshop_eastmid.jpg';
	    imagedetail = ' width="309" height="340"';
    }
  
    if (theRegion.toLowerCase() == "south west") {
	    imagename = 'regionshop_southwest.jpg';
	    imagedetail = ' width="434" height="340"';
    }
    if (theRegion.toLowerCase() == "north west") {
	    imagename = 'regionshop_northwest.jpg';
	    imagedetail = ' width="308" height="400"';
    }
    if (theRegion.toLowerCase() == "scotland") {
	    imagename = 'regionshop_scotland.jpg';
	    imagedetail = ' width="285" height="400"';
    }
    if (theRegion.toLowerCase() == "wales") {
	    imagename = 'regionshop_wales.jpg';
	    imagedetail = ' width="267" height="340"';
    }
    
    if (theRegion.toLowerCase() == "west midlands") {
	    imagename = 'regionshop_westmid.jpg';
	    imagedetail = ' width="325" height="340"';
    }
    if (theRegion.toLowerCase() == "ireland") {
	    imagename = 'regionshop_ireland.jpg';
	    imagedetail = ' width="279" height="340"';
    }

    //alert(imagename + ' ' + imagedetail);

	// ***************************************
	//  Title Row
	// ***************************************
	document.write('<TR><TD><IMG SRC="images/spacer.gif" HEIGHT="10"></TD></TR>' );
	document.write('<TR align=left><TD><div class="titletext">');
	document.write('Magic Shops: [' + theRegion + ']</div></TD></TR>' );
	document.write('<tr><td><img src="images/purpledot.gif" height=1 width="100%"></td></tr>' );
	document.write('<TR><TD><IMG SRC="images/spacer.gif" HEIGHT="10"></TD></TR>' );

	// ***************************************
	//  Table Row and Column
	// ***************************************
	document.write ( '<tr>' );
	
	// ***************************************
	//  Map Column
	// ***************************************
	document.write ( '<td valign="top" align="center">' );
	document.write ( '<map name="FPMap0">');
	
	// ***************************************
	//  Process each entry in the collection
	// ***************************************
   for (var i = 0; i <= this.numberEntries -1; i++) {

        var my = this.entries[i];
        if (my.region.toLowerCase() == theRegion.toLowerCase()) {
			document.write ( '<area alt="' + my.name + '" ');
			document.write ( '     shape="circle" href="#' + my.id + '" ');
			document.write ( '     coords="' + my.pos1 + ', ' + my.pos2 + ', ' + my.pos3 + '">' );
        }
    }
    
    document.write ( '</map>' );
    document.write ( '<img src="images/maps/shops/' + imagename + '" ');
    document.write ( '     border="0" usemap="#FPMap0" ');
    document.write ( imagedetail + '>');
    document.write ( '</td>');

    document.write ( '</tr>');


}

// **********************************************************
// * magicshop_menuindex
// * Displays the index to link to all shop regions
// * processed from: linshopuk HTM page
// **********************************************************
function magicshop_menuindex () {

 // ***************************************
 // * Index Column
 // ***************************************
    document.write ( '<tr>');
    document.write ( '<td>');
    document.write ( '<Table class="footer" width="450">');
    document.write ( '<tr align="left">');
    document.write ( '<td><a href="linshopregion.htm?region=South West">South West</a></td>');
	document.write ( '<td><a href="linshopregion.htm?region=North West">North West</a></td>');
	document.write ( '<td><a href="linshopregion.htm?region=West Midlands">West Mid</a></td>');
	document.write ( '<td><a href="linshopregion.htm?region=London">London</a></td>');
	document.write ( '<td><a href="linshopregion.htm?region=Yorkshire">Yorkshire</a></td>');
	document.write ( '<td><a href="linshopregion.htm?region=Scotland">Scotland</a></td>');
	document.write ( '</tr>');
    document.write ( '<tr align="left">');
	document.write ( '<td><a href="linshopregion.htm?region=South East">South East</a></td>');
	document.write ( '<td><a href="linshopregion.htm?region=North East">North East</a></td>');
	document.write ( '<td><a href="linshopregion.htm?region=East Midlands">East Mid</a></td>');
	document.write ( '<td><a href="linshopregion.htm?region=East">East</a></td>');
	document.write ( '<td><a href="linshopregion.htm?region=Wales">Wales</a></td>');
	document.write ( '<td><a href="linshopregion.htm?region=Ireland">Ireland</a></td>');
	document.write ( '<td></td>');
    document.write ( '</tr>');
    document.write ( '</table>');
	document.write ( '</td>' );
    document.write ( '</tr>');

}


// *****************************************************
// * magicsoc_display outputs the magic society table
// * built from the contents of magicshopitems.js
// *****************************************************
function magicshop_showshop (theId) {

	// ***************************************
	//  Process each entry in the collection
	// ***************************************
   var textstring = "";
   
   for (var i = 0; i <= this.numberEntries -1; i++) {
        var my = this.entries[i];
        if (my.id == theId) {
           //alert (my.name + ' ' + theId);
        	textstring = '<table class="tbltext" cellspacing="0" cellpadding="0" ';
        	textstring +=  '      border="0" width="450" >';
            textstring += displayshoprow (my)
			textstring += '</Table>';
			return textstring;
        }
   }     

}

/*
// *****************************************************
// * magicsoc_display outputs the magic society table
// * built from the contents of magicsocitems.js
// *****************************************************
function magicshop_displayregion (theRegion) {
   	var iRegion=0;

	// ***************************************
	// Table Header Row Details
	// ***************************************
	document.write ( '<DIV class="ListNuggetBody" id="Link' + theRegion + 'Body" name="Link' + theRegion + 'Body">' );
	
	document.write ( '<table class="tbltext" cellspacing="0" cellpadding="0" ' );
	document.write ( '      border="0" width="450" id="tablesoc' + theRegion + '">' ); 

	// ***************************************
	//  Process blank line if no details
	// ***************************************
	if (this.numberEntries == 0) {
		document.write ( '<TR><TD>&nbsp;</TD><TD&nbsp;</TD></TD><TD&nbsp;</TD></TR>' );
	}

	// ***************************************
	//  Process each entry in the collection
	// ***************************************
   for (var i = 0; i <= this.numberEntries -1; i++) {

        var my = this.entries[i];
        if (my.region.toLowerCase() == theRegion.toLowerCase()) {
            
//alert ('magicsoc display B ' + my.name);                 
	        iRegion += 1; 

            document.write (displaysocietyrow(my))

		   //*********************************
		   // Break Line
		   //*********************************
	        document.write( '<TR><TD colspan="3">' );
	        document.write( '<img src="images/purpledot.gif" height="1" width="100%">' );
	        document.write( '</TR></TD>' );

		} // End If Region Matches    
     }  // End for

//alert ('magicsoc display C ' + this.numberEntries);                 

     // ****************************************************************
     // * Last Rows for links to other sites with soc list (remove?)
     // ****************************************************************
	 document.write ( '<tr><td colspan="3">&nbsp;</td></tr>' );
	 document.write ( '<tr><td></td><td colspan="2">' );
	 document.write ( 'Total Societies = ' + iRegion + ' of ' + this.numberEntries + '</td></tr>' );
	 document.write ( '<tr><td colspan="3">&nbsp;</td></tr>' );


   // ***************************************
   //  End the Table
   // ***************************************
     document.write ( '</TABLE>' );
	 document.write ( '</DIV' );


} // End Function
*/


// ************************************************
// * Show all Shops for The Region 
// * Processed from linshopregion.htm
// ************************************************
function magicshop_displayregion2 () {
   

   	var iRegion=0;
	var args = getArgs();
	var theRegion = "East";
	if (args.region) theRegion = args.region;
	
	//alert('>>DisplayRegion:' + theRegion);

	// ***************************************
	// Table Header Row Details
	// ***************************************
	document.write ( '<DIV >' );
	document.write ( '<table class="tbltext" cellspacing="0" cellpadding="0" ' );
	document.write ( '      border="0" width="450" id="tablesoc' + theRegion + '">' ); 

	// ***************************************
	//  Process blank line if no details
	// ***************************************
	if (this.numberEntries == 0) {
		document.write ( '<TR><TD>&nbsp;</TD><TD&nbsp;</TD></TD><TD&nbsp;</TD></TR>' );
	}

	// ***************************************
	//  Process each entry in the collection
	// ***************************************
   for (var i = 0; i <= this.numberEntries -1; i++) {

        var my = this.entries[i];
        if (my.region.toLowerCase() == theRegion.toLowerCase()) {
            
//alert ('magicsoc display B ' + my.name);                 
	        iRegion += 1; 


            document.write (displayshoprow(my))

		   //*********************************
		   // Break Line
		   //*********************************

	        document.write( '<TR><TD colspan="3">' );

	        document.write( '<img src="images/purpledot.gif" height="1" width="100%">' );
	        document.write( '</TR></TD>' );

		} // End If Region Matches    
     }  // End for

//alert ('magicsoc display C ' + this.numberEntries);                 

     // ****************************************************************
     // * Last Rows for links to other sites with soc list (remove?)
     // ****************************************************************
	 document.write ( '<tr><td colspan="3">&nbsp;</td></tr>' );
	 document.write ( '<tr><td></td><td colspan="2">' );
	 document.write ( 'Total Magic Shops = ' + iRegion + ' of ' + this.numberEntries + '</td></tr>' );
	 document.write ( '<tr><td colspan="3">&nbsp;</td></tr>' );


   // ***************************************
   //  End the Table
   // ***************************************
     document.write ( '</TABLE>' );
	 document.write ( '</DIV' );


} // End Function

/*
// *************************************************
// * Display Collapsable regionHeader
// * Processed From:
// *************************************************
function magicshop_dispheader (theRegion, theDisplayRegion) {

	alert('>>DisplayHeader:' + theRegion + ', ' + theDisplayRegion);

	document.write( '<TABLE class="ListNuggetHeaderClosed" width="100%" cellSpacing="0" cellPadding="0" ' );
	document.write( '		id="Link' + theRegion + 'Header" name="Link' + theRegion + 'Header">' );
	document.write( '	<TR>' );
	
	document.write( '		<TD class="ListNuggetTitleCellBlue" ');
	document.write( '           onselectstart="window.event.cancelBubble=true; return false;" ' );

	document.write( '			onclick="PartWrapperToggle(\'Link' + theRegion + '\');">' );
	document.write( '		<A class="ListNuggetTitle" ' );
	document.write( '			onclick="return PartWrapperToggle(\'Link' + theRegion + '\');" ' );
	document.write( '			href="javascript:PartWrapperToggle(\'Link' + theRegion + '\');">' );
	document.write( theDisplayRegion);
	document.write( '		</A>');
	document.write( '		</TD>' );
	document.write( '		<TD class="ListNuggetButtonCellBlue" ' );
	document.write( '			onclick="PartWrapperToggle(\'Link' + theRegion + '\');">' );
	document.write( '			<DIV class="ListNuggetButton">' );
	document.write( '			<IMG class="ListNuggetUpButton" ' );
	document.write( '				id="Link' + theRegion + 'Up" ' );
	document.write( '				height="17" alt="Hide" src="images/gold-chevron_up.gif" ' );
	document.write( '				width="17" align="right" border="0" ' );
	document.write( '				name="Link' + theRegion + 'Up">' );
	document.write( '			<IMG class="ListNuggetDownButton" ' );
	document.write( '				id="Link' + theRegion + 'Down" ' );
	document.write( '			    height="17" alt="Show" src="images/gray-chevron_down.gif" ' );
	document.write( '				width="17" align="right" border="0" ' );
	document.write( '				name="Link' + theRegion + 'Down">' );
	document.write( '			</DIV>' );
	document.write( '		</TD>' );
	document.write( '	</TR>' );
	document.write( '</TABLE>' );

}
*/
// ***************************************
// * get querystring arguments
// ***************************************
function getArgs() {

	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split(",");
	for (var i = 0; i < pairs.length; i++) {
		var pos = pairs[i].indexOf('=');
		if (pos == -1) continue;
		var argname = pairs[i].substring(0,pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
   }

// *****************************************
// * Create an instance of the Magicsoc object
// *****************************************

var Magicshop = new magicshop();
