// 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 = 11;

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 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;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

//Telephone Number Verify

function verifycnt() {
var txt = "";
var Phone=document.frmcnt.phone

  if (document.frmcnt.name.value=="") {
     txt = txt + "\n * Please enter a Name";
  }
  if (document.frmcnt.surname.value=="") {
     txt = txt + "\n * Please enter a Surname";
  }
  
//  if ((Phone.value==null)||(Phone.value=="")){
//		txt = txt + "\n * Please Enter a Phone Number";
//  }
  if (checkInternationalPhone(Phone.value)==false){
		txt = txt + "\n * Please Enter a Valid Phone Number";
  }
	

  
  var str=document.frmcnt.email.value
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i 
  if (!filter.test(str)) {
     txt = txt + "\n * Please input a valid Email address";
  }
  
  if (document.frmcnt.message.value=="") {
     txt = txt + "\n * Please enter a Message";
  }

	if (txt) {
		alert ("The folowing fields are required:\n" + txt);
		return false;
	}	
}

function verifyfrmlc() {
var txt = "";

  for(var i = 0; i < document.frmlc.location.length; i++) {
	if(document.frmlc.location[i].selected) {
		if(document.frmlc.location[i].value=="") {
		  txt = txt + "\n * Select Location";
		}
	}
  }
	if (txt) {
		alert ("The folowing fields are required:\n" + txt);
		return false;
	}	
}

// Refresh page when search

function refresh()
{
var sURL = window.location.href
var Quant = document.frmsrc.res_coun.value
sURL = "?cnt_id=" + Quant
window.location.replace( sURL );
}