// Javascript script to be used for Affiliate referral tracking
// with 1ShoppingCart(c) 2009 http://www.1shoppingcart.com
// Only supports ?af=nnnnnn url parameters, not other general 
// commands included in 1ShoppingCart's server-side scripts
// cmd.php or cmd.asp. This is for performance speedup reasons.

// Gets the value of a request parameter
function getRequestParameter(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];
	}
}

// Checks the existence of a parameter
function isset(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	if (results === null) {
		return false;
	} else {
		return true;
	}
}

function generateUrlAndRedirect() {
	var baseurl = "http://www.1shoppingcart.com";
	var dest = "http://www.Recruit-Me.com";
	var localaf = "";

	// Query string
	var querystring = "";
	if (window.location.search.length > 0) {
		querystring = window.location.search.split("?")[1];
	}

	// Affiliate
	if (isset("af")) {
		localaf = getRequestParameter("af");
	} else if (isset("AF")) {
		localaf = getRequestParameter("AF");
	} else if(isset("Af")) {
		localaf = getRequestParameter("Af");
	} else if(isset("aF")) {
        localaf = getRequestParameter("aF");
    }

    if (localaf != "") {
        dest = baseurl + "/app/aftrack.asp?afid=" + localaf;
    } 

	window.location = dest;
}

window.onload = generateUrlAndRedirect;
