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 pnumOnly()
{
	if((window.event.keyCode<48 || window.event.keyCode>57 ) && (window.event.keyCode != 13))
	{
		window.event.keyCode=null;
		//alert("Please Enter Numeric Values Only");
	}
}

function check()
{
	if(window.event.keyCode == 34 || window.event.keyCode == 39 )
	{
		window.event.keyCode=null;
		//alert("Please Enter Numeric Values Only");
	}
}

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 ValidatePhone(phNumber){
	var Phone = phNumber;
	if ((Phone==null)||(Phone=="")){
		//alert("Please Enter your Phone Number")
		return false
	}
	if (checkInternationalPhone(Phone)==false){
		//alert("Please Enter a Valid Phone Number")
		return false
	}
	return true
 }

function isEmail(string) {
if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
return true;
else
return false;
}

function isDate(day,month,year)
{
	var dteDate;
	month = month - 1
	dteDate=new Date(year,month,day);
	return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
}


function validatelength(ta_name,a)
{
	var p;
	p = ta_name.value;

	
	if(window.event.keyCode == 34 || window.event.keyCode == 39 )
	{
		window.event.keyCode=null;
		return;
		//alert("Please Enter Numeric Values Only");
	}
	
	if ((a==1) && (p.length >= 255))
	{
		alert("Max. Charatcters Limit 255 Exceeds");
		window.event.keyCode=null;
	}
	if ((a==2) && (p.length > 255))
	{
		alert("Max. Charatcters Limit 255 Exceeds");
		ta_name.value = p.substring(0,255);
	}
}

function checkField(field_name,err_msg)
{
	if (document.getElementById(field_name).value == "")
	{
		alert(err_msg);
		document.getElementById(field_name).focus();
		return false;
	}
	return true;
}

function checkFile(fname,extension)
{
		  
	var ext = document.getElementById(fname).value;
	if (ext == "")
	{	
		alert("Select a File in (." + extension + ") Format");
		document.getElementById(fname).focus();
		return false;
	}
	ext = ext.substring(ext.length-3,ext.length);
	ext = ext.toLowerCase();
	if (ext != extension)
	{
		alert("You selected a ." + ext + " file; please select a ." + extension + " file instead!");
		document.getElementById(fname).focus();
		return false;
	}
	return true;
}

