﻿function AlphaLockWithDot_keypress(evt)
{
    var code = evt.charCode;
	if(code == 46 && eval(evt).value.indexOf(".") != -1)
	evt.preventDefault();
	if((code >=48 && code <=57) || code == 46 || (code == 8))
	{}
	else
	evt.preventDefault();
}

function PhoneNumber_keypress(evt) 
   {
   
      var code = evt.charCode;
      
      if(!((code >=48 && code <=57) || (code ==45)||(code ==47) || (code == 8)|| (code == 46) || (code == 40)|| (code == 41)|| (code == 32)))
      {
         evt.preventDefault();
      }
   }
   
 function AlphaLockWithSlash_keypress(evt) 
   {
   
      var code = evt.charCode;
      if(!((code >=48 && code <=57) || (code ==47)|| (code == 8)|| (code == 46)))
      {
         evt.preventDefault();
      }
   }  


function Navigate(PageType)
{
    var theForm = getForm();
	theForm.PageType.value = PageType;
	theForm.Navigate.value = true;
	theForm.SelectionType.value ='';
 	theForm.submit(); 	
}

function GoTo(SelectionType, ID,MillId, CustomerId)
{
    var theForm = getForm();
	theForm.SelectionType.value = SelectionType;
	theForm.ID.value = ID;
	theForm.MillId.value=MillId;
	theForm.CustomerId.value=CustomerId;
	theForm.submit();
}

function GoToMCSDetails(SelectionType,TagId,HeatNum,ProdId,BolNumber,MillId,CustomerId)
{
    var theForm = getForm();
	theForm.SelectionType.value = SelectionType;
	theForm.TagId.value = TagId;
	theForm.HeatNum.value = HeatNum;
	theForm.ProdId.value = ProdId;
	theForm.BolNumber.value=BolNumber;
	theForm.MillId.value=MillId;
	theForm.CustomerId.value=CustomerId;
	theForm.submit();
}

function SwitchCustomers(CustomerId, MillId)
{
    var theForm = getForm();
	theForm.CustomerId.value = CustomerId;
	theForm.MillId.value = MillId;
	theForm.submit();
}

function Process(e)
{
	var keycode;
	if (window.event) 
	{
		keycode = window.event.keyCode;
	}
	else if (e) 
	{
		keycode = e.which;
	}
	else 
	{
		return true;
	}
	
	if (keycode == 13)
	{
	    var theForm = getForm();
		theForm.WasSubmitted.value = 'true';
		theForm.submit();
		return false;
	}
	else
	{
		return true;
	}
}


function CheckAll(Field, ToggleField)
{
    var theForm = getForm();
    var ToCheck = false;
   
    for (i = 0; i < theForm.length; i++) {
        if (theForm[i].type == 'checkbox' && theForm[i].name.indexOf(Field) > 0) {
            if (theForm[i].checked == false) {

                ToCheck = 'true';
            }
        }
    }   
    
    
	for (i=0; i < theForm.length; i++)
	{		
		if (theForm[i].type == 'checkbox' && theForm[i].name.indexOf(Field) > 0)
		{		
			if (ToCheck == 'true')
			{
				theForm[i].checked = true;
			}
			else
			{
				theForm[i].checked = false;
			}			
		}		
	}
	
	if (ToCheck == 'true')
	{
		ToCheck = 'false';
	}
	else
	{
		ToCheck = 'true';
	}

	
}

function OpenWindow(newUrl, width, height) 
{ 
	window.open(newUrl, "nothing", "menubar=no,toolbars=no,scrollbars=yes,status=no,width="+width+",height="+height+",resizable=yes,directories=no,left=150,top=100") ;	
}

function OpenFullWindow(newUrl, width, height) 
{ 
	window.open(newUrl, "nothing", "menubar=yes,toolbars=no,scrollbars=yes,status=no,width="+width+",height="+height+",resizable=yes,directories=no,left=150,top=100") 
}

function Toggle(item)
{

   var itemElement = document.getElementById(item);
   var theForm = getForm();
   
   if(itemElement != null)
   {
		if (itemElement.style.display == 'none') 
		{
				itemElement.style.display = '';
		      
				if (theForm.DisplayStyle != null)
				{
					theForm.DisplayStyle.value = '';
				}
		}
		else  
		{
				itemElement.style.display = 'none';
		      
      			if (theForm.DisplayStyle != null)
				{
					theForm.DisplayStyle.value = 'display:none';
				}
		} 
   }
}

function ChangeCompany(FormName) {

    document.getElementsByName("hdnCompany")[0].value = document.getElementById("Company").value;
    document.forms.CompanyForm.submit();
}

function AddProduct(InventoryId, MillId)
{
    var theForm = getForm();
	var CurField = theForm.product;

	if (CurField.length == undefined)
	{
		CurField.checked = true;
	}
	else
	{
		for (i = 0; i < CurField.length; i++)
		{
			if (CurField[i].value == InventoryId + '_' + MillId)
			{
				CurField[i].checked = true;
			}
		}
	}
    
	theForm.AreItems.value = 'true';
	theForm.submit();
}

function SetTons(ProductKey)	   
{
    var theForm = getForm();
	if (theForm['tons1_' + ProductKey].value == '' && theForm['tons2_' + ProductKey].value == '' && theForm['tons3_' + ProductKey].value == '')
	{
		theForm['tons1_' + ProductKey].value = theForm['totaltons_' + ProductKey].value 
	}
}

function GetDetails(ProductTypeId, Millid, PageType)
{
    var theForm = getForm();
	theFormProductTypeId.value = ProductTypeId;
	theForm.Millid.value = Millid;	
	theForm.PageType.value = PageType;	
	theForm.submit();
}

function DetailLoaded()
{
    var theForm = getForm();
	theForm.IsLoaded.value = 'true';
	theForm.submit();	
}

function ClosedDetails(OrderId, MillId, PageType)
{
    var theForm = getForm();
	theForm.OrderId.value = OrderId;
	theForm.MillId.value = MillId;
	theForm.PageType.value = PageType;	
	theForm.submit();
}

function LoadPartNum()
{	
    var theForm = getForm();
	var PartNum = theForm.Length.value.split("|_|");	
	theForm.CustomerPartNumber.value = PartNum[4];
}

function PrintSelected()
{
    var theForm = getForm();
	var MillId = theForm.MillId.value;
	var BolId = theForm.BolId.value;
	var CustomerId = theForm.CustomerId.value;
	var Tags = '';
	
	
	var CurField = theForm.Tags;

	for (i = 0; i < CurField.length; i++)
	{
		if (CurField[i].checked)
		{
			CurField[i].checked = false;
			
			if (Tags.length > 0)
			{
				Tags += ',';
			}
			
			Tags += CurField[i].value;
		}
	}
	
	if (Tags.length > 0)
	{
		OpenFullWindow('MillCertificationDetails.aspx?pf=t&b=' + BolId + '&m=' + MillId + '&tag=' + Tags + '&c=' + CustomerId, 630, 600);
	}
}


function TreeViewToggle(Node, imagePath)
{
	// Unfold the branch if it isn't visible
	if (Node.nextSibling.style.display == 'none')
	{
		// Change the image (if there is an image)
		if (Node.children != null && Node.children.length > 0)
		{
			if (Node.children.item(0).tagName == "IMG")
			{
				Node.children.item(0).src = imagePath + "minus.gif";
			}
		}

		Node.nextSibling.style.display = '';
	}
	// Collapse the branch if it IS visible
	else
	{
		// Change the image (if there is an image)
		if (Node.children != null && Node.children.length > 0)
		{
			if (Node.children.item(0).tagName == "IMG")
			{
				Node.children.item(0).src = imagePath + "plus.gif";
			}
		}

		Node.nextSibling.style.display = 'none';
	}
}

function SelectParentCategory(parentCategoryId, parentCategory, parentCatNameId) {
    var theForm = getForm();
    var myItem = document.getElementById(parentCatNameId);
    theForm.ParentCatID.value = parentCategoryId;
    myItem.value = parentCategory;
}

function ShowHideItems(myItem, myButton,imagePath)
{
	var myItem = document.getElementById(myItem);
	var myButton = document.getElementById(myButton);
	if (myItem.style.display != "none") 
	{
	   myItem.style.display = "none";
	   myButton.src = imagePath + "plus.gif";
	}
	else 
	{
       myItem.style.display = "block";
       myButton.src = imagePath + "minus.gif";
	}
}


function AttachFiles(pageURL)
{
	var Files = '';
	var theForm = getForm();
	var CurField = theForm.Files;

	for (i = 0; i < CurField.length; i++)
	{
		if (CurField[i].checked)
		{
			
			if (Files.length > 0)
			{
				Files += ',';
			}
			
			Files += CurField[i].value;
		}
	}
	
	if (Files.length > 0)
	{
        OpenWindow(pageURL + '&files=' + Files,550,300);

	}
}

function GoShipAddress(AddressId,ContactId,MillId,s,oi,m,c,od)
{
    var theForm = getForm();
    
    theForm.AddAddress.value = true;
   	theForm.AddressId.value = AddressId;
	theForm.ContactId.value = ContactId;
	theForm.MillId.value=MillId;  

	theForm.s.value=s;  
	theForm.s.value=oi;  
	theForm.s.value=m;  
	theForm.s.value=c;  
	theForm.s.value=od;  

 	theForm.submit(); 	
}

function SubmitShippedAddress()
{
 	getForm().submit(); 	
}

function getForm()
{
    return document.getElementById('aspnetForm');
}

function ShowHideDetails(myItem, myButton,imagePath, displayText)
{
	var myItem = document.getElementById(myItem);
	var myButton = document.getElementById(myButton);
	var myText = document.getElementById(displayText);
	if (myItem.style.display != 'none') 
	{
	   myItem.style.display = 'none';
	   myButton.src = imagePath + "plus.gif";
	   myText.innerHTML = "Show Details"; 
	}
	else 
	{
       myItem.style.display = '';
       myButton.src = imagePath + "minus.gif";
       myText.innerHTML = "Hide Details"; 
	}
}

function ToggleSelectionFilter(item,myButton,imagePath,myFilter)
{
  
   var myButtonElement;
   if(document.getElementsByName(myButton) != null)
   {
		myButtonElement = document.getElementsByName(myButton)[0];
   }
   
   if(myButtonElement != null)
   {
		var myFilter = document.getElementById(myFilter);
		var element = document.getElementById(item);
		var theForm = getForm();

		myFilter.innerHTML="Selection Filter";
		   

		myButtonElement.src = imagePath + "minus.gif";
		   
		   
		if (element.style.display == 'none') 
		{
				element.style.display = '';   
		               
				if (theForm.DisplayStyle != null)
				{
				    theForm.DisplayStyle.value = '';
				    myButtonElement.src = imagePath + "minus.gif";
				}
		}
		else  
		{
				element.style.display = 'none';
		      
      			if (theForm.DisplayStyle != null)
				{
				    theForm.DisplayStyle.value = 'display:none';
				    myButtonElement.src = imagePath + "plus.gif";
				}
		}
   }
}

function DisplayRolloverText(item,myFilter,actionFlag)
{
   
   var myFilter = document.getElementById(myFilter);
   var element = document.getElementById(item);
   var theForm = getForm();
   
   if (actionFlag == 1)
   {
		if (element.style.display == 'none') 
		{
			if (theForm.DisplayStyle != null)
			{
			   myFilter.innerHTML="Click here for more options";
			}
		}
   }
   else
   {
      myFilter.innerHTML="Selection Filter";
   }
}

function TabNavigate(TabType)
{
    var theForm = getForm();
	theForm.FilterTabType.value = TabType;
	theForm.TabChanged.value = true;
 	theForm.submit(); 	
}

function ShowRandomImage(myImage,imageList,imagePath)
{
  
	var randomImage = document.getElementById(myImage); 

    if (randomImage != null)
    {          
		imageSet = new Array();		
			
        // si: start index, ei: end index,  cc: current count  
		si=0; 
		cc=0;
		ei = imageList.length;
	        
		for (i=1;i<ei;i++)
		{
			if (imageList.charAt(i) == ',') 
			{
				imageSet[cc] = imageList.substring(si,i);
				cc++;
				si=i+1;
			}
		}
	    
		ind = Math.floor(Math.random() *cc);		              
		randomImage.src = imagePath + imageSet[ind];               	    
    }
}

function ChangeMessage(appMessageId) {
    var theForm = getForm();
    theForm.AppMessageId.value = appMessageId;
    theForm.MessageChanged.value = true;
    theForm.submit();
}


function ExpandCollapseImages(imagePath) {

    var ExpandCollapse = document.getElementById('ExpandCollapseLink');
    var ImpExpCollapse = document.getElementById('ImgExpandCollapse');
    var imgButtons = document.getElementsByName('imgProduct');
    var Expand;


    // Change the Expand/Collapse hyperlink name 
    if (ExpandCollapse.innerHTML == 'Expand All') {
        Expand = false;
        ExpandCollapse.innerHTML = "Collapse All";
        ImpExpCollapse.src = imagePath + "minus.gif";
    }
    else {
        Expand = true;
        ExpandCollapse.innerHTML = "Expand All";
        ImpExpCollapse.src = imagePath + "plus.gif";
    }
    
    //Change Image and ImageRow display style
    for (var i = 0; i < imgButtons.length; i++) {
        var imgButton = imgButtons[i];
        var imgRow = document.getElementById(imgButton.attributes.getNamedItem('rel').value);       
        if (imgRow != undefined) {
            if (Expand) {
                imgRow.style.display = 'none';
                imgButton.src = imagePath + "plus.gif";
            }
            else {
                imgRow.style.display = '';
                imgButton.src = imagePath + "minus.gif";
            }
        }
    }

}

function fnSelectCheckBoxes(isChecked, checkName) {

    var objTopCheck = document.getElementsByName('chkSelectAll');

    var objCheckBoxes = document.getElementsByName(checkName);
    if (objCheckBoxes) {
        for (var i = 0; i < objCheckBoxes.length; i++) {

            objCheckBoxes[i].checked = isChecked;


        }
    }
}
