﻿// JScript File
var actionObject = 'none';
var actionEnabled = false;
var actionCmd = 'none';
var firstY = '0';
var downloading = false;

var minmoveY = 0;
var movmouseX = 0;
var movmouseY = 0;
var OS,browser,version,total,thestring;

//-----------------------------------------------------------------------------------------------------------
//base functions 
    function addEvent( obj, type, fn ){  // add the event function
        if (obj.addEventListener) obj.addEventListener( type, fn, false );
        else if (obj.attachEvent) {
            obj["e"+type+fn] = fn;
            obj[type+fn] = function() {
                obj["e"+type+fn]( window.event );
            };
            obj.attachEvent( "on"+type, obj[type+fn] );
        }
    };
    
    function removeEvent( obj, type, fn ){  // remove the event function
        if (obj.removeEventListener) obj.removeEventListener( type, fn, false );
        else if (obj.detachEvent) {
            obj["e"+type+fn] = fn;
            obj[type+fn] = function() {
                obj["e"+type+fn]( window.event );
            };
            obj.detachEvent( "on"+type, obj[type+fn] );
        }
    };

//-----------------------------------------------------------------------------------------------------------
//.document extensions  

    // Move window, or restore cursor

    addEvent(document, 'mousemove', function(e) {                
        if (!e) var e = event;
        //div2.innerText = e.srcElement.id;
        if (browser != 'Netscape Navigator' & e.button != 1) actionEnabled = false;        
        if (actionEnabled) {
           
            if (actionCmd == 'move') {           
                if ((e.clientY - movemouseY) <= minmoveY) {return false};
                if (browser != 'Netscape Navigator') {
                    document.getElementById(actionObject).style.pixelLeft = e.clientX - movemouseX;
                    document.getElementById(actionObject).style.pixelTop = e.clientY - movemouseY;
                } else {                    
                    document.getElementById(actionObject).style.left = (e.clientX - movemouseX) + 'px';
                    document.getElementById(actionObject).style.top = (e.clientY -movemouseY) + 'px';
                };
            }else if (actionCmd == 'resize') {
                if (browser != 'Netscape Navigator') {                    
                    document.getElementById(actionObject).style.pixelWidth = e.clientX - document.getElementById(actionObject).style.pixelLeft;
                    document.getElementById(actionObject).style.pixelHeight = e.clientY - document.getElementById(actionObject).style.pixelTop;
                }else{
                    document.getElementById(actionObject).style.width = (e.clientX - parseInt(document.getElementById(actionObject).style.left, 10)) + 'px';
                    document.getElementById(actionObject).style.height = (e.clientY - parseInt(document.getElementById(actionObject).style.top, 10)) + 'px';
                };            
            };
            
        };        
    });    

    // Move window, or restore cursor
    addEvent(document, 'mouseup', function(e) {
        //if (actionCmd == 'close') nwindow.close();
        actionEnabled = false;   
    });


//-----------------------------------------------------------------------------------------------------------
// Check browser       
    var detect = navigator.userAgent.toLowerCase();  
    if (checkIt('konqueror'))
    {
    	browser = "Konqueror";
    	OS = "Linux";
    }
    else if (checkIt('safari')) browser = "Safari"
    else if (checkIt('omniweb')) browser = "OmniWeb"
    else if (checkIt('opera')) browser = "Opera"
    else if (checkIt('webtv')) browser = "WebTV";
    else if (checkIt('icab')) browser = "iCab"
    else if (checkIt('msie')) browser = "Internet Explorer"
    else if (!checkIt('compatible'))
    {
    	browser = "Netscape Navigator"
    	version = detect.charAt(8);
    }
    else browser = "An unknown browser";
    
    if (!version) version = detect.charAt(place + thestring.length);

    if (!OS)
    {
    	if (checkIt('linux')) OS = "Linux";
    	else if (checkIt('x11')) OS = "Unix";
    	else if (checkIt('mac')) OS = "Mac"
    	else if (checkIt('win')) OS = "Windows"
    	else OS = "an unknown operating system";
    }

    function checkIt(string)
    {
    	place = detect.indexOf(string) + 1;
    	thestring = string;
    	return place;
    }   

//-----------------------------------------------------------------------------------------------------------
// Get Window width    
    function GetWindowWidth(){
        bodyWidth=0;
        if (typeof(window.innerWidth)=='number') {
            bodyWidth=window.innerWidth;
        } else {
            if (document.documentElement && document.documentElement.clientWidth) {
                bodyWidth = document.documentElement.clientWidth;
            } else {
                if (document.body&&document.body.clientWidth) {
                    bodyWidth=document.body.clientWidth;
                }
            }
        };
        return bodyWidth;
    };    

//-----------------------------------------------------------------------------------------------------------
// Get Window height    
    function GetWindowHeight(){
        bodyHeight=0;
        if (typeof(window.innerHeight)=='number') {
            bodyHeight=window.innerHeight;
        } else {
            if (document.documentElement && document.documentElement.clientHeight) {
                bodyHeight = document.documentElement.clientHeight;
            } else {
                if (document.body&&document.body.clientHeight) {
                    bodyHeight=document.body.clientHeight;
                }
            }
        };
        return bodyHeight;
    };       
    

//-----------------------------------------------------------------------------------------------------------
// Get Cookie Value    
	function getCookieVal (offset) {
	   var endstr = document.cookie.indexOf (";", offset);
	   if (endstr == -1)
	      endstr = document.cookie.length;
	   return unescape(document.cookie.substring(offset, endstr));
	}

//-----------------------------------------------------------------------------------------------------------
// Read Cookie
	function GetCookie (name) {
	        var arg = name + "=";
	        var alen = arg.length;
	        var clen = document.cookie.length;
	        var i = 0;
	        while (i < clen) {
	                var j = i + alen;
	                if (document.cookie.substring(i, j) == arg)
	                        return getCookieVal (j);
	                i = document.cookie.indexOf(" ", i) + 1;
	                        if (i == 0)
	                                break;
	                }
	   return null;
	}

//-----------------------------------------------------------------------------------------------------------
// Set Cookie     	
	function SetCookie (name, value) {
	        var argv = SetCookie.arguments;
	   	    var argc = SetCookie.arguments.length;
	        var expires = (argc > 2) ? argv[2] : null;
	        var path = (argc > 3) ? argv[3] : null;
	        var domain = (argc > 4) ? argv[4] : null;
	        var secure = (argc > 5) ? argv[5] : false;
	        document.cookie = name + "=" + escape (value) +
	                ((expires == null) ? "" : ("; expires=" +
						expires.toGMTString())) +
	                ((path == null) ? "" : ("; path=" + path)) +
	                ((domain == null) ? "" : ("; domain=" + domain)) +
	                ((secure == true) ? "; secure" : "");
	}
  
//-----------------------------------------------------------------------------------------------------------
// Check editbox value     	
    function CheckEditValue(editValue, isNumbers, minLength, maxLength) {
        if (editValue.length < minLength) return false;
        if (editValue.length > maxLength) return false;
        if (isNumbers == true) {
            for (i=0; i < editValue.length; i++){
                var numbers = '0123456789';
                if (numbers.indexOf(editValue.charAt(i)) < 0) {
                    return false;
                };
            };
        };
        return true;
    };  

    function FillStr(strFiller, strCount) {
        var retVal = "";
        for (i=0; i < strCount; i++){
            retVal += strFiller;
        };
        return retVal;
    };