//Usage: var retval = fireThruEventPixel("popUnder(strGratisURL, 'GratisPop', 700, 500, true, true, true, true, true, true, true);");
function fireThruEventPixel(status, pevent, zipcode, referringdomain, refcode1, refcode2, eid, agent) {
	var cd;
	var cu;
	var ce;
	if(location.href.indexOf("https:")!=-1){
		cd = "https://www.inphonic.com"; //this should contain the domain of the web site
	}
	else{
		cd = "http://www.inphonic.com"; //this should contain the domain of the web site
	}
	cu = "/_images/Epixel.gif?log=1"; //this should contain the full path to the zag.gif file (excluding domain) and include the query string of log=1

	var cb = new Date().getTime(); 
	var vo = "&cb=" + cb + "&status=" + status + "&event=" + pevent + "&zipcode=" + zipcode + "&referringdomain=" + referringdomain + "&refcode1=" + refcode1 + "&refcode2=" + refcode2 + "&eid=" + eid + "&agent=" + agent; //tack on additional capture parameters here
	
	var img = new Image();
	//img.onload = function() { eval(js) };
	img.src = cd + cu + vo;
	
	return false;
}


// Start PRN 31563
function TrackEmailAddress(EmailValue)
{
    var docUrl = location.href.toLowerCase();
    //only log emails for check out page
    if (docUrl.indexOf("ordersteps.asp") == -1)
        return;
        
    var cd;
    var cu;     
    if (location.href.indexOf("https:") != -1)
        cd = "https://www.inphonic.com";
    else
        cd = "http://www.inphonic.com";
    cu = "/_images/tpixel.gif?Log=1";      
    //trim email value
    EmailValue = EmailValue.replace(/^\s+|\s+$/g, '');
    if (IsValidEmail(EmailValue) && IsNewEmail(EmailValue)) 
    {
        var emailLog = "&email=" + escapeModified(EmailValue) + "&cb=" + new Date().getTime();
        var img = new Image();
        img.src = cd + cu + emailLog;             
    }
}
function IsValidEmail(emailValue) 
{
    var filter = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z0-9]{2,15}$/i;
    if (emailValue.search(filter) == -1)
        return false;
    else
        return true;
}
var EmailsList = new Array();
//used so we don't log same email address within same page request
function IsNewEmail(emailValue) 
{
    for (x in EmailsList) 
    {
        if (EmailsList[x] == emailValue)
            return false;
    }
    EmailsList.push(emailValue);
    return true;
}
function escapeModified(s)
{ return escape(s).replace(/\+/g, "%2B") }
// End PRN 31563

function fireEventPixel(pevent, referringdomain, refcode1) {

    var cd;
    var cu;
    var ce;
    if (location.href.indexOf("https:") != -1) {
        cd = "https://www.inphonic.com"; //this should contain the domain of the web site
    }
    else {
        cd = "http://www.inphonic.com"; //this should contain the domain of the web site
    }
    cu = "/_images/Epixel.gif?log=1"; //this should contain the full path to the zag.gif file (excluding domain) and include the query string of log=1

    var cb = new Date().getTime();
    var vo = "&cb=" + cb + "&event=" + pevent + "&referringdomain=" + referringdomain + "&refcode1=" + refcode1; //tack on additional capture parameters here
	//alert("Fired " + cd + cu + vo);
    var img = new Image();
    //img.onload = function() { eval(js) };
    img.src = cd + cu + vo;
	
}
//Start changes for PRN:34260
function fireFilterEventPixelOnPhonesTab(cbk, filterType, filterName) {

    if(cbk.checked)
    {
        var cd;
        var cu;
        var ce;
        if (location.href.indexOf("https:") != -1) {
            cd = "https://www.inphonic.com"; //this should contain the domain of the web site
        }
        else {
            cd = "http://www.inphonic.com"; //this should contain the domain of the web site
        }
        cu = "/_images/Epixel.gif?log=1"; //this should contain the full path to the zag.gif file (excluding domain) and include the query string of log=1

        var cb = new Date().getTime();
        var vo = "&cb=" + cb + "&event=PhonesTabFilter&filter_" + filterType + "=" + filterName; //tack on additional capture parameters here

        var img = new Image();
        //img.onload = function() { eval(js) };
        img.src = cd + cu + vo;
    }
}

//End changes for PRN:34260

// MT Event Pixel

function fireEventPixelFormSubmit(pevent, referringdomain, refcode1, formname) {
	// This function REQUIRES JQuery

    var cd;
    var cu;
    var ce;
    if (location.href.indexOf("https:") != -1) {
        cd = "https://www.inphonic.com"; //this should contain the domain of the web site
    }
    else {
        cd = "http://www.inphonic.com"; //this should contain the domain of the web site
    }
    cu = "/_images/Epixel.gif?log=1"; //this should contain the full path to the zag.gif file (excluding domain) and include the query string of log=1

    var cb = new Date().getTime();
    var vo = "&cb=" + cb + "&event=" + pevent + "&referringdomain=" + referringdomain + "&refcode1=" + refcode1; //tack on additional capture parameters here
	//alert("Fired " + cd + cu + vo);

	var img = new Image();
	img.onload = function() { fireEventPixelFormSubmit_pixel_loaded(formname) };
	img.src = cd + cu + vo;
	return true;
}

function fireEventPixelFormSubmit_pixel_loaded(formname){
	document.forms[formname].submit();
}


