var GlobalHomePage=0;var GlobalImgBanner_Text = new Array();var GlobalAnimation=1;var GlobalHomeOM=0;var GlobalHomeCAT=0;var xmlCatalogue='';var MasterAccess=0;
var myDomain = document.domain 
var myURL = document.URL     
if (myURL.toLowerCase().indexOf('.htm') != -1){
   var pu1 = myURL.lastIndexOf('/')  
   var pu2 = myURL.lastIndexOf('\\')  
   if (pu1 != -1 && pu1 > pu2){myURL = myURL.substring(0,pu1)}
   else{myURL = myURL.substring(0,pu2)}
}
var lng=myURL.length
if (myURL.substring(lng-1,lng)=='#'){myURL=myURL.substring(0,lng-1)}

var locAddress = myURL+'/Library/'
var locMainAddress = myURL
if(myDomain.toLowerCase().indexOf('ecat_') != -1 || myURL.toLowerCase().indexOf('ecat_') != -1 ||  myURL.toLowerCase().indexOf('file://') != -1){
   locMainAddress = 'http://www.epublisher.co.za'
   locAddress = 'http://www.epublisher.co.za/Library/' 
}
if(myDomain.toLowerCase().indexOf('localhost_ecat') != -1 || myURL.toLowerCase().indexOf('localhost_ecat') != -1){
   locMainAddress = 'http://localhost/onlinecatalogue/electronic%20catalogue' 
   locAddress = 'http://localhost/onlinecatalogue/electronic%20catalogue/Library/' 
}
document.write('<sc'+'ript');document.write(' type="text/javascript"');document.write(' language="JavaScript"');document.write(' src="'+locAddress+'JavaScriptWindowEvent.js">');document.write('</sc'+'ript>')
document.write('<sc'+'ript');document.write(' type="text/javascript"');document.write(' language="JavaScript"');document.write(' src="'+locAddress+'JavaScriptLibrary.js">');document.write('</sc'+'ript>')
document.write('<sc'+'ript');document.write(' type="text/javascript"');document.write(' language="JavaScript"');document.write(' src="'+locAddress+'JavaScriptDataFnc.js">');document.write('</sc'+'ript>');
document.write('<sc'+'ript');document.write(' type="text/javascript"');document.write(' language="JavaScript"');document.write(' src="'+locAddress+'JavaScriptTree.js">');document.write('</sc'+'ript>')
document.write('<sc'+'ript');document.write(' type="text/javascript"');document.write(' language="JavaScript"');document.write(' src="'+locAddress+'JavaScriptUtility.js">');document.write('</sc'+'ript>')
document.write('<sc'+'ript');document.write(' type="text/javascript"');document.write(' language="JavaScript"');document.write(' src="'+locAddress+'JavaScriptBasket.js">');document.write('</sc'+'ript>');
document.write('<sc'+'ript');document.write(' type="text/javascript"');document.write(' language="JavaScript"');document.write(' src="'+locAddress+'JavaScriptAnimation.js">');document.write('</sc'+'ript>')
document.write('<sc'+'ript');document.write(' type="text/javascript"');document.write(' language="JavaScript"');document.write(' src="'+locAddress+'JavaScriptOM.js">');document.write('</sc'+'ript>')
document.write('<sc'+'ript');document.write(' type="text/javascript"');document.write(' language="JavaScript"');document.write(' src="'+locAddress+'JavaScriptForum.js">');document.write('</sc'+'ript>')
document.write('<sc'+'ript');document.write(' type="text/javascript"');document.write(' language="JavaScript"');document.write(' src="'+locAddress+'JavaScriptFileUpload.js">');document.write('</sc'+'ript>')
setTimeout("TimerLoad()",200)
	
function TimerLoad(){
  var locData = document.getElementById('ECAT_ID')
  if (locData != null){
  	 //if (document.getElementById('Divider_Catalogue')!=null){GlobalDivider_other = 'xxx'}
    WindowEventLoad(locMainAddress)
    LocalInit()
    if (GlobalAnimation==1&&GlobalHomePage==1){
	    GlobalImgBanner_Duration = 2000
	    BannerText()
       GlobalImgBanner_Array.push('images/Banner_OnlineMarketing.jpg')
       GlobalImgBanner_Array.push('images/Banner_SearchEngineOptimization.jpg')    
       GlobalImgBanner_Array.push('images/Banner_OnlineCatalogue.jpg')       
       GlobalImgBanner_Array.push('images/Banner_DatabaseSolutions.jpg')       	   
       GlobalImgBanner_Array.push('images/Banner_eCommerceSolutions.jpg')       	   	   
       GlobalImgBanner_Array.push('images/Banner_OnlineManagement.jpg')       	   	   	   
       LocalInit_Anim()
   	   GlobalImgBanner_Duration = 5000
	}
    if (GlobalHomeOM==1){LocalOM_Init()}
	if (GlobalHomeCAT==1){LocalCAT_Init()}
  } else{setTimeout("TimerLoad()",100)}
}
function LocalInit(){
   GlobalPopup_XPos = Utility_ScreenMiddle(1,400)
   GlobalPopup_YPos = 150
   GlobalPopup_ProductDetails = 1
   GlobalPopup_Login = 1
   GlobalPopup_Register = 1
   if (document.getElementById('Div_ImgBanner1')!=null){GlobalHomePage=1}
   if (document.getElementById('Divider_OM_WebActivities')!=null){GlobalHomeOM=1}
   if (document.getElementById('Divider_Catalogue')!=null){GlobalHomeCAT=1}   
    var locURL = document.URL.toLowerCase()	 
    if (locURL.indexOf('contact_us.html') != -1) { 
       var locObj = document.getElementById('Enquiry_Product')
       var locProduct = Utility_URLRetrieveParam('autofill','#')	
       if (locObj != null&&locProduct!=null) {locObj.value = locProduct}
    }	
   var p1=locURL.indexOf('(')
   var p2=locURL.indexOf('(')
   if (p1!=-1&&p2!=-1){
   	  var locIndex=UtilityText_ExtractText(locURL,'(',')')
      LocalCatalogueDisplay(locIndex)
   }
   var locObjGallery = document.getElementById('Divider_Gallery')
   if (locObjGallery!=null){
	   var locName = locObjGallery.title
	   LocalGalleryDisplay(locName)
   }
   if (locURL.indexOf('ecat_online.html')==-1){   
      toggle('menu',-1)
   }
   LocalLoginText()
}
function LocalCAT_Init(){
   var sParam = Utility_URLRetrieveParam('name')
   var sUsername = Utility_URLRetrieveParam('username')
   var sPassword = Utility_URLRetrieveParam('password')
   var locStatement = 'SELECT * FROM dbo.Company WHERE (INFOVALUE3 IS NOT NULL AND LEN(INFOVALUE3)>0)'
   xmlCatalogue = DataFnc_LoadSQL('COMPANY',1,'',16,locStatement,0,0)
   var sResponse = DataFnc_Locate(1,0,sParam,'name',xmlCatalogue)
   var sMaster = DataFnc_Locate(1,0,'ECAT','name',xmlCatalogue)
   
   if (sResponse.length>0){
      var sDatabase=UtilityXML_ExtractValue(sResponse,'infovalue3')
	   Local_CatalogueSelection(sDatabase)
   }
   else{
      mUsername=UtilityXML_ExtractValue(sMaster,'username')
      mPassword=UtilityXML_ExtractValue(sMaster,'userpassword')
      if (sPassword == mPassword&&mUsername.length>0&&mPassword.length>0){
      	Local_CatalogueMain()
      }
   }
}
function Local_CatalogueMain(){
  MasterAccess=1
  xmlCatalogue = DataFnc_FieldSort(xmlCatalogue,'name')
  var xmlString = WebXML_AddMetadata(xmlCatalogue)
  var xmlObject = ConvertStringToXMLObject(xmlString)
  var locStylesheet = getXSLStyleSheet('Catalogue.xsl')
  doTransformXSLT(locStylesheet, xmlObject, 'Divider_ProductDetails')
}
function Local_CatalogueSelection(pDatabase,pUsername,pPassword){
   var sResponse = DataFnc_Locate(1,0,pDatabase,'infovalue3',xmlCatalogue)	
   var sUsername = UtilityXML_ExtractValue(sResponse,'username')
   var sPassword = UtilityXML_ExtractValue(sResponse,'userpassword')
   if ((sUsername==pUsername&&sPassword==sPassword)||(MasterAccess==1)){
   	WebTree_HistoryEmpty()
   	Utility_DatabaseFnc(1,pDatabase)
      var locID = Guid_Empty
      WebFnc_TransformItemSummary(2,'Product_ChildrenSummary.xsl','Divider_ProductDetails',locID,'','ID,PARENTID,CHILDCOUNT,ISLEAF,NAME,SEQUENCE,IMAGENAME,IMAGEPATH')
   }
}
function toggle(pID,pView){
	var locObj=document.getElementById(pID)	
	var locStyle = locObj.style.visibility
   if (locStyle=='visible'||locStyle==''){
      locObj.style.visibility='hidden'
	}else{locObj.style.visibility='visible'}
	if (pView!=null&&pView==1){locObj.style.visibility='hidden'}
	if (pView!=null&&pView==-1){locObj.style.visibility='visible'}	
}

function DisplayPage(pMode){
   var locURL = document.URL.toLowerCase()	 
  if (pMode == 1){
     if (GlobalUserID.length==0){
 	    Utility_URLRedirect('ECAT_Online.html')
	 }else{
  	    WebFunction_UserLogout()
       LocalLoginText()
       if (locURL.indexOf('ecat_online.html') != -1){
       	Utility_URLRedirect('ECAT_Online.html')
       }else{Utility_Message('You have been logged out of your account','Logged Out')}
     }
  }
  if (pMode == 2){
  	  Utility_URLRedirect('ECAT_Online.html')
  	}
  if (pMode == 3){BasketDisplayCurrent(1,'QuoteDebtor')}
  if (pMode == 4){BasketDisplayHistory(1,'QuoteDebtor')}
}
function LocalLoginText(){
   var locObj1=document.getElementById('sign')
   var locObj2=document.getElementById('register')
	if (locObj1!=null&&locObj2!=null){
	   if (GlobalUserID.length>0){
		   Utility_ObjectWrite(locObj1,'Logged Out')
		   Utility_ObjectWrite(locObj2,'View Details')
	   }
	   else{
	      Utility_ObjectWrite(locObj1,'Client Login')
	      Utility_ObjectWrite(locObj2,'Contact us')
	   }
   }
}
/*====================== GALLERY =====================*/
function LocalGalleryDisplay(pSection){
   var locID=null;var xmlString='';var locID=''
   var locStatement = 'SELECT ID,NAME,WEBSITE,TEL1NO,EMAIL FROM dbo.Company WHERE (DISABLE=0 AND PARENTID IS NULL AND WEBSITE IS NOT NULL AND LEN(WEBSITE)>0 AND INFOVALUE1 = \''+pSection+'\')'
   xmlString = DataFnc_LoadSQL('COMPANY',1,'',16,locStatement,0,0)
   if (xmlString.length>0){
   	   xmlString = DataFnc_FieldSort(xmlString,'name')
       xmlString = WebXML_AddMetadata(xmlString)
	   var xmlObject = ConvertStringToXMLObject(xmlString)
   	   var locStylesheet = getXSLStyleSheet('Company_Gallery.xsl')
   	   doTransformXSLT(locStylesheet, xmlObject, 'Divider_Gallery')
   }
}

/*========================== SEARCH ===========================*/
function LocalSearch(pInputID,pEvent){
   GlobalInputID = pInputID
   if (pEvent != null){
      var locKey = Utility_EnterKey(pEvent,pInputID,1)
      if (locKey != 13){return}
   }
   GlobalInputID = pInputID
   GlobalSearchHTML=1
   var locTitle = window.location.href
   var locSearch = document.getElementById('txtsearch')   
   WebDisplay_DataSearch('Search_HTML.xsl','Divider_SearchDetails',0,GlobalInputID,'',GlobalMemory_Search,Tree_RowPerPage('Tree_ecat'),1,'','','ID, Name, Code, ChildCount, InfoAmount1, InfoAmount2, ImageName, ImagePath')
}
function LocalQuickSearch(pText){
	if (ProgressActive()==1){return}
	var locSearch = document.getElementById('txtsearch')   
	Utility_ObjectWrite(locSearch,pText)
}

/*=================== BUILT IN FUNCTIONS ====================*/
function Local_WindowActionAfter(){
	if (GlobalTransform_Last.toLowerCase().indexOf('gallery')==-1){
	   toggle('menu',1);
	   LocalHideBanner();
   }
}	

function LocalImgBanner_InsideSelect(){
   GlobalImgBanner_Duration = 5000
   var locDelay=0
   setTimeout("BannerText()",1800)   
   BannerDisplay_Mode=1
}
function BannerText(){
   var locObjText = document.getElementById('banner_text')
   var locObj=document.getElementById('banner_'+GlobalImgBanner_Timer)
   locObjText.innerHTML = locObj.innerHTML
   var locMenu = document.getElementById('menu'+GlobalImgBanner_Timer)   
   for (var i=0; i<6; i++){
	   var locIndex = i+1
	   document.getElementById('menu'+locIndex).style.backgroundColor=""
	   document.getElementById('menu'+locIndex).style.color =""
   }
   locMenu.style.backgroundColor="#C0C0C0"
   locMenu.style.color = "#000000"
}
function LocalHideBanner(){
	if (GlobalHomePage==0){return}
	GlobalMainClosed=1;GlobalAnim_Page=0
	if (document.getElementById('Div_Banner')!=null){
      document.getElementById('Div_Banner').style.visibility='hidden'
      document.getElementById('Div_Banner').style.position='absolute'   
      document.getElementById('Div_Banner').style.height='0px'
   }
   document.getElementById('Div_ImgBanner1').style.visibility='hidden'
   document.getElementById('Div_ImgBanner1').style.position='absolute'   
   document.getElementById('Div_ImgBanner1').style.height='0px'
   document.getElementById('Div_ImgBanner2').style.visibility='hidden'
   document.getElementById('Div_ImgBanner2').style.position='absolute'      
   document.getElementById('Div_ImgBanner2').style.height='0px'
}
function LocalAnim_InsideMainEnd(){}
function LocalAnim_InsideBannerEnd(){}
