//=====================================================================||
//               BLACK DOG CAFE JavaScript                             ||
//                                                                     ||
// 			                                               ||
// JavaScript Shop Module, V.1.0                                       ||
//=====================================================================||

browserName = navigator.appName;
browserVer = parseInt ( navigator.appVersion );

version = "n2";
if ( browserName == "Netscape" && browserVer >= 3 ) version = "n3";
if ( browserName == "Microsoft Internet Explorer" && browserVer >=4 ) version = "e4";

//---------------- HEADER ----------------------------------

function header( floating_text ) {
   var strOutput      = "";   //String to be written to page

	strOutput +=  "<tr>";
	strOutput +=     "<td height=\"20%\" width=\"100%\" colspan=\"4\" align=\"center\" valign=\"bottom\"  background=\"images/head-graphic-6.jpg\" style=\"background-repeat: no-repeat;\" bgcolor=\"#FFFFDB\" width=\"100%\" width=\"100%\"  scope=\"col\">";
	strOutput +=  	    "<table width=\"100%\" height=\"100%\" align=\"left\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
	strOutput +=  	       "<tr><td align=\"center\" width=\"30%\" height=\"170\" valign=\"bottom\" colspan=\"1\">";
	strOutput +=           "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"images/logo.gif\" width=\"234\" width=\"139\"><br />";
	strOutput +=  	       "</td>";
        strOutput +=  	       "<td align=\"left\" valign=\"center\" width=\"70%\" height=\"170\" colspan=\"1\">";
        strOutput +=           "<br /><br /><br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src=\"http://www.blackdog-cafe.com/images/headtext.gif\">";
        strOutput +=  	       "</td></tr>";
        //----------------- NAVIGATION LINKS ----------------------
        strOutput +=  	       "<tr><td width=\"100%\" height=\"40\" align=\"center\" valign=\"bottom\" colspan=\"2\">";
        strOutput +=              "<table width=\"78%\" height=\"100%\" align=\"left\" valign=\"top\" border=\"0\">";
        strOutput +=              "<tr>";
        strOutput +=                "<td align=\"center\"><a href=\"http://www.blackdog-cafe.com/index.html\">BDC Home</a></td>";
        strOutput +=                "<td align=\"center\"><a href=\"http://www.blackdog-cafe.com/galleries.html\">Artist Galleries</a></td>";
        strOutput +=                "<td align=\"center\"><a href=\"http://www.cafepress.com/blackdogcafe\">CafeStore </a></td>";
        strOutput +=                "<td align=\"center\"><a href=\"http://www.blackdog-cafe.com/nonsense.html\">Opinions & Nonsense</a></td>";
        strOutput +=                "<td align=\"center\"><a href=\"http://www.blackdog-cafe.com/information.html\">Information </a></td>";
        strOutput +=                "<td align=\"center\"><a href=\"mailto:info@blackdog-cafe.com\">Contact</a></td>";     
        strOutput +=              "</tr>";
        strOutput +=              "</table>" ;
	strOutput +=  	       "</td></tr>";
	strOutput +=  	    "</table>";
	strOutput +=     "</td>";
	strOutput +=  "</tr>";

   document.write(strOutput);
   document.close();
}
  



//-------------------------------------------------------------------------------
function left_column( pagename ) {
  // THIS IS THE LEFT COLUMN (Left side of page) that is repeated verbatim on each page  
   var strOutput      = "";   //String to be written to page
           strOutput += "<tr>";
	   strOutput += "<td rowspan=\"1\" colspan=\"1\" align=left valign=top width=\"5%\">";			   
	   strOutput += "<img src=\"http://www.blackdog-cafe.com/images/sidebar.gif\" height=\"780\" width=\"68\">";
	   strOutput += "</td>";

//---------THIS IS THE MAIN CENTER COLUMN WHERE THE CONTENT GOES-------------------
	   
           strOutput += "<td width=\"75%\" align=\"LEFT\" valign=\"top\"><br />";

   document.write(strOutput);
   document.close();
}

//-------------------------------------------------------------------------------
function right_column( pagename ) {
  // THIS IS THE MAIN MENU (Right side of page) that is repeated (almost) verbatim on each page  
   var strOutput      = "";   //String to be written to page

	strOutput +=    "</td>";
	strOutput +=    "<td rowspan=\"1\" colspan=\"1\" align=center valign=top width=\"15%\" ><br />";

        strOutput +=     "<a href=\"http://www.cafepress.com/blackdogcafe\">";
        strOutput +=	 "<img src=\"http://www.blackdog-cafe.com/images/shop-logo.gif\" alt=\"Shop the CafeStore\" name=\"shop-logo\" width=\"125\" height=\"150\" border=\"0\"></a>";


	if ( ( pagename == "holt" ) || ( pagename == "affiliate" ) || ( pagename == "gallery" ) ) {
	     // use skyscraper ad format
	   strOutput +=          "<table width=\"100%\" height=\"10\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#5D5A38\">";
	   strOutput +=            "<tr><td width=\"100%\" height=\"25\" align=\"center\"  scope=\"col\">";
	   strOutput +=              "<IFRAME SRC=\"http://www.blackdog-cafe.com/embedded/embedAS-SS.html\" WIDTH=\"130\" height=\"620\" FRAMEBORDER=\"0\" SCROLLING=\"no\" ></IFRAME>";
	   strOutput +=            "</td></tr>";
	   strOutput +=          "</table> ";
	}
	else 
        {
	   //   use text ad format
	   strOutput +=          "<table width=\"100%\" height=\"10\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#5D5A38\">";
	   strOutput +=            "<tr><td width=\"100%\" height=\"25\" align=\"center\"  scope=\"col\">";
	   strOutput +=              "<IFRAME SRC=\"http://www.blackdog-cafe.com/embedded/embedAS-TA.html\" WIDTH=\"130\" height=\"270\" FRAMEBORDER=\"0\" SCROLLING=\"no\" ></IFRAME>";
	   strOutput +=            "</td></tr>";
	   strOutput +=          "</table> ";
          
	}	

	   //   Google reference
	   strOutput +=          "<table width=\"100%\" height=\"10\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#5D5A38\">";
	   strOutput +=            "<tr><td width=\"100%\" height=\"25\" align=\"left\"  scope=\"col\">";
	   strOutput +=              "<IFRAME SRC=\"http://www.blackdog-cafe.com/embedded/embedGR.html\"  WIDTH=\"100%\" height=\"100\" FRAMEBORDER=\"0\" SCROLLING=\"no\"></IFRAME>";
	   strOutput +=            "</td></tr>";
	   strOutput +=          "</table> ";

        // WRAP UP
	   strOutput +=        "</td>";  
           //---THIS IS A SPACER COLUMN------
           strOutput += "<td width=\"5%\" height=\"80%\" rowspan=\"1\" colspan=\"1\" align=left valign=top >";			   
	   strOutput +=    "&nbsp;";
	   strOutput += "</td>";
           strOutput += "</tr>";
	
   document.write(strOutput);
   document.close();
}

//-------------------------------------------------------------------------------
function footer( pagename ) {  
   var strOutput      = "";   //String to be written to page

	strOutput +=  "<tr>";
	strOutput +=  "   <td height=\"5\" colspan=\"4\" align=\"center\" valign=\"middle\" bgcolor=\"#FFFFDB\">";
	strOutput +=  "      <span class=\"style14\">";
	strOutput +=  " 	For information contact </span><a href=\"mailto:info@blackdog-cafe.com\" span class=\"style16\">info@blackdog-cafe.com </span></a>."; 
	strOutput +=  "	        &nbsp; &nbsp; <span class=\"style14\">  Website Design Copyright Blackdog Cafe 2006 ";
	strOutput +=  "	     </span>";
	strOutput +=  "   </td>";
	strOutput +=  "</tr>";

   document.write(strOutput);
   document.close();
}

//-------------------------------------------------------------------------------

//---------------- USER COOKIE FUNCTIONALITY ----------------------------------
   function setUserCookie(username) 
   {
      cookie_name = "artistCookie";
      if(document.cookie != document.cookie) 
      {
         index = document.cookie.indexOf(cookie_name);}
      else 
      { index = -1;}

      if (index == -1)
      {
         //     ATTENTION:  Note the expiration date here!!!
         document.cookie=cookie_name+"="+username+"; expires=Monday, 04-Apr-2010 05:00:00 GMT";
      }
   }

   function getUserCookie() 
   {
      cookie_name = "artistCookie";
      var username;
      if(document.cookie)
      {
         index = document.cookie.indexOf(cookie_name);
         if (index != -1)
         {
            namestart = (document.cookie.indexOf("=", index) + 1);
            nameend = document.cookie.indexOf(";", index);
            if (nameend == -1) {  nameend = document.cookie.length;  }
            username = document.cookie.substring(namestart, nameend);
            return username;
         }
      }
   }
//---------------- END USER COOKIE FUNCTIONALITY ----------------------------------

//----------------LOGIN FUNCTIONALITY ----------------------------------
      var reqXML;  //global variables to hold our request object
      var url;     //global variable to hold the url
      var strName; //global variable to hold the username

      //Create our function to start the request
      function VerifyLogin(){

        //inform there is an action!
        document.getElementById("spanLog").innerHTML = "<span style='color:green'> Checking Information</span>";

        //Grab our form field values
        strName = document.Form1.username.value;
        var strPass = document.Form1.password.value;
        
        //Make the URL for the request
        //  strName_strPass.html
        url = "http://www.blackdog-cafe.com/affiliates/private/" + strName + '_' + strPass + ".html";

        //determine if the browser is Moz, FF, NN, Op
        if (window.XMLHttpRequest){ 
          reqXML = new XMLHttpRequest();            //set the request
          reqXML.onreadystatechange = LoginUser;    //function to call on each set
          reqXML.open("GET", url, true);            //set the page to request
          reqXML.send(null);                        //initialize the request 
        }
        //ActiveX - can we say IE?
        else if(window.ActiveXObject){ 
          //Create our RequestObject
          reqXML = new ActiveXObject("Microsoft.XMLHTTP"); 
          if(reqXML){ 
            reqXML.onreadystatechange = LoginUser  //function to call on each step
            reqXML.open("GET", url, true);         //set the page to request
            reqXML.send(null);                     //initialize the request
          }
        }
        else{  //I do not support this so I need to do something!
           window.location.href = "http://www.blackdog-cafe.com";
        }       
      }
          
      function LoginUser(){

        //Look to see if the request is in the 4th stage (complete)         
        if(reqXML.readyState == 4){
          //Make sure that we get a sucess page status  
          if(reqXML.status == 200)
          {
            //set the global username and change our location
            setUserCookie(strName);
            window.location.href = "http://www.blackdog-cafe.com/affiliates/priv-artist.asp";
        //    else if (url == "http://www.blackdog-cafe.com/affiliates/private/woody_ginger5126.html")
        //    {
        //       setUserCookie("woody");
        //       window.location.href = "http://www.blackdog-cafe.com/affiliates/priv-artist.html";
        //    }
        //    else
        //       document.getElementById("spanLog").innerHTML = "<span style='color:green'> Unable to Log In: Please Contact the Webmaster. </span>";
          }
          //For all of the wrong error pages here
          else{
            document.getElementById("spanLog").innerHTML = "<span style='color:red'> Error: username and password is not correct!</span>";
          }
        }
      }


//----------------END LOGIN FUNCTIONALITY ----------------------------------

function formatCurrency(num) 
{
   num = num.toString().replace(/\$|\,/g,'');
   if(isNaN(num))
      num = "0";
   sign = (num == (num = Math.abs(num)));
   num = Math.floor(num*100+0.50000000001);
   cents = num%100;
   num = Math.floor(num/100).toString();
   if(cents<10)
      cents = "0" + cents;
   for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
      num = num.substring(0,num.length-(4*i+3))+','+
   num.substring(num.length-(4*i+3));
   return (((sign)?'':'-') + '$' + num + '.' + cents);
}

//-------------------------Artist Data Table -------------------

function loadArtistData()
{
   if (window.ActiveXObject)
   {
      xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.onreadystatechange = function () 
      {
         if (xmlDoc.readyState == 4) showArtistData()
      };
   }
   // code for Mozilla, etc.
   else if (document.implementation && document.implementation.createDocument)
   {
      xmlDoc = document.implementation.createDocument("", "", null);
      xmlDoc.onload = showArtistData;
   }
   else
   {
      alert('Your browser can\'t handle this script');
      return;
   }
   xmlDoc.load("http://www.blackdog-cafe.com/affiliates/artist.xml");  //  HARDCODED FILE NAME:  ENSURE THIS FILE IS VALID!!!

}
//------------------------------------------------------------------------------- 
      //SAMPLE code to get http load params
      //urlquery=location.href.split("?");
      //rnurlterms=urlquery[1].split(",");
      //tstr += "url is: " + " " + urlquery + "<br />";
//-------------------------------------------------------------------------------
function showArtistData()
{
      var qty;
      var comm;
      var subtotal = 0;
      var total    = 0;

      username = getUserCookie();

      var tstr    = "";  //generalized output string
      tstr += "<B>Hello " + " " + username + "!</B><br /><br />";  //Identify the user!!!
      tstr += "This is your personal account summary as of: ";

      var items          = xmlDoc.getElementsByTagName("default"); 
      var products       = items[0].getElementsByTagName("prod");
      tstr += xmlDoc.getElementsByTagName('datesold'  )[0].firstChild.data + ".";
      tstr += "&nbsp; At the bottom of this page you may upload images for your account. <br /><br />";

      items          = xmlDoc.getElementsByTagName(username); 
      products       = items[0].getElementsByTagName("prod");

      tstr += '<table width="100%" border="1">'; 
      tstr += '<tr>';
      tstr += '<th bgcolor="5d5a38"><span class=\"style22\">Date         </span>  </th>';
      tstr += '<th bgcolor="5d5a38"><span class=\"style22\">Product Name </span>  </th>';
      tstr += '<th bgcolor="5d5a38"><span class=\"style22\">Qty          </span>  </th>';
      tstr += '<th bgcolor="5d5a38"><span class=\"style22\">Commission   </span>  </th>'; 
      tstr += '<th bgcolor="5d5a38"><span class=\"style22\">Subtotal     </span>  </th>';
      tstr += '</tr>'; 

      for(var i=0; i<products.length; i++) 
      { 
         tstr += '<tr align=\"left\">'; 
         tmpstr = products[i].getElementsByTagName("datesold")[0].firstChild.data;
         tstr += '<td width="20%" align="center">' + tmpstr + '</td>';
         tmpstr = products[i].getElementsByTagName("descript")[0].firstChild.data;
         tstr += '<td width="35%" align="left">'   + tmpstr + '</td>'; 
         tmpstr = products[i].getElementsByTagName("quantity")[0].firstChild.data;
         qty  = parseInt(tmpstr) ;
         tstr += '<td width="10%" align="center">' + tmpstr + '</td>'; 
         tmpstr = products[i].getElementsByTagName("commission")[0].firstChild.data;
         comm = parseFloat(tmpstr);
         tstr += '<td width="15%" align="right">'  + tmpstr + '</td>';
         subtotal = comm * qty;
         tstr += '<td width="20%" align="right">'  + formatCurrency(subtotal) + '</td>';
         tstr += '</tr>'; 
         total    += subtotal;
      } 
      tstr += '<tr align=\"left\">'; 
      tstr += '<td bgcolor="5d5a38" width="20%" align="center"></td>';
      tstr += '<td bgcolor="5d5a38" width="35%" align="left"></td>'; 
      tstr += '<td bgcolor="5d5a38" width="10%" align="center"></td>'; 
      tstr += '<td bgcolor="5d5a38" width="15%" align="center"><span class=\"style22\"><b>Total</b></span></td>';
      tstr += '<td width="20%" align="right">'  + formatCurrency(total) + '</td>';
      tstr += '</tr>'; 
      tstr += '</table>';


      tstr += "<br /><br /><b>Account History</b><br /><br />";

      //NOW show the history
      items          = xmlDoc.getElementsByTagName(username); 
      products       = items[0].getElementsByTagName("historyentry");

      tstr += '<table width="100%" border="1">'; 
      tstr += '<tr>';
      tstr += '<th bgcolor="5d5a38"><span class=\"style22\">Date         </span>  </th>';
      tstr += '<th bgcolor="5d5a38"><span class=\"style22\">Balance      </span>  </th>';
      tstr += '<th bgcolor="5d5a38"><span class=\"style22\">Sales        </span>  </th>';
      tstr += '<th bgcolor="5d5a38"><span class=\"style22\">Payment      </span>  </th>'; 
      tstr += '<th bgcolor="5d5a38"><span class=\"style22\">New Balance  </span>  </th>';
      tstr += '</tr>'; 

      for(var i=0; i<products.length; i++) 
      { 
         tstr += '<tr align=\"left\">'; 
         tstr += '<td width="20%" align="center">' + products[i].getElementsByTagName('date'      )[0].firstChild.data + '</td>';
         tstr += '<td width="20%" align="left">'   + products[i].getElementsByTagName('balance'   )[0].firstChild.data + '</td>'; 
         tstr += '<td width="20%" align="center">' + products[i].getElementsByTagName('sales'     )[0].firstChild.data + '</td>'; 
         tstr += '<td width="20%" align="right">'  + products[i].getElementsByTagName('payment'   )[0].firstChild.data + '</td>';
         tstr += '<td width="20%" align="right">'  + products[i].getElementsByTagName('newbalance')[0].firstChild.data + '</td>';
         tstr += '</tr>'; 
      } 
      tstr += '</table>';

      document.getElementById('artistdata').innerHTML = tstr; 
}
//-------------------------END of Artist Data Table -------------------



//-------------------------Products and Pricing Table -------------------

//-------------------------------------------------------------------------------
function newBrWindow(theURL,winName,features) { //v2.0  
   window.open(theURL,winName,features);
   return false;
}
//-------------------------------------------------------------------------------
function loadXML()
{
   if (window.ActiveXObject)
   {
      xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.onreadystatechange = function () 
      {
         if (xmlDoc.readyState == 4) showData()
      };
   }
   // code for Mozilla, etc.
   else if (document.implementation && document.implementation.createDocument)
   {
      xmlDoc = document.implementation.createDocument("", "", null);
      xmlDoc.onload = showData;
   }
   else
   {
      alert('Your browser can\'t handle this script');
      return;
   }
   xmlDoc.load("http://www.blackdog-cafe.com/catalog-pp.xml");  //  HARDCODED FILE NAME:  ENSURE THIS FILE IS VALID!!!
}
//-------------------------------------------------------------------------------
function showData()
{
      var tstr    = "";  //generalized output string
           var catalogitems=xmlDoc.getElementsByTagName("catalog"); 
           var products=catalogitems[0].getElementsByTagName("prod");
 
      tstr += '<table width="90%" border="1">'; 
      tstr += '<tr><th bgcolor="5d5a38"><span class=\"style22\">Description</span></th><th bgcolor="5d5a38"><span class=\"style22\">Retail</span></th><th bgcolor="5d5a38"><span class=\"style22\">Commission</span></th></tr>'; 
      for(var i=0; i<products.length; i++) { 

         tstr += '<tr align=\"left\">'; 
         tstr += '<td width="50%" align="left">' ; 
         lnkstr = xmlDoc.getElementsByTagName('urlink')[i].firstChild.data;
 
         tstr += '<a href=\"' + lnkstr + '\"'; 
         tstr += ' onclick=\"newBrWindow(\'' + lnkstr +'\',' ;  
         tstr +=  "'','resizable=yes,width=400,height=500');return false\">" ;
         tstr += xmlDoc.getElementsByTagName('descript')[i].firstChild.data; 
         tstr += '</a></td>';

         tstr += '<td width="25%" align="right">' + xmlDoc.getElementsByTagName('retail')[i].firstChild.data + '</td>'; 
         tstr += '<td width="25%" align="right">' + xmlDoc.getElementsByTagName('commission')[i].firstChild.data + '</td>'; 
         tstr += '</tr>'; 
      } 
      tstr += '</table>';
      document.getElementById('catalog').innerHTML = tstr; 

}
//-------------------------END of Products and Pricing Table -------------------

//-------------------------------------------------------------------------------
// Start of no right click script <script language="JavaScript">
// No rightclick script.
// Find more great scripts and applets at the JavaFile!
// http://www.javafile.com
// Do not delete this header!

var message="Right Click has been diabled on this page."; // Put your message for the alert box between the quotes.

// Don't edit below!

function click(e) {
	if (document.all) {
		if (event.button == 2) {
			alert(message);
			return false;
		}
	}
	if (document.layers) {
		if (e.which == 3) {
			alert(message);
			return false;
		}
	}
}

if (document.layers) {  document.captureEvents(Event.MOUSEDOWN);  }

document.onmousedown=click;





