/*************************************************\
| Preorder/Backorder Mod v2.0                     |
|                                                 |
| BCS Engineering                                 |
| Copyright (c) 2006-2008 BCS Engineering,        |
| Carrie L. Saunders <support@bcsengineering.com> |
| All rights reserved.                            |
| See http://www.bcsengineering.com/license.shtml |
| for full license                                |
| For X-cart versions 4.0.X                       |
\*************************************************/

var base_preorder_text = "<b>"+pb_product_not_available+"</b>&nbsp;<span onclick=\"javascript: window.open('preorder_backorder.php?productid="+pb_productid+"&variantid=@@variantid@@','pbwin','width=500,height=500');\" onmouseover=\"javascript: this.className = 'preorder_hover';\" onmouseout=\"javascript: this.className = 'preorder';\" class=\"preorder\">"+pb_preorder+"</span> "+pb_yours_today+".<br />"+
"<span style=\"color:red;\">"+pb_due_in_stock+": @@due_in_stock@@</span><br />";

var base_backorder_text = "<b>"+pb_product_out_of_stock+"</b>&nbsp;<span onclick=\"javascript: window.open('preorder_backorder.php?productid="+pb_productid+"&variantid=@@variantid@@','pbwin','width=500,height=500');\" onmouseover=\"javascript: this.className = 'preorder_hover';\" onmouseout=\"javascript: this.className = 'preorder';\" class=\"preorder\">"+pb_backorder+"</span> "+pb_yours_today+".<br />"+
"<span style=\"color:red;\">"+pb_due_in_stock+": @@due_in_stock@@</span><br />"

function set_pb_text(variant_element){

	var variantid = variantids[variant_element];

	if(!document.getElementById('pre_text'))
		return;

	var text_element = document.getElementById('pre_text');

	text_element.innerHTML = '';

	if(variant_preorder.length < 1)
		return;

	var variant_found = false;
	for(var x in variant_preorder){
		if(x == variantid){
			variant_found = true;
			break;
		}
	}

	if(!variant_found)
		return;

	if(variant_preorder[variantid]['pb'] == 'B' && document.getElementById('product_avail') && document.getElementById('product_avail').tagName.toUpperCase() == "SELECT"){
		var avail_select = document.getElementById('product_avail');

		while(avail_select.options.length > 0)
			avail_select.options[0] = null;

		var cnt = 0;
		for(var i = 1; i <= 50; i++)
			avail_select.options[cnt++] = new Option(i, i);

		avail_select.options[0].selected = true;
	}

	if(variant_preorder[variantid]['pb'] == 'P')
		var html_text = base_preorder_text.replace("@@variantid@@",variantid);
	else
		var html_text = base_backorder_text.replace("@@variantid@@",variantid);

	html_text = html_text.replace('@@due_in_stock@@',variant_preorder[variantid]['date_avail']);

	text_element.innerHTML = html_text;

	return;
}

