/**
 *	Javascript for AJAX
 *
 */
 
 
 

function AJAXhandler()
{
    var ret = null;
    try {
        ret = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (e) {
        try {
            ret = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (ee) {
            ret = null;
        }
    }

	if (!ret && typeof XMLHttpRequest != 'undefined')
		ret = new XMLHttpRequest();

    return ret;
}// EOF AJAXhandler()


// AJAX request is made here for dash_pricing
function AJAX_DASH_process(O, D, W)
{
	var ajax = AJAXhandler();
	var uri  = "forAjax.php?for=dash&origin="+O+"&destination="+D+"&weight="+W;

	ajax.open("GET", uri, true);
	ajax.onreadystatechange=function()
	{
	  if (ajax.readyState==4)
	  {
	   data = ajax.responseText;
	   	showWeightRate(data);
	  }
 	}
	ajax.send(null)
}// EOF AJAX_DASH_process()

// AJAX request is made here for priority_zones_settings
function AJAX_PRIORITY_process(O, D)
{
	var ajax = AJAXhandler();
	var uri  = "forAjax.php?for=priority&origin="+O+"&destination="+D;

	ajax.open("GET", uri, true);
	ajax.onreadystatechange=function()
	{
	  if (ajax.readyState==4)
	  {
	   data = ajax.responseText;
	   	showMinimumBulk(data);
	  }
 	}
	ajax.send(null)
}// EOF AJAX_PRIORITY_process()

function AJAX_CITY_process(S, ID)
{
 // alert(S);
 // alert(ID);
	disableCity(ID);
	var ajax = AJAXhandler();
	if(ID=='state')
	{
		var uri  = "FORAJAX.PHP?for=city&state="+S;}
		
	//alert (uri);
	
	ajax.open("GET", uri, true);
	ajax.onreadystatechange=function()
	{
	  if (ajax.readyState==4)
	  {
		  if(ajax.status==200){
	   data = ajax.responseText;
	   //alert(data.length+"\n"+"LLL");

		showCity(data, ID);}
	  }
 	}
	ajax.send(null)
}// EOF AJAX_CITY_process()

function AJAX_SPLPRIORITY_process(O, D)
{
	var ajax = AJAXhandler();
	var uri  = "forAjax.php?for=splp&origin="+O+"&destination="+D;

	ajax.open("GET", uri, true);
	ajax.onreadystatechange=function()
	{
	  if (ajax.readyState==4)
	  {
	   data = ajax.responseText;
	   	showSplMinimumBulk(data);
	  }
 	}
	ajax.send(null)
}// EOF AJAX_SPLPRIORITY_process()

//-----------------------------------------

// data is fed to dash processing form here
function showWeightRate(data)
{
	var Add = document.getElementById('add');
	var Edit= document.getElementById('edit');
	var val = data.split(',');
	if (!val[0])
	{
		val[0] = 'Not Set';
		val[2] = '';
		if (Add.style.display == 'none') {
			Add.style.display  = 'block';
			Edit.style.display = 'none';
		}	
	} else {
				if (Edit.style.display == 'none') {
					Edit.style.display  = 'block';
					Add.style.display = 'none';
				}	
		   }

	document.frmDashPrices.rate.value = val[0];
	document.frmDashPrices.id.value   = val[2];
	if (val[1])
		document.frmDashPrices.weight.selectedIndex = val[1]-1;

	return;
}// EOF showWeightRate()


// data is fed to dash processing form here
function showMinimumBulk(data)
{
	var Add = document.getElementById('add');
	var Edit= document.getElementById('edit');
	var val = data.split(',');
	if (!val[0])
	{
		val[0] = 'Not Set';
		val[1] = 'Not Set';
		val[2] = '';
		if (Add.style.display == 'none') {
			Add.style.display  = 'block';
			Edit.style.display = 'none';
		}	
	} else {
				if (Edit.style.display == 'none') {
					Edit.style.display = 'block';
					Add.style.display  = 'none';
				}
		   }

	document.frmPriorityZoneSettings.minimum.value   = val[0];
	document.frmPriorityZoneSettings.bulk.value 	 = val[1];
	document.frmPriorityZoneSettings.id.value   	 = val[2];

	return;
}// EOF showMinimumBulk()


function showCity(data, id) { 
	if (data.indexOf(':')<0) {
		alert('No sublevel for the selected category!!');
		return;
	}
	
	var cities  = data.split(':');
	var C		= document.getElementById(id);

var vijay="";
	for (i=0;i<cities.length;i++)
	{
		city = cities[i].split(',');
		vijay += city[1] + "\n";
		if (city[2] != 'undefined' && city[2] != null) { 
			city[1] += ' / '+city[2];
//			city[0]  = city[2];

		}
		C.options[i] = new Option(city[1], city[0]);
	}

//	C.options[0] = new Option('select');
	C.selectedIndex = cities.length-1;
	C.disabled = 0;
	return;
}// EOF showCity()

function disableCity(id) {
		var C	 = document.getElementById(id);
		C.options.length = 0;
		C.options[0] = new Option('Loading..');
		C.disabled = 1;
}// EOF disableCity()


// data is fed to spl. priority pricing form here
function showSplMinimumBulk(data)
{
	var Add = document.getElementById('add');
	var Edit= document.getElementById('edit');
	var val = data.split(',');
	if (!val[0])
	{
		val[0] = 'Not Set';
		val[1] = 'Not Set';
		val[2] = '';
		if (Add.style.display == 'none') {
			Add.style.display  = 'block';
			Edit.style.display = 'none';
		}	
	} else {
				if (Edit.style.display == 'none') {
					Edit.style.display = 'block';
					Add.style.display  = 'none';
				}
		   }

	document.frmSplPriorityPricing.minimum.value = val[0];
	document.frmSplPriorityPricing.bulk.value 	 = val[1];
	document.frmSplPriorityPricing.id.value   	 = val[2];

	return;
}// EOF showSplMinimumBulk()




