/**/
function MessageOpenAction(querystring, channelTechnicalName)
{
	var url;
	var target;
	var parameters;
	var channelTechnicalName = channelTechnicalName.toLowerCase();
	if(channelTechnicalName == "email")
	{
		url = "EmailMessage/EmailMessage.aspx" + querystring;
		target = "EmailMessage";
		parameters = "location=no,menubar=no,resizable=yes,scrollbars=no,status=yes,toolbar=no,titlebar=no,width=700,height=550";
	}
	else
	{
		url = "ViewMessage.aspx" + querystring;
		target = "ViewMessage";
		parameters = "toolbar,width=150,height=100";
	}

	window.open(url, target, parameters);
}

/*Removes all whitespaces in a string.*/
function RemoveWhiteSpace(inputString)
{
	return inputString.replace(/[\s]+/g, '');
}

/*Removes all leading and trailing whitespaces in a string.*/
function RemoveLeadingTrailingWhiteSpace(inputString)
{
	return inputString.replace(/^\s*/, '').replace(/\s*$/, ''); 
}

/*Enables or disables a field.*/
function EnableDisableField(field, enable) 
{
	var fld = document.getElementById(field);
	if(enable)
		fld.disabled = '';
	else
		fld.disabled = 'disabled';
}

/*Enables/disables a number ofcontrols specified in an array. */
function DisableControls(arrControls, disable)
{
	for(var i=0;i<arrControls.length;i++)
	{
		var ctrl = document.getElementById(arrControls[i]);
		//Must change for 'null' since some of the elements might be disabled from code behind and because 
		//of that not available on the client.
		if(ctrl != null)
			ctrl.disabled = disable;
	}
}

/*Selects or unselects a radiobutton or an checkbox.*/
function CheckControl(field, check)
{
	var fld = document.getElementById(field);
	
	if(fld == null) 
		return;
	
	if(check)
		fld.checked = true;
	else
		fld.checked = false;
}

/*Selects or unselects all radiobuttons or checkboxes in an array except the one specifid in the exceptedField parameter.*/
function CheckControls(fields, exceptedField, check)
{
	for(var i=0;i<fields.length;i++)
	{
		if(fields[i] != exceptedField)
		{
			CheckControl(fields[i], check)
		}
	}
		
}

/*Clears a contol's valuefield.*/
function ClearTextField(field)
{
	var fld = document.getElementById(field);
	fld.value = "";
		
}

/*Clears the valuefields of all controls in an array except the one specifid in the exceptedField parameter.*/
function ClearTextFields(fields, exceptedField)
{
	var fld;
	
	for(var i=0;i<fields.length;i++)
	{
		if(fields[i] != exceptedField)
		{
			fld = document.getElementById(fields[i]);
			if(fld != null)
				fld.value = "";
		}
	}
		
}

/*Sets the text of a textbox.*/
function SetTextbox(controlId, txt)
{
	var ctrl = document.getElementById(controlId);
	ctrl.value = txt;
}

/*Sets the focus to the specified control.*/
function FocusControl(controlId)
{
	var ctrl = document.getElementById(controlId);
	ctrl.focus();
}

/* Returns the super array's subarray specified by the arrayNumber parameter.
If the superArray = [["Name1",45, subArray1],["Name2", 34, subArray2]]
and the arrayId = 34. The subArray2 is returned.*/
function GetSubArray(superArray, arrayId)
{
	for(var i=0;i<superArray.length;i++)
	{
		if(superArray[i][1] == arrayId && superArray[i][2][0].length > 0)
			return superArray[i][2];
	}
	//Returns -1 if no array is found.
	return -1;
}

/*Populates a list from an array with format: [["Text1", value], ["Text2", value], ["Text3", value]]*/
function PopulateList(list, values)
{
	var lst = document.getElementById(list);
	lst.options.length = 0;
	for(var i=0;i<values.length;i++)
	{
		lst.options[i] = new Option(values[i][0], values[i][1]);
	}
}

/*Searches a list and selects the option element if a match is found.*/
function SelectListObject(objectText, listId)
{
	var list = document.getElementById(listId);
	//alert(li);
	for(var i=0;i<list.length;i++)
	{
		if(list.options[i].text == objectText)
		{
			list.selectedIndex = i;
		}
	}
}

/*Enables a Calendar popup control.*/
function EnableCalendarPopUp(calendarId)
{
	document.getElementById(calendarId +"_outer").disabled=false;
	document.getElementById(calendarId).disabled=false;
	document.getElementById(calendarId).readOnly=false;
	var spanCal = document.getElementById(calendarId + "_outer");
	if(spanCal.getElementsByTagName("a")[0] != null)
		spanCal.getElementsByTagName("a")[0].href = "javascript:" + calendarId + "_Up_CallClick(event);";
}

/*Enables or disables the html representation of an radiobuttonlist.*/
function EnableRadioButtonList(controlId, disable)
{
	var e = document.getElementById(controlId);
	e.disabled = false;
	var elems1 = e.getElementsByTagName("input");
	for (var i=0; i < elems1.length; i++)
	{
		elems1[i].disabled = false;
		elems1[i].readOnly = false;
	}
	var elems2 = e.getElementsByTagName("span");
	for (var i=0; i < elems2.length; i++)
	{
		elems2[i].disabled = false;
		elems2[i].readOnly = false;
	}
}


/*Converts a date to the specified date format.*/
function formatDate(date,format)
{
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	var value=new Object();
	if(y.length < 4)
	{
		y=""+(y-0+1900);
	}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if(H==0)
	{
		value["h"]=12;
	}
	else if(H>12)
	{
		value["h"]=H-12;
	}
	else
	{
		value["h"]=H;
	}
	value["hh"]=LZ(value["h"]);
	if(H>11)
	{
		value["K"]=H-12;
	}
	else
	{
		value["K"]=H;
	}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if(H > 11)
	{
		value["a"]="PM";
	}
	else
	{
		value["a"]="AM";
	}
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while(i_format < format.length)
	{
		c=format.charAt(i_format);
		token="";
		while((format.charAt(i_format)==c) &&(i_format < format.length))
		{
			token += format.charAt(i_format++);
		}
		if(value[token] != null)
		{
			result=result + value[token];
		}
		else
		{
			result=result + token;
		}
	}
	return result;
}

/*Help function to formatDate(date,format).*/
function LZ(x)
{
	return(x<0||x>9?"":"0")+x
}

/*Help variables to formatDate(date,format).*/
var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');


