﻿// JScript File
      
        function IsNumeric(sText) {
           var ValidChars = "0123456789.";
           var IsNumber=true; var Char;    
           for (i = 0; i < sText.length && IsNumber == true; i++) { 
              Char = sText.charAt(i); 
              if (ValidChars.indexOf(Char) == -1) {IsNumber = false;}
           }
           return IsNumber;}

        function trim(s){
            if (s=="") return s;
            return rtrim(ltrim(s));}
        function ltrim(s){
            if (s=="") return s;
	        var l=0;
	        while(l < s.length && s[l] == ' '){	l++; }
	        return s.substring(l, s.length);}
        function rtrim(s){
            if (s=="") return s;
	        var r=s.length -1;
	        while(r > 0 && s[r] == ' ')	{	r-=1;	}
	        return s.substring(0, r+1);}


    ///////////////////////////////////////////////////////////////////////	
    // preview functions	
    ///////////////////////////////////////////////////////////////////////

	    var PreviewBGHeight=200;
	    var PreviewBGwidth=200;
	    var PreviewBGOffset=7;
	    var isIE = document.all?true:false;

	    function Show_Preview(x,y,visible) {
		    // resize and Move the basket to the bottom of the page 	
		    var objPreviewDiv	 =document.getElementById("PreviewLayer");
		    var objPreviewSpan	 =document.getElementById("PreviewBGSpan");
		    var objPreviewSpanImg=document.getElementById("PreviewBGImg");
    			
		    var objMainImageDiv	 =document.getElementById("MainImageDiv");
		    var objMainImageSpan =document.getElementById("MainImageSpan");
		    var objMainImage     =document.getElementById("MainImage");
    				
		    objPreviewDiv.style.top=y;
		    objPreviewDiv.style.left=x;
		    objPreviewDiv.style.width=PreviewBGwidth;
		    objPreviewDiv.style.height=PreviewBGHeight;

		    objPreviewSpanImg.style.left=0;
		    objPreviewSpanImg.style.top=0;	
		    objPreviewSpanImg.style.width=PreviewBGwidth;
		    objPreviewSpanImg.style.height=PreviewBGHeight;
    		
		    objMainImageDiv.style.left= (PreviewBGwidth-objMainImage.width) / 2;	
		    objMainImageDiv.style.top= (PreviewBGHeight-objMainImage.height) / 2;	

		    if (visible) {
			    objPreviewDiv.style.visibility="visible";
			    objMainImageDiv.style.visibility="visible";
		    }
		    else {
			    objPreviewDiv.style.visibility="hidden";
			    objMainImageDiv.style.visibility="hidden";	
		    }
	    }

	    function RegisterMouseMove(imagename) {
		    if (!isIE) document.captureEvents(Event.MOUSEMOVE);
		    document.onmousemove = Move_Preview;
		    var objMainImage     =document.getElementById("MainImage");
		    objMainImage.src	 =imagename;
		    PreviewBGwidth = objMainImage.width + (PreviewBGOffset * 2);
		    PreviewBGHeight = objMainImage.height + (PreviewBGOffset * 2);
	    }

	    function UnregisterMouseMove() {
		    if (!isIE) document.releaseEvents(Event.MOUSEMOVE);
		    document.onmousemove = null;
		    Show_Preview(0,0,false);
	    }

	    function Move_Preview(e) {
		    var mx;
		    var my;
		    if (!isIE) {
			    mx = e.pageX;
			    my = e.pageY;
		    }
		    if (isIE) {
			    mx = event.clientX + document.body.scrollLeft;
			    my = event.clientY + document.body.scrollTop;
		    }
		
		    var objMainImage     =document.getElementById("MainImage");
		    PreviewBGwidth = objMainImage.width + (PreviewBGOffset * 2);
		    PreviewBGHeight = objMainImage.height + (PreviewBGOffset * 2);		
		
		    var xpos		
		    if (mx-PreviewBGwidth-5<0)
			    xpos=mx+5
		    else
			    xpos=mx-PreviewBGwidth-5
    		
		    var ypos
		    if (my-PreviewBGHeight-5<0)
			    ypos=my+5
		    else
			    ypos=my-PreviewBGHeight-5
    				
		    Show_Preview(xpos,ypos,true);
    			
		    return true;
	    }

        /////////////////////////////////////////////////////////////////////////////////////				
        // Utility functions from library
        /////////////////////////////////////////////////////////////////////////////////////				
         function htmlDencode(s) {
             var str = new String(s);
             str = str.replace(/&amp;/gi, "&")
             str = str.replace(/&lt;/gi, "<");
             str = str.replace(/&gt;/gi, ">");
             str = str.replace(/&quot;/gi, '"');
             return str;
         } 
         
         function Right(String, Length) {
            if (String == null) return (false);
            var dest = '';
            for (var i = (String.length - 1); i >= 0; i--)
                dest = dest + String.charAt(i);
            String = dest;
            String = String.substr(0, Length);
            dest = '';
            for (var i = (String.length - 1); i >= 0; i--)
                dest = dest + String.charAt(i);
            return dest;
        }         

        function Left(String, Length) {
            if (String == null)
                return (false);
            return String.substr(0, Length);
        }  
        
        function Create_XML_Object() {
            var progids = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
            // Try For IE
            var obj;        
            for(var i = 0; i < progids.length; i++) {
                try { obj = new ActiveXObject(progids[i]);
                    isIE=true;
                    return obj; }
                catch (ex) {}; }
            
            // Try for Firefox
            try { obj = new XMLHttpRequest(); 
                isIE=false;
                return obj; }
            catch (ex) {};
        }   
        
        function AJAX_Call(FunctionName, TargetControlID, contextKey, Async){
        
            var AJAXreturn=false;
	        var Ajaxobj=Create_XML_Object();
	        if(Ajaxobj!=null) {		
		        Ajaxobj.open("POST", FunctionName, Async);
		        Ajaxobj.setRequestHeader("Host","localhost");
		        Ajaxobj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		        Ajaxobj.setRequestHeader("Content-Length","12");	
		        // Inner funtion 
		        //---------------------------------------------------------------------------				
		        Ajaxobj.onreadystatechange = function() {
			        if(Ajaxobj.readyState == 4) { 
				        if(Ajaxobj.status == 200) { 
					        // Digest the results
		                    //---------------------------------------------------------------------------				
                            objTargetControl = document.getElementById(TargetControlID);                        
                            objTargetControl.innerHTML = htmlDencode(Ajaxobj.responseText);				
				        }
				        else //if(Ajaxobj.status != 200)
					        alert("Error retrieving data! (never returned a 200) " + Ajaxobj.status);							
					        return false;
			        } //(Ajaxobj.readyState == 4)
		        } // End of the inner funtion 	
		        
		        // RUN the function 
		        //---------------------------------------------------------------------------							        
		        var querystring="contextKey=" + contextKey;		       		        
		        Ajaxobj.send(querystring);	
		        // Look at the Sync options
		        //---------------------------------------------------------------------------			
		        if (!Async) {
		           	if(Ajaxobj.readyState == 4) { 
				        if(Ajaxobj.status == 200) {
					        // Digest the results
		                    //---------------------------------------------------------------------------						                    
                            objTargetControl = document.getElementById(TargetControlID);                        
                            objTargetControl.innerHTML = htmlDencode(Ajaxobj.responseText);	                            			
                            return true;
				        }
				        else //if(Ajaxobj.status != 200)
					        alert("Error retrieving data! (never returned a 200) " + Ajaxobj.status);							
					        return false;
			        } //(Ajaxobj.readyState == 4)
		        }			
	        } 
	        else 
		        return false;
        }	 
        /////////////////////////////////////////////////////////////////////////////////////				
        // End of Utility functions 
        /////////////////////////////////////////////////////////////////////////////////////				




