var clk_apnd = "source=aw";
var aff_id = "affid=";
var is_ca = false;
var is_afid = false;
var affiliate = "";

function fixPhoneData(){
	all_ck = document.cookie.split(';');
	for(i=0; i<all_ck.length; i++){
		ck = all_ck[i]+'';
		if (ck.indexOf("showPhone") != -1){
			//alert('cookie found');
			is_ca = true;
			is_afid = true;
		}
		if (ck.indexOf("affID") != -1){
			affiliate = readCookie("affID");
		}
	}
	if (!is_ca){
		doc = document.location+'';
		if (doc.indexOf(clk_apnd) != -1){
			createCookie("showPhone","1",30);
			//alert('cookie created');
			is_ca = true;
			is_afid = true;
		}
		hq_1 = doc.split('?');
		hq = hq_1[1].split('&');
		for(i=0; i<hq.length; i++){
			if (hq[i].indexOf(aff_id) != -1){
				aaf = hq[i].split('=');
				createCookie("affID",aaf[1],30);
				affiliate = aaf[1];
			}
		}
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function fixSubmitForm(){
	dc = document.location+'';
	if ((dc.indexOf(aff_id) != -1) || (is_afid)){
		x = Math.random()+'';
		t = x.split('.');
		document.getElementById('title').value = t[1]+'-'+affiliate;
		document.getElementById('urlSuccess').value = "http://www.futuresdevelopment.com/complete.php?REF="+t[1];
	}else{
		document.getElementById('urlSuccess').value = "http://www.futuresdevelopment.com/complete.html";
	}
}

function swapButtonBG(elm,new_bg){
	elm.style.backgroundImage = "url("+new_bg+")";
}