//<!-- Original:  Cyanide_7 (leo7278@hotmail.com) -->
//<!-- Web Site:  http://members.xoom.com/cyanide_7 -->

//<!-- This script and many more are available free online at -->
//<!-- The JavaScript Source!! http://javascript.internet.com -->

//<!-- Begin
//Tis is auto tab
var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	/*if(input.value.length >= len && !containsElement(filter,keyCode)) {
	input.value = input.value.slice(0, len);
	input.form[(getIndex(input)+1) % input.form.length].focus();*/
	if(document.getElementById(input).value.length>=len && !containsElement(filter,keyCode)){
	document.getElementById(input).value = document.getElementById(input).value.slice(0, len);
	document.getElementById(input).form[(getIndex(document.getElementById(input))+1) % document.getElementById(input).form.length].focus();
	document.getElementById(input).form[(getIndex(document.getElementById(input))+1) % document.getElementById(input).form.length].select();
}

function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
	if(arr[index] == ele)
		found = true;
	else
		index++;
	return found;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
	if (input.form[i] == input)index = i;
	else i++;
	return index;
	}
	return true;
}
//  End -->

function emailValidate(emailIn){
	if(emailIn.value.length==0){
		return (false);
	}else{
		with(emailIn){
			apos=emailIn.value.indexOf("@");
			dotpos=emailIn.value.lastIndexOf(".");
			if (apos<1||dotpos-apos<2){
				return (false);
			}else{
				return (true);
			}
		}
	}
}
function isInt(str){
	var i = parseInt (str);

	if (isNaN (i)){
		return false;
	}

	i = i . toString();
	if (i != str){
		return false;
	}
	return true;
}
//Original:  Nannette Thacker
//http://www.shiningstar.net
//Taken from http://www.shiningstar.net/articles/articles/javascript/checkNumeric.asp?ID=AW
//Begin
function checkNumeric(objName,minval, maxval,comma,period,hyphen){
	//var numberfield = objName;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false){
		//numberfield.select();
		//numberfield.focus();
		return false;
	}else{
		return true;
	}
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen){
	// only allow 0-9 be entered, plus any values passed
	// (can be in any order, and don't have to be comma, period, or hyphen)
	// if all numbers allow commas, periods, hyphens or whatever,
	// just hard code it here and take out the passed parameters
	var checkOK = "0123456789" + comma + period + hyphen;
	var checkStr = objName;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";

	for (i = 0;  i < checkStr.value.length;  i++){
		ch = checkStr.value.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		if (ch == checkOK.charAt(j))
		break;
		if (j == checkOK.length){
			allValid = false;
			break;
		}
		if (ch != ",")
		allNum += ch;
	}

	// set the minimum and maximum
	var chkVal = allNum;
	var prsVal = parseInt(allNum);
	if (!allValid){	
		alertsay = "Please enter only these values \""
		alertsay = alertsay + checkOK + "\" in the \"" + checkStr.name + "\" field."
		//alert(alertsay);
		return (false);
	}else if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval)){
		alertsay = "Please enter a value greater than or "
		alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
		alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
		//alert(alertsay);
		return (false);
	}else{
		return (true);
	}
}

//http://www.webdeveloper.com/forum/showthread.php?t=95583
function validZip(zip){
	if (zip.match(/^[0-9]{5}$/)) {
		return true;
	}
	zip=zip.toUpperCase();
	if (zip.match(/^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/)) {
		return true;
	}
	if (zip.match(/^[A-Z][0-9][A-Z].[0-9][A-Z][0-9]$/)) {
		return true;
	}
	//alert('*** Bad ZIP.');
	return false;
}

function clearField(theTextField){
	var theString;
	theString=theTextField.value;
	theString=theString.replace(/ /gi, "");
	theString=theString.replace(/\n/gi, "");//remove lines
	theString=theString.replace(/\r/gi, "");//remove lines
	theString=theString.replace(/\t/gi, "");//remove tabs
	if(theTextField.value==theTextField.defaultValue){
		theTextField.value="";
	}else if(theString.length==0){
		theTextField.value=theTextField.defaultValue;
	}
 }

 function jstrim(stringIn){
	stringOut=stringIn;
	stringOut=stringOut.replace(/ /gi, "");
	stringOut=stringOut.replace(/\n/gi, "");//remove lines
	stringOut=stringOut.replace(/\r/gi, "");//remove lines
	stringOut=stringOut.replace(/\t/gi, "");//remove tabs
	return stringOut;
}
function parseUrl(url){
	url=url.toString();
	//var e = /((http|https):\/\/)?((.*?)\/)?((.*)\/)?(.*)?/;
	var e = /^(http|https):\/\/(.+)$/;//
	if(e.test(url)){
		/*
		return  { url:     RegExp['$&']
		, protocol: RegExp.$2
		, host:     RegExp.$4
		, path:     RegExp.$6
		, file:     RegExp.$7
		, hash:     RegExp.$8 };*/
		return true;
	}else {
		//return  {url:"", protocol:"",host:"",path:"",file:"",hash:""};
		return false;
	}
}function parseUrl(url){
	url=url.toString();
	//var e = /((http|https):\/\/)?((.*?)\/)?((.*)\/)?(.*)?/;
	var e = /^(http|https):\/\/(.+)$/;//
	if(e.test(url)){
		/*
		return  { url:     RegExp['$&']
		, protocol: RegExp.$2
		, host:     RegExp.$4
		, path:     RegExp.$6
		, file:     RegExp.$7
		, hash:     RegExp.$8 };*/
		return true;
	}else {
		//return  {url:"", protocol:"",host:"",path:"",file:"",hash:""};
		return false;
	}
}function isAlphaNumeric(val){
	if (val.match(/^[a-zA-Z0-9\-_\.]+$/)){
		return true;
	}else{
		return false;
	}	
}

function comment_validate(stringIn){
	 var text1 = stringIn;
	 var text2 = text1.replace(/\s+/g, ' ');
	 var text3 = text2.split(' ');
	 var numberOfWords = text3.length;
	if(numberOfWords>10){
		return true;}
	else{
		return false;}
}
