// ===================================================================
// Author: Brian Lonardo and Corey Christensen
// Date:  7/1/02
// Here you'll find all AOC created Javascript functions for this site
// ===================================================================




// Start functions


function win(fileName) {
     myWin = window.open('','myWindow','scrollbars=no,directories=no,status=no,resizable=no,toolbar=no,copyhistory=no,location=no,menubar=no,width=500,height=400,scrollbars=yes,top=10,left=10')
     myWin.location.href = fileName;
}
			function launch(url) {
			  self.name = "opener";
			  remote = open(url, "remote", "scrollbars,width=500,height=300,left=0,top=0");
			}
function printwin(fileName) {
     myWin = window.open('','myWindow','scrollbars=no,directories=no,status=no,resizable=no,toolbar=no,copyhistory=no,location=no,menubar=no,width=500,height=400,scrollbars=yes,top=10,left=10')
     myWin.location.href = fileName;
}
			function launch(url) {
			  self.name = "opener";
			  remote = open(url, "remote", "scrollbars,width=500,height=400,left=0,top=0");
			}
			
			
			
	function disp1(){
		var mymonth=document.calendarform.month.options[document.calendarform.month.selectedIndex].value;
		var myyear=document.calendarform.year.options[document.calendarform.year.selectedIndex].value;
		window.location="?fa=calendar.home.cfm&year="+myyear+"&month="+mymonth;
	}
	function disp2(){
		var mymonth=document.calendarform.month.options[document.calendarform.month.selectedIndex].value;
		var myyear=document.calendarform.year.options[document.calendarform.year.selectedIndex].value;	
		window.location="?fa=calendar.home.cfm&year="+myyear+"&month="+mymonth;
	}
	
	function clearText(thefield)
	{
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
	} 
	
	function openWindow(url, name, w, h) 
	{ popupWin = window.open(url, name, 'width=380,height=320'); }
	


// OpenFullWindow() for opening window Popup Pages
	function openFullWindow(url, name, w, h) 
	{ 
		popupWin = window.open('https://www.courts.wa.gov/proseforms/login/login.cfm', name, 'scrollbars=no,directories=no,status=no,resizable=no,toolbar=no,copyhistory=no,location=no,menubar=no,width=780,height=500,scrollbars=yes,top=10,left=10'); 
	}

// launchExteral(URL) for opening external Popup Pages
	function launchexternal(url)  {
  self.name = "opener";
 remote = open(url, "remote", "directories=0,location,menubar=0,titlebar=0,resizable,scrollbars=0,status=0,toolbar=0,width=780,height=680,left=5,top=5");
}
	
// closeDep() for closing external Popup Pages
	function closeDep() 
	{
		if (remote && remote.open && !remote.closed) remote.close();
	}


// launchContract(URL) for opening external Popup Click Through Agreement
	function launchContract(url,readFlg) 
	{
		with( document.forms[0] )
		alert(readFlg + " currently " + document.forms[0].elements[readFlg].checked + " to be set indicating the agreement is read");
		document.forms[0].elements[readFlg].checked=1;
		alert(readFlg + " currently " + document.forms[0].elements[readFlg].checked + " to be set indicating the agreement is read");
		self.name = "opener"; 
		remote = open(url, "remote", "scrollbars,width=793,height=550,left=0,top=0");
	}


// ChkAgreement(grouplist) for validation of Data Dissemination submission Page
	function chkAgreement(groupList)
	{
	with( document.forms[0] )
		{

		if(elements['requestDesc'].value.length == 0)
			{
			alert("Request Description is a required field")
			return false;
			}
		else 
			{
				if (groupList !='Guest')

				{
					return true;
				}
				else
				{
					if (elements[ 'acceptAgreement' ].checked)

					{
						return true;
					}
					else
					{
						if (confirm ("By clicking OK you:\n* Agree to use and distribute the information only as provided in the above referenced statement of intended use;\n* Agree not to use for commercial purposes(Data Dissemination Policy IIIA(5));\n* Agree to take reasonable precautions to prevent disclosure of information beyond the above referenced statement of intended use;\n* Agree to pay, unless payment is waived, the cost upon fulfillment of the request and receipt of an invoice from the Administrator's Office for the Courts;\n* Understand that the Administrator's Office for the Courts makes no representation as to the accuracy and completeness of the data except for court purposes and agree to indemnify and hold harmless the Administrator's Office for the Courts from any claims for damages arising from applicant's use and distribution of the information; and\n* Certify, under penalty of law, that all the information supplied herein is true and a complete description."))
						{
						return true;
						}
						else
						{
						alert("By not agreeing to the terms you may not continue.\nIf you cannot agree to the terms, then use the Cancel button on the form to exit.")
						return false;
						}
					}
				}
			}
		}
	}
// validateCurrency(object,num) validate currency input
	function validateCurrency(colName,num) 
	{
		with( document.forms[0] )
		if(formatCurrency(num) == '-$1.00')
			{
			msg=num + " not a valid amount for " + colName
//			msg=document.forms[0].elements[colName].tabIndex + " table index for " + colName
			
			document.forms[0].elements[colName].focus();
			document.forms[0].elements[colName].select();
			alert(msg)			
			return true;
			}
		else
			{
			document.forms[0].elements[colName].value =formatCurrency(num)
			return true;
			}
	}
// formatCurrency(num) format currency output
	function formatCurrency(num) 
	{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "-1";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
	}
	
// validatePctg(num) validate currency input
	function validatePctg(colName,num) 
	{
		if(formatPctg(num) == '0.00%')
			{
			msg=num + " not a valid amount pctg for " + colName
			document.forms[0].elements[colName].focus();
			document.forms[0].elements[colName].select();
			alert(msg)
			return false;
			}
		else
			{
			document.forms[0].elements[colName].value =formatPctg(num)
			return true;
			}
	}
// formatPctg(num) format pctg output
	function formatPctg(num) 
	{
	num = num.toString().replace(/\%|\,/g,'');
	if(isNaN(num))
	{
	num = "0";
	}
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents + '%');
	}
function CheckNumeric()
{
   // Get ASCII value of key that user pressed
   var key = window.event.keyCode;

   // Was key that was pressed a decimal point or numeric character (. or 0-9)?
   if ( key == 46 || (key > 47 && key < 58 )) 
      return; // if so, do nothing
	else
      window.event.returnValue = null; // otherwise, 
	                               // discard character
}

function CheckNumeral()
{
   // Get ASCII value of key that user pressed
   var key = window.event.keyCode;

   // Was key that was pressed a decimal point or numeric character (. or 0-9)?
   if (key > 47 && key < 58 )
      return; // if so, do nothing
	else
      window.event.returnValue = null; // otherwise, 
	                               // discard character
}



// 	function dofocus()
//{	document.#formname#.#fieldname#.focus();}

// Function to Set a field value based on Combo Box selection 
// Used for Court Forms Maint. 
 	function CheckValue()
	{
		{
			//alert("Combo Box Value = " + document.forms[0].Group_Type.value);
			//Clear Action Fields In case user changes combo back and forth
			document.forms[0].File_Type.value = ''
			document.forms[0].File_Type.disabled = false
			document.forms[0].Group_Title.value = ''
			document.forms[0].Group_Title.disabled = false
			
			if (document.forms[0].Group_Type.value == 7) 
				{
				document.forms[0].Group_Title.value = 'Form File Type'
				document.forms[0].Group_Title.disabled = true
				}
			else 
				{
				if (document.forms[0].Group_Type.value == 2) {  //Self Help Type
				document.forms[0].File_Type.value = 'Self Help'
				document.forms[0].File_Type.disabled = true
				}
				} //end else
				document.forms[0].CategoryID.focus()
				return true;
		}		
	}
// validateNumber(num) validate number input
	function validateNumber(colName,val,precision) 
	{
		if  (isNaN(val))
			{
			msg=" Value " + val + " Must Be Numeric for: " + colName
			document.forms[0].elements[colName].focus();
			document.forms[0].elements[colName].select();
			alert(msg)
			return false;
			}
		else
			{
			if ((val.length) == 0)
				{
					val = 0;
				}
			document.forms[0].elements[colName].value = formatFloat(val,precision)
			return true;
			}
	}

// validateInteger(num) validate number input
	function validateInteger(colName,val) 
	{
		if  (isNaN(val))
			{
			msg=" Value " + val + " Must Be Numeric for: " + colName
			document.forms[0].elements[colName].focus();
			document.forms[0].elements[colName].select();
			alert(msg)
			return false;
			}
		else
			{
			if ((val.length) == 0)
				{
					val = 0;
				}
			document.forms[0].elements[colName].value =parseInt(val)
			return true;
			}
	}

// formatFloat(num) format float output
	function formatFloat(num,precision) 
	{
	num = num.toString().replace(/\,/g,'');
	if(isNaN(num))
	{
	num = "0";
	}
	sign = (num == (num = Math.abs(num)));
	var tenStr = "1"
	while (tenStr.length <=precision){
		tenStr = tenStr + "0"
	}
	var tenNum = tenStr - 0
	num = Math.floor(num*tenNum+0.50000000001);
//	fract = num%tenNum;
	numStr = num.toString();
	fract = numStr.substring(1+precision,numStr.length-precision);
	num = Math.floor(num/tenNum).toString();
	if(precision > 0)
	{
		fract = "." + fract.toString();
	}
	else
	{
		fract="";
	}
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + fract );
	}

	
//<!--- chkEmail. copied from the CartEase package. -vsa --->
	function chkEmail(colName,eMail,ctlFlg) 
	{
		var chkFlg = true;
		if (eMail.length > 0) {
			if (eMail.indexOf('@') == -1) {
			alert("No @ sign detected.  An @ sign is part of every e-mail address.");
			chkFlg = false
			}	else if (eMail.search('@') == (eMail.length-1)) {
			alert("An @ sign cannot be the last character of an e-mail address.");
			chkFlg = false
			}	else if (eMail.search("@")== 0) {
			alert("An @ sign cannot be the first character of an e-mail address.");
			chkFlg = false
			}	else if (eMail.indexOf('.')== -1) {
			alert("No period detected.  A valid e-mail address must contain at least one period.");
			chkFlg = false
			}	else if (eMail.lastIndexOf('.') == (eMail.length -1)) {
			alert("A period cannot be the last character of an e-mail address.");
			chkFlg = false
			}	else if (eMail.indexOf(".")== 0) {
			alert("A period cannot be the first character of an e-mail address.");
			chkFlg = false
			}	else if (eMail.search(',') > -1) {
			alert("A valid e-mail address cannot contain any commas.");
			chkFlg = false
			}	else if (eMail.indexOf('*') > -1) {
			alert("A valid e-mail address cannot contain any asterisks.");
			chkFlg = false
			}	else if (eMail.indexOf(')') > -1) {
			alert("A valid e-mail address cannot contain any right parentheses.");
			chkFlg = false
			}	else if (eMail.indexOf('(') > -1) {
			alert("A valid e-mail address cannot contain any left parentheses.");
			chkFlg = false
			}	else if (eMail.indexOf('>') > -1) {
			alert("A valid e-mail address cannot contain a 'greater than' sign.");
			chkFlg = false
			}	else if (eMail.search('\<') > -1) {
			alert("A valid e-mail address cannot contain a 'less than' sign.");
			chkFlg = false
			}	else if (eMail.search('\:') > -1) {
			alert("A valid e-mail address cannot contain a colon.");
			chkFlg = false
			}	else if (eMail.search('\;') > -1) {
			alert("A valid e-mail address cannot contain a semi-colon.");
			chkFlg = false
			}	else if (eMail.search('\ ') > -1) {
			alert("A valid e-mail address cannot contain any spaces.");
			chkFlg = false
			}	else if (eMail.search('\"') > -1) {
			alert("A valid e-mail address cannot contain quotation marks.");
			chkFlg = false
			}	else if (eMail.indexOf('@')>=0)	{
					var ndx = eMail.indexOf('@');
					if (eMail.indexOf('@',ndx+1) > 0)	{
						alert("A valid e-mail address can contain only one @ sign.");
						chkFlg = false
					}
			}	else {
			return true
			}
		}
		else if (ctlFlg==1)
		{
 		alert("E-mail address is required");
		chkFlg = false;
		}
		
		if (chkFlg == false){
			document.forms[0].elements[colName].focus();
			document.forms[0].elements[colName].select();
			return false
		}
	}
	
// added by ferd 11/20/03 checkiing for double submit
var submitcount=0;
function checkFields() {                      
   if (submitcount == 0)
      {
      submitcount++;
      return true;
      }
   else 
      {
      alert("This search has already been submitted.  Thanks!");
      return false;
      }
   }
   
//added by Corey 05/07/04 checking for credit card shipping screen
<!--//
function show(layerid) {
if (document.all){
layerid.style.visibility="visible"
}
else
if(document.layers){
layerid.visibility="show"
}
} 
function hide(layerid){ 
if (document.all){ 
layerid.style.visibility="hidden"
}
else
if(document.layers){
layerid.visibility="hide"
}
} 

//  End -->



