var isIE = document.all?true:false;
document.onmousemove = getMousePosition;
function getMousePosition(e) {
  var _x;
  var _y;
  if (!isIE) {
    _x = e.pageX;
    _y = e.pageY;
  }
  if (isIE) {
    _x = event.clientX + document.body.scrollLeft;
    _y = event.clientY + document.body.scrollTop;
  }

posX=_x;
posY=_y;

  return true;
}
function SelectDate() 
{ 
    D = document.getElementById('Date').value; 
    if(D){ 
        D = D.split('/'); 
    }else{ 
        Dat = new Date(); 
        D = new Array(Dat.getDay(), Dat.getMonth(), Dat.getFullYear()); 
    } 
    win = window.open("files/date-picker.html","win","status=no,scrollbars=no,toolbar=no,menubar=no,resizable=no,height=150,width=250,left="+posX+",top="+posY+""); 
    if (parseInt(navigator.appVersion) == 2 && navigator.appName == "Netscape") 
        win = window.open("files/date-picker.html","win","status=yes,height=325,width=250"); 
        //win'MakeDate',D[2], D[1],D[0], 'SetDate'); 
        //win.MakeDate(D[2], D[1], D[0]); 
} 
function SetDate(Day, Month, Year) 
{ 
	CheckDat = new Date(); 
	CheckNewDat = new Date(Year +"," +"," + Month + "," + Day); 
	if(CheckNewDat < CheckDat){
		alert("OBS! Datumet har redan paserat!");
		return false;
	}
	if(Month<=9){
		Month= '0'+Month;
	}
	if(Day<=9){
		Day= '0'+Day;
	}
    document.getElementById('Date').value = Year +""+ Month +""+ Day; 
} 
function SelectDateFrom() 
{ 
    D = document.getElementById('DateFrom').value; 
    if(D){ 
        D = D.split('/'); 
    }else{ 
        Dat = new Date(); 
        D = new Array(Dat.getDay(), Dat.getMonth(), Dat.getFullYear()); 
    } 
    win = window.open("https://www.klickportalen.se/files/date-pickerFrom.html","win","status=no,scrollbars=no,toolbar=no,menubar=no,resizable=no,height=150,width=250,left="+posX+",top="+posY+""); 
    if (parseInt(navigator.appVersion) == 2 && navigator.appName == "Netscape") 
        win = window.open("https://www.klickportalen.se/files/date-pickerFrom.html","win","status=yes,height=325,width=250"); 
        //win'MakeDate',D[2], D[1],D[0], 'SetDateFrom'); 
        //win.MakeDate(D[2], D[1], D[0]); 
} 
function SelectDateTo() 
{ 
    D = document.getElementById('DateTo').value; 
    if(D){ 
        D = D.split('/'); 
    }else{ 
        Dat = new Date(); 
        D = new Array(Dat.getDay(), Dat.getMonth(), Dat.getFullYear()); 
    } 
    win = window.open("https://www.klickportalen.se/files/date-pickerTo.html","win","status=no,scrollbars=no,toolbar=no,menubar=no,resizable=no,height=150,width=250,left="+posX+",top="+posY+""); 
    if (parseInt(navigator.appVersion) == 2 && navigator.appName == "Netscape") 
        win = window.open("https://www.klickportalen.se/files/date-pickerTo.html","win","status=yes,height=325,width=250"); 
        //win'MakeDate',D[2], D[1],D[0], 'SetDateTo'); 
        //win.MakeDate(D[2], D[1], D[0]); 
} 
function SetDateFrom(Day, Month, Year) 
{ 
	CheckDat = new Date(); 
	CheckNewDat = new Date(Year +"," +"," + Month + "," + Day); 
	if(Month<=9){
		Month= '0'+Month;
	}
	if(Day<=9){
		Day= '0'+Day;
	}
    document.getElementById('DateFrom').value = Year +"-"+ Month +"-"+ Day; 
} 
function SetDateTo(Day, Month, Year) 
{ 
	CheckDat = new Date(); 
	CheckNewDat = new Date(Year +"," +"," + Month + "," + Day); 
	if(Month<=9){
		Month= '0'+Month;
	}
	if(Day<=9){
		Day= '0'+Day;
	}
    document.getElementById('DateTo').value = Year +"-"+ Month +"-"+ Day; 
} 
function GeneratePassword() {
    
    if (parseInt(navigator.appVersion) <= 3) { 
        alert("Sorry this only works in 4.0 browsers"); 
        return true; 
    }
    
    var length=8;
    var sPassword = "";
    length = 6;
    
    var noPunction = 1;
    var randomLength = 0;
    
    if (randomLength) { 
        length = Math.random(); 
        
        length = parseInt(length * 100);
        length = (length % 7) + 6
    }
    
    
    for (i=0; i < length; i++) {
    
        numI = getRandomNum();
        if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }
        
        sPassword = sPassword + String.fromCharCode(numI);
    }
    
    document.getElementById('pass1').value = sPassword
    document.getElementById('pass2').value = sPassword
    
    return true;
}

function getRandomNum() {
        
    // between 0 - 1
    var rndNum = Math.random()

    // rndNum from 0 - 1000    
    rndNum = parseInt(rndNum * 1000);

    // rndNum from 33 - 127        
    rndNum = (rndNum % 94) + 33;
            
    return rndNum;
}

function checkPunc(num) {
    
    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }    
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }
    
    return false;
}
