
function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()

function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}
// end of function CommaFormatted()

function addParenthesis(number) {
	if (number.substring(0,1) == '-')
		temp = "(" + number.substring(1,number.length) + ")";
	else 
		temp = number;
	return temp;
}

function formatNumber(number) {
	var result = CurrencyFormatted(number);
	result = CommaFormatted(result);
	result = addParenthesis(result);
	return result;
}
function calculate_amount(type,flag) {
	form = document.frm;
	obj_total = document.getElementById(type+'_total');
	obj_grand_total = document.getElementById('grand_total');
	
	total = 0;
	for(i=0; i<form.length;i++) {
		obj = form.elements[i];
		val = obj.value.slice(obj.value.indexOf('|')+1,obj.value.length);
		if(obj.name.substr(0,3) != type) {
			continue;
		} 
		if((obj.type == "radio") || (obj.type == "checkbox")) {
			if(obj.checked == true) 
				total += Number(val) ;
		} else if(obj.type == "select-one") 
			total += Number(val) ;
	}
	
	if(obj_grand_total != null) {
		pre_total = obj_total.innerHTML;
		pre_total = pre_total.replace("$","");
		pre_total = pre_total.replace(",","");
	
		pre_grand_total = obj_grand_total.innerHTML;
		pre_grand_total = pre_grand_total.replace("$","");
		pre_grand_total = pre_grand_total.replace(",","");
		
		

		if(isNaN(pre_grand_total))  pre_grand_total = 0;
		if(isNaN(pre_total))  pre_total = 0;
		
		//alert("pre g total = " + pre_grand_total + "\n pre total = " + pre_total);
	
		temp = Number(pre_grand_total) + Number(total);
		
		if(flag == 0) temp = temp - Number(pre_total);
		//alert(temp);
		obj_grand_total.innerHTML = "$" + formatNumber(temp);
	}
	
	obj_total.innerHTML = "$" + formatNumber(total);

}





/*function close_func(id)
{
var div_id = id;
document.getElementById(div_id).style.display = 'none';
}*/

function close_func(id,id2,typ,lh)
{
var div_id = id;
var oth_div_id = id2;
var form_type = typ;
var line_hide = lh;
document.getElementById(div_id).style.display = 'none';
document.getElementById(line_hide).style.display = '';

var ss = document.getElementById(oth_div_id).style.display;

obj_total = document.getElementById(form_type+'_total');
obj_grand_total = document.getElementById('grand_total');
document.getElementById('include_'+form_type).value=0;

pre_total = obj_total.innerHTML;
		pre_total = pre_total.replace("$","");
		pre_total = pre_total.replace(",","");
	
		pre_grand_total = obj_grand_total.innerHTML;
		pre_grand_total = pre_grand_total.replace("$","");
		pre_grand_total = pre_grand_total.replace(",","");

		if(isNaN(pre_grand_total))  pre_grand_total = 0;
		if(isNaN(pre_total))  pre_total = 0;
	
		temp = Number(pre_grand_total) - Number(pre_total); 
		obj_grand_total.innerHTML = "$" + formatNumber(temp);


if(ss == 'none')
{
document.getElementById("t_cost").style.display = 'none';
}

}
 
/*function close_func_2(id,id2,id3)
{
var div_id = id;
var oth_div_id = id2;
var oth_div_id2 = id3;
document.getElementById(div_id).style.display = 'none';

var ss = document.getElementById(oth_div_id).style.display;
var ss2 = document.getElementById(oth_div_id2).style.display;

if(ss == 'none' && ss2 == 'none')
{
document.getElementById("t_cost").style.display = 'none';
}

}
*/

function close_func_2(id,id2,id3,typ,lh)
{
var div_id = id;
var oth_div_id = id2;
var oth_div_id2 = id3;
var form_type = typ;
var line_hide = lh;
document.getElementById(div_id).style.display = 'none';
document.getElementById(line_hide).style.display = '';

var ss = document.getElementById(oth_div_id).style.display;
var ss2 = document.getElementById(oth_div_id2).style.display;


obj_total = document.getElementById(form_type+'_total');
obj_grand_total = document.getElementById('grand_total');
document.getElementById('include_'+form_type).value=0;


pre_total = obj_total.innerHTML;
		pre_total = pre_total.replace("$","");
		pre_total = pre_total.replace(",","");
	
		pre_grand_total = obj_grand_total.innerHTML;
		pre_grand_total = pre_grand_total.replace("$","");
		pre_grand_total = pre_grand_total.replace(",","");

		if(isNaN(pre_grand_total))  pre_grand_total = 0;
		if(isNaN(pre_total))  pre_total = 0;
	
		temp = Number(pre_grand_total) - Number(pre_total);
		obj_grand_total.innerHTML = "$" + formatNumber(temp);




if(ss == 'none' && ss2 == 'none')
{
document.getElementById("t_cost").style.display = 'none';
}

}


function open_func(id,typ,lh)
{
var div_id = id;
var form_type = typ;
var line_hide = lh;
var disp_chk = document.getElementById(div_id).style.display;
if(disp_chk == 'none')
{
calculate_amount(form_type,1);
}
document.getElementById('include_'+form_type).value=1;
document.getElementById(div_id).style.display = '';
document.getElementById("t_cost").style.display = '';
document.getElementById(line_hide).style.display = 'none';



}




function SEO_C() 
{
var price = 0;
var duration = document.getElementById("consultation_duration").value; 

		if (duration=='1 Hour')
	{
		price =  price + 500;
	}
	if (duration=='2 Hours')
	{
		price =  price + 1000;
	}
	if (duration=='3 Hours')
	{
		price =  price + 1500;
	}
	
	
document.getElementById("amount").innerHTML = '<b>$</b>' + price; 

}
