function special_update(e) {
	var id, qty;
	var el;
	var special_offer_string = '';

	if (window.event && window.event.srcElement) el = window.event.srcElement;
	if (e && e.target) el = e.target;
	if (!el) return;

	id = parseInt(el.getAttribute('id').split('-')[1]);
	// qty = parseInt(el.value);
	qty = el.checked ? 1 : 0;
	special_offers[id] = qty;
	for (var i in special_offers)
		if (special_offers[i] > 0) special_offer_string += i + ':' + special_offers[i] + ';';
	special_offer_string = special_offer_string.substring(0, special_offer_string.length - 1);

	var pricebox = document.getElementById('pricebox');
	var inputs = pricebox.getElementsByTagName('input');
	for (var i=0; i<inputs.length; i++) {
		if (inputs[i].getAttribute('id') == 'specials')
			inputs[i].value = special_offer_string;
	}
}

function addListeners(e) {
	sp = document.getElementById('specialoffer');
	if (sp) {
		selects = sp.getElementsByTagName('input');
		for (var i=0; i<selects.length; i++) {
			addEvent(selects[i], 'change', special_update, false);
		}
	}
}

number_of_special_offers = 0;
addEvent(window, 'load', addListeners, false);
special_offers = new Object;

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture); 
		return true; 
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn); 
		return r; 
	} else {
		elm['on' + evType] = fn;
	}
}

function specials_check(theForm) {
	specials = document.getElementById('specials').value;
	
	//  special offer for subscription pack -  start --Addded
//start	
	var test = document.getElementById('special').value; //Get Name of all check box
		//alert(test);
		var split_check = test.split("*");
		//alert(split_check.length);
		for(k=0;k<split_check.length-1;k++)
		{
			product = split_check[k];
			var select_special = document.getElementById(product).checked;			
			if(select_special==true){ var submitform = true;}
			//alert(select_special);
		}

		
	//alert(submitform);
		if(submitform==true)
		{
			//alert("iasf");
			if(theForm.subscription!= null)
				{
					var subscription = theForm.subscription.value;
					//alert(subscription);
					document.getElementById('subscription_id1').value = subscription;
				}
					//  special offer for subscription pack -  End
					variation = theForm.variation.value;
					//alert(variation);
					document.getElementById('special-variations1').value = variation;
					
					//alert(document.getElementById('special-variations1').value);

			document.special2.submit();
			return false;
			
		}
//end

//alert(theForm.subscription);
	if(theForm.subscription!= null)
	{
		//var subscription = theForm.subscription.value;
		for (var i=0; i < theForm.subscription.length; i++)
		   {
		   if (theForm.subscription[i].checked)
			  {
			  var subscription = theForm.subscription[i].value;
			  }
		   }
		//alert(subscription);
		document.getElementById('subscription_id').value = subscription;
	}
	//  special offer for subscription pack -  End
	variation = theForm.variation.value;
	//alert(variation);
	document.getElementById('special-variations').value = variation;
	if (number_of_special_offers > 0 && specials == '' && false) {
		document.getElementById('specialofferreminder').style.visibility = 'visible';
		return false;
	} else {
		return true;
	}
}
