﻿// JScript File

    $(document).ready(function() {
        $('a.menuItem').hover(function() {
            $('#dropmenudiv').children().css('width', $('#dropmenudiv').width() - 7);
        });
    });

    function getRequest() {
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandler);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
    }
    function beginRequestHandler(sender, args)
    {
         var elem = args.get_postBackElement();
         elem.style.visibility = "hidden";
     }
     function endRequestHandler(sender, args) {
     }    

    function startPopupUserDefault(msg, idx, path) {
        $(document).ready(function() {
            msg = msg.replace(/\n/g, '<br />');
            $("[id$='_lblMessage']").html(msg);
            $.ajax({
                type: 'POST',
                url: path + '/StemsourceWebService.asmx/SetAlertId',
                data: { aid: idx }
            })
            loadPopup();
        });
    }

    function setDatePicker(idx, culture) {
        $(document).ready(function() {
            $.datepicker.setDefaults($.datepicker.regional[""]);
            $(idx).datepicker($.datepicker.regional[culture]);
        });
    }


    // OLD JS CODE ------------------------------------------------------------------------------------

    function CloseandReloadParent()
    {      
         window.opener.location.reload();
         self.close();return false;
         //alert(window.opener.location);
    }

    function openPrintout(url) {
       var w = window.open(url, 'PrintPopout', 'top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=100,statusbar=0,menubar=0,resizable=1,modal=yes');
    }

    function openCryostoragePrintout(strpath) {
       var url = strpath + "/ProcTech/CryostoragePrintout.aspx";
       var w = window.open(url, 'PrintPopout', 'top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=100,statusbar=0,menubar=0,resizable=1,modal=yes');
    }

    function openProcessingPrintout(strpath)
    {
        var url = strpath + "/ProcTech/ProcessingPrintout.aspx";
        var w = window.open(url,'PrintPopout','top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=100,statusbar=0,menubar=0,resizable=1,modal=yes');
    }
    
    function openRetrievalPrintout(strpath)
    {
      var url = strpath + "/ProcTech/RetrievalPrintout.aspx";
        var w = window.open(url,'PrintPopout','top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,modal=yes');            
    }
    
    function openPrepareCryoprotectantPrintout(strpath)
    {
        var url = strpath + "/ProcTech/PrepareCryoprotectantPrintout.aspx";
        //alert(url);
        var w = window.open(url,'PrintPopout','top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,modal=yes');            
    }
    
//        function openTissueCollectionPrintout(strpath)
//        {
//            var url = strpath + "/ProcTech/TissueCollectionPrintout.aspx";
//            var w = window.open(url,'PrintPopout','top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,modal=yes');
//        }
    
    function printWindow()
    {
      window.print();
     }
   
   function openCryoPreservationPrintout (strpath)
    {
        var url = strpath + "/ProcTech/CryopreservationPrintout.aspx";
        var w = window.open(url,'PrintPopout','top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,modal=yes');
    } 
    
    function openPatientPrintout(strpath)
    {
        var url = strpath + "/ProcTech/PatientFormPrintout.aspx";
        var w = window.open(url,'PrintPopout','top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=100,statusbar=0,menubar=0,resizable=1,modal=yes');
    }

    function openPatientIDPrintout(strpath) {
        var url = strpath + "/ProcTech/PatientIDPrintout.aspx";
        var w = window.open(url, 'PrintPopout', 'top=50,left=100,height=320,width=420,toolbar=0,scrollbars=1,location=100,statusbar=0,menubar=0,resizable=0,modal=yes');
    }

    function openSampleDispositionPrintout(strpath)
    {
        var url = strpath + "/ProcTech/DisposeSamplePrintout.aspx";
        var w = window.open(url,'PrintPopout','top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=100,statusbar=0,menubar=0,resizable=1,modal=yes');
    }
    
    function openMaintenancePrintout(strpath)
    {
        var url = strpath + "/Equipment/UnschedMaintenancePrintout.aspx";
        var w = window.open(url,'PrintPopout','top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=100,statusbar=0,menubar=0,resizable=1,modal=yes');
    }

    function openFreezerLocationPrintout(strpath) {
        var url = strpath + "/ProcTech/FreezerLocationPrintout.aspx";
        var w = window.open(url, 'PrintPopout', 'top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=100,statusbar=0,menubar=0,resizable=1,modal=yes');
    }
    
    function checkFileUpload(control)
    {
       var ccontrol = document.getElementsByName(control)[0];
       if(ccontrol.value.length >= 1)
       {
         var ccontrol1 = ccontrol.cloneNode(true);
         ccontrol1.onchange = ccontrol.onchange;
         ccontrol.parentNode.replaceChild(ccontrol1,ccontrol);
       }
    }
    
    function ClientAlert(strMessage)
    {
        alert(strMessage);
    }

    function ClientConfirm(strMessage)
    {
        confirm(strMessage);
    }
    
    //from master pages
    function CheckFileUpload(control) {
        var ccontrol = document.getElementsByName(control)[0];
        //alert(ccontrol.value);
        if (ccontrol.value.length >= 1) {
            var ccontrol1 = ccontrol.cloneNode(false);
            ccontrol1.onchange = ccontrol.onchange;
            ccontrol.parentNode.replaceChild(ccontrol1, ccontrol);
            alert('Please use the browse button to select a file for uploading.');
        }
    }

    function CheckFileUpload1(control, control2) {
        var ccontrol = document.getElementsByName(control)[0];
        var pathfilename = ccontrol.value;
        var pathfilename_array = pathfilename.split("/");
        var lowerbound = pathfilename_array.length - 1;
        var filename = pathfilename_array[lowerbound];
        var filename_array = filename.split(".");
        var lowerbound1 = filename_array.length - 1;
        var filetype = filename_array[lowerbound1];

        if (filetype != "pdf") {
            clearFileUploadValue(ccontrol)
            alert('Cannot upload files other than pdf.');
        }

    }

    function clearFileUploadValue(ccontrol) {
        var ccontrol1 = ccontrol.cloneNode(false);
        ccontrol1.onchange = ccontrol.onchange;
        ccontrol.parentNode.replaceChild(ccontrol1, ccontrol);
    }

    function openPrintout(url) {
        var w = window.open(url, 'PrintPopout', 'top=50,left=100,height=650,width=600,toolbar=0,scrollbars=1,location=100,statusbar=0,menubar=0,resizable=1,modal=yes');
    }

    //from validateTextbox.js
    function checkLength(control, maxLength) {
        var ccontrol = document.getElementById(control);

        if (ccontrol.value.length > maxLength) {
            ccontrol.value = ccontrol.value.substring(0, maxLength);
        }
    }

    function CheckUncheckAll(cbid, gvid) {
        var gv = document.getElementById(gvid);
        var cell;
        if (gv.rows.length > 0) {
            for (i = 1; i < gv.rows.length; i++) {
                cell = gv.rows[i].cells[0];
                for (j = 0; j < cell.childNodes.length; j++) {
                    if (cell.childNodes[j].type == "checkbox") {
                        cell.childNodes[j].checked = document.getElementById(cbid).checked;
                    }
                }
            }
        }
    }

    function ClearFileUpload(FileUploadid) {
        var fileupload = document.getElementsByName(FileUploadid)[0];
        fileupload.value = "";

        var fileupload2 = fileupload.cloneNode(false);
        fileupload2.onchange = fileupload.onchange;
        fileupload.parentNode.replaceChild(fileupload2, fileupload);

    }

    // from BarcodePrintout01.aspx

		function trim12(str) {
			str = str.replace(/^\s\s*/, ''),
		        ws = /\s/,
		        i = str.length;
			while (ws.test(str.charAt(--i)));
			return str.slice(0, i + 1);
		}

		function addOption(selectbox, text, value) {
			var optn = document.createElement("OPTION");
			optn.text = text;
			optn.value = value;
			selectbox.options.add(optn);
		}

		function GetPrinters(htxt) {
			var iCount = 0;
			var BC_Printer = document.getElementById("BC_Printer");
			BC_Printer.Key = "41029F45DAF8CECCAED99F98E9AE9F67DF33EB66DA75712BBD1F52D9CA3652208A11FCA8EC86CF4402AB050";   //production key
			var s = BC_Printer.GetPrinters(iCount, true);
			var b1 = s.toString();
			var b = b1.split('|');

			var ddlp = document.getElementById("ddlPrinter");
			ddlp.options.length = 0;

			if (s != null) {
				for (x = 0; x < b.length; x++) {
					var printer_name = b[x];
					addOption(ddlp, printer_name, printer_name);
					if (x == 0) {
						var t = document.getElementById(htxt);
						t.value = printer_name;
					}
				}
			}
		}

		function onSelectPrinter1(ddlp, htxt) {
			//alert(ddlp);
			var s = document.getElementById("ddlPrinter");

			var n = s.selectedIndex;
			var g_printerName = n != -1 ? s.options[n].value : "";

			var t = document.getElementById(htxt);
			t.value = g_printerName;
		}

		function PrintRawData(data, printer1, data1) {
			var d1 = document.getElementById(data);
			var p1 = document.getElementById(printer1);
			var dd1 = document.getElementById(data1);

			var d2 = d1.value;
			var p2 = p1.value;
			var dd2 = dd1.value;

			if (p2.toString().indexOf("DYMO") >= 0) {
				PrintDymoData(dd2.toString());
			}
			else {
				var prin = document.getElementById("BC_Printer");
				prin.PrintRawData(d2.toString(), "", trim12(p2.toString()));
			}
		}

		function PrintDymoData(data) {
			var DymoAddIn, DymoLabel;
			DymoAddIn = new ActiveXObject('DYMO.DymoAddIn');
			DymoLabel = new ActiveXObject('DYMO.DymoLabels');
			if (DymoAddIn.Open('C:\\Documents and Settings\\All Users\\Documents\\DYMO Label\\Label Files\\BarcodeGs1.LWL')) {
				var arrBc = new Array();
				arrBc = data.split("***");
				for (i = 0; i < arrBc.length; i++) {
					if (arrBc[i].length != 0) {
						var arr1 = new Array();
						arr1 = arrBc[i].toString().split("???");

						{
							DymoLabel.SetField('BARCODE', arr1[0].toString());
							DymoLabel.SetField('TEXT', arr1[1].toString());
							DymoAddIn.Print(1, true);
						}

					}
				}
			}
		}

		// from callPostBack.js
		
		function callPostback() {
		    var cc = document.getElementById("btnHidden");
		    cc.click();
		}
    

        
