// BEGIN BROWSER SNIFF / STYLESHEET SNIFF
// *************************************************************
//  GLOBAL VARIABLES.
// *************************************************************
var __global = 1;	//Define the global script
var __util = 1;	    //Define the until script
var __childWindows = new Array();

// *************************************************************
//  CLIENT_SIDE SNIFFER CODE
// *************************************************************
// convert all characters to lowercase to simplify testing 
var agt=navigator.userAgent.toLowerCase(); 

// *** BROWSER VERSION *** 
// Note: On IE5, these return 4, so use is_ie5up to detect IE5. 
var is_major = parseInt(navigator.appVersion); 
var is_minor = parseFloat(navigator.appVersion); 

// *** BROWSER TYPE *** 
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) 
            && (agt.indexOf('webtv')==-1));
var is_nav4up = (is_nav && (is_major >= 4));  
var is_nav6up = (is_nav && (is_major > 4));
var is_ie   = (agt.indexOf("msie") != -1); 
var is_ie3  = (is_ie && (is_major < 4)); 
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) && (agt.indexOf("msie 6.0")==-1));
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1));  
var is_ie6  = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.0")!=-1));
var is_ie4up = (is_ie  && !is_ie3);
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);  

// *** PLATFORM ***
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac    = (agt.indexOf("mac")!=-1);


// *********************************************************************
// ARRAY FUNCTIONS
// *********************************************************************



function checkemail(pEmail) {
	var testresults
	var str = pEmail;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		testresults = true;
	else {
		testresults=false;
	}
	return (testresults);
}
function ArrayIndexOf(a, value)
{
	var index = -1;
	if (a != null && a.length != 0)
	{		
		for (i=0, j=a.length; i<j && index == -1; i++)
		{
			if (a[i] == value)
				index = i;
		}
	}
	return index;
}

function ArrayRemoveAt(a, index)
{
	if (a == null || a.length == 0 || index < 0 || index >= a.length)
	{
		return false;
	}
	else
	{
		a[index] = a[a.length-1];
		a.pop();
		return true;
	}
}

// *********************************************************************
// STRING FUNCTIONS
// *********************************************************************

function IsStringOfDigits(s)
{
	if ((s==null) || (s.length==0))
		return false;
	else
	{
		var ch;
		for (i=0, j=s.length; i<j; i++)
		{
			ch = s.charAt(i);
			if ((ch<'0') || (ch>'9'))
			{
				return false;
			}
		}
		
		return true;
	}
}

function IsStringOfDigits2(s, l)
{
	if ((s==null) || (s.length!=l))
		return false;
	else
	{
		var ch;
		for (i=0, j=s.length; i<j; i++)
		{
			ch = s.charAt(i);
			if ((ch<'0') || (ch>'9'))
			{
				return false;
			}
		}
		
		return true;
	}
}

function IsKeyPressedDigit()
{
	if (event != null)
	{
		return (event.keyCode >= 48 && event.keyCode <= 57);
	}
	else {return true;}
}

function PCase(s)
{
	var c;
	var cc;
	var result = "";
	var upper = true;
	var l = s.length;

	if (l > 0)
	{	
		s = s.toLowerCase();
		for (i=0, j=l; i<j; i++)
		{	
			c = s.charAt(i);
			cc = s.charCodeAt(i);
			result += (upper ? c.toUpperCase() : c);
			
			if ((cc == 99 || cc == 67) && (i>0) &&
				(s.charCodeAt(i-1)==77 || s.charCodeAt(i-1)==109))
			{
				upper = true;
			}
			else
			{
				upper = ((cc == 32) || (cc == 45) || (cc == 46));
			}
		}
	}
	return result;
}

function PCaseInput(src)
{
	if (src != null && src.value)
	{
		src.value = PCase(src.value);
	}
}

function GetDocumentClientID()
{
	return (document.forms[0].DocumentClientID.value);
	
}

// *********************************************************************
// ELEMENT FUNCTIONS
// *********************************************************************
function HideElement(element)
{
	if (element != null)
	{
		element.style.visibility = "hidden";
		element.style.position = "absolute";
	}
}

function ShowElement(element)
{
	if (element != null)
	{
		element.style.visibility = "visible";
		element.style.position = "";
	}
}

function GetElementLeft(element)
{
	var left = element.offsetLeft;
	
	while ((element.offsetParent != "undefined") && (element.offsetParent != null))
	{
		element = element.offsetParent;
		left += element.offsetLeft;
	}
	
	return left;
}

function GetElementTop(element)
{
	var top = element.offsetTop;
	
	while ((element.offsetParent != "undefined") && (element.offsetParent != null))
	{
		element = element.offsetParent;
		top += element.offsetTop;
	}
	
	return top;
}

function AddElementToForm(elementstr)
{
	var elem = document.createElement(elementstr);
	document.forms[0].insertBefore(elem);
}

// *********************************************************************
// WINDOW FUNCTIONS
// *********************************************************************
function ShowDialog(url, name, width, height, resizable)
{
	var features = "height=" + height
		+ ",width=" + width
		+ ",resizable=" + resizable
		+ ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,directories=no";
	if ((__global == 1) && (is_ie4up))
	{
		features = features
			+ ",left=" + ((screen.availWidth-width)/2)
			+ ",top=" + ((screen.availHeight-height-20)/2)
	}	
	__childWindows[name] = window.open(url, name, features);
	return __childWindows[name];
}

function ShowDialogWithToolbar(url, name, width, height, resizable)
{
	var features = "height=" + height
		+ ",width=" + width
		+ ",resizable=" + resizable
		+ ",status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes,directories=no";
	if ((__global == 1) && (is_ie4up))
	{
		features = features
			+ ",left=" + ((screen.availWidth-width)/2)
			+ ",top=" + ((screen.availHeight-height-20)/2)
	}
	__childWindows[name] = window.open(url, name, features);	
	return __childWindows[name];
}

function CloseAllChildWindows()
{
	var child;
	for (key in __childWindows)
	{
		child = __childWindows[key];
		if ((child != null) && !child.closed)
		{
			child.close();
			__childWindows[key] = null;
		}
	}
}

function AddQueryString(argToAdd, valueToAdd)
{
	var qstring = window.location.pathname.split('?');
}

// *********************************************************************
// FORM FUNCTIONS
// *********************************************************************
// Autotabs between multi-field input values
function AutoTab(input,len, e) {
	var keyCode = (is_nav) ? e.which : e.keyCode; 
	var filter = (is_nav) ? [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();
	}

	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;
}

// test if the keycode of the key pressed is in a filter array
function InKeySet(e, filter)
{
	if ((filter != null) && (filter.length != 0))
	{
		var found = false;
		var keyCode = (is_nav) ? e.which : e.keyCode;
		for (i=0, j=filter.length; i<j && !found; i++)
			if (filter[i] == keyCode)
				found = true;
		return found;
	}
	return true;
}

// test if the keycode of the key pressed is between mix and max
function InKeyRange(e, min, max)
{
	if (min == null)
		min = 0;
	
	if (max == null)
		max = 65000;
	
	if (max < min)
	{
		var tmp = min;
		min = max;
		max = tmp;
	}
	
	var keyCode = (is_nav) ? e.which : e.keyCode;
	return ((min <= keyCode) && (keyCode <= max));
}

function IsControlKey(e)
{
	var keyCode = (is_nav) ? e.which : e.keyCode;
	return (keyCode == 8) || (keyCode == 0);
}

// test if the keycode of the key pressed is a numeric key 0-9
function IsNumericKey(e)
{
	return InKeyRange(e, 48, 57);
	var keyCode = (is_nav) ? e.which : e.keyCode;
	return ((keyCode == 8) || (keyCode == 0) || (48<=keyCode) && (keyCode<=57));
}
		
function IsNumericWithNegKey(e)
{							  
	return IsNumericKey(e) || IsNegKey(e);
}

// test if the keycode of the key pressed is a numeric key 0-9 or decimal point
function IsNumericDecimalPointKey(e)
{
	return IsNumericKey(e) || IsDecimalPointKey(e);
}

// test if the keycode of the key pressed is an alphabet, a-z or A-Z
function IsAlphaKey(e)
{
	var keyCode = (is_nav) ? e.which : e.keyCode;
	return ((keyCode == 8) || (keyCode == 0) || ((97<=keyCode) && (keyCode<=122)) || ((65<=keyCode) && (keyCode<=90)));
}

function IsAlphaSpaceKey(e)
{
	var keyCode = (is_nav) ? e.which : e.keyCode;
	return ((keyCode == 8) || (keyCode == 0) || (keyCode == 32) || ((97<=keyCode) && (keyCode<=122)) || ((65<=keyCode) && (keyCode<=90)));
}

// test if the keycode of the key pressed is in a-z or A-Z, or 0-9
function IsAlphaNumericKey(e)
{
	return IsAlphaKey(e) || IsNumericKey(e) || IsControlKey(e);
}

// test if the keycode of the key pressed is in a-z or A-Z, or 0-9
function IsAlphaNumericSpaceKey(e)
{
	return IsAlphaSpaceKey(e) || IsNumericKey(e) || IsControlKey(e);
}

// test if the keycode of the key pressed is in a-z
function IsLCaseAlphaKey(e)
{
	return InKeyRange(e, 97, 122) || IsControlKey(e);
}

// test if the keycode of the key pressed is in A-Z
function IsUCaseAlphaKey(e)
{
	return InKeyRange(e, 65, 90) || IsControlKey(e);
}

function IsSpaceKey(e)
{
	return (((is_nav) ? e.which : e.keyCode) == 32);
}

function IsNegKey(e)
{
	return (((is_nav) ? e.which : e.keyCode) == 45);
}

function IsDecimalPointKey(e)
{
	return (((is_nav) ? e.which : e.keyCode) == 46);
}

function IsValidNameKey(e)
{
	return (IsAlphaSpaceKey(e) || InKeySet(e,[39,45,46]) || IsControlKey(e));
}

function IsValidAddressKey(e)
{
	return (IsAlphaNumericSpaceKey(e) || InKeySet(e,[39,45,46,47]) || IsControlKey(e));
}


function alertDelete()
{

 var msg;
 msg=confirm("Are you sure you want to delete this database??");
 if (msg)
 {
 
 return true;
 }
 else
 {
 
 return false;
 
 
 }
 
 
 
 



}

//******************************   mainentry.asp validations:  *********//
  function getTimeOnLoad()
  {
       earlierdate=earlierdate.getTime();
  }
function timeDifference() {
    var laterdate=new Date();
    
    var difference = laterdate.getTime() - earlierdate;

    var minutesDifference = Math.floor(difference/1000/60);
    difference -= minutesDifference*1000*60;
    var secondsDifference = Math.floor(difference/1000);
 
    if (gCounter==1)
    {  
        if (minutesDifference<8)
        {
           alert("Warning: It appears that you have rushed through the survey.  Please take your time and consider each question carefully to avoid being disqualified.  Once you have reviewed your responses, please click the Submit Survey button again.");
           gCounter=gCounter+1;
           return false;
         }
    }
    else
    {
    return true;
    }   
     
} 





function Trim(strInput)
{
	var l_Exp = /^\s*/;
  	var r_Exp = /\s*$/;
	
  	strInput = strInput.replace(l_Exp, "");
  	strInput = strInput.replace(r_Exp, "");
	return strInput;
}
// This function will validate the input to make sure it contains nothing but
// numbers from "0-9",  "," and "." only.
function IsDigits(strNumber)
{
    var strDigits = "1234567890.%";
	var blnIsDigits = true;
	
	for (i=0; i<strNumber.length; i++)
	{
		var strFirstLetter = strNumber.charAt(i);
		if (strDigits.indexOf(strFirstLetter) == -1)
		{
			blnIsDigits = false;
			break;
		}
	}
	return blnIsDigits;
}
function isN(t,f,v,Q)
{
    //this function filters the non numeric inputs 

    var re = /^[0123456789]*$/; 
    if (!re.test(v))
    {
        alert("Value must be all numeric characters, non numerics removed from field!");
        t.value = v.replace(/[^0123456789]/g,"");
    }
    //calculate(f,Q);//call the calculate function
    return false;
}

function isNdot(t,f,v,Q)
{
    //this function filters the non numeric inputs 

    var re = /^[0123456789.]*$/; 
    if (!re.test(v))
    {
        alert("Value must be all numeric characters, non numerics removed from field!");
        t.value = v.replace(/[^0123456789]/g,"");
    }
    //calculate(f,Q);//call the calculate function
    return false;
}

function HideAlert()
{
//alert('hide');


}

function ShowAlert()
{
//document.getElementById("content").innerHtml="<font color=red><b>Dial country code without 001</b></font>";

}
function hidediv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('dhtmltooltip').style.visibility = 'hidden';
document.getElementById('dhtmltooltip').style.left=document.getElementById("ctl00_MainContent_PhoneNumber").style.left;
 
}
else {
if (document.layers) { // Netscape 4
document.hideshow.visibility = 'hidden';
}
else { // IE 4
document.all.hideshow.style.visibility = 'hidden';
}
}
}

function showdiv() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('dhtmltooltip').style.visibility = 'visible';
 
}
else {
if (document.layers) { // Netscape 4
document.hideshow.visibility = 'visible';

}
else { // IE 4
document.all.hideshow.style.visibility = 'visible';
}
}
} 

function DeleteZeros()
{

var Phone=document.getElementById("ctl00_MainContent_PhoneNumber");


Phone=Phone.value;

firstChar=Phone.substring(0,1);

if (firstChar=='0')
{

//ddrivetip('JavaScriptKit.com JavaScript tutorials', 300);
//document.getElementById("dhtmltooltip").style.visibility="visible";
 showdiv();
//document.getElementById("dhtmlpointer").style.visibility="visible";
var phoneValue=document.aspnetForm.ctl00_MainContent_PhoneNumber.value;
document.aspnetForm.ctl00_MainContent_PhoneNumber.value=phoneValue.substring(1,eval(phoneValue.length));

}
else
{
//hideddrivetip();
hidediv();
//document.getElementById("dhtmltooltip").style.visibility="hidden";
//document.getElementById("dhtmlpointer").style.visibility="hidden";
}


}