﻿var xmlHTTP = false;
        
function getHTTPRequestObject()
{
    try
    {
        //try legacy object first
        xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            //try IE implementation now
            xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(E)
        {
            xmlHTTP = false;
        }
    }            
    if (!xmlHTTP && typeof XMLHttpRequest != 'undefined')
    {
        //we must be using a Mozilla-based browser
        //so create a native request object now
        xmlHTTP = new XMLHttpRequest();
    }
}
function LoggedOut(returnVal)
{                                             
    // Create a new XMLHttpRequest object   
    getHTTPRequestObject();
    if (xmlHTTP)
    {                
        // we're passing false so this is a syncronous request.   
        // The script will stall until the document has been loaded.      
        xmlHTTP.open("GET", 'LogSession.ashx', false); 
        
        // Handle ready state changes ( ignore them until readyState = 4 )   
        xmlHTTP.onreadystatechange= function() 
            { 
                if (xmlHTTP.readyState!=4) 
                {
                    return false; 
                }
                else
                {
                    if (xmlHTTP.status!=200)
                        return false; 
                }    
            }            
                        
        xmlHTTP.send(null);  
    }                      
}

function ValidateLogin()
{
    if ((window.document.aspnetForm.ctl00$Login1$txtBoxLogin.value=='')&&(window.document.aspnetForm.ctl00$Login1$txtBoxPassword.value==''))
    {
        alert('Παρακαλώ συμπληρώστε Login ID και Password.');
        return false;
    }   
    else         
    {
        if (window.document.aspnetForm.ctl00$Login1$txtBoxLogin.value=='')
        {
            alert('Παρακαλώ συμπληρώστε Login ID.');
            return false;
        }  
        else
        {
            if (window.document.aspnetForm.ctl00$Login1$txtBoxPassword.value=='')
            {
                alert('Παρακαλώ συμπληρώστε Password.');
                return false;
            }           
        }
    }    
               
    return true;
}


function isDate(dateStr,currLang) 
{
    var datePat = /^(\d{2})(\/)(\d{2})(\/)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?

    if (matchArray == null) 
    {
        if (currLang=='en')  
            alert("Please select a date using the following format: dd/MM/yyyy.");
        else
            alert("Παρακαλώ επιλέξτε Ημερομηνία στη μορφή dd/MM/yyyy.");
        return false;
    }

    day = matchArray[1]; // p@rse date into variables
    month = matchArray[3]; 
    year = matchArray[5];

    if (month < 1 || month > 12) 
    { // check month range
        if (currLang=='en')  
            alert("The Month has to be a number between 1 and 12.");
        else
            alert("Ο Μήνας πρέπει να είναι μεταξύ 1 και 12.");
        return false;
    }

    if (day < 1 || day > 31) 
    {
        if (currLang=='en')  
            alert("The Day has to be a number between 1 and 31.");
        else
            alert("Η Ημέρα πρέπει να είναι μεταξύ 1 και 31.");
        return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) 
    {
        if (currLang=='en')  
            alert("The Selected Month ("+month+") doesn't have 31 Days!");
        else
            alert("Ο "+month+"ος Μήνας δεν έχει 31 Ημέρες!")
        return false;
    }

    if (month == 2) 
    { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) 
        {
            if (currLang=='en')  
                alert("February of " + year + " doesn't have " + day + "Days!");
            else    
                alert("Ο Φεβρουάριος του " + year + " δεν έχει " + day + " Ημέρες!");
            return false;
        }
    }
    return true; // date is valid
}
        
function todayStr() 
{
    var today=new Date()
    return today.getMonth()+1+"/"+today.getDate()+"/"+today.getFullYear();
}