'------------------------------------------------------------------------------------------------------------------------
'  This is the new logic to display specific content in the UPSELL for each & every  Affiliate
'  If CONTENT is not available for any given affiliate, MCAFEE content will be shown as DEFAULT
'  For some reason, if XML is not loaded properly/with any error, Hardcoded DEFAULT (McAFee) content will be shown    
'------------------------------------------------------------------------------------------------------------------------
Dim intAffID
Dim blnIsXMLContentAvailable 
Dim strUpsellTitle, strUpsellVSO, strUpsellVSOBuy

Const intDefaultAffID = 0 
blnIsXMLContentAvailable = False

'-- Get Affid 
intAffID = GetAffid()

'-- Get content for a specific Affiliate (from XML) 
GetUpsellContent (intAffID)

'-- If XML is not available/if there is any issue, get DEFAULT Hardcoded Content 
If Not blnIsXMLContentAvailable Then 
	GetDEFAULT_HardCodedContent
End If
'------------------------------------------------------------------------------------------------------------------------
Function GetAffid ()
'{
	Dim QryStringAffid
	Dim strReferrer 
	
	strReferrer = document.referrer
	
	Debug ("strReferrer :" & strReferrer)
	
	If Instr(strReferrer,"appaffid") > 0 Then
	'{
		QryStringAffid = Mid(strReferrer,Instr(strReferrer,"appaffid")+9,Len(strReferrer))
		Debug ("query sting has APPAFFID :" & QryStringAffid)
	'}		
	ElseIf Instr(strReferrer,"affid") > 0 Then
	'{
		QryStringAffid = Mid(strReferrer,Instr(strReferrer,"affid")+6,Len(strReferrer))
		Debug ("query sting has AFFID :" & QryStringAffid)
	'}		
	Else
	'{
		QryStringAffid = 0 
		Debug ("AFFID is not passed in Querystring, so assign DEFAULT MCAFEE Affiliate")
	'}		
	End If
	
	If Instr(QryStringAffid,"-") > 0 Then 
	'{
		QryStringAffid = Mid(QryStringAffid,1,Instr(QryStringAffid,"-")-1)
		Debug ("after trimming appid from affid  : " & QryStringAffid )
	'}		
	End If 
	
	GetAffid = QryStringAffid
'}
End Function      
'------------------------------------------------------------------------------------------------------------------------
Sub GetUpsellContent (intAffID )
'{
	Dim strXPath
	Dim blnLoadXML

	Dim objXMLDom
	Dim objAffiliateNode
	Dim objTitle, strTitle
	Dim objContent, strContent
	Dim objContentDesc, strContentDesc

	Set objXMLDom = CreateObject("Msxml2.DOMDocument.3.0")
	
	If Not objXMLDom Is Nothing Then
	'{
		Debug("objXMLDom is successfully created")
		objXMLDom.async = false
		blnLoadXML = objXMLDom.Load("http://us.mcafee.com/en-us/global/xml/products/Freescan.xml")
		
		If blnLoadXML Then  
			Debug ("XML file has been loaded SUCESSFULLY")
		Else
			Debug ("XML file loading is FAILED")
			Exit Sub
		End if
				
		strXPath = "Language/Affiliate[@id='"& Trim(intAffID) &"']"
		Debug("strXPath  : " & strXPath )
			
		Set objAffiliateNode = objXMLDom.DocumentElement.selectSingleNode(strXPath)
		
		If objAffiliateNode Is Nothing Then 
			Debug("No content is available for this affiliate Affid ("& intAffID & ") so we are assiging to default Affid 0")
			strXPath = "Language/Affiliate[@id='"& intDefaultAffID &"']"
			Set objAffiliateNode = Nothing
		End If 	
			
		Set objAffiliateNode = objXMLDom.DocumentElement.selectSingleNode(strXPath)
			
		If Not objAffiliateNode Is Nothing Then 
		'{
			Debug ("<xmp>" & objAffiliateNode.xml & "</xmp>")
				
			Set objTitle       = objAffiliateNode.SelectSingleNode("title")
			Set objContent     = objAffiliateNode.SelectSingleNode("content")
			Set objContentDesc = objAffiliateNode.SelectSingleNode("desc")
			
			Set objAlertScanCancelled = objAffiliateNode.SelectSingleNode("alertscancancelled")		
			Set objAlertNoVirusFound  =  objAffiliateNode.SelectSingleNode("alertnovirusfound")
			Set objAlertVirusesDetected = objAffiliateNode.SelectSingleNode("alertvirussesdetected")
			
			Debug ("objTitle : <xmp>" & objTitle.xml & "</xmp>")
			Debug ("objContent : <xmp>" & objContent.xml & "</xmp>")
			Debug ("objContentDesc :<xmp>" & objContentDesc.xml & "</xmp>")
				
			strTitle       = Trim(objTitle.text)
			strContent     = Trim(objContent.text)
			strContentDesc = Trim(objContentDesc.text)
			
			strAlertScanCancelled   = Trim(objAlertScanCancelled.text)		
			strAlertNoVirusFound    = Trim(objAlertNoVirusFound.text)
			strAlertVirusesDetected = Trim(objAlertVirusesDetected.text)
			
			Debug ("strTitle: " & strTitle)
			Debug ("strContent: " & strContent)
			Debug ("strContentDesc: " & strContentDesc)
				
			strUpsellTitle   = strTitle
			strUpsellVSO     = strContent
			strUpsellVSOBuy  = strContentDesc
				
			blnIsXMLContentAvailable = True
		'}
		End If
	'}		
	End If 	
'}		
End Sub
'------------------------------------------------------------------------------------------------------------------------
Sub GetDEFAULT_HardCodedContent 
'{
	
	Debug ("Since XML file is not available, lets take the DEFAULT HARDCODED CONTENT")
	
	strUpsellTitle = "<b>McAfee Security Recommendation</b>"
	strUpsellVSO   = "<a target='LPage' class='hlink' onclick='openCampaignURL(7)' style='color:d00000'><b>ALL YOU NEED!  McAfee Total Protection with SiteAdvisor™ - </b></a><br>Features 12-in-1 always-updating protection that proactively guards your PC and what you value, while blocking offensive content and preventing malicious activity."

	'=============================================================================================
	' IntlAppsSS\MFS\en-us folder is used for all sites with default site language as US English
	' (ex: msn,us etc.). So, use the domain value to determine the current site and hard code 
	' the VSO discount specific to the site. (As of now, hard code VSO discount as $10 for 
	' msn site, otherwise $5.)
	'=============================================================================================
	
	If InStr(strDomainName, "msn") > 0 Then 
		strUpsellVSOBuy = "<a target='LPage' class='hlink' onclick='openCampaignURL(6)' style='color:d00000'><img src='images/buy_now.gif' width='66' height='15' border='0' align=left></a>&nbsp;&nbsp;<b>$59.99 (USD)</b> after $20 rebate."
	Else
		strUpsellVSOBuy = "<a target='LPage' class='hlink' onclick='openCampaignURL(6)' style='color:d00000'><img src='images/buy_now.gif' width='66' height='15' border='0' align=left></a>&nbsp;&nbsp;<b>$59.99 (USD)</b> after $20 rebate."
	End If
'}	    
End Sub
'------------------------------------------------------------------------------------------------------------------------
Sub Debug (strMsg)
'{
	Dim blnDisplayMsg 
	
	blnDisplayMsg  = True
	blnDisplayMsg  = False
	
	If blnDisplayMsg Then
		msgbox (strMsg)
	End If	
'}
End Sub 
'------------------------------------------------------------------------------------------------------------------------












