﻿


		////THis function is triggered by the onFocus event of the relevant form
		//window.onload = function firstInputFieldFocus(){

        //    var sFieldToFocusID //name of field to set focus to

		//	objFirstTextBox = document.getElementById(sFieldToFocusID)
		//	objFirstTextBox.focus()
			
		//}//firstInputFieldFocus
		
		

		//////////////////////////////////////////////////////////////
		//Function that opens a help pop-up window under tab strip
		//Similar to openWindow() 
		function openTabWindow(pagePath)
		{
			window.open("../../helpRedirect.aspx?pagePath=" + pagePath ,"windowComment","scrollbars,HEIGHT=560,WIDTH=690"); 
		}




//		///////////////////////////////////////
//		// T R A C K I N G   F U N C T I O N S
		
//		var barcodeList = ""
//		var barcodeHTMLList = ""
//		var arrBarcodes = new Array()
		
//		//SET FOCUS TO BARCODE FIELD
//		window.onload = function setFocus(){
//			//document.forms(0).elements["txtTRK_BoxBarcode"].focus() 
//		}		
		
//		//Build list of barcodes before submit
//		function addBarcodes(){
//			if (document.forms(0).elements["txtTRK_BoxBarcode"].value == ""){
//				alert("You must scan/enter a box barcode AND click 'View Content' before adding new questionnaires!")
//			}else{
//				var barcodeNum = document.forms(0).elements["txtTRK_ItemBarcode"].value
//					if(barcodeNum != ""){
//						//create array of barcodes
//						arrBarcodes.push(barcodeNum)
//						//barcodeList += barcodeNum + '|'
//						//document.forms(0).elements["txtTRK_Hidden"].value = barcodeList
//
//						//Display barcodes
//						showBarcodeList()
//					}
//			}
//		}


//		//remove one barcode from list
//		function removeBarcode(iBarcodeIndexNum){
//			arrBarcodes.splice(iBarcodeIndexNum, 1)
//			showBarcodeList()
//		}


//		//CHECK IF SAVED
//		window.onunload = function checkIfSaved(){
//			var ref = document.location.href;
//			if (arrBarcodes.length > 0){
//			} 					
//		}


//		//DISABLE THE ENTER KEY (so that page not re-loaded by scanner)
//		window.document.onkeypress = function disableEnterKey(){
//			if (window.event.keyCode == 13){
//			window.event.keyCode =0;
//			addBarcodes()
//			document.forms(0).elements["txtTRK_ItemBarcode"].value=""
//			document.forms(0).elements["txtTRK_ItemBarcode"].focus()
//			}		
//		}  

//		//Display list of barcodes
//		function showBarcodeList(){
//			barcodeHTMLList = ""
//			var num
			
//			//Prompt user to save before continue
//			if(arrBarcodes.length > 24){
//				alert("Please add existing barcodes to box before you continue...")
//			}
			
//			for (num = 0; num < arrBarcodes.length; num++) {
//				barcodeHTMLList += arrBarcodes[num] + " <a href=\"Javascript:void(0)\" onclick=\"removeBarcode('" + num + "')\"> Remove</a><br>\n"
//			}
//				//Convert to string
//				document.forms(0).elements["txtTRK_Hidden"].value = arrBarcodes.toString()
//				document.forms(0).elements["txtTRK_Hidden"].value = document.forms(0).elements["txtTRK_Hidden"].value.replace(/,/g, "|")
//				
//				objDivBarcodeList = document.getElementById('divBarcodeList');
//				objDivBarcodeList.innerHTML = barcodeHTMLList;
//
//				//Re-focus the barcode field
//				document.forms(0).elements["txtTRK_ItemBarcode"].focus()
//		}		



//		/////////////////////////////////////////////////////////
//		//Function that opens a label pop-up window for printing
//		function openLabelPrintWindow()
//		{
//			var doPreview	//When = 0 the pop-up window will just initiate
//							// a print and close immediately.
//			if (Form1.checkPrintPreview.checked){
//				doPreview = "&doPreview=" + 1
//			}else{
//				doPreview = "&doPreview=" + 0	
//			}
//			window.open("itemLabelTemplate.aspx?" + Form1.txtSelectedOrderListParameters.value + Form1.txtLabelParameters.value + doPreview, "windowComment","scrollbars,HEIGHT=450,WIDTH=550"); 
//		}


        //this function will show the content within the <div> tag
        function showLoader() 
        {
          thisDiv = document.getElementById('loader');
          if (thisDiv) 
          {
            if (thisDiv.style.display == "none") {
              thisDiv.style.display = "block"; //"inline";
            }
            
          // IN IE the loader image stops animating on postback
          // Solution: set the src on load and..
          // Add the following to button  click event:
          // setTimeout('showLoader();',50);
          
          var img = document.getElementById('loaderImage');
              //Use when go-Live  
              img.src = "/images/loading.gif";
              //Use when site runs in virtul directory called 'steps' OR on myHOsting.com (LIVE)
              //img.src = "/steps/images/loading.gif";
          //img.setAttribute("width", 32);
          //img.setAttribute("height", 32);
              
          }
          
          else {
            //alert("Error: Could not locate div with id: " + divName);
          }
        }


        //this function will hide the content within the <div> tag
        function hideLoader() 
        {
          thisDiv = document.getElementById('loader');
          if (thisDiv) 
          {
            //if (thisDiv.style.display == "block") {
              var img = document.getElementById('loaderImage');
              //Use when go-Live  
              img.src = "/images/loading.gif";
              //Use when site runs in virtul directory called 'steps'
              //img.src = "/steps/images/loading.gif";
              img.setAttribute("width", 32);
              img.setAttribute("height", 32);

              thisDiv.style.display = "none";
              
            //}
          }
          else {
            //alert("Error: Could not locate div with id: " + divName);
          }
        }


        ///////////////////////////////////////////////////////////////
        //this function will show the content within the <div> tag
        function showLoader_line() 
        {

            thisDiv = document.getElementById('loader_line');
          if (thisDiv) 
          {
            if (thisDiv.style.display == "none") {
              thisDiv.style.display = "block"; //"inline";
            }
            
          // IN IE the loader image stops animating on postback
          // Solution: set the src on load and..
          // Add the following to button  click event:
          // setTimeout('showLoader();',50);
          
          var img = document.getElementsByName('loaderImage_line');
              //Use when go-Live
          img.src = "./images/loading_line2.gif";
              //Use when site runs in virtul directory called 'steps'
              //img.src = "/steps/images/loading_line.gif";
          //img.setAttribute("width", 32);
          //img.setAttribute("height", 32);
              
          }
          
          else {
            //alert("Error: Could not locate div with id: " + divName);
          }
        }


        //this function will hide the content within the <div> tag
        function hideLoader_line() 
        {
        
          try{
                     
              thisDiv = document.getElementById('loader_line');
              if (thisDiv) 
              {
                //if (thisDiv.style.display == "block") {
                  var img = document.getElementsByName('loaderImage_line');
                  //Use when go-Live
                  img.src = "./images/loading_line2.gif";
                  //Use when site runs in virtul directory called 'steps'
                  //img.src = "/steps/images/loading_line.gif";
                  //img.setAttribute("width", 32);
                  //img.setAttribute("height", 32);

                  thisDiv.style.display = "none";
                  
                //}
              }
              else {
                //alert("Error: Could not locate div with id: " + divName);
              }

         }catch(e){
            //dO NOTHING
         }        


        }


    ///////////////////////////////
    ///// HIGHLIGHT GRIDVIEW ROW - START
        
        // try{
        
        // }catch(e){

        // }
        
           var gridViewCtlId = '<%=gvMain.ClientID%>';
            var gridViewCtl = null;
            var curSelRow = null;
            function getGridViewControl()
            {
                if (null == gridViewCtl)
                {
                    
                    try{
                    gridViewCtl = document.getElementById(gridViewCtlId);
                    }catch(e){
                        // Do nothing
                    }
                }
            }
            
            function onGridViewRowSelected(rowIdx)
            {
                var selRow = getSelectedRow(rowIdx);
                if (curSelRow != null)
                {
                    curSelRow.style.backgroundColor = '#ffffff';
                }
                
                if (null != selRow)
                {
                    curSelRow = selRow;
                    curSelRow.style.backgroundColor = '#ff0022';
                }
            }
            
            function getSelectedRow(rowIdx)
            {
                getGridViewControl();
                if (null != gridViewCtl)
                {
                    return gridViewCtl.rows[rowIdx];
                }
                return null;
            }

    //// HIGHLIGHT GRIDVIEW ROW - END


            // AUTO POSTBACK   F U N C T I O N S --------------------------------------- START
            // Script to generate an automatic postBack to the server
            var secs
            var timerID = null
            var timerRunning = false
            var delay = 1000
            function InitializeTimer()
            {
                // Set the length of the timer,
                 // in seconds. Your choise
                secs = 10

                StopTheClock()
                StartTheTimer()
            }
            
            function StopTheClock()
            {
                if(timerRunning)
                    clearTimeout(timerID)
                timerRunning = false
            }
            
            function StartTheTimer()
            {
            
                if (secs==0)
                {
                    StopTheClock()

                    //EXCUTE SCRIPT TO CHECK FOR ADMIN ALERTS on regular intervals!
                    getNotification()  
                 
                }
                else
                {
                    secs = secs - 1
                    timerRunning = true
                    timerID = self.setTimeout("StartTheTimer()", delay)
                }
            }
    
    
    
    
    		// A J A X   F U N C T I O N S --------------------------------------- START
		
			var xmlHttp = null; 
			var requestURL = ''; 

			var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
			var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
			var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
			//netscape, safari, mozilla behave the same??? 
			var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0; 
		

			//THIS FUNCTION FIRES ON REGULAR INTERVALS TO GET URGENT NOTIFICATIONS FROM ADMIN,
			//E.G. SERVER RE-START!
			function getNotification(){
			    try {
                
				    //The UniqueDivID, UniqueImageID to be returned with status update from server for updating status image
				    requestURL = "/ajaxUpdate.aspx?action=getLIVENotification"  
				    //alert(requestURL)
    			
     			    // POST to get message
     			    //show_data(UniqueDivID, UniqueImageID, requestURL)
     			    xmlreqGET(requestURL)

			    }catch(exc){
				    //Do nothing
			    }
			}
	

		//Variable contains multiple Request Objects for Async Postbacks
		var xmlreqs = new Array();

		//Create new XMLHttpRequest Objects
		function CXMLReq(freed) {
			this.freed = freed;
			this.xmlhttp = false;
			if (window.XMLHttpRequest) {
				this.xmlhttp = new XMLHttpRequest();
			} else if (window.ActiveXObject) {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}


		// GET METHOD OF POSTING DATA
		//When either xmlreq function is called, it searches the array for a free object and sets pos equal to 
		//that object's position (or to the end of the array if no free objects are available).

		function xmlreqGET(requestURL) {
			var pos = -1;
			for (var i=0; i<xmlreqs.length; i++) {
				if (xmlreqs[i].freed == 1) { pos = i; break; }
			}
			if (pos == -1) { pos = xmlreqs.length; xmlreqs[pos] = new CXMLReq(1); }
			if (xmlreqs[pos].xmlhttp) {

				xmlreqs[pos].freed = 0;
				
				xmlreqs[pos].xmlhttp.open("GET",requestURL,true); //True means Asynchronous

				//The onreadystatechange function is now declared inline, so that we can pass an argument,
				//to xmlhttpChange, the handler that fires when info is returned. 
				//Rather than loop through the array every time we get a result, just tell it which item we want to use 
				//in the first place. Since we never remove items from the array, passing pos won't cause problems.

				xmlreqs[pos].xmlhttp.onreadystatechange = function() {
					if (typeof(xmlhttpChange) != 'undefined') { 
					xmlhttpChange(pos); 
					}
				}


				if (window.XMLHttpRequest) {
					xmlreqs[pos].xmlhttp.send(null);
				} else if (window.ActiveXObject) {
					xmlreqs[pos].xmlhttp.send();
				}
			}
		}



		// POST METHOD OF POSTING DATA
		function xmlreqPOST(requestURL,data) {
			var pos = -1;
			for (var i=0; i<xmlreqs.length; i++) {
				if (xmlreqs[i].freed == 1) { pos = i; break; }
			}
			if (pos == -1) { pos = xmlreqs.length; xmlreqs[pos] = new CXMLReq(1); }
			if (xmlreqs[pos].xmlhttp) {
				xmlreqs[pos].freed = 0;
				xmlreqs[pos].xmlhttp.open("POST",requestURL,true);
				xmlreqs[pos].xmlhttp.onreadystatechange = function() {
					if (typeof(xmlhttpChange) != 'undefined') { xmlhttpChange(pos); }
				}
				xmlreqs[pos].xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xmlreqs[pos].xmlhttp.send(data);
			}
		}



		// THIS HANDLER WILL FIRE WHEN THE STATE HAS CHANGED, i.e. DATA RECEIVED BACK FROM SERVER
		function xmlhttpChange(pos) {
			//Execute only when: xmlreqs ARRAY is not Undefined, AND Object is FREE, AND Readystate complete (All data downloaded) 
			if (typeof(xmlreqs[pos]) != 'undefined' && xmlreqs[pos].freed == 0 && xmlreqs[pos].xmlhttp.readyState == 4) {


				if (xmlreqs[pos].xmlhttp.status == 200 || xmlreqs[pos].xmlhttp.status == 304) {


					//if you just want to put the entire response into an element, 			
					//you can use responseText instead of responseXML
					
							//Gather the results from the callback 
							var str = xmlreqs[pos].xmlhttp.responseText //xmlHttp.responseText; 

							//check if valid result returned
							if (str.indexOf("||", 0) >= 0){
								
								//Response string looks like:
							    // alert||UserID||UniqueMessageID||message||Error (If any)
								var arrResult = str.split("||")

								//alert(arrResult[1])

								if (arrResult[0] == 'alert') {

                                    if (readCookie(arrResult[2]) != null) {
                                    
                                        // do not pop up message, already exists

                                    } else {
                                    
                                    //DISPLAY THE MESSAGE:
                                        //Day
                                        var currentDate = new Date()
                                        var day = currentDate.getDate()
                                        var month = currentDate.getMonth()
                                        var year = currentDate.getFullYear()
                                        //Time
                                        var currentTime = new Date()
                                        var hours = currentTime.getHours()
                                        var minutes = currentTime.getMinutes()

                                        if (minutes < 10)
                                        minutes = "0" + minutes


                                        var MSGTag
                                        MSGTag = "MESSAGE SENT ON: " + day + "/" + month + "/" + year + " " + hours + " h " + minutes

                                        //NOTE var UserID is set in parent page
                                        //If the userID in APP variable matches the current user's
                                        //personnelif OR if 0 (ALL USERS), then display message.
                                        if (UserID == arrResult[1] || arrResult[1] == 0) {
                                        
                                            //ALERT USER
                                            alert(arrResult[3] + "\n\n" + MSGTag)
                                            //alert("ID: " + arrResult[2] + "\n\n" + arrResult[3] + "\n\n" + MSGTag + "\n\nUserID: " + UserID + " / arrResult[1]" + arrResult[1])

                                            //PROMPT FOR FEEDBACK
                                            //var name = prompt(arrResult[3] + "\n\n" + MSGTag + "\n\nPLEASE CONFIRM BELOW:", "");
                                            //if (name != null && name != "") {
                                                //alert("Thank you " + name + "!");
                                                //POST ANSWER BACK top ADMIN:
                                                
                                            //}

                                        //CREATE COOKIE TO STOP MULTIPLE POP-UPS
                                        createCookie(arrResult[2], arrResult[3], 30)
                                        }

                                    }
    
								
								} else {
                                    //do nothing									
								}
													
							}else{
                                //do nothing									
							}
					//This function will process the XML document returned
					//handle_response(xmlreqs[pos].xmlhttp.responseXML);
					

				} else {
				//handle_error();
					// THIS MUST BE DISABLED ON LIVE....
					alert("STEPS AJAX FAILED: " + xmlreqs[pos].xmlhttp.responseText)
				}
				xmlreqs[pos].freed = 1; //set freed to 1 in order to re-use the xmlhttp object
			}
		}


		// A J A X   F U N C T I O N S --------------------------------------- END



		// C O O K I E   F U N C T I O N S ----------------------------------- START 


		function createCookie(name, value, days) {
		    if (days) {
		        var date = new Date();
		        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		        var expires = "; expires=" + date.toGMTString();
		    }
		    else var expires = "";
		    document.cookie = name + "=" + value + expires + "; path=/";
		}

		function readCookie(name) {
		    var nameEQ = name + "=";
		    var ca = document.cookie.split(';');
		    for (var i = 0; i < ca.length; i++) {
		        var c = ca[i];
		        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
		    }
		    return null;
		}

		function eraseCookie(name) {
		    createCookie(name, "", -1);
		}

		// C O O K I E   F U N C T I O N S ----------------------------------- END



		// URL ENCODE/DECODE   F U N C T I O N S ----------------------------- START

		//<!CDATA[
		// ====================================================================
		//       URLEncode and URLDecode functions
		//
		// Copyright Albion Research Ltd. 2002
		// http://www.albionresearch.com/
		//
		// You may copy these functions providing that 
		// (a) you leave this copyright notice intact, and 
		// (b) if you use these functions on a publicly accessible
		//     web site you include a credit somewhere on the web site 
		//     with a link back to http://www.albionresearch.com/
		//
		// If you find or fix any bugs, please let us know at albionresearch.com
		//
		// SpecialThanks to Neelesh Thakur for being the first to
		// report a bug in URLDecode() - now fixed 2003-02-19.
		// And thanks to everyone else who has provided comments and suggestions.
		// ====================================================================
		function URLEncode(plaintext) {
		    
		        // The Javascript escape and unescape functions do not correspond
		        // with what browsers actually do...
		        var SAFECHARS = "0123456789" + 				// Numeric
		        "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
		        "abcdefghijklmnopqrstuvwxyz" +
		        "-_.!~*'()"; 				// RFC2396 Mark characters
		        var HEX = "0123456789ABCDEF";

		        var encoded = "";
		        for (var i = 0; i < plaintext.length; i++) {
		            var ch = plaintext.charAt(i);
		            if (ch == " ") {
		                encoded += "+"; 			// x-www-urlencoded, rather than %20
		            } else if (SAFECHARS.indexOf(ch) != -1) {
		                encoded += ch;
		            } else {
		                var charCode = ch.charCodeAt(0);
		                if (charCode > 255) {
		                    alert("Unicode Character '"
                          + ch
                          + "' cannot be encoded using standard RFC2396 encoding.\n" +
	                  "(URL encoding only supports 8-bit characters.)\n" +
			          "A space (+) will be substituted.");
		                    encoded += "+";
		                } else {
		                    encoded += "%";
		                    encoded += HEX.charAt((charCode >> 4) & 0xF);
		                    encoded += HEX.charAt(charCode & 0xF);
		                }
		            }
		        } // for

		        return encoded;
		};


		function URLDecode(encoded) {
		        // Replace + with ' '
		        // Replace %xx with equivalent character
		        // Put [ERROR] in output if %xx is invalid.
		        var HEXCHARS = "0123456789ABCDEFabcdef";
		        var plaintext = "";
		        var i = 0;
		        while (i < encoded.length) {
		            var ch = encoded.charAt(i);
		            if (ch == "+") {
		                plaintext += " ";
		                i++;
		            } else if (ch == "%") {
		                if (i < (encoded.length - 2)
					  && HEXCHARS.indexOf(encoded.charAt(i + 1)) != -1
					  && HEXCHARS.indexOf(encoded.charAt(i + 2)) != -1) {
		                    plaintext += unescape(encoded.substr(i, 3));
		                    i += 3;
		                } else {
		                    alert('Bad escape combination near ...' + encoded.substr(i));
		                    plaintext += "%[ERROR]";
		                    i++;
		                }
		            } else {
		                plaintext += ch;
		                i++;
		            }
		        } // while
		        return plaintext;
		};
		//]]>
		// URL ENCODE/DECODE   F U N C T I O N S ----------------------------- END

