cy = new Object();

cy.documentdomain=window.document.domain;
cy.locationpathname=window.location.pathname;
cy.documentreferrer=window.document.referrer;
cy.PageName='';//geturlparameter('act');
cy.FunnelLevel="0";
cy.Section="";
cy.UserId="";
cy.Product="";
cy.Quantity=0;
cy.Value=0.0;
cy.ReturnToLink="";
cy.Custom1="";
cy.Custom2="";
cy.Custom3="";
cy.Custom4="";
cy.CustomerCode='0535204506';

function cy_getCookie(c_name, suffix_allowed)
{
	// Search case-insensitive
	if (document.cookie.length>0)
	{
		if (suffix_allowed == false)
		{
			// Look for a complete word match
			c_start = document.cookie.toLowerCase().indexOf(c_name.toLowerCase() + "=");

			if (c_start != -1)
			{
				c_start = c_start + c_name.length + 1;
				c_end = document.cookie.indexOf(";", c_start);

				if (c_end == -1)
				{
					c_end = document.cookie.length;
				}

				return decodeURIComponent(document.cookie.substring(c_start, c_end));
			}
		}
		else
		{
			// Look for a partial word match
			regexp = c_name.toLowerCase() + "(.*)=";

			c_start = document.cookie.toLowerCase().search(regexp);

			if (c_start != -1)
			{
				// create new string with our search criteria at the beginning
				s1 = document.cookie.slice(c_start);

				// Search from the beginning of this new string for "="
				c_start = s1.indexOf("=") +1;

				if (c_start != -1)	// overkill
				{
					c_end = s1.indexOf(";");

					if (c_end == -1)
					{
						c_end = s1.length;
					}

					return decodeURIComponent(s1.substring(c_start, c_end));
				}
			}
		}

	}

	return "";
}

function cy_convertCYPropertyNamesToUpperCase()
{
	var propertyValue = "";
	for ( var propertyName in cy )
	{
		propertyValue = cy[propertyName];
		cy[propertyName.toUpperCase()] = propertyValue;
	}
	return "";
}

function cy_getImageSrc()
{
	cy_convertCYPropertyNamesToUpperCase();
	var protocol;
	var port;
	var swd='abandonment.saas.seewhy.com';
	var path='/abandonment/WE/seewhy.gif';
	var ssl = window.location.protocol.toLowerCase().indexOf('https') >= 0;
	if (ssl)
	{
		protocol='https';
		port=8443;
	}
	else
	{
		protocol='http';
		port=8080;
	}
	var swi = protocol+'://'+swd+':'+port+path;
	var rn = Math.random();

	if (cy.SESSIONID == null)
	{
		var sessionId = cy_getCookie("JSESSIONID", false);
		if (sessionId == "")
		{
			sessionId = cy_getCookie("ASPSESSIONID", true);
		}
		if (sessionId == "")
		{
			sessionId = cy_getCookie("PHPSESSID", false);
		}
		if (sessionId == "")
		{
			sessionId = cy_getCookie("ASP.NET_SessionId", false);
		}
		if (sessionId == "")
		{
			sessionId = cy_getCookie("sid", false);
		}
		if (sessionId == "")
		{
			sessionId = cy_getCookie("SESS", true);
		}
		if (sessionId == "")
		{
			sessionId = cy_getCookie("SID_CRAZYCAMERAS", true);
		}
	}
	else
	{
		sessionId = cy.SESSIONID;
	}

	var queryString="?Event=WebEvent"+
			"&CustomerCode=" +cy.CUSTOMERCODE+
			"&Server=" +cy.DOCUMENTDOMAIN+
			"&DefaultPageName=" +encodeURIComponent(cy.LOCATIONPATHNAME)+
			"&Referrer=" +encodeURIComponent(cy.DOCUMENTREFERRER)+
			"&SessionID=" +encodeURIComponent(sessionId)+
			"&FunnelLevel=" +encodeURIComponent(cy.FUNNELLEVEL)+
			"&Section=" +encodeURIComponent(cy.SECTION)+
			"&UserID=" +encodeURIComponent(cy.USERID)+
			"&Product=" +encodeURIComponent(cy.PRODUCT)+
			"&Quantity=" +encodeURIComponent(cy.QUANTITY)+
			"&Value=" +encodeURIComponent(cy.VALUE)+
			"&PageName=" +encodeURIComponent(cy.PAGENAME)+
			"&ReturnToLink=" +encodeURIComponent(cy.RETURNTOLINK)+
			"&Custom1=" +encodeURIComponent(cy.CUSTOM1)+
			"&Custom2=" +encodeURIComponent(cy.CUSTOM2)+
			"&Custom3=" +encodeURIComponent(cy.CUSTOM3)+
			"&Custom4=" +encodeURIComponent(cy.CUSTOM4);

	src = swi+"/"+rn+queryString;

	document.getElementById("cy_image").src=src;
}



function geturlparameter( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}