function changeWebLink(obj)
{
	if(obj.value != "")
	{
		window.open( obj.value );
	}
}
function CheckAll(status)
{
	var alen = document.frmList.chkid.length;
	if(alen == null && document.frmList.chkid != null)
	{
		document.frmList.chkid.checked = status;
	}
	else
	{
		for(var i=0;i<alen;i++)
		{
			document.frmList.chkid[i].checked = status;				
		}
	}	
	if(document.frmList.chkCheckAll != null)
	{
		document.frmList.chkCheckAll.checked = (status)? true : false;
	}	
	Set_Color("tblGrid", status);
}
function Set_Color(table_id, status)
{
	var tblGrid = document.getElementById(table_id);
	if(tblGrid != null)
	{
		for(var i=0;i<tblGrid.rows.length;i++)
		{
			if(tblGrid.rows[i].id != '')
			{
				if(status)
					tblGrid.rows[i].className = 'TRSelected';
				else
					tblGrid.rows[i].className = '';	
			}
		}
	}	
}
function CheckOne(obj, trID)
{	
	//set color for tr tag
	var objRow = document.getElementById(trID);
	if(obj.checked)
		objRow.className = 'TRSelected';
	else
		objRow.className = '';	
					
	//set check all
	if(document.frmList.chkCheckAll != null)
	{
		var check = IsCheckedAll();				
		if(check)	
			document.frmList.chkCheckAll.checked = true;
		else
			document.frmList.chkCheckAll.checked = false;
	}
	calculate_Selected();
}
function getInputObject(obj, typeName, name, id)
{
	for(var i=0;i<obj.length;i++)
	{
		if( obj[i].type == typeName && (obj[i].name == name || obj[i].id == id) )
			return obj[i];
	}
	return null;
}
var allowClickRow = true;
function clickTableRow(trID)
{	
	if(!allowClickRow)
		return false;
	//set color for tr tag
	var tblGrid = document.getElementById("tblGrid");
	if(tblGrid != null)
	{
		var trs = tblGrid.getElementsByTagName('tr');
		for(var i=0;i<tblGrid.rows.length;i++)
		{
			if(tblGrid.rows[i].id == trID)
			{				
				var checkboxTag = tblGrid.rows[i].getElementsByTagName("input");				
				var objCheckBox = getInputObject(checkboxTag, 'checkbox', 'chkid', '');
				if(objCheckBox != null)
				{
					if(tblGrid.rows[i].className == 'TRSelected')
					{
						tblGrid.rows[i].className = '';	
						objCheckBox.checked = false;
					}
					else
					{
						tblGrid.rows[i].className = 'TRSelected';	
						objCheckBox.checked = true;	
					}
				}
				break;	
			}
		}
	}
	//set check all
	if(document.frmList.chkCheckAll != null)
	{
		var check = IsCheckedAll();				
		if(check)	
			document.frmList.chkCheckAll.checked = true;
		else
			document.frmList.chkCheckAll.checked = false;
	}
	calculate_Selected();
}
function IsCheckedAll()
{
	var alen = document.frmList.chkid.length;
	if(alen == null && document.frmList.chkid != null)
	{
		if(document.frmList.chkid.checked == false)
			return false;
	}	
	for (var i=0; i < alen; i++) 
	{	    
		if(document.frmList.chkid[i].checked == false)
			return false;
	}
	return true;
}
function calculate_Selected()
{			
	var strSelected = "";					
	var alen = document.frmList.chkid.length;
	if (alen > 0)
	{
		for(var i=0;i<alen;i++)
			if(document.frmList.chkid[i].checked)
				strSelected += document.frmList.chkid[i].value + ";";
	}
	else
	{
		if(document.frmList.chkid.checked)
			strSelected = document.frmList.chkid.value;
	}				
	strSelected = trimEnd(strSelected, ';');
	document.frmList.hidden_selectedItems.value = strSelected;					
}
function trimEnd(str, trimChar)
{
	if(str != '' && str.indexOf(trimChar) != -1)
		str = str.substr(0, str.lastIndexOf(trimChar));		
	return str;
}
function itemIsChecked()
{
	if(document.frmList.chkid == null)
		return false;
	var isChecked = false;	
	var alen=document.frmList.elements.length;	
	alen=(alen>0)?document.frmList.chkid.length:0;
	if (alen>1)
	{
		for(var i=0;i<alen;i++)
			if(document.frmList.chkid[i].checked==true)
				isChecked=true;
	}else
	{
		if(document.frmList.chkid.checked==true)
			isChecked=true;
	}
	
	if (!isChecked)											
		alert("Please select at least one of them.");
	else
		calculate_Selected();
	//if(isChecked)
		//return confirm('Are you sure you want to delete this items?');
	return isChecked;
}
function checkSearch()
{
	return true;
}
function listPageSubmit()
{
	if(itemIsChecked())
		document.frmList.action = window.location.href;			
	else
		return false;
}
function deleteListItems()
{
	if(itemIsChecked() && confirm('Are you sure you want to delete this items?'))
	{
		document.frmList.hidden_submitType.value = 'delete';
		document.frmList.action = window.location.href;		
	}
	else 
		return false;	
}
function deleteListItem(itemDelete)
{	
	var isDelete = confirm('Are you sure you want to delete this items?');
	if(isDelete)
	{
		document.frmList.hidden_submitType.value = 'delete';
		document.frmList.hidden_selectedItems.value = itemDelete;	
		document.frmList.action = window.location.href;		
	}
	allowClickRow = false;
	return isDelete;
}
function GotoPage(iPage) 
{	
	document.frmPaging.curPg.value = iPage;
    document.frmPaging.submit();
}
function DoonMouseOver(obj)
{
	if(obj.className != 'TRSelected')
		obj.className = 'TRonMouseOver';
}
function DoonMouseOut(obj)
{
	if(obj.className != 'TRSelected')
		obj.className = '';
}

function isEmail(s)
{   
  s = s.toLowerCase();
  if (s=="") return false;
  if(s.indexOf(" ")>0) return false;
  if(s.indexOf("@")==-1) return false;
  var i = 1;
  var sLength = s.length;
  if (s.indexOf(".")==-1) return false;
  if (s.indexOf("..")!=-1) return false;
  if (s.indexOf("@")!=s.lastIndexOf("@")) return false;
  if (s.lastIndexOf(".")==s.length-1) return false;
  var str="abcdefghikjlmnopqrstuvwxyz-@._1234567890"; 
  for(var j=0;j<s.length;j++)
	if(str.indexOf(s.charAt(j))==-1)
		return false;
   return true;
}
function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{   
	var whitespace = " \t\n\r";
	var i;

  if (isEmpty(s)) return true;
  for (i = 0; i < s.length; i++)
  {   
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1) return false;
  }
  return true;
}
function sort_grid(sort_column)
{					
	var str_sort = document.frmList.hidden_sort_column.value;
	if(str_sort == "")
		str_sort = sort_column + ';' + 'ASC';
	else
	{	
		if(str_sort.indexOf(";") != -1)
		{
			var cmd = str_sort.split(";");
			if(sort_column == cmd[0])
			{
				if(cmd[1] == "ASC")
					str_sort = sort_column + ';' + 'DESC';
				else
					str_sort = sort_column + ';' + 'ASC';
			}
			else
			{
				str_sort = sort_column + ';' + 'ASC';
			}	
		}
	}
	document.frmList.hidden_sort_column.value = str_sort;
	document.frmList.action = window.location.href;
	document.frmList.submit();
}
//Add/Remove
function compareOptionValues(a, b) 
{ 
  var sA = parseInt( a.value, 36 );  
  var sB = parseInt( b.value, 36 );  
  return sA - sB;
}
function compareOptionText(a, b) 
{ 
  var sA = parseInt( a.text, 36 );  
  var sB = parseInt( b.text, 36 );  
  return sA - sB;
}
function moveDualList( srcList, destList, moveAll ) 
{
  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )
  {
    return;
  }
  newDestList = new Array( destList.options.length );
  var len = 0;
  for( len = 0; len < destList.options.length; len++ ) 
  {
    if ( destList.options[ len ] != null )
    {
      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
    }
  }
  for( var i = 0; i < srcList.options.length; i++ ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );
       len++;
    }
  }
  // Sort out the new destination list
  newDestList.sort( compareOptionValues );   // BY VALUES

  //newDestList.sort( compareOptionText );   // BY TEXT

  // Populate the destination with the items from the new array
  for ( var j = 0; j < newDestList.length; j++ ) 
  {
    if ( newDestList[ j ] != null )
    {
      destList.options[ j ] = newDestList[ j ];
    }
  }
  for( var i = srcList.options.length - 1; i >= 0; i-- ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       srcList.options[i]       = null;
    }
  }
} 
function itemisexist(srcList, item_value)
{
	for(var i = 0; i < srcList.options.length; i++ ) 
	{
		if(srcList.options[ i ].value == item_value)	
			return true;
	}
	return false;
}
function moveDualListLeft( srcList, destList, moveAll ) 
{
  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )
  {
    return;
  }
  newDestList = new Array( destList.options.length );
  var len = 0;
  for( len = 0; len < destList.options.length; len++ ) 
  {
    if ( destList.options[ len ] != null )
    {
      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
    }
  }
  for( var i = 0; i < srcList.options.length; i++ ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
	   if(!itemisexist(destList, srcList.options[i].value))
	   {
	       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );
    	   len++;
	   }
    }
  }
  // Sort out the new destination list
  newDestList.sort( compareOptionValues );   // BY VALUES

  //newDestList.sort( compareOptionText );   // BY TEXT

  // Populate the destination with the items from the new array
  for ( var j = 0; j < newDestList.length; j++ ) 
  {
    if ( newDestList[ j ] != null )
    {
      destList.options[ j ] = newDestList[ j ];
    }
  }  
}

function moveDualListRight( srcList, destList, moveAll ) 
{
  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )
  {
    return;
  }
  newDestList = new Array( destList.options.length );
  var len = 0;
  for( len = 0; len < destList.options.length; len++ ) 
  {
    if ( destList.options[ len ] != null )
    {
      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
    }
  }
  
  // Sort out the new destination list
  newDestList.sort( compareOptionValues );   // BY VALUES

  //newDestList.sort( compareOptionText );   // BY TEXT

  // Populate the destination with the items from the new array
  for ( var j = 0; j < newDestList.length; j++ ) 
  {
    if ( newDestList[ j ] != null )
    {
      destList.options[ j ] = newDestList[ j ];
    }
  }
  for( var i = srcList.options.length - 1; i >= 0; i-- ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       srcList.options[i]       = null;
    }
  }
}
function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}
function moveOptionUp(obj) 
{
	if (!hasOptions(obj)) { return; }
	for (i=0; i<obj.options.length; i++) 
	{
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
}
function moveOptionDown(obj) 
{
	if (!hasOptions(obj)) { return; }
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
	}
}
function get_listbox(destList)
{
	var str = "";
	for(var i = 0; i < destList.options.length; i++ ) 
	{
		if( i!=0 )
		{
			str += ";";
		}	
		str += destList.options[i].value + '#' + destList.options[i].text;
	}
	return str;
}
//end Add/Remove

function selected_selectControl(selectID, selectValue)
{
	var objSelect = document.getElementById(selectID);
	if(objSelect != null)
	{
		objSelect.selectedIndex = 0;
		for(var i=0;i<objSelect.length;i++)
		{
			if(objSelect[i].value == selectValue)
			{
					objSelect.selectedIndex = i;
					break;
			}
		}
	}
	else
	{
		//alert("selected_selectControl: " + selectID + ' is null');	
	}
}

function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
function trim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
function isNumber(str)
{
	 var validChars = "0123456789.,";
	 for (i = 0; i < str.length; i++) 
	 {
		var char = str.charAt(i); 
		if (validChars.indexOf(char) == -1) 
		{
			return false;
		}
	 }			 
	 return true;
}
function Splits(str, tag)
{
	var i = 0;
	var arr = new Array();
	while(str.indexOf(tag) != -1)	
	{
		arr[i] = str.substr(0,str.indexOf(tag));
		str = str.substr(str.indexOf(tag) + tag.length, str.length - str.indexOf(tag) - tag.length);			
		i++;
	}
	arr[i] = str;
	return arr;
}

function readOnly_control(control_id, flag)
{
	if(document.getElementById(control_id) != null)
		document.getElementById(control_id).readOnly = flag;
}
function display_control(control_id, flag)
{
	var obj = document.getElementById(control_id);
	if(obj != null)
	{
		var isMozilla = document.getElementById&&!document.all;
		if(flag)
		{
			if(isMozilla)
			{
				obj.style.display = 'table-row';
			}
			else
			{
				obj.style.display = 'Block';
			}
		}
		else
		{
			if(isMozilla)
			{
				obj.style.display = 'None';
			}
			else
			{
				obj.style.display = 'None';
			}	
		}
	}
}
function get_browsers()
{
	var result = -1;	
	
	var isIE = navigator.appName.indexOf("Microsoft") !=-1 ? 1 : 0;
		if(isIE) result = 0;

	var isMozilla = document.getElementById&&!document.all;	
	if(isMozilla)
		result = 1;
		
	return 	result;
}
function disabled_control()
{
	try
	{
		var obj = document.getElementsByTagName("select");	
		for(var i=0;i<obj.length;i++)
		{
			obj[i].disabled = true;			
		}
		obj = document.getElementsByTagName("input");
		for(var i=0;i<obj.length;i++)
		{
			obj[i].disabled = true;			
			if(obj[i].id == 'bt_cancel' || obj[i].name == 'bt_cancel' || obj[i].value == 'Cancel')
				obj[i].disabled = false;
			if(obj[i].type == 'submit' || obj[i].value == 'Save' || obj[i].value == 'Update' || obj[i].value == 'Export')	
			{
				obj[i].style.display = 'None';	
			}
		}
		obj = document.getElementsByTagName("textarea");
		for(var i=0;i<obj.length;i++)
		{
			obj[i].disabled = true;			
		}
		obj = document.getElementsByTagName("img");
		for(var i=0;i<obj.length;i++)
		{
			//obj[i].style.display = 'None';
		}
	}
	catch(e)
	{
		//alert(e.message);	
	}
}
function createCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else 
	{
		var expires = "";
	}
	document.cookie = name+"="+value+expires;
}	
function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function redirectPage(url)
{
	location.href = url;
	return false;
}
function editItems(url)
{	
	location.href = url;
	return false;
}
function popupBlocked() 
{
	var PUtest = window.open(null,"","width=100,height=100");
	try 
	{ 
		PUtest.close(); 
		alert('Test popup was blocked.');	
		return false;
	 }
	catch(e) 
	{ 
		return true; 
	}	
}
function onFocusSearch(obj,defaultValue)
{
	if(obj.value==defaultValue)
	{ 
		obj.value=''; 
		obj.style.color='#000000';
	}
}

function onBlurSearch(obj, defaultValue)
{
	if(obj.value=='')
	{
		obj.value=defaultValue;
		obj.style.color='#b2b2b2';
	}
}
function reloadPage()
{
	location.reload(true);
}
function roundNumber(number)
{
	var result = Math.round(number*100)/100; //15.567
	return result; //15.57
}
function toFixedNumber(number)
{
	var result = number.toFixed(2); //15.56789342
	return result; // 15.56
}
function removeOption(id)
{
  var elSel = document.getElementById(id);
  for (var i = elSel.length - 1; i>=0; i--) 
  {
	elSel.remove(i);
  }
}
function replace_comma_to_dot(str)
{
	if(str.length > 1)
  		str = str.replace(',','.');
	return str;
}
function confirmAndCloseWindow()
{
	if(confirm('Are you sure you want to close window?'))
		window.close();
}
function explorer(iself,name1,name2,divID) 
{
	var srcImg = iself.src.substring(0,iself.src.lastIndexOf('/')+1);
	
	if (iself.src.lastIndexOf(name1)==iself.src.length-name1.length) 
	{	
		iself.src = srcImg + name2;
		display_control(divID, true);
	}
	else 
	{
		iself.src = srcImg + name1;
		display_control(divID, false);
	}	
}
function explorer_categories(iself,name1,name2,divID, count) 
{
	var srcImg = iself.src.substring(0,iself.src.lastIndexOf('/')+1);
	
	if (iself.src.lastIndexOf(name1)==iself.src.length-name1.length) 
	{	
		iself.src = srcImg + name2;
		for(var i = 0; i < count; i++)
		{
			display_control(divID + '_' + i, true);
		}
	}
	else 
	{
		iself.src = srcImg + name1;
		for(var i = 0; i < count; i++)
		{
			display_control(divID + '_' + i, false);
		}
	}	
}
function showProgress(show_id, hide_id, selected_id, unselected_id)
{
	display_control(show_id, true);	
	display_control(hide_id, false);	
	
	document.getElementById(selected_id).className = 'selected';
	document.getElementById(selected_id).style.cursor = 'default';
	
	document.getElementById(unselected_id).className = '';
	document.getElementById(unselected_id).style.cursor = '';
}