// JavaScript Document

// the following are the functions for the main navigation menu

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// end 


// Beginning of validation functions

function check_date(my_form) {
	
		var problem = false;
		
		if (my_form.name.value == "") {
			
			alert("You must enter a value");
			
			my_form.name.value = "Select Search";
			my_form.name.focus();
			problem = true;
			
			}
			
		if ((my_form.url_category.selectedIndex == 0) || 
			(my_form.url_category.value == 0 ) ) {
				
				alert("Please select a Search Category");
				
				problem = true;
				
			}
			
		if(problem) {
			
			return false;
			
		} else {
			
			return true;
		}
}



//Beginning of function to react to checkbox clicks

 function checkArray(form, arrayName)
  {
    var retval = new Array();

    for(var i=0; i < form.elements.length; i++) {
	
			var el_type = document.form1.elements[i].type
			var el_name = document.form1.elements[i].name
			var el_id = document.form1.elements[i].id
			
			
				if (el_type == 'checkbox') {
				
					if(document.form1.elements[i].checked) {
			
					//alert('Type is: ' + el_type + ', Name is: ' + el_name + ', Id is ' + el_id)
					//alert(document.form1.elements[i].parentNode.previousSibling.previousSibling.childNodes[0].value);
											
					//alert(document.form1.elements[i].parentNode.previousSibling.previousSibling.previousSibling.childNodes[0].value);

					var el = form.elements[i];
					var doc_loc = document.form1.elements[i].parentNode.previousSibling.previousSibling.childNodes[0].value
					var doc_dest = document.form1.elements[i].parentNode.previousSibling.previousSibling.previousSibling.childNodes[0].value
					var doc_cont = document.form1.elements[i].parentNode.previousSibling.previousSibling.previousSibling.previousSibling.previousSibling.previousSibling.innerText
					//alert(doc_cont);
      				
					if(el.type == "checkbox" && el.name == arrayName && el.checked) {
						
							if (document.form1.elements[i].parentNode.previousSibling.previousSibling.childNodes[0].value == '') {
								
									doc_loc = 'NOLOCATION';
									
							}
							
							if (document.form1.elements[i].parentNode.previousSibling.previousSibling.previousSibling.childNodes[0].value == '') {
								
									doc_dest = 'NODATE';
									
							}
							
							
				
        				retval.push(el.value +'#'+ doc_loc+'#'+doc_dest+'#'+doc_cont+'#');
						//retval.push('Type is: ' + el_type + ', Name is: ' + el_name + ', Id is ' + el_id)
      			
						}
				
					}		
				
				}
			
    
	}
    
	return retval;
  
  }
  
  
  /*********************/
  
  
  function checkForm(form)
  {
    var itemsChecked = checkArray(form, "tmparray[]") ;
    
	//alert("You selected " + (itemsChecked.length) + " items");
    
		if(itemsChecked.length <= 0) {
	
			alert("You have not selected any shipments to update.  Please select at least 1 before submitting the page.");
			
	
			
			return false;
		
	  
    		}
			
		if(itemsChecked.length > 0) {
			
			
			
			 for(var i=0; i < itemsChecked.length; i++) {
				 
				 //alert("You selected at least 1");
				// alert(itemsChecked[i]);
				 //alert(itemsChecked[i].length);
				var strItem = itemsChecked[i];
				var broken_up_string = strItem.split("#");
				var part_one = broken_up_string[0];
				var part_two = broken_up_string[1]; 
					
				var part_three = broken_up_string[2]; 
					if (part_two == 'NOLOCATION' && part_three == 'NODATE') {
							alert('Please select a location and a date for TMP: ' + part_one );
							return false;
							}
					
					if (part_three == 'NODATE') {
							alert('Please select a date for TMP: ' + part_one);
							return false;							
							}
							
					if (part_two == 'NOLOCATION') {
							alert('Please select a location for TMP: ' + part_one);
							return false;							
							}


				 // alert("string index of #: " + strItem.indexOf('#'));
				 // alert(part_one);
				 //alert(part_two);
				 // alert(part_three);
		 		
			 	}
			
			
			
		}
		
	return true;
  
  }
  
  
  
 //***********************************************************************************
 
  function deliverytable(obj) {
	  						//alert(obj.parentNode.previousSibling.previousSibling.previousSibling.previousSibling.previousSibling.previousSibling.innerText);
	  						if(obj.checked == false)
										{
													//alert("false");
			obj.parentNode.previousSibling.previousSibling.style.backgroundColor = "";
			obj.parentNode.previousSibling.previousSibling.childNodes.item(0).style.backgroundColor = "#e5e5e5";
			obj.parentNode.previousSibling.previousSibling.previousSibling.style.backgroundColor = "";
			obj.parentNode.previousSibling.previousSibling.previousSibling.childNodes.item(0).style.backgroundColor = "#e5e5e5";
			obj.parentNode.previousSibling.previousSibling.childNodes.item(0).disabled = true; 
			obj.parentNode.previousSibling.previousSibling.previousSibling.childNodes.item(0).disabled = true;
			obj.parentNode.previousSibling.previousSibling.childNodes.item(0).value = ""; 
			obj.parentNode.previousSibling.previousSibling.previousSibling.childNodes.item(0).value = "";
			
										} else {
													//alert("true");
													obj.parentNode.previousSibling.previousSibling.style.backgroundColor = "blue";
													obj.parentNode.previousSibling.previousSibling.childNodes.item(0).style.backgroundColor = "white";
													obj.parentNode.previousSibling.previousSibling.previousSibling.style.backgroundColor = "blue";
													obj.parentNode.previousSibling.previousSibling.previousSibling.childNodes.item(0).style.backgroundColor = "white";
													obj.parentNode.previousSibling.previousSibling.childNodes.item(0).disabled = false;
													obj.parentNode.previousSibling.previousSibling.previousSibling.childNodes.item(0).disabled = false;
												}
													
													
  								}
								
								
								
	//*******************************************************
	
	function formconfirm_dl() {
		
		alert('You\'re update has been cancelled.  You will now be redirected back to the delivery page.');
		window.location = "http://www.crowncontainer.com/delivery_droplot.php";
		
		
		return false;

		
	}
	
	
	function formconfirm_rail() {
		
		alert('You\'re update has been cancelled.  You will now be redirected back to the delivery page.');
		window.location = "http://www.crowncontainer.com/delivery_rail.php";
		
		
		return false;

		
	}
	
	
	
	
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','tab1ready','tab2ready','tab3ready','content1','content2','content3');

// 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"; }
   }
}


function isRailBilling()
{
	var rb = 'depotsearchselect';
	var rb = document.getElementById(rb);
	if(rb.value == 'rb')
	{
		window.location = "http://www.crowncontainer.com/railbilling.php";
	}
}
		
	




