function ValidateEmail(email)
{		
	RegularExpression = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/
	if(RegularExpression.test(email))
		return true;
	else 
		return false;		
}		

//# TRIM [.INI] ==================================================================================
function Trim( str ) {
	var resultStr = "";
	
	resultStr = TrimLeft(str);
	resultStr = TrimRight(resultStr);
	
	return resultStr;
}

function TrimLeft( str ) {
	var resultStr = "";
	var i = len = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";

	if (str.length == 0) 
		resultStr = "";
	else {	
  		// Loop through string starting at the beginning as long as there
  		// are spaces.
//	  	len = str.length - 1;
		len = str.length;
		
  		while ( (i <= len) && (str.charAt(i) == " " || str.charCodeAt(i)==10 || str.charCodeAt(i)==13) )
			i++;

   	// When the loop is done, we're sitting at the first non-space char,
 		// so return that char plus the remaining chars of the string.
  		resultStr = str.substring(i, len);
  	}

  	return resultStr;
}

function TrimRight( str ) {
	var resultStr = "";
	var i = 0;

	// Return immediately if an invalid value was passed in
	if (str+"" == "undefined" || str == null)	
		return null;

	// Make sure the argument is a string
	str += "";
	
	if (str.length == 0) 
		resultStr = "";
	else {
  		// Loop through string starting at the end as long as there
  		// are spaces.
  		i = str.length - 1;
  		while ( (i >= 0) && (str.charAt(i) == " " || str.charCodeAt(i)==10 || str.charCodeAt(i)==13) )
 			i--;
 			
 		// When the loop is done, we're sitting at the last non-space char,
 		// so return that char plus all previous chars of the string.
  		resultStr = str.substring(0, i + 1);
  	}
  	
  	return resultStr;  	
}
//# TRIM [.FIN] ==================================================================================

//# LISTAS [.INI]  ==========================================================================
function AddItem(selectName_source, selectName_destiny) 
{
	srcList  = document.getElementById(selectName_source);
   	destList  = document.getElementById(selectName_destiny);
     
   	var len = destList.length;
   	for(var i = 0; i < srcList.length; i++) 
   	{
    	if ((srcList.options[i] != null) && (srcList.options[i].selected)) 
	 	{	//Check if this value already exist in the destList or not
			//if not then add it otherwise do not add it.
			var found = false;
			for(var count = 0; count < len; count++) 
			{   
				if (destList.options[count] != null) 
				{ 
					if (srcList.options[i].text == destList.options[count].text) 
			  		{  
						found = true;
			     		break;
      		  		}
   				}
			}
			if (found != true) 
			{   
				destList.options[len] = new Option(srcList.options[i].text, srcList.options[i].value); 
				len++;
        	}
     	}
  	}
}

function AddAllItems(selectName_source, selectName_destiny) 
{
	srcList  = document.getElementById(selectName_source);
	destList  = document.getElementById(selectName_destiny);
     
   	var len = destList.length;
   	for(var i = 0; i < srcList.length; i++) 
   	{
     	//if ((srcList.options[i] != null) && (srcList.options[i].selected)) 
	 	if ((srcList.options[i] != null)) 
	 	{	
			//Check if this value already exist in the destList or not
			//if not then add it otherwise do not add it.
			var found = false;
			for(var count = 0; count < len; count++) 
			{   
				if (destList.options[count] != null) 
				{ 
					if (srcList.options[i].text == destList.options[count].text) 
			  		{ 
						found = true;
			     		break;
      		  		}
   				}
			}
		
			if (found != true) 
			{   
				destList.options[len] = new Option(srcList.options[i].text, srcList.options[i].value); 
				len++;
        	}
     	}
  	}		
}

function RemoveItem(selectName_destiny) 
{
	destList  = document.getElementById(selectName_destiny);
	
    var len = destList.options.length;
    for(var i = (len-1); i >= 0; i--) 
	{
		if ((destList.options[i] != null) && (destList.options[i].selected == true)) 
		{ 
			destList.options[i] = null;
        }
	}
}

function RemoveAllItems(selectName_destiny) 
{
	destList  = document.getElementById(selectName_destiny);
   
	var len = destList.options.length;
    
	for(var i = (len-1); i >= 0; i--) 
	{
    	//if ((destList.options[i] != null) && (destList.options[i].selected == true)) 
		if ((destList.options[i] != null)) 
		{ 
			destList.options[i] = null;
		}
	}
}

function SelectAllItems(form, selectName_destiny)
{	
	var forma = "";
	var destList  = selectName_destiny;
	var selectedItems = "";
	
	//forma = document.getElementById(form);
	forma = form;
	
	if(destList.length > 0)
	{	
		for(i=0; i<destList.length; i++)
		{			
			destList.options[i].selected = true;
			selectedItems += destList.options[i].value+",";
		}
		
		selectedItems = selectedItems.substr(0,selectedItems.length-1);
		
		//forma.hdn_selected_items_list_destiny.value = selectedItems
		
		return true;
	}
	else
		return false;
}
//# LISTAS [.FIN]  ==========================================================================

function OnlyNumbersAllowed(cadena, obj, e)
{
opc = false;
tecla = (document.all) ? e.keyCode : e.which;

	if (cadena == "%d")
		if (tecla > 47 && tecla < 58)
			opc = true;


	
	if (cadena == "%f")
	{
		if(tecla == 8 || tecla == 0)
			opc = true;
		
		if (tecla > 47 && tecla < 58)
			opc = true;
		
		if (obj.value.search("[.*]") == -1 && obj.value.length != 0)
			if (tecla == 46)
				opc = true;
	}

return opc;
}

