//'###########################################################################
function trim(strComp){
	ltrim = /^\s+/
	rtrim = /\s+$/
	strComp = strComp.replace(ltrim,'');
	strComp = strComp.replace(rtrim,'');
	return strComp;
}
//'###########################################################################
function displayProperties(obj) {
	var str = "";
	var arrProp = new Array();
	var prop;
	var arrIndex = 0;

	if(typeof(obj) == "undefined"){
		alert('displayProperties: Parameter is not an object!');
		return false;
	}
	
	if(typeof(obj[0]) != "undefined") {
		for(prop = 0;prop < obj.length;prop++) {
			str += "\n" + prop + "=" + obj[prop];
			arrProp[arrIndex++] = "\n" + prop + "=" + obj[prop];
		}
	}
	else {
		for(prop in obj) {
			str += "\n" + prop + "=" + eval("obj." + prop);
			arrProp[arrIndex++] = "\n" + prop + "=" + obj[prop];
		}
	}
	alert(arrProp.sort());
}
//'###########################################################################
function ToggleSearchType(tdCountryCode,tdZip,lnkSearchType,txtZipCode){	
	//var strInnerText = new string(lnkSearchType.innerText.toLowerCase());
	var strInnerText = lnkSearchType.innerText.toLowerCase();
	tdCountryCode.style.display = tdCountryCode.style.display=='none'? '':'none';
	tdZip.style.display = tdZip.style.display=='none'? '':'none';
	if(strInnerText.indexOf("zip",0)<0)
		txtZipCode.value = "";
	strInnerText = strInnerText.indexOf("zip",0)>0 ? "Search to Country" : "Search to Zip Code";
	lnkSearchType.innerText = strInnerText;
}
//'###########################################################################
function Redirect()
{
	
}
//'###########################################################################
function ToggleCollapseExpand(strTableId,objInput)
{	
	var ctrl = document.getElementById(strTableId);
	var strState = ctrl.style.display=='none'?'':'none';
	var strText = '';
	if(objInput){
		strText = ctrl.style.display=='none'? 'Less' : 'More'
	}
	try{
		for(i=0; i < trList.length; i++){
			if(strTableId == trList[i]){				
				if(objInput)
					CollapseExpand(trList[i],objInput,strState,strText);
				else
					CollapseExpand(trList[i],null,strState,strText);
			}else{
				if(objInput)
					CollapseExpand(trList[i],objInput,'none',strText);
				else
					CollapseExpand(trList[i],null,'none',strText);
			}
		}	
	}
	catch(exc){
		alert(exc.message);
	}
}
//'###########################################################################
 function TgCollapseExpandFriend(strTableId,objInput)
 {
	
	var ctrl = document.getElementById(strTableId);
	var strState = ctrl.style.display=='none'?'':'none';
	var strText = '';
	if(objInput){
		strText = ctrl.style.display=='none'? 'Click To Collapse (-)' : 'Click To Collapse (+)'
	}
	try{
		for(i=0; i < trList.length; i++){
			if(strTableId == trList[i]){				
				if(objInput)
					CollapseExpand(trList[i],objInput,strState,strText);
				else
					CollapseExpand(trList[i],null,strState,strText);
			}else{
				if(objInput)
					CollapseExpand(trList[i],objInput,'none',strText);
				else
					CollapseExpand(trList[i],null,'none',strText);
			}
		}	
	}
	catch(exc){
		alert(exc.message);
	}
 }
//############################################################################
function CollapseExpand(strTableId,objInput,strState,strText){
	var ctrl = document.getElementById(strTableId);	
	try	{		
		if(ctrl!=null)
		{			
			ctrl.style.display = strState;
			if(objInput != null)
				objInput.innerText = strText;
/*				
			if(ctrl.style.display.toLowerCase()=="none"){
				ctrl.style.display = strState;
				if(objInput != null)
					objInput.innerText = strText;
			}
			else if(ctrl.style.display.toLowerCase()==""){
				ctrl.style.display = 'none';
				if(objInput != null)
					objInput.innerText = 'More...';
			}
*/			
		}
	}
	catch(exc)
	{
		alert(exc.message);
	}
}
//'###########################################################################
function IAgreeValidate(objInput)
{	
	var strErrMessage = "Please enter 'I Agree' in the given box before continuing.";
	var blnReturnValue;
	if(trim(objInput.value) != '')
	{
		if(objInput.value.toLowerCase() == 'i agree')
			blnReturnValue =  true;
		else
			blnReturnValue =  false;
	}
	else
		blnReturnValue =  false;
	if(!blnReturnValue){
		alert(strErrMessage);								
		event.returnValue = false;
	}
}

//'###########################################################################
function ValidateUserNameLength(sender,args)
{
	args.IsValid = args.Value.length >= 3;
}
//'###########################################################################
function ValidateEMail(sender,args){
	displayProperties(sender)
	if(args.Value.length == '') 
	{
		
	} 
}
//'###########################################################################
function SelectedUsers(objInput){
	var ctrlUserList = document.getElementById('txtUserIds');
	var ctrlSend = document.getElementById('imgbtnSend');
	if(ctrlUserList != null || typeof(ctrlUserList) != 'undefined'){
		if(objInput.checked)
			ctrlUserList.value = AddUser(objInput.id,ctrlUserList.value);
		else
			ctrlUserList.value = RemoveUser(objInput.id,ctrlUserList.value);		
		if(trim(ctrlUserList.value)!='' && ctrlSend!=null)
			ctrlSend.disabled=false;
		else if(trim(ctrlUserList.value)=='' && ctrlSend!=null)
			ctrlSend.disabled=true;
	}
}
//'###########################################################################
function MessageValidate(){
	var ctrlMessage = document.getElementById('txtMessage');	
	
	if(ctrlMessage!=null && trim(ctrlMessage.value)!= '')
		return true;
	else{
		alert('Please enter some message before continuing.');
		return false;
	}
}
//'###########################################################################
function AddUser(strUserId,strUserList){
	var strUsers = strUserList;
	if(trim(strUserList) == '')
		return (strUserId);
	else{
		strUsers = ',' + strUserList + ',';		
		if(strUsers.indexOf(','+strUserId+',')>=0){
			return (strUserList);
		}
		else
			return (strUserList + ',' + strUserId);
	}
}
//'###########################################################################
function RemoveUser(strUserId,strUserList){		
	var strUsers = strUserList;
	var intIndex;
	if(trim(strUserList) == '')
		return (strUserList);
	else{ 
		strUsers = ',' + strUserList + ',';
		intIndex = strUsers.indexOf(','+trim(strUserId)+',');
		if(intIndex==0){
			//Begnining of the string.			
			var strValue = strUsers.replace(','+strUserId+',','');
			return (strValue.substring(0,strValue.length-1));
		}else if(intIndex >0 &&  parseInt(intIndex+2)==parseInt(strUsers.length-1)){
			//In end of the string.			
			return (strUsers.substring(1,strUsers.length).replace(','+strUserId+',',''));
		}else if(intIndex>0){
			//In middle of the string						
			return(strUsers.substring(1,strUsers.length-1).replace(','+strUserId,''));
		}
					
	}
}
//'###########################################################################
function textboxChange(elemId, charElemId, maxLen) {
   var txtelem = document.getElementById(elemId);
   if (txtelem) {
      var curvalue = String(txtelem.value);
      if (curvalue.length > maxLen) {
         txtelem.value = curvalue.substring(0, maxLen);
      }

      var charelem = document.getElementById(charElemId);
      if (charelem) {
         charelem.innerHTML = String(maxLen - txtelem.value.length);
      }
   }
}
//'###########################################################################
function SetMaxLengthLabel(objInput,lblLabel,intMaxLength,args){	
	try{
		//displayProperties(args);
		//args.keyCode = 8;
		if(parseInt(intMaxLength) - parseInt(objInput.value.length)>=0){
			lblLabel.innerText = parseInt(intMaxLength) - parseInt(objInput.value.length);
		}
		if(parseInt(objInput.value.length) > parseInt(intMaxLength)) {
			objInput.value = objInput.value.substring(0, intMaxLength);
		}
	}catch(Exc){
		alert(Exc.message);
	}
}
//'###########################################################################
function CheckAll(objInput){
	var ctrl;	
	var blnChekced = objInput.checked;
	for(var i=0;i<chkArr.length;i++){
		ctrl = document.getElementById(chkArr[i]);
		if(ctrl)
			ctrl.checked = blnChekced;
	}
}
//'###########################################################################
function OCheckAll(objInput,strGridId){
	
}
//'###########################################################################
function TgCollapseExpand(strTableId)
{	
	//alert("first " + strTableId);	
	//var ctrl = document.getElementById(strTableId);
	//alert("second " + typeof(ctrl));	
	//alert("third "  + strTableId.style.display);
	if (tblBasicTrust.style.display == null)
	{
		tblBasicTrust.style.display = "none";
	}
	else
	{
		tblBasicTrust.style.display = "block";
	}
}