//Add or update the group detail
function group_UpdateGroupInfo(GroupID){

	var AfterUpdate = function(oXML) {	
		var returnVal = oXML.responseText
		
//		prompt ("",returnVal);
//		return;
		if (returnVal.substr(0,5) == "Error") {
			alert(returnVal)
		}
		else {
			//portal_reloadUserGrid()
			alert(returnVal);
			checkAction(22,82,2,null,false,null,false);
		}
		regularCursor();
	}
	
	if (document.getElementById("txtGroup").value != "") {		
		var activeBit
		if (document.getElementById("chkActive").checked) {
			activeBit = "1";
		} else {
			activeBit = "0";
		}
		
		var GroupName = document.getElementById("txtGroup").value;
		var contactids = "";
		
		var t = document.getElementById('ContactRight');
		for (i = 0; i < t.options.length; i++){
			//t.options[i].selected = true;
			contactids = contactids + t.options[i].value + ","
		}
		contactids = contactids.substring(0, contactids.length - 1);
		
		var page = "modules/sms/Groups.asp";
		var	data = "action=updategroup&txtGroup=" + encodeURIComponent(GroupName) + "&GroupID=" + GroupID + "&Active=" + activeBit + "&ContactIDs=" + contactids;
			
		hiddenSubmit(page,data, AfterUpdate, 0, null,null, false)
	}
	else{
		alert ("Please enter a valid group name")
	}
}

// JavaScript Document

function ShowHideType(TypeID)
{
	var getSMSTypeVariable = function(oXML) {
		var returnVal = oXML.responseText;			
		//document.getElementById("smstypevariablecontainer").innerHTML = returnVal			
		regularCursor();
	}
	if(TypeID == 1)
	{
		document.getElementById("rowFrequencySpace").style.display = '';	
		document.getElementById("rowFrequency").style.display = '';	
		//document.getElementById("rowExposure").style.display = 'none';	
		//document.getElementById("rowExposureSpace").style.display = 'none';	
		//document.getElementById("rowExpVariable").style.display = 'block';	
		//document.getElementById("rowExpVariableSpace").style.display = 'block';
		/*document.getElementById("btnAdd").src = "/images/add_off.gif"
		document.getElementById("btnAdd").onmouseover= function(){
			document.getElementById("btnAdd").src = "/images/add_on.gif"
		}
		document.getElementById("btnAdd").onmouseout= function(){
			document.getElementById("btnAdd").src = "/images/add_off.gif"
		}*/		
		document.getElementById("btnAdd").innerHTML = "Add";
	}
	else if(TypeID == 3)
	{
		document.getElementById("rowFrequencySpace").style.display = 'none';	
		document.getElementById("rowFrequency").style.display = 'none';			
		//document.getElementById("rowExposure").style.display = 'none';	
		//document.getElementById("rowExposureSpace").style.display = 'none';				
		//document.getElementById("rowExpVariable").style.display = 'none';	
		//document.getElementById("rowExpVariableSpace").style.display = 'none';	
		/*document.getElementById("btnAdd").src = "/images/send_off.gif"
		document.getElementById("btnAdd").onmouseover= function(){
			document.getElementById("btnAdd").src = "/images/send_on.gif"
		}
		document.getElementById("btnAdd").onmouseout= function(){
			document.getElementById("btnAdd").src = "/images/send_off.gif"
		}*/
		document.getElementById("btnAdd").innerHTML = "Send";
	}
	else
	{
		/*document.getElementById("btnAdd").src = "/images/add_off.gif"
		document.getElementById("btnAdd").onmouseover= function(){
			document.getElementById("btnAdd").src = "/images/add_on.gif"
		}
		document.getElementById("btnAdd").onmouseout= function(){
			document.getElementById("btnAdd").src = "/images/add_off.gif"
		}*/
		document.getElementById("btnAdd").innerHTML = "Add";
		document.getElementById("rowFrequencySpace").style.display = 'none';
		document.getElementById("rowFrequency").style.display = 'none';
		//document.getElementById("rowExposure").style.display = 'block';	
		//document.getElementById("rowExposureSpace").style.display = 'block';	
		//document.getElementById("rowExpVariable").style.display = 'block';	
		//document.getElementById("rowExpVariableSpace").style.display = 'block';	

		/*var page = "/modules/sms/editsmslist.asp";
		var SMSTypeID = document.getElementById("selType").value;
		var data = "ActionName=GetSMSTypeVariables&SMSTypeID=" + SMSTypeID;
		hiddenSubmit(page,data,getSMSTypeVariable,0,null,true);*/
	}
	
	var page = "/modules/sms/editsmslist.asp";
	var SMSTypeID = document.getElementById("selType").value;
	var data = "ActionName=GetSMSTypeVariables&SMSTypeID=" + SMSTypeID;
	//hiddenSubmit(page,data,whenDoneRunThis,modeDelimiter,div,postload,syncmode)
	hiddenSubmit(page,data,getSMSTypeVariable,0,null,null,true);
}

function numberonly(e)
{
	var evt = e || window.event;
	var unicode = evt.which || evt.keyCode;

	if(unicode != 8 && unicode != 13)
	{
		if(unicode<48||unicode>57)
		{
			return false;	
		}
	}
}

function CheckYear(Value, Checked)
{
	
	if (Value == 'NULL' && Checked == true)
	{	
		for(var i=0;i<6;i++)
		{
			if (document.all("chkYear")[i].checked == true)
			{
				if (document.all("chkYear")[i].value != 'NULL')
				{
					document.all("chkYear")[i].checked = false;
				}
			}
		}
	}
	else
	{
		for(var i=0;i<6;i++)
		{
			if (document.all("chkYear")[i].checked == true)
			{
				if (document.all("chkYear")[i].value == 'NULL')
				{
					document.all("chkYear")[i].checked = false;
				}
			}
		}		
	}
	
	var StrCheckYear = '';
	for(var i=0;i<6;i++)
	{
		if (document.all("chkYear")[i].checked == true)
		{
			StrCheckYear = StrCheckYear + document.all("chkYear")[i].value + '|';
		}
	}
	
	document.getElementById("txtYear").value = StrCheckYear
}

function insertAtCaret(areaId,text) 
{ 
	var txtarea = document.getElementById(areaId); 
	var scrollPos = txtarea.scrollTop; 
	var strPos = 0; 
	var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ) ); 
	
	if (br == "ie") 
	{ 
		txtarea.focus(); 
		var range = document.selection.createRange(); 
		range.moveStart ('character', -txtarea.value.length); 
		strPos = range.text.length; 
	} 
	else if (br == "ff") 
		strPos = txtarea.selectionStart; 
	
	var front = (txtarea.value).substring(0,strPos); 
	var back = (txtarea.value).substring(strPos,txtarea.value.length); 
	txtarea.value=front+text+back; 
	strPos = strPos + text.length; 
	
	if (br == "ie") 
	{ 
		txtarea.focus(); 
		var range = document.selection.createRange(); 
		range.moveStart ('character', -txtarea.value.length); 
		range.moveStart ('character', strPos); 
		range.moveEnd ('character', 0); 
		range.select(); 
	} 
	else if (br == "ff") 
	{ 
		txtarea.selectionStart = strPos; 
		txtarea.selectionEnd = strPos;
		txtarea.focus(); 
	} 
	txtarea.scrollTop = scrollPos; 
}

function ShowHideFrequency(FrequencyID)
{
	if(FrequencyID == 1 || FrequencyID == 2)
	{
		document.getElementById("rowWeeklySpace").style.display = 'none';	
		document.getElementById("rowWeekly").style.display = 'none';	
		document.getElementById("rowMonthlySpace").style.display = 'none';	
		document.getElementById("rowMonthly").style.display = 'none';	
		document.getElementById("rowMonthDaySpace").style.display = 'none';	
		document.getElementById("rowMonthDay").style.display = 'none';		
	}
	else if(FrequencyID == 3)
	{
		document.getElementById("rowWeeklySpace").style.display = '';	
		document.getElementById("rowWeekly").style.display = '';	
		document.getElementById("rowMonthlySpace").style.display = 'none';	
		document.getElementById("rowMonthly").style.display = 'none';	
		document.getElementById("rowMonthDaySpace").style.display = 'none';	
		document.getElementById("rowMonthDay").style.display = 'none';		
		
	}
	else if(FrequencyID == 4)
	{
		document.getElementById("rowWeeklySpace").style.display = 'none';	
		document.getElementById("rowWeekly").style.display = 'none';	
		document.getElementById("rowMonthlySpace").style.display = '';	
		document.getElementById("rowMonthly").style.display = '';	
		//document.getElementById("rowMonthlyTypeSpace").style.display = 'block';	
		//document.getElementById("rowMonthlyType").style.display = 'block';	
		document.getElementById("rowMonthDaySpace").style.display = '';	
		document.getElementById("rowMonthDay").style.display = '';		

	}
}

function ShowHideMonthly(MonthlyTypeID)
{
	if(MonthlyTypeID == 1)
	{
		document.getElementById("rowWeeklySpace").style.display = '';	
		document.getElementById("rowWeekly").style.display = '';	
		document.getElementById("rowMonthDaySpace").style.display = 'none';	
		document.getElementById("rowMonthDay").style.display = 'none';	
		document.getElementById("rowWeekSpace").style.display = '';	
		document.getElementById("rowWeek").style.display = '';	
	}
	else
	{
		document.getElementById("rowWeeklySpace").style.display = 'none';	
		document.getElementById("rowWeekly").style.display = 'none';	
		document.getElementById("rowMonthDaySpace").style.display = '';	
		document.getElementById("rowMonthDay").style.display = '';	
		document.getElementById("rowWeekSpace").style.display = 'none';	
		document.getElementById("rowWeek").style.display = 'none';	
	}
}

function saveGroup(ActionName){
	var GroupID = document.getElementById("GroupID").value;
	var GroupDesc = document.getElementById("Description").value;
	var compID = document.getElementById("cid").value;
	var displayMode = document.getElementById("displaymode").value;
	var Active = 0;
	
	if(GroupDesc == ''){
		alert('Please enter a valid group name.');
		document.getElementById("Description").focus();
	}
	else {
		if (document.getElementById("Active").checked == true){
			Active = 1;
		}
		for (var k=0;k<document.getElementById("lstSelected").options.length;k++){
			document.getElementById("lstSelected").options[k].selected = true;
		}
		var page = "modules/sms/editSMSGroup.asp";
		//var data = "ActionName="+ ActionName +"&GroupID=" + GroupID + "&Description=" + encodeURIComponent(GroupDesc) +  "&Active=" + Active + "&lstSelected=" + document.getElementById("lstSelected").value;
		var data = fetchInputFormData("frmGroupList");
		//alert(data);
		//hiddenSubmit(page,data,whenDoneRunThis,modeDelimiter,div,postload,syncmode)
		hiddenSubmit(page,data,alertHiddenResponse,0,null,null,true);
		//checkAction(actionID,compID,displayMode,formName,useCustomFunction,completionFunction,isModal)
		checkAction(22,compID,displayMode,null,false,null,false);
		//checkAction("LoadViewGroup",158,null,false,null);
	}
}

function savesms(ActionName){

	var SMSID = document.getElementById("txtSMSID").value;
	var SMSCode = document.getElementById("txtSMSCode").value;
	var SMSGroup = document.getElementById("lstGroup").value;
	var Name = document.getElementById("txtName").value;
	var Content = document.getElementById("txtContent").value;
	var SMSType = document.getElementById("selType").value;
	var ExposureCondition = '';
	var FrequencyID = 0;
	var StartDate = '';
	var StartTime = '';
	var MonthType = ''
	var compID = document.getElementById("cid").value;
	var displayMode = document.getElementById("displaymode").value;
	
	if (SMSGroup == '')
	{
		alert('Please select a valid SMS group.');
		document.getElementById("lstGroup").focus();
	}
	else if(Name == '')
	{
		alert('Please enter a valid SMS Name.');
		document.getElementById("txtName").focus();
	}
	else if(Content == '')
	{
		alert('Please enter valid SMS content.');
		document.getElementById("txtContent").focus();
	}
/*	else if(document.getElementById("selLanguage").value == '')
	{
		alert('Please select an SMS language.');
		document.getElementById("selLanguage").focus()
	}*/
/*	else if(SMSType == 2 && document.getElementById("txtExpCondition").value == '')
	{
		alert('Please enter valid SMS exposure limit.');
		document.getElementById("txtExpCondition").focus();
	}
	else if(SMSType == 2 && (eval(document.getElementById("txtExpCondition").value) < 1 || eval(document.getElementById("txtExpCondition").value) > 100))
	{
		//alert(eval(document.getElementById("txtExpCondition")));
		alert('The exposure limit should be a value between 1 and 100. Please enter a valid value.')
		document.getElementById("txtExpCondition").focus();
	}*/
	else
	{
		//Content += document.getElementById("txtOptOut").value;
		
		/*if(SMSType == 2)
		{
			ExposureCondition = document.getElementById("txtExpCondition").value;
		}*/
		if(SMSType == 1)
		{
			FrequencyID = document.getElementById("selFrequency").value;
			StartDate = document.getElementById("StartDate").value;
			StartTime = document.getElementById("StartTime").value;
		}
		else if(SMSType == 3)
		{
			FrequencyID = 1;
		}
		
		if (SMSType == 1 && StartTime == '')
		{
			alert('Please enter a valid SMS start time.');
			document.getElementById("StartTime").focus();
		}
		else
		{
			var GroupID;
			var Active = (document.getElementById("chkActive").checked)? 1 : 0;
			var chkval = '';
			var MonthName = '';
			
			for(var i=0;i<document.getElementById("lstGroup").options.length;i++)
			{
				if(document.getElementById("lstGroup").options[i].selected == true)
				{
					chkval = chkval + document.getElementById("lstGroup").options[i].value + '|'
				}
			}	
		
			GroupID = chkval
			chkval = ''	 
			
			if(ActionName == 'Add' || ActionName == 'Edit')
			{
				var Validate = false;
				if(document.getElementById("txtName").value == '')
				{
					alert('Please enter valid SMS name.');
					document.getElementById("txtName").focus()
				}
				else if(document.getElementById("txtContent").value == '')
				{
					alert('Please enter valid SMS content.');
					document.getElementById("txtContent").focus()
				}
				else
				{
					Validate = true;
				}
		
				if (Validate == true && SMSType == 1)
				{
					document.getElementById("txtWeekDays").value = '';
					document.getElementById("txtMonth").value = '';
					document.getElementById("txtWeek").value = '';
					document.getElementById("txtDay").value = '';
					if (document.getElementById("rowWeekly").style.display == '')
					{
						for(var i=0;i<7;i++)
						{
							if (document.all("chkWeekDays")[i].checked == true)
							{
								chkval = chkval + document.all("chkWeekDays")[i].value + '|'
							}
						}
						document.getElementById("txtWeekDays").value = chkval
						chkval = ''
					}
					if (document.getElementById("rowMonthly").style.display == '')
					{
						var Curdate = new Date();
						var CurYear = Curdate.getYear();
						var LastDate = 0;
						var MonthID = 0;
						
						for(var k=0;k<12;k++)
						{
							if (document.all("chkMonth")[k].checked == true)
							{
								MonthID = document.all("chkMonth")[k].value;
								LastDate = getLastDayOfMonth(MonthID,CurYear);
								for(i=0;i<31;i++)
								{
									if (document.all("chkDay")[i].checked == true)
									{
										var DayVal = document.all("chkDay")[i].value;
										if(DayVal > LastDate)
										{
											document.all("chkMonth")[k].checked = false;
											MonthName = MonthName + getMonthName(MonthID) + ', ';
											break;
										}
									}
								}
							}
						}				
					
						MonthType = document.getElementById("selMonthlyType").value;
						for(var i=0;i<12;i++)
						{
							if (document.all("chkMonth")[i].checked == true)
							{
								chkval = chkval + document.all("chkMonth")[i].value + '|'
							}
						}
						document.getElementById("txtMonth").value = chkval
						chkval = ''
					}
					if (document.getElementById("rowWeek").style.display == '')
					{
						for(var i=0;i<4;i++)
						{
							if (document.all("chkWeek")[i].checked == true)
							{
								chkval = chkval + document.all("chkWeek")[i].value + '|'
							}
						}
						document.getElementById("txtWeek").value = chkval
						chkval = ''
					}
					if (document.getElementById("rowMonthDay").style.display == '')
					{
						for(var i=0;i<31;i++)
						{
							if (document.all("chkDay")[i].checked == true)
							{
								chkval = chkval + document.all("chkDay")[i].value + '|'
							}
						}
						document.getElementById("txtDay").value = chkval
						chkval = ''
					}
				}

				if (FrequencyID == 3 && document.getElementById("txtWeekDays").value == '')
				{
					alert('Please select at least one week day to proceed.')					
				}
				else if(FrequencyID == 4 && document.getElementById("txtMonth").value == '')
				{
					alert('Please select at least one month to proceed.')					
				}
				else if(FrequencyID == 4 && document.getElementById("txtDay").value == '')
				{
					alert('Please select at least one month date to proceed.')					
				}				
				else
				{
					if (MonthName != '')
					{
						var Msg = 'Month(s) ' + StrLeft(MonthName,(MonthName.length - 2)) + ' are not included, because of the Last Day of Month, Are you sure you want to save?'
					}
					else
					{
						var Msg = 'Are you sure you want to save?'
					}
					//alert(Content);
					if (confirm(Msg))
					{
						var page = "modules/sms/editsmslist.asp";
						var data = "ActionName="+ ActionName +"&SMSID=" + SMSID + "&SMSCode=" + SMSCode + "&Name=" + encodeURIComponent(Name) + "&Content=" + encodeURIComponent(Content) + "&SMSType=" + SMSType;
						data = data + "&FrequencyID="+FrequencyID+"&StartDate="+StartDate+"&StartTime="+StartTime+"&MonthType="+MonthType;
						data = data + "&GroupID="+GroupID+"&Active="+Active+"&WeekDays="+document.getElementById("txtWeekDays").value+"&Month="+document.getElementById("txtMonth").value;
						data = data + "&Week="+document.getElementById("txtWeek").value+"&Day="+document.getElementById("txtDay").value+"&Year="+document.getElementById("txtYear").value;
						//data = data + "&selLanguage="+ document.getElementById("selLanguage").value;
						//alert(data);
						//hiddenSubmit(page,data,whenDoneRunThis,modeDelimiter,div,postload,syncmode)
						hiddenSubmit(page,data,alertHiddenResponse,0,null,null,true);
						//hiddenSubmit(page,data,promptHiddenResponse,0,null,true);
						//checkAction(actionID,compID,displayMode,formName,useCustomFunction,completionFunction,isModal)
						
						
						/*
						
						
						checkAction(19,compID,displayMode,null,false,null,false);
						
						
						*/
						
						
						//checkAction("LoadViewSMS",154,null,false,null);
					}
				}
			}
		}
	}
}

function StrLeft(str, n)
{
   if (n <= 0)
         return "";
   else if (n > String(str).length)
         return str;
   else
         return String(str).substring(0,n);
}

function getLastDayOfMonth(month,year)
{
// returns the last day of a given month
	var aDate = new Date(year,month,0)
    var m = new Number(aDate.getMonth());
    var y = new Number(aDate.getYear());
    var tmpDate = new Date(y, m, 28);
    var checkMonth = tmpDate.getMonth();
    var lastDay = 27;

    while(lastDay <= 31){
        tmpDate.setDate(lastDay + 1);
        if(checkMonth != tmpDate.getMonth())
            break;
        lastDay++
    }
    return lastDay;
}

function getMonthName(MonthNo)
{
	var MonthName = new Array(12);
	MonthName[0] = 'January';
	MonthName[1] = 'February';
	MonthName[2] = 'March';
	MonthName[3] = 'April';
	MonthName[4] = 'May';
	MonthName[5] = 'June';
	MonthName[6] = 'July';
	MonthName[7] = 'August';
	MonthName[8] = 'September';
	MonthName[9] = 'October';
	MonthName[10] = 'November';
	MonthName[11] = 'December';
	return MonthName[MonthNo - 1];
}

function ExecuteSMS()
{
	var page = "modules/sms/editsmslist.asp";
	var SMSID =  document.getElementById("txtSMSID").value;
	var data = "ActionName=ExecuteSMS&SMSID=" + SMSID;
	//hiddenSubmit(page,data,whenDoneRunThis,modeDelimiter,div,postload,syncmode)
	hiddenSubmit(page,data,alertHiddenResponse,0,null,null,true);
	//hiddenSubmit(page,data,promptHiddenResponse,0,null,true);
}

function ShowGroup(SMSID)
{
	var URL = '/modules/sms/linking.asp?SMSID='+SMSID;
	window.open(URL)
}

var t = 1;

function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) 
{
    var countedTextBox = opt_countedTextBox ? opt_countedTextBox : "txtContent";
    var countBody = opt_countBody ? opt_countBody : "txtCount";
    var maxSize = opt_maxSize ? opt_maxSize : 1024;
    var field = document.getElementById(countedTextBox);
	var txtField = document.getElementById(countBody);
	var Limit = maxSize;	
	var ActualCount = field.value.length + document.getElementById("txtOptOut").value.length;
	var SMSCount = ActualCount/maxSize;
	
	if (SMSCount > 1)
	{
		var c = String(SMSCount).split('.')
		t = ActualCount - (Limit * eval(c[0]));
		txtField.innerHTML = t + '/' + c[0];
	}
    else
    {
		if (txtField && ActualCount <= maxSize)
		{  
		    txtField.innerHTML = ActualCount;
		}
    }    
}

function MoveListItems(ObjA, ObjS, All){
	var ObjAvailable = document.getElementById(ObjA);
	var ObjSelected = document.getElementById(ObjS);	
	
	if (All == 0){
		for (var i=0; i < ObjAvailable.length; i++){
			if (ObjAvailable.options[i].selected == true){
				ObjSelected.options[ObjSelected.length] = new Option(ObjAvailable.options[i].text, ObjAvailable.options[i].value);
				ObjAvailable.options[i] = null;
				i--;
			}
		}
	}
	else {
		for (var i=0; i < ObjAvailable.length; i++){
			ObjSelected.options[ObjSelected.length] = new Option(ObjAvailable.options[i].text, ObjAvailable.options[i].value);
			ObjAvailable.options[i] = null;
			i--;
		}		
	}
}

//==========================SMS Delivery report =======================================

//Opens a window displaying the report on the report server
function report_SMSDelivery(form) {
	var fromDate = form.txtSentFrom.value;
	var toDate = form.txtSentTo.value;
	var Status = CheckNull(form.selStatus, 'StatusID');
	var reportURL = form.reportaction.value;
	var SMSID = CheckNull(form.selSms, 'SMSID');
	var DateSent = CheckNull(form.selDateSent, 'DateSent');
	var TimeSent = CheckNull(form.selTimeSent, 'TimeSent');
	reportURL = reportURL + "&SentFrom=" + fromDate + "&SentTo=" + toDate + "&" + Status + "&" +  SMSID + "&" + DateSent + "&" + TimeSent;
	//alert(reportURL);
	window.open(reportURL, "_blank", "toolbar=no,menubar=no,location=no,resizable=yes");
}

function CheckNull(Obj,ValueName){
	var retValue;
	if (Obj.value == '' || Obj.value == 0){
		retValue = ValueName + ":isnull=true"	
	}
	else {
		retValue = ValueName + "=" + Obj.value;
	}
	return retValue;
}
//=========================END OF SMS Delivery report================================

function manageTimeChange(){
	try {
		var selHour = document.getElementById("selHour").value;
		var selMinute = document.getElementById("selMinute").value;
		if (selHour == "" || selMinute == "") {
			document.getElementById("StartTime").value = "";
		}
		else {
			document.getElementById("StartTime").value = selHour + ":" + selMinute;
		}
	}
	catch (ex) {
		alert(ex.message);
	}
}
/*
function manageLanguageChange(languageID){
	try {
		if (languageID != ""){
			var completedOptOutLoad = function(oXML) {
				var returnValue = oXML.responseText;
				document.getElementById("OptOutDisplay").innerHTML = returnValue;
				document.getElementById("txtOptOut").value = returnValue;
				//Update counter after update
				counterUpdate('txtContent', 'txtCount','160');
				hideLoading();
				oXML = null;
			}
			var page = "/modules/sms/editsmslist.asp";
			var data = "ActionName=GetLanguageOptOut&languageID=" + languageID;
			//alert(data);
			hiddenSubmit(page,data,completedOptOutLoad,0,null,null,true);
		}
		else {
			document.getElementById("OptOutDisplay").innerHTML = "";
			document.getElementById("txtOptOut").value = "";
			//Update counter after update
			counterUpdate('txtContent', 'txtCount','160');
		}
	}
	catch (ex) {
		alert(ex.message);
	}
}
*/
function getData(action,dropdown, SentFrom, SentTo, StatusID, SMSID, DateSend, TimeSend)
{
	var page = "/modules/sms/ReportSMSDelivery.asp";
	var DataToSend = "action=" + action + "&SentFrom=" + SentFrom + "&SentTo=" + SentTo + "&StatusID=" + StatusID + "&SMSID=" + SMSID + "&DateSend=" + DateSend  + "&TimeSend=" + TimeSend;
	//alert('data: ' +  DataToSend);
	var returnvals = hiddenSubmitme(page,DataToSend);
	//alert(returnvals);
	var doc = document.getElementById(dropdown)

	if (returnvals != '')
	{
		var valarray = new Array();
		valarray = returnvals.split(",");
		ClearOptions(doc);
		if (dropdown == 'selSms')
		{
			doc = document.getElementById('selDateSent');
			ClearOptions(doc);
			doc = document.getElementById('selTimeSent');
			ClearOptions(doc);
		}	
		if (dropdown == 'selDateSent')
		{
			doc = document.getElementById('selTimeSent');
			ClearOptions(doc);
		}			
		for (var i = 0;i < valarray.length;i++){
			var secid = valarray[i];
			var secname = valarray[++i];
			addData(secid,secname,dropdown);
		}
	}
	else
	{
		ClearOptions(doc);
		if (dropdown == 'selSms')
		{
			doc = document.getElementById('selDateSent');
			ClearOptions(doc);
			doc = document.getElementById('selTimeSent');
			ClearOptions(doc);
		}
		if (dropdown == 'selDateSent')
		{
			doc = document.getElementById('selTimeSent');
			ClearOptions(doc);
		}		
	}
}

function ClearOptions(theSel)
{
  	var selIndex = theSel.selectedIndex;
	for(i=theSel.length-1; i>=0; i--)
	{
		if (theSel.options[i].value != 0)
		{
			theSel.options[i] = null;
		}
	}
	if (theSel.length > 0) {
	  theSel.selectedIndex = 0;
	}
}

function addData(secid,secname,dropdown){
	if (secid != '' && secname != '' && secid != 'undefined' && secname != 'undefined') {
		var subnum = document.getElementById(dropdown).options.length;
		var doc = document.getElementById(dropdown)
		var bln = false
		for (var i = 0;i < subnum;i++){
			if (doc.options[i].value == secid){
				bln = true
			}
		}
		if(!bln){
			doc.options[subnum] = new Option(secname,secid);
		}
	}
}

function hiddenSubmitme(page,data){
	var xmlhttp = createXMLHttp();
	if (xmlhttp){
		xmlhttp.open("POST", page , false);
		if (data != "") {
			xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		}
		xmlhttp.send(data);
		return xmlhttp.responseText;
	}
	else {
		alert("XMLHTTP is not supported by your browser.");
	}
	return;
}

