function SetFocus() {
  if (document.forms.length > 0) {
    isNotAdminLanguage:
    for (f=0; f<document.forms.length; f++) {
      if (document.forms[f].name != "adminlanguage") {
        var field = document.forms[f];
        for (i=0; i<field.length; i++) {
          if ( (field.elements[i].type != "image") &&
               (field.elements[i].type != "hidden") &&
               (field.elements[i].type != "reset") &&
               (field.elements[i].type != "submit") ) {

            document.forms[f].elements[i].focus();

            if ( (field.elements[i].type == "text") ||
                 (field.elements[i].type == "password") )
              document.forms[f].elements[i].select();

            break isNotAdminLanguage;
          }
        }
      }
    }
  }
}
function trim(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
function echeck(str) 
{		
	var at="@"		
	var dot="."		
	var lat=str.indexOf(at)		
	var lstr=str.length		
	var ldot=str.indexOf(dot)		
	if (str.indexOf(at)==-1)
	{		   
		alert("Invalid email. Please enter valid email.")
		return false		
	}		
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{		   
		alert("Invalid email. Please enter valid email.")		   
		return false		
	}		
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{		    
		alert("Invalid email. Please enter valid email.")		    
		return false		
	}		 
	if (str.indexOf(at,(lat+1))!=-1)
	{		    
		alert("Invalid email. Please enter valid email.")		    
		return false		 
	}		 
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{		    
		alert("Invalid email. Please enter valid email.")		    
		return false		 
	}		 
	if (str.indexOf(dot,(lat+2))==-1)
	{		    
		alert("Invalid email. Please enter valid email.")		   
	 	return false		 
	 }				 
	 if (str.indexOf(" ")!=-1)
	 {		    
	 	alert("Invalid email. Please enter valid email.")		   
	 	return false		 
	 } 		 
	  
	  return true						
}

function rowOverEffect(object) {
  if (object.className == 'dataTableRow') object.className = 'dataTableRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'dataTableRowOver') object.className = 'dataTableRow';
}

function toggleDivBlock(id) {
  if (document.getElementById) {
    itm = document.getElementById(id);
  } else if (document.all){
    itm = document.all[id];
  } else if (document.layers){
    itm = document.layers[id];
  }

  if (itm) {
    if (itm.style.display != "none") {
      itm.style.display = "none";
    } else {
      itm.style.display = "block";
    }
  }
}
 
function ZipValidate(strValue)
{

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.\/?~!@#$%^&* ";
  var checkStr = strValue;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}
function ValidAlpha(strValue)
{

  var checkOK = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
  var checkStr = strValue;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}

function ValidAlpha_SPEC(strValue)
{

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 '";
  var checkStr = strValue;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}

function ValidEmailChar(strValue)
{
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._@";
  var checkStr = strValue;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}

function ValidAlphaNum(strValue)
{

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
  var checkStr = strValue;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}

function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }
    return str;
}

function PlaceDeshInPhone(ElementId)   
{
   
    var Phone = ElementId;
    var phoneNew='';
    var tempphone='';
    
    tempphone=replaceAll(Phone,")",'');
  
    tempphone=replaceAll(tempphone,"(",'');
    tempphone=replaceAll(tempphone,"-",'');
    tempphone=replaceAll(tempphone,".",'');
   
    Phone=tempphone;
    
    
    
    if(Phone.length == 10)
    {
        phoneNew=Phone.substring(0,3);
        phoneNew= phoneNew + '-' + Phone.substring(3,6);
        phoneNew=phoneNew + '-' + Phone.substring(6,10);
        return phoneNew;
    }
    else
    {
        return '';
    }
}
function ValidatePhoneNum(elem)
{
    var elem1=trim(elem.value);
    var elem2=PlaceDeshInPhone(elem1);
   
    if(elem2!='')
    {
    elem.value=elem2;
    }
    else
    {
    return false; 
    }
    
    if(elem.value!=false && elem.value!='')
        {
            
            var phoneRE =/^(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d{6}))*$/;

           
            if (elem.value.match(phoneRE)) 
            { 
               return true; 
            } 
            else 
            { 
                
               
                return false; 
            }          
        }
        else
        {
         return true; 
        }
}
/*function ValidatePhoneNum(elem)
{
    if(elem.value!=false && elem.value!='')
        {
       
            var phoneRE =/^(1\s*[-\/\.]?)?(\((\d{3})\)|(\d{3}))\s*[-\/\.]?\s*(\d{3})\s*[-\/\.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT])\.?\s*(\d{6}))*$/;

            ///^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/;
            if (elem.value.match(phoneRE)) 
            { 
                return true; 
            } 
            else 
            { 
                
               // alert('The phone number entered is invalid'); 
                // elem.focus();
              
                return false; 
            }          
        }
        else
        {
         return true; 
        }
}*/
function isZip(s) 
{

     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

     if (!reZip.test(s)) {
          alert("Invalid Zip.");
          return false;
     }

return true;
}
function ValidateWebsiteUrl(elem)
{
    if(elem!=false && elem!='')
    {
                var exp =/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
                ///^\(((ht|f)tp(s?))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$/;
                      var regex = new RegExp(exp);
                      var result;

                      var s = elem;
                      if (s.match(exp))
                      {
                             return true; 
                      } 
                      else 
                      { 
//       					alert('Please enter valid Website URL');
  //                               document.getElementById(elem).focus(); 
                                return false; 
                      } 
     }   
        return true;   
}
function ValidModelNum(strValue)
{

var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789#-_% ";
  var checkStr = strValue;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
  
}