var ns4 = (document.layers?true:false);
var ie4 = (document.all?true:false);
var ns7 = (document.getElementById?true:false);

with (document) 
{
	write("<STYLE TYPE='text/css'>");
    if (ns4 || ns7) 
    {
        write(".openI {position:absolute; visibility:visible;}");
        write(".closeI {position:absolute; visibility:hidden;}");
    }
    else {
           write(".closeI {display:none}")
    }
    write("</STYLE>");
}

function getLayer(pLayer) {
	if (ns7) return document.getElementById(pLayer);
	else if (ie4) return eval('document.all.' + pLayer);
	else if (ns4) return eval('document.' + pLayer);
}

function setLayerTop(pLayer, pTop) {
		if (ie4) getLayer(pLayer).style.pixelTop = pTop;
		if (ns4) getLayer(pLayer).top = pTop;
		if (ns7) getLayer(pLayer).style.top = pTop;
}
function setLayerLeft(pLayer, pLeft) {
		if (ie4) getLayer(pLayer).style.pixelLeft = pLeft;
		if (ns4) getLayer(pLayer).left = pLeft;
		if (ns7) getLayer(pLayer).style.left = pLeft;
}
function setLayerVisibility(pLayer,pVisible) { 
	lVisible = pVisible?(ie4 || ns7)?"visible":"show":(ie4 || ns7)?"hidden":"hide";
	if (ie4 || ns7) getLayer(pLayer).style.visibility = lVisible;
	if (ns4) getLayer(pLayer).visibility = lVisible;
}

function OpenDiv(strDivOpen)
{
	setLayerVisibility(strDivOpen,true);
}

function CloseDiv(DivClose)
{
	setLayerVisibility(DivClose,false);
}

function OpenWindow(HtmlPage, WinType)
{
	if (HtmlPage.indexOf("?") < 0)
		{HtmlPage += "?";}
	else
		{HtmlPage += "&";}
		
	HtmlPage += "PIDII="+document.thisForm.ztextpageidii.value+"&SHID="+document.thisForm.ztextsession.value;
//	alert(HtmlPage);
	if (WinType == 1) {
		NewWindow = window.open(HtmlPage, 'LocxWineWindow');
		NewWindow.focus();
		return;
	}
	location.href = HtmlPage;
}
function openwindow(HtmlPage, WinType)
{
	if (WinType == 1) {
		NewWindow = window.open(HtmlPage, 'LocxWineWindow');
		NewWindow.focus();
		return;
	}
	if (HtmlPage.indexOf("?") < 0)
	{HtmlPage += "?";}
	else
	{HtmlPage += "&";}
	HtmlPage += "PIDII="+document.thisForm.ztextpageidii.value+"&SHID="+document.thisForm.ztextsession.value;
	location.href = HtmlPage;
}
function OpenIt(HtmlPage)
{
	if (HtmlPage.indexOf("?") < 0)
	{HtmlPage += "?";}
	else
	{HtmlPage += "&";}
	HtmlPage += "PIDII="+document.thisForm.ztextpageidii.value+"&SHID="+document.thisForm.ztextsession.value;

	NewWindow = window.open(HtmlPage, 'LocxWine1Window','location=no,directories=no,status=no,resizable=yes,scrollbars=yes');
	NewWindow.focus();
	return;
}
function OpenIt2(HtmlPage)
{
	if (HtmlPage.indexOf("?") < 0)
		{HtmlPage += "?";}
	else
		{HtmlPage += "&";}
	HtmlPage += "PIDII="+document.thisForm.ztextpageidii.value+"&SHID="+document.thisForm.ztextsession.value;

	NewWindow = window.open(HtmlPage, 'LocxWine2Window','location=no,directories=no,status=no,resizable=yes,scrollbars=yes');
	NewWindow.focus();
	return;
}
function OpenIt3(HtmlPage)
{
	if (HtmlPage.indexOf("?") < 0)
		{HtmlPage += "?";}
	else
		{HtmlPage += "&";}
	HtmlPage += "PIDII="+document.thisForm.ztextpageidii.value+"&SHID="+document.thisForm.ztextsession.value;

	NewWindow = window.open(HtmlPage, 'LocxWine3Window','location=no,directories=no,status=no,resizable=yes,scrollbars=yes');
	NewWindow.focus();
	return;
}
function OpenItW(HtmlPage,strWidth,strHeight)
{
	if (HtmlPage.indexOf("?") < 0)
	{HtmlPage += "?";}
	else
	{HtmlPage += "&";}
	HtmlPage += "PIDII="+document.thisForm.ztextpageidii.value+"&SHID="+document.thisForm.ztextsession.value;

	NewWindow = window.open(HtmlPage, 'LocxWine0Window','width='+strWidth+', height='+strHeight+', location=no,directories=no,status=no,resizable=yes,scrollbars=yes');
	NewWindow.focus();
	return;
}

function ChkThemAll(strDesc,strTextField,strType,strData)
{   
	ThisField = eval(strTextField);
	
	if (ThisField.value=='' || ThisField.value==null)
	{
		if (strData==0)
		{
			alert(strDesc+" is a required field");
			return;
		}
	}
	
	if (strType==1)
	{
		StripThem(strTextField);
		return true;
	}
	if (strType==2)
	{
		StripThem(strTextField);
		ThisField.value = FixName(ThisField.value);
		return true;
	}
	if (strType==3)
	{
		//StripThem(strTextField);
		ThisField.value = FixName(ThisField.value);
		return true;
	}
	if (strType==4)
	{
		StripChr(strTextField,'.0123456789');
		return true;
	}
	if (strType==5)
	{
		StripChr(strTextField,'0123456789');
		return true;
	}
	if (strType==6)
	{
		StripChr(strTextField,'( )-0123456789');
		return true;
	}
	if (strType==7)
	{
		if (ThisField.value!="" && ThisField.value!=null)
		{if (isValidDate(ThisField, ThisField.value))
			{return;}
		}
	}
	if (strType==8)
	{
	if (!EmailChk(ThisField.value))
		{document.thisForm.ThisField.focus();}
	}
	return;
}

function EmailChk(strText)
{
	var regexp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;

    if(strText == null)
		return true;
		
	if(strText == '')
		return true;
   
	if(strText.search(regexp)==-1)
	{
	    alert("Invalid Email Address");
   		return false;
	}
	
	return true;
}

function StripThem(strTextField)

{   
	strTextField = eval(strTextField);
	var i;
    var returnString = "";
	var strTextToRemove = "<>\'%*+&()=;";
	if(strTextField.type == 'textarea')
		strTextToRemove = strTextToRemove.slice(0,11);
	
	var strText = strTextField.value;
    for (i = 0; i < strText.length; i++)
    {
        var c = strText.charAt(i);
        if (strTextToRemove.indexOf(c) == -1) returnString += c;
    }

	strTextField.value = returnString;
    return returnString;
}

function StripChr(strTextField,strTextToRemove)

{   
	strTextField = eval(strTextField);
	var i;
    var returnString = "";

	if(strTextField.type == 'textarea')
		strTextToRemove = strTextToRemove.slice(0,11);
	
	var strText = strTextField.value;
    for (i = 0; i < strText.length; i++)
    {
        var c = strText.charAt(i);
        if (strTextToRemove.indexOf(c) >= 0) returnString += c;
    }

	strTextField.value = returnString;
    return returnString;
}

function StripAlpha(strTextField)

{   
	strTextField = eval(strTextField);
	var i;
    var returnString = "";
	var strTextToRemove = ".0123456789";
	if(strTextField.type == 'textarea')
		strTextToRemove = strTextToRemove.slice(0,11);
	
	var strText = strTextField.value;
    for (i = 0; i < strText.length; i++)
    {
        var c = strText.charAt(i);
        if (strTextToRemove.indexOf(c) >= 0) returnString += c;
    }

	strTextField.value = returnString;
    return returnString;
}

function FixName(strName) 
{
    strName = strName.toLowerCase();
    var c = strName.charAt(0);
    var returnString = c.toUpperCase();
    for (i = 1; i < strName.length; i++)
    {
        c = strName.charAt(i);
        if (c == " "||c==".")
        {
			returnString += c;
	        c = strName.charAt(i+1);
			returnString += c.toUpperCase();
			i++
		}	
		else
		{
			returnString += c;
		}
    }

    return returnString;
}

function ValidDesc(ThisField,strName) {
	if (ThisField.value.length == 0) {
		alert("Please enter a '"+strName+"' before proceeding.");
		ThisField.focus();
		return false;
	}
    var newString = "";
	var strText = ThisField.value;

    for (i = 0; i < strText.length; i++)
    {
        var c = strText.charAt(i);
        if (c!=" ") newString += c;
    }
	if (newString.length == 0) {
		alert("We're sorry, but one or more fields are incomplete or incorrect.\n\nPlease enter a valid "+strName+".");
		ThisField.value = "";
		ThisField.focus();
		return false;
	}
	return true;
}

function ValidNum(ThisField,strName) {
	if (isNaN(ThisField.value) == true) {
		alert(strName+": Value must be numeric.");
		ThisField.focus();
		return false;
	}
	return true;
}
function ValidSize(ThisField,strName, strSize) {
	if (ThisField.value.length < strSize) {
		alert(strName+": Must have at least "+strSize+ " Characters");
		ThisField.focus();
		return false;
	}
	return true;
}
function isValidDate(ThisField, dateStr) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert("Date is not in a valid format.");
		ThisField.focus();
		return false;
	}
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
		ThisField.focus();		
		return false;
	}
	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
		ThisField.focus();		
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!");
		ThisField.focus();		
		return false;
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn't have " + day + " days!");
			ThisField.focus();		
			return false;
		}
	}
	return true;  // date is valid
}

function Chk2Date(strStart,strEnd)
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

	var matchSArray = strStart.match(datePat);
	Smonth = matchSArray[1];
	Sday = matchSArray[3];
	Syear = matchSArray[4];
	if (Syear.length == 2)
		Syear = "20" + Syear

	var matchEArray = strEnd.match(datePat);
	Emonth = matchEArray[1];
	Eday = matchEArray[3];
	Eyear = matchEArray[4];
	if (Eyear.length == 2)
		Eyear = "20" + Eyear
		
	if (parseInt(Eyear) < parseInt(Syear))
	{
		//alert("Years in dates are not correct");
		return false;
	}	
	if (parseInt(Emonth) < parseInt(Smonth) && parseInt(Eyear) == parseInt(Syear))
	{
		//alert("Months in dates are not correct");
		return false;
	}		
	if (parseInt(Eday) < parseInt(Sday) && parseInt(Eyear) == parseInt(Syear) && parseInt(Emonth) == parseInt(Smonth))
	{
		//alert("Days in dates are not correct");
		return false;
	}
	return true;
}

function ChkEDate(strStart,strEnd)
{
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

	var matchSArray = strStart.match(datePat);
	Smonth = matchSArray[1];
	Sday = matchSArray[3];
	Syear = matchSArray[4];
	if (Syear.length == 2)
		Syear = "20" + Syear

	var matchEArray = strEnd.match(datePat);
	Emonth = matchEArray[1];
	Eday = matchEArray[3];
	Eyear = matchEArray[4];
	if (Eyear.length == 2)
		Eyear = "20" + Eyear
		
	if (parseInt(Eyear) < parseInt(Syear))
	{
		//alert("Years in dates are not correct");
		return false;
	}	
	if (parseInt(Emonth) < parseInt(Smonth) && parseInt(Eyear) == parseInt(Syear))
	{
		//alert("Months in dates are not correct");
		return false;
	}		
	if (parseInt(Eday) <= parseInt(Sday) && parseInt(Eyear) == parseInt(Syear) && parseInt(Emonth) == parseInt(Smonth))
	{
		//alert("Days in dates are not correct");
		return false;
	}
	return true;
}

function RadioClicked(strField,strId) {
	strRadio = eval("document.thisForm.c"+strField);
	strRadio.value = strId;
}
function ListCheckAll(strField,strChecked) {
	strList = eval("document.thisForm."+strField+"ct");
	strDetailCt = strList.value;
	for (j=1; j<=strDetailCt; j++)
	{
		strPro = eval("document.thisForm."+strField+j);
		if (strChecked == 0)
			strPro.checked = true;
		else
			strPro.checked = false;
	}
}

function DoSearch() {
	if (document.thisForm.textTopSearch.value.length == 0) {
		alert("Search Text Must have Entry.");
		document.thisForm.textTopSearch.focus();
		return;
	}
	OpenIt("/ResPlus/home/Search/DoSearch.asp?TEXT="+document.thisForm.textTopSearch.value);
}

var zx = 0;
var zy = 0;
var blnclose = 0;

function LoadClock(strMnOut,strSeOut,CloseWindow)
{
       zy = strMnOut;
       zx = strSeOut;
       blnclose = CloseWindow;
       startClock();
}

function startClock()
{
       zx = zx - 1;
       if (zx < 10)
       {zx = "0" + zx;}
       setTimeout("startClock()", 1000);
       window.status = zy + ":" + zx;
       if(zx==0)
       {
               if (zy==0)
               {
                    if(blnclose==1)
                    {
                        parent.opener.window.focus();
	                    window.close();
                    }
                    else
                    {
                       OpenWindow("Default.asp",0);
                       return;
                    }                       
               }
               zy = zy - 1;
               zx = 60;
               window.status = zy + ":" + zx;
               return;
       }
}

function SubmitGreyOn()
{
    document.getElementById('blackout').style.visibility = 'visible';
    document.getElementById('blackout').style.height = document.body.clientHeight;
}

function GreyOn()
{
    var strHeight = document.body.clientHeight;
    if (strHeight < document.documentElement.clientHeight)
    {strHeight = document.documentElement.clientHeight}

	SelfSelectGrey(document.getElementById('thisForm'),true)
    document.getElementById('blackout').style.visibility = 'visible';
    document.getElementById('blackout').style.height = strHeight;
    document.body.style.overflow = 'hidden';
}

function GreyOff()
{
	SelfSelectGrey(document.getElementById('thisForm'),false)
    document.getElementById('blackout').style.visibility = 'hidden';
    document.body.style.overflow = '';
}

function ParentGreyOn()
{
    var strHeight = parent.opener.document.body.clientHeight;
    if (strHeight < parent.opener.document.documentElement.clientHeight)
    {strHeight = parent.opener.document.documentElement.clientHeight}

    parent.opener.document.body.style.overflow = 'hidden';

	SelfSelectGrey(parent.opener.document.getElementById('thisForm'),true)
    parent.opener.document.getElementById('blackout').style.visibility = 'visible';
    parent.opener.document.getElementById('blackout').style.height = strHeight;
}

function ParentGreyOff()
{
	SelfSelectGrey(parent.opener.document.getElementById('thisForm'),false)
    parent.opener.document.getElementById('blackout').style.visibility = 'hidden';
    parent.opener.document.body.style.overflow = '';
}

function SelfSelectGrey(strThisForm,strSwitch)
{
	var els = strThisForm.elements; 
	for(i=0; i<els.length; i++){ 
		if (els[i].type=="select-one")
		{
			els[i].disabled=strSwitch;
		}
	}
}

function onKeyPress () {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	if (keycode == 13) 
	{
		if(typeof(document.thisForm.textTopSearch) == "object")
		{
			if (document.thisForm.textTopSearch.value.length > 0) 
			{
				OpenIt("/ResPlus/home/Search/DoSearch.asp?TEXT="+document.thisForm.textTopSearch.value);
				return false;
			}
		}
		if(typeof(document.thisForm.textPassword0) == "object")
		{
			if (document.thisForm.textPassword0.value.length > 0)
			{Login();
			return false;}
		}
		if(typeof(document.thisForm.textPassword1) == "object")
		{
			if (document.thisForm.textPassword1.value.length > 0)
			{Login();
			return false;}
		}
		if(typeof(document.thisForm.textPassword2) == "object")
		{
			if (document.thisForm.textPassword2.value.length > 0)
			{Login();
			return false;}
		}

	}
return true ;
}
document.onkeypress = onKeyPress;
