function externalLink() {
   if (!document.getElementsByTagName) return false;
   var links = document.getElementsByTagName("a");
   for (var i=0; i<links.length; i++) {
      if (links[i].getAttribute("rel") == "external") {
         links[i].onclick = function() {
            return !window.open(this.href);
         }
      }
   }
}

function numeric_check(p_val){
    var parm1 = p_val;
	for(i=0; i<parm1.length; i++)
	{
    	if (parm1.substring(i, i+1)< "0" || parm1.substring(i, i+1)> "9")
		{
            	return false;
        }
    }
       return true;
} //End of numeric_check()
//************************************************************************************
//************************************************************************************
/*************** To check the given value is alpha**************/
function isAlpha(p_val){
	var validchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var parm1 = p_val.toUpperCase();
	for (var i=0; i<parm1.length; i++) {
		temp = "" + parm1.substring(i, i+1);
		if (validchars.indexOf(temp) == -1) {
			return false;
		}
	}
	return true;
}
function isAlphaOrSpace(p_val){
	var validchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var parm1 = p_val.toUpperCase();
	for (var i=0; i<parm1.length; i++) {
		temp = "" + parm1.substring(i, i+1);
		if (validchars.indexOf(temp) == -1 && temp != " ") {
			return false;
		}
	}
	return true;
}
/*************** To check the given value is alphanumericspace**************/
function isAlphaNumericSpace(p_val){
	var validchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var parm1 = p_val.toUpperCase();
	for (var i=0; i<parm1.length; i++) {
		temp = "" + parm1.substring(i, i+1);
		if (validchars.indexOf(temp) == -1 && temp !=" ") {
			return false;
		}
	}
	return true;
}
//**********************************************************************

/*************** To check the given value is alphanumeric**************/
function isAlphaNumeric(p_val){
	var validchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var parm1 = p_val.toUpperCase();
	for (var i=0; i<parm1.length; i++) {
		temp = "" + parm1.substring(i, i+1);
		if (validchars.indexOf(temp) == -1) {
			return false;
		}
	}
	return true;
}
//**********************************************************************
/*************** To disable the form submit**************/
function disableSubmits (form) 
{ 
	for (var i = 0; i < form.elements.length; i++) 
		if (form.elements[i].type.toLowerCase() == 'submit') 
			form.elements[i].disabled = true; 
} 
//**********************************************************************
/*************** To check the Given value is non zero, 
				 before checking this, value should pass numeric check**************/
function isNonZeroValue(p_value){
	var numvalue = "" + p_value * 1;
	if (numvalue == "0"){
		return false;
	}
	return true;
}
//**********************************************************************
/*************** To check the telephone is valid **************/

function isValidTelephone(p_value){
	var validchars = "0123456789-";
	var parm1 = p_value;
	for (var i=0; i<parm1.length; i++) {
		temp = "" + parm1.substring(i, i+1);
		if (validchars.indexOf(temp) == -1) {
			return false;
		}
	}
	return true;
}
//**********************************************************************
/*************** To check the null and empty string**************/

function isEmpty(frm_fld){
	if (frm_fld.value.length < 1){
		return true;
	} else {
		var strInput = new String(frm_fld.value);
		if (strInput.trim()=="") {
			return true;
		}
		return false;
	}
	return false;
}//End of function  ChecktxtValue
//**********************************************************************
function isLetter(sChar) {
	if (sChar.toUpperCase() < "A" || sChar.toUpperCase() > "Z") {
			return false;
	 }
	return true;
}

function isSeparator(sChar) {
    if (sChar == " " || sChar == "-" || sChar == "_") return true;
    return false;
}

//This function is used to for performing EMail-Id validation
function checkEmail(strng) {
		var error = ""
		if(strng==null ||strng == "") {
		  return "";
		}
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) {
		  error = "Please enter a valid email address.\n";
		}
		var illegalChars= /[\(\)\<\>\%\=\,\;\:\\\/\"\[\]]/
		if (!strng.match(illegalChars)) {
		  error = "The email address contains illegal characters.\n";
		}
		var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._@-";
		var checkStr = strng;
		var passValid = true; var ch;
		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){
					passValid = false;
					break;
				}
		}
		if (passValid)	{
			error= "";
		} else
			error="invalid characters in email is not allowed.\n";

		return error;
} // function checkEmail  ends here

//**********************************************************************************************************

//This function is used to check whether the EMail-ID field and EMail-Confirm field are same or not . If not returns error .
function confirmEmailAddress(jsEmail1, jsEmail2) {
	var error = "Email, Confirm Email do not match";
		if(jsEmail1.toUpperCase() == jsEmail2.toUpperCase()) {
			return "";
		} else {
			return error;
		}
}// function confirmEmailAddress  ends here
//**********************************************************************************************************

// Add a function called trim as a method of the prototype .// object of the String constructor.
String.prototype.trim = function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");    // Use a regular expression to replace leading and trailing  spaces with the empty string
}

//**********************************************************************************************************
//This function Checks for Spaces
function Check_NullString(frm_fld){
	var strInput = new String(frm_fld.value);
	if (strInput.trim()=="") {
		return false;
	}
	return true;
}//End of function  Check_NullString
//**********************************************************************************************************
function isBothStringsEqual(p_str1, p_str2) {
	if(p_str1.toUpperCase() == p_str2.toUpperCase()) {
			return true;
	} else {
		return false;
	}
}// End of isBothStringsEqual()
//************To Check the given value is having invalid chars.*********************//
function isInvalidCharsExist(p_str){
	var illegalChars= /[\(\)\<\>\%\=\,\&\'\*\;\:\\\/\"\[\]@]/
	if (p_str.match(illegalChars) != null) {
		return true;
	}
	return false;
}// End of isInvalidCharsExist

//************To Check the given value is having meta chars.*********************//
function hasMetaChars(p_str){
	var illegalChars= /[\<\>]/
	if (p_str.match(illegalChars) != null) {
		return true;
	}
	return false;
}// End of hasMetaChars

function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
var expdate = new Date ();
var ckydays = 24 * 30; //24 hrs * 30 = 30 days
FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
expdate.setTime (expdate.getTime() + (ckydays * 60 * 60 * 1000));

function setHMCky(jsVal) {
	SetCookie ("hmuname", jsVal, expdate, null, null, true);
}
function getHMCky() {
	jsVal=null;
	if(document.frmLogin!=null) jsVal = GetCookie ("hmuname");
	if(jsVal!=null) document.frmLogin.Username.value=jsVal;
}
function delHMCky() {
	DeleteCookie ("hmuname", null, null);
}

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
} 

function trim(inputString) {
		 var retValue = inputString;
		 var ch = retValue.substring(0, 1);
		 while (ch == " ") {
				retValue = retValue.substring(1, retValue.length);
				ch = retValue.substring(0, 1);
		 }
		 ch = retValue.substring(retValue.length-1, retValue.length);
		 while (ch == " ") {
				retValue = retValue.substring(0, retValue.length-1);
				ch = retValue.substring(retValue.length-1, retValue.length);
		 }
		 return retValue;
}
function isMetaCharacter(p_val){
	var validchars = "{}[]+<>!";
	var parm1 = p_val.toUpperCase();
	for (var i=0; i<parm1.length; i++) {
		temp = "" + parm1.substring(i, i+1);
		if (validchars.indexOf(temp) >= 0 && temp != " ") {
			return true;
		}
	}
	return false;
}

//************to check if the word is a lengthy one.*********************//
function isLengthyWord (jsValue, jsMaxChars, jsFieldName) {
	var maxChars = jsMaxChars;
	var fieldValue	= jsValue+" ";
	var fieldLength	= jsValue.length+1;
        var errorMsg = "Use of long words in "+jsFieldName+" is restricted\n";
	var startpos = 0;
	var endpos = 0;
	var str;

	var diff = 0;
	for (var i=0;i<fieldLength;i++) {
		str = fieldValue.charAt(i);
		if(str== " ") {
			startpos = i+1;
			diff = startpos-endpos;
			if(diff > maxChars) {
				return errorMsg;
			}
			endpos = startpos;
			startpos=0;
		}
	}
	if(fieldValue.indexOf(" ")==-1 && fieldLength > maxChars) {
		return errorMsg;
	}
        return "";
} // End of isLengthyWord