function validateSOC(checkthis,txtvalue,required)
{ 
  var Valid=true;
  var msg1 = '';
  if(Valid) Valid = chkString(checkthis,1,0,3)
  if(Valid) Valid = chkString(checkthis,1,4,6)
  if(Valid) Valid = chkString(checkthis,1,7,11)
  if(checkthis.charAt(3) != '-' || checkthis.charAt(6) != '-') Valid = false;
  if(Valid == false && checkthis != '' && required == false) {
		txtvalue.style.backgroundColor ="#ffffcc";
		msg1 = (' -Enter Social Security Number in (xxx-xx-xxxx) format or keep it blank.\n');
		return msg1;
  }
  else if(!Valid && required == true)
  {
		txtvalue.style.backgroundColor ="#ffffcc";
		msg1 = (' -Enter Social Security Number in (xxx-xx-xxxx) format.\n');
  }else msg1 = ''
  return msg1;
}

function validatePhone(checkthis,txtvalue,showstr,required)
{ 
  var Valid=true;
  var msg1 = '';
  if(Valid) Valid = chkString(checkthis,1,0,3)
  if(Valid) Valid = chkString(checkthis,1,4,7)
  if(Valid) Valid = chkString(checkthis,1,8,12)
  if(checkthis.charAt(3) != '-' || checkthis.charAt(7) != '-') Valid = false;
  if(Valid == false && checkthis != '' && required == false) {
		txtvalue.style.backgroundColor ="#ffffcc";
		msg1 = (' -Enter ' + showstr + ' in (xxx-xxx-xxxx) format or keep it blank.\n');
		return msg1;
  }
  else if(!Valid && required == true)
  {
		txtvalue.style.backgroundColor ="#ffffcc";
		msg1 = (' -Enter ' + showstr + ' in (xxx-xxx-xxxx) format.\n');
  }else msg1 = ''
  return msg1;
}
function subValidateAll(required,checkthis,txtvalue,showstr,charType,len,minLen)
{
	var Valid = true;
	var msg1 = '';
	var msg ='';
	if (checkthis == '' && required == true)
	{
		msg1 = ' -'+ showstr + ' is required.\n';
		txtvalue.style.backgroundColor ="#ffffcc";
		return msg1;
	}
	if(checkthis.length > len && (charType != 1 ))
	{
		msg1 = msg1 + ' -Allowed Length of ' + showstr + ' field is ' + len + ' only.\n';
		txtvalue.style.backgroundColor ="#ffffcc";
		return msg1;
	}
	else if(checkthis.value > len && charType == 1)
	{
		msg1 = msg1 + ' -Allowed Length of ' + showstr + ' field is ' + len + ' only.\n';
		txtvalue.style.backgroundColor ="#ffffcc";
		return msg1;
	}
	if(checkthis.length < minLen)
	{
		msg1 = msg1 + ' -Minimum required length for ' + showstr + ' field is ' + minLen + '.\n';
		txtvalue.style.backgroundColor ="#ffffcc";
		return msg1;
	}
	if(charType == 1) // only Numerics allowed.
	{
		if(required)msg = ' -Only Numeric Characters allowed in '+showstr +' field.\n';
		else msg = ' -Only Numeric Characters allowed in '+showstr +' field or keep itblank.\n';
		Valid = chkString(checkthis,1,0,checkthis.length);
	}
	else if(charType == 2) // all alpha allowed
	{
		if(required)msg=' -Only Alphabets characters allowed in '+showstr +' field.\n';
		else msg=' -Only Alphabets characters allowed in '+showstr +' field or keep it blank.\n';
		Valid = chkString(checkthis,2,0,checkthis.length);
	}	
	else if(charType == 3) // only numeric, Alphabets and -_. allowed.
	{	
		if(required)msg = ' -Only Numerics, Alphabets and -_. Characters allowed in '+showstr +' field.\n'
		else msg = ' -Only Numerics, Alphabets and -_. Characters allowed in '+showstr +' field or keep it blank.\n'
		Valid = chkString(checkthis,3,0,checkthis.length);
	}
	else if(charType == 4) 
	{
		if(required) msg = " -Only numeric, Alphabets , Blank Space and -_.,'& allowed in "+showstr +" field.\n"
		else msg = " -Only numeric, Alphabets , Blank Space and -_.,'& allowed in "+showstr +" field or keep it blank.\n"
		Valid = chkString(checkthis,4,0,checkthis.length);
	}
	else if(charType == 5)
	{
  	   if(required) msg=" -Only numeric, Alphabets , Blank Space and ,._@-'\/*:()&$#!+%=:;?{}[] allowed in "+showstr +" field.\n"
	   else msg=" -Only numeric, Alphabets , Blank Space and ,._@-'\/*:()&$#!+%=:;?{}[] allowed in "+showstr +" field or keep it blank.\n"
		Valid = chkString(checkthis,5,0,checkthis.length);
	}
	else if(charType == 6)
	{
		if(required) msg = " -Only Alphabets and Blank Space allowed in "+showstr+" field.\n";
		else msg=" -Only Alphabets and Blank Space allowed in "+showstr+" field or keep it blank.\n";
		Valid = chkString(checkthis,6,0,checkthis.length);
	}
	if (!Valid)
	{
		txtvalue.style.backgroundColor ="#ffffcc";
		msg1 = msg1 + msg;
	}
	return msg1;
}//end function subValidateAll
function chkString(checkthis,charType,start,end)
{
  var Valid = true;
  if(charType == 1) chOK = "0123456789";
  else if(charType == 2) chOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";  
  else if(charType == 3) chOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_."; //for user name, password
  else if(charType == 4) chOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.,'& ";
  else if(charType == 5) chOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ,._@-'*:()&$#!+%=:;?{}[]";
  else if(charType == 6) chOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz. ";

  for (i = start;  i < end;  i++)
  {
	ch = checkthis.charAt(i);
	for (j = 0;  j < chOK.length;  j++)
		if (ch == chOK.charAt(j))
			break;
		if (j == chOK.length)
		{
			Valid = false;
			break;
		}
  }
  return Valid;
}
function validateWeight(checkthis,txtvalue,showstr,min,max,required)
{
  var Valid = true;
  var msg1;
  if(required || checkthis != '')
  if(checkthis > max || checkthis < min) Valid = false;
  if (!Valid)
  {
		txtvalue.style.backgroundColor ="#ffffcc";
		if(required) msg1 = ' -Enter valid ' + showstr + '.\n';
		else msg1 = ' -Enter valid ' + showstr + ' or keep it blank.\n';
  }else msg1 = ''
  return msg1; 
}

function validateEmail(checkthis,txtvalue,showStr,required)
{
 var msg = '';
 var dotat, dot, atat, at;
 var flag_dot = false;
 var flag_at = false;
 if(checkthis == "" && required == true){
 	msg = " -" + showStr + " is required.\n";
	txtvalue.style.backgroundColor ="#ffffcc";
	return msg;
 }
 else if(checkthis.length < 7){
	 txtvalue.style.backgroundColor ="#ffffcc";
	 msg =" -Enter Valid " + showStr + '.\n';
	 return msg;
 }
 else{
	for(i = 0;i < checkthis.length; i++){
		if(checkthis.substr(i,1) == "."){
			dotat = i;
			dot += 1;
			flag_dot = true;
		}
		else if(checkthis.substr(i,1) == "@"){
			atat = i;
			at += 1;
			flag_at = true;
		}
	}
	if((dot < 1 && at != 1) || dotat - atat == 1  || atat - dotat == 1){
		txtvalue.style.backgroundColor ="#ffffcc";
		msg = " -Enter Valid " + showStr + '.\n';
	}
	var after_dot_str = checkthis.substring(dotat,checkthis.length);
	if(after_dot_str.length < 3){
		txtvalue.style.backgroundColor ="#ffffcc";
		msg = " -Enter Valid " + showStr + '.\n';
	}
	if(Valid = chkString(after_dot_str,2,1,3) == false){
		txtvalue.style.backgroundColor ="#ffffcc";
		msg = " -Enter Valid " + showStr + '.\n';
	}
	if(flag_dot == false|| flag_at ==false){
		txtvalue.style.backgroundColor ="#ffffcc";
		msg = " -Enter Valid " + showStr + '.\n';
	}
 }
 return(msg);	
}