﻿function getCheckedValue(id) {
	radioObj=document.getElementById(id);
	if(!radioObj)
		return "-0";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function subscription(_command,_id)
{
	if(_command=="")
	{
		alert('Subscription Command Error');
	}
	if(_command=='Action:AddToBasket')
	{
		window.open('subscription.php?action=AddToBasket&id='+_id,'mywindow1','width=700,height=300,toolbar=no,location=yes,directories=yes,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	}
	if(_command=='Action:Archive')
	{
		window.open('subscription_archive.php','mywindow1','width=700,height=300,toolbar=no,location=yes,directories=yes,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
	}

	if(_command=='Action:Delete')
	{
		var tt=window.confirm('از حذف این اشتراک مطمئنید ؟');
		if(tt)
		{			
			document.location.href='subscription.php?action=Delete&id='+_id;
		}
	}
	if(_command=='Action:Update')
	{
		var cc=document.getElementById('count_'+_id).value;
		
		var type1=getCheckedValue('baskettype1_'+_id);
		var type2=getCheckedValue('baskettype2_'+_id);
		var type3=getCheckedValue('baskettype3_'+_id);
		
		if(type1!="") type=type1;
		if(type2!="") type=type2;
		if(type3!="") type=type3;
		
		var cycle1=getCheckedValue('cycle1_'+_id);
		var cycle2=getCheckedValue('cycle2_'+_id);
		var cycle3=getCheckedValue('cycle3_'+_id);
		
		if(cycle1!="") _cycle=cycle1;
		if(cycle2!="") _cycle=cycle2;
		if(cycle3!="") _cycle=cycle3;
		
		var yeartype1=getCheckedValue('yeartype1_'+_id);
		var yeartype2=getCheckedValue('yeartype2_'+_id);		
		
		if(yeartype1!="") yeartype=yeartype1;
		if(yeartype2!="") yeartype=yeartype2;				
		
		var _subsub1=document.getElementById('subsub1_'+_id).value;
		var _subsub2=document.getElementById('subsub2_'+_id).value;
		var _subsub3=document.getElementById('subsub3_'+_id).value;
		
		document.location.href='subscription.php?action=Update&id='+_id+'&count='+cc+'&type='+type+'&cycle='+_cycle+'&subsub1='+_subsub1+'&subsub2='+_subsub2+'&subsub3='+_subsub3+'&yeartype='+yeartype;

	}

}
