//REDECLARE FUNCTION MAKE SURE IT IS INCLUDED
function loadXMLDoc(url) {
	var req;
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		req.open("GET", url, true);
		req.send("");
	}
}

//JavaScript Functions used in tracking the zones of the website
function checkZones() {
	if (document.getElementsByTagName) {
		var zone_list = "";
		var Nodes = document.body.getElementsByTagName('div');
		var nodeMax = Nodes.length
        for(var i=0; i<nodeMax; i++) {
			var nodeObj = Nodes.item(i)
			var re = /^izone_([0-9]{1,4})$/
			if(re.test(nodeObj.id)) {
				var izone = re.exec(nodeObj.id);
				if (izone) {
					zId = izone[1];
					zone_list+=zId+",";
					nodeObj.onclick = zoneClick;
				}
			}
        }
		if (zone_list.length>0) 
			loadXMLDoc('/index.html?view=isol_views&type=ab_zone&creatives='+zone_list);
	}	
}

function checkPages() {
	if (document.getElementsByTagName) {
		var page = "";
		var Nodes = document.body.getElementsByTagName('div');
		var nodeMax = Nodes.length
        for(var i=0; i<nodeMax; i++) {
			var nodeObj = Nodes.item(i)
			var re = /^abp_([0-9]{1,4})_([0-9]{1,4})$/
			if(re.test(nodeObj.id)) {
				var thePage = re.exec(nodeObj.id);
				if (thePage[1]>0 && thePage[2]){
					loadXMLDoc('/index.html?view=isol_views&type=ab_page&ab_page='+thePage[2]+'&ab_test='+thePage[1]);
					nodeObj.onclick = pageClick;
				} 
			}
        }
		
	}	
}

function zoneClick() {
	var re = /^izone_([0-9]{1,11})$/
	var izone = re.exec(this.id);
	if (izone[1]>0) 
		loadXMLDoc('/index.html?view=isol_clicks&type=ab_zone&creatives='+izone[1]);
	return true;
}

function pageClick() {
	var re = /^abp_([0-9]{1,11})_([0-9]{1,11})$/
	var thePage = re.exec(this.id);
	if (thePage[1]>0 && thePage[2]) 
		loadXMLDoc('/index.html?view=isol_clicks&ab_page='+thePage[2]+'&ab_test='+thePage[1]);
	return true;
}


//Initiate Tracking
checkZones();
checkPages();