/* global variables and functions */

function disableButtons() {

  if (document.getElementsByClassName == undefined) {
	    document.getElementsByClassName = function(className)
	    {
		    var allElements = document.getElementsByTagName("*");
		    var elements =[];

		    var element;
		    for (var i = 0; (element = allElements[i]) != null; i++) {			    
			    if (element.className && element.className.indexOf(className) != -1 )
				    elements.push(element);
		    }

		    return elements;
	    }
     }
   var elements = document.getElementsByClassName("submit")
   for ( var i = 0; i < elements.length; i++ )
   {
    elements[i].disabled = true
   } 
}    
window.onbeforeunload = disableButtons;


history.forward (15);

var screenHeight = screen.height;
var screenWidth = screen.width;

function LaunchEnhancedSearchWindow ( url, type, countryId, directShip, width, height, title)
{
    var oWin;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	url = url + "?type="+ type +"&Country="+ countryId +"&directShip="+ directShip + "&WinTitle="+ title;
	
	oWin = window.open ( url, 'EnhancedSearch', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );
}

function LaunchCustomerSelectForRohsExceptionWindow ( url )
{
    var oWin;
    var width = 650;
    var height = 400;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	oWin = window.open ( url, 'customerSelect', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );
}


function LaunchPartAvailabilityWindow ( url, x, y )
{
    var oWin;
    var width = 700;
    var height = 420;
    var top	= ( screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	oWin = window.open ( url, 'PartAvailability', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );	
}

function LaunchPartAvailabilityWindowWithPart ( url, part, width, height )
{
    var oWin;
    var width = 700;
    var height = 420;
    var top	= ( screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	url = url + "?part=" + part;
	oWin = window.open ( url, 'PartAvailability', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );	
}

function LaunchCalenderWindow ( url, format, textBoxId, width, height )
{
    var calendar_window;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	url = url + "?textBoxId=" + textBoxId;
	
	if (format != '' )
	{
	    url += "&format="+format;
	}
	calendar_window = window.open ( url, 'Calender', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	calendar_window.focus ( );
}

function SetDateValue ( textBoxId, val )
{
    var textBox1 = window.opener.document.getElementsByName ( textBoxId );
    textBox1[0].value = val;
    window.close ( );
}

function ClosePartAvailabilityWindow ( )
{      
    window.close ( );
}

function CloseEnhancedSearchWindow ( )
{      
    window.close ( );
}

function SubmitEnhancedSearch ( )
{
    window.opener.document.location = 'EnhancedSearchResults.aspx';
    window.close ( );
}

function ReloadExceptions ( )
{
    window.opener.document.location = 'RoHSExceptions.aspx';
    window.close ( );
}

function LaunchFeedbackWindow ( url )
{
    var oWin;
    
    width = 620;
    height = 660;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	oWin = window.open ( url, 'Feedback', 'status=no,toolbar=no,menubar=no,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );
}

function LaunchAddressWindow ( url, width, height )
{
  
    var oWin;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	oWin = window.open ( url, 'Address', 'status=no,toolbar=no,titlebar=no,menubar=no,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=yes' )
	oWin.focus ( );
}
function CloseAddressWindow ( )
{
    window.close ( );
}

function AddAddress  ( submitBtnID )
{
    //window.opener.location.reload( ) ;
    var submitbtn =  window.opener.document.getElementById( submitBtnID );
    if (submitbtn != null){
    submitbtn.click(); ; //.forms(0).submit();
    }
    else
    {
     window.opener.document.forms(0).submit();
    }
    window.close ( );
}

function LaunchContactWindow ( url, width, height )
{   
    var oWin;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
   // window.opener.document.getElementById('ctl00$DynamicContentAreaPH$Button1').click(); 
	oWin = window.open ( url, 'Contact', 'status=no,toolbar=no,menubar=no,titlebar=no,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );
}
function LaunchContactUsWindow ( url, width, height )
{   
    var oWin;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
   
   	oWin = window.open ( url, 'ContactUs', 'status=no,toolbar=no,menubar=no,titlebar=no,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
   //	oWin.document.title = 'title';
	oWin.focus ( );
}
function CloseContactWindow ( )
{
    window.close ( );
}

function AddContact ( submitBtnID )
{
    //window.opener.location.reload( ) ;
    var submitbtn =  window.opener.document.getElementById( submitBtnID );
    if (submitbtn != null){
    submitbtn.click(); ; //.forms(0).submit();
    }
    else
    {
     window.opener.document.forms(0).submit();
    }
    window.close ( );
}

function MoveFromSourceBoxToTargetBox(targetItemBoxId, sourceItemBoxId, sourceItemFieldId, targetItemFieldId, grouptoValidate, keepSourceState, keepTargetState, sortTarget)
{
    if (Page_ClientValidate( grouptoValidate )) {
    var targetItemBox = document.getElementById( targetItemBoxId );
    var sourceItemBox = document.getElementById( sourceItemBoxId );
    var targetItemField = document.getElementById( targetItemFieldId );
    var sourceItemField = document.getElementById( sourceItemFieldId );
    var i;
    var str = "";
    
    //alert("step1");
    for(i = sourceItemBox.options.length-1; i >= 0; i--)
    {
        if(sourceItemBox.options[i].selected)
        {
            var optionObject = new Option(sourceItemBox.options[i].text,sourceItemBox.options[i].value);
            
            var j;
            for(j=targetItemBox.options.length-1; j >= 0; j--)
            {
                if(targetItemBox.options[j].text == sourceItemBox.options[i].text) targetItemBox.remove(j);
            }

            var optionRank = targetItemBox.options.length;
            targetItemBox.options[optionRank]=optionObject;
            sourceItemBox.remove(i);
        }
    }
    
    if (sortTarget == "True")
    {
        //alert("step2");
        SortList(targetItemBox);
    }

    if (keepSourceState == "True")
    {    
        //alert("step3");
        str = "";
        if (sourceItemBox.options.length > 0)
        {
            str = sourceItemBox.options[0].value + "|" + sourceItemBox.options[0].text;
        }
        for( i = 1; i < sourceItemBox.options.length; i++)
        {
            str = str + "^" + sourceItemBox.options[i].value + "|" + sourceItemBox.options[i].text; 
        }
        sourceItemField.value = str;
        // for debug use
        //alert(str);
    }
        
    if (keepTargetState == "True")
    {
        //alert("step4");
        str = "";
        if (targetItemBox.options.length > 0)
        {
            str = targetItemBox.options[0].value + "|" + targetItemBox.options[0].text;
        }
        // for debug use
        //alert(str);
        for( i = 1; i < targetItemBox.options.length; i++)
        {
            str = str + "^" + targetItemBox.options[i].value + "|" + targetItemBox.options[i].text; 
        }
        targetItemField.value = str;
        // for debug use
        //alert(str);
    }
    
}}

function CompareList(a, b)
{
    if (a.textVal < b.textVal) { return -1 }
    if (a.textVal > b.textVal) { return 1 }
    return 0;
}

function SortList(listBoxToSort) 
{        
    arrTexts = new Array();
    for(i=0; i<listBoxToSort.length; i++)  
    {
        arrTexts[i] = {textVal:listBoxToSort.options[i].text, valueVal:listBoxToSort.options[i].value};
    }

    arrTexts.sort(CompareList);
    for(i=0; i<listBoxToSort.length; i++)  
    {
      listBoxToSort.options[i].text = arrTexts[i].textVal;
      listBoxToSort.options[i].value = arrTexts[i].valueVal;
    }
}

function ShowBlockInputDiv ( )
{
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "block";   
    document.getElementById ( "OrderManagementSubmitOrderConfirmationDiv" ).style.display = "block";   
    self.location.href = '#top';
    
}

function HideBlockInputDiv ( )
{
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "none";
    document.getElementById ( "OrderManagementSubmitOrderConfirmationDiv" ).style.display = "none";   
}

function ShowDeleteReservedInventoryDiv ( )
{
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "block";   
    document.getElementById ( "deleteReserveInventoryConfirmationDiv" ).style.display = "block";   
    self.location.href = '#top'; 
}

function HideDeleteReservedInventoryDiv ( )
{
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "none";
    document.getElementById ( "deleteReserveInventoryConfirmationDiv" ).style.display = "none";   
}

function ShowOrderOnHoldDiv (IsPaymentAvailable)
{
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "block";
    document.getElementById ( "OrderManagementSubmitOrderConfirmationDiv" ).style.display = "none";   
    document.getElementById ( "OrderManagementOnHoldConfirmationDiv" ).style.display = "block";   
    self.location.href = '#top'; 
}

function ShowNotEnoughInventoryWarning ( )
{
	document.getElementById ( "NotEnoughInventoryWarningDiv" ).style.display = "block";
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "block";
    self.location.href = '#top'; 
}

function ShowNotEnoughInventoryWarningForQuote ( )
{
	
	document.getElementById ( "NotEnoughInventoryWarningDivQuote" ).style.display = "block";
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "block";
    //self.location.href = '#top'; 
}

function HideNotEnoughInventoryWarningForQuote ( )
{
    document.getElementById ( "NotEnoughInventoryWarningDivQuote" ).style.display = "none";
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "none";
}

function HideOrderOnHoldDiv (IsPaymentAvailable )
{
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "none";
    document.getElementById ( "OrderManagementOnHoldConfirmationDiv" ).style.display = "none";
    
    if(IsPaymentAvailable == "False")
    {
        alert("PO number is required to submit an order. Please specify PO Number on the Enter Order Details page in order to submit the order.");
    }
}

function ShowRoHSErrorDiv ( )
{
    document.getElementById ( "RoHSErrorDiv" ).style.display = "block";
    document.getElementById ( "OrderManagementSubmitOrderConfirmationDiv" ).style.display = "none";   
    self.location.href = '#top';     
}

function HideRoHSErrorDiv ( )
{
    document.getElementById ( "RoHSErrorDiv" ).style.display = "none";
}

function ShowQuoteDraftPopup ( )
{
	    // IE 6.0 Bug We need to hide the drop downs. 
    document.getElementById ( "countryDropDownDiv" ).style.visibility = "hidden";
    document.getElementById ( "quoteReasonDropDownDiv" ).style.visibility = "hidden";
    document.getElementById ( "competitionDropDownDiv" ).style.visibility = "hidden";
    document.getElementById ( "accountManagerDropDownDiv" ).style.visibility = "hidden";

    document.getElementById ( "SaveQuoteDraftDiv" ).style.top = f_scrollTop() + (f_clientHeight() - 250)/2;
    document.getElementById ( "SaveQuoteDraftDiv" ).style.display = "block";
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "block";   
}

function HideQuoteDraftPopup ( )
{
	    // IE 6.0 Bug We need to show hidden drop downs. 
    document.getElementById ( "countryDropDownDiv" ).style.visibility = "visible";
    document.getElementById ( "quoteReasonDropDownDiv" ).style.visibility = "visible";
    document.getElementById ( "competitionDropDownDiv" ).style.visibility = "visible";
    document.getElementById ( "accountManagerDropDownDiv" ).style.visibility = "visible";

    document.getElementById ( "SaveQuoteDraftDiv" ).style.display = "none";
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "none";   
}

function ShowExportOptionsPopup ( id, exportButtonId, exportRtfButtonId, requiredClientId, expressionClientId )
{
	var exportOptions = document.getElementById ( id );
	
    document.getElementById ( exportButtonId ).style.display = "inline";
	document.getElementById ( exportRtfButtonId ).style.display = "none";
	
	var required = document.getElementById ( requiredClientId );
	var expression = document.getElementById ( expressionClientId );
	
	ValidatorEnable(required, false);	
	ValidatorEnable(expression, false);	
		
	if ( exportOptions.options[exportOptions.selectedIndex].value != "" )
	{
	    
	    // IE 6.0 Bug We need to hide the drop downs. 
	    if ( document.getElementById ( "cancellationDropDownDiv" ) != null )
	        document.getElementById ( "cancellationDropDownDiv" ).style.visibility = "hidden";
	    if ( document.getElementById ( "declineDropDownDiv" ) != null )
	        document.getElementById ( "declineDropDownDiv" ).style.visibility = "hidden";
	    if ( document.getElementById ( "exportDropDownDiv" ) != null )    
	        document.getElementById ( "exportDropDownDiv" ).style.visibility = "hidden";
	    
		document.getElementById ( "emailAddressDiv" ).style.display = "block";
		document.getElementById ( "RTFDiv" ).style.display = "none";
		document.getElementById ( "faxDiv" ).style.display = "none";
		document.getElementById ( "emailDiv" ).style.display = "none";
		document.getElementById ( "amrmDiv" ).style.display = "none";
		
		if ( exportOptions.options[exportOptions.selectedIndex].value == "1600" ) // RTf
		{
			document.getElementById ( "RTFDiv" ).style.display = "block";
			document.getElementById ( "emailAddressDiv" ).style.display = "none";
			document.getElementById ( "commentAddressDiv" ).style.display = "none";
			
			document.getElementById ( exportButtonId ).style.display = "none";
	        document.getElementById ( exportRtfButtonId ).style.display = "inline";
		}
		else if ( exportOptions.options[exportOptions.selectedIndex].value == "1601" )
		{
			document.getElementById ( "emailDiv" ).style.display = "block";
			document.getElementById ( "commentAddressDiv" ).style.display = "block";
		}
		else if ( exportOptions.options[exportOptions.selectedIndex].value == "1602" )
		{
			document.getElementById ( "faxDiv" ).style.display = "block";
			document.getElementById ( "emailAddressDiv" ).style.display = "block";
			document.getElementById ( "commentAddressDiv" ).style.display = "block";
		}
		else if ( exportOptions.options[exportOptions.selectedIndex].value == "1603" )
		{
			document.getElementById ( "amrmDiv" ).style.display = "block";
			document.getElementById ( "emailAddressDiv" ).style.display = "none";
			document.getElementById ( "commentAddressDiv" ).style.display = "none";
		}		
		
		document.getElementById ( "QuoteExportOptionsDiv" ).style.display = "block";
		document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "block";   
		self.location.href = '#top'; 
	}
}

function HideExportOptionsPopup ( ExportOptionsDropDownClientId, cancelDropDownClientId, declineDropDownClientId )
{
    // IE 6.0 Bug We need to show the drop down on cancel
    if ( document.getElementById ( "cancellationDropDownDiv" ) != null ) 
        document.getElementById ( "cancellationDropDownDiv" ).style.visibility = "visible";
        
    if ( document.getElementById ( "declineDropDownDiv" ) != null )     
        document.getElementById ( "declineDropDownDiv" ).style.visibility = "visible";
    
    if ( document.getElementById ( "exportDropDownDiv" ) != null )         
        document.getElementById ( "exportDropDownDiv" ).style.visibility = "visible";    

    document.getElementById ( "QuoteExportOptionsDiv" ).style.display = "none";
    document.getElementById ( "OrderManagementBlockInputDiv" ).style.display = "none";   
}

function CancelReservedInventory ( id )
{
    if ( confirm ( 'You are about to cancel this reserved inventory and release the items.\n\nDo you wish to continue' ) ) 
    {
        __doPostBack('CancelReservedInventory',id)
    }
}

function ConvertReservedInventoryToOrderAlert ( )
{   
    alert("PO number is required to submit an order. Please specify PO Number on the Enter Order Details page in order to submit the order.");
}

function ConvertReservedInventoryToOrder ( id )
{

    if ( confirm ( 'You are about to convert this reserved inventory into an order.\n\nDo you wish to continue' ) ) 
    {
        __doPostBack('ConvertReservedInventoryToOrder',id)
    }
}

function LoadEditExpiry ( id, type ) 
{
    var oWin;
    var height = 350;
    var width = 500
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	var url = "../CSR/CSREditExpiry.aspx?OrderId=" + id + "&CartType=" + type;
	
	oWin = window.open ( url, 'EditExpiry', 'status=no,toolbar=no,menubar=no,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );    
}

function EditExpiry(  )
{
    window.opener.location.reload(); //= '../Orders/OrderDetails.aspx?OrderId=' + id;
    window.close ( );
}


function LoadUpdateStatusWindow ( status )
{
    var oWin;
    var height = 250;
    var width = 500
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	var url = "../CSR/CSRUpdateOrderStatus.aspx?statusId=" + status;
	
	oWin = window.open ( url, 'StatusUpdate', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );	   
}

function UpdateStatus(  )
{
    window.opener.location = "../CSR/CSROrderSummary.aspx"; 
    window.close ( );
}


function LaunchEditPriceWindow ( productLineItemId, type, quoteId )
{
    var oWin;
    var height = 300;
    var width = 400
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	var url = "../CSR/CSREditPrice.aspx?LineItemId=" + productLineItemId + "&type=" + type + "&quoteId=" + quoteId ;
	
	oWin = window.open ( url, 'StatusUpdate', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );	   
}

function EditPrice ( id )
{
    window.opener.location.href = window.opener.location.href;
    window.close ( );
}

function TransferAllQuantity ( id, quantity )
{
    var targetQuantityBox = document.getElementById( id )
    targetQuantityBox.value = quantity;
}

function ShowNewOrder ( id, count )
{
    var oWin;
    var height = 150;
    var width = 200;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	var url = "../CSR/CSRSplitConfirmation.aspx?splitType=Order&Id=" + id + "&Count=" +count;
	
	oWin = window.open ( url, 'SplitOrderConfirmation', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );	  
}

function ShowNewQuote ( id, count )
{
    var oWin;
    var height = 150;
    var width = 200;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	var url = "../CSR/CSRSplitConfirmation.aspx?splitType=Quote&Id=" + id + "&Count=" +count;
	
	oWin = window.open ( url, 'SplitOrderConfirmation', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );	  
}

function LaunchSelectQuoteWindow (excludedQuoteId )
{
    var oWin;
    var height = 350;
    var width = 700;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	var url = "../CSR/SelectQuote.aspx?excludedQuoteId=" + excludedQuoteId;
	
	oWin = window.open ( url, 'SelectQuote', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=yes' )
	oWin.focus ( );	   
}

function UnfeasibleInventoryTransfer()
{
    alert("None of the products can be transferred. No inventory has been allocated for this quote.");
}

function SelectQuote (  )
{
    window.opener.location = '../CSR/CSRTransferInventory.aspx';
    window.close ( );
}

function LaunchTempShipWindow( orderID )
{
    var oWin;
    var height = 200;
    var width = 350;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;

	var url = "../CSR/CSREditTempShip.aspx?orderid=" + orderID;
	
	oWin = window.open ( url, 'TempShip', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );	   
}

function ClickClearText(thisFieldId, defaultText) 
{
    var thisField = document.getElementById( thisFieldId );
    if (thisField.value == defaultText) 
    {
        thisField.value = "";
    }
}

function ClickRecall(thisFieldId, defaultText) 
{
    var thisField = document.getElementById( thisFieldId );
    if (thisField.value == "") 
    {
        thisField.value = defaultText;
    }
}

function LaunchDefaultAddressWindow ( url, width, height )
{
    var oWin;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	oWin = window.open ( url, 'Address', 'status=no,toolbar=no,menubar=no,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=yes' )
	oWin.focus ( );
}

function ValidateZIPCode ( countrydropdown )
{
   var e = document.getElementById( countrydropdown );
   var selectedcountry = e.options[e.selectedIndex].value;
  
   if (selectedcountry == "CA")
    {
     return Page_ClientValidate('ZIPVal') && Page_ClientValidate('CAZIPVal');
    } 
    else if (selectedcountry=='US')
    {
     return Page_ClientValidate('ZIPVal') && Page_ClientValidate('USZIPVal');
    }
   
   return true;
     
}
function ValidateOrderDetailsPage ( creditcardrbID , purchasenumberrbID , countrydropdown )
{ 
  var creditradio =document.getElementById( creditcardrbID );
  var purchaseradio = document.getElementById( purchasenumberrbID );
     
    if ( creditradio != null && creditradio.checked ) 
     { 
      return Page_ClientValidate( "byCreditCardVal" ) && Page_ClientValidate( "QuantityVal" ) && Page_ClientValidate( "AccountManagerVal" ) && ValidateZIPCode ( countrydropdown );
     } 
     else if( purchaseradio != null && purchaseradio.checked )
     {
       return Page_ClientValidate("byPurchaseNumVal") && Page_ClientValidate( "QuantityVal" ) && Page_ClientValidate( "AccountManagerVal");
     }
 }
 


function LaunchDownloadBasicSearchResult ( type )
{
    var oWin;
    var url = "DownloadBasicSearchResult.aspx";
    
    if ( type == 'Quote' )
	{
	    url = "../Orders/" + url;
	}
    
	oWin = window.open ( url, 'DownloadBasicSearch')
	oWin.focus ( );	
}


function DownloadAllInventoryforHelp ( url, width, height )
{
    var oWin;
    var top	= (screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	oWin = window.open ( url, 'DownloadAllInventoryForHelp', 'status=no,toolbar=no,menubar=no,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=yes' )
	oWin.focus ( );
}

function LaunchDownloadBasicSearchResultXLS ( )
{
    var oWin;
    var url = "DownloadBasicSearchResult.aspx";
   
	    url = "../Orders/" + url;
    
	oWin = window.open ( url, 'DownloadBasicSearch')
	oWin.focus ( );	
}
function AddressValCustom ( sender, args )
{
    var nonelb = document.getElementById( sender.FieldToCheck );
    args.IsValid= ( nonelb == null || nonelb.innerHTML != "(None)" )
    
    if (sender.NotMandatoryFieldIndicator != null)
    { 
    var isnotmandatory = document.getElementById( sender.NotMandatoryFieldIndicator );
    if ( isnotmandatory.checked )
    { args.IsValid =  true; }
   }

 
}


function AccountNumberEntered ( sender, args )
{
    var ismandatory = null;
    var fieldtocheck = null;
    var carriername = null;
    args.IsValid= true;
    
    if  (sender.MandatoryFieldIndicator != null)
    {
    ismandatory = document.getElementById( sender.MandatoryFieldIndicator );
    }
    if (sender.FieldtoCheck != null)
    {
     fieldtocheck = document.getElementById( sender.FieldtoCheck )
  
     if (fieldtocheck != null) 
        carriername=  fieldtocheck.options[fieldtocheck.selectedIndex].text;
    }
    
    if ( ismandatory == null || ismandatory.checked  )
    { 
     if ( args.Value == null || args.Value == "" )
         {args.IsValid=false;} 
         
     if (args.IsValid == true){
        
       if ( carriername != null && carriername.length >= 0)
        {
       
          if (carriername == "DHL"  )
          { 
            args.IsValid = ValidateRegularExpression(args.Value, "^[A-Za-z0-9]{9}$")
          }
          else
          if (carriername == "FEDEX"  )
          { 
            args.IsValid = ValidateRegularExpression(args.Value, "^[A-Za-z0-9]{9}$")
          }
          else
          if (carriername == "BAX GLOBAL"  )
          { 
            args.IsValid = ValidateRegularExpression(args.Value, "^[A-Za-z0-9]{9}$")
          }
          else
          if (carriername == "UPS"  )
          { 
            args.IsValid = ValidateRegularExpression(args.Value, "^[A-Za-z0-9]{6}$")
          }
          else 
          if (carriername == "EAGLE"  )
          { 
            args.IsValid = true
          }
          else
            args.IsValid = ValidateRegularExpression(args.Value, "^[A-Za-z0-9]{6,19}$")
          
         }
        }
    }

}

  function ValidateRegularExpression( control, validexpress ) 
   { 
      var matches = false;
      
      if(validexpress != null) 
      { 
         var rx = new RegExp(validexpress); 
         matches = rx.test(control); 
     
      } 
      return matches;
   }


function ValidatePostalCode ( sender, args )
{
    var countrycontrol = document.getElementById( sender.FieldToCheck );
    var selectedcountry = countrycontrol.options[countrycontrol.selectedIndex].value;
   
   
   if (selectedcountry == "CA")
    {
     args.IsValid = ValidateRegularExpression( args.Value , "^[abceghjklmnprstvxyABCEGHJKLMNPRSTVXY][0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ] {0,1}[0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ][0-9]$" ) ;
    } 
    else 
    if (selectedcountry == "US")
    {  
     args.IsValid=  ValidateRegularExpression( args.Value , "^[0-9]{5}$" ) ;
    }
    else 
    args.IsValid= true;
 
}
function ValidateQuoteAction ( sender, args )
{
    var fieldtocheck = document.getElementById( sender.FieldToCheck );
    var fieldtocheckvalue = fieldtocheck.options[fieldtocheck.selectedIndex].value;
     
   if (args.Value == ""  && fieldtocheckvalue == sender.ValueToCheck)
    {
     args.IsValid = false; 
    } 
    else 
    {
     args.IsValid= true;
    }
    
}


function ValidateTheatherTime ( sender, args )
{
  var radiolist = document.getElementById( sender.FieldToCheck );

 
    var requiresvalidation  = isValidationRequired(radiolist ,"No");
 
   if ( requiresvalidation && (args.Value == null || args.Value == "" ) )
    {
     args.IsValid = false; 
    } 
    else 
    {
     args.IsValid= true;
    }
}
function isValidationRequired(radiolist, valuetocheck) 
{
        var radioButtons = radiolist.getElementsByTagName('input');
        var result = true;
        for (var x = 0; x < radioButtons.length; x ++)
        { 
          if (radioButtons[x].checked && radioButtons[x].value == valuetocheck)
           {
           result = false;
            }
          }
          
     return result;
      }

function isnullorempty ( valuetocheck )
{
 var result = true;
 if ( valuetocheck != null ) 
 {
 if (valuetocheck.value != "") { result = false;}
 }
 return result;
}

function ValidateSearchFor ( sender, args )
{
   var FieldToCheck = document.getElementById( sender.FieldToCheck );
   var FieldToCheck1 = document.getElementById( sender.FieldToCheck1 );
   var FieldToCheck2 = document.getElementById( sender.FieldToCheck2 );
   var FieldToCheck3 = document.getElementById( sender.FieldToCheck3 );

   if (isnullorempty(FieldToCheck) && isnullorempty(FieldToCheck1) && isnullorempty(FieldToCheck2) && isnullorempty(FieldToCheck3) && args.Value == ""  )
    {
     args.IsValid = false ;
    } 
    else {
    args.IsValid= true;
    
 }
}
function CSRGoto ( url )
{
	return (confirm ( "sure?" ) );
}

var isOnDiv = false;
var currentlyVisibleQuickViewId ='';

var isSNVOnDiv = false;
var currentlyVisibleSiteNameId ='';
function ShowSiteName ( id )
{
	if ( currentlyVisibleSiteNameId != '' )
	{
		isSNVOnDiv = false;
		HideSiteName ( currentlyVisibleSiteNameId );
	}
	
	document.getElementById ( id ).style.visibility = 'visible';
	document.getElementById ( id ).style.position = 'static';

	isSNVOnDiv = false;
	currentlyVisibleSiteNameId = id;
	
	setTimeout ( "HideSiteName( '" + id + "' )", 2000 );
}

function HideSiteName ( id )
{
	if ( !isSNVOnDiv )
	{
		currentlyVisibleSiteNameId = ''
		document.getElementById ( id ).style.visibility = 'hidden';
	}
}
function RegisterMouseOverSNVOn (id )
{
	isSNVOnDiv = true;
}

function RegisterMouseOutSNVFrom ( id )
{
	isSNVOnDiv = false;
	setTimeout ( "HideSiteName( '" + id + "' )", 2000 );
}

function ShowQuickView ( id )
{
	if ( currentlyVisibleQuickViewId != '' )
	{
		isOnDiv = false;
		HideQuickView ( currentlyVisibleQuickViewId );
	}
	
	document.getElementById ( id ).style.visibility = 'visible';
	document.getElementById ( id ).style.position = 'static';

	isOnDiv = false;
	currentlyVisibleQuickViewId = id;
	
	setTimeout ( "HideQuickView( '" + id + "' )", 2000 );
}

function HideQuickView ( id )
{
	if ( !isOnDiv )
	{
		currentlyVisibleQuickViewId = ''
		document.getElementById ( id ).style.visibility = 'hidden';
	}
}

function RegisterMouseOverOn (id )
{
	isOnDiv = true;
}

function RegisterMouseOutFrom ( id )
{
	isOnDiv = false;
	setTimeout ( "HideQuickView( '" + id + "' )", 2000 );
}


function DeletePromoCode (  )
{   var result = false;
    if ( confirm ( 'You are about to delete this promotional document.\n\nDo you wish to continue' ) ) 
    {
        result = true;
    }
    return result;
}


function DeleteTheater (  )
{   
    var result = false;
    if ( confirm ( 'You are about to delete this theater.\n\nDo you wish to continue' ) ) 
    {
        result = true;
    }
    return result;
}

function LaunchRTFQuote ( )
{
	oWin = window.open ( "RTFQuote.aspx", 'QuoteRTF', 'status=no,toolbar=no,menubar=no,titlebar=0,location=no,resizable=yes,scrollbars=yes' )
	oWin.focus ( );	
}
function LaunchFileUpload( btnUpload , txPath )
{
    btnUpload.click();
    txPath.value= btnUpload.value;
    return  false;

}

function ShowHidePromoCode(ids, id2)
{       
    var controlIds = ids.split(",");    
 
    var count = 0;    
    
    for(i = 0; i < controlIds.length; i++)
    {    
         if(document.getElementById(controlIds[i]).value.length > 0) 
             count++;  
    }   

    if (count > 0)
    {   
        document.getElementById(id2).disabled = true;                
    }
    else
    {
        document.getElementById(id2).disabled = false;    
    }    
        
}

function ShowHideDiscount(id, ids)
{       
    var controlIds = ids.split(",");    
 
    var count = 0;    
    var strValue = "";
    strValue = document.getElementById(id).value;
    
    if (strValue == "")
    {   
        for(i = 0; i < controlIds.length; i++)
        {
          document.getElementById(controlIds[i]).disabled = false;          
        }
                      
    }
    else
    {
        for(i = 0; i < controlIds.length; i++)
        {
          document.getElementById(controlIds[i]).disabled = true;          
        }    
    }        
}
function SetFillSpace ( text )
{ // this function is to fill spaces on the part number field as it's no clickable(this will help). the popup quickview is interfering.
 var result = text;
 if (text == "")
 {
  result = "Enter Part Number";

 }
 else
 {
  if (text.length < 34) 
    {
    var i=0;
    for (i=text.length;i<=34; i++) 
        {
        text = text  + " ";
        }
        result = text;
    }
}
return result;
}


function SelectAll (id, checkboxes )
{
    for ( var i=0; i < checkboxes.length; i ++ )
    {
        var obj = document.getElementById ( checkboxes [ i ] );
        obj.checked = id.checked;
    }
}

var newQuoteCountryVal1;
var newQuoteCountryVal1;

function LaunchCustomerSelectWindow ( url,  theater, salesChannel, tbClientId, hdnClientId, countryRequired, countryRequiredMulti  )
{
    var oWin;
    var width = 700;
    var height = 340;
    var top	= ( screenHeight - height ) / 2-50;
	var left = ( screenWidth - width )/2;
	
	InitializeNewQuoteConsoleValidatorsClientVariables ( countryRequired, countryRequiredMulti )
	
	url = url + "?theater=" + theater + "&salesChannel=" + salesChannel + "&textboxcid=" + tbClientId + "&hiddencid=" + hdnClientId;
	oWin = window.open ( url, 'SelectQuoteCustomer', 'status=no,toolbar=no,menubar=no,titlebar=0,width=' + width + ',height=' + height + ' ,top=' + top + ', left=' + left + ',location=no,resizable=no,scrollbars=no' )
	oWin.focus ( );	
}

function InitializeNewQuoteConsoleValidatorsClientVariables ( id1, id2 )
{
    newQuoteCountryVal1 = document.getElementById( id1 );
    newQuoteCountryVal2 = document.getElementById( id2 );
}

function DisableNewQuoteValidators ( )
{
    ValidatorEnable(newQuoteCountryVal1, false); 
    ValidatorEnable(newQuoteCountryVal2, false); 
}

function SelectQuoteCustomer ( txt, id, tbClientId, hdnClientId  )
{
    var tb = window.opener.document.getElementById ( tbClientId );
    var hdn = window.opener.document.getElementById ( hdnClientId );
    var flag = window.opener.document.getElementById ( "customerSelctSubmitted" );
    
    tb.value = txt;
    hdn.value = id;
    
    flag.value = 'true';
    
    window.opener.DisableNewQuoteValidators ( );
    window.opener.document.forms(0).submit();   
    window.close ( );
}


function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}


function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function OnChangePaymentMethod(poNumberTextBoxId, confirmPONumberTextBoxId, purchaseOrderNumberRadioButtonId, 
                            creditCardRadioButtonId, cardTypeDropDownListId, cardNumberTextBoxId, 
                            cardNameTextBoxId, monthDropDownListId, yearDropDownListId, addressLine1TextBoxId, 
                            addressLine2TextBoxId, cityTextBoxId, stateProvinceTextBoxId, zipPostalTextBoxId, countryDropDownListId)
{
    poNumberTextBox = document.getElementById(poNumberTextBoxId);
    confirmPONumberTextBox = document.getElementById(confirmPONumberTextBoxId);
    purchaseOrderNumberRadioButton = document.getElementById(purchaseOrderNumberRadioButtonId);
    creditCardRadioButton = document.getElementById(creditCardRadioButtonId);
    cardTypeDropDownList = document.getElementById(cardTypeDropDownListId);
    cardNumberTextBox = document.getElementById(cardNumberTextBoxId);
    cardNameTextBox = document.getElementById(cardNameTextBoxId);
    monthDropDownList = document.getElementById(monthDropDownListId);
    yearDropDownList = document.getElementById(yearDropDownListId);
    addressLine1TextBox = document.getElementById(addressLine1TextBoxId);
    addressLine2TextBox = document.getElementById(addressLine2TextBoxId);
    cityTextBox = document.getElementById(cityTextBoxId);
    stateProvinceTextBox = document.getElementById(stateProvinceTextBoxId);
    zipPostalTextBox = document.getElementById(zipPostalTextBoxId);
    countryDropDownList = document.getElementById(countryDropDownListId);

    if ( purchaseOrderNumberRadioButton.checked)
    {
       poNumberTextBox.disabled = false;   
       confirmPONumberTextBox.disabled = false;
       
       cardTypeDropDownList.disabled = true; 
       cardTypeDropDownList.selectedIndex = 0;
       
       cardNumberTextBox.disabled = true;
       cardNumberTextBox.value = "";
       
       cardNameTextBox.disabled = true;
       cardNameTextBox.value = "";
       
       monthDropDownList.selectedIndex = 0;
       monthDropDownList.disabled = true;

       yearDropDownList.selectedIndex = 0;
       yearDropDownList.disabled = true;

       
       addressLine1TextBox.disabled = true;
       addressLine1TextBox.value = "";
       
       addressLine2TextBox.disabled = true;
       addressLine2TextBox.value = "";
       
       cityTextBox.disabled = true;
       cityTextBox.value = "";
       
       stateProvinceTextBox.disabled = true;
       stateProvinceTextBox.value = "";
       
       zipPostalTextBox.disabled = true;
       zipPostalTextBox.value = "";
       
       countryDropDownList.selectedIndex = 0;
       countryDropDownList.disabled = true;
    }
    else
    {
       poNumberTextBox.disabled = true;  
       poNumberTextBox.value = "";
        
       confirmPONumberTextBox.disabled = true;  
       confirmPONumberTextBox.value = "";
       
       cardTypeDropDownList.disabled = false; 
       cardNumberTextBox.disabled = false;
       cardNameTextBox.disabled = false;
       monthDropDownList.disabled = false;
       yearDropDownList.disabled = false;
       addressLine1TextBox.disabled = false;
       addressLine2TextBox.disabled = false;
       cityTextBox.disabled = false;
       stateProvinceTextBox.disabled = false;
       zipPostalTextBox.disabled = false;
       countryDropDownList.disabled = false;
    }
        
}