/*
	This snippet of JS will determine if secure or non-secure URL's should be used.
	
	This will assign the correct URL to be used into the variables as follows:
		TX URL's (TX Engine)= tx_url
		CB URL's (Cobrand) = cb_url
		IMP URL's (Impressions) = imp_url
*/


var window_url = window.location;
var url_str = new String(window_url);

if(url_str.indexOf("https://") === 0) {
	// Secure URL's
	var tx_url = "https://secure.adprofile.net/tx/r";
	var cb_url = "https://secure.adprofile.net";
	var imp_url = "https://secure.adprofile.net/tx/r";
} else {
	// Non-secure URL's
	var tx_url = "http://tx.adprofile.net/tx/r";
	var cb_url = "http://cb.adprofile.net";
	var imp_url = "http://imp.adprofile.net/imp";
}


// ==================================================
//	Get Protocol
// ==================================================
function getProtocol() {
	if (url_str.indexOf("https://") === 0) {
		return "https://";
	} else if (url_str.indexOf("http://") === 0) {
		return "http://";
	}
}

// ==================================================
//	Form Action
// ==================================================

var applyForm = document.forms[0];

if (applyForm) {
	var questionmark_pos = applyForm.action.indexOf("?");
	
	var action_query = '';
	
	if (questionmark_pos >= 0) {
		action_query = applyForm.action.substr(questionmark_pos);
	}	
	
	// Check if the action is a TX link or a CB link, and assign the action accordingly
	if (applyForm.action.indexOf("tx.adprofile.net") > 0) {
		// TX Link
		applyForm.action = tx_url + action_query;
	} else if (applyForm.action.indexOf("cb.adprofile.net") > 0) {
		// CB Link
		applyForm.action = cb_url + action_query;
	}
}