// THIS JAVASCRIPT FUNCTION IS USED TO CALCULATE CAR COST USING AJAX //
/**
* Sweadi
* AJAX Combo Updater
*
* LICENSE: The source file is subject to GNU Public License
* You can Modify, Delete, Use this Class in Personal and Commerical Projects
*
*
* @author Asad Mehmood
* @copyright 2009 sweadi
* @version v1.0.1 03/31/2010 16:20:46 PM
*/
/**
* Retrieve values from Cost Calculator and Display the calculated values in hidden Div
*
*/
var type;
function calCost(costType)
{
var frm = document.calFrm;
var flag = false;
var country = frm.cal_country.value;
var port = frm.cal_port.value;
var freight_type = frm.freight_type.value;
var url_param1 = "";
type = costType;
if(country.length == 0)
{
alert("Please Select Country");
frm.cal_country.focus();
}
else if(port.length == 0)
{
alert("Please Select Port");
frm.cal_port.focus();
}
else if(freight_type.length == 0)
{
alert("Please Select Freight Type");
frm.freight_type.focus();
}
else
flag = true;
if(costType == "catalog")
{
var make = frm.cal_make.value;
var model = frm.cal_model.value;
if(make.length == 0)
{
alert("Please Select Make");
frm.cal_make.focus();
flag = false;
}
else if(model.length == 0)
{
alert("Please Select Make");
frm.cal_model.focus();
flag = false;
}
url_param1 = "&make="+make+"&model="+model;
}
else if(costType == "cardetail")
{
var m3 = frm.m3.value;
var fob_price = frm.fob_price.value;
var inspection = (frm.chk_inspection.checked) ? 1 : 0;
if(m3.length == 0)
{
alert("Please Enter M3");
frm.cal_make.focus();
flag = false;
}
else if(fob_price.length == 0)
{
alert("Please Enter Estimated FOB Price");
frm.fob_price.focus();
}
url_param1 = "&fob_price="+fob_price+"inspection="+inspection+"&m3="+m3;
}
url_param = "action=cost_cal&cost_type="+costType+"&country="+country+"&port="+port+"&fob_price="+fob_price+"&freight_type="+freight_type+"&inspection="+inspection+url_param1;
if(flag)
{
if (window.XMLHttpRequest)
{
http_request = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
url ='http://www.autocraftjapan.com/ajax/cost.ajax.php?'+url_param;
try
{
http_request.open('GET', url,true)
}
catch(err){alert(err.toString());}
http_request.onreadystatechange = handleCalculation;
try
{
http_request.send(null);
}catch(err){alert(err.toString());}
}
}
function handleCalculation()
{
if(http_request.readyState != 4)
{
document.getElementById('loadingDiv').innerHTML = '
';
showDiv('loadingDiv');
}
if (http_request.readyState == 4)
{
xmldoc=http_request.responseXML;
if(xmldoc.getElementsByTagName("CAL")[0].hasChildNodes())
{
if(xmldoc.getElementsByTagName("ERROR_FLAG")[0].hasChildNodes())
{
if(xmldoc.getElementsByTagName("ERROR_FLAG")[0].firstChild.data==0)
{
if(type=="catalog")
{
reshtml = '
| M3 | '+xmldoc.getElementsByTagName("M3")[0].firstChild.data+' |
| FREIGHT(USD) | '+xmldoc.getElementsByTagName("FREIGHT_USD")[0].firstChild.data+' Approx |
| FREIGHT(JPY) | '+xmldoc.getElementsByTagName("FREIGHT_JPY")[0].firstChild.data+' Approx |