    js = new Object;
    js.loadedModules = new Array;
    js.include = function(path) {
        if(js.loadedModules[path]) return;
        js.loadedModules[path] = true;
        $.ajax({
        	url: path,
        	dataType: "script",
        	async: false,
        	success: function(js){if(jQuery.browser.safari){eval(js);}}
        });
    }
    
    js.include('-fjs/menu.js');
    
    $(document).ready(function(){                           

        $("#mailForm_1").submit(function(){
            var cust_name = $("#cust_name_1").val();
            var one = $("#one_1").val();
            var two = $("#two_1").val();
            var three = $("#three_1").val();
            var cust_email = $("#cust_email_1").val();
            var origin_zip = $("#origin_zip_1").val();
            var destination_zip = $("#destination_zip_1").val();
            if( cust_name.length < 3 )
            {
                alert( "The Full Name field must be at least 6 characters in length" );
                return false;
            }
            if( one.length != 3 && two.length != 3 && three.length != 4 )
            {
                alert( "The Phone field must contain a valid phone number" );
                return false;                                
            }
            
            var reg = new RegExp("[0-9a-z_]+@[\-0-9a-z_^.]+\\.[a-z]{2,3}", 'i');
            if ( !reg.test(cust_email) ) 
            {
                alert("The E-mail field must contain a valid email address");
                return false;
            }    
            if( origin_zip.length != 5 )
            {
                alert( "Please fill in Origin Zip Code" );
                $("#origin_zip_1").val('').focus();
                return false;
            } 
            if( destination_zip.length != 5 )
            {
                alert( "Please fill in Destination Zip Code" );
                $("#destination_zip_1").val('').focus();
                return false;
            }                                   
            return true;
        });        
        
        
        $(".detailsButton").hover(function(e){
            //$(".detailsDiv").css("left", e.pageX - 150);
            //$(".detailsDiv").css("top", e.pageY + 15);             
            $(".detailsDiv").css("display", "block");
        },function(e){
            setTimeout(function(){$(".detailsDiv").css("display", "none")}, 500);                              
        });        
        
        
        // prices.htm#localMoving Проверяем поля формы и сабмитим на дальнейший заказ
        $("#reserveButton").click(function(){
            var zo = $("#zo").val();
            var zd = $("#zd").val();
            var respZo = checkZip(zo);
            var respZd = checkZip(zd);
            if( respZo.status == "OK" && respZd.status == "OK" )
            {
                $("#localMovingForm").submit();
            }
            else
            {
                if( respZo.status == "error" )
                {
                    alert( "Start Location " + respZo.message );
                }
                if( respZd.status == "error" )
                {
                    alert( "Destination Location " + respZd.message );
                }            
            }        
        });
        
        $("#reserveButton2").click(function(){
            var zo = $("#zo2").val();
            var zd = $("#zd2").val();
            var respZo = checkZip(zo);
            var respZd = checkZip(zd);
            if( respZo.status == "OK" && respZd.status == "OK" )
            {
                $("#localMovingForm2").submit();
            }
            else
            {
                if( respZo.status == "error" )
                {
                    alert( "Start Location " + respZo.message );
                }
                if( respZd.status == "error" )
                {
                    alert( "Destination Location " + respZd.message );
                }            
            }        
        });        

        
        $("#mailForm").submit(function(){
            var cust_name = $("#cust_name").val();
            var one = $("#one").val();
            var two = $("#two").val();
            var three = $("#three").val();
            var cust_email = $("#cust_email").val();
            var origin_zip = $("#origin_zip").val();
            if( cust_name.length < 3 )
            {
                alert( "The Full Name field must be at least 6 characters in length" );
                return false;
            }
            if( one.length != 3 && two.length != 3 && three.length != 4 )
            {
                alert( "The Phone field must contain a valid phone number" );
                return false;                                
            }
            
            var reg = new RegExp("[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]{2,3}", 'i');
            if ( !reg.test(cust_email) ) 
            {
                alert("The E-mail field must contain a valid email address");
                return false;
            }    
            if( origin_zip.length != 5 )
            {
                alert( "Please fill in Origin Zip Code" );
                $("#origin_zip").val('').focus();
                return false;
            }                        
            return true;
        });
        
        
        
        // prices.htm#localMoving Кнопка подсчета цены за переезд
        $("#localMovingPrice").click(function(){
            var data = new Object();
            data.zo = $("#zo").val();
            data.zd = $("#zd").val();
            data.containers = $("#containers").val();
            
            
            var respZo = checkZip(data.zo);
            var respZd = checkZip(data.zd);
            

            if( respZo.status != "error" || respZd.status != "error" )
            {                         
                $("#lmzo, #lmzd").empty();

                if( respZo.status == "extended" )
                {
                    $("#lmzo").html('<a class="details" onclick="showTip(\'extended_area_alt\', this)">Extended Area Delivery</a>');
                }
                
                if( respZd.status == "extended" )
                {
                    $("#lmzd").html('<a class="details" onclick="showTip(\'extended_area_alt\', this)">Extended Area Delivery</a>');
                }                

                $.ajax({
                    type: "POST",
                    url: "http://"+location.host+"/prices/local_moving_price.htm", 
                    data: data,
                    success: function(json)
                    {
          		        var response = eval('(' + json + ')');
          		        if( response.status == "OK" )
                        {
                            $("#localMovingPriceTotal").html("$"+response.tp);
                            var zoZipcode = response.zo.zipcode;
                            var zoCity = response.zo.city;
                            var zdZipcode = response.zd.zipcode;
                            var zdCity = response.zd.city; 
                            $("#zoInfo").html('<div>'+zoZipcode+'</div><div>'+zoCity+'</div>');
                            $("#zdInfo").html('<div>'+zdZipcode+'</div><div>'+zdCity+'</div>');                          
                        }
                        else
                        {
                            alert(response.message);	                    
                        }
                    }    
                });                
            }
            else
            {
                if( respZo.status == "error" )
                {
                    alert( "Start Location " + respZo.message );
                }
                if( respZd.status == "error" )
                {
                    alert( "Destination Location " + respZd.message );
                }            
            }                             
        });
        
        $("#localMovingPrice2").click(function(){
            var data = new Object();
            data.zo = $("#zo2").val();
            data.zd = $("#zd2").val();
            data.zd_days = $("#zd_days").val();
            data.zo_days = $("#zo_days").val();
            data.containers = $("#containers2").val();
            
            
            var respZo = checkZip(data.zo);
            var respZd = checkZip(data.zd);
            
            if( respZo.status != "error" || respZd.status != "error" )
            { 
                $("#lmnszo, #lmnszd").empty();
                if( respZo.status == "extended" )
                {
                    $("#lmnszo").html('<a class="details" onclick="showTip(\'extended_area_alt\', this)">Extended Area Delivery</a>');
                }
                
                if( respZd.status == "extended" )
                {
                    $("#lmnszd").html('<a class="details" onclick="showTip(\'extended_area_alt\', this)">Extended Area Delivery</a>');
                }                 
                
                $.ajax({
                    type: "POST",
                    url: siteUrl+"/prices/local_moving_price_day.htm", 
                    data: data,
                    success: function(json)
                    {
          		        var response = eval('(' + json + ')');
          		        if( response.status == "OK" )
                        {
                            if( respZo.status == "extended" || respZd.status == "extended" )
                            {
                                $("#localMovingPriceTotalWs").html("<small>Service Not Available</small>");  
                                $("#day_charge").css("visibility", "hidden");
                            }
                            else
                            {
                                $("#localMovingPriceTotalWs").html("$"+response.tp);
                                $("#day_charge").css("visibility", "visible");
                            }
                            
                            var zoZipcode = response.zo.zipcode;
                            var zoCity = response.zo.city;
                            var zdZipcode = response.zd.zipcode;
                            var zdCity = response.zd.city; 
                            $("#zoInfoWs").html('<div>'+zoZipcode+'</div><div>'+zoCity+'</div>');
                            $("#zdInfoWs").html('<div>'+zdZipcode+'</div><div>'+zdCity+'</div>');                          
                        }
                        else
                        {
                            alert(response.message);	                    
                        }
                    }    
                });                
            }
            else
            {
                if( respZo.status == "error" )
                {
                    alert( "Start Location " + respZo.message );
                }
                if( respZd.status == "error" )
                {
                    alert( "Destination Location " + respZd.message );
                }            
            }                             
        });        
        

        // prices.htm#storageQuote кнопка "другой зип"
        $("#anotherZipSubmit").click(function(){
             anotherZip();              
        });


        $("#anotherZip").keyup(function(e){      
             if( $("#anotherZip").val().length == 5 && e.keyCode == 13 )
             {                
                anotherZip(); 
             }                            
        });        
        
        

     
        $("#zipButton, #topFormButton").bind('click', function(){
            checkZipExtended();
        });
        
        $("#zipForm, #topForm").bind('keyup', function(e){
            if( e.keyCode == 13 )
            {
                checkZipExtended();
            }
            return false;
        });

        
        
        $("#readFull").click(function(){
            $("#thirdParagraph").slideToggle("slow", function(){
                if( $("#readFull").attr("src") == "-fimages/readFull.gif" )
                {
                    $("#readFull").attr("src", "-fimages/articleUp.gif");     
                }
                else
                {
                    $("#readFull").attr("src", "-fimages/readFull.gif");  
                }
            });
                         
        });                       

        
        $("#zip").focus( function(){
            $(this).val('');        
        });         
    });
    
    
    
    
jQuery.extend({
	/*
	 * included scripts
	 */
	includedScripts: {},

	/*
	 * include timer
	 */
	includeTimer: null,

	/*
	 * include
	 */
	include: function (url, onload) {
		if (jQuery.includedScripts[url] != undefined) {
			return;
		}

		jQuery.isReady = false;

		if (jQuery.readyList == null) {
			jQuery.readyList = [];
		}

		var script = document.createElement('script');

		script.type = 'text/javascript';
		script.onload = function () {
			jQuery.includedScripts[url] = true;

			if (typeof onload == 'function') {
				onload.apply(jQuery(script), arguments);
			}
		};
		script.onreadystatechange = function () {
			if (script.readyState == 'complete') {
				jQuery.includedScripts[url] = true;

				if (typeof onload == 'function') {
					onload.apply(jQuery(script), arguments);
				}
			}
		};
		script.src = url;

		jQuery.includedScripts[url] = false;
		document.getElementsByTagName('head')[0].appendChild(script);

		if (!jQuery.includeTimer) {
			jQuery.includeTimer = window.setInterval(function () {
				jQuery.ready();
			}, 10);
		}
	}
});

/*
 * replacement of jQuery.ready
 */
jQuery.extend({
	/*
	 * hijack jQuery.ready
	 */
	_ready: jQuery.ready,

	/*
	 * jQuery.ready replacement
	 */
	ready: function () {
		isReady = true;

		for (var script in jQuery.includedScripts) {
			if (jQuery.includedScripts[script] == false) {
				isReady = false;
				break;
			}
		}

		if (isReady) {
			window.clearInterval(jQuery.includeTimer);
			jQuery._ready.apply(jQuery, arguments);
		}
	}
}); 
    
    
    
        function checkZipExtended()
        {
            var zip = '';
            var form = '#zipForm';
            if( $('#resZipVal').length > 0 && $('#resZipVal').val() != '' && $('#resZipVal').val() != 'Zip Code' )
            {
                zip = $('#resZipVal').val();
                form = '#topForm';
            }
            else if( $("#zip").length > 0 && $("#zip").val() != '' )
            {
                zip = $("#zip").val();
            }
            else if( $('#resZip').length > 0 && $('#resZip').val() != '' && $('#resZip').val() != 'Zip Code' )
            {
                zip = $('#resZip').val();
            }
    

            if( zip == '' || zip == 'Enter Zip' || zip == null )
            {
                alert( 'Enter Zip!' );
                $("#zip").focus();
            } 
            else 
            {
                $.fancybox.showActivity();
                $.ajax({
                    acync   : false,
                    type    : "POST",
                    url     : '/zip.htm', 
                    data    : "ip="+ip+"&referer="+referer+"&http_user_agent="+http_user_agent+"&zip="+zip,
                    success : function(msg)
                    {
                        if( msg.length > 0 )
                        {
                            var json = eval('('+msg+')');
                            if( typeof json == 'object' && json.status == 'extended' )
                            {
                                $.fancybox(json.message);
                                $.fancybox.hideActivity();
                                return false;
                            } 
                            else if ( json.status == 'error' )
                            {
                                alert(json.message);
                                return false;
                            }                       
                        }
                        $(form).submit();  
                    }    
                }); 
                $.fancybox.hideActivity();                
            }
            return false;                     
        }    
    
    
    
    
    // динамическая загрузка css
    function load_css(css){
        var st = document.createElement("link");
        st.setAttribute("rel","stylesheet");
        st.setAttribute("href", css);
        st.setAttribute("type", "text/css");
        document.getElementsByTagName("head")[0].appendChild(st)    
    }

    // показываем всплывающую подсказку
    function showTip(id, obj){                         	
		var marginHeight = 25;
		var marginWidth = 0;
		$.ajax({
            type: "POST",
            url: tipUrl, 
            data: "id="+id,
            success: function(msg)
            {
                if( $("#tip_outer").html() != null ) $("#tip_outer").remove();
				var html = '<div id="tip_outer"><div id="tip_inner"><div id="tip_close" class="close" style="display:block"></div><div id="tip_content">'+msg+'</div></div></div>';
				$(html).appendTo("body");
	
				var linkTop = $(obj).offset().top;
                var linkLeft = $(obj).offset().left;
				var tip = $("#tip_outer");
				var tipWidth = tip.width();
				var tipHeight = tip.height();		
				var clientWidth = $(window).width();
				var clientHeight = $(window).height();
				var scrollTop = $(window).scrollTop();
				var scrollLeft = $(document).scrollLeft();				
				
				tip.fadeIn("slow");

				var top = linkTop + marginHeight;
				if( top + tipHeight >= ( clientHeight + scrollTop ) ){
					top = linkTop - tipHeight - marginHeight/2;
				}
				
				var left = linkLeft + marginWidth;
				if( left + tipWidth >= ( clientWidth + scrollLeft ) ){
					left = clientWidth + scrollLeft - tipWidth - 30;
				}				
				
				tip.css({"top":top, "left":left});
				
                $(".close").each(function(){            
                    $(this).click(function(){
                        $(this).parent().parent().fadeOut("slow", function(){$(this).remove()});
                    });           
                });
            }    
        });	
	}	
    
	
	function getClientWidth()
	{
  			return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
	}

    function getElementPosition(elem)
	{
	    //var elem = document.getElementById(elemId);
		
	    var w = elem.offsetWidth;
	    var h = elem.offsetHeight;
		
	    var l = 0;
	    var t = 0;
		
	    while (elem)
	    {
	        l += elem.offsetLeft;
	        t += elem.offsetTop;
	        elem = elem.offsetParent;
	    }
	
	    return {"left":l, "top":t, "width": w, "height":h};
	}


    
	function submitEmailForm()
	{
		var final="";
			
		if (document.emailForm.firstname.value.length < 2)
        {        
            final = "\n * First name should containt at least 2 characters";
        }
		if (document.emailForm.lastname.value.length < 2)
        { 
            final += "\n * Last name should containt at least 2 characters";
		}
		if (document.emailForm.email.value == '')
        { 
            final += "\n * Email is empty";
        }
        else
        {
            var reg = new RegExp("[0-9a-z_]+@[\-0-9a-z_^.]+\\.[a-z]{2,3}", 'i');
            if ( !reg.test(document.emailForm.email.value) ) 
            {
                final += "\n * Email is invalid";
            }    
        } 
        if (document.emailForm.email1.value == '')
        { 
            final += "\n * Re-enter Email is empty";
        }
        else
        {
            var reg = new RegExp("[0-9a-z_]+@[\-0-9a-z_^.]+\\.[a-z]{2,3}", 'i');
            if ( !reg.test(document.emailForm.email1.value) ) 
            {               
                final += "\n * Re-enter Email is invalid";
            }    
        } 
        if( document.emailForm.email.value != document.emailForm.email1.value )  
        {
            final += "\n * Emails are not equal";
        }     
		if (final.length <1 )
        {
            return true;
        } 
		else
        {
			alert(" Please check possible errors: " +final);
			return false;
		}
	}

    
    var month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];    

    function showAjaxContent(url){
        $.fancybox.showActivity();
        var url = "http://"+location.host+"/"+url;
        $.ajax({
    		type	: "POST",
            cache	: false,
    		url		: url,
    		success : function(data) {
    			$.fancybox(data);
    		}
    	});
    
    	return false;
    }     
      

    function showSpecial(obj, s_check, del_type){
        var end_date = new Date(parseInt(obj.end_date)*1000);
        var html = '';
        
        if( del_type == 1 )
        {
            html += '<div id="resTopBlockRightRow1">Extended Area</div>';
            html += '<div id="resTopBlockRightRow2">Delivery</div>';
            html += '<div id="resTopBlockRightRow3">Custom Delivery Fee Special</div>';
        }
        else
        {
            html += '<div id="resTopBlockRightRow1">'+obj.special_title_1+'</div>';
            html += '<div id="resTopBlockRightRow2">'+obj.special_title_2+'</div>';
            html += '<div id="resTopBlockRightRow3">'+obj.sub_title+'</div>';
        }
        
        if( del_type == 1 )
        {   
            html += '<div id="resTopBlockRightRow4"><a onclick="showTip(\'extended_area\', this)">Learn more...</a></div>';
        }
        else
        {
            html += '<div id="resTopBlockRightRow4"><a onclick="showTip(\'specials_id#'+obj.specials_id+'\', this)">Learn more...</a></div>';
        }

        html += '<div id="resTopBlockRightRowSeparator"></div>';

        if( s_check == 1 )
        {
            html += '<div id="resPackageDealSavings"><a onclick="showAjaxContent(\'prices/see_package_deal_savings.htm\')">See package deal savings</a></div>';
        }
        
        html += '<div id="resTopBlockRightRow6"><form onsubmit="return checkQuoteForm(this)" action="'+siteUrl+'/reservation.htm" method="post"><input type="submit" class="reserve" value=""><input type="hidden" name="student" value="1"><input type="hidden" name="offer" value="1"><input type="hidden" name="zipcode1" value="'+obj.zipcode1+'" class="zipcode1"><input type="hidden" value="Reserve Now"></form></div>';
        $("#resTopBlockRight").html(html);
        
        var html = '';
        if( del_type == 1 )
        { 
            html += '<div>Extended Area</div>';
            html += '<div>Delivery</div>'; 
            
            $(".specialBoxTip").html('<a class="details" onclick="showTip(\'extended_area\', this)">details...</a>');   
            
            $("#ttip").html('<a onclick="showTip(\'extended_area_alt\', this)" class="details">details...</a>');   
            
        }
        else
        {
            html += '<div>'+obj.special_title_1+'</div>';
            html += '<div>'+obj.special_title_2+'</div>'; 
            
            $(".specialBoxTip").html('<a class="details" onclick="showTip(\'specials_id#'+obj.specials_id+'\', this)">details...</a>');  
            
            $("#ttip").html('<a onclick="showTip(\'base_delivery\', this)" class="details">details...</a>');         
        }
        
        if( s_check == 1 ) 
        {
            $("#seePackageDealSavingsBox").html('<a class="see_package_deal_savings" onclick="showAjaxContent(\'prices/see_package_deal_savings.htm\')">See package deal savings</a>');
            $(".specialBoxTip").html('');
        } 
        else 
        {
            $("#seePackageDealSavingsBox").html('');
        }
        $("#specialBox").html(html);
        
        
        $("#specialBoxZip").val(obj.zipcode1);
    }



    function openWindow(url,w,h) {
        e=window.open(url,'_blank', 'resizable=yes,width='+w +', height=' +h +',scrollbars=yes,toolbar=no,menubar=no,status=yes,location=no');
    }     
    
    // переводим страницу вверх
    function onTop(){
        window.scrollTo(0,0);
    }
    
    function popupWindow(url) {
        window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=600,height=800,screenX=150,screenY=150,top=150,left=150')
    }
    
    function OnLoad() {
        new CSEOverlay("005152992814805417409:fdfktbppxmg",
                 document.getElementById("searchbox_005152992814805417409:fdfktbppxmg"),
                 document.getElementById("results_005152992814805417409:fdfktbppxmg"));
    }
    
    // проверяем зип. Возвращает объект JSON
    function checkZip(zip)
    {    
        var response = $.ajax({
              url: siteUrl+"/prices/do_zip.htm", 
              type: "POST",
              data: "zip="+zip,
              async: false
           }
        ).responseText; 
        var json = eval('(' + response + ')');
        return json;            
    }    
    
    // prices.htm#storageQuote Если клиент не ввел зип, просим ввести
    function checkQuoteForm(form)
    {        
        var zipVal = form.zipcode1.value;
        if( zipVal == 0 )
        {
            alert( "Please enter Zip Code" );
            $("#anotherZip").focus().css("border", "1px solid red");
            return false;
        }
        else
        {
            return true;
        }        
    }
    
    
    function anotherZip(form)
    {         
            $("#anotherZip").css("border", "1px solid #AAAAAA");
            var zip = $("#anotherZip").val();            
            var respZip = checkZip(zip);
            if( respZip.status == "error" )
            {
                alert( respZip.message );
                $("#anotherZip").val('').focus();
            }
            else
            {
                if( respZip.status == 'extended' )
                {
                    if( confirm('We are sorry, but your zip code '+zip+' appears to be outside of our standard coverage area. We can provide you with a custom quote for the delivery to this zip code. Click "OK" if you would like to see the delivery fee or "Cancel" if you made an error entering your zip code.') == false )
                    {
                        return false;
                    }
                } 
                
                var deliverySumm = respZip.delivery_fee;
                
                if( respZip.zip.del_type == 1 )
                {
                    $("#FeeName").html('Custom');
                }
                else
                {
                    $("#FeeName").html('Regular');
                }

                
                if( deliverySumm == 0 )
                {
                    deliverySumm = "FREE";
                }
                else
                {
                    deliverySumm = "$"+deliverySumm;
                }
              
                $("#zd2, #zd, #zo, #zo2, .anotherZipYellow, #origin_zip_1, #origin_zip, #destination_zip_1").val(zip);

                showSpecial(respZip.special, respZip.zip.s_check, respZip.zip.del_type);

                $("#zipInfoArea").html(respZip.zip.city);
                $("#zipInfoZip").html(respZip.zip.zipcode);
                $("#RegularDeliveryFee").html(deliverySumm);               
                $(".zipcode1").each(function(){
                    $(this).val(respZip.zip.zipcode);
                });
            }     
    }    
    
    
    
    
