function RequiredField(id)
{
      obj = document.getElementById(id);
	  
      spErr = document.getElementById("spError_" + id);
      
      if(obj != null)
      {
            if(obj.value == "")
            {
                  if(spErr == null)
                        obj.parentNode.innerHTML += "&nbsp;<span id=\"spError_" + id + "\" style=\"color:Red\">Required field</span>";
                    else
                        spErr.style.display = "inline";
                        
                  return false;
            }
            else
            {
              if(spErr != null)
                  spErr.style.display = "none";
                  
              return true;
            }
      }
}

function RequiredSameValue(id1, id2)
{
      obj1 = document.getElementById(id1);
      obj2 = document.getElementById(id2);
      
      spErr1 = document.getElementById("spError_" + id1 + "_" + id2);
      
      if(obj1 != null && obj2 != null)
      {
            if(obj1.value != obj2.value)
            {
                  if(spErr1 == null)
                        obj1.parentNode.innerHTML += "&nbsp;<span id=\"spError_" + id1 + "_" + id2 + "\" style=\"color:Red\">Passwords must match</span>";
                    else
                        spErr1.style.display = "inline";
                  
                  return false;
            }
            else
            {
              if(spErr1 != null)
                  spErr1.style.display = "none";
                  
              return true;
            }
      }
}

function RequiredCardNumber(id)
{
      obj = document.getElementById(id);
      spErr = document.getElementById("spError_" + id);
      if(obj != null)
      {
            if(!isLengthBetween(obj.value, 16, 16) || !IsNumeric(obj.value) )
            {
                  if(spErr == null)
                        obj.parentNode.innerHTML += "&nbsp;<span id=\"spError_" + id + "\" style=\"color:Red\">16 numbers only - no spaces</span>";
                    else
                        spErr.style.display = "inline";
                  obj.focus();
                  return false;
            }
            else
            {
              if(spErr != null)
                  spErr.style.display = "none";
              return true;
            }
      }
	  return false;
}

function RequiredCardNo(id)
{
      obj = document.getElementById(id);
      spErr = document.getElementById("spError_" + id);
      if(obj != null)
      {
            if(!isLengthBetween(obj.value, 3, 4) || !IsNumeric(obj.value) )
            {
                  if(spErr == null)
                        obj.parentNode.innerHTML += "&nbsp;<span id=\"spError_" + id + "\" style=\"color:Red\">3 or 4 numbers only - no spaces</span>";
                    else
                        spErr.style.display = "inline";
                  obj.focus();
                  return false;
            }
            else
            {
              if(spErr != null)
                  spErr.style.display = "none";
              return true;
            }
      }
	  return false;
}

function RequiredValidData(id1,id2,id3,id4)
{
	var  obj1, obj2, obj3, obj4;
      obj1 = document.getElementById(id1);
      obj2 = document.getElementById(id2);
      obj3 = document.getElementById(id3);
      obj4 = document.getElementById(id4);
      spErr = document.getElementById("spError_" + id1);
      if((obj1 != null) && (obj2 != null))
      {
			if(obj2.value != "" && obj4.value != "")
			{
	            if(parseInt(obj2.value) == parseInt(obj4.value))
	            {
					if(obj1.value <= obj3.value)
					{
	                  if(spErr == null)
	                        obj1.parentNode.innerHTML += "&nbsp;<span id=\"spError_" + id1 + "\" style=\"color:Red\">Required valid data.</span>";
	                    else
	                        spErr.style.display = "inline";
	                  obj1.focus();
	                  return false;
					}
					else
					{
		              return true;
					}
	            }
	            else
	            {
	              if(spErr != null)
	                  spErr.style.display = "none";
	              return true;
	            }
			}
			else
			{
				RequiredField(id1);
				RequiredField(id2);
			}
      }
}

function isEmail(str){
  if(isEmpty(str)) return false;
  var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
  return re.test(str);
}

function RequiredEmail(id)
{
      eobj = document.getElementById(id);
      spErr2 = document.getElementById("spEmailError_" + id);
      
      if(eobj != null)
      {
            if(eobj.value.indexOf(".") < 0 ||  eobj.value.indexOf("@") < 0)
            {
                  if(spErr2 == null)
                        eobj.parentNode.innerHTML += "&nbsp;<span id=\"spEmailError_" + id + "\" style=\"color:Red\">Enter a valid email</span>";
                    else
                        spErr2.style.display = "inline";
                        
                  eobj.focus();
                        
                  return false;
            }
            else
            {
              if(spErr2 != null)
                  spErr2.style.display = "none";
                  
              return true;
            }
      }
}


function isLengthBetween(str, min, max)
{
  return (str.length >= min)&&(str.length <= max);
}

function IsNumeric(strString)
   //  check for valid numeric strings	
{
   var strValidChars = "0123456789-.";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function SetSelfFormAction(frm)
{
      var loc = new String(document.location.href);
      frm.action = loc;
}
