/**
 * INIT shadow
 *
 */

var ShadowState = Class.create();
ShadowState.prototype = {

    initialize: function(name){
        this.form = $(name);
    },
	
	setRegionId: function(shadow_regionId){
		$('shadow_regionId').value = shadow_regionId;
	},
		
	submit: function(action){	
		Form.getInputs('product_addtocart_form','radio','aw_sarp_subscription_type').each(function(radio) {
			radio.checked = false;
		});
			
		if (!isNaN($('qty').value)){
			this.form.submit();			
		}
		else {
			alert('Invalid Quantity');
		}
	}
}

var ShadowSubscriptionState = Class.create();
ShadowSubscriptionState.prototype = {

    initialize: function(name){
        this.form = $(name);
    },
	
	setRegionId: function(shadow_regionId){
		$('shadow_regionId').value = shadow_regionId;
	},
	
	submit: function(action){
		$('qty').value = $('qtySubscribe').value;
		if (this.rewrite) {
			if (action == null) {
				action = $('sh-cartUrl').value;
			}
			this.form.action = action;
		}
		
		if (!isNaN($('qty').value)){
			this.form.submit();			
		}
		else {
			alert('Invalid Quantity');
		}
	}
}

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;
	}
	
}
