var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

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);
}

function ValidateForm()
{
	strError = "";
	strErrChk = 0;

	if (document.talkForm.t1_name.value == "")
	{ 
	  strError = "You have not entered any name\n"
	  strErrChk = 1;	
    } 

	if (document.talkForm.t2_email.value == "")
	{ 
	  strError = strError + "You have not entered any email address\n"
	  strErrChk = 1;	
    } 
    else 
    {
	  if (!isValidEmail(document.talkForm.t2_email.value))
      {
	    strError = strError + "Invalid Email Address\n"
	    strErrChk = 1;	
      }
    }
	
	if (document.talkForm.t3_phone.value == "")
	{ 
	  strError = strError + "You have not entered any contact number\n"
	  strErrChk = 1;	
    }
    else {
	if (checkInternationalPhone(document.talkForm.t3_phone.value)==false){
		strError = strError + "Invalid Contact Number\n"
	    strErrChk = 1;	
	}
    } 

	if (document.talkForm.t4_comment.value == "")
    {
	  strError = strError + "You have not entered any comments\n"
	  strErrChk = 1;	
    }
 
    if (strErrChk == 1)
	{ 
	  alert (strError); 
	  return false;
	}
    
	return true;
	
} 


