var loadedLevel2CategoryDivID = null; // the div id for the level 2 sub category that is open

var categoryTitle = ''; // category title
var subCateogryTitle_Level2 = '';
var subCateogryTitle_Level3 = '';

function GetXmlHttpObject() {
 var xmlHttp=null;
 try { // Firefox, Opera 8.0+, Safari
   xmlHttp=new XMLHttpRequest();
 } catch (e) {
  // Internet Explorer
  try {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
  }
 return xmlHttp;
} // end of GetXmlHttpObject



function LoadIndexPage() {
 LoadPageHeader();
 LoadSearchNewsTicker();

 LoadLeftColumn();
 LoadRightColumn();

 LoadPageFooter();
 


 if(document.location.hash != "") { // if hash URL
  var url;
  var formFlag = /##/;
  var categoryFlag = /#-/;
  
  // if hash is for a specific page 
  if (formFlag.test(document.location.hash)) { // if hash is for a form page
   url = "_content_form.php?type=" + (document.location.hash).replace("##", "");


   LoadPageContent(url);

  } else if(categoryFlag.test(document.location.hash)) { // if hash is for a category page
   LoadBreadCrumbs('_content_home.php');
   LoadPageContent('_content_home.php'); 
   // add stub to load product specific pages
   // alert("content page");
   
   
  } else { // for regular content pages 
   url = "_content_" + (document.location.hash).replace("#", "") + ".php";
   LoadBreadCrumbs(url);
   LoadPageContent(url); 
 } // end of if hash is for a specific page 


 } else { // index page
  //LoadPageBody('_content_home.php');	 
  LoadBreadCrumbs('_content_home.php');
  LoadPageContent('_content_home.php');
 } // end of if hash URL




} // end of LoadIndexPage



function LoadPage(url) {
 LoadPageHeader();
 LoadSearchNewsTicker();
 LoadBreadCrumbs(url);
 LoadLeftColumn();
 LoadRightColumn();
 LoadPageContent(url);
 LoadPageFooter();
} // end of LoadIndexPage



function LoadPageHeader() { 
 LoadURLContent('libHeader.php?echo=1', 'pageHeader')
} // end of LoadPageHeader



function LoadPageFooter() { 
 LoadURLContent('libFooter.php?echo=1', 'pageFooter')
} // end of LoadPageFooter


function LoadSearchNewsTicker() {
// LoadURLContent('libSearchNewsTicker.php?echo=1', 'searchNewsTicker');		
} // end of LoadSearchNewsTicker()


function LoadLeftColumn() {
 var url = "_content_product_category.php";
 LoadURLContent(url, 'leftColumn');
} // end of LoadLeftColumn



function LoadRightColumn() {
  LoadURLContent('libBody.php?echo=1&functionName=RightColumn', 'rightColumn');	
} // end of LoadRightColumn





function LoadProductList() {
 var url = "_content_products_list.php";
 
 LoadPageContent(url);
} // end of LoadRightColumn



function LoadPageContent(url) {
 // laod bread crumbs here
 LoadBreadCrumbs(url, '');
 LoadURLContent(url, 'pageContent');
} // end of LoadPageContent



function LoadSalesmanDialog() {
 document.getElementById("salesmanDialogImage").src = "images/salesman_dialog/salesman_" + Math.ceil(5 * Math.random()) + ".jpg";	
 return;
} // end of LoadSalesmanDialog



function LoadBreadCrumbs(contentURL, title) {
 var url = '_content_bread_crumbs.php?contentURL=' + contentURL + "&title=" + title;
 var elementID = 'breadCrumbs';

 var xmlHttp;
 var HTTPContent;

 xmlHttp = GetXmlHttpObject();
 if (xmlHttp == null) {
  alert ("Your browser does not support AJAX!");
  return;
 } 
 
 if(elementID == "breadCrumbs") {
  document.getElementById(elementID).innerHTML = '';
  document.getElementById(elementID).innerHTML = '<div align="center"><span class="text4"><img src="images/loading/2.gif" height="10"></div>';
 }
 
 xmlHttp.onreadystatechange = function() {
   if(xmlHttp.readyState == 4) {
     HTTPContent = xmlHttp.responseText;
	 document.getElementById(elementID).innerHTML = xmlHttp.responseText;
	 LoadSalesmanDialog(); // keep changing images all the time	
//	 xmlHttp.responseText = '';
    }
   } 

 xmlHttp.open("GET", url, true);
 xmlHttp.send(null);


} // end of LoadBreadCrumbs()


function LoadSubCategory(level, title, subCategoryURL, divID, pageContentURL) {
 // sub category level IF
 //alert("LEVEL " + level);
 
 if(level == '2') { // if call for a LEVEL 2 load
  loadedLevel2CategoryDivID = null;
  categoryTitle = title;
  LoadBreadCrumbs('product', title);
 } else if(level == '3') { // if call for a LEVEL 3 load
	 
  if( loadedLevel2CategoryDivID != null) {	// if any Level 2 category is loaded  
   document.getElementById(loadedLevel2CategoryDivID).innerHTML = '';
  }

  loadedLevel2CategoryDivID = divID;
  subCategoryTitle_Level2 = title;
  LoadBreadCrumbs('product', (categoryTitle + " > " + title));
 } // end of sub category level IF
 
 LoadURLContent(subCategoryURL, divID); 
 LoadURLContent(pageContentURL, 'pageContent'); 
} // end of LoadSubCategory


function LoadProduct(productsListURL, title) {
 subCateogryTitle_Level3 = title;
 
 LoadBreadCrumbs('product', (categoryTitle + " > " + subCategoryTitle_Level2 + " > " + subCateogryTitle_Level3));
 LoadURLContent(productsListURL, 'pageContent'); 	
} // end of LoadProduct



function LoadURLContent(url, elementID) {
 var xmlHttp;
 var HTTPContent;

 xmlHttp = GetXmlHttpObject();
 if (xmlHttp == null) {
  alert ("Your browser does not support AJAX!");
  return;
 } 
 
 if(elementID == "breadCrumbs") {
  document.getElementById(elementID).innerHTML = '';
  document.getElementById(elementID).innerHTML = '<div align="center"><br><br><br><span class="text4">Loading. . .<br><br></span><img src="images/loading/1.gif"></div>';
 }
 
 xmlHttp.onreadystatechange = function() {
   if(xmlHttp.readyState == 4) {
     HTTPContent = xmlHttp.responseText;
	 document.getElementById(elementID).innerHTML = xmlHttp.responseText;
//	 xmlHttp.responseText = '';
    }
   } 

 xmlHttp.open("GET", url, true);
 xmlHttp.send(null);
} // end of LoadURLContent







function show_description_div(product_id) {
	var div_id = '#description_' + product_id;
	var div_url_id = '#description_url_' + product_id;
	$(div_url_id).hide();
	$(div_id).show();
	//alert(div_id);
} // end of show_description_div



function hide_description_div(product_id) {
	var div_id = '#description_' + product_id;
	var div_url_id = '#description_url_' + product_id;
	
	$(div_url_id).show();
	$(div_id).hide();
} // end of hide_description_div




function TestFunction() {
	 alert("CALL CALL!!");
}

