﻿var strInvalid = "~!@#$%^()|\\\'\"[]{}<>+-;";
function CallForSearch(ID) {
  var blnSearch = false;
  var Value = document.getElementById(ID).value;
  if (trim(Value) != "") {
    for (i = 0; i <= strInvalid.length; i++) {
      if (Value.indexOf(strInvalid.charAt(i)) > 0 || Value.charAt(0) == strInvalid.charAt(i)) {
        alert("Search keywords cannot contain any of the following chars:\n" + strInvalid)
        blnSearch = true;
        break
      }
    }
  }
  else {
    blnSearch = true;
    alert("Please enter key to search.");
    document.getElementById(ID).focus();
  }
  if (!blnSearch)
    window.location.href = "IndexServer.asp?SearchValue=" + Value;
}

function CallForSearchHTML(ID) {
  var blnSearch = false;
  var Value = document.getElementById(ID).value;
  if (trim(Value) != "") {
    for (i = 0; i <= strInvalid.length; i++) {
      if (Value.indexOf(strInvalid.charAt(i)) > 0 || Value.charAt(0) == strInvalid.charAt(i)) {
        alert("Search keywords cannot contain any of the following chars:\n" + strInvalid)
        blnSearch = true;
        break
      }
    }
  }
  else {
    blnSearch = true;
    alert("Please enter key to search.");
    document.getElementById(ID).focus();
  }
  if (!blnSearch)
    window.location.href = "../IndexServer.asp?SearchValue=" + Value;
}


function CallForSearchHTML2(ID) {
  var blnSearch = false;
  var Value = document.getElementById(ID).value;
  if (trim(Value) != "") {
    for (i = 0; i <= strInvalid.length; i++) {
      if (Value.indexOf(strInvalid.charAt(i)) > 0 || Value.charAt(0) == strInvalid.charAt(i)) {
        alert("Search keywords cannot contain any of the following chars:\n" + strInvalid)
        blnSearch = true;
        break
      }
    }
  }
  else {
    blnSearch = true;
    alert("Please enter key to search.");
    document.getElementById(ID).focus();
  }
  if (!blnSearch)
    window.location.href = "../../IndexServer.asp?SearchValue=" + Value;
}

function CallForSearchFromASPX(ID) {
  var blnSearch = false;
  var Value = document.getElementById(ID).value;
  if (trim(Value) != "") {
    for (i = 0; i <= strInvalid.length; i++) {
      if (Value.indexOf(strInvalid.charAt(i)) > 0 || Value.charAt(0) == strInvalid.charAt(i)) {
        alert("Search keywords cannot contain any of the following chars:\n" + strInvalid);
        blnSearch = true;
       break
      }
    }
  }
  else {
    blnSearch = true;
    alert("Please enter key to search.");
  }
   
  if (!blnSearch)
    window.location.href = "../IndexServer.asp?SearchValue=" + Value;
}

//Trim function
function trim(strValue) {
  return strValue.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
}

function RemoveBlanks(strValue) {
  var strTemp = "";
  for (i = 0; i < strValue.length; i++) {
    if (strValue.charAt(i) != " ") {
      strTemp = strTemp + strValue.charAt(i);
    }
  }
  return strTemp;
}

var emailRegxp = /^[a-z|A-Z][a-z|0-9|A-Z]*([_|-][a-z|0-9|A-Z]+)*([.][a-z|0-9]+([_][a-z|0-9]+)*)?@[a-z|0-9|][a-z|0-9|]([a-z|0-9]+([_|-][a-z|0-9]+)*)*\.([a-z][a-z|0-9|A-Z]*(\.[a-z][a-z|0-9|A-Z]*)?)$/;
var Email;
var xmlReq;
function ValidateEmail(EmailVal, emailId) {
  var url = document.URL;
  Email = EmailVal
  xmlReq = CreateXmlHttp();
  if (xmlReq == null) return;
  actionString = '?EmailId=' + Email;
  url += actionString;
  if (EmailValidations(Email, emailId)) {
    return true;
  }
  else {
    return false;
  }
}

function EmailValidations(strEmail, emailId) {
  if (emailRegxp.test(strEmail) != true) {
    alert("Not a valid email address.");
    emailId.value = "";
    emailId.focus();
    return false;
  }
  else {
    return true;
  }
}

function IfExistsEmailIdCount() {
  if (xmlReq.readyState == 4 && xmlReq.status == 200) {
    var responseText = new String(xmlReq.responseText);
    if (responseText.toLowerCase() == "true") {
      alert("Email Already Exists");
      document.getElementById(txtEmailClientID).value = "";
      document.getElementById(txtEmailClientID).focus();
      return false;
    }
  }
}

function CreateXmlHttp() {
  //Creating object of XMLHTTP in IE
  try {
    XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e) {
    try {
      XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (oc) {
      XmlHttp = null;
    }
  }

  //Creating object of XMLHTTP in Mozilla and Safari 
  if (!XmlHttp && typeof XMLHttpRequest != "undefined") {
    XmlHttp = new XMLHttpRequest();
  }

  return XmlHttp;
}

/**
* DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s) {
  var i;
  for (i = 0; i < s.length; i++) {
    // Check that current character is number.
    var c = s.charAt(i);
    if (((c < "0") || (c > "9"))) return false;
  }
  // All characters are numbers.
  return true;
}
function trim(s) {
  var i;
  var returnString = "";
  // Search through string's characters one by one.
  // If character is not a whitespace, append to returnString.
  for (i = 0; i < s.length; i++) {
    // Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (c != " ") returnString += c;
  }
  return returnString;
}
function stripCharsInBag(s, bag) {
  var i;
  var returnString = "";
  // Search through string's characters one by one.
  // If character is not in bag, append to returnString.
  for (i = 0; i < s.length; i++) {
    // Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
  }
  //alert(returnString)
  return returnString;
}

function checkInternationalPhone(strPhone) {
  var bracket = 3
  strPhone = trim(strPhone)
  if (strPhone.indexOf("+") > 1) return false
  if (strPhone.indexOf("-") != -1) { bracket = bracket + 1 }
  if (strPhone.indexOf("(") != -1 && strPhone.indexOf("(") > bracket) return false
  var brchr = strPhone.indexOf("(")
  if ((strPhone.indexOf("(") == -1 && strPhone.charAt(brchr + 2) == ")")) return false
  if (strPhone.indexOf("(") == -1 && strPhone.indexOf(")") != -1) return false
  s = stripCharsInBag(strPhone, validWorldPhoneChars);
  return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}