<!--

//IMPORTANT!!! This file uses prototype methods, so prototype needs to be included


/** GENERIC FUNCTIONS ***************
/***********************************/

/**
 * Update the order total
 *
 */
function update_total() {
	var total = 0;

	total += get_product_total(); //the total cost of the selected product
	total += get_upgrades_total(); //the total cost of the selected upgrades

	$('total').update(total);
}

/**
 * Retrieve the price of the selected plan
 *
 */
function get_product_total() {
	var products = $$('.product_element');
	var prices = $$('.product_price_element');
	var total = 0;

	products.each(function(e, i) {

		//get the price of the selected product
		if (e.checked) {
			total = parseInt(prices[i].innerHTML.gsub(/[^0-9\.]/, ''));
			throw $break;
		}
	});

	return total;
}

/**
 * Retrieve the total of the selected upgrades
 *
 */
function get_upgrades_total() {
	var upgrades = $$('.upgrade_element');
	var prices = $$('.upgrade_price_element');
	var total = 0;

	upgrades.each(function(e, i) {

		//get the price of the selected product
		if (e.checked) {
			total += parseInt(prices[i].innerHTML.gsub(/[^0-9\.]/, ''));
		}
	});

	return total;
}

/**
 * Selected the specified products
 *
 */
function set_product() {
	product_selected.each(function(e) {
		e = $('product_' + e);

		if (e != null) {
			e.checked = true;
		}
	});
}

/**
 * Selected the specified upgrades
 *
 */
function set_upgrades() {
	upgrade_selected.each(function(e) {
		e = $('upgrade_' + e);

		if (e != null) {
			e.checked = true;
		}
	});
}


/** SSL RELATED FUNCTIONS **********
/***********************************/

function set_hosted_with(v) {
	document.getElementById('hosted_with_' + v).checked = true;

	if (v == 'syra') {
		document.getElementById('ssl_information').style.display = 'none';
	} else {
		document.getElementById('ssl_information').style.display = '';
	}
}

function set_server_software(v) {
	document.getElementById('server_software_element').value = v;
}

function update_hosted_with(v) {
	if (v == 'syra') {
		document.getElementById('ssl_information').style.display = 'none';
	} else {
		document.getElementById('ssl_information').style.display = '';
	}
}

function formCheckSSL(formobj) {
	var alertMsg = "Please complete the following required fields:\n";
    var l_Msg = alertMsg.length;

    if (document.getElementById('hosted_with_other').checked) {
		fieldRequired = Array('domain_name', 'csr', 'server_software');
		fieldDescription = Array('Domain Name', 'CSR File', 'Server Software');
	} else {
		fieldRequired = Array('domain_name');
		fieldDescription = Array('Domain Name');
	}

	//validate the form fields
	alertMsg += formCheck(formobj);

    if (alertMsg.length == l_Msg) {
        return true;
    } else {
        alert(alertMsg);

        return false;
    }
}


/** VIRTUAL SERVER FUNCTIONS ********
/***********************************/

/**
 * Update the product list to match the managed/unmanaged products
 *
 */
function update_managed(v) {
	if (v == 'yes') {
		document.getElementById('managed_yes_block').style.display = '';
		document.getElementById('managed_no_block').style.display = 'none';
	} else {
		document.getElementById('managed_yes_block').style.display = 'none';
		document.getElementById('managed_no_block').style.display = '';
	}

	$$('#managed_' + v + '_block input.product_element')[0].checked = true;

	//$$('.product_row').each(function(tr, i) {
		//tr.update(row_data[i]);
	//});

	update_total();
}


/**
 * Set the initial operating system
 *
 */
function set_os(v) {
	document.getElementById('os_' + v).checked = true;
}


/**
 * Set the initial managed value and called the update_managed function
 *
 */
function set_managed(v) {
	document.getElementById('managed_' + v).checked = true;

	update_managed(v);
}


/** SPAM FILTER TRIAL FUNCTIONS *****
/***********************************/

function formCheckSpamTrial(formobj) {
	var alertMsg = "Please complete the following required fields:\n";
    var l_Msg = alertMsg.length;

    fieldRequired = new Array('domain_name');
	fieldDescription = new Array('Domain Name');

	if (validate_login == 'true') {
		fieldRequired.push('username_login', 'password_login');
		fieldDescription.push('Username', 'Password');
	}

	//validate the form fields
	alertMsg += formCheck(formobj);

    if (alertMsg.length == l_Msg) {
        return true;
    } else {
        alert(alertMsg);

        return false;
    }
}

-->
