	function checkValidZipCityField(type) {
		switch (type) {
				case 'from':
					if ((jQuery('#fzip').val() == '' || jQuery('#fstate').val() == '' ||  jQuery('#fcity').val() == '') && jQuery('#fcityorzip').val() != '' ) {
jQuery.post("wrongziplength.php",{fzip:jQuery('#fzip').val(),fstate:jQuery('#fstate').val(),fcity:jQuery('#fcity').val(),fcityorzip:jQuery('#fcityorzip').val(),val:type});
						return false;
					}
				break;
				case 'to':
					if ((jQuery('#tzip').val() == '' || jQuery('#tstate').val() == '' || jQuery('#tcity').val() == '') && jQuery('#tcityorzip').val() != '') {
						return false;
					}
				break;

				case 'from2':
					if ((jQuery('#fzip2').val() == '' || jQuery('#fstate2').val() == '' ||  jQuery('#fcity2').val() == '') && jQuery('#fcityorzip2').val() != '' ) {
						return false;
					}
				break;
				case 'to2':
					if ((jQuery('#tzip2').val() == '' || jQuery('#tstate2').val() == '' || jQuery('#tcity2').val() == '') && jQuery('#tcityorzip2').val() != '') {
						return false;
					}
				break;

				case 'from3':
					if ((jQuery('#fzip3').val() == '' || jQuery('#fstate3').val() == '' ||  jQuery('#fcity3').val() == '') && jQuery('#fcityorzip3').val() != '' ) {
						return false;
					}
				break;
				case 'to3':
					if ((jQuery('#tzip3').val() == '' || jQuery('#tstate3').val() == '' || jQuery('#tcity3').val() == '') && jQuery('#tcityorzip3').val() != '') {
						return false;
					}
				break;
				
		}
		return true;
	}
	function checkZipLength (name) {
		_type = parseInt(jQuery('#'+name).val());
		if (!isNaN(_type)) {
			if (String(_type).length != 5 ) {
				jQuery('#'+name).css('border', '1px solid #ff0000');
				return true;
			}
		} 
		return false;
	}

	function setCityZipIfOne (name) {
		if (getCheckZipInf(name) == true) {
			  eval(jQuery('#state-from-popup-0 li a').attr('href'));
		} 
	}
	
	function getCheckZipInf(name) {
		if(jQuery('#state-from-popup-0 li').length == 1) {
			return true;
		} else {
			jQuery('#state-from-popup-0').show();
			return false;
		};
	}
	
	function countSelectedCityZip(name) {
		
		if(jQuery('#state-from-popup-0 li').length == 1) {
			if (name != undefined) {
				setCityZipIfOne (name);
			}
			return true;
		} else {
			jQuery('#state-from-popup-0').show();
			return false;
		};
	}

	/** 
	 *	waiting 1 second befor send ajax-request - to get states dropdown
	 */
	function fetchZipInfo (zip, type) {
		zip = escape(zip);
		type = escape(type);
		cleanTarget('','','',type);
		clearTimeout(xtime);
		xtime = setTimeout(
			"fetchZipInfoTime('"+zip+"', '"+type+"')"
		, 1000); 
	}

	
	
	/**
	 *	get states dropdown
	 */
	function fetchZipInfoTime(zip, type) 
	{
		//url = 'get_location.php'+"?qtype=" +type + "&"+"query="+zip;
		//alert(url);
		xss_ajax(url);
	}

	
	function validZip(zipField) {
		if (zipField.value){
			if (! IsNumeric(zipField.value) || zipField.value.length < 5){
				failedValidates++;
				setFailedValidateMessage();
				theZip = zipField.id;
				alert ('Zip Code must be a 5 digit number.\n' + failedValidateMessage);
				return false;
			}
			return true;
		}
	}
	function showVariants(data, type) {
		switch (type) {
			case 'from':
				if (data) {
					jQuery('#state-from-popup-0').remove();
					jQuery('#fcityorzip').after(
'<div id="state-from-popup-0" style="display:none" class="state-from-popup">' + data + '</div>');
					globArray['from'] = countSelectedCityZip('from');
					
				} else {
					jQuery('#state-from-popup-0').remove();
					jQuery('#fcityorzip').css('border', '1px solid #ff0000');
					globArray['from'] = false;
				}
				break;

			case 'to':
				if (data) {
					jQuery('#state-from-popup-0').remove();
					jQuery('#tcityorzip').after('<div id="state-from-popup-0" style="display:none" class="state-from-popup">' + data + '</div>');
					globArray['to'] = countSelectedCityZip('to');
				} else {
					jQuery('#state-from-popup-0').remove();
					globArray['to'] = false;
				}
				break;
			case 'from2':
				if (data) {
					jQuery('#state-from-popup-0').remove();
					jQuery('#fcityorzip2').after('<div id="state-from-popup-0" style="display:none" class="state-from-popup">' + data + '</div>');
					globArray['from2'] = countSelectedCityZip('from2');
				} else {
					jQuery('#state-from-popup-0').remove();
					globArray['from2'] = false;
				}
				break;

			case 'to2':
				if (data) {
					jQuery('#state-from-popup-0').remove();
					jQuery('#tcityorzip2').after('<div id="state-from-popup-0" style="display:none" class="state-from-popup">' + data + '</div>');
					globArray['to2'] = countSelectedCityZip('to2');
				} else {
					jQuery('#state-from-popup-0').remove();
					globArray['to2'] = false;
				}
				break;
			case 'from3':
				if (data) {
					jQuery('#state-from-popup-0').remove();
					jQuery('#fcityorzip3').after('<div id="state-from-popup-0" style="display:none" class="state-from-popup">' + data + '</div>');
					globArray['from3'] = countSelectedCityZip('from3');
				} else {
					jQuery('#state-from-popup-0').remove();
					globArray['from3'] = false;
				}
				break;

			case 'to3':
				if (data) {
					jQuery('#state-from-popup-0').remove();
					jQuery('#tcityorzip3').after('<div id="state-from-popup-0" style="display:none" class="state-from-popup">' + data + '</div>');
					globArray['to3'] = countSelectedCityZip('to3');
				} else {
					jQuery('#state-from-popup-0').remove();
					globArray['to3'] = false;
				}
				break;			
			default:
				break;
		}
	}

	function cleanTarget(city, state, zip, type) {
		switch (type) {
			case 'from':
				jQuery('#fstate').val(state);
				jQuery('#fcity').val(city);
				jQuery('#fzip').val(zip);
				break;
			case 'to':
				jQuery('#tstate').val(state);
				jQuery('#tcity').val(city);
				jQuery('#tzip').val(zip);
				break;
			case 'from2':
				jQuery('#fstate2').val(state);
				jQuery('#fcity2').val(city);
				jQuery('#fzip2').val(zip);
				break;
			case 'to2':
				jQuery('#tstate2').val(state);
				jQuery('#tcity2').val(city);
				jQuery('#tzip2').val(zip);
				break;
			case 'from3':
				jQuery('#fstate3').val(state);
				jQuery('#fcity3').val(city);
				jQuery('#fzip3').val(zip);
				break;
			case 'to3':
				jQuery('#tstate3').val(state);
				jQuery('#tcity3').val(city);
				jQuery('#tzip3').val(zip);
				break;
		}
	}

	function setCityZipFrom (fromname, city, state, zip, type, flag) {
	  jQuery('#fcityorzip').val(ucwords(city.toLowerCase()) +", " + ucwords(state.toUpperCase()) );
	  jQuery('#fcityorzip2').val(ucwords(city.toLowerCase()) + ", " + ucwords(state.toUpperCase()));
	  jQuery('#fcityorzip3').val(ucwords(city.toLowerCase())+", "+ucwords(state.toUpperCase()));
	  jQuery('#fstate').val(state);
	  jQuery('#fstate2').val(state);
	  jQuery('#fstate3').val(state);
	  jQuery('#fcity').val(city);
  	  jQuery('#fcity2').val(city);
	  jQuery('#fcity3').val(city);
	  jQuery('#fzip').val(zip);
	  jQuery('#fzip2').val(zip);
	  jQuery('#fzip3').val(zip);
	  jQuery(fromname).css('border', '1px solid #d2d2d2');
	  jQuery('#state-from-popup-0').remove();
	  return true;
	}

	function setCityZipTo (toname, city, state, zip, type, flag) {
	  jQuery('#tcityorzip').val(ucwords(city.toLowerCase())+ ", "+ucwords(state.toUpperCase()));
	  jQuery('#tcityorzip3').val(ucwords(city.toLowerCase()) + ", " + ucwords(state.toUpperCase()));
	  jQuery('#tstate').val(state);
	  jQuery('#tstate3').val(state);
	  jQuery('#tcity').val(city);
	  jQuery('#tcity3').val(city);
	  jQuery('#tzip').val(zip);
	  jQuery('#tzip3').val(zip);
	  jQuery(toname).css('border', '1px solid #d2d2d2');
	  jQuery('#state-from-popup-0').remove();
	  return true;
	}

	function setTarget(city, state, zip, type, flag) { //someone clicked on the City, State dropdown list
		if (flag == undefined ) { flag = true; }
		switch (type) {
			case 'from':
				fromname = '#fcityorzip';
				toname = '#tcityorzip';
				setCityZipFrom (fromname, city, state, zip, type, flag);
				jQuery('#tcityorzip').focus();
				break;
			case 'from2':
				fromname = '#fcityorzip2';
				toname = '#tcityorzip2';
				setCityZipFrom (fromname, city, state, zip, type, flag);
                jQuery('#ti_dcountry').focus();
				break;
			case 'from3':
				fromname = '#fcityorzip3';
				toname = '#tcityorzip3';
				setCityZipFrom (fromname, city, state, zip, type, flag);

                 jQuery('#tcityorzip3').focus();
				break;	

			case 'to':
				fromname = '#fcityorzip';
				toname = '#tcityorzip';
				setCityZipTo (toname, city, state, zip, type, flag);
				break;
			case 'to2':
				fromname = '#fcityorzip2';
				toname = '#tcityorzip2';
				setCityZipTo (toname, city, state, zip, type, flag);
				break;
			case 'to3':
				fromname = '#fcityorzip3';
				toname = '#tcityorzip3';
				setCityZipTo (toname, city, state, zip, type, flag);
				break;	
					
			
			default:
				alert(type + " was not caught");
				//alert("oops");
				//return true;
				break;
		}
     	saveFormInfo();
		
	}
