/********************************************************************/
/* Aresta Ascent Framework v2.3                                     */
/* ----------------------------                                     */
/* Copyright ©2004-2007 Aresta Enterprise LLC. All Rights Reserved. */
/* This file may not be redistributed in whole or significant part. */
/********************************************************************/

/************************************* adClick ***********************************/
function adClick(id,cost,user,buyer) {
	if (window.XMLHttpRequest) {
		adClickResponse = new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
		adClickResponse = new ActiveXObject('Microsoft.XMLHTTP');
	}
	//alert('http://www.writerscafe.org/?ajaxRequest=true&adClick=true&id='+id+'&cost='+cost+'&user='+user);
			
	adClickResponse.open('GET', 'http://www.writerscafe.org/?ajaxRequest=true&adClick=true&id='+id+'&cost='+cost+'&user='+user+'&buyer='+buyer);
	adClickResponse.send(null);
}

function checkAmount() {
	if (document.form_ad_buy._a.value < 5) {
		document.getElementById('_a_warning').innerHTML = "Each ad buy must be at least $5.00<br />";
		document.form_ad_buy.submit.disabled = true;
	}
	else {
		document.getElementById('_a_warning').innerHTML = "";
		document.form_ad_buy.submit.disabled = false;
	}
}

function checkBudget() {
	if (document.budget_form.budget.value < 2.5) {
		document.getElementById('budget_warning').innerHTML = "Your daily budget must be at least $2.50<br />";
		document.budget_form.submit.disabled = true;
	}
	else {
		document.getElementById('budget_warning').innerHTML = "";
		if ((document.budget_form.per[0].checked && document.budget_form.bid.value >= .5) || (document.budget_form.per[1].checked && document.budget_form.bid.value >= .25)) document.budget_form.submit.disabled = false;
	}
}

function checkBid() {
	//for (var i=0; i < document.budget_form.per.length; i++){ if (document.budget_form.per[i].checked){ var rad_val = document.budget_form.per[i].value; } }
	if (document.budget_form.per[0].checked) {
		if (document.budget_form.bid.value < .5) {
			document.getElementById('bid_warning').innerHTML = "The minimum bid is $0.50 per 1000 impressions<br />";
			document.budget_form.submit.disabled = true;
		}
		else {
			document.getElementById('bid_warning').innerHTML = "";
			if (document.budget_form.budget.value >= 2.5) document.budget_form.submit.disabled = false;
		}
	}
	if (document.budget_form.per[1].checked) {
		if (document.budget_form.bid.value < .25) {
			document.getElementById('bid_warning').innerHTML = "The minimum bid is $0.25 per click<br />";
			document.budget_form.submit.disabled = true;
		}
		else {
			document.getElementById('bid_warning').innerHTML = "";
			if (document.budget_form.budget.value >= 2.5) document.budget_form.submit.disabled = false;
		}
	}
}

function changeAmount() {
	// Recurring
	if (document.form_ad_buy.recurring.checked == true) document.form_ad_buy.a3.value = document.form_ad_buy._a.value;
	
	// One Time
	if (document.form_ad_buy.recurring.checked == false) document.form_ad_buy.amount.value = document.form_ad_buy._a.value;
}

function changePeriod() {
	if ($("monthly").checked) { period = "month"; }
	if ($("weekly").checked)  { period = "week"; }
	if ($("daily").checked)  { period = "day"; }
	
	// Recurring
	if (document.form_ad_buy.recurring.checked == true) {
		if (period == "month") {
			//document.form_ad_buy.a3.value = document.form_ad_buy.amount_m.value;
			document.form_ad_buy.t3.value = "M";
		} else if (period == "week") {
			//document.form_ad_buy.a3.value = document.form_ad_buy.amount_y.value;
			document.form_ad_buy.t3.value = "W";
		} else if (period == "day") {
			//document.form_ad_buy.a3.value = document.form_ad_buy.amount_y.value;
			document.form_ad_buy.t3.value = "D";
		}
	}
	
	// One Time
	/*if (document.form_ad_buy.recurring.checked == false) {
		if (period == "month") document.form_ad_buy.amount.value = document.form_ad_buy.amount_m.value;
		if (period == "week")  document.form_ad_buy.amount.value = document.form_ad_buy.amount_y.value;
	}
	
	/*new Ajax.Request('/?ajaxReq=buyExpires&period=' + period + '&recurring=' + document.form_ad_buy.recurring.checked + '&e=' + document.form_ad_buy.e.value,
	{
		method:'get',
		onSuccess: function(t){
			var r = t.responseText || "";
			$("recurring_text").innerHTML = "Have this automatically renew each " + period + ".";
			$('buyExpires').innerHTML = r;
		}
	});*/
}

function changeRecurring() {
	if ($("monthly").checked) { period = "month"; }
	if ($("weekly").checked)  { period = "year"; }
	if ($("daily").checked)  { period = "daily"; }
	
	// Recurring
	if (document.form_ad_buy.recurring.checked == true) {
		document.getElementById('renew').style.display = 'block';
		document.form_ad_buy.cmd.value = "_xclick-subscriptions";
		document.form_ad_buy.a3.value = document.form_ad_buy._a.value;
		document.form_ad_buy.amount.value = "";
		if (period == "month") { document.form_ad_buy.t3.value = "M"; }
		if (period == "weekly")  { document.form_ad_buy.t3.value = "W"; }
		if (period == "daily")  { document.form_ad_buy.t3.value = "D"; }
		document.form_ad_buy.p3.value = "1";
		document.form_ad_buy.src.value = "1";
		document.form_ad_buy.sra.value = "1";
	}
	
	// One Time
	if (document.form_ad_buy.recurring.checked == false) {
		document.getElementById('renew').style.display = 'none';
		document.form_ad_buy.cmd.value = "_xclick";
		document.form_ad_buy.amount.value = document.form_ad_buy._a.value;
		document.form_ad_buy.a3.value = "";
		document.form_ad_buy.t3.value = "";
		document.form_ad_buy.p3.value = "";
		document.form_ad_buy.src.value = "";
		document.form_ad_buy.sra.value = "";
	}
	
	/*new Ajax.Request('/?ajaxReq=buyExpires&period=' + period + '&recurring=' + document.form_ad_buy.recurring.checked + '&e=' + document.form_ad_buy.e.value,
	{
		method:'get',
		onSuccess: function(t){
			var r = t.responseText || "";
			$('buyExpires').innerHTML = r;
		}
	});*/
}