function formatNumber(myNum, numOfDec)
{
	var decimal = 1
	for(i=1; i<=numOfDec;i++)
	decimal = decimal *10

	var myFormattedNum = (Math.round(myNum * decimal)/decimal).toFixed(numOfDec)
	return(myFormattedNum)
} 

function cost_calc(hit_size, website_size, hits_day){
	month_transfer = (((hits_day * hit_size) / 1024) * 30.417) / 4;
	month_storage = website_size / 4;
	calc_total = formatNumber((month_transfer + month_storage), 2);
	
	if (calc_total > 300){calc_total = 300;}
	return "R "+calc_total;
}

function sel_pack(text){
	var http = new XMLHttpRequest();   

    http.open("POST", "ajax_load_session.php", true);   
    params = "text=" + text;
    
    //Send the proper header information along with the request
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    
    http.onreadystatechange = function(){//Call a function when the state changes.
        if (http.readyState == 4 && http.status == 200) {
			//alert(http.responseText);	
        }
    }
    http.send(params);
}

function submit_request(){
	// Selected radio options.
	var pack_option = "";
	var got_web = "";
	var contact_how = "";
	
	// Other options.
	var sel_pack = document.getElementById("selected_package").innerHTML;
	var web_address = document.getElementById("web-site-address").value;
	var your_name = document.getElementById("your-name").value;
	var business_name = document.getElementById("business-name").value;
	var contact_mail = document.getElementById("my_mail").value;
	var contact_phone = document.getElementById("my_phone").value;
	
	// Requirements.
	var requirements = document.getElementById("web-design-features").value;
	
	for( i = 0; i < document.getElementsByName('web-host').length; i++ )
	{
		if( document.getElementsByName('web-host')[i].checked == true )
		pack_option = document.getElementsByName('web-host')[i].value;
	}
	
	for( i = 0; i < document.getElementsByName('got-web-site').length; i++ )
	{
		if( document.getElementsByName('got-web-site')[i].checked == true )
		got_web = document.getElementsByName('got-web-site')[i].value;
	}
	
	for( i = 0; i < document.getElementsByName('howto_contact').length; i++ )
	{
		if( document.getElementsByName('howto_contact')[i].checked == true )
		contact_how = document.getElementsByName('howto_contact')[i].value;
	}
	
	// AJAX
	var http = new XMLHttpRequest();   

    http.open("POST", "submit_request.php", true);   
    params = "pack_option=" + pack_option;
	params += "&sel_pack=" + sel_pack;
	params += "&got_web=" + got_web;
	params += "&web_address=" + web_address;
	params += "&contact_how=" + contact_how;
	params += "&your_name=" + your_name;
	params += "&business_name=" + business_name;
	params += "&contact_mail=" + contact_mail;
	params += "&contact_phone=" + contact_phone;
	params += "&requirements=" + requirements;
    
    //Send the proper header information along with the request
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");
    
    http.onreadystatechange = function(){//Call a function when the state changes.
        if (http.readyState == 4 && http.status == 200) {
			alert(http.responseText);	
        }
    }
    http.send(params);	
}

