$(document)
		.ready(
				function() {
					soap.Impfclptp();
					$("#Exp-content").hide();
					$("#Imp-label").click(ShowHide);
					$("#Exp-label").click(ShowHide);
					$("#btnCalculate").click(getResult);
					$("#btnReset").click(resultClear);
					$(
							"input[@name=ImpService], input[@name=ExpService], input[@name=ExpType], input[@name=ImpType]")
							.click(showDestination);
					$('#ExpInsur').hide();
					$('#container-1').tabs( {
						fxFade : true,
						fxSpeed : 'fast',
						onClick : function(o) {
							resultClear();
							var fn = o.id + '();';
							eval(fn);
						},
						onHide : function() {
							// alert('onHide');
					},
					onShow : function() {
						// alert('onShow');
					}

					});
				});

function ShowHide() {
	var id = this.id.replace('-label', '');
	$('#' + id + '-content').show("slow");
	idH = ((id == 'Imp') ? 'Exp' : 'Imp');
	$('#' + idH + '-content').hide("slow");
	var fn = 'soap.' + id + 'fclptp()';
	request.ID = id;
	eval(fn);
	RowCount[id] = 0;
	resultClear();
}

function showDestination() {
	resultClear();
	var id = this.id.replace('-ptp', '');
	id = id.replace('-ptd', '');
	id = id.replace('-Type', '');
	id = id.replace('-rate', '');
	var fn = $('input[@name=' + id + 'Type]:checked').val()
			+ $('input[@name=' + id + 'Service]:checked').val() + '()';
	;
	fn = 'soap.' + id + fn;
	eval(fn);
}

function _DestinationCityClear(id) {
	$('#' + id + 'DestinationCity').hide("slow", function() {
		$('#' + id + 'DestinationCity').html('');
	});
}

function AddSelectBox(div, selectId, label, onchange, reloadicon) {
	_insert($('#' + request.ID + div), getSelectHTML(selectId, label, onchange,
			reloadicon));
}
function AddTextBox(div, Id, label) {
	_insert($('#' + request.ID + div), getTextHTML(Id, label));
}

function _insert(div, html) {
	div.hide("slow", function() {
		div.html(html);
	});
	div.show("slow");
}

function _getPrefix(id) {
	if (id == 'Imp')
		return 'GetImport';
	else
		return 'GetExport';
}

function getSelectHTML(key, label, onchange, reloadicon) {
	var id = request.ID + key;
	if (reloadicon) {
		display = '';
	} else
		display = 'none';
	return '<label style="width: 170px;" for="'
			+ label
			+ '">'
			+ label
			+ ':&nbsp;</label><select style="float:left;width: 150px;" onchange="'
			+ onchange + '" class="textBox" id="' + id + '" name="' + id
			+ '"><option value="" selected="selected">-----</option></select>'
			+ '<div style="display:' + display + '" id="' + id
			+ '-reloadicon"class="reloadicon"><img src="' + HTTP_PATH
			+ 'img/ajax-loader.gif"></div>';
}

function getTextHTML(key, label) {
	var id = request.ID + key;
	return '<label style="width: 170px;" for="' + label + '">' + label
			+ ':&nbsp;</label><input class="textBox" type="text" id="' + id
			+ '" name="' + id + '"/>';
}

function empty(mixed_var) {
	var key;
	if (mixed_var === "" || mixed_var === 0 || mixed_var === "0"
			|| mixed_var === null || mixed_var === false
			|| mixed_var === undefined) {
		return true;
	}

	if (typeof mixed_var == 'object') {
		for (key in mixed_var) {
			return false;
		}
		return true;
	}
	return false;
}

function isNumber(val) {
	return /^-?((\d+\.?\d?)|(\.\d+))$/.test(val);
}

function is_valid_email(email) {
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
			.test(email);
}

function OnLocationServiceClick(objCheckBox) {
	// For All Pickup Location Services////////////////
	if (objCheckBox.id == "chkResPick") {
		if (objCheckBox.checked)
			_set('chkConstPick', false, true);
		else
			_set('chkConstPick', false, false);
	} else if (objCheckBox.id == "chkConstPick") {
		if (objCheckBox.checked)
			_set('chkResPick', false, true);
		else
			_set('chkResPick', false, false);
	}
	// For All Delivery Location Services////////////////
	if (objCheckBox.id == "chkResDel") {
		if (objCheckBox.checked)
			_set('chkConstDel', false, true);
		else
			_set('chkConstDel', false, false);
	} else if (objCheckBox.id == "chkConstDel") {
		if (objCheckBox.checked)
			_set('chkResDel', false, true);
		else
			_set('chkResDel', false, false);
	}
}

function _set(id, checked, disabled) {
	$('#' + id).attr('checked', checked);
	$('#' + id).attr('disabled', disabled);
}

function setData(objID) {
	if (!empty(request.responceData)) {
		_reloadBOX($('#' + request.ID + objID), request.responceData.split(':'));
	}
	$('#' + request.ID + objID + '-reloadicon').css( {
		display : 'none'
	});
}

function _reloadBOX(obj, dataArray) {
	if (obj.length > 0) {
		obj.html('<option value="" selected="selected">-----</option>');
		for (k in dataArray) {
			obj.append($("<option></option>").attr("value", dataArray[k]).text(
					dataArray[k]));
		}
	}
}

function getCityState(obj, id) {
	var zipID = '#' + obj.id;
	var cityID = '#' + obj.id.replace('Zip', 'CityState');
	var zipCode = $(zipID).val();
	var selectBox = $(cityID);
	selectBox.html('');
	if (isNumber(zipCode)) {
		var url = HTTP_PATH + 'rater-selections-zip-citystate.php';
		$.get(url, {
			zip : zipCode
		}, function(data) {
			var arr = data.split('|');
			for (k in arr) {
				var data = arr[k].split(':');
				if (!empty(data[0])) {
					var text = data[0] + ', ' + data[1];
					selectBox.append($("<option></option>").attr("value", text)
							.text(text));
				}
			}
		});
	}
}