//<!-- 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;
	}	
}
if(typeof(document.getElementsByClassName)!='function'){
	document.getElementsByClassName = function(cl) {//older browsers
		var retnode = [];
		var myclass = new RegExp('\\b'+cl+'\\b');
		var elem = this.getElementsByTagName('*');
		for (var i = 0; i < elem.length; i++) {
			var classes = elem[i].className;
			if (myclass.test(classes)) retnode.push(elem[i]);
		}
		return retnode;
	};
}
function BDremoveElement(theObj){
	var parentOBJ;
	if(typeof(theObj.tagName)!='undefined'){
		parentOBJ=get_parent(theObj);
		parentOBJ.removeChild(theObj);
	}
}
function errClose(whatObj,parentSeek){
	if(!parentSeek){parentSeek='*';}
	formOBJ=get_parent(whatObj,'form',true);
	var form_name=formOBJ.name;
	jump_to=document.forms[form_name].elements['error_anchor_jump'].value;
	if(basic_check(jump_to)){
		var jump_name='formErr';
		if(document.forms[form_name].elements[jump_to].length>0){
			if(document.forms[form_name].elements[jump_to][0]){
				var jumpOBJ=get_parent(document.forms[form_name].elements[jump_to][0],parentSeek);}
			else{
				var jumpOBJ=get_parent(document.forms[form_name].elements[jump_to],parentSeek);}
		}else{
			var jumpOBJ=get_parent(document.forms[form_name].elements[jump_to],parentSeek);}
		injectAndJump(jumpOBJ,parentSeek);
	}
}
function injectAndJump(jumpOBJ,parentSeek){
	if(!parentSeek){parentSeek='*';}
	/*if(typeof(jumpOBJ)!='object'){}*/
	var theClassName='BJDtmpJSjumperBJD';
	var oldAnchors=document.getElementsByClassName(theClassName);
	var err_key;
	for(var err_key in oldAnchors){BDremoveElement(oldAnchors[err_key]);}
	if(jumpOBJ){
		var jump_name='formErr';
		var myElement=document.createElement('a');
		myElement.className=theClassName;
		myElement.name=jump_name;
		if(jumpOBJ.tagName.toLowerCase()=='td'){
			var tmpNodeList;
			tmpNodeList=new Array();
			var is_ie=false;
			if(navigator.appName.toLowerCase().indexOf('microsoft')>0 || navigator.appName.toLowerCase().indexOf('internet explorer')>0){
				is_ie=true;}
			while(jumpOBJ.childNodes.length >=1){
				if(typeof(jQuery)=='function' && is_ie===false){//JQUERY AND NOT IE.  JS Clone doesn't carry jquery.  All this because IE doesn't undersand tables.... gggrrrr
					tmpNodeList[tmpNodeList.length]=jumpOBJ.childNodes[0].clone(true);
					jumpOBJ.removeChild(jumpOBJ.childNodes[0]);
				}else{
					tmpNodeList[tmpNodeList.length]=jumpOBJ.childNodes[0].cloneNode(true);
					jumpOBJ.removeChild(jumpOBJ.childNodes[0]);
				}
			}
			jumpOBJ.appendChild(myElement);
			for(var k in tmpNodeList){
				if(k.toString().toLowerCase()!='length'){
					jumpOBJ.appendChild(tmpNodeList[k]);
				}
			}
		}else{
			jumpOBJ.parentNode.insertBefore(myElement,jumpOBJ);}
		//window.location = "#"+jump_name;
		window.location.hash = jump_name;
	}
}
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;}
}
function adjustStyle(obj,isError,origClass,errClass){
	if(!origClass){origClass='';}
	if(!errClass){errClass='elementErr';}

	if(isError==true){
		obj.className=origClass+' '+errClass;
	}else if(isError==false){
		obj.className=origClass;
	}
}
function is_set_set(compare,stringIn){
	if(!basic_check(compare)){
		return stringIn;
	}else{
		return compare;
	}
}
