/**
 * INIT shadow
 *
 */

var ShadowState = Class.create();
ShadowState.prototype = {

    initialize: function(name, rewrite){
		this.rewrite = rewrite;
        this.form = $(name);
		this.action = '';
		this.stateId = '';
    },
	
	setState: function(id){
		$('sh-state').value = id;
	},
	
	setCartUrl: function(url){
		$('sh-cartUrl').value = url;
	},
	
	submit: function(action){
		if (this.rewrite) {
			if (action == null) {
				action = $('sh-cartUrl').value;
			}
			this.form.action = action;
		}
		this.form.submit();
	}
}

var StateCheck = Class.create();
StateCheck.prototype = {

    initialize: function(id, isPrescriptionRequired, allowedStateId){
		this.isPrescriptionRequired = isPrescriptionRequired;
		this.allowedStateId = allowedStateId;
		this.id = id;
    },
	
	setRegionId:function(regionId) {
		$(this.id).value = regionId;
	},

	check:function() {
		var regionId = $(this.id).value;
		
		if (this.isPrescriptionRequired) {
			var allowedRegionId = eval(this.allowedStateId);
			var flag = true;

			for (var i=0;i<this.allowedStateId.length;i++){
				if (this.allowedStateId[i] == regionId) {
					flag = false;
				}
			}
			if (flag) {
				return confirm("We dont have pharmacy license for your state yet. Click at OK button will remove your prescription required items from your cart.");
			}
		}		 
		return true;
	}
	
}