// JavaScript Document
function javascriptTest()
{
	alert('response')
}

var original_tr_background
function mouseOverTableRow(obj){
	//alert(obj);
	original_tr_background = obj.style.backgroundColor.value;
	//alert(original_tr_background);
	obj.style.backgroundColor = "FF9900";
}

function mouseOffTableRow(obj){
	//alert(obj);
	obj.style.backgroundColor = "FFFFFF";
}

function disableEnterKey(e)
{
     var key;      
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox      

     return (key != 13);
}



function switchMenu(obj) {
	//alert(obj);
var el = document.getElementById(obj);
//alert(el);
	if ( el.style.display != 'none' ) {
	el.style.display = 'none';
	}
	else {
	el.style.display = '';
	}
}

function testFieldSize(str){
//alert(str.length);	
if(str.length < 4)
	{
		alert('This equipment field is required and must be at least 4 characters long. \n\r Example: APLU,HCJU,etc'); 
		return false;
	
	} else 
	{ 
		return true;
	}
}

function testImageFieldSize(str){
//alert(str.length);	
if(str.length < 1)
	{
		alert('This input field is required and must be at least 1 character long.'); 
		return false;
	
	} else { 
		
		return true;
	}
}


function testFieldSizeForms(str)
{
	//alert(str.length);	
	if(str.length <= 0)
	{
		alert('You must enter a value in this field.'); 
		return false;
	
	} else 
	{ 
		return true;
	}
}


function clearDataset()
{
	
	document.getElementById("txtinsertId").innerHTML='';
}
	
function verifyDateNotInFuture(y,m,d){
	//alert( y + ',' + m + ',' + d);
	var currentTime = new Date();
	var currentMonth = (currentTime.getMonth()+1);
	var currentDay = currentTime.getDate();
	var currentYear = currentTime.getYear();

	if(currentYear == y)
	{	//alert(currentYear + ' , ' + y);
	
	if(currentMonth < m)
		{
			alert('Activity date can not be greater than today.  \n\rYou have chosen a month greater than the current month.');
			return false;
		}  else if (currentMonth == m)
		
			{
				
				if(currentDay < d) {
					alert('Activity date can not be greater than today. \n\rYou have chosen a day that is greater than today\'s date.')
					return false;
					}
		
				
			}	else if (currentYear < y)
			
			{ alert('Activity date can not be greater than today.  \n\rYou have chosen a year greater than the current year.');
			return false;
				
			} 
			
			
	}	else {
			
			return true;
			
		}
			
	
} //end function

function valButton(btn) {
	
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) 
	{
        if (btn[i].checked) 
		{
			cnt = i; i = -1; /*alert(btn[cnt].value)*/
			var direction = btn[cnt].value
			//alert(direction)
			return direction
		}
		
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
	

}
/*
The following function is used in the admin form to add a user or to edit one.  It controls the enable / disable status of the different account type input fields.
*/
function assocation_management(val) {
	
				switch(val)
				{
					case 'D':
					//alert('DEPOT');
					document.getElementById("ds").style.backgroundColor = "#DEE6ED";
					document.getElementById("ds").style.borderColor = "#7f9db9";
					//document.getElementById("ds").style.border = "thin solid #7f9db9";
					document.getElementById("ds").style.visibility = "visible";
					document.getElementById("ds").disabled = false;
					document.getElementById("pt").disabled = true;
					document.getElementById("pt").style.visibility = "hidden";
					break
					case 'T':
					//alert('TRUCKING');
					document.getElementById("pt").style.backgroundColor = "#DEE6ED";
					document.getElementById("pt").style.borderColor = "#7f9db9";
					//document.getElementById("ds").style.border = "thin solid #7f9db9";
					document.getElementById("pt").style.visibility = "visible";
					document.getElementById("pt").disabled = false;
					document.getElementById("ds").disabled = true;
					document.getElementById("ds").style.visibility = "hidden";
					break
					case 'B':
					//alert('BOTH');
					document.getElementById("ds").style.backgroundColor = "#DEE6ED";
					document.getElementById("ds").style.borderColor = "#7f9db9";
					document.getElementById("ds").disabled = false;
					document.getElementById("pt").style.backgroundColor = "#DEE6ED";
					document.getElementById("pt").style.borderColor = "#7f9db9";
					document.getElementById("pt").disabled = false;
					document.getElementById("ds").style.visibility = "visible";
					document.getElementById("pt").style.visibility = "visible";
					
					break
					case 'C':
					//alert('CONSIGNEE');
					document.getElementById("pt").style.backgroundColor = "#DEE6ED";
					document.getElementById("pt").style.borderColor = "#7f9db9";
					//document.getElementById("ds").style.border = "thin solid #7f9db9";
					document.getElementById("pt").style.visibility = "visible";
					document.getElementById("pt").disabled = false;
					document.getElementById("ds").disabled = true;
					document.getElementById("ds").style.visibility = "hidden";
					break
					default:
					alert('You must select either DEPOT, TRUCKING, BOTH, or CONSIGNEE');
					document.getElementById("pt").style.visibility = "hidden";
					document.getElementById("ds").style.visibility = "hidden";
					break
				}
	
	return val
	
}

function stateChanged() 
{
	//alert(xmlHttp.readyState);
	if (xmlHttp.readyState==1 )
	 { 
	 document.getElementById("txtinsertId").innerHTML="<img src='images/load.gif' alt='loading...' />"; 
	 }  

	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	 { 
	 document.getElementById("txtinsertId").innerHTML=xmlHttp.responseText 
	 xmlHttp = null;
	 } 
} //end stateChanged



function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	 {
	 // Firefox, Opera 8.0+, Safari
	 xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
	 //Internet Explorer
	 try
	  {
	  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e)
	  {
	  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	 }
	return xmlHttp;
}


function ManageTabPanelDisplay() {
//
// Between the parenthesis, list the id's of the div's that 
//     will be effected when tabs are clicked. List in any 
//     order. Put the id's in single quotes (apostrophes) 
//     and separate them with a comma -- all one line.
//
var idlist = new Array('tab1focus','tab2focus','tab3focus','tab4focus','tab5focus','tab6focus','tab7focus','tab1ready','tab2ready','tab3ready','tab4ready','tab5ready','tab6ready','tab7ready','content1','content2','content3','content4','content5','content6','content7');



// No other customizations are necessary.
if(arguments.length < 1) { return; }
for(var i = 0; i < idlist.length; i++) {
   var block = false;
   for(var ii = 0; ii < arguments.length; ii++) {
      if(idlist[i] == arguments[ii]) {
         block = true;
         break;
         }
      }
   if(block) { document.getElementById(idlist[i]).style.display = "block"; }
   else { document.getElementById(idlist[i]).style.display = "none"; }
   }
}



//the following functions are used in dataset_delivery_droplot and dataset_delivery_rail and dataset_update_empty
function validate_form(thisform)
{
	with (thisform)
	{
		//alert("hello")
		var counter = 0; //sets the counter to determine if any checkboxes have been checked.
		//alert(counter)
		for(var i=0; i < thisform.elements.length; i++) //for each element in the form, run the following loop
		{
			var el_type = thisform.elements[i].type; //assign the element to the variable el_type 
			//alert(el_type);
			if (el_type == 'checkbox') //test if its a checkbox
			{
				if(thisform.elements[i].checked) // test if the checkbox is checked.
				{
					//alert("found one");
					counter = counter +1; //if the checkbox is checked, increment the counter to 1.
				}
			}
		}
		//alert("counter =: " + counter);
		
		if( (counter) <= 0)
		{
			alert("You must check at least 1 record for updating before submitting the request");
			return false
		
		} else {
			
			//alert("You have checked: " + (counter) + "items to be updated")
			for(var i=0; i < thisform.elements.length; i++)
			{
				var el_type = thisform.elements[i].type;
				//alert(el_type);
				if (el_type == 'checkbox')
				{
						
					if(thisform.elements[i].checked)
					{
						
						
						filename = getFileName()
	
						if(filename == 'delivery_rail' || 'delivery_droplot')
						{						
						
							//alert("found one");
							//counter = counter +1;
							var strTmp = thisform.elements[i].id //assigns the tmp to the variable strTmp
							var strId = strTmp.substring(4) //reduces the string to the number i.e. tmp_01 become 01, and this number will be added to the following variables
							//alert(strId)
							var locationId = 'location_'+strId // assigns the value location_strId value to locID
							var dateId = 'date_'+strId // assigns the value date_strId value to datId
							var timeId = 'time_'+strId // assigns the value date_strId value to datId
							//alert(locId)
							//alert(datId)
							var location_str = document.getElementById(locationId) // gets the value of the post variable from the form to the variable newstr
							var date_str = document.getElementById(dateId) // get the value of the post variable from the from to the variable newstr2
							var time_str = document.getElementById(timeId) // get the value of the post variable from the from to the variable newstr2
							var location_str_value = location_str.value
							var date_str_value = date_str.value
							var time_str_value = time_str.value
							//alert(location_str_value);
							
							//alert(strValue.length + ' and ' + strValue2.length)
							var location_str_length = location_str_value.length
							var date_str_length = date_str_value.length
							var time_str_length = time_str_value.length
							if(location_str_value == 319)
							{
								//alert('yes it is equal')
								if((location_str_length <= 0))
								{
								
								alert("A date or location field is blank on line: " + strId + ".  Please correct this and resubmit.")
								return false
								
								} //ends the first strLength comparison 
							} else {
							
							
								if((location_str_length <= 0) || (date_str_length <=0))
								{
								
								alert("A date or location field is blank on line: " + strId + ".  Please correct this and resubmit.")
								return false
								
								} //ends the first strLength comparison 	
							
							
							}
						
						} //ends the if(filename == 'delivery_rail' || 'delivery_droplot')
						
						if(filename == 'update_empty')
						{
							//alert("found two");
							//counter = counter +1;
							var strTmp = thisform.elements[i].id //assigns the tmp to the variable strTmp
							var strId = strTmp.substring(4) //reduces the string to the number i.e. tmp_01 become 01, and this number will be added to the following variables
							//alert(strId)
							var locationId = 'location_'+strId // assigns the value location_strId value to locID
							var location_str = document.getElementById(locationId) // gets the value of the post variable from the form to the variable newstr
							var location_str_value = location_str.value
							var location_str_length = location_str_value.length
							if(location_str_length <= 0)
							{
								
								alert("A date or location field is blank on line: " + strId + ".  Please correct this and resubmit.")
								return false
								
							} //ends the first strLength comparison 
							
						}//ends the if(filename == 'update_empty')
						
					} //ends the if(thisform.elements[i].checked)
				
				} // ends the if(el_type == 'checkbox')
						
			} // ends the last for loop
					
		} //should end the if (counter <=0) conditional
			
	} //ends the with statement

} //concludes the function

function getFileName()
{	
	var url = window.location.href
	//alert(url)
	//determine the filename:
	var url_starting_point = (url.lastIndexOf('/') + 1)
	//alert(url_starting_point)
	var url_ending_point = url.lastIndexOf('.')
	//alert(url_ending_point)
	var filename = url.substring(url_starting_point,url_ending_point)
	//alert(filename)
	return filename
	
}
	
	
	

/*
The function validate_check is invoked when the user clicks the check box on a given line item.  It disables and enables access to the combo box fields.
*/
function validate_check(check)
{	
	var url = window.location.href
	//alert(url)
	//determine the filename:
	var url_starting_point = (url.lastIndexOf('/') + 1)
	//alert(url_starting_point)
	var url_ending_point = url.lastIndexOf('.')
	//alert(url_ending_point)
	var filename = url.substring(url_starting_point,url_ending_point)
	//alert(filename)
	var file_length = filename.length
	//alert(file_length)
	
	//fn = getFileName()
	//alert fn
	if(file_length>12)
	{
		//alert('equal')
		//get the id name of the tmp you selected.
		var strTmp = check.id
		//alert(strTmp);
		//cut off the tmp_ so that all you have is the number.
		var strId = strTmp.substring(4)
		//alert(strId)
		//create the variable that represents the id of the facility location drop down
		var locId = 'location_'+strId
		//alert(locId)
		//grab the element that holds the location value and put it in the newstr variable
		var element_locationId = document.getElementById(locId)
		//alert(element_locationId)
		var dateId = 'date_'+strId
		//alert(dateId)
		//grab the element that holds the date value and put it in the newstr variable
		var element_dateId = document.getElementById(dateId)
		//alert(element_dateId)
		var timeId = 'time_'+strId
		//alert(timeId)
		//grab the element that holds the time value and put it in the newstr variable
		var element_timeId = document.getElementById(timeId)
		//alert(element_timeId)
		//create the variable that represents the TR element that contains this tmp's table data.
		var trId = 'tr_'+strId
		//alert(trId);
		var element_trId = document.getElementById(trId)
		//alert(element_trId)
		//the following two lines get the value for the hidden field, which holds a yes or no, depending on whether or not the line number is odd or even
		var floattest = 'numtype_'+strId
		//alert(floattest);
		var element_floattest = document.getElementById(floattest)
		//alert(element_floattest);
		
		if(check.checked) 
		{	
			//alert('not empty');
			element_locationId.disabled = false
			element_locationId.parentNode.style.background = "#009900";
			element_timeId.disabled = false
			element_timeId.parentNode.style.background = "#009900";
			element_dateId.disabled = false
			element_dateId.parentNode.style.background = "#009900";
			//alert(newstr.parentNode.name);
									
		} else {
					
			if(element_floattest.value == 'yes')
			{
				element_locationId.parentNode.style.background = "#FFFFFF";
				element_timeId.parentNode.style.background = "#FFFFFF";
				element_dateId.parentNode.style.background = "#FFFFFF";
			} else {
					
				element_locationId.parentNode.style.background = "#F4F4F4";
				element_timeId.parentNode.style.background = "#F4F4F4";
				element_dateId.parentNode.style.background = "#F4F4F4";
			}
			
			element_locationId.value = '';
			element_locationId.disabled = true
			element_timeId.disabled = true
			element_dateId.value = '';
			element_dateId.disabled = true
							
		}
	}
	
	
	if(file_length=12)
	{
		//alert('empty')
		//get the id name of the tmp you selected.
		var strTmp = check.id
		//alert(strTmp);
		//cut off the tmp_ so that all you have is the number.
		var strId = strTmp.substring(4)
		//alert(strId)
		//create the variable that represents the id of the facility location drop down
		var locId = 'location_'+strId
		//alert(locId)
		//grab the element that holds the location value and put it in the newstr variable
		var element_locationId = document.getElementById(locId)
		//alert(element_locationId)
		
		var floattest = 'numtype_'+strId
		//alert(floattest);
		var element_floattest = document.getElementById(floattest)
		//alert(element_floattest);
		
		if(check.checked) 
		{	
			//alert('checked');
			element_locationId.disabled = false
			element_locationId.parentNode.style.background = "#009900";
			
									
		} else {
					
			if(element_floattest.value == 'yes')
			{
				element_locationId.parentNode.style.background = "#FFFFFF";
				
			} else {
					
				element_locationId.parentNode.style.background = "#F4F4F4";
				
			}
			
			element_locationId.value = '';
			element_locationId.disabled = true
			
							
		}
	}
					
					
}
	

function dropLotDropDown(tmp)
{
	var url = window.location.href
	//alert(url)
	//determine the filename:
	var url_starting_point = (url.lastIndexOf('/') + 1)
	//alert(url_starting_point)
	var url_ending_point = url.lastIndexOf('.')
	//alert(url_ending_point)
	var filename = url.substring(url_starting_point,url_ending_point)
	//alert(filename)
	if(filename == 'update_empty')
	{
		return false
	}
	//determine if the selected value is drop lot
	var value = tmp.value
	var name = tmp.name
	var strId = name.substring(8)
	//alert(strId);
	var dtime = 'time'+strId
	var ddate = 'date'+strId
	//alert(ddate)
	var lastfreeday = 'lfd'+strId
	//alert(dtime);
	var delTime = document.getElementById(dtime);
	var delDate = document.getElementById(ddate);
	//alert(delDate.value);
	var lfd = document.getElementById(lastfreeday);
	var lfd_parent = lfd.parentNode.innerText
	//alert(lfd_parent);
	//var td_lfd = 'lfd_td'+strId
	//alert(td_lfd)
	//var element_td_lfd = document.getElementById(lastfreeday);
	//alert element_td_lfd.innerText
	if(value == '319')
	{
		
		delTime.disabled = true;
		delDate.disabled = true;
		delDate.value = lfd_parent;
		//alert(delDate.value)
		
		
	} else {
		delTime.disabled = false;
		delDate.disabled = false;
	}
}




function confirmTableCancel(url)
{
	//var url = window.location.href
	//alert(url);
	window.location.href = url;
}
