// JavaScript Document

function getFreightEstimateSetup() {	
if (jQuery('div#ajaxIndicator').length==0) {
	// create indicator 	
	var oIndicator= new Image();
	oIndicator.src="sophio-shared-assets/js/jquery/ajax-loader.gif";
	jQuery('<div id="ajaxIndicator" style="border:2px solid #000;padding:8px; display:none;"></div>')
	.append(jQuery('<span id="ajaxIndicatorText"></span>'))
	.append(jQuery('<span id="ajaxIndicatorImage" style="margin-left:10px;"></span>').append(oIndicator))
	.appendTo('body');
	//
}									
	// setup blockUI our overlayer
	jQuery.blockUI.defaults = {		
	css: {	
        padding:        0, 
        margin:         0, 
        width:          'auto',  
        top:            '40%',  
        left:           '35%',  
        textAlign:      'left',  
        color:          '#000',  
        border:         '0px', 
        backgroundColor:'#fff', 
        cursor:         'wait' 
    } ,
	 overlayCSS:  {  
        backgroundColor:'#000',  
        opacity:        '0.5'  
    }, 
	 baseZ: 1000, 
	message:jQuery('div#ajaxIndicator')
	}
	
	jQuery().ajaxStop(jQuery.unblockUI); 
	// jQuery().ajaxStart( jQuery.blockUI({ message:  }));
}

function getFreightEstimateShoppingCart() {
	getFreightEstimateSetup();
	jQuery("#btnFreightQuote").click(function(){
		if (jQuery('#divGetFreightEstimate').length==0) {
			jQuery('#ajaxIndicatorText').html("Hang On! Getting freight quote form from server!");
			jQuery.blockUI();
			//jQuery.get("getFreightEstimate.wws",{mode:'CHECK',isAjax:'true'},function(data) {
			jQuery('#getFreightEstimateForm').load("getFreightEstimate.wws?mode=CHECK&isAjax=true",{},function(){
				jQuery('#getfreightresetbtn').attr("value","Hide").click( function() { 
					jQuery('#divGetFreightEstimate').slideUp("slow");
					jQuery('#ship_zip').focus();
					return false;
				});
			});
			//});
		} else {
			jQuery('#divGetFreightEstimate').show();
		}
		return false;
	});
}

function getFreightEstimateForm() {
	getFreightEstimateSetup();
	 if (isIntlStore==="N") {	 
		jQuery("#st_CtryID").removeOption(eval('/[^'+storeCntry+']/i')).selectOptions(storeCntry,true);  
	 } else {
		 jQuery("#st_CtryID").selectOptions(storeCntry,true);
	 }
	 
	 jQuery('#frmGetFreight').ajaxForm({ 
        target:		'#getFreightEstimateValues',
		type:		'post',
		url:		'GetFreightEstimate.wws?mode=check&isAjax=true',
		success: function() {jQuery('#getFreightEstimateValues').show();},
		beforeSubmit : function() {
			if (jQuery('#ship_zip').val()=="") { window.alert("Please enter a zip/postal code first!"); jQuery('#ship_zip').focus(); return false;}
			jQuery('#ajaxIndicatorText').html("Hang On! Getting freight from server.");
			jQuery('#getFreightEstimateValues').hide();
			jQuery.blockUI();
			}
		}); 
}