<!--
//check valid url

function isValidURL(url)
{	var j = new RegExp(); 
	j.compile("^[A-Za-z]+://[A-Za-z0-9-:]+\.[A-Za-z0-9]+"); 
	if (!j.test(url)) 
	{	alert("Enter a valid URL."); 
		return false; 
	} 
	return true;
}
//check for us phone no like (233)456-7890
function isUSPhoneNumber(str){
  //var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
  var re = /^\([2-9]\d{2}[\)]\d{3}[\-]\d{4}$/
  return re.test(str);
}

function isValidZipcode(str)
{
	var us1 =  /^[0-9]{5}\-[0-9]{4}$/ 
	var us2 =  /^[0-9]{5}$/
	var can =  /^[a-zA-Z][0-9][a-zA-Z]\s?[0-9][a-zA-Z][0-9]$/ 
	var uk =  /^[A-Za-z]{1,2}[0-9A-Za-z]{1,2}[ ]?[0-9]{0,1}[A-Za-z]{2}$/
	if(us1.test(str) || can.test(str) || uk.test(str) || us2.test(str))
	{
		return true;
	}
	else
	{
		return false;
	}
}


function isFirstName(str)
{
	var frst =  /^[a-zA-Z]+[\']*[a-zA-Z]+$/
	if(frst.test(str))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function isGenericPhone(str)
{
	var mob1 =  /[\(][\+][\d]{2}[\)][\d]{10}/
	var mob2 =  /^[\d]{10}$/
	var usphone =  /[\(][\d]{3}[\)][\ ][\d]{3}[\-][\d]{4}/
	var usphone2 = /^\([2-9]\d{2}[\)]\d{3}[\-]\d{4}$/
	var usphone3 = /^[1-9]\d{2}\-\s?\d{3}\-\d{4}$/
		
	if(mob1.test(str) || mob2.test(str) || usphone.test(str) || usphone2.test(str) || usphone3.test(str))
	{
		return true;
	}
	else
	{
		return false;
	}
}

//check alphanumric value
function IsAlphaNumeric (strData)
{
	var nStrLength;
	nStrLength =  strData.length;
	for(i=0; i<nStrLength; i++)
	{
		if( ! ( ((strData.charAt(i) >= '0') && (strData.charAt(i) <= '9')) ||
				((strData.charAt(i) >= 'a') && (strData.charAt(i) <= 'z')) ||
				((strData.charAt(i) >= 'A') && (strData.charAt(i) <= 'Z')) ) )
		{
			return false;
		}
	}
	return true;
}

//check numric value
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;
   
   }
   
function IsInteger (str)
{
	for(i=0; i<str.length; i++)
	{
		if( ! ((str.charAt(i) >= '0') && (str.charAt(i) <= '9')) )
		{
			return false;
		}
	}
	return true;
}

//check phone no
function IsPhoneNo(strValue)
{
		var strLastDigits, strFirst3, strMid3, strHyphen1, strHyphen2				
		if((strValue.length != 12) && (strValue.length != 10))
		{
			return false;
		}
		
		strFirst3 = strValue.substring(0,3)
		if (!IsInteger(strFirst3))
		{
			return false;
		}
		
		if(strValue.length == 12) 
		{
			strHyphen1 = strValue.substring(3,4)		
			if ( strHyphen1 != "-")
			{
				return false;
			}
			strHyphen2 = strValue.substring(7,8)
			if ( strHyphen2 != "-")
			{
				return false;
			}
			strMid3 = strValue.substring(4,7)
			strLastDigits = strValue.substring(8,12)
		}
		else  //if Length is 10
		{
			strMid3 = strValue.substring(3,6)
			strLastDigits = strValue.substring(6,10)		
		}
		
		if (!IsInteger(strMid3))
		{
			return false;
		}
		
		if ((!IsInteger(strLastDigits)) || (strLastDigits.length != 4))
		{
			return false;
		}
		
		return true;
}
// check valid email address
function IsEmail(str)
{
	var strAtFound, strDotFound, bValid;
	var intIndex
	intIndex = 0;
	for(j=0; j<str.length; j++)
	{
		if( (str.charAt(j) == '.') || (str.charAt(j) == '@'))
		{
			if (str.charAt(j) == '@' &&	strAtFound == "Y" )		 
			{
				bValid = false;
				break;
			}
			if (str.charAt(j) == '.' &&	strAtFound == "Y" )
			{
				if( intIndex != 2) //To ensure that atleast one character exists after '.'
				{
					if(! ((j + 1) < str.length))   
						return false;
					intIndex++;
				}
				
				strDotFound = "Y";
			}
			else
				if (str.charAt(j) == '@')
				{
					if(! j > 0 ) // To ensure that atleast one character exists Before '@'
						return false;
					strAtFound = "Y";
				}				
			if( intIndex != 2) 
			{
				if( Checkprecededfollowed(str,j) == false)
				{
					bValid = false;
					break;
				}
				else
				{
					bValid = true;
				}	
			}
			else //once checking is over for @ and two dots exit 
				return true;
			
		}
	}
	if (strDotFound == "Y" && strAtFound == "Y" && bValid == true)
		return true;
	else
		return false;
}
function Checkprecededfollowed(str,intPos)
{
	
	if ( IsAlphaNumeric(str.charAt(intPos - 1)) && IsAlphaNumeric(str.charAt(intPos + 1)))
	{
		return true;				
	}
	else
	{
		return false;
	}	
}

//check valid date
function IsDateMMYYYY( strDate )
{
	var theLength = strDate.length
	if ( theLength < 6 || theLength > 7 )
		return false ;
	
	if ( theLength == 7 )
	{
		var theYear = strDate.substring(3,7) ;
		var theMonth = strDate.substring(0,2) ;
		if ( theMonth > 12 || theMonth < 1) 
			return false ;
		if ( theYear < 1753) 
			return false ;

		if ( strDate.charAt(2) != '/' ) 
			return false ;
		
	}
	if ( theLength == 6 )
	{
		var theYear = strDate.substring(3,6) ;
		var theMonth = strDate.substring(0,1) ;
		if ( theYear < 1753) 
			return false ;
		if ( theMonth > 12 || theMonth < 1) 
				return false ;
		
		if ( strDate.charAt(1) != '/' ) 
				return false ;
	}
	for( i = 0 ; i < theLength ; i++ )
	{
		if (!(( strDate.charAt(i) >= '0' && strDate.charAt(i) <= '9')||(strDate.charAt(i) == '/')))
		{
				return false ;
		}
	}
			
return true ;
}

//check empty value
function IsEmpty(checkString)
{
    count = 0;         // COUNTER FOR LOOPING THROUGH STRING
    var first_char = 0;
    if (checkString != null)
    {
		for (i = 0; i < checkString.length; i++) 
		{
		    ch = checkString.substring(i, i+1);
		    if ((ch == " " ) && (first_char == 0))
		    {
		        continue;
		    }
		    else
		    {
				first_char = 1;
				break;
		    }
		}
    }
	if (first_char == 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}

// trim space from value
function TrimSpaces(checkString)
{
    newString = "";    // REVISED/CORRECTED STRING

    for (i = 0; i < checkString.length; i++) 
    {
        ch = checkString.substring(i, i+1);
        if (ch != " " ) 
        {
            newString += ch;
        }
    }

        return newString;
}

//confirm box for delete
function ConfirmDelete()
{
	if (confirm ("Do you want to delete")) 
		return true;
	else
		return false;
}

//parse int values
function IsQuotePresent(str)
{
	for(i=0; i<str.length; i++)
	{
		if (str.charAt(i) == '"' )
		{
			return true;
		}
	}
	
	return false;
	
}

//check the decimal values
function IsDecimal(str)
{
var dotcount = 0;
	for(i=0; i<str.length; i++)
	{
	
		if(  ((str.charAt(i) >= '0') && (str.charAt(i) <= '9')) ||
			  (str.charAt(i) == '.'))
		{
			if (str.charAt(i) == '.') 
			{
				dotcount = dotcount + 1;
			}
			if (dotcount > 1)
				return false;
		}
		else 
			return false;
	}
	
	return true;
}

//check new phone no.
function NewPhone(s)   
{
	for (var i = 0; i < s.length; i++)
	{
	if ((s.charAt(i) == 0) || (s.charAt(i) == 1) || 
		(s.charAt(i) == 2) || (s.charAt(i) == 3) ||
		(s.charAt(i) == 4) || (s.charAt(i) == 5) ||
		(s.charAt(i) == 6) || (s.charAt(i) == 7) ||
		(s.charAt(i) == 8) ||(s.charAt(i) == 9)||
		(s.charCodeAt(i) == 43)||(s.charCodeAt(i) == 45))
		{
			//alert ("inloop>> " + i + "   charat>> " + s.charAt(i));
			continue;
		}
	else 
		{

			//alert ("returning false for fnIsInteger");
			return false;
		}
	}
	//alert ("returning true for fnIsInteger");
	return true;
}

function isPostCode(entry)
{	
	// CANADIAN CODES ONLY
	strlen=entry.length; if(strlen!=6) {return false;}
	entry=entry.toUpperCase();    // in case of lowercase characters
	// Check for legal characters in string - note index starts at zero
	if('ABCEGHJKLMNPRSTVXY'.indexOf(entry.charAt(0))<0)
		{
			alert("no1");
			return false;
		}
	if('0123456789'.indexOf(entry.charAt(1))<0)
		{
			alert("no2");
			return false;
		}
	if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2))<0)
		{
			alert("no3");
			return false;
		}
	if('0123456789'.indexOf(entry.charAt(3))<0)
		{
			alert("no4");
			return false;
		}
	if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(4))<0)
		{
			alert("no5");
			return false;
		}
	if('0123456789'.indexOf(entry.charAt(5))<0)
		{
			alert("no6");
			return false;
		}
	
	return true;
}

//-->