
var xmlHttpAds
	
	function stateChangedAds() 
		{ 
			if (xmlHttpAds.readyState==4)
			{ 
					openAds();
			}
		}
		
	function GetxmlHttpObjectAds()
		{
		var xmlHttpAds=null;
		try
		  {
		  // Firefox, Opera 8.0+, Safari
		  xmlHttpAds=new XMLHttpRequest();
		  }
		catch (e)
		  {
		  // Internet Explorer
		  try
			{
			xmlHttpAds=new ActiveXObject("Msxml2.XMLHTTP");
			}
		  catch (e)
			{
			xmlHttpAds=new ActiveXObject("Microsoft.XMLHTTP");
			}
		  }
		return xmlHttpAds;
	}
	var product = '';
	var adsClicked = '';
	var Urlproduct = '';
	
	function updateAds(id,product_id,Url){
		adsClicked = id;
		xmlHttpAds = GetxmlHttpObjectAds();
		var url = "";
		
		//ALMAC - Determine the browser protocol and assign prefix.
		var loc = new String(window.parent.document.location);
		if (loc.indexOf("https://")!= -1){
			prefix = "https://";
		}
		else{
			prefix = "http://"; 
		}
		
		//ALMAC - Assign the address ...
	    var serverNameURL = prefix + "www.thinkpharmacy.com.au";

		var url=serverNameURL+"/ajax/updateAds.php?id="+id;	
		
		var page="/ajax/updateAds.php?id="+id;	
		
		//alert("page is " + page);
		// DMD Edit
		//alert(url);
		product = product_id;
		xmlHttpAds.onreadystatechange=stateChangedAds;
		xmlHttpAds.open("GET",url,true);
		xmlHttpAds.send(null);
		Urlproduct = Url;
		//alert('URLproduct is ' + Urlproduct);
		//Redirect to the product page - ALMAC
		window.location = Urlproduct;

	}

	function openAds(){
		/*
		alert("inside the open ads fucntion");
		window.location = url;
		alert("location " + window.location);
		
		*/
		if(Urlproduct == ""){
			gid("linkAdsProd"+adsClicked).click();
		}else{
			gid("linkAds"+adsClicked).click();
		}

	}