/**
 * site_functions.js - JavaScript Functions.
 * @package site_functions.js
 * @author Victor Leonard :: OSD
 * @copyright 2005 - 2006 Victor Leonard
*/


/**
 * popUp Function
 * Launches pop up with given URL.
 * @param string URL (URL to include in the popup)
 * @param string height (height of the popup)
 * @param string width (width of the popup)
 * @param string scroll (boolean to show / hide the scrollbar)
 * @param string resize (boolean to enable / disable the resizing)
 * @access public
*/
function popUp(URL, height, width, scroll, resize) { 
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '"+id+"', 'toolbar=0,scrollbars="+scroll+ ",location=0,statusbar=0,menubar=0,resizable="+resize+",width="+width+",height="+height+",left = 10,top = 10');");
}

/**
 * calcTotal Function
 * Takes details of item selected and adds cost * quantity 
 * to total order cost.
 * @param string qty_id (HTML Form quantity element ID)
 * @param string qty_value (HTML Form quantity element value)
 * @param string item_id (HTML Form item details ID)
 * @access public
*/
function calcTotal(qty_id, qty_value, item_id) { 
	/** Define var for total cost for page. */
	var order_total = 0.00;

	if (isNaN(qty_value) || qty_value.match(/ /g) || qty_value == '') { 
		alert('Please Enter a Quantity');
		document.getElementById(qty_id).value = 0;
	}
	num_items = parseInt(document.getElementById('num_items').value);
	for (i=1; i <= num_items; i++) { 
		item_price = parseFloat(document.getElementById('item_price_'+i).value);
		item_qty = parseInt(document.getElementById('item_qty_'+i).value);
		order_total+= item_price * item_qty;
	}

	formatted_total = order_total.toFixed(2);
	document.getElementById('order_total').value = formatted_total;
}

/**
 * calcTotal Function
 * Takes details of item selected and adds cost * quantity 
 * to total order cost.
 * @param string qty_id (HTML Form quantity element ID)
 * @param string qty_value (HTML Form quantity element value)
 * @param string item_id (HTML Form item details ID)
 * @access public
*/
function calcTotal2(qty_id, qty_value, item_id) { 
	/** Define var for total cost for page. */
	var order_total = 0.00;

	if (isNaN(qty_value) || qty_value.match(/ /g)) { 
		alert('Please Enter a Quantity');
		document.getElementById(qty_id).value = 0;
	}
	num_items = parseInt(document.getElementById('num_items2').value);
	for (i=1; i <= num_items; i++) { 
		item_price = parseFloat(document.getElementById('2item_price_'+i).value);
		item_qty = parseInt(document.getElementById('2item_qty_'+i).value);
		order_total+= item_price * item_qty;
	}

	formatted_total = order_total.toFixed(2);
	document.getElementById('2order_total').value = formatted_total;
}

/**
 * CheckOrderSubmit Function
 * Checks details of items selected customer details.
 * @access public
*/
function CheckOrderSubmit() { 
	var order_total = parseFloat(document.getElementById('order_total').value);
	var emailVal = document.form.email.value;
	var pass = true;
	var details = 'Invalid information entered.\n\n';

	//if (order_total == 0.00) { 
	//	details+= '- Please select some Services.\n\n';
	//	pass = false;
	//}
	if (document.form.bride.value == '') { 
		details+= '- Please enter Name of the Bride.\n\n';
		if (pass) document.form.bride.focus();
		pass = false;
	}
	if (document.form.groom.value == '') { 
		details+= '- Please enter Name of the Groom.\n\n';
		if (pass) document.form.groom.focus();
		pass = false;
	}
	if (document.form.telno.value == '') { 
		details+= '- Please enter a Telephone Number.\n\n';
		if (pass) document.form.telno.focus();
		pass = false;
	}
	if (document.form.address.value == '') { 
		details+= '- Please enter an Address.\n\n';
		if (pass) document.form.address.focus();
		pass = false;
	}
	if (document.form.reception.value == '') { 
		details+= '- Please enter a Reception Venue.\n\n';
		if (pass) document.form.reception.focus();
		pass = false;
	}
	if (emailVal == '') { 
		details+= '- Please enter an Email Address.\n\n';
    	if (pass) document.form.email.focus();
		pass = false;
	}
	else if (emailVal.indexOf("@") == -1){ 
		details+= '- Please enter a properly formatted Email Address.\n\n';
    	if (pass) document.form.email.focus();
		pass = false;
	}
	else if (emailVal.indexOf(".") == -1){ 
		details+= '- Please enter a properly formatted Email Address.\n\n';
    	if (pass) document.form.email.focus();
		pass = false;
	}
	if (document.form.date.value == '') { 
		details+= '- Please enter a Wedding Date.\n\n';
		if (pass) document.form.date.focus();
		pass = false;
	}
	if (document.form.church.value == '') { 
		details+= '- Please enter a Church.\n\n';
		if (pass) document.form.church.focus();
		pass = false;
	}
	if (document.form.guests.value == '') { 
		details+= '- Please enter a estimate Number of Guests.\n\n';
		if (pass) document.form.guests.focus();
		pass = false;
	}
	if (pass) { 
		//alert('submits okay');
		return true;
	}
	else { 
		details+= 'Please correct the above errors before proceeding.    \n\n';
		alert(details);
		return false;
	}
}

function writetostatus(input){
    window.status=input
    return true
}
