var GlobalPage_Home = 0;var Global_Mode=0;var MemoryItems = 0;var HookURL='';
var locCount = 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('localhost_ecat') != -1 || myURL.toLowerCase().indexOf('localhost_ecat') != -1){
    locMainAddress = 'http://localhost/onlinecatalogue/electronic%20catalogue' 
    locAddress = 'http://localhost/onlinecatalogue/electronic%20catalogue/Library/' 
}
else if(myDomain.toLowerCase().indexOf('websites_ecatalogue') != -1 || myURL.toLowerCase().indexOf('websites_ecatalogue') != -1 || myURL.toLowerCase().indexOf('file://') != -1){
    locMainAddress = 'http://196.30.166.51/qaCatalogue'
    locAddress = 'http://196.30.166.51/qaCatalogue/Library/' 
}
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+'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>')
setTimeout("TimerLoad()",1000)
	
function TimerLoad(){
  var locData = document.getElementById('ECAT_ID')
  if (locData != null){
      WindowEventLoad(locMainAddress)
      LocalInit()       
      LocalBasketUpdate()
      EventTransform('','','otherPages')
      BasketClearItem('Quote')   	  
  }
  else{setTimeout("TimerLoad()",100)}
}  
function LocalInit(){
   GlobalPopup_XPos = Utility_ScreenMiddle(1,400)+'px'
   GlobalPopup_YPos = '30px'
   GlobalPopup_ProductDetails = 1
   GlobalPopup_Login = 1
   GlobalPopup_Register = 1
   MemoryItems = GlobalMemory_ItemList
   var locObj = document.getElementById('Divider_Home')
   if (locObj != null){GlobalPage_Home = 1}
   var locURL = document.URL.toLowerCase()
   if (locURL.indexOf('online_catalogue.html') != -1){ 
   	 var locUsername = Utility_URLRetrieveParam('username')
   	 var locPassword = Utility_URLRetrieveParam('password')
   	 HookURL = Utility_URLRetrieveParam('hook_url')
   	 if (locUsername.length>0){
   	    WebFunction_UserAutoLogin(2,locUsername,locPassword)
   	    var locData=UtilityXML_ExtractValue(GlobalUserXML,'linkdatabase')
   	    if (locData=='EXTERNAL'){
   	       Global_Mode=1
   	    }
   	 }
   }   
   else if (locURL.indexOf('enquiry.html') != -1) { 
     var locObj = document.getElementById('Enquiry_Product')
     var locProduct = Utility_URLRetrieveParam('autofill')	
     if (locObj != null) {locObj.value = locProduct}
   }   
   GlobalImgBanner_Array.push('images/banner/Banner-MiningIndustry1.gif')
   GlobalImgBanner_Array.push('images/banner/Banner-Lighting.gif')    
   GlobalImgBanner_Array.push('images/banner/Banner-MiningIndustry2.gif')
   GlobalImgBanner_Array.push('images/banner/Banner-Lighting.gif')    
   LocalInit_Anim()
   //Global_Mode=1
   //alert(Global_Mode)
   Local_BasketFill()
   ActivateDisplay()
   
}
function Local_WindowMetadata(pXML){
  var xmlString=pXML
  xmlString = Utility_AjaxRemove(xmlString)
  xmlString=xmlString+'<metadata><mode>'+Global_Mode+'</mode></metadata>'
  xmlString='<ajaxresponse>'+xmlString+'</ajaxresponse>'
  return xmlString
}
function ActivateDisplay(){
 var locObjLog=document.getElementById('login')
 var locObjMenu=document.getElementById('menu') 
 if (Global_Mode==1){
    document.getElementById('basket_1').style.visibility='visible' 
    document.getElementById('basket_1').style.position='static' 	
 }
 else{	
	  locObjLog.style.visibility='visible'
	  locObjMenu.style.visibility='visible'
 	 document.getElementById('Azolite_product').style.visibility='visible' 
}}
function LocalPage(pMode){
  if (pMode==1){WebDisplay_UserLogin()}
  if (pMode==2){WebDisplay_UserRegister()}  
  if (pMode==3){BasketDisplayCurrent(1,'QuoteDebtor')}  
  if (pMode==4){BasketDisplayHistory(1,'QuoteDebtor')}    
}
function Local_TopLink(pInfo1,pInfo2){
   if (pInfo1==1){WebDisplay_ItemDetails(pInfo2)}
	if (pInfo1==2){
		var locObj=document.getElementById('txtsearch')
		locObj.value=pInfo2
		LocalSearch('txtsearch')
} }
function LocalProduct(pSection){
   var locID=null
   var locStylesheet='Product_Children(100).xsl' 
   if (Global_Mode==1){locStylesheet='Product_Children(200).xsl'}
   if (pSection==null||pSection.length==0){locID=Guid_Empty}
   if (locID==null||locID.length==0){
      var locStatement = 'SELECT ID,NAME,PARENTID FROM dbo.Product WHERE (NAME = \''+pSection+'\' AND ITEMLEVEL <= 2)'
      var xmlString = DataFnc_LoadSQL('PRODUCT',1,'',16,locStatement,0,0)
      locID = UtilityXML_ExtractValue(xmlString,'id')
   }
   if (locID!=null&&locID.length>0){
      WebFnc_TransformItemSummary(2,locStylesheet,'Divider_ProductDetails',locID,pSection,'ID,PARENTID,CHILDCOUNT,ISLEAF,NAME,CODE,INFOAMOUNT1,SEQUENCE,IMAGENAME,IMAGEPATH','',null,MemoryItems)
   }
}
function Local_Hide(){
	var locObj=document.getElementById('banner')
	if (locObj!=null){
	  GlobalAnim_Page=0
	  GlobalMainClosed=1
	  locObj.style.visibility='hidden'
	  locObj.style.position = 'absolute'
	  locObj.style.height='0px'
	  document.getElementById('images_Banner1').style.visibiltiy='hidden'
	  document.getElementById('Div_ImgBanner1').style.visibiltiy='hidden'
	  document.getElementById('Div_ImgBanner1').style.position='absolute'
	  document.getElementById('Div_ImgBanner1').style.height='0px'
	  document.getElementById('images_Banner2').style.visibiltiy='hidden'
	  document.getElementById('Div_ImgBanner2').style.visibiltiy='hidden'
	  document.getElementById('Div_ImgBanner2').style.position='absolute'
	  document.getElementById('Div_ImgBanner2').style.height='0px'
	}
}
function Local_WindowActionAfter(){
   Local_Hide()	
}
function Local_WindowBasketUpdate(pItemID){
   LocalBasketUpdate()
   Local_BasketFill()
   document.getElementById('basket_2').style.visibility='visible' 
   document.getElementById('basket_2').style.position='static' 	
}
function Local_BasketTransfer(){
   ProgressImageDisplay(true)
   setTimeout("Local_BasketTransferTimer()",1000)
}
function Local_BasketTransferTimer(){
	var locForm = document.getElementById('Form_SAP')
	if (locForm!=null&&HookURL.length>0){
   	   //------ Read All Info --------
       locForm.action = HookURL
	   var locFilter = ''
       for (var i=0; i<BasketArrayID.length; i++){
		   if (locFilter.length>0){locFilter = locFilter+' OR '}
		   locFilter = locFilter+'ID=\''+BasketArrayID[i]+'\''
	   }
       var locStatement = 'SELECT ID,TPSID,NAME,CODE,INFOAMOUNT1,DESCRIPTION1 FROM dbo.Product WHERE ('+locFilter+')'
       var xmlString = DataFnc_LoadSQL('PRODUCT',1,'',16,locStatement,0,0)
       for (var i=0; i<BasketArrayID.length; i++){
         var locResponse = DataFnc_Locate(1,0,BasketArrayID[i],xmlString)
		   if (locResponse.length==0){locResponse = DataFnc_Locate(1,MemoryItems,BasketArrayID[i],'id')}
		   var locCount = i+1
		   var locHTML = ''  
         var newdiv = document.createElement('div');
         var locFullPrice = UtilityXML_ExtractValue(locResponse,'infoamount1')
         var locPrice = locFullPrice
         var locDecimal = '0'
         var p1=locFullPrice.indexOf('.')
         var lng=locFullPrice.length
         if (p1!=-1){
         	locPrice = locFullPrice.substring(0,p1)
         	locDecimal = locFullPrice.substring(p1+1,lng)
         }
         locPrice
         locHTML = locHTML+"<input type='text' name='NEW_ITEM-DESCRIPTION["+locCount+"]' value='"+UtilityXML_ExtractValue(locResponse,'name')+"'><br/>"
		   locHTML = locHTML+"<input type='text' name='NEW_ITEM-PRICE["+locCount+"]' value='"+locFullPrice+"'><br/>"  
		   locHTML = locHTML+"<input type='text' name='NEW_ITEM-QUANTITY["+locCount+"]' value='"+BasketArrayQty[i]+"'><br/>"		   
		   locHTML = locHTML+"<input type='text' name='NEW_ITEM-UNIT["+locCount+"]' value='each'><br/>"		   		   
		   locHTML = locHTML+"<input type='text' name='NEW_ITEM-CURRENCY["+locCount+"]' value='ZAR'><br/>"		   		 
		   locHTML = locHTML+"<input type='text' name='NEW_ITEM-LONGTEXT["+locCount+"]' value='"+UtilityXML_ExtractValue(locResponse,'description1')+"'><br/>"		   		   		   		   
		   locHTML = locHTML+"<input type='text' name='NEW_ITEM-VENDORMAT["+locCount+"]' value='"+UtilityXML_ExtractValue(locResponse,'code')+"'><br/>"		   		   		   		   		   
		   locHTML = locHTML+"<input type='text' name='NEW_ITEM-MANUFACTCODE["+locCount+"]' value='"+UtilityXML_ExtractValue(locResponse,'code')+"'><br/>"		   		   		   		   		   		   
		   locHTML = locHTML+"<input type='text' name='NEW_ITEM-MANUFACTMAT["+locCount+"]' value='"+UtilityXML_ExtractValue(locResponse,'code')+"'><br/>"		   		   		   		   		   		   		   
		   newdiv.innerHTML = locHTML
         document.getElementById('Div_Input').appendChild(newdiv);
	   }
       document.forms['Form_SAP'].submit() 
   }
   	ProgressImageDisplay(false)
	BasketClearItem('Quote')   
}
function Local_BasketFill(){
   var xmlString = ''
   for (var i=0; i<BasketArrayID.length; i++){
   	  var locID = BasketArrayID[i]
   	  var locQty = BasketArrayQty[i]
      var locResponse = DataFnc_Locate(1,MemoryItems,locID,'id')
      xmlString = xmlString+locResponse
   }
   Utility_ListFillXML('basket_list',xmlString)
}
function LocalBasketUpdate(){
   var locCntItem = BasketTotal(1,'Quote')
   var locCntQty  = BasketTotal(2,'Quote')
   var locDiv1 = document.getElementById('quote_totalitem')
   var locDiv2 = document.getElementById('quote_totalqty')   
   if (locDiv1 != null && locDiv2 != null){
      if (locCntItem == 0){locDiv1.innerHTML = ' Nb. of Items:<font style="font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000080">'+locCntItem+'</font>'}
	  else{locDiv1.innerHTML = ' Nb. of Items:<font style="font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#C00000">'+locCntItem+'</font>'}
      if (locCntQty == 0){locDiv2.innerHTML = 'Total Quantity:<font style="font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000080">'+locCntQty+'</font>'}
	  else{locDiv2.innerHTML = 'Total Quantity:<font style="font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#C00000">'+locCntQty+'</font>'}
	  if (Global_Mode==1){
	  	 
 	  }
   } 
}
function LocalTreeTitle(pTitle){
 var locObj = document.getElementById('span_TreeTitle')
 if (locObj != null){locObj.innerHTML = pTitle}
}
function LocalTreeParentName(pTreeID,pSection){
	var locObjTree = document.getElementById(pTreeID)
	if (locObjTree != null){
	   var locTreeParam = Utility_TreeParam(0,locObjTree)
	   var locTreeParent = UtilityText_ExtractText(locTreeParam,'TreeParentName(',')') 
	   if (locTreeParent.length == 0){locTreeParam = locTreeParam+'TreeParentName('+pSection+')'}
       else{locTreeParam = UtilityText_Replace(locTreeParam,'TreeParentName('+locTreeParent+')','TreeParentName('+pSection+')')}
 	   Utility_TreeParam(1,locObjTree,locTreeParam)
	}
}
function LocalTree(pTreeID,pSection){
	LocalTreeTitle(pSection)
	LocalTreeParentName(pTreeID,pSection)
 	WebDisplay_TreeInit(pTreeID)	
}
function LocalSearch(pInputID,pEvent){
   GlobalInputID = pInputID
   if (pEvent != null){
      var locKey = Utility_EnterKey(pEvent,pInputID,1)
      if (locKey != 13){return}
   }
   GlobalInputID = pInputID
   var locTitle = window.location.href
   var locSearch = document.getElementById('txtsearch')   
   var locStylesheet='Search_Item.xsl' 
   if (Global_Mode==1){locStylesheet='Search_Item(200).xsl'}
   WebDisplay_DataSearch(locStylesheet,'Divider_SearchDetails',2,GlobalInputID,'',MemoryItems,Tree_RowPerPage('Tree_ecat'),1,'','','ID, Name, Code, ChildCount, InfoAmount1, InfoAmount2, ImageName, ImagePath')
}

function LocalDate(){var mydate=new Date();var year=mydate.getYear();if (year < 1000){year+=1900}
var day=mydate.getDay();var month=mydate.getMonth();var daym=mydate.getDate();if (daym<10){daym="0"+daym}
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
return dayarray[day]+", "+montharray[month]+" "+daym+", "+year
}

