
function getSetCodes() {
	//requires jQuery 1.3+
	//requires jquery.cookie.js
	if (getValue('primaryBrokerId') != '') {
		$.cookie('primaryBrokerId', getValue('primaryBrokerId').substr(0,8), { path: '/', expires: 180 });
	}
	if (getValue('producingBrokerId') != '') {
		$.cookie('producingBrokerId', getValue('producingBrokerId').substr(0,8), { path: '/', expires: 180 });
	}
	if (getValue('GA') != '') {
		$.cookie('primaryBrokerId', getValue('GA').substr(0,8), { path: '/', expires: 180 });
	}
	if (getValue('PB') != '') {
		$.cookie('producingBrokerId', getValue('PB').substr(0,8), { path: '/', expires: 180 });
	}
	if (getValue('repCode') != '') {
		$.cookie('repCode', getValue('repCode'), { path: '/', expires: 180 });
	}
	if (getValue('tracking') != '') {
		$.cookie('tracking', getValue('tracking'), { path: '/', expires: 180 });
	}
}


function getValue(varname)
{
  // First, we load the URL into a variable
  var url = window.location.href;

  // Next, split the url by the ?
  var qparts = url.split("?");

  // Check that there is a querystring, return "" if not
  if (qparts.length < 2)
  {
    return "";
  }
  // Then find the querystring, everything after the ?
  var query = qparts[1];

  // Split the query string into variables (separates by &s)
  var vars = query.split("&");
  // Initialize the value with "" as default
  var value = "";

  // Iterate through vars, checking each one for varname
  for (i=0;i<vars.length;i++)
  {
    // Split the variable by =, which splits name and value
    var parts = vars[i].split("=");
    
    // Check if the correct variable
    if (parts[0] == varname)
    {
      // Load value into variable
      value = parts[1];
      // End the loop
      break;
    }
  }
  
  // Convert escape code
  value = unescape(value);

  // Convert "+"s to " "s
  value.replace(/\+/g," ");

  // Return the value
  return value;
}

function spawnQuoteWindow(href){

	if ($.cookie('primaryBrokerId') || $.cookie('repCode') || $.cookie('repCode') || $.cookie('tracking')) {
			tempStr = (href.indexOf("?") > 0) ? "&" : "?";
			if ($.cookie('primaryBrokerId') && !$.cookie('tracking')) {
				tempStr += ("primaryBrokerId=" + $.cookie('primaryBrokerId') + "&producingBrokerId=" + $.cookie('producingBrokerId'));
			} else if ($.cookie('primaryBrokerId') && $.cookie('tracking')) {
				tempStr += ("primaryBrokerId=" + $.cookie('primaryBrokerId') + "&producingBrokerId=" + $.cookie('producingBrokerId') + "&tracking=" + $.cookie('tracking'));
			} else if ($.cookie('repCode') && !$.cookie('tracking')) {
				tempStr += "repCode="+$.cookie('repCode');
			} else if ($.cookie('repCode') && $.cookie('tracking')) {
				tempStr += ("repCode="+$.cookie('repCode') + "&tracking=" + $.cookie('tracking'));
			} else if ($.cookie('tracking') && !$.cookie('repCode') && !$.cookie('primaryBrokerId')) {
				tempStr += "tracking=" + $.cookie('tracking');
			}
	href += tempStr;
		}
   spawnWindow('standard', href);
   return false;
   }

function spawnApplyWindow(href){

	if ($.cookie('primaryBrokerId') || $.cookie('repCode') || $.cookie('repCode') || $.cookie('tracking')) {
			tempStr = (href.indexOf("?") > 0) ? "&" : "?";
			if ($.cookie('primaryBrokerId') && !$.cookie('tracking')) {
				tempStr += ("primaryBrokerId=" + $.cookie('primaryBrokerId') + "&producingBrokerId=" + $.cookie('producingBrokerId'));
			} else if ($.cookie('primaryBrokerId') && $.cookie('tracking')) {
				tempStr += ("primaryBrokerId=" + $.cookie('primaryBrokerId') + "&producingBrokerId=" + $.cookie('producingBrokerId') + "&tracking=" + $.cookie('tracking'));
			} else if ($.cookie('repCode') && !$.cookie('tracking')) {
				tempStr += "repCode="+$.cookie('repCode');
			} else if ($.cookie('repCode') && $.cookie('tracking')) {
				tempStr += ("repCode="+$.cookie('repCode') + "&tracking=" + $.cookie('tracking'));
			} else if ($.cookie('tracking') && !$.cookie('repCode') && !$.cookie('primaryBrokerId')) {
				tempStr += "tracking=" + $.cookie('tracking');
			}
	href += tempStr;
		}
   spawnSecureWindow(href);
   return false;
   }

