function _f2void() { return; }

function _f2sleep(ms)
{
	var start = new Date();
	var now = new Date();
	while(now.getTime() - start.getTime() < ms)
	{
		now = new Date();
	}
}


function f2convert(cid, pids)
{
    try
    {   
        var img = new Image(1,1);
	var src = "//rd.clickshift.com/convert.gif?cid=" + escape(cid);
	try {
	  if (location.protocol == 'file:') {
		src = "http:" + src;
	  }
	} catch (ex) { }
	
	src += "&pids=" + escape(pids);

        // conversion_id is optional third parameter
        if (f2convert.arguments.length > 2) {
            var conversion_id = f2convert.arguments[2];
            src += "&conversion_id=" + (conversion_id ? escape(conversion_id) : '');
        }
        if (f2convert.arguments.length > 3) {
            if (f2convert.arguments[3]) {
                src += "&pof=1";
            }
        }
        if (f2convert.arguments.length > 4) {
	    var cs_data = f2convert.arguments[4];
            src += "&cshift_ck=" + (cs_data ? escape(cs_data) : '');
        }
        if (f2convert.arguments.length > 5) {
	    var attribution = f2convert.arguments[5];
            src += "&attribution=" + (attribution ? escape(attribution) : '');
        }

	img.onload = function () { _f2void(); }
	img.src = src;
    } catch (ex) {}

    try 
    {
        // activate custom code. Right now for ShopNBC only
        // possibly not supporting this anymore
        if (cid == 1000 || cid == 5031){
            java_script = '<script language="javascript">var f2Params = new Array(); f2Params["pids"]="' + pids + '";';
            if (f2convert.arguments.length > 2)
                java_script = java_script + 'f2Params["conversion_id"]="' + f2convert.arguments[2] + '";';
            if (f2convert.arguments.length > 3)
                java_script = java_script + 'f2Params["pof"]="' + f2convert.arguments[3] + '";';
            if (f2convert.arguments.length > 4)
                java_script = java_script + 'f2Params["cshift_ck"]="' + f2convert.arguments[4] + '";';
            if (f2convert.arguments.length > 5)
                java_script = java_script + 'f2Params["attribution"]="' + f2convert.arguments[5] + '";';
	    var base_url = '//rd.clickshift.com/js/';
	    try {
	      if (location.protocol == 'file:') {
	          base_url = "http:" + base_url;
	      }
	    } catch (ex) { }
	    java_script = java_script + '</script><script language="javascript" src="' + base_url + cid + '_custom_convert.js"></script>';
	    document.write(java_script);
        }
    } catch(ex){}

    return true;
}


function f2_onclick_convert(cid, pids)
{
        var img = new Image(1,1);
	var src = "//rd.clickshift.com/convert.gif?cid=" + escape(cid);
	try {
	  if (location.protocol == 'file:') {
		src = "http:" + src;
	  }
	} catch (ex) { }
	src += "&pids=" + escape(pids);

        // conversion_id is optional third parameter
        if (f2_onclick_convert.arguments.length > 2) {
            var conversion_id = f2_onclick_convert.arguments[2];
            src += "&conversion_id=" + (conversion_id ? escape(conversion_id) : '');
        }
        if (f2_onclick_convert.arguments.length > 3) {
            if (f2_onclick_convert.arguments[3]) {
                src += "&pof=1";
            }
        }
        if (f2_onclick_convert.arguments.length > 4) {
	    var cs_data = f2_onclick_convert.arguments[4];
            src += "&cshift_ck=" + (cs_data ? escape(cs_data) : '');
        }
        if (f2_onclick_convert.arguments.length > 5) {
	    var attribution = f2_onclick_convert.arguments[5];
            src += "&attribution=" + (attribution ? escape(attribution) : '');
        }
	src += "&rnd=" + escape(Math.round(1E10*Math.random()));

	img.onload = function () { _f2void(); }
	img.src = src;

    try
    {   
	if(navigator.appName != "Microsoft Internet Explorer")
	{
		// Firefox will abort image loads if a navigation
		// event occurs, so we'll need to slow things down
		// a bit.
		_f2sleep(500);
	}

    } catch (ex) {}
    return true;
}



