/*************************************************/	
function ShowTooltip(tooltip)
{
    document.getElementById("ToolTipRow").innerHtml = tooltip; 
    //document.getElementById("td1").innerText=address;
    /*document.getElementById("td2").innerText=city;
    document.getElementById("td3").innerText=state;
    document.getElementById("td4").innerText=phone1;
    document.getElementById("td5").innerText=fax;*/
    x = event.clientX; + document.body.scrollLeft;
    y = event.clientY; + document.body.scrollTop + 10;
    
    Popup.style.visibility='visible';
    Popup.style.left = x;
    Popup.style.top = y;
 }

function HideTooltip()
{
    Popup.style.visibility="hidden";
}

/*************************************************/	
function getConfirm()
{
	return confirm("Are you sure to delete your selection (s)?");
}

/*************************************************/	
function PrintContent(tble, csspath)
{
		var tbl= document.getElementById(tble); 
		
		newwin  = window.open("Print","printwindow")
		newwin.document.write("<HTML>");
		newwin.document.write("<head>");
		newwin.document.write("<Title></Title>");
		newwin.document.write('<style type="text/css">BODY { MARGIN: 0px }</style>');
		newwin.document.write('	<LINK type="text/css" rel="stylesheet" href= ' + csspath + '>');
		newwin.document.write("</head>");
		newwin.document.write("<body>");
		newwin.document.write('<table  cellSpacing="0" cellPadding="4" width="100%" border="0" >');
		
		newwin.document.write(tbl.innerHTML);
		
		newwin.document.write("</table>");
		newwin.document.write("</body>");
		newwin.document.write("</HTML>");
		//newwin.print();
		//newwin.document.getElementById('btnPrint').style.visibility='hidden';		
}

/*************************************************/	
function AddDataToHiddenControl(List, ValueTextBox)
{
	var counter;
	var Data,Temp;
	Data ="";
	Temp ="";
		
	for(counter = 0; counter < List.length; counter++ )
	{	
		Temp = List.options[counter].value;	 	
		Data = Data + Temp;
		if( counter != List.length-1 )
		{
			Data = Data + ",";
		}
	}
	ValueTextBox.value =Data;
}

/*************************************************/	
function moveOptions(ListFrom, ListTo)
{	
	var selLength = ListFrom.length;
	var selectedText = new Array();
	var selectedValues = new Array();
	var selectedCount = 0;
	var i;
		
	for(i = selLength-1; i>=0; i--)
	{
		if(ListFrom.options[i].selected)
		{
			selectedText[selectedCount] = ListFrom.options[i].text;
			selectedValues[selectedCount] = ListFrom.options[i].value;
			deleteOption(ListFrom, i);
			selectedCount++;
		}
	}
	for(i = selectedCount-1; i>=0; i--)
	{
		addOption(ListTo, selectedText[i], selectedValues[i]);		
	}
	
}

/*************************************************/	
function AddVariables( ListFrom, TextBoxTo )
{
	var lstVariables  = ListFrom;
	var selLength = lstVariables.length;
	var txtbody = FTB_API['TextBoxTo'];
	for(i = selLength-1; i >= 0 ; i-- )
	{
		if(lstVariables.options[i].selected)
		{
			txtbody.SetHtml(txtbody.GetHtml() + "<b>" + "{{" + lstVariables.options[i].text + "}}" + "</b>" );
		}
	}	
}

/*************************************************/	


function deleteOption(List, theIndex)
{	
	var selLength = List.length;
	if( selLength > 0 )
	{
		List.options[theIndex] = null;
	}
}

/*************************************************/	
function addOption(List, theText, theValue)
{
	var newOpt = new Option(theText, theValue);
	var selLength = List.length;
	List.options[selLength] = newOpt;
}

/*************************************************/	
function  IsSelected(  )
{
	var frm = document.MainForm;
	
	for(i = 0;i< frm.length;i++)
		{
			e = frm.elements[i];
			if(e.type == 'checkbox' && e.name.indexOf('chkSelect') != -1 && e.checked == true )
			{
				return true;					
			}
		}
	return false;
}

/*************************************************/	

function IsListItemSelected(lst)
{
	var i ;
	i =0;
	var count ;
	count =0;
	
	for( i = 0; i< lst.length; i++ )
	{
		if (lst.options[i] == true)
		{
			count = count +1;
		}
	}
	
	if ( count > 0 )
		return true;
	else
		return false;
}

/*************************************************/	
function CheckChanged()
	{
		var frm = document.MainForm;
		var boolAllChecked;
		boolAllChecked = true;

		for( i = 0;i < frm.length; i++ )
		{
			e = frm.elements[i];
		
			if ( e.type == 'checkbox' && e.name.indexOf('chkSelect') != -1 )
			
			{
				var All = e.name.indexOf('chkSelectAll');
				 
				if(e.checked == false && All == -1 )
				{
					boolAllChecked = false;
					break;
				}
			}					
		}
		
		for(i = 0;i< frm.length;i++)
		{
			e = frm.elements[i];
			if ( e.type == 'checkbox' && e.name.indexOf('chkSelectAll') != -1 )    
			{
				if( boolAllChecked == false)
				{
					e.checked = false ;
					break;
				}
				else(boolAllChecked == true)
				{
					e.checked = true;
					break;
				}					
			}
		}
	}
	
/*************************************************/	

function CloseWindow()
{
	window.close();
}


/*************************************************/	
function CheckAll( checkAllBox )
{
var ChkState = checkAllBox.checked;
var frm = document.MainForm;
var TR;

 for(i = 0;i< frm.length;i++)
	{
		e = frm.elements[i];
		
		if( e.type == 'hidden' && e.name.indexOf('txtColor' ) != -1 )
		{
			if( ChkState == false )
			{
				Row = e.parentNode.parentNode;
				Row.style.foregroundColor = "Black";
				Row.style.backgroundColor = e.value;
			
			}
		}
		
		if(e.type == 'checkbox' && e.name.indexOf('chkSelect') != -1)
		{
			e.checked = ChkState;
			if( e.name.indexOf( 'chkSelectAll' )== -1)
			{			
				TR = e.parentNode.parentNode;
				if( ChkState == true )
				{
					TR.style.foregroundColor = "White";
					TR.style.backgroundColor = "#D9E6F9";			
				}
			}			
		}
	}
}

/*************************************************/	
function saveColors(Grid)
{
	
}
/*************************************************/	
function colorRow()
{
	var frm = document.MainForm;
	for(i = 0;i< frm.length;i++)
	{
		e = frm.elements[i];
		if(e.type == 'checkbox' && e.name.indexOf('chkSelect') != -1)
		{
			ChkState = e.checked;
			if( e.name.indexOf('chkSelectAll')== -1 )
			{			
				TR = e.parentNode.parentNode;
				if( ChkState == true )
				{
					TR.style.foregroundColor = "White";
					TR.style.backgroundColor = "#D9E6F9";								
				}
			}			
		}
		
		if( e.type == 'hidden' && e.name.indexOf('txtColor' ) != -1 )
		{
			if( ChkState == false )
			{
				Row = e.parentNode.parentNode;
				Row.style.foregroundColor = "Black";
				Row.style.backgroundColor = e.value;
			}
		}
	}
	CheckChanged();
}

/*************************************************/	

function openWindow(pageURL, pageHeight, pageWidth) {

	
	if (navigator.userAgent.indexOf("MSIE") != -1){
		var a = new Array();
		a[0] = window;
		var dlgOptions = "dialogHeight: " + pageHeight + "px; dialogWidth: " + pageWidth + "px ; center: Yes; edge: Sunken; help: No; resizable: No; scroll: Yes; status: No;";
		window.showModalDialog(pageURL, a, dlgOptions);
	}else{
		var topPos = (screen.height - pageHeight.substring(0,pageHeight.length-2)) / 2;
		var leftPos = (screen.width - pageWidth.substring(0,pageWidth.length-2)) / 2;
		var windowOptions = "height=" + pageHeight + ",width=" + pageWidth + ",directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,modal=yes,top=" + topPos + ",left=" + leftPos;
		window.open(pageURL,"NewWindow",windowOptions);
	}
	return false;
}

/*************************************************/	
function CustomClose(postBackButton)
{
	
	if (navigator.userAgent.indexOf("MSIE") != -1){			
		var a = window.dialogArguments;
		a[0].__doPostBack(postBackButton, '');
		
	}else{
		window.opener.__doPostBack(postBackButton, '');
	}
	window.close();
}

/*************************************************/	
function ShowSelected( LstBox, Grid )
{
	var Count = LstBox.length;
	var SelectedValues = "";
	var SelectedText = "";
	var row; 
	for( i= 0; i < Count;i++ )
	{
		if( LstBox.options[i].selected )
		{
			SelectedValues	+= LstBox.options[i].value + ",";
			SelectedText	+= LstBox.options[i].text + ",";
		}	
	}	
	
	SelectedValues	= SelectedValues.substr(0, SelectedValues.length -1 );
	SelectedText	= SelectedText.substr(0, SelectedText.length -1 );
		
	if( SelectedText != "" )
	{
		igtbl_addNew( Grid, 0 );
		row = igtbl_getActiveRow( Grid );
		row.getCell(0).setValue( SelectedValues );
		row.getCell(1).setValue( SelectedText );
	}
		
	var oGrid		= igtbl_getGridById( Grid )
    var oRows		= oGrid.Rows;
    var total		= oRows.length;    
       
    for( i = 0; i< oRows.length; i++ ) 
    {
      oRow			 = oRows.getRow(i);
      total			+= oRow.ChildRowsCount
    }
        
    if( SelectedText != "" )    
    {
		row.getCell(0).setValue( total );		   
    } 
}