	function GetAttributeValue(sAttribute, sCollection)
	{
		var itemAttributes= sCollection.split(";");
		var result="";
		
		for ( i=0; i<itemAttributes.length;i++ )
		{
			var colonIndex=itemAttributes[i].indexOf(":");
			
			if ( colonIndex <=0 ) continue;
			
			var attribute = itemAttributes[i].substring(0,colonIndex);
			var value = itemAttributes[i].substring(colonIndex+1,itemAttributes[i].length);
			
			//alert("Attribute:" + attribute + ";Value:" + value);
			
			if ( sAttribute.toLowerCase() == attribute.toLowerCase() )
			{
				result= value;
				break;
			}
		
			 
		}
		
		
		return result;
		
	
	}
	function validateControl(ctlInfo)
	{
		var msg="";
		
		
		if ( document.getElementById(GetAttributeValue("Id",ctlInfo)) == null )
		{
			return "";
		}
		
		
		var ctl = document.getElementById(GetAttributeValue("Id",ctlInfo))
		
		var ctlType=GetAttributeValue("Type",ctlInfo).toLowerCase();
		var ctlLabel=GetAttributeValue("Label",ctlInfo);
		
		if (  GetAttributeValue("Required",ctlInfo).toLowerCase() == "true" )
		{
			
			// alert(ctl.name +":" +ctl.type);
			
			
			if ( ( ctl.type =="text" || ctl.type =="password" || ctl.type =="textarea" || ctl.type =="file" || ctl.type =="hidden" )  &&  trim(ctl.value) =="" )
			{
				
				msg+="- Please enter value in '" + ctlLabel + "'\n";
			}
			else if ( ctl.type=="select-one" )
			{
				var startIndex = GetAttributeValue("StartIndex",ctlInfo);
				
				if ( ! isNumeric(startIndex) ) 
				{
					startIndex = -1;
				}
				
				if ( ctl.selectedIndex < startIndex  )
				{
					msg+="- Please select value for '" + ctlLabel + "'\n";
				}
			}
		}
		
		if ( ctlType =="email" &&  trim(ctl.value) !="" && ! isEmail(ctl.value)   )
		{
			msg+="- Please enter a valid email format:'name@domain.com' in '" + ctlLabel + "'\n";
		}
		else if ( ctlType =="emaillist" &&  trim(ctl.value) !="" && ! valdiateEmailsList(ctl.value)   )
		{
			msg+="- Please enter a valid email format:'name@domain.com' in '" + ctlLabel + "'\n";
		}
		else if ( ctlType =="number" && ! isNumeric(ctl.value)  )
		{
			msg+="- Please enter a valid numeric value in '" + ctlLabel + "'\n";
		}
		
		return msg;
		
	}
	
	function  getFormValidationMessage(sCollection) 
	{
		var items= sCollection.split("|");
		var msg = "";
		var count =items.length;
		
		
		for ( index=0; index<count;index++ )
		{	
			msg+=validateControl(items[index]);
		}
		
		if ( msg!="" )
		{
			msg = "Please correct the following error(s):\n"+msg
		}
		
		return msg;
	}
	
	function validateFormEntries(sCollection) 
	{
		
		var msg = getFormValidationMessage(sCollection);
		
		if ( msg!="" )
		{
			alert(msg);
			return false;
		}
		
		return true;
	}

function valdiateEmailsList(emailsList) 
	{
			var emails = emailsList.split(";");
			var i=0;
			var validate = true;
			var emailCount =0;
			var invalidEmail = false;
			for ( i=0;i<emails.length;i++ )
			{
			  if ( 	trim(emails[i]) == "" ) continue;
			  
			  if (	!IsValidEmail(emails[i]) )
			  {
				invalidEmail = true;
				break;
			  }
			  emailCount++;
			}
			
			if ( invalidEmail )
			{
				validate = false;
			}
			else if ( emailCount == 0 ) 
			{
				validate = false;
			}
			
			return validate;
	}
	
function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}	

function IsValidEmail(Email)
	{
		var regex = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/ ;//  /^[\w\.-]+@[\w\.-]+\.[a-zA-Z]{2,3}$/
		//alert(Email + "\n" + regex.test(Email));
		if (!regex.test(Email)) 
			return (false);
		else
			return (true);   

	}

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

 // whitespace characters
      var whitespace = " \t\n\r";

      /****************************************************************/

      // Check whether string s is empty.
      function isEmpty(s)
      { return ((s == null) || (s.length == 0)) }

      /****************************************************************/

      function isWhitespace (s)
      {
           var i;

           // Is s empty?
           if (isEmpty(s)) return true;

           // Search through string's characters one by one
           // until we find a non-whitespace character.
           // When we do, return false; if we don't, return true.

           for (i = 0; i < s.length; i++)
           {
                // Check that current character isn't whitespace.
                var c = s.charAt(i);

                if (whitespace.indexOf(c) == -1) return false;
           }

           // All characters are whitespace.
           return true;
      }

      /****************************************************************/

      function ForceEntry(val, str) {
           var strInput = new String(val.value);

           if (isWhitespace(strInput)) {
                alert(str);
                return false;
           } else
                return true;

      }
      
      function promptDelete(form)
		{
			return confirm("You are about to delete the selected record(s) permanently. \nProceed?");
		}
