// Set Window Status
window.status = "BizLink";
// Change Window Status
function stat(x) {
	window.status=x;
}
// OnLoad
function loaded() {
	if(document.Insert.elements) {
		for(var x=0;x<document.Insert.length;x++) {
			if(document.Insert.elements[x].disabled == false) {
				if(document.Insert.elements[x].type == "button") {
                } else {
                  	document.Insert.elements[x].focus();
                  	return;
				}
       		}
    	}
  	}
}
// Site Tools Nav
function cLinkOvr( cLOvrId, stat ){
  if (document.getElementById){
  		cLOvr = document.getElementById( cLOvrId );
  		if (cLOvr.style.background == "#CEE7FF"){
  			cLOvr.style.background = "#F8F8F8";
  		} else {
  			cLOvr.style.background = "#CEE7FF";
			window.status = stat;
		}
  	}
}
function cLinkOut( cLinkId, stat ){
  if (document.getElementById){
  		cLOut = document.getElementById( cLinkId );
  		if (cLOut.style.background == "#F8F8F8"){
  			cLOut.style.background = "#CEE7FF";
  		} else {
  			cLOut.style.background = "#F8F8F8";
			if (stat) {
				window.status = stat;
			} else {
				window.status = "BizLink";
			}
  		}
  	}
}
//  Numeric Function	
function IsNumeric(strString) {
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;
	if (strString.length == 0) return false;
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	 }
	return blnResult;
}
function valNum(f,e,t)
{
	var key;
	var keyChr;
	var cursor = getSelectionStart(f);
	if ( window.event )
	{
		key = window.event.keyCode;
	}
	else if ( e )
	{
		key = e.which;
	}
	keyChr = String.fromCharCode(key);
	if ( ("0123456789").indexOf(keyChr) > -1 || (key==null) || (key==0) || (key==3) || (key==8) || (key==9) || (key==13) || (key==27) || (key==63272) || (key==63234) || (key==63235) )
	{
		return true;
	}
	else if ( t == "emp" )
	{
		if ( cursor == 0 )
		{
			return ( ("BbDdIi").indexOf(keyChr) > -1 )
		}
		else if ( cursor == 1 )
		{
			if ( f.value.substring(0,1) == "I" )
			{
				return ( ("Ss").indexOf(keyChr) > -1 )
			}
			else
			{
				return ( ("Ii").indexOf(keyChr) > -1 )
			}
		}
		else if ( cursor == 2 )
		{
			if ( f.value.substring(0,1) == "I" )
			{
				return ( ("Aa").indexOf(keyChr) > -1 )
			}
			else if ( f.value.substring(0,1) == "B" )
			{
				return ( ("Zz").indexOf(keyChr) > -1 )
			}
			else
			{
				return ( ("Ss").indexOf(keyChr) > -1 )
			}
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
}
function chkNum(f,e,t){
	var key;
	var keyChr;
	var fValue;
	var reg;
	var cursor = getSelectionStart(f);
	if ( window.event )
	{
		key = window.event.keyCode;
	}
	else if ( e )
	{
		key = e.which;
	}
	if ( key!=8 && key!=9 && key!=16 && key != 37 && key != 39 && key!=46 )
	{
		reg = /-/g;
		fValue = f.value.replace(reg, "");
		cursor = getSelectionStart(f);
		f.value = '';
		if ( t == "phn" )
		{
			if ( fValue.length < 3 )
			{
				f.value=fValue;
			}
			else if ( cursor == 3 )
			{
				cursor=4;
				f.value=fValue.substring(0,3)+"-"+fValue.substring(3,6);
			}
			else if ( fValue.length < 6 )
			{
				f.value=fValue.substring(0,3)+"-"+fValue.substring(3,6);
			}
			else if ( cursor == 7 )
			{
				cursor=8;
				f.value=fValue.substring(0,3)+"-"+fValue.substring(3,6)+"-"+fValue.substring(6,10);
			}
			else
			{
				f.value=fValue.substring(0,3)+"-"+fValue.substring(3,6)+"-"+fValue.substring(6,10);
			}
		}
		else if ( t == "soc" )
		{
			if ( fValue.length < 3 )
			{
				f.value=fValue;
			}
			else if ( cursor == 3 )
			{
				cursor=4;
				f.value=fValue.substring(0,3)+"-"+fValue.substring(3,5);
			}
			else if ( fValue.length < 5 )
			{
				f.value=fValue.substring(0,3)+"-"+fValue.substring(3,5);
			}
			else if ( cursor == 6 )
			{
				cursor=7;
				f.value=fValue.substring(0,3)+"-"+fValue.substring(3,5)+"-"+fValue.substring(5,9);
			}
			else
			{
				f.value=fValue.substring(0,3)+"-"+fValue.substring(3,5)+"-"+fValue.substring(5,9);
			}
		}
		else if ( t == "dob" )
		{
			if ( fValue.length < 2 )
			{
				f.value=fValue;
			}
			else if ( cursor == 2 )
			{
				cursor=3;
				f.value=fValue.substring(0,2)+"-"+fValue.substring(2,4);
			}
			else if ( fValue.length < 4 )
			{
				f.value=fValue.substring(0,2)+"-"+fValue.substring(2,4);
			}
			else if ( cursor == 5 )
			{
				cursor=6;
				f.value=fValue.substring(0,2)+"-"+fValue.substring(2,4)+"-"+fValue.substring(4,8);
			}
			else
			{
				f.value=fValue.substring(0,2)+"-"+fValue.substring(2,4)+"-"+fValue.substring(4,8);
			}
		}
		else if ( t == "emp" )
		{
			if ( cursor == 1 || cursor == 2 || cursor == 3 )
			{
				f.value=fValue.toUpperCase();
			}
			else
			{
				f.value=fValue;
			}
		}
		moveSelection(f,cursor);
	}
}
function setNum(f,t){
	if ( f.value )
	{
		if ( t == "phn" )
		{
			var reg = /\d\d\d-\d\d\d-\d\d\d\d/;
			if ( f.value.length != 12 )
			{
				alert("Please use proper format for Phone #\n\n111-111-1111");
				f.select();
			}
			else if ( ! f.value.match(reg) )
			{
				alert("Please use proper format for Phone #\n\n111-111-1111");
				f.select();
			}
		}
		else if ( t == "soc" )
		{
			var reg = /\d\d\d-\d\d-\d\d\d\d/;
			if ( f.value.length != 11 )
			{
				alert("Please use proper format for Social #\n\n111-11-1111");
				f.select();
			}
			else if ( ! f.value.match(reg) )
			{
				alert("Please use proper format for Social #\n\n111-11-1111");
				f.select();
			}
		}
		else if ( t == "dob" )
		{
			var reg = /\d\d-\d\d-\d\d\d\d/;
			if ( f.value.length != 10 )
			{
				alert("Please use proper format for Date of Birth\n\n11-11-1111");
				f.select();
			}
			else if ( ! f.value.match(reg) )
			{
				alert("Please use proper format for Date of Birth\n\n11-11-1111");
				f.select();
			}
		}
		else if ( t == "zip" )
		{
			if ( f.value.length != 5 )
			{
				alert("Please use proper format for Zip\n\n11111");
				f.select();
			}
		}
		else if ( t == "emp" )
		{
			var reg = /\D\D\D\d{6,}/;
			if ( ! f.value.match(reg) )
			{
				f.value="";
			}
		}
	}
}
function moveSelection(o,n)
{
	o.focus()
	var V = o.value
	o.value = ''
	o.value = V
	var L = n
	if ( o.setSelectionRange )
	{
		o.setSelectionRange(L, L)
	}
	else if ( o.createTextRange )
	{
		var range = o.createTextRange()
		range.collapse(true)
		range.moveEnd('character', L)
		range.moveStart('character', L)
		range.select();
	}
}
function getSelectionStart(o)
{
	if (o.createTextRange)
	{
		var r = document.selection.createRange().duplicate()
		r.moveEnd('character', o.value.length)
		if (r.text == '') return o.value.length
		return o.value.lastIndexOf(r.text)
	}
	else
	{
		return o.selectionStart
	}
}

function getSelectionEnd(o)
{
	if (o.createTextRange) {
		var r = document.selection.createRange().duplicate()
		r.moveStart('character', -o.value.length)
		return r.text.length
	}
	else
	{
		return o.selectionEnd
	}
}
