//===========================================================================================
//build table from array
//===========================================================================================
function build_table(arrContent,color1,color2,color3,dest_loc)
{
	var build_table_output = "<table>";
	var color;
	var rowContent = new Array;
	for(var i=0;i<arrContent.length;i++)
	{  
		if(i%2==0)   
		{
			color = color1;
		}
		else
		{
		 	color = color2;
		}
		if (i==0) color=color3;
		build_table_output += "<tr bgcolor='" + color + "'>";
		if (i!=0) build_table_output += "<td align='center'><img src='art/delete.jpg' onclick=\"javascript:delete_row_from_table(arrContent,'"+i+"','"+color1+"','"+color2+"','"+color3+"','"+dest_loc+"');\"></td>";
		if (i!=0) build_table_output += "<td align='center'>" + i + "</td>";
		rowContent = arrContent[i].split("|")
		for (var j=0;j<rowContent.length;j++)
		{
			build_table_output += "<td align='center'>" + rowContent[j] + "</td>";
		}  
		build_table_output += "</tr>";
	}
	// Close table
	build_table_output += "</table>";  
	build_table_output += "<input type=hidden name='CopyLocationFee_Array' value='"+arrContent+"'>";  
	
	document.getElementById(dest_loc).innerHTML = build_table_output;
}
function add_row_to_table(arrContent,item_to_add,color1,color2,color3,dest_loc)
{
	//alert(arrContent);
	//alert(item_to_add);
	arrContent[arrContent.length] = item_to_add;
	//alert(document.getElementById('fees_table_data').innerHTML);
	build_table(arrContent,color1,color2,color3,dest_loc);
}
function delete_row_from_table(arrContent,item_to_delete,color1,color2,color3,dest_loc)
{
	//var arrContent = new Array;
	//arrContent =arrContent_temp[0].split(",");
	arrContent.splice(item_to_delete,1);
	build_table(arrContent,color1,color2,color3,dest_loc);
}
//===========================================================================================
//Date Formatting
//===========================================================================================
/*
	Date Format 1.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT license
	With code by Scott Trenda (Z and o flags, and enhanced brevity)
*/

/*** dateFormat
	Accepts a date, a mask, or a date and a mask.
	Returns a formatted version of the given date.
	The date defaults to the current date/time.
	The mask defaults ``"ddd mmm d yyyy HH:MM:ss"``.
*/
var dateFormat = function () {
	var	token        = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloZ]|"[^"]*"|'[^']*'/g,
		timezone     = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (value, length) {
			value = String(value);
			length = parseInt(length) || 2;
			while (value.length < length)
				value = "0" + value;
			return value;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask) {
		// Treat the first argument as a mask if it doesn't contain any numbers
		if (
			arguments.length == 1 &&
			(typeof date == "string" || date instanceof String) &&
			!/\d/.test(date)
		) {
			mask = date;
			date = undefined;
		}

		date = date ? new Date(date) : new Date();
		if (isNaN(date))
			throw "invalid date";

		var dF = dateFormat;
		mask   = String(dF.masks[mask] || mask || dF.masks["default"]);

		var	d = date.getDate(),
			D = date.getDay(),
			m = date.getMonth(),
			y = date.getFullYear(),
			H = date.getHours(),
			M = date.getMinutes(),
			s = date.getSeconds(),
			L = date.getMilliseconds(),
			o = date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4)
			};

		return mask.replace(token, function ($0) {
			return ($0 in flags) ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":       "ddd mmm d yyyy HH:MM:ss",
	shortDate:       "m/d/yyyy",
	mediumDate:      "mmm d, yyyy",
	longDate:        "mmmm d, yyyy",
	fullDate:        "dddd, mmmm d, yyyy",
	shortTime:       "h:MM TT",
	mediumTime:      "h:MM:ss TT",
	longTime:        "h:MM:ss TT Z",
	isoDate:         "yyyy-mm-dd",
	isoTime:         "HH:MM:ss",
	isoDateTime:     "yyyy-mm-dd'T'HH:MM:ss",
	isoFullDateTime: "yyyy-mm-dd'T'HH:MM:ss.lo",
	longdatetime:	 "m/d/yyyy H:MM:ss TT"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask) {
	return dateFormat(this, mask);
}
//===========================================================================================
//toggle visibility on ID based on field value
//===========================================================================================
function check_value(IDa,IDb,field_value)
{
  var e = document.getElementById(IDb);
  if ((e.value == field_value)||(e.checked == true))
  {
  	toggle_display(IDa,'show');  	
  }
  else
  {
    toggle_display(IDa,'hide');
  }
}
function toggle_display(IDa,show_hide)
{
  //if (IDa == "first_only_table") {alert(IDa + ' - ' + show_hide);}
  var browser = navigator.appName;
  var el = document.getElementById(IDa);
  if(browser.indexOf("Netscape")>=0) show_value = 'table-row';
  if(browser.indexOf("Microsoft")>=0) show_value = 'inline';
  if ((show_hide == 'hide')||((show_hide == 'toggle') && (el.style.display==show_value)))
  {
	el.style.display = 'none';
  }
  else
  {
	el.style.display=show_value;
  }
}

//add days to date
function add_days_to_date(sDate,DaystoAdd)
{
  if ((isDate(sDate,"mm/dd/yyyy")) || (isDate(sDate,"M/d/y h:m:s a")))
  {
    var d = new Date(sDate);
	d = new Date(d.getTime() + DaystoAdd*24*60*60*1000);
	return d.formatDate("m/d/Y");
	//d.setDate(d.getDate() +DaystoAdd);
	//alert((d.getMonth()+1)+"/"+d.getDate()+"/"+d.getYear());  
  }
}

//payperiod change
function payperiod_location()
{
	a = document.getElementById('Payperiod')
	b = document.getElementById('PayPeriod_href')
	document.location = b.value + a.options[a.selectedIndex].value;
}
//payperiod change users
function payperiod_locationA()
{
	a = document.getElementById('PayperiodA')
	b = document.getElementById('PayPeriod_hrefA')
	document.location = b.value + a.options[a.selectedIndex].value;
}
//validate payperiod
function validate_payperiod()
{
	alert_msg = "";
	a = document.getElementById('PayPeriod_StartDate')
	b = document.getElementById('PayPeriod_EndDate')
	if (validateDate(a.value, "%m/%d/%yyyy") == false)
	{
		time_in = 0;
		alert_msg = "Start Date is not valid.";
	}
	else
	{
		time_in = 1;
	}
	
	if (validateDate(b.value, "%m/%d/%yyyy") == false)
	{
		time_out = 0;
		if (time_in == 0) alert_msg = alert_msg + "\n";
		alert_msg = alert_msg + "End Date is not valid.";
	}
	else
	{
		time_out = 1;
	}
	if ((time_in == 1) && (time_out == 1))
	{
		if (Date.parse(a.value) > Date.parse(b.value))
		{
			time_in = 0;
			alert_msg = "Start Date is after the End Date.";
		}
	}
	if ((time_in == 0)||(time_out == 0))
	{
		alert(alert_msg);
		return false;
	}
	else
	{
		return true;
	}
	return false;
}


//validate timecard dates
function validate_timecard()
{
	alert_msg = "";
	a = document.getElementById('TimeCard_TimeIn')
	b = document.getElementById('TimeCard_TimeOut')
	if (validateDate(a.value, "%m/%d/%yyyy %h:%mins:%s %ampm") == false)
	{
		time_in = 0;
		alert_msg = "Time In is not valid please use proper formatting ('dd/mm/yyyy hh:mm:ss  ampm')";
	}
	else
	{
		time_in = 1;
	}
	
	if (validateDate(b.value, "%m/%d/%yyyy %h:%mins:%s %ampm") == false)
	{
		time_out = 0;
		if (time_in == 0) alert_msg = alert_msg + "\n";
		alert_msg = alert_msg + "Time Out is not valid please use proper formatting ('dd/mm/yyyy hh:mm:ss  ampm')";
	}
	else
	{
		time_out = 1;
	}
	
	if ((time_in == 1) && (time_out == 1))
	{
		if (Date.parse(a.value) > Date.parse(b.value))
		{
			time_in = 0;
			alert_msg = "Time In is after the Time Out.";
		}
	}
	
	if ((time_in == 0)||(time_out == 0))
	{
		alert(alert_msg);
		return false;
	}
	else
	{
		return true;
	}
	return false;
}

//set field value from cookie
function set_field_value_from_cookie(cookie_name,field_name) 
{
	a = eval('this.form.'+formfield)
	a.value = getCookie(cookie_name);
}

//get cookie value
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

//changes the input box date to offset based on current dropdown value
function statistics_lead_time_change_date(){
	date_offset = this.document.statistics_lead_time_snooze.snooze_delay.value;
	d = new Date();
	day  = d.getDate() + date_offset * 1;
	s = (d.getMonth() + 1) + "/";
	s += day + "/";
	s += d.getYear();
	this.document.statistics_lead_time_snooze.statistics_lead_time_snooze_date.value =  s;
}

//notes_find.asp show associated cities checkbox cookie code
function notes_find_show_only_associated_cities(){
	if (this.document.notes_find.show_only_associated_cities.checked) 
	{
		this.document.notes_find.show_only_associated_cities_hidden.value = "on";
	}
	else
	{
		this.document.notes_find.show_only_associated_cities_hidden.value = "off";
	}
}

//stats lead time snoozed checkbox cookie code
function statistics_lead_time_snoozed_cases(){
	if (this.document.Statistics_Lead_Time.show_snoozed_cases.checked) 
	{
		this.document.Statistics_Lead_Time.show_snoozed_cases_hidden.value = "on";
	}
	else
	{
		this.document.Statistics_Lead_Time.show_snoozed_cases_hidden.value = "off";
	}
}

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDateA(dtStr,field_name){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert(field_name+":The date format for should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert(field_name+":Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert(field_name+":Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert(field_name+":Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert(field_name+":Please enter a valid date")
		return false
	}
return true
}


function verify_permissions(ID) {	
	popupWin = window.open('keyflick_popup.asp'+ID, 'kfpopup','width=300,height=150,status=yes,scrollbars=1,resizable=1,top=100,left=100,location=no');
}
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
function selectlist(formName, formfield) {
a = eval('document.'+formName+'.'+formfield)
for (var i=0; i<a.options.length; i++) {
		a.options[i].selected = true;
		}
}

function changefocus(formName,fieldnum,e) {
	var characterCode 
	var a
	a = eval('document.'+formName)
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e
	characterCode = e.which //character code is contained in NN4's which property
	}
	else{
	e = event
	characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if((characterCode == 13) || (characterCode == 9)){ //if generated character code is equal to ascii 13 (if enter key)
		a[fieldnum].focus(); //tab the form
	return false; 
	}
	else{
	return true 
	
	}
}

function calculate_work_order() {
	document.work_order_add.WorkOrder_Amount.value = '$' + document.work_order_add.WorkOrder_BillableHours.value * document.work_order_add.WorkOrder_Rate.value
	document.work_order_add.WorkOrder_BillableHours.value = document.work_order_add.WorkOrder_BillableHours.value
	document.work_order_add.WorkOrder_Rate.value = document.work_order_add.WorkOrder_Rate.value
	document.work_order_add.Totals.value = document.work_order_add.WorkOrder_Amount.value
}
function calculate_billing(formname) {
   var subtotal_val = 0
   var totals_val = 0
   field_cnt = eval('document.'+formname+'.field_cnt');
   var z_limit = field_cnt.value
   
   for (z=1; z<z_limit; z++){
   	c = eval('document.'+formname+'.c'+z);
	b = eval('document.'+formname+'.b'+z);
	a = eval('document.'+formname+'.a'+z);
	e = eval('document.'+formname+'.e'+z);
	
	b_val = b.value
	b_vala = b_val.indexOf("$")
	if (b_vala >= 0){
		b_val = b_val.substring(1,b_val.length);
		b_val = parseFloat(b_val);
	}
	
	subtotal = eval('document.'+formname+'.subtotal');
	totals = eval('document.'+formname+'.totals');
	balancedue = eval('document.'+formname+'.balancedue');
	credits = eval('document.'+formname+'.credits');
	salestax = eval('document.'+formname+'.salestax');

	c.value = formatCurrency(a.value*b_val);
	b.value = formatCurrency(b_val);
	if (e.value == 'Discount'){
	subtotal_val -= a.value*b_val;
	}else{
	subtotal_val += a.value*b_val;
	}
	
   }
   subtotal.value = formatCurrency(subtotal_val);   
   totals_val = subtotal_val * (1+salestax.value/100);
   //credits.value = formatCurrency(credits.value);
   totals.value = formatCurrency(totals_val);
   if (credits.value.substr(0,1) == '$')
   {
     credits_temp = credits.value.slice(1)
   }
   else
   {
     credits_temp = credits.value
   }
   balancedue.value = formatCurrency(totals_val - parseFloat(credits_temp));
}
function formatCurrency(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 onul() {
	event.returnValue = "You will loose all data if not already saved!";
}

function open_Update_Entity(entityID) {
  popupWin = window.open('entity_add.asp?ID=' + entityID , 'remote1', 'width=450,height=500');
}
function open_Update_Entity_Enc(EncEntityID) {
  popupWin = window.open('entity_add.asp?' + EncEntityID , 'remote1', 'width=450,height=500');
}
function open_RemoteWindow(page) {
  popupWin = window.open(page, 'remote', 'width=750,height=450,scrollbars=1,resizable=1,top=243,left=300');
}
function open_RemoteWindowSized(page,width,height) {
  popupWin = window.open(page, 'remote','width=' + width + ',height=' + height + ',location=no,status=yes,scrollbars=1,resizable=1,top=100,left=100');
}
function open_RemoteWindowSizeda(page,width,height,name) {
  popupWin = window.open(page, name,'width=' + width + ',height=' + height + ',status=yes,scrollbars=1,resizable=1,top=100,left=100');
}
function open_RemoteWindowSizedb(page,width,height,name) {
  popupWin = window.open(page, name,'width=' + width + ',height=' + height + ',status=no,scrollbars=0,resizable=0,top=200,left=200');
}
function open_RemoteWindow_w_value(page, findValue) {
  popupWin = window.open(page+'&findother='+findValue, 'remote', 'location=no,width=750,height=450,scrollbars=1,resizable=1,top=243,left=300');
}
function open_RemoteWindowGeneric(theURL,winName,features) {
window.open(theURL,winName,features);
}
function set_cookie(name, value, expires) {
  if (!expires) expires = new Date();
  document.cookie= name + "=" +escape(value)
  document.cookie.expires = expires
}
function set_cookie_no_encode(name, value, expires) {
  if (!expires) expires = new Date();
  document.cookie= name + "=" +value
  document.cookie.expires = expires
}
function set_cookie_live_notes(name, field, expires) {
  value = eval('document.notes_add.'+field+'.value')
  if (!expires) expires = new Date();
  document.cookie= name + "=" +escape(value)
  document.cookie.expires = expires
}
function set_cookie_live_bill(name, field, expires) {
  value = eval('document.bill_to_add.'+field+'.value')
  if (!expires) expires = new Date();
  document.cookie= name + "=" +escape(value)
  document.cookie.expires = expires
}
function set_cookie_live_ship(name, field, expires) {
  value = eval('document.ship_to_add.'+field+'.value')
  if (!expires) expires = new Date();
  document.cookie= name + "=" +escape(value)
  document.cookie.expires = expires
}
function delete_cookie(name) {
  document.cookie= name + "="
  document.cookie.expires = "01/01/2000"
}
function removevalue(elementName) {
  document.requestor_add[elementName].value = "";
}
function VerifyData_Case() {
	if (document.case_add.Case_Type.value == "") {
		alert("You specify Case Type.");
		return false;
	} else if (document.case_add.Case_SubpoenaType.value == "") {
		alert("You must specify a Subpoena Type.");
		return false;
	} else if (document.case_add.Case_Name.value == "") {
		alert("You must enter a Name.");
		return false;
	} else if (document.case_add.Case_SSN.value == "") {
		alert("You must enter specify a S.S.N.");
		return false;
	} else if (document.case_add.Case_DOB.value == "") {
		alert("You must specify a D.O.B.");
		return false;
	} else if (document.case_add.Case_DOI.value == "") {
		alert("You must specify a D.O.I.");
		return false;
	} else if (document.case_add.Case_Coordinator.value == "") {
		alert("You must specify a Coordinator.");
		return false;
	} else
		return true;
}
function VerifyData_Requestor() {
	if (document.requestor_add.Entity_LawOffice_Name.value == "") {
		alert("You must enter a Law Office.");
		return false;
	} else if (document.requestor_add.Attorney_ID.value == "") {
		alert("You must enter an Attorney.");
		return false;
	} else if (document.requestor_add.Requestor_Representation.value == "") {
		alert("You must specify representation.");
		return false;
	} else
		return true;
}
function VerifyData_Court() {
	if (document.court_add.Entity_CourtName.value == "") {
		alert("You must enter a Court Name.");
		return false;
	} else if (document.court_add.Court_CaseNo.value == "") {
		alert("You must enter a Case Number.");
		return false;
	} else if (document.court_add.Court_Defendants.value == "") {
		alert("You must specify Defendants.");
		return false;
	} else
		return true;
}
function VerifyData_Parties() {
	if (document.parties_add.Entity_LawOffice_Name.value == "") {
		alert("You must enter a Law Office.");
		return false;
	} else if (document.parties_add.Entity_Attorney_Name.value == "") {
		alert("You must enter an Attorney.");
		return false;
	} else if (document.parties_add.Notice.value == "") {
		alert("You must specify Notice.");
		return false;
	} else
		return true;
}
function VerifyData_Statistics_Lead_Time() {
	if (document.Statistics_Lead_Time.statistics_lead_time_date_from.value == "") {
		alert("You must Specify a Start Date");
		document.Statistics_Lead_Time.statistics_lead_time_date_from.focus()
		return false
	}
	if (document.Statistics_Lead_Time.statistics_lead_time_date_from.value != "") {
		if (isDateA(document.Statistics_Lead_Time.statistics_lead_time_date_from.value,"Start Date")==false){
			document.Statistics_Lead_Time.statistics_lead_time_date_from.focus()
			return false
		}
	}
	if (document.Statistics_Lead_Time.statistics_lead_time_date_to.value == "") {
		alert("You must Specify a End Date");
		document.Statistics_Lead_Time.statistics_lead_time_date_to.focus()
		return false
	}
	if (document.Statistics_Lead_Time.statistics_lead_time_date_to.value != "") {
		if (isDateA(document.Statistics_Lead_Time.statistics_lead_time_date_to.value,"End Date")==false){
			document.Statistics_Lead_Time.statistics_lead_time_date_to.focus()
			return false
		}
	}
}
function VerifyData_Statistics_Lead_Time_Snooze() {
	if (document.statistics_lead_time_snooze.statistics_lead_time_snooze_date.value == "") {
		alert("You must Specify a Snooze Date");
		document.statistics_lead_time_snooze.statistics_lead_time_snooze_date.focus()
		return false
	}
	if (document.statistics_lead_time_snooze.statistics_lead_time_snooze_date.value != "") {
		if (isDateA(document.statistics_lead_time_snooze.statistics_lead_time_snooze_date.value,"Snooze Date")==false){
			document.statistics_lead_time_snooze.statistics_lead_time_snooze_date.focus()
			return false
		}
	}
}
function VerifyData_CopyLocation() {
   var x=document.getElementsByTagName('input') 	
   var checkbox = 0;
   var radio = 0;
   for (i=0; i<x.length;i++) {
     if (x[i].type=='checkbox') {
       if (x[i].checked){
	   		checkbox++;
	   }
       }
     if (x[i].type=='radio') {
       if (x[i].checked){
	   		radio++;
	   }
       }
   }
	if (document.copy_location_add.CopyLocation_Name.value == "") {
		alert("You must specify a Name.");
		return false;
	} 
	if (document.copy_location_add.CopyLocation_DepoDate.value == "") {
		alert("You must specify a Depo Date.");
		return false;
	} 
	if (document.copy_location_add.CopyLocation_DepoDate.value != "") {
		if (isDateA(document.copy_location_add.CopyLocation_DepoDate.value,"Depo Date")==false){
			document.copy_location_add.CopyLocation_DepoDate.focus()
			return false
		}
	} 
	if (document.copy_location_add.CopyLocation_DateServed.value != "") {
		if (isDateA(document.copy_location_add.CopyLocation_DateServed.value,"Date Served")==false){
			document.copy_location_add.CopyLocation_DateServed.focus()
			return false
		}
	} 
	if (document.copy_location_add.CopyLocation_DateCopied.value != "") {
		if (isDateA(document.copy_location_add.CopyLocation_DateCopied.value,"Date Copied")==false){
			document.copy_location_add.CopyLocation_DateCopied.focus()
			return false
		}
	} 
	if (document.copy_location_add.CopyLocation_DateReady.value != "") {
		if (isDateA(document.copy_location_add.CopyLocation_DateReady.value,"Date Ready")==false){
			document.copy_location_add.CopyLocation_DateReady.focus()
			return false
		}
	} 
	if (document.copy_location_add.CopyLocation_DepoTime.value == "") {
		alert("You must specify a Depo Time.");
		return false;
	} 
	if (radio == 0) {
		alert("You must specify if Ammended or Not.");
		return false;
	} 
	return true;
}
function VerifyData_BillTo() {
   var x=document.getElementsByTagName('input') 	
   var checkbox = 0;
   var radio = 0;
   for (i=0; i<x.length;i++) {
     if (x[i].type=='checkbox') {
       if (x[i].checked){
	   		checkbox++;
	   }
       }
     if (x[i].type=='radio') {
       if (x[i].checked){
	   		radio++;
	   }
       }
   }
	
	if (document.bill_to_add.Entity_Name.value == "") {
		alert("You must enter a Name.");
		return false;
	} else if (radio == 0) {
		alert("You must specify Party Notice.");
		return false;
	} else if (checkbox == 0) {
		alert("You must select one copy location.");
		return false;
	} else
		return true;
}
function cntprimary(cnt){
cnt=0;
   for(i=1; i<=8; i++){
   var enc=eval("document.nameofform.checkbox"+i+".checked");
     if(enc){
         cnt++;
     }
   }
   return cnt;
}

function VerifyData_ShipTo() {
	if (document.ship_to_add.Entity_Name.value == "") {
		alert("You must enter a Name.");
		return false;
	} else if (document.ship_to_add.radioval.value == "") {
		alert("You must select one copy location.");
		return false;
	} else
		return true;
}
function VerifyData_Notes() {
	if (document.notes_add.Notes_Title.value == "") {
		alert("You must enter a Title.");
		return false;
	} else if (document.notes_add.Notes_Note.value == "") {
		alert("You must enter a note.");
		return false;
	} else
		return true;
}
function VerifyData_User() {
	if (document.admin_passwords.Users_Name.value == "") {
		alert("You must enter a Name.");
		return false;
	} else if (document.admin_passwords.Users_Login.value == "") {
		alert("You must enter a Login value.");
		return false;
	} else if (document.admin_passwords.Users_Pass.value == "") {
		alert("You must enter a Password value.");
		return false;
	} else
		return true;
}
function ConfirmChoice(alertmsg, url) { 
	if (confirm(alertmsg)) {
		document.location.href = url;
	}	 
	else {
		return false;
	}
}
function ConfirmChoiceClose(alertmsg) { 
	if (confirm(alertmsg)) {
		self.close();
	}	 
	else {
		return false;
	}
}
function setTextBoxValue() {
	TextValue = document.copy_location_add.CopyLocation_RecordType.value;
	TextValueA = eval('document.copy_location_add.'+ TextValue +'.value');
	document.copy_location_add.CopyLocation_RecordText.value = TextValueA;
	return true;
}
function set_Date(newDate) {
	document.copy_location_add.CopyLocation_DepoDate.value = newDate;
}




function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}


function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

//window.onload=resizeCaller

function resizeTableWidth(){
var currenttable=document.getElementById('table3')
currenttable.width = 1000
}

var deg2radians = Math.PI * 2 / 360;
function fnSetRotation(deg)
{    
	rad = deg * deg2radians ;
    costheta = Math.cos(rad);
    sintheta = Math.sin(rad);
	
	var x = document.getElementsByTagName('div');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].className == 'header3') {
			x[i].filters.item(0).M11 = costheta;
			x[i].filters.item(0).M12 = -sintheta;
			x[i].filters.item(0).M21 = sintheta;
			x[i].filters.item(0).M22 = costheta;			
		}
	}
}

//User Select script ===============================================================
// -------------------------------------------------------------------
// selectUnselectMatchingOptions(select_object,regex,select/unselect,true/false)
//  This is a general function used by the select functions below, to
//  avoid code duplication
// -------------------------------------------------------------------
function selectUnselectMatchingOptions(obj,regex,which,only) {
	if (window.RegExp) {
		if (which == "select") {
			var selected1=true;
			var selected2=false;
			}
		else if (which == "unselect") {
			var selected1=false;
			var selected2=true;
			}
		else {
			return;
			}
		var re = new RegExp(regex);
		for (var i=0; i<obj.options.length; i++) {
			if (re.test(obj.options[i].text)) {
				obj.options[i].selected = selected1;
				}
			else {
				if (only == true) {
					obj.options[i].selected = selected2;
					}
				}
			}
		}
	}
		
// -------------------------------------------------------------------
// selectMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Currently-selected options will not be changed.
// -------------------------------------------------------------------
function selectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",false);
	}
// -------------------------------------------------------------------
// selectOnlyMatchingOptions(select_object,regex)
//  This function selects all options that match the regular expression
//  passed in. Selected options that don't match will be un-selected.
// -------------------------------------------------------------------
function selectOnlyMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"select",true);
	}
// -------------------------------------------------------------------
// unSelectMatchingOptions(select_object,regex)
//  This function Unselects all options that match the regular expression
//  passed in. 
// -------------------------------------------------------------------
function unSelectMatchingOptions(obj,regex) {
	selectUnselectMatchingOptions(obj,regex,"unselect",false);
	}
	
// -------------------------------------------------------------------
// sortSelect(select_object)
//   Pass this function a SELECT object and the options will be sorted
//   by their text (display) values
// -------------------------------------------------------------------
function sortSelect(obj) {
	var o = new Array();
	if (obj.options==null) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
		}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
			} 
		);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
		}
	}

// -------------------------------------------------------------------
// selectAllOptions(select_object)
//  This function takes a select box and selects all options (in a 
//  multiple select object). This is used when passing values between
//  two select boxes. Select all options in the right box before 
//  submitting the form so the values will be sent to the server.
// -------------------------------------------------------------------
function selectAllOptions(obj) {
	for (var i=0; i<obj.options.length; i++) {
		obj.options[i].selected = true;
		}
	}
	
// -------------------------------------------------------------------
// moveSelectedOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  This function moves options between select boxes. Works best with
//  multi-select boxes to create the common Windows control effect.
//  Passes all selected values from the first object to the second
//  object and re-sorts each box.
//  If a third argument of 'false' is passed, then the lists are not
//  sorted after the move.
//  If a fourth string argument is passed, this will function as a
//  Regular Expression to match against the TEXT or the options. If 
//  the text of an option matches the pattern, it will NOT be moved.
//  It will be treated as an unmoveable option.
//  You can also put this into the <SELECT> object as follows:
//    onDblClick="moveSelectedOptions(this,this.form.target)
//  This way, when the user double-clicks on a value in one box, it
//  will be transferred to the other (in browsers that support the 
//  onDblClick() event handler).
// -------------------------------------------------------------------
function moveSelectedOptions(from,to) {
	// Unselect matching options, if required
	if (arguments.length>3) {
		var regex = arguments[3];
		if (regex != "") {
			//unSelectMatchingOptions(from,regex);
			selectOnlyMatchingOptions(from,regex);
			}
		}
	// Move them over
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			to.options[to.options.length] = new Option( o.text, o.value, false, false);
			}
		}
	// Delete them from original
	for (var i=(from.options.length-1); i>=0; i--) {
		var o = from.options[i];
		if (o.selected) {
			from.options[i] = null;
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(from);
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// copySelectedOptions(select_object,select_object[,autosort(true/false)])
//  This function copies options between select boxes instead of 
//  moving items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copySelectedOptions(from,to) {
	var options = new Object();
	for (var i=0; i<to.options.length; i++) {
		options[to.options[i].value] = to.options[i].text;
		}
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
				to.options[to.options.length] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}

// -------------------------------------------------------------------
// moveAllOptions(select_object,select_object[,autosort(true/false)[,regex]])
//  Move all options from one select box to another.
// -------------------------------------------------------------------
function moveAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		moveSelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		moveSelectedOptions(from,to,arguments[2]);
		}
	else if (arguments.length==4) {
		moveSelectedOptions(from,to,arguments[2],arguments[3]);
		}
	}

// -------------------------------------------------------------------
// copyAllOptions(select_object,select_object[,autosort(true/false)])
//  Copy all options from one select box to another, instead of
//  removing items. Duplicates in the target list are not allowed.
// -------------------------------------------------------------------
function copyAllOptions(from,to) {
	selectAllOptions(from);
	if (arguments.length==2) {
		copySelectedOptions(from,to);
		}
	else if (arguments.length==3) {
		copySelectedOptions(from,to,arguments[2]);
		}
	}

// -------------------------------------------------------------------
// swapOptions(select_object,option1,option2)
//  Swap positions of two options in a select list
// -------------------------------------------------------------------
function swapOptions(obj,i,j) {
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
	}
	
// -------------------------------------------------------------------
// moveOptionUp(select_object)
//  Move selected option in a select list up one
// -------------------------------------------------------------------
function moveOptionUp(obj) {
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// moveOptionDown(select_object)
//  Move selected option in a select list down one
// -------------------------------------------------------------------
function moveOptionDown(obj) {
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				}
			}
		}
	}

// -------------------------------------------------------------------
// removeSelectedOptions(select_object)
//  Remove all selected options from a list
//  (Thanks to Gene Ninestein)
// -------------------------------------------------------------------
function removeSelectedOptions(from) { 
	for (var i=(from.options.length-1); i>=0; i--) { 
		var o=from.options[i]; 
		if (o.selected) { 
			from.options[i] = null; 
			} 
		} 
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// removeAllOptions(select_object)
//  Remove all options from a list
// -------------------------------------------------------------------
function removeAllOptions(from) { 
	for (var i=(from.options.length-1); i>=0; i--) { 
		from.options[i] = null; 
		} 
	from.selectedIndex = -1; 
	} 

// -------------------------------------------------------------------
// addOption(select_object,display_text,value,selected)
//  Add an option to a list
// -------------------------------------------------------------------
function addOption(obj,text,value,selected) {
	if (obj!=null && obj.options!=null) {
		obj.options[obj.options.length] = new Option(text, value, false, selected);
		}
	}

function change_style(ID,style_name)
{
	el = document.getElementById(ID);
	el.className = style_name;
}
//End of User Select Script============================================
