
function flyoutMenu(i)  {

	var offset = $("#flyout > li:nth-child(1)").offset();
	alert('left: ' + offset.left + ' top: ' + offset.top);	
}

function popUp(url,w,h)  {

	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var param = "toolbar=0,location=0,top=" + wint +",left=" +winl+ ",directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=" + w + ",height=" + h;
	//var param = "toolbar=1,location=1,top=" + wint +",left=" +winl+ ",directories=0,status=1,menubar=1,scrollbars=1,resizable=0,width=" + w + ",height=" + h;
    floater = window.open(url, "PopUp", param);
    floater.focus();
}

function toggle_feature(divid)  {

	// allow document.all, for older browsers
	var div = (document.getElementById) ? document.getElementById(divid) : 
			((document.all) ? document.all(divid) : null);
	div.className = (div.className == "open") ? "closed" : "open";
}

function round(number,X) {
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function setRegionCodes()  {

	var country = $('#CountryCode option:selected').val();
	if (country == 'US')  {
		$('#state_label').html("US State");
		$('#state_field_us').css("display","inline");
		$('#state_field_non').css("display", "none");
		$('#zip_label').html("US Zip Code");
        $('#state_row').removeClass("highlight");
        $('#zip_row').removeClass("highlight");

	}  else  {
		$('#state_label').html("Region/Province");
		$('#state_field_us').css("display","none");
		$('#state_field_non').css("display", "inline");
		$('#zip_label').html("Postal Code");
        $('#state_row').addClass("highlight");
        $('#zip_row').addClass("highlight");
	}
}

function confirmDeleteAddress()  {

	ask_user  = confirm("Are you sure you would like to delete this address?")
	if (ask_user == true)  return true;

	return false;

}

function updateConfigurator(cino)  {

	var selectid = 'cino_' + cino;
	var component_price_id = 'price_' + cino;

	var configprice = $('#configprice').val();

}

function configurator_update(cfgid,cino)  {

	// ajax call to update configuration in the db
	var qty_id = '#' + cino + '_qty';
	var pid_id = '#' + cino + '_pid';
	var qty = $(qty_id).val();
	var pid = $(pid_id).val();

	$.post("/ajax_gw.php", {configid: cfgid, configitemno: cino, qty: qty,
						    pid: pid,action: 'configurator_update'}, function(data)  {

		// parse error messages (configitemno, txt)
		var error_id;
		var error_msg;

		// clear errors
		$('.configerror').html('');

		for (x in data)  {
		
			error_id = '#error_' + x;
			error_msg = data[x];
			$(error_id).html(error_msg); 
			$(error_id).show('slow');
			//$('#error_40').html('showing data: ' + error_id + ' ' + error_msg);
			//$('#error_40').show('slow');

		}
	
	},"json");

	var high_id = '#' + cino;
	$(high_id).animate({backgroundColor: "gold" },250);
	$(high_id).animate({backgroundColor: "white" },750);

}

function configurator_updatename(cfgid)  {

	var name = $('#configname').val();
	var note = $('#confignote').val();

	$.post("/ajax_gw.php", {configid: cfgid, configname: name, confignote: note, action: 'configurator_updatename'});

	$('#configurator_status').html("Updated configuration name and notes.");
	$('#configurator_status').show('slow');
	$('#configurator_status').hide('slow');
}

function configurator_add_to_cart(cfgid)  {

	$.post("/ajax_gw.php", {configid: cfgid, action: 'configurator_add_to_cart'}, function(data) {

		$('#configurator_status').html(data);
		$('#configurator_status').show('slow');

	});

}

function promo_add_to_cart(cfgid)  {

	$.post("/ajax_gw.php", {configid: cfgid, action: 'configurator_add_to_cart'}, function(data) {

		$('#promo_status').html(data);
		$('#promo_status').show('slow');

	});

}
function sales_help_returning()  {

	var email = $('#email_addy').val();

	$.post("/ajax_gw.php", {email: email, action: 'sales_help_check_email'}, function(data)  {

		// found customer. hide new form.
		if (data >= 1)  {
			$('#f_email').val(email);
			$('#returning_customer_block').hide('slow');
			$('#new_customer_block').hide();
			$('#returning_customer_block2').show('slow');

		// did not find customer.
		}  else  {

			$('#email').val(email);
			$('#returning_customer_block').html('<span style="color: orange;">The email address you entered was not recognized. Please complete the following form to submit your quote request or question.</span>');
		}

	});

}

function check_imf_form()  {


	var fname = $('#fname').val();
	var lname = $('#lname').val();
	var email = $('#email').val();
    var phone = $('#phone').val();
	var street = $('#address').val();
	var city = $('#city').val();
	var zip = $('#zip').val();

	var country = $('#country').val();
	if ((country != 'US') || (country != 'CA'))
		country = '';

	if (country == 'US')  {
		var state = $('#state option:selected').val();
	}  else  {
		var state = $('#province').val();
	}

	if ((!fname.length) || (!lname.length) || (!email.length) || (!phone.length)
        (!street.length) || (!city.length) || (!zip.length) || (!email.length))  {

		$('#imf_form_errors').show();
		$('#imf_form_errors').html("Please complete all required fields.");

		return false;
	}
	alert(email.length);
	return true;


}

function update_state()  {

    $('#state_us_options').hide();
    $('#state_ca_options').hide();
    $('#state_uk_options').hide();
    $('#state_province').hide();

    if ($('#country_select').val() == 'US')  {
        $('#state_us_options').show();
    }  else if ($('#country_select').val() == 'CA')  {
        $('#state_ca_options').show();
    }  else if ($('#country_select').val() == 'GB')  {
        $('#state_uk_options').show();
    }  else  {
        $('#state_province').show();
    }
}

function support_portal_login()  {

	var email = $('#sp_email').val();
	var pw    = $('#sp_pw').val();

	var url = 'https://na3.salesforce.com/secur/login_portal.jsp?orgId=00D300000000y1I&portalId=06050000000D4C9&action=loginAction'
			+ '&un=' + email
			+ '&pw=' + pw;
	popUp(url,1250,800);

}


function redraw_raid_summary()  {

	var cfgid = $('#cfgid').val();
	$.post("/ajax_gw.php", { action: 'get_raid_summary', cfgid: cfgid},
                    function(data) {
                        $("#raid_summary").html(data);

                    }
	);
}

function redraw_partition_summary()  {

	var cfgid = $('#cfgid').val();
	$.post("/ajax_gw.php", { action: 'get_partition_summary', cfgid: cfgid},
                    function(data) {
                        $("#partition_summary").html(data);

                    }
	);
}
function delete_raid_vol(cfgid,rdvol)  {

	$.post("/ajax_gw.php", { action: 'delete_raid_volume', cfgid: cfgid, rdvol: rdvol},
                    function(data) {
                        $("#raid_summary").html(data);

                    }
	);

}

function validate_form(captid) {

	var user_capt = $('#security_code').val();
	if (user_capt == captid)  {
		return true;
	}  else  {

		alert("Oops! Your entry of " + user_capt + " does not match! (" + captid + ")");
		return false;		
	}
}
