function createCookie(name,value,seconds)
{
	if (seconds)
	{
		var date = new Date();
		date.setTime(date.getTime() + seconds);
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/;domain=automaticbuilder.com";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0, limit = theForm.length;
	var str;
	for (i=0; i < limit; i++) 
	{
		if(theForm[i].type=='checkbox')
		{
			theForm[i].checked = theElement.checked;
		}
	}
}
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 

}

function trackerLoader()
{
	var leadsource = readCookie('leadsource');
	var source = readCookie('source');
	var guid = readCookie('guid');
	var qleadsource = getQueryVariable('coop');
	if(qleadsource != null)
	{
		leadsource = qleadsource;
		source = getQueryVariable('source');
		var leid = getQueryVariable('leid');	
	}
	
	var leadtracked = readCookie('leadtracked');
	var country = getQueryVariable('country_group');
	
	var rand = Math.floor(Math.random() * 100000000);
	if(country == 'Primary')
	{
		if(leadsource == 'company1050' && leadtracked != 1)
		{
			document.write('<IMG SRC="http://users.marketleverage.com/track_lead/372/" width="1" height="1">');
			document.write('<IMG SRC="/wx3/guidtrack.php?guid=' + guid + '&coop=' + leadsource + '" width="1" height="1">');
		}
		else if(leadsource == 'company1120' && leadtracked != 1)
		{
			document.write('<script language="Javascript" type="text/javascript" src="http://c.azjmp.com/az/pixels_js.php?f=1278"></script><noscript><img src="http://c.azjmp.com/az/pixels_js.php?f=1278" height=1 width=1></noscript>');
			document.write('<IMG SRC="/wx3/guidtrack.php?guid=' + guid + '&coop=' + leadsource + '&source=' + source + '" width="1" height="1">');
		}
		else if(leadsource == 'company2005' && leadtracked != 1)
		{
			document.write('<IMG SRC="/wx3/guidtrack.php?guid=' + guid + '&coop=' + leadsource + '&source=' + source + '" width="1" height="1">');
			document.write('<script src="http://www.incentaclick.com/tracklead"></script><img src="http://www.incentaclick.com/cgi-bin/tracklead?camp_id=2862" onLoad="camp(2862)" /><div id="ic"></div>');
			document.write('<IMG SRC="http://exchange.earndailydirect.com/track_lead/15/OPTIONAL_INFORMATION">');
			if(source == 'company200502600810')
			{
				document.write('<script src="http://secure.directtrack.com/third_lead/poweradz/6/OPTIONAL_INFORMATION"></script><noscript><IMG SRC="http://secure.directtrack.com/lead/poweradz/6/OPTIONAL_INFORMATION"></noscript>');
			}
			else if(source == 'company2005ARC131')
			{
				document.write('<img src="http://www.affiliatefuel.com/cgi-bin/lead?offerid=109708" height=1 width=1>');
			}
			else if(source == 'company2005ARC146')
			{
				document.write('<IMG SRC="http://partners.trafficneeds.com/track_lead/57/OPTIONAL_INFORMATION">');
			}
			else if(source == 'company2005ARC157')
			{
				document.write('<script src="http://users.marketleverage.com/lead_third/372/OPTIONAL_INFORMATION"></script><noscript><IMG SRC="http://users.marketleverage.com/track_lead/372/OPTIONAL_INFORMATION"></noscript>');
			}
			else if(source == 'company2005ARC393')
			{
				document.write('<img src="http://www.filitrac.com/Lead.aspx?pid=7cvHzkQJTtQA&ref=' + rand + '" height="1" width="1" border="0">');
			}
			else if(source == 'company2005ARC1050')
			{
				document.write('<script src="http://www.apex6.com/3rd/1006/OPTIONAL_DATA/"></script><img src="http://www.apex6.com/pixel/1006/OPTIONAL_DATA/" />');
			}
			else if(source == 'company2005ARC1096')
			{
				document.write('<script src="http://partners.cpacoreg.com/lead_third/680/OPTIONAL_INFORMATION"></script><noscript><IMG SRC="http://partners.cpacoreg.com/track_lead/680/OPTIONAL_INFORMATION"></noscript>');
			}
			else if(source == 'company2005ARC1127')
			{
				document.write('<script type="text/javascript">pixel_image=new Image();pixel_image.src="https://ssl.bluerockdove.com/pixel.php?id=1052"</script>');
			}
			else if(source == 'company2005ARC1247')
			{
				document.write('<script src="https://www.discovertotal.com/t?o=69"></script><noscript><img src="https://www.discovertotal.com/tp?o=69"></noscript>');
			}
		}
		else if(leadsource == 'gbm2005')
		{
			document.write('<IMG SRC="/wx3/guidtrack.php?guid=' + guid + '&coop=' + leadsource + '&source=' + source + '" width="1" height="1">');
		}
		else if(leadsource == 'cp1001' && leadtracked != 1)
		{
			document.write('<IMG SRC="/wx3/guidtrack.php?guid=' + guid + '&coop=' + leadsource + '&source=' + source + '" width="1" height="1">');
		}
		else if(leadsource == 'formula2005' && leadtracked != 1)
		{
			document.write('<IMG SRC="/wx3/guidtrack.php?guid=' + guid + '&coop=' + leadsource + '&source=' + source + '" width="1" height="1">');
		}
		else if(leadsource == 'formula1009' && leadtracked != 1)
		{
			document.write('<IMG SRC="http://rextopia.com/track_lead/407" height=1 width=1 border=0>');
		}
		else if(leadsource == 'company1139' && leadtracked != 1)
		{
			document.write('<IMG SRC="http://partners.ethosinteractive.com/track_lead/75/" height=1 width=1 border=0>');
		}
		else if(leadsource == 'company1178' && leadtracked != 1)
		{
			document.write('<script src="http://login.tracking101.com/lead_third/1213/"></script><noscript><IMG SRC="http://login.tracking101.com/track_lead/1213/"></noscript>');
		}		
		else if(leadsource == 'company1269' && leadtracked != 1)
		{
			document.write('<IMG SRC="http://www.filitrac.com/Lead.aspx?pid=UF2YVUEunnwA" HEIGHT="1" WIDTH="1">');
		}
		else if(leadsource == 'formula1008' && leadtracked != 1)
		{
			document.write('<script src="http://rextopia.com/track_lead/407"></script><noscript><IMG SRC="http://rextopia.com/track_lead/407" height=1 width=1 border=0></noscript>');
		}
		else if(leadsource == 'company1280' && leadtracked != 1)
		{
			document.write('<img src=http://www.maxbounty.com/lead.asp?o=316&d=' + guid + ' border=0 width=1 height=1>');
			document.write('<IMG SRC="/wx3/guidtrack.php?guid=' + guid + '&coop=' + leadsource + '" width="1" height="1">');
		}
		else if(leadsource == 'formula1006' && leadtracked != 1)
		{
			document.write('<script src="http://thebizoppnetwork.com/lead_third/151/OPTIONAL_INFORMATION"></script><noscript><IMG SRC="http://thebizoppnetwork.com/track_lead/151/OPTIONAL_INFORMATION"></noscript>');
			document.write('<img src="http://clicks.emarketmakers.com/conversions/advertiser/pix.aspx?o=1685&s=ok&order_id=' + guid + '&tm=' + rand + '" width="1" height="1" border="0"> ');
			document.write('<script src="http://rextopia.com/lead_third/597/"></script><noscript><IMG SRC="http://rextopia.com/track_lead/597/" height=1 width=1 border=0></noscript>');
			document.write('<IMG SRC="/wx3/guidtrack.php?guid=' + guid + '&coop=' + leadsource + '" width="1" height="1">');
			document.write('<script src="http://www.eajmp.com/lead_third/704/OPTIONAL_INFORMATION"></script><noscript><IMG SRC="http://www.eajmp.com/track_lead/704/OPTIONAL_INFORMATION"></noscript>');
			document.write('<IMG SRC="http://www.conversiontracker.net/trk.aspx?advertiser=425" height=1 width=1>');
		}
		else if(leadsource == 'formula1006_rex' && leadtracked != 1)
		{
			document.write('<script src="http://rextopia.com/lead_third/597/"></script><noscript><IMG SRC="http://rextopia.com/track_lead/597/" height=1 width=1 border=0></noscript>');
			document.write('<IMG SRC="/wx3/guidtrack.php?guid=' + guid + '&coop=' + leadsource + '" width="1" height="1">');
		}
		else if(leadsource == 'uniqueleads' && leadtracked != 1)
		{
			document.write('<!-- Google Code for Purchase Conversion Page --><script language="JavaScript" type="text/javascript"><!--var google_conversion_id = 1071447662;var google_conversion_language = "en_US";var google_conversion_format = "1";var google_conversion_color = "FFFFFF";if (1) {  var google_conversion_value = 1;}var google_conversion_label = "Purchase";//--></script><script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js"></script><noscript><img height=1 width=1 border=0 src="http://www.googleadservices.com/pagead/conversion/1071447662/?value=1&label=Purchase&script=0"></noscript>');
			document.write('<IMG SRC="/wx3/guidtrack.php?leid=' + leid + '&coop=' + leadsource + '&source=' + source + '" width="1" height="1">');
		}
		else if(leid)
		{
			document.write('<IMG SRC="/wx3/guidtrack.php?leid=' + leid + '&coop=' + leadsource + '&source=' + source + '" width="1" height="1">');
		}
	}
	createCookie('leadtracked',1,2592000);
	return true;
}

function setGuid(prefix)
{
	var guid = readCookie('guid');
	if(!guid)
	{
		var d=new Date();
		var rand = Math.floor(Math.random() * 100000000);
		var id = prefix + '_' + d.getMonth() + d.getDate() + d.getHours() + rand;
		createCookie('guid',id,2592000);
	}
}

function sourceTrace()
{
	var source = getQueryVariable('source');
	if(source)
	{
		createCookie('source',source,2592000);
	}
}
function disableSubmit(theform) {
	if (document.all || document.getElementById) 
	{
		for (i = 0; i < theform.length; i++)
		{
			var tempobj = theform.elements[i];
			if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
				tempobj.disabled = true;
		}
	}
	return true;
}