function namecheck(nameTxt)
{
	var i;
	var boolvalue=true;
	for(i=0;i<nameTxt.length;i++)
	{
		var a1 = nameTxt.charAt(i);
		var h1 = a1.charCodeAt(0);
		if((h1 > 47 && h1<59)||(h1>32 && h1<46)||(h1==47)||(h1>90 && h1<97)||(h1>122 && h1<128))
		{
			boolvalue=false;
			break;
		}
	}
	return boolvalue;
}
function alphanum(nameTxt)
{
	var i;
	var boolvalue=true;
	for(i=0;i<nameTxt.length;i++)
	{
		var a1 = nameTxt.charAt(i);
		var h1 = a1.charCodeAt(0);
		if((h1>32 && h1<46)||(h1==47)||(h1>90 && h1<97)||(h1>122 && h1<128))
		{
			boolvalue=false;
			break;
		}
	}
	return boolvalue;
}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}


function emailvalidate(emailText)
{
	var i;
	var count=0;
	for(i=0;i<emailText.length;i++)
	{
		var a1 = emailText.charAt(i);
		var h1 = a1.charCodeAt(0);
		if(h1 == 64 )
		count++;
	}
		if (count > 1)
			return false;
		else
			return true;
}

function Trim(inString)
{
  inString = inString.replace( /^\s+/g, "" );	// strip leading
  return inString.replace( /\s+$/g, "" );		// strip trailing
}

// Invalid E-mail
function InvalidEmail(email)
{
	var atsign = email.indexOf("@");
	var period = email.lastIndexOf(".");

	if(atsign == -1)
		return true;
	else if(atsign == 0 || atsign == email.length)
		return true;

	if(period == -1)
		return true;
	else if(period == 0 || period == email.length)
		return true;
	else if(email.charAt(period-1) == '@')
		return true;
	else if(period < atsign)
		return true;

	return false;
}

// Invalid Zip code
function InvalidZip(zip)
{
	numberzip = Trim(zip).replace("-","");

	if(!isInteger(numberzip))
		return true;

	if(zip.indexOf("-") == -1)
	{
		if(Trim(zip).length != 5)
			return true;
	}
	else
	{
		var zipstart = Trim(zip).substring(0,zip.indexOf("-"));
		var zipend = Trim(zip).substring(zip.indexOf("-")+1,Trim(zip).length);

		if(zipstart.length != 5 || zipend.length != 4)
			return true;
	}

	return false;
}

// Invalid Phone No.
function InvalidPhone(phone)
{
	var fmtphone = Trim(phone).replace(/ /g,"");
	fmtphone = fmtphone.replace(/-/g,"");
	fmtphone = fmtphone.replace("(","");
	fmtphone = fmtphone.replace(")","");

	if(!isInteger(fmtphone))
		return true;

	// 9999999
	if(fmtphone.length == 10)
	{
		if(phone.indexOf("(") != -1)
		{
			if(Trim(phone).charAt(0) != '(' && Trim(phone).charAt(4) != ')')
				return true;
			if(Trim(phone).charAt(Trim(phone).length-5) != '-')
				return true;
		}
		else if(phone.indexOf("-") != -1)
		{
			// (111) 222-3333 or 111-222-3333 or 111 222-3333
			if(!(Trim(phone).charAt(3) == '-' || Trim(phone).charAt(3) == ' ') ||
			 Trim(phone).charAt(Trim(phone).length-5) != '-')
				return true;
		}
	}
	// 18001112222
	else if(fmtphone.length == 11)
	{
		var nospace = phone.replace(/ /g,"");

		if(phone.indexOf("(") != -1)
		{
			if(nospace.charAt(1) != '(' && nospace.charAt(4) != ')')
				return true;
			else if(nospace.charAt(nospace.length-5) != '-')
				return true;
		}
		else if(phone.indexOf("-") != -1)
		{
			if(!(Trim(phone).charAt(1) == '-' || Trim(phone).charAt(1) == ' ') ||
		 	!(Trim(phone).charAt(5) == '-' || Trim(phone).charAt(5) == ' ') ||
			nospace.charAt(nospace.length-5) != '-')
				return true;
		}
	}
	else
		return true;

	return false;
}

// Check to see if string is all numeric
function isInteger(num)
{
	var numbers = "0123456789";
	var i = 0;

	for(i=0;i<num.length;i++)
	{
		if(numbers.indexOf(num.charAt(i)) == -1)
			return false;
	}

	return true;
}

// Only allow number input
function numbersOnly(e)
{
	var keynum;
	var keychar;
	var numcheck;

	if(window.event)
		keynum = e.keyCode;
	else if(e.which)
		keynum = e.which;

	if((keynum <= 57 && keynum != 32) || (keynum >= 96 && keynum <= 105))
		return true;
	else
		return false;
}

function GetXmlHttpObject()
{
	var objXMLHttp=null
	if (window.XMLHttpRequest)objXMLHttp=new XMLHttpRequest()
	else if (window.ActiveXObject)	objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	return objXMLHttp
}

function createXML( root, nodes )
{
	var xml = "";
	if( root )
		xml += "<" + root + ">";
	for( theNode in nodes )
		xml += "<" + theNode + ">" + nodes[theNode] + "</" + theNode + ">";
	if( root )
		xml += "</" + root + ">";
	return xml;
}

function extractFile(data)
{
	alert(data);
	var m = data.match(/(.*)\/([^\/\\]+)(\.\w+)$/);
	alert(m);
	return {path: m[1], file: m[2], extension: m[3]}
}


