/*********************************************************************/
//********** Common Utility Functions in JavaScript *****************//
/*******************trim************************************************/
function trim(str) {
 if (str == null)
  	return "";
 if (str.length <1)
    return "";
 var i =0;
 while (str.charAt(i) == ' ')
        i++;
 str = str.substr(i);
 i = str.length;
 while (str.charAt(--i) == ' ')
 str = str.substr(0, (str.length  + (i - str.length)));
 	return str;
}
//****************************isValidMessage******************************************

function isValidMessage(str){
 str = trim(str);
 if (str.length < 3)
    return false;
    
  for (i=0; i < str.length; i++)
  {
    if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
      continue;
    if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
      continue;
       if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
      if (str.charAt(i) ==' ')
      continue;
      if (str.charAt(i) ==',')
      continue;
      if (str.charAt(i) =='.')
      continue;
      if (str.charAt(i) =='-')
      continue;
      if (str.charAt(i) =='\'')
      continue;
      if (str.charAt(i) =='?')
      continue;
      if (str.charAt(i) =='!')
      continue;
      if (str.charAt(i) =='(')
      continue;
      if (str.charAt(i) ==')')
      continue;
      if (str.charAt(i) =='\"')
      continue;
      if (str.charAt(i) =='\t')
      continue;
      if (str.charAt(i) =='\n')
      continue;
      if (str.charAt(i) =='\r')
      continue;
      if (str.charAt(i) =='[')
      continue;
      if (str.charAt(i) ==']')
      continue;
      if (str.charAt(i) =='\\')
      continue;
      if (str.charAt(i) =='/')
      continue;
      if (str.charAt(i) =='<')
      continue;
      if (str.charAt(i) =='>')
      continue;
       if (str.charAt(i) =='#')
      continue;
        if (str.charAt(i) =='&')
      continue;
         if (str.charAt(i) =='@')
      continue;
      if (str.charAt(i) =='$')
      continue;
      if (str.charAt(i) =='%')
      continue;     
    return false;
  }
 
 
   
  return true;

}
//****************************isValidName******************************************
function isValidName(str){
 str = trim(str);
 if (str.length < 1)
    return false;
    
  for (i=0; i < str.length; i++)
  {
    if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
      continue;
    if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
      continue;
    if (str.charAt(i) == ' ')
      continue;
    if (str.charAt(i) == '.')
      continue;
    return false;
  }
 
  if (str.indexOf('.') != str.lastIndexOf('.'))
    return false;
  if ((str.charAt(0) == '.') || (str.charAt(str.length-1) == '.'))
    return false;
   
  return true;

}
//****************************isValidTelNum******************************************
function isValidTelNum(str){
  if (str == null)
     return false;
  str = trim(str);
    
  if (str.length < 6 )
     return false;
     
  for (i=0; i < str.length; i++){
    if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
    if (str.charAt(i) == '-')
      continue;
    if (str.charAt(i) == ' ')
      continue;
   if (str.charAt(i) == ')')
    continue;
   if (str.charAt(i) == '(')
    continue;
      if (str.charAt(i) == ',')
      continue;
    return false;
  }
    
  return true;

}
//****************************isValidTelStd******************************************
function isValidStd(str){
  if (str == null)
     return false;
  str = trim(str);
    
  if (str.length < 3)
     return false;
     
  for (i=0; i < str.length; i++){
    if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
    if (str.charAt(i) == '-')
      continue;
    if (str.charAt(i) == ' ')
      continue;
      if (str.charAt(i) == ',')
      continue;
    return false;
  }
    
  return true;

}
/*********************************isValidPhone***********************************************/
function isValidPhone(str){
  if (str == null)
     return false;
 str = trim(str);
    
  if (str.length < 5 || str.length > 30)
     return false;
    
  for (i=0; i < str.length; i++){
    if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
       if (str.charAt(i) == ',')
      continue;
      if (str.charAt(i) == '-')
      continue;
      if (str.charAt(i) == '(')
      continue;
      if (str.charAt(i) == ')')
      continue;
      if (str.charAt(i) == '+')
      continue;
    return false;
  }
    
  return true;

}
/*********************************isValidMobile***********************************************/
function isValidMobile(str){
  if (str == null)
     return false;
  str = trim(str);
    
  if (str.length < 10 || str.length > 12)
     return false;
    
  for (i=0; i < str.length; i++){
    if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
    return false;
  }
    
  return true;

}
//********************************isInteger**************************************
function isInteger(str){
  if (!isANumber(str))
   return false;
  if (str.indexOf('.') != -1)
    return false;
   return true;

}
/*****************************isValidZip*****************************************/
function isValidZip(str){
  str = trim(str);

  if (str.length < 6)
   return false;
  for (i=0; i < str.length; i++){
    if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
    return false;
  }
   
  return true;

}
/*******************************isImage**************************************************/
function isImage(s)
				{
					if(!Trim(s)=='')
					{
						var regexp = /^.*(\.(gif|jpg|bmp))$/
						return regexp.test(s);
					}
					else
					{
						return true;
					}
				}
/********************************8*****************************************************/

function isValidAddress(str)
{
	if(str==null) return false;
	if(str.length<3) return false;
	if(str.indexOf('@') != -1) return false;
	if(str.indexOf('<')!= -1) return false;
	if(str.indexOf('>')!=-1) return false;
	if(str.indexOf('%')!=-1) return false;
	if(str.indexOf('^')!=-1) return false;
	if(str.indexOf('*')!=-1) return false;
	if(str.indexOf('\"')!=-1) return false;
	if(str.indexOf('{')!=-1) return false;
	if(str.indexOf('}')!=-1) return false;
	return true;
}

function isValidSearch(str)
{
	if(str==null) return false;
	if(str.length<2) return false;
	if(str.indexOf('<')!= -1) return false;
	if(str.indexOf('>')!=-1) return false;
	if(str.indexOf('%')!=-1) return false;
	if(str.indexOf('^')!=-1) return false;
	if(str.indexOf('*')!=-1) return false;
	if(str.indexOf('\"')!=-1) return false;
	if(str.indexOf('{')!=-1) return false;
	if(str.indexOf('}')!=-1) return false;
	return true;
}
//****************************isValidEMail****************************************//
function isValidEmail(str) {
 if (str == null)
  return false;
  str = trim(str);
 if (str.length <8)    return false;   
 if (str.indexOf('@') == -1)    return false;
 if (str.indexOf('@') == 0)    return false;
 if (str.indexOf('@') == (str.length-1))    return false;
 if (str.indexOf("@@") != -1)    return false;
 if (str.indexOf('@') != str.lastIndexOf('@'))    return false;
 if (str.indexOf('.@') != -1)    return false;
 if (str.indexOf('@.') != -1)    return false;
 if (str.indexOf(' ') != -1)    return false;
 if (str.indexOf('.') == -1)    return false;
 if (str.indexOf('.') == 0)    return false;
 if (str.indexOf('.') == (str.length-1))    return false;
 if (str.indexOf('..') != -1)    return false;
 if (str.indexOf('<') != -1)    return false;
 if (str.indexOf('>') != -1)    return false;
 if (str.indexOf('=') != -1)    return false;
 if (str.indexOf('~') != -1)    return false;
 if (str.indexOf('^') != -1)    return false;
 if (str.indexOf('%') != -1)    return false;
 if (str.indexOf('+') != -1)    return false;
 if (str.indexOf('$') != -1)    return false;
 if (str.indexOf('#') != -1)    return false;
 if (str.indexOf('!') != -1)    return false;
 if (str.indexOf('(') != -1)    return false;
 if (str.indexOf(')') != -1)    return false;
 if (str.indexOf('\\') != -1)    return false;
 if (str.indexOf('/') != -1)    return false;
 if (str.indexOf('\"') != -1)    return false;
 if (str.indexOf('\'') != -1)    return false;
 if (str.indexOf('?') != -1)    return false;
 if (str.indexOf(';') != -1)    return false;
 if (str.indexOf(',') != -1)    return false;
 if (str.indexOf('\t') != -1)    return false;
 if (str.indexOf('*') != -1)    return false;
 if (str.indexOf('|') != -1)    return false;

 return true;
 
}//end of isValidEMail()
function isValidPwd(str)
{

 if (str == null)
  return false;
  str = trim(str);
 if (str.indexOf('<') != -1)    return false;
 if (str.indexOf('>') != -1)    return false;
 if (str.indexOf('\\') != -1)    return false;
 if (str.indexOf('/') != -1)    return false;
 if (str.indexOf('\"') != -1)    return false;
 if (str.indexOf('\'') != -1)    return false;
 if (str.indexOf(' ') != -1)    return false;
 if (str.indexOf(';') != -1)    return false;
 if (str.indexOf('&') != -1)    return false;
 
 return true;
 
}
///***************************************************************************************//
function isValidStringMul(str)
{
 str = trim(str);
 if (str.length < 4)
    return false;
    
  for (i=0; i < str.length; i++)
  {
    if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
      continue;
    if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
      continue;
      if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
      if (str.charAt(i) ==' ')
      continue;      
    return false;
  }
 
  if (str.indexOf('.') != str.lastIndexOf('.'))
    return false;
  if ((str.charAt(0) == '.') || (str.charAt(str.length-1) == '.'))
    return false;
  
  return true;
  }
///***************************************************************************************//


//***************************isValidDate**************************8
Months = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];

// Non-Leap year Month days..
DOMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
lDOMonth = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function get_month(monthNo) {
	return Months[monthNo];
}
//****************************************************************8
function getDaysOfMonth(monthNo, p_year) {
	if ((p_year % 4) == 0) {
		if ((p_year % 100) == 0 && (p_year % 400) != 0)
			return DOMonth[monthNo];

		return lDOMonth[monthNo];
	} 
	else
		return DOMonth[monthNo];
}
//************************************************************************8
function isValidDate(dd,mm,yyyy)
{
  if (mm < 0 || mm > 12)
     return false;
  if (dd < 0 || dd > 31)
     return false;
  if (getDaysOfMonth(mm,yyyy) < dd) 
     return false;
  return true; 
}
/*****************************isValidZip*****************************************/
function isValidPwdLength(str){
  str = trim(str);

  if ((str.length < 6) || (str.length>15))
   return false;
	
	for (i=0; i < str.length; i++){
  
      if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
      continue;
     if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
      continue;
      if ((str.charAt(i) >='0') && (str.charAt(i) <= '9'))
      continue;
      
    return false;
  }
   
  return true;

}
/*************************************************************************************

    /***** CUSTOMIZE THESE VARIABLES *****/
      // width to resize large images to
    var maxWidth=100;
      // height to resize large images to
    var maxHeight=100;
      // valid file types
    //var fileTypes=["bmp","gif","png","jpg","jpeg"];
    var fileTypes=["doc","txt","pdf"];
      // the id of the preview image tag
    var outImage="previewField";
      // what to display when the image is not valid
    var defaultPic="spacer.gif";
    /***** DO NOT EDIT BELOW *****/

function preview(str)
    {  
     // var fileTypes=["bmp","gif","png","jpg","jpeg"];
    var fileTypes=["doc","txt","pdf"];
      var source=str.value;
      var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
      flag=false;
      var len=fileTypes.length;
      for (var i=0; i<len; i++)
      { 
         if (fileTypes[i]==ext) 
         {
             flag=true;             
         }         
      }
   if(flag==false)
   {return false;}
   return true;
   }
/********************************VALIDATE URL***************************************/

function validateURL1(urlStr)
{
if (urlStr.indexOf(" ")!=-1)
{
//alert("Spaces are not allowed in a URL");
return false;
}
if((urlStr=="") || (urlStr==null))
{
return false;
}
urlStr=urlStr.toLowerCase();
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var atom=validChars + '+';var urlPat=/^http:\/\/(\w*)\.([\-\+a-z0-9]*)\.(\w*)/;
var matchArray=urlStr.match(urlPat);
if (matchArray==null){
//alert("The URL seems incorrect \ncheck it begins with http://\n and it has 2 .'s");
return false;
}
var user=matchArray[2];var domain=matchArray[3];
for (i=0; i<user.length; i++) 
{
if (user.charCodeAt(i)>127) 
{
//alert("This domain contains invalid characters.");
return false;
}
}
for (i=0; i<domain.length; i++) 
{
if (domain.charCodeAt(i)>127) {
//alert("This domain name contains invalid characters.");
return false;
}
}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			//alert("The domain name does not seem to be valid.");
			return false;
		}
	}
	if (domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		//alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	    return true;
	}

      /*function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }*/

function isValidUrl(str)
{
     var theurl=str;
    // var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
     var tomatch= /http:\/\/(\w*)\.([\-\+a-z0-9]*)\.(\w*)/
     if (tomatch.test(theurl))
     {
     //window.alert("URL OK.");
     return true;
     }
     else
     {
     //window.alert("URL invalid. Try again.");
     return false; 
    }
}
//*============================================================================*/
function isValidString(str)
{
 str = trim(str);
 if (str.length < 4)
    return false;
    
  for (i=0; i < str.length; i++)
  {
    if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
      continue;
    if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
      continue;
       if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
      if (str.charAt(i) ==' ')
      continue;
      if (str.charAt(i) ==',')
      continue;
      if (str.charAt(i) =='.')
      continue;
      if (str.charAt(i) =='-')
      continue;
      if (str.charAt(i) =='\'')
      continue;
      if (str.charAt(i) =='(')
      continue;
      if (str.charAt(i) ==')')
      continue;
      if (str.charAt(i) =='\"')
      continue;
      if (str.charAt(i) =='\t')
      continue;
      if (str.charAt(i) =='\n')
      continue;
      if (str.charAt(i) =='\r')
      continue;
      if (str.charAt(i) =='/')
      continue;
      if (str.charAt(i) =='<')
      continue;
      if (str.charAt(i) =='>')
      continue;
       if (str.charAt(i) ==';')
      continue;
    return false;
  }
 
  
  return true;
  }
  //////////////////////////////////////////////////////////////
  function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
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 isValidMessagee(str)
{
 str = trim(str);
// if (str.length < 4)
//    return false;
    
  for (i=0; i < str.length; i++)
  {
    if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
      continue;
    if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
      continue;
       if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
      if (str.charAt(i) ==' ')
      continue;
      if (str.charAt(i) ==',')
      continue;
      if (str.charAt(i) =='.')
      continue;
      if (str.charAt(i) =='-')
      continue;
      if (str.charAt(i) =='\'')
      continue;
      if (str.charAt(i) =='?')
      continue;
      if (str.charAt(i) =='!')
      continue;
      if (str.charAt(i) =='(')
      continue;
      if (str.charAt(i) ==')')
      continue;
      if (str.charAt(i) =='\"')
      continue;
      if (str.charAt(i) =='\t')
      continue;
      if (str.charAt(i) =='\n')
      continue;
      if (str.charAt(i) =='\r')
      continue;
      if (str.charAt(i) =='[')
      continue;
      if (str.charAt(i) ==']')
      continue;
      if (str.charAt(i) =='\\')
      continue;
      if (str.charAt(i) =='/')
      continue;
      if (str.charAt(i) =='<')
      return false;
      if (str.charAt(i) =='>')
      return false;
            
    return false;
  }
 
  
  return true;
  }
  
 function isValidMessagee1(str)
   {
   
      str = trim(str);
//      if (str == null)
//      alert("Please enter the keyword");
//        return false;
      if (str.length < 2)
         return false;
     
        for (i=0; i < str.length; i++)
      {
    if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
      continue;
    if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
      continue;
       if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
      if (str.charAt(i) ==' ')
      continue;
      if (str.charAt(i) =='?')
      continue;
       if (str.charAt(i) =='\r')
      continue;
       
     
    return false;
  }
 
  
  return true;
  }
  
  function isValidMessagee2(str)
   {
      str = trim(str);
      if (str.length < 4)
    return false;
     
        for (i=0; i < str.length; i++)
      {
    if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
      continue;
    if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
      continue;
       if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
       if (str.charAt(i) =='\r')
      continue;
      if (str.charAt(i) ==' ')
      continue;
       if (str.charAt(i) =='\"')
      continue;
      if (str.charAt(i) ==',')
      continue;
      if (str.charAt(i) =='.')
      continue;
      if (str.charAt(i) =='-')
      continue;
       if (str.charAt(i) =='(')
      continue;
      if (str.charAt(i) ==')')
      continue;
       if (str.charAt(i) =='[')
      continue;
      if (str.charAt(i) ==']')
      continue;
      
     
    return false;
  }
 
  
  return true;
  }
  
  function isValidMessage3(str)
  {
    str = trim(str);
    if (str.length < 2 )
    return false;
    for (i=0; i < str.length; i++)
    {
        if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
        continue;
        if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
        continue;
        if (str.charAt(i) == ' ')
        continue;
        return false;
    }
    return true;
  }
  
  
  function isValidMsgstring(str)
  {
    str=trim(str);
    if(str.length<2)
        return false;
    for(i=0; i<str.length; i++)
    {
        if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
            continue;
        if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
        continue;
        if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
            continue;
        if (str.charAt(i) =='\t')
            continue;
        if (str.charAt(i) =='\n')
            continue;
        if (str.charAt(i) =='\r')
            continue;
        if (str.charAt(i) ==' ')
            continue;
        if (str.charAt(i) =='\"')
            continue;
        if (str.charAt(i) ==',')
            continue;
        if (str.charAt(i) =='.')
            continue;
        if (str.charAt(i) =='-')
            continue;
        if (str.charAt(i) =='(')
            continue;
        if (str.charAt(i) ==')')
            continue;
        if (str.charAt(i) =='[')
            continue;
        if (str.charAt(i) ==']')
            continue;
        if (str.charAt(i) =='?')
            continue;
        if (str.charAt(i) =='!')
            continue;
        if (str.charAt(i) =='&')
            continue;
        if (str.charAt(i) =='\'')
            continue;        
        return false;
    }
    return true;
  }

    var win=null;

    function NewWindow(mypage,myname,w,h,scroll,pos)

    {

    if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}

    if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}

    else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}

    settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';

    win=window.open(mypage,myname,settings);

    }
    
    /*****************************isValidalphanumeric*****************************************/
function isValidNumAlpha(str){
  str = trim(str);

  if ((str.length < 1) || (str.length>20))
   return false;
	
	for (i=0; i < str.length; i++){
  
      if ((str.charAt(i) >= 'a') && (str.charAt(i) <= 'z'))
      continue;
     if ((str.charAt(i) >= 'A') && (str.charAt(i) <= 'Z'))
      continue;
      if ((str.charAt(i) >='0') && (str.charAt(i) <= '9'))
      continue;
      
    return false;
  }
   
  return true;

}
/**********************************isValidCardNo***************************************************/

function isValidCardNo(str){
  str = trim(str);

  if (str.length < 16)
   return false;
  for (i=0; i < str.length; i++){
    if ((str.charAt(i) >= '0') && (str.charAt(i) <= '9'))
      continue;
    return false;
  }
   
  return true;

}

/*************************************************************************************/

